-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path_statements_ren.py
107 lines (79 loc) · 2.74 KB
/
_statements_ren.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from typing import Any, Callable, Optional
from renpy.lexer import Lexer
import renpy.exports as renpy
from game._lovense.LovenseAction_ren import LovenseAction
from game._lovense.Lovense_ren import Lovense
path_builder: bool
lovense = Lovense()
"""renpy
python early:
"""
def parse_lovense(lexer: "Lexer") -> tuple[str, str]:
action: Optional[str] = lexer.name()
if not action:
lexer.error("Expected action name.")
if action == "stop":
return (action, "0")
strength = lexer.simple_expression()
if not strength:
lexer.error("Expected strength.")
return (action, strength)
def lint_lovense(lovense_expr: tuple[str, str]) -> None:
action: str = lovense_expr[0]
try:
action_func: Any = getattr(lovense, action)
except AttributeError:
renpy.error(
f"Unrecognized lovense action '{action}'. Please check if the action name is correct and supported."
)
return
if not callable(action_func):
renpy.error(
f"The lovense action '{action}' is not a function. Please ensure that it is a valid callable action."
)
if action == "stop":
return
try:
strength: Any = eval(lovense_expr[1])
except (SyntaxError, TypeError) as e:
renpy.error(
f"The strength expression '{lovense_expr[1]}' could not be evaluated due to an error: {e}"
)
return
except NameError as e:
strength = 0
renpy.error(f"Warning: Usage of variables cannot be checked at lint time. {e}")
if not isinstance(strength, int):
renpy.error(
f"The lovense strength value '{strength}' is not an integer. Strength values must be integer types."
)
if strength < 0:
renpy.error(
f"The lovense strength value '{strength}' is negative. Strength values must be non-negative integers."
)
try:
max_strength: int = Lovense.MAX_STRENGTHS[LovenseAction[action.upper()]]
except KeyError:
renpy.error(
f"The action '{action}' is not associated with a maximum strength value in 'Lovense.MAX_STRENGTHS'."
)
return
if strength > max_strength:
renpy.error(
f"The strength '{strength}' exceeds the maximum allowed strength of '{max_strength}' for the action '{action}'."
)
def execute_lovense(lovense_expr: tuple[str, str]) -> None:
action: str = lovense_expr[0]
strength: int = eval(lovense_expr[1])
f: Callable[..., None] = getattr(lovense, action)
if action == "stop":
f()
else:
f(strength)
return
renpy.register_statement( # type: ignore
name="lovense",
parse=parse_lovense,
lint=lint_lovense,
execute=execute_lovense,
)