exopython 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- exopy/__init__.py +270 -0
- exopy/__main__.py +20 -0
- exopy/_state.py +7 -0
- exopy/binary.py +48 -0
- exopy/constants.py +121 -0
- exopy/decompile.py +528 -0
- exopy/scripts.py +257 -0
- exopy/stdlib.py +65 -0
- exopy/variables.py +318 -0
- exopython-1.0.0.dist-info/METADATA +39 -0
- exopython-1.0.0.dist-info/RECORD +14 -0
- exopython-1.0.0.dist-info/WHEEL +5 -0
- exopython-1.0.0.dist-info/licenses/LICENSE +21 -0
- exopython-1.0.0.dist-info/top_level.txt +1 -0
exopy/scripts.py
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
from . import _state
|
|
3
|
+
from .binary import BinaryWriter
|
|
4
|
+
from .constants import ActionID, StaticType
|
|
5
|
+
from .variables import (
|
|
6
|
+
NovaValue, Variable, Parameter,
|
|
7
|
+
as_nova, as_float_nova, as_object_set, as_typed_nova,
|
|
8
|
+
default_nova_for, resolve_static_type, return_reg,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
class Activator:
|
|
12
|
+
def __init__(self, activator_type: int, params=()):
|
|
13
|
+
self.activator_type = int(activator_type)
|
|
14
|
+
self.parameters = [as_nova(p) for p in params]
|
|
15
|
+
def _write_to(self, w: BinaryWriter):
|
|
16
|
+
w.write_i32(self.activator_type)
|
|
17
|
+
w.write_vec(self.parameters, lambda p: p._write_to(w))
|
|
18
|
+
|
|
19
|
+
class Action:
|
|
20
|
+
def __init__(self, action_id: int, writer_fn, *, wait=False, closed=False):
|
|
21
|
+
self.action_id, self.writer_fn, self.wait, self.closed = int(action_id), writer_fn, bool(wait), bool(closed)
|
|
22
|
+
def _write_to(self, w: BinaryWriter):
|
|
23
|
+
w.write_i32(self.action_id); w.write_bool(self.closed); w.write_bool(self.wait)
|
|
24
|
+
self.writer_fn(w)
|
|
25
|
+
|
|
26
|
+
class CallParameter:
|
|
27
|
+
def __init__(self, parameter_id: int, value: NovaValue):
|
|
28
|
+
self.parameter_id = int(parameter_id)
|
|
29
|
+
self.value = value
|
|
30
|
+
def _write_to(self, w: BinaryWriter):
|
|
31
|
+
w.write_i32(self.parameter_id)
|
|
32
|
+
self.value._write_to(w)
|
|
33
|
+
|
|
34
|
+
class FunctionCall:
|
|
35
|
+
def __init__(self, script_id: int, parameters):
|
|
36
|
+
self.script_id = int(script_id)
|
|
37
|
+
self.parameters = list(parameters)
|
|
38
|
+
def _write_to(self, w: BinaryWriter):
|
|
39
|
+
w.write_i32(self.script_id)
|
|
40
|
+
w.write_vec(self.parameters, lambda p: p._write_to(w))
|
|
41
|
+
|
|
42
|
+
def _unwrap(acts):
|
|
43
|
+
if acts is None: return []
|
|
44
|
+
return acts.actions if hasattr(acts, "actions") else list(acts)
|
|
45
|
+
|
|
46
|
+
class _ActionBuilder:
|
|
47
|
+
def __init__(self):
|
|
48
|
+
self.actions = []
|
|
49
|
+
|
|
50
|
+
def _push(self, aid, fn, wait=False):
|
|
51
|
+
self.actions.append(Action(aid, fn, wait=wait))
|
|
52
|
+
return self
|
|
53
|
+
|
|
54
|
+
def wait(self, duration):
|
|
55
|
+
d = as_float_nova(duration)
|
|
56
|
+
return self._push(ActionID.Wait, lambda w: d._write_to(w), wait=True)
|
|
57
|
+
|
|
58
|
+
def wait_frames(self, frames):
|
|
59
|
+
f = as_nova(frames)
|
|
60
|
+
return self._push(ActionID.WaitFrames, lambda w: f._write_to(w), wait=True)
|
|
61
|
+
|
|
62
|
+
def repeat(self, count, body, *, wait=True):
|
|
63
|
+
c, acts = as_nova(count), _unwrap(body)
|
|
64
|
+
return self._push(ActionID.Repeat, lambda w: (w.write_vec(acts, lambda a: a._write_to(w)), c._write_to(w)), wait=wait)
|
|
65
|
+
|
|
66
|
+
def repeat_while(self, condition, body, *, wait=True):
|
|
67
|
+
cond, acts = as_nova(condition), _unwrap(body)
|
|
68
|
+
return self._push(ActionID.RepeatWhile, lambda w: (w.write_vec(acts, lambda a: a._write_to(w)), cond._write_to(w)), wait=wait)
|
|
69
|
+
|
|
70
|
+
def if_else(self, condition, if_body, else_body=None, *, wait=True):
|
|
71
|
+
cond, ifa, elsa = as_nova(condition), _unwrap(if_body), _unwrap(else_body)
|
|
72
|
+
return self._push(ActionID.ConditionBlock, lambda w: (
|
|
73
|
+
w.write_vec(ifa, lambda a: a._write_to(w)),
|
|
74
|
+
w.write_vec(elsa, lambda a: a._write_to(w)),
|
|
75
|
+
cond._write_to(w),
|
|
76
|
+
), wait=wait)
|
|
77
|
+
|
|
78
|
+
def move(self, target, pos, *, is_global=True, duration=0.0, easing=0, wait=False):
|
|
79
|
+
vals = (as_object_set(target), as_nova(pos), as_nova(bool(is_global)), as_float_nova(duration), NovaValue.easing(easing))
|
|
80
|
+
return self._push(ActionID.Move, lambda w: [v._write_to(w) for v in vals], wait=wait)
|
|
81
|
+
|
|
82
|
+
def scale(self, target, sc, *, duration=0.0, easing=0, wait=False):
|
|
83
|
+
vals = (as_object_set(target), as_nova(sc), as_float_nova(duration), NovaValue.easing(easing))
|
|
84
|
+
return self._push(ActionID.Scale, lambda w: [v._write_to(w) for v in vals], wait=wait)
|
|
85
|
+
|
|
86
|
+
def rotate(self, target, rot, *, shortest_path=True, is_global=False, duration=0.0, easing=0, wait=False):
|
|
87
|
+
vals = (as_object_set(target), as_float_nova(rot), as_nova(bool(shortest_path)), as_nova(bool(is_global)), as_float_nova(duration), NovaValue.easing(easing))
|
|
88
|
+
return self._push(ActionID.Rotate, lambda w: [v._write_to(w) for v in vals], wait=wait)
|
|
89
|
+
|
|
90
|
+
def set_var(self, var, value):
|
|
91
|
+
vid = var.variable_id if isinstance(var, Variable) else int(var)
|
|
92
|
+
val = as_nova(value) if value is not None else None
|
|
93
|
+
return self._push(ActionID.SetVariable, lambda w: (w.write_i32(vid), w.write_option(val, lambda v: v._write_to(w))))
|
|
94
|
+
|
|
95
|
+
def reset_var(self, var):
|
|
96
|
+
vid = var.variable_id if isinstance(var, Variable) else int(var)
|
|
97
|
+
return self._push(ActionID.ResetVariable, lambda w: w.write_i32(vid))
|
|
98
|
+
|
|
99
|
+
def set_color(self, target, color, *, channel=0, duration=0.0, easing=0, wait=False):
|
|
100
|
+
col = as_nova(color) if isinstance(color, (NovaValue, Variable, Parameter)) else NovaValue.color(color)
|
|
101
|
+
vals = (as_object_set(target), col, NovaValue.int(channel), as_float_nova(duration), NovaValue.easing(easing))
|
|
102
|
+
return self._push(ActionID.SetColor, lambda w: [v._write_to(w) for v in vals], wait=wait)
|
|
103
|
+
|
|
104
|
+
def set_text(self, target, text):
|
|
105
|
+
t = as_object_set(target)
|
|
106
|
+
txt = as_nova(text) if isinstance(text, (NovaValue, Variable, Parameter)) else NovaValue.string(text)
|
|
107
|
+
return self._push(ActionID.SetText, lambda w: (t._write_to(w), txt._write_to(w)))
|
|
108
|
+
|
|
109
|
+
def set_enabled(self, target, enabled):
|
|
110
|
+
t, en = as_object_set(target), as_nova(enabled)
|
|
111
|
+
return self._push(ActionID.SetEnabled, lambda w: (t._write_to(w), en._write_to(w)))
|
|
112
|
+
|
|
113
|
+
def camera_pan(self, pos, *, duration=0.0, easing=0, wait=False):
|
|
114
|
+
vals = (as_nova(pos), as_float_nova(duration), NovaValue.easing(easing))
|
|
115
|
+
return self._push(ActionID.CameraPan, lambda w: [v._write_to(w) for v in vals], wait=wait)
|
|
116
|
+
|
|
117
|
+
def camera_zoom(self, viewport_size, *, duration=0.0, easing=0, wait=False):
|
|
118
|
+
vals = (as_float_nova(viewport_size), as_float_nova(duration), NovaValue.easing(easing))
|
|
119
|
+
return self._push(ActionID.CameraZoom, lambda w: [v._write_to(w) for v in vals], wait=wait)
|
|
120
|
+
|
|
121
|
+
def camera_shake(self, strength=0.8, roughness=8.0, fade_in=0.02, fade_out=0.15, duration=0.2, wait=False):
|
|
122
|
+
vals = [as_float_nova(x) for x in (strength, roughness, fade_in, fade_out, duration)]
|
|
123
|
+
return self._push(ActionID.CameraShake, lambda w: [v._write_to(w) for v in vals], wait=wait)
|
|
124
|
+
|
|
125
|
+
def game_text(self, text, duration=2.0, wait=False):
|
|
126
|
+
txt = as_nova(text) if isinstance(text, (NovaValue, Variable, Parameter)) else NovaValue.string(text)
|
|
127
|
+
d = as_float_nova(duration)
|
|
128
|
+
return self._push(ActionID.GameTextShow, lambda w: (txt._write_to(w), d._write_to(w)), wait=wait)
|
|
129
|
+
|
|
130
|
+
def activate(self, target):
|
|
131
|
+
t = as_object_set(target)
|
|
132
|
+
return self._push(ActionID.Activate, lambda w: t._write_to(w))
|
|
133
|
+
|
|
134
|
+
def deactivate(self, target):
|
|
135
|
+
t = as_object_set(target)
|
|
136
|
+
return self._push(ActionID.Deactivate, lambda w: t._write_to(w))
|
|
137
|
+
|
|
138
|
+
def kill(self, target):
|
|
139
|
+
t = as_object_set(target)
|
|
140
|
+
return self._push(ActionID.Kill, lambda w: t._write_to(w))
|
|
141
|
+
|
|
142
|
+
def game_finish(self):
|
|
143
|
+
return self._push(ActionID.GameFinish, lambda w: None)
|
|
144
|
+
|
|
145
|
+
def raw_action(self, action_id: int, *fields, wait=False):
|
|
146
|
+
vals = [as_nova(f) for f in fields]
|
|
147
|
+
return self._push(action_id, lambda w: [v._write_to(w) for v in vals], wait=wait)
|
|
148
|
+
|
|
149
|
+
def ret(self, value, stype=None):
|
|
150
|
+
"""Store a return value into the level's shared return register."""
|
|
151
|
+
if stype is None:
|
|
152
|
+
stype = resolve_static_type(None, value)
|
|
153
|
+
else:
|
|
154
|
+
stype = resolve_static_type(stype)
|
|
155
|
+
reg = return_reg(stype)
|
|
156
|
+
return self.set_var(reg, as_typed_nova(value, stype))
|
|
157
|
+
|
|
158
|
+
def call(self, fn, *args, wait=True, **kwargs):
|
|
159
|
+
"""Invoke a NovaScript function (ActionID.RunFunction = 47)."""
|
|
160
|
+
if not isinstance(fn, Script) or not fn.is_function:
|
|
161
|
+
raise TypeError(f"Expected an @exoscript.func / function Script, got {fn!r}")
|
|
162
|
+
if len(args) > len(fn.parameters):
|
|
163
|
+
raise TypeError(f"{fn.script_name}() takes {len(fn.parameters)} args, got {len(args)}")
|
|
164
|
+
|
|
165
|
+
call_params = []
|
|
166
|
+
for idx, p in enumerate(fn.parameters):
|
|
167
|
+
if idx < len(args):
|
|
168
|
+
val = as_typed_nova(args[idx], p.static_type)
|
|
169
|
+
elif p.name in kwargs:
|
|
170
|
+
val = as_typed_nova(kwargs[p.name], p.static_type)
|
|
171
|
+
else:
|
|
172
|
+
val = p.default_value
|
|
173
|
+
call_params.append(CallParameter(p.parameter_id, val))
|
|
174
|
+
|
|
175
|
+
fc = FunctionCall(fn.script_id, call_params)
|
|
176
|
+
return self._push(ActionID.RunFunction, lambda w: fc._write_to(w), wait=wait)
|
|
177
|
+
|
|
178
|
+
def call_id(self, script_id: int, params=(), *, wait=True):
|
|
179
|
+
fc = FunctionCall(script_id, [CallParameter(pid, as_nova(val)) for pid, val in params])
|
|
180
|
+
return self._push(ActionID.RunFunction, lambda w: fc._write_to(w), wait=wait)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
class Script(_ActionBuilder):
|
|
184
|
+
def __init__(self, name: str, *, is_function=False, activation_count=0, condition=True):
|
|
185
|
+
super().__init__()
|
|
186
|
+
lvl = _state.get_level()
|
|
187
|
+
self.script_id = lvl._next_script_id()
|
|
188
|
+
self.script_name = str(name)
|
|
189
|
+
self.is_function = bool(is_function)
|
|
190
|
+
self.activation_count = int(activation_count)
|
|
191
|
+
self.condition = as_nova(condition)
|
|
192
|
+
self.activation_list, self.parameters, self.variables = [], [], []
|
|
193
|
+
self._level = lvl
|
|
194
|
+
self._packed = False
|
|
195
|
+
|
|
196
|
+
def on(self, activator_type: int, *params):
|
|
197
|
+
self.activation_list.append(Activator(activator_type, params))
|
|
198
|
+
return self
|
|
199
|
+
|
|
200
|
+
def param(self, name: str, stype, default=None) -> Parameter:
|
|
201
|
+
st = resolve_static_type(stype, default)
|
|
202
|
+
dv = default_nova_for(st) if default is None else as_typed_nova(default, st)
|
|
203
|
+
p = Parameter(self._level._next_param_id(), name, st, dv)
|
|
204
|
+
self.parameters.append(p)
|
|
205
|
+
return p
|
|
206
|
+
|
|
207
|
+
def local(self, name: str, stype, default=None) -> Variable:
|
|
208
|
+
st = resolve_static_type(stype, default)
|
|
209
|
+
iv = default_nova_for(st) if default is None else as_typed_nova(default, st)
|
|
210
|
+
v = Variable(self._level._next_var_id(), name, st, iv)
|
|
211
|
+
self.variables.append(v)
|
|
212
|
+
return v
|
|
213
|
+
|
|
214
|
+
def pack(self):
|
|
215
|
+
if not self._packed:
|
|
216
|
+
self._level.nova_scripts.append(self)
|
|
217
|
+
self._packed = True
|
|
218
|
+
return self
|
|
219
|
+
|
|
220
|
+
def _write_to(self, w: BinaryWriter):
|
|
221
|
+
w.write_i32(self.script_id); w.write_str(self.script_name); w.write_bool(self.is_function)
|
|
222
|
+
w.write_i32(self.activation_count); self.condition._write_to(w)
|
|
223
|
+
w.write_vec(self.activation_list, lambda a: a._write_to(w))
|
|
224
|
+
w.write_vec(self.parameters, lambda p: p._write_to(w))
|
|
225
|
+
w.write_vec(self.variables, lambda v: v._write_to(w))
|
|
226
|
+
w.write_vec(self.actions, lambda a: a._write_to(w))
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def create(name: str, *, is_function=False, activation_count=0, condition=True) -> Script:
|
|
230
|
+
return Script(name, is_function=is_function, activation_count=activation_count, condition=condition)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def function(name: str) -> Script:
|
|
234
|
+
return Script(name, is_function=True, activation_count=0)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def block() -> _ActionBuilder:
|
|
238
|
+
return _ActionBuilder()
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def func(py_fn=None, *, name=None):
|
|
242
|
+
"""Decorator: turn a Python function into a reusable packed Exoracer NovaScript function."""
|
|
243
|
+
def decorator(f):
|
|
244
|
+
sig = inspect.signature(f)
|
|
245
|
+
fn_script = function(name or f.__name__)
|
|
246
|
+
param_objs = []
|
|
247
|
+
for pname, p in sig.parameters.items():
|
|
248
|
+
hint = None if p.annotation is inspect.Parameter.empty else p.annotation
|
|
249
|
+
default = None if p.default is inspect.Parameter.empty else p.default
|
|
250
|
+
param_objs.append(fn_script.param(pname, hint, default))
|
|
251
|
+
|
|
252
|
+
body = f(*param_objs)
|
|
253
|
+
if body is not None:
|
|
254
|
+
fn_script.actions.extend(_unwrap(body))
|
|
255
|
+
return fn_script.pack()
|
|
256
|
+
|
|
257
|
+
return decorator(py_fn) if py_fn is not None else decorator
|
exopy/stdlib.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Pre-built reusable NovaScript functions that compile straight into your .exolvl."""
|
|
2
|
+
from . import _state
|
|
3
|
+
from . import scripts as exoscript
|
|
4
|
+
from . import variables as exovar
|
|
5
|
+
|
|
6
|
+
def _cached(key: str, builder):
|
|
7
|
+
lvl = _state.get_level()
|
|
8
|
+
if key not in lvl._stdlib_cache:
|
|
9
|
+
lvl._stdlib_cache[key] = builder()
|
|
10
|
+
return lvl._stdlib_cache[key]
|
|
11
|
+
|
|
12
|
+
def flash():
|
|
13
|
+
"""flash(target: ObjectSet, hi_color: Color, base_color: Color, duration: Float)"""
|
|
14
|
+
def build():
|
|
15
|
+
@exoscript.func(name="std_flash")
|
|
16
|
+
def _fn(target: exovar.ObjectSet, hi_color: exovar.Color = "#FFFFFF", base_color: exovar.Color = "#00F5FF", duration: exovar.Float = 0.15):
|
|
17
|
+
return (
|
|
18
|
+
exoscript.block()
|
|
19
|
+
.set_color(target, hi_color, duration=0.04, wait=True)
|
|
20
|
+
.wait(duration)
|
|
21
|
+
.set_color(target, base_color, duration=0.12, wait=True)
|
|
22
|
+
)
|
|
23
|
+
return _fn
|
|
24
|
+
return _cached("flash", build)
|
|
25
|
+
|
|
26
|
+
def pulse():
|
|
27
|
+
"""pulse(target: ObjectSet, big_scale: Vector, duration: Float)"""
|
|
28
|
+
def build():
|
|
29
|
+
@exoscript.func(name="std_pulse")
|
|
30
|
+
def _fn(target: exovar.ObjectSet, big_scale: exovar.Vector = (1.35, 1.35), duration: exovar.Float = 0.15):
|
|
31
|
+
return (
|
|
32
|
+
exoscript.block()
|
|
33
|
+
.scale(target, big_scale, duration=duration, wait=True)
|
|
34
|
+
.scale(target, (1.0, 1.0), duration=duration, wait=True)
|
|
35
|
+
)
|
|
36
|
+
return _fn
|
|
37
|
+
return _cached("pulse", build)
|
|
38
|
+
|
|
39
|
+
def glide_between():
|
|
40
|
+
"""glide_between(target: ObjectSet, pos_a: Vector, pos_b: Vector, duration: Float)"""
|
|
41
|
+
def build():
|
|
42
|
+
@exoscript.func(name="std_glide_between")
|
|
43
|
+
def _fn(target: exovar.ObjectSet, pos_a: exovar.Vector = (0, 0), pos_b: exovar.Vector = (5, 0), duration: exovar.Float = 1.5):
|
|
44
|
+
return (
|
|
45
|
+
exoscript.block()
|
|
46
|
+
.move(target, pos_b, is_global=True, duration=duration, wait=True)
|
|
47
|
+
.move(target, pos_a, is_global=True, duration=duration, wait=True)
|
|
48
|
+
)
|
|
49
|
+
return _fn
|
|
50
|
+
return _cached("glide_between", build)
|
|
51
|
+
|
|
52
|
+
def banner():
|
|
53
|
+
"""banner(label: ObjectSet, message: String, color: Color)"""
|
|
54
|
+
def build():
|
|
55
|
+
@exoscript.func(name="std_banner")
|
|
56
|
+
def _fn(label: exovar.ObjectSet, message: exovar.String = "HELLO", color: exovar.Color = "#FFE66D"):
|
|
57
|
+
return (
|
|
58
|
+
exoscript.block()
|
|
59
|
+
.set_text(label, message)
|
|
60
|
+
.set_color(label, color, duration=0.1)
|
|
61
|
+
.scale(label, (1.25, 1.25), duration=0.12, wait=True)
|
|
62
|
+
.scale(label, (1.0, 1.0), duration=0.12, wait=True)
|
|
63
|
+
)
|
|
64
|
+
return _fn
|
|
65
|
+
return _cached("banner", build)
|
exopy/variables.py
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
from . import _state
|
|
2
|
+
from .binary import BinaryWriter, parse_color
|
|
3
|
+
from .constants import DynamicType, StaticType
|
|
4
|
+
|
|
5
|
+
_STATIC_TO_VAR_DYNAMIC = {
|
|
6
|
+
StaticType.Bool: DynamicType.BoolVariable,
|
|
7
|
+
StaticType.Int: DynamicType.IntVariable,
|
|
8
|
+
StaticType.Float: DynamicType.FloatVariable,
|
|
9
|
+
StaticType.String: DynamicType.StringVariable,
|
|
10
|
+
StaticType.Color: DynamicType.ColorVariable,
|
|
11
|
+
StaticType.Vector: DynamicType.VectorVariable,
|
|
12
|
+
StaticType.Sound: DynamicType.SoundVariable,
|
|
13
|
+
StaticType.Music: DynamicType.MusicVariable,
|
|
14
|
+
StaticType.Object: DynamicType.ObjectVariable,
|
|
15
|
+
StaticType.ObjectSet: DynamicType.ObjectSetVariable,
|
|
16
|
+
StaticType.Transition: DynamicType.TransitionVariable,
|
|
17
|
+
StaticType.Easing: DynamicType.EasingVariable,
|
|
18
|
+
StaticType.Sprite: DynamicType.SpriteVariable,
|
|
19
|
+
StaticType.Script: DynamicType.ScriptVariable,
|
|
20
|
+
StaticType.Layer: DynamicType.LayerVariable,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
_STATIC_TO_PARAM_DYNAMIC = {
|
|
24
|
+
StaticType.Bool: DynamicType.BoolParameter,
|
|
25
|
+
StaticType.Int: DynamicType.IntParameter,
|
|
26
|
+
StaticType.Float: DynamicType.FloatParameter,
|
|
27
|
+
StaticType.String: DynamicType.StringParameter,
|
|
28
|
+
StaticType.Color: DynamicType.ColorParameter,
|
|
29
|
+
StaticType.Vector: DynamicType.VectorParameter,
|
|
30
|
+
StaticType.Sound: DynamicType.SoundParameter,
|
|
31
|
+
StaticType.Music: DynamicType.MusicParameter,
|
|
32
|
+
StaticType.Object: DynamicType.ObjectParameter,
|
|
33
|
+
StaticType.ObjectSet: DynamicType.ObjectSetParameter,
|
|
34
|
+
StaticType.Transition: DynamicType.TransitionParameter,
|
|
35
|
+
StaticType.Easing: DynamicType.EasingParameter,
|
|
36
|
+
StaticType.Sprite: DynamicType.SpriteParameter,
|
|
37
|
+
StaticType.Script: DynamicType.ScriptParameter,
|
|
38
|
+
StaticType.Layer: DynamicType.LayerParameter,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class NovaValue:
|
|
42
|
+
def __init__(self, dynamic_type: int, *, bool_value=False, int_value=0, float_value=0.0,
|
|
43
|
+
string_value=None, color_value=(0.0,0.0,0.0,0.0), vector_value=(0.0,0.0),
|
|
44
|
+
int_list_value=None, sub_values=None):
|
|
45
|
+
self.dynamic_type = int(dynamic_type)
|
|
46
|
+
self.bool_value = bool(bool_value)
|
|
47
|
+
self.int_value = int(int_value)
|
|
48
|
+
self.float_value = float(float_value)
|
|
49
|
+
self.string_value = string_value
|
|
50
|
+
self.color_value = parse_color(color_value)
|
|
51
|
+
self.vector_value = (float(vector_value[0]), float(vector_value[1]))
|
|
52
|
+
self.int_list_value = list(int_list_value) if int_list_value is not None else None
|
|
53
|
+
self.sub_values = list(sub_values) if sub_values is not None else None
|
|
54
|
+
|
|
55
|
+
@classmethod
|
|
56
|
+
def bool(cls, v): return cls(DynamicType.BoolConstant, bool_value=bool(v))
|
|
57
|
+
@classmethod
|
|
58
|
+
def int(cls, v): return cls(DynamicType.IntConstant, int_value=int(v))
|
|
59
|
+
@classmethod
|
|
60
|
+
def float(cls, v): return cls(DynamicType.FloatConstant, float_value=float(v))
|
|
61
|
+
@classmethod
|
|
62
|
+
def string(cls, v): return cls(DynamicType.StringConstant, string_value=str(v))
|
|
63
|
+
@classmethod
|
|
64
|
+
def color(cls, v): return cls(DynamicType.ColorConstant, color_value=v)
|
|
65
|
+
@classmethod
|
|
66
|
+
def vector(cls, v): return cls(DynamicType.VectorConstant, vector_value=v)
|
|
67
|
+
@classmethod
|
|
68
|
+
def easing(cls, v=0): return cls(DynamicType.EasingConstant, int_value=int(v))
|
|
69
|
+
@classmethod
|
|
70
|
+
def transition(cls, v=0): return cls(DynamicType.TransitionConstant, int_value=int(v))
|
|
71
|
+
@classmethod
|
|
72
|
+
def sound(cls, v=""): return cls(DynamicType.SoundConstant, string_value=str(v))
|
|
73
|
+
@classmethod
|
|
74
|
+
def music(cls, v=""): return cls(DynamicType.MusicConstant, string_value=str(v))
|
|
75
|
+
@classmethod
|
|
76
|
+
def sprite(cls, v=""): return cls(DynamicType.SpriteConstant, string_value=str(v))
|
|
77
|
+
@classmethod
|
|
78
|
+
def script(cls, s): return cls(DynamicType.ScriptConstant, int_value=s.script_id if hasattr(s, "script_id") else int(s))
|
|
79
|
+
@classmethod
|
|
80
|
+
def layer(cls, l): return cls(DynamicType.LayerConstant, int_value=l.layer_id if hasattr(l, "layer_id") else int(l))
|
|
81
|
+
@classmethod
|
|
82
|
+
def object(cls, o): return cls(DynamicType.ObjectConstant, int_value=o.entity_id if hasattr(o, "entity_id") else int(o))
|
|
83
|
+
@classmethod
|
|
84
|
+
def object_set(cls, objs): return cls(DynamicType.ObjectSetConstant, int_list_value=[o.entity_id if hasattr(o, "entity_id") else int(o) for o in objs])
|
|
85
|
+
@classmethod
|
|
86
|
+
def expr(cls, dt, *args): return cls(dt, sub_values=[as_nova(a) for a in args])
|
|
87
|
+
|
|
88
|
+
def _is_f(self):
|
|
89
|
+
return 56 <= self.dynamic_type <= 93 or self.dynamic_type in (145, DynamicType.FloatParameter)
|
|
90
|
+
|
|
91
|
+
def _is_s(self):
|
|
92
|
+
return self.dynamic_type in (
|
|
93
|
+
DynamicType.StringConstant, DynamicType.StringVariable,
|
|
94
|
+
DynamicType.StringFromInt, DynamicType.StringFromFloat,
|
|
95
|
+
DynamicType.StringConcat, DynamicType.StringParameter,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
def __add__(self, o):
|
|
99
|
+
o = as_nova(o)
|
|
100
|
+
if self._is_s() or o._is_s():
|
|
101
|
+
return NovaValue.expr(DynamicType.StringConcat, self, o)
|
|
102
|
+
return NovaValue.expr(DynamicType.FloatAdd if (self._is_f() or o._is_f()) else DynamicType.IntAdd, self, o)
|
|
103
|
+
def __sub__(self, o):
|
|
104
|
+
o = as_nova(o)
|
|
105
|
+
return NovaValue.expr(DynamicType.FloatSubtract if (self._is_f() or o._is_f()) else DynamicType.IntSubtract, self, o)
|
|
106
|
+
def __mul__(self, o):
|
|
107
|
+
o = as_nova(o)
|
|
108
|
+
return NovaValue.expr(DynamicType.FloatMultiply if (self._is_f() or o._is_f()) else DynamicType.IntMultiply, self, o)
|
|
109
|
+
def __truediv__(self, o):
|
|
110
|
+
o = as_nova(o)
|
|
111
|
+
return NovaValue.expr(DynamicType.FloatDivide if (self._is_f() or o._is_f()) else DynamicType.IntDivide, self, o)
|
|
112
|
+
def __lt__(self, o): return NovaValue.expr(DynamicType.BoolLess, self, as_nova(o))
|
|
113
|
+
def __le__(self, o): return NovaValue.expr(DynamicType.BoolLessOrEqual, self, as_nova(o))
|
|
114
|
+
def __gt__(self, o): return NovaValue.expr(DynamicType.BoolGreater, self, as_nova(o))
|
|
115
|
+
def __ge__(self, o): return NovaValue.expr(DynamicType.BoolGreaterOrEqual, self, as_nova(o))
|
|
116
|
+
def eq(self, o): return NovaValue.expr(DynamicType.BoolEqualNumber, self, as_nova(o))
|
|
117
|
+
def ne(self, o): return NovaValue.expr(DynamicType.BoolNotEqualNumber, self, as_nova(o))
|
|
118
|
+
|
|
119
|
+
def _write_to(self, w: BinaryWriter):
|
|
120
|
+
w.write_i32(self.dynamic_type)
|
|
121
|
+
w.write_bool(self.bool_value)
|
|
122
|
+
w.write_i32(self.int_value)
|
|
123
|
+
w.write_f32(self.float_value)
|
|
124
|
+
w.write_option(self.string_value, w.write_str)
|
|
125
|
+
w.write_color(self.color_value)
|
|
126
|
+
w.write_vec2(self.vector_value)
|
|
127
|
+
w.write_option(self.int_list_value, lambda lst: w.write_vec(lst, w.write_i32))
|
|
128
|
+
w.write_option(self.sub_values, lambda lst: w.write_vec(lst, lambda v: v._write_to(w)))
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class _ExprMixin:
|
|
132
|
+
def __add__(self, o): return self.ref() + o
|
|
133
|
+
def __sub__(self, o): return self.ref() - o
|
|
134
|
+
def __mul__(self, o): return self.ref() * o
|
|
135
|
+
def __truediv__(self, o): return self.ref() / o
|
|
136
|
+
def __lt__(self, o): return self.ref() < o
|
|
137
|
+
def __le__(self, o): return self.ref() <= o
|
|
138
|
+
def __gt__(self, o): return self.ref() > o
|
|
139
|
+
def __ge__(self, o): return self.ref() >= o
|
|
140
|
+
def eq(self, o): return self.ref().eq(o)
|
|
141
|
+
def ne(self, o): return self.ref().ne(o)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class Variable(_ExprMixin):
|
|
145
|
+
def __init__(self, vid, name, stype, init_val):
|
|
146
|
+
self.variable_id, self.name, self.static_type = int(vid), str(name), int(stype)
|
|
147
|
+
self.initial_value = as_typed_nova(init_val, self.static_type)
|
|
148
|
+
def ref(self):
|
|
149
|
+
return NovaValue(_STATIC_TO_VAR_DYNAMIC[self.static_type], int_value=self.variable_id)
|
|
150
|
+
def _write_to(self, w: BinaryWriter):
|
|
151
|
+
w.write_i32(self.variable_id); w.write_str(self.name); w.write_i32(self.static_type)
|
|
152
|
+
self.initial_value._write_to(w)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class Parameter(_ExprMixin):
|
|
156
|
+
def __init__(self, pid, name, stype, default_val):
|
|
157
|
+
self.parameter_id, self.name, self.static_type = int(pid), str(name), int(stype)
|
|
158
|
+
self.default_value = as_typed_nova(default_val, self.static_type)
|
|
159
|
+
def ref(self):
|
|
160
|
+
return NovaValue(_STATIC_TO_PARAM_DYNAMIC[self.static_type], int_value=self.parameter_id)
|
|
161
|
+
def _write_to(self, w: BinaryWriter):
|
|
162
|
+
w.write_i32(self.parameter_id); w.write_str(self.name); w.write_i32(self.static_type)
|
|
163
|
+
self.default_value._write_to(w)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def as_nova(val):
|
|
167
|
+
if isinstance(val, NovaValue): return val
|
|
168
|
+
if isinstance(val, (Variable, Parameter)): return val.ref()
|
|
169
|
+
if isinstance(val, bool): return NovaValue.bool(val)
|
|
170
|
+
if isinstance(val, int): return NovaValue.int(val)
|
|
171
|
+
if isinstance(val, float): return NovaValue.float(val)
|
|
172
|
+
if isinstance(val, str):
|
|
173
|
+
return NovaValue.color(val) if (val.startswith("#") and len(val) in (7, 9)) else NovaValue.string(val)
|
|
174
|
+
if hasattr(val, "entity_id"): return NovaValue.object(val)
|
|
175
|
+
if isinstance(val, (tuple, list)):
|
|
176
|
+
if len(val) == 2 and all(isinstance(x, (int, float)) for x in val): return NovaValue.vector(val)
|
|
177
|
+
if len(val) == 4 and all(isinstance(x, (int, float)) for x in val): return NovaValue.color(val)
|
|
178
|
+
return NovaValue.object_set(val)
|
|
179
|
+
raise TypeError(f"Cannot convert {type(val).__name__} to NovaValue")
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def as_float_nova(val):
|
|
183
|
+
if isinstance(val, (NovaValue, Variable, Parameter)):
|
|
184
|
+
return as_nova(val)
|
|
185
|
+
if isinstance(val, (int, float)) and not isinstance(val, bool):
|
|
186
|
+
return NovaValue.float(val)
|
|
187
|
+
return as_nova(val)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def as_object_set(target):
|
|
191
|
+
if isinstance(target, (NovaValue, Variable, Parameter)): return as_nova(target)
|
|
192
|
+
if isinstance(target, str): return NovaValue.expr(DynamicType.ObjectSetObjectsWithTag, NovaValue.string(target))
|
|
193
|
+
if hasattr(target, "entity_id"): return NovaValue.object_set([target])
|
|
194
|
+
if isinstance(target, (list, tuple)): return NovaValue.object_set(target)
|
|
195
|
+
raise TypeError(f"Invalid target: {target!r}")
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def default_nova_for(stype: int) -> NovaValue:
|
|
199
|
+
return {
|
|
200
|
+
StaticType.Bool: NovaValue.bool(False),
|
|
201
|
+
StaticType.Int: NovaValue.int(0),
|
|
202
|
+
StaticType.Float: NovaValue.float(0.0),
|
|
203
|
+
StaticType.String: NovaValue.string(""),
|
|
204
|
+
StaticType.Color: NovaValue.color("#FFFFFF"),
|
|
205
|
+
StaticType.Vector: NovaValue.vector((0.0, 0.0)),
|
|
206
|
+
StaticType.Sound: NovaValue.sound(""),
|
|
207
|
+
StaticType.Music: NovaValue.music(""),
|
|
208
|
+
StaticType.Object: NovaValue.object(0),
|
|
209
|
+
StaticType.ObjectSet: NovaValue.object_set([]),
|
|
210
|
+
StaticType.Transition: NovaValue.transition(0),
|
|
211
|
+
StaticType.Easing: NovaValue.easing(0),
|
|
212
|
+
StaticType.Sprite: NovaValue.sprite(""),
|
|
213
|
+
StaticType.Script: NovaValue.script(0),
|
|
214
|
+
StaticType.Layer: NovaValue.layer(1),
|
|
215
|
+
}[int(stype)]
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def as_typed_nova(val, stype: int) -> NovaValue:
|
|
219
|
+
if isinstance(val, (NovaValue, Variable, Parameter)):
|
|
220
|
+
return as_nova(val)
|
|
221
|
+
st = int(stype)
|
|
222
|
+
if st == StaticType.Bool: return NovaValue.bool(val)
|
|
223
|
+
if st == StaticType.Int: return NovaValue.int(val)
|
|
224
|
+
if st == StaticType.Float: return NovaValue.float(val)
|
|
225
|
+
if st == StaticType.String: return NovaValue.string(val)
|
|
226
|
+
if st == StaticType.Color: return NovaValue.color(val)
|
|
227
|
+
if st == StaticType.Vector: return NovaValue.vector(val)
|
|
228
|
+
if st == StaticType.Sound: return NovaValue.sound(val)
|
|
229
|
+
if st == StaticType.Music: return NovaValue.music(val)
|
|
230
|
+
if st == StaticType.Object: return NovaValue.object(val)
|
|
231
|
+
if st == StaticType.ObjectSet: return as_object_set(val)
|
|
232
|
+
if st == StaticType.Transition: return NovaValue.transition(val)
|
|
233
|
+
if st == StaticType.Easing: return NovaValue.easing(val)
|
|
234
|
+
if st == StaticType.Sprite: return NovaValue.sprite(val)
|
|
235
|
+
if st == StaticType.Script: return NovaValue.script(val)
|
|
236
|
+
if st == StaticType.Layer: return NovaValue.layer(val)
|
|
237
|
+
return as_nova(val)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def _reg(name, st, iv, is_global=True):
|
|
241
|
+
lvl = _state.get_level()
|
|
242
|
+
v = Variable(lvl._next_var_id(), name, st, iv)
|
|
243
|
+
if is_global: lvl.global_variables.append(v)
|
|
244
|
+
return v
|
|
245
|
+
|
|
246
|
+
def Bool(name, value=False, *, is_global=True): return _reg(name, StaticType.Bool, NovaValue.bool(value), is_global)
|
|
247
|
+
def Int(name, value=0, *, is_global=True): return _reg(name, StaticType.Int, NovaValue.int(value), is_global)
|
|
248
|
+
def Float(name, value=0.0, *, is_global=True): return _reg(name, StaticType.Float, NovaValue.float(value), is_global)
|
|
249
|
+
def String(name, value="", *, is_global=True): return _reg(name, StaticType.String, NovaValue.string(value), is_global)
|
|
250
|
+
def Color(name, value="#FFFFFF", *, is_global=True): return _reg(name, StaticType.Color, NovaValue.color(value), is_global)
|
|
251
|
+
def Vector(name, value=(0.0,0.0), *, is_global=True): return _reg(name, StaticType.Vector, NovaValue.vector(value), is_global)
|
|
252
|
+
def Object(name, obj=0, *, is_global=True): return _reg(name, StaticType.Object, NovaValue.object(obj), is_global)
|
|
253
|
+
def ObjectSet(name, objs=(), *, is_global=True): return _reg(name, StaticType.ObjectSet, NovaValue.object_set(objs), is_global)
|
|
254
|
+
|
|
255
|
+
# Resolve Python type hints or exovar constructors -> StaticType
|
|
256
|
+
HINT_TO_STATIC = {
|
|
257
|
+
bool: StaticType.Bool, Bool: StaticType.Bool,
|
|
258
|
+
int: StaticType.Int, Int: StaticType.Int,
|
|
259
|
+
float: StaticType.Float, Float: StaticType.Float,
|
|
260
|
+
str: StaticType.String, String: StaticType.String,
|
|
261
|
+
Color: StaticType.Color,
|
|
262
|
+
Vector: StaticType.Vector,
|
|
263
|
+
Object: StaticType.Object,
|
|
264
|
+
ObjectSet: StaticType.ObjectSet,
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
def resolve_static_type(hint, default=None) -> int:
|
|
268
|
+
if isinstance(hint, int) and 0 <= hint <= 14:
|
|
269
|
+
return hint
|
|
270
|
+
if hint in HINT_TO_STATIC:
|
|
271
|
+
return HINT_TO_STATIC[hint]
|
|
272
|
+
if default is not None:
|
|
273
|
+
if isinstance(default, bool): return StaticType.Bool
|
|
274
|
+
if isinstance(default, int): return StaticType.Int
|
|
275
|
+
if isinstance(default, float): return StaticType.Float
|
|
276
|
+
if isinstance(default, str):
|
|
277
|
+
return StaticType.Color if (default.startswith("#") and len(default) in (7, 9)) else StaticType.String
|
|
278
|
+
if isinstance(default, (tuple, list)) and len(default) == 2: return StaticType.Vector
|
|
279
|
+
raise ValueError(f"Cannot infer StaticType from annotation {hint!r} / default {default!r}")
|
|
280
|
+
|
|
281
|
+
# Shared Return Registers (lazily registered per level, Blockvale-style)
|
|
282
|
+
def return_reg(stype: int) -> Variable:
|
|
283
|
+
lvl = _state.get_level()
|
|
284
|
+
st = int(stype)
|
|
285
|
+
if st not in lvl._return_regs:
|
|
286
|
+
names = {
|
|
287
|
+
StaticType.Bool: "_rv_bool", StaticType.Int: "_rv_int",
|
|
288
|
+
StaticType.Float: "_rv_float", StaticType.String: "_rv_str",
|
|
289
|
+
StaticType.Color: "_rv_color", StaticType.Vector: "_rv_vec",
|
|
290
|
+
StaticType.Object: "_rv_obj", StaticType.ObjectSet: "_rv_set",
|
|
291
|
+
}
|
|
292
|
+
lvl._return_regs[st] = _reg(names.get(st, f"_rv_{st}"), st, default_nova_for(st), is_global=True)
|
|
293
|
+
return lvl._return_regs[st]
|
|
294
|
+
|
|
295
|
+
# Built-in Expressions
|
|
296
|
+
def player(): return NovaValue(DynamicType.ObjectPlayer)
|
|
297
|
+
def players(): return NovaValue(DynamicType.ObjectSetPlayers)
|
|
298
|
+
def tag(name): return NovaValue.expr(DynamicType.ObjectSetObjectsWithTag, NovaValue.string(name))
|
|
299
|
+
def obj_pos(obj): return NovaValue.expr(DynamicType.VectorObjectPos, obj)
|
|
300
|
+
def obj_global_pos(obj): return NovaValue.expr(DynamicType.VectorObjectGlobalPos, obj)
|
|
301
|
+
def pointer_world_pos(): return NovaValue(DynamicType.VectorPointerWorldPosition)
|
|
302
|
+
def pointer_down(): return NovaValue(DynamicType.BoolPointerDown)
|
|
303
|
+
def pointer_held(): return NovaValue(DynamicType.BoolPointerHeld)
|
|
304
|
+
def distance(a, b): return NovaValue.expr(DynamicType.FloatVectorDistance, a, b)
|
|
305
|
+
def random_int(lo, hi): return NovaValue.expr(DynamicType.IntRandom, int(lo), int(hi))
|
|
306
|
+
def to_str(val): return NovaValue.expr(DynamicType.StringFromInt, val)
|
|
307
|
+
def concat(a, b): return NovaValue.expr(DynamicType.StringConcat, NovaValue.string(a) if isinstance(a, str) else a, NovaValue.string(b) if isinstance(b, str) else b)
|
|
308
|
+
def not_(cond): return NovaValue.expr(DynamicType.BoolNot, cond)
|
|
309
|
+
def and_(a, b): return NovaValue.expr(DynamicType.BoolAnd, a, b)
|
|
310
|
+
def or_(a, b): return NovaValue.expr(DynamicType.BoolOr, a, b)
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
# Public exovar wrappers (keeps NovaValue internal)
|
|
314
|
+
def value(dynamic_type: int, **kwargs):
|
|
315
|
+
return NovaValue(dynamic_type, **kwargs)
|
|
316
|
+
|
|
317
|
+
def object_set(objs):
|
|
318
|
+
return NovaValue.object_set(objs)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: exopython
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Programmatic level builder, decompiler, and obfuscator for Exoracer (.exolvl)
|
|
5
|
+
License: MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2026
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
|
|
27
|
+
Requires-Python: >=3.8
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# exopy
|
|
33
|
+
|
|
34
|
+
Programmatic level builder, decompiler, and source-protection toolkit for **Exoracer** (`.exolvl`).
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install .
|