sonolus.py 0.1.3__py3-none-any.whl → 0.1.5__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.
Potentially problematic release.
This version of sonolus.py might be problematic. Click here for more details.
- sonolus/backend/blocks.py +756 -756
- sonolus/backend/excepthook.py +37 -37
- sonolus/backend/finalize.py +77 -69
- sonolus/backend/interpret.py +7 -7
- sonolus/backend/ir.py +29 -3
- sonolus/backend/mode.py +24 -24
- sonolus/backend/node.py +40 -40
- sonolus/backend/ops.py +197 -197
- sonolus/backend/optimize/__init__.py +0 -0
- sonolus/backend/optimize/allocate.py +126 -0
- sonolus/backend/optimize/constant_evaluation.py +374 -0
- sonolus/backend/optimize/copy_coalesce.py +85 -0
- sonolus/backend/optimize/dead_code.py +185 -0
- sonolus/backend/optimize/dominance.py +96 -0
- sonolus/backend/{flow.py → optimize/flow.py} +122 -92
- sonolus/backend/optimize/inlining.py +137 -0
- sonolus/backend/optimize/liveness.py +177 -0
- sonolus/backend/optimize/optimize.py +44 -0
- sonolus/backend/optimize/passes.py +52 -0
- sonolus/backend/optimize/simplify.py +191 -0
- sonolus/backend/optimize/ssa.py +200 -0
- sonolus/backend/place.py +17 -25
- sonolus/backend/utils.py +58 -48
- sonolus/backend/visitor.py +1151 -882
- sonolus/build/cli.py +7 -1
- sonolus/build/compile.py +88 -90
- sonolus/build/engine.py +10 -5
- sonolus/build/level.py +24 -23
- sonolus/build/node.py +43 -43
- sonolus/script/archetype.py +438 -139
- sonolus/script/array.py +27 -10
- sonolus/script/array_like.py +297 -0
- sonolus/script/bucket.py +253 -191
- sonolus/script/containers.py +257 -51
- sonolus/script/debug.py +26 -10
- sonolus/script/easing.py +365 -0
- sonolus/script/effect.py +191 -131
- sonolus/script/engine.py +71 -4
- sonolus/script/globals.py +303 -269
- sonolus/script/instruction.py +205 -151
- sonolus/script/internal/__init__.py +5 -5
- sonolus/script/internal/builtin_impls.py +255 -144
- sonolus/script/{callbacks.py → internal/callbacks.py} +127 -127
- sonolus/script/internal/constant.py +139 -0
- sonolus/script/internal/context.py +26 -9
- sonolus/script/internal/descriptor.py +17 -17
- sonolus/script/internal/dict_impl.py +65 -0
- sonolus/script/internal/generic.py +6 -9
- sonolus/script/internal/impl.py +38 -13
- sonolus/script/internal/introspection.py +17 -14
- sonolus/script/internal/math_impls.py +121 -0
- sonolus/script/internal/native.py +40 -38
- sonolus/script/internal/random.py +67 -0
- sonolus/script/internal/range.py +81 -0
- sonolus/script/internal/transient.py +51 -0
- sonolus/script/internal/tuple_impl.py +113 -0
- sonolus/script/internal/value.py +3 -3
- sonolus/script/interval.py +338 -112
- sonolus/script/iterator.py +167 -214
- sonolus/script/level.py +24 -0
- sonolus/script/num.py +80 -48
- sonolus/script/options.py +257 -191
- sonolus/script/particle.py +190 -157
- sonolus/script/pointer.py +30 -30
- sonolus/script/print.py +102 -81
- sonolus/script/project.py +8 -0
- sonolus/script/quad.py +263 -0
- sonolus/script/record.py +47 -16
- sonolus/script/runtime.py +52 -1
- sonolus/script/sprite.py +418 -333
- sonolus/script/text.py +409 -407
- sonolus/script/timing.py +114 -42
- sonolus/script/transform.py +332 -48
- sonolus/script/ui.py +216 -160
- sonolus/script/values.py +6 -13
- sonolus/script/vec.py +196 -78
- {sonolus_py-0.1.3.dist-info → sonolus_py-0.1.5.dist-info}/METADATA +1 -1
- sonolus_py-0.1.5.dist-info/RECORD +89 -0
- {sonolus_py-0.1.3.dist-info → sonolus_py-0.1.5.dist-info}/WHEEL +1 -1
- {sonolus_py-0.1.3.dist-info → sonolus_py-0.1.5.dist-info}/licenses/LICENSE +21 -21
- sonolus/backend/allocate.py +0 -51
- sonolus/backend/optimize.py +0 -9
- sonolus/backend/passes.py +0 -6
- sonolus/backend/simplify.py +0 -30
- sonolus/script/comptime.py +0 -160
- sonolus/script/graphics.py +0 -150
- sonolus/script/math.py +0 -92
- sonolus/script/range.py +0 -58
- sonolus_py-0.1.3.dist-info/RECORD +0 -75
- {sonolus_py-0.1.3.dist-info → sonolus_py-0.1.5.dist-info}/entry_points.txt +0 -0
sonolus/script/instruction.py
CHANGED
|
@@ -1,151 +1,205 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
2
|
-
from typing import Annotated, Any, NewType, dataclass_transform, get_origin
|
|
3
|
-
|
|
4
|
-
from sonolus.backend.ops import Op
|
|
5
|
-
from sonolus.script.internal.introspection import get_field_specifiers
|
|
6
|
-
from sonolus.script.internal.native import native_function
|
|
7
|
-
from sonolus.script.record import Record
|
|
8
|
-
from sonolus.script.runtime import _TutorialInstruction
|
|
9
|
-
from sonolus.script.text import StandardText
|
|
10
|
-
from sonolus.script.vec import Vec2
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Annotated, Any, NewType, dataclass_transform, get_origin
|
|
3
|
+
|
|
4
|
+
from sonolus.backend.ops import Op
|
|
5
|
+
from sonolus.script.internal.introspection import get_field_specifiers
|
|
6
|
+
from sonolus.script.internal.native import native_function
|
|
7
|
+
from sonolus.script.record import Record
|
|
8
|
+
from sonolus.script.runtime import _TutorialInstruction
|
|
9
|
+
from sonolus.script.text import StandardText
|
|
10
|
+
from sonolus.script.vec import Vec2
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Instruction(Record):
|
|
14
|
+
"""Tutorial instruction text.
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
```python
|
|
18
|
+
Instruction(id: int)
|
|
19
|
+
```
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
id: int
|
|
23
|
+
|
|
24
|
+
def show(self):
|
|
25
|
+
"""Show this instruction text."""
|
|
26
|
+
show_instruction(self)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class InstructionIcon(Record):
|
|
30
|
+
"""Tutorial instruction icon.
|
|
31
|
+
|
|
32
|
+
Usage:
|
|
33
|
+
```python
|
|
34
|
+
InstructionIcon(id: int)
|
|
35
|
+
```
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
id: int
|
|
39
|
+
|
|
40
|
+
def paint(self, position: Vec2, size: float, rotation: float, z: float, a: float):
|
|
41
|
+
"""Paint this instruction icon.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
position: The position of the icon.
|
|
45
|
+
size: The size of the icon.
|
|
46
|
+
rotation: The rotation of the icon.
|
|
47
|
+
z: The z-index of the icon.
|
|
48
|
+
a: The alpha of the icon.
|
|
49
|
+
"""
|
|
50
|
+
_paint(self.id, position.x, position.y, size, rotation, z, a)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@dataclass
|
|
54
|
+
class _InstructionTextInfo:
|
|
55
|
+
name: str
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass
|
|
59
|
+
class _InstructionIconInfo:
|
|
60
|
+
name: str
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def instruction(name: str) -> Any:
|
|
64
|
+
"""Define an instruction with the given name."""
|
|
65
|
+
return _InstructionTextInfo(name=name)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def instruction_icon(name: str) -> Any:
|
|
69
|
+
"""Define an instruction icon with the given name."""
|
|
70
|
+
return _InstructionIconInfo(name=name)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
type TutorialInstructions = NewType("TutorialInstructions", Any)
|
|
74
|
+
type TutorialInstructionIcons = NewType("TutorialInstructionIcons", Any)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@dataclass_transform()
|
|
78
|
+
def instructions[T](cls: type[T]) -> T | TutorialInstructions:
|
|
79
|
+
"""Decorator to define tutorial instructions.
|
|
80
|
+
|
|
81
|
+
Usage:
|
|
82
|
+
```python
|
|
83
|
+
@instructions
|
|
84
|
+
class Instructions:
|
|
85
|
+
tap: StandardInstruction.TAP
|
|
86
|
+
other_instruction: InstructionText = instruction("Other Instruction")
|
|
87
|
+
```
|
|
88
|
+
"""
|
|
89
|
+
if len(cls.__bases__) != 1:
|
|
90
|
+
raise ValueError("Instructions class must not inherit from any class (except object)")
|
|
91
|
+
instance = cls()
|
|
92
|
+
names = []
|
|
93
|
+
for i, (name, annotation) in enumerate(get_field_specifiers(cls).items()):
|
|
94
|
+
if get_origin(annotation) is not Annotated:
|
|
95
|
+
raise TypeError(f"Invalid annotation for instruction: {annotation}")
|
|
96
|
+
annotation_type = annotation.__args__[0]
|
|
97
|
+
annotation_values = annotation.__metadata__
|
|
98
|
+
if annotation_type is not Instruction:
|
|
99
|
+
raise TypeError(
|
|
100
|
+
f"Invalid annotation for instruction: {annotation}, expected annotation of type InstructionText"
|
|
101
|
+
)
|
|
102
|
+
if len(annotation_values) != 1 or not isinstance(annotation_values[0], _InstructionTextInfo):
|
|
103
|
+
raise TypeError(f"Invalid annotation for instruction: {annotation}, expected a single annotation value")
|
|
104
|
+
instruction_name = annotation_values[0].name
|
|
105
|
+
names.append(instruction_name)
|
|
106
|
+
setattr(instance, name, Instruction(i))
|
|
107
|
+
instance._instructions_ = names
|
|
108
|
+
instance._is_comptime_value_ = True
|
|
109
|
+
return instance
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@dataclass_transform()
|
|
113
|
+
def instruction_icons[T](cls: type[T]) -> T | TutorialInstructionIcons:
|
|
114
|
+
"""Decorator to define tutorial instruction icons.
|
|
115
|
+
|
|
116
|
+
Usage:
|
|
117
|
+
```python
|
|
118
|
+
@instruction_icons
|
|
119
|
+
class InstructionIcons:
|
|
120
|
+
hand: StandardInstructionIcon.HAND
|
|
121
|
+
other_icon: InstructionIcon = instruction_icon("Other Icon")
|
|
122
|
+
```
|
|
123
|
+
"""
|
|
124
|
+
if len(cls.__bases__) != 1:
|
|
125
|
+
raise ValueError("Instruction icons class must not inherit from any class (except object)")
|
|
126
|
+
instance = cls()
|
|
127
|
+
names = []
|
|
128
|
+
for i, (name, annotation) in enumerate(get_field_specifiers(cls).items()):
|
|
129
|
+
if get_origin(annotation) is not Annotated:
|
|
130
|
+
raise TypeError(f"Invalid annotation for instruction icon: {annotation}")
|
|
131
|
+
annotation_type = annotation.__args__[0]
|
|
132
|
+
annotation_values = annotation.__metadata__
|
|
133
|
+
if annotation_type is not InstructionIcon:
|
|
134
|
+
raise TypeError(
|
|
135
|
+
f"Invalid annotation for instruction icon: {annotation}, expected annotation of type InstructionIcon"
|
|
136
|
+
)
|
|
137
|
+
if len(annotation_values) != 1 or not isinstance(annotation_values[0], _InstructionIconInfo):
|
|
138
|
+
raise TypeError(
|
|
139
|
+
f"Invalid annotation for instruction icon: {annotation}, expected a single annotation value"
|
|
140
|
+
)
|
|
141
|
+
icon_name = annotation_values[0].name
|
|
142
|
+
names.append(icon_name)
|
|
143
|
+
setattr(instance, name, InstructionIcon(i))
|
|
144
|
+
instance._instruction_icons_ = names
|
|
145
|
+
instance._is_comptime_value_ = True
|
|
146
|
+
return instance
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class StandardInstruction:
|
|
150
|
+
"""Standard instructions."""
|
|
151
|
+
|
|
152
|
+
TAP = Annotated[Instruction, instruction(StandardText.TAP)]
|
|
153
|
+
TAP_HOLD = Annotated[Instruction, instruction(StandardText.TAP_HOLD)]
|
|
154
|
+
TAP_RELEASE = Annotated[Instruction, instruction(StandardText.TAP_RELEASE)]
|
|
155
|
+
TAP_FLICK = Annotated[Instruction, instruction(StandardText.TAP_FLICK)]
|
|
156
|
+
TAP_SLIDE = Annotated[Instruction, instruction(StandardText.TAP_SLIDE)]
|
|
157
|
+
HOLD = Annotated[Instruction, instruction(StandardText.HOLD)]
|
|
158
|
+
HOLD_SLIDE = Annotated[Instruction, instruction(StandardText.HOLD_SLIDE)]
|
|
159
|
+
HOLD_FOLLOW = Annotated[Instruction, instruction(StandardText.HOLD_FOLLOW)]
|
|
160
|
+
RELEASE = Annotated[Instruction, instruction(StandardText.RELEASE)]
|
|
161
|
+
FLICK = Annotated[Instruction, instruction(StandardText.FLICK)]
|
|
162
|
+
SLIDE = Annotated[Instruction, instruction(StandardText.SLIDE)]
|
|
163
|
+
SLIDE_FLICK = Annotated[Instruction, instruction(StandardText.SLIDE_FLICK)]
|
|
164
|
+
AVOID = Annotated[Instruction, instruction(StandardText.AVOID)]
|
|
165
|
+
JIGGLE = Annotated[Instruction, instruction(StandardText.JIGGLE)]
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class StandardInstructionIcon:
|
|
169
|
+
"""Standard instruction icons."""
|
|
170
|
+
|
|
171
|
+
HAND = Annotated[InstructionIcon, instruction_icon("#HAND")]
|
|
172
|
+
ARROW = Annotated[InstructionIcon, instruction_icon("#ARROW")]
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
@instructions
|
|
176
|
+
class EmptyInstructions:
|
|
177
|
+
pass
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
@instruction_icons
|
|
181
|
+
class EmptyInstructionIcons:
|
|
182
|
+
pass
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@native_function(Op.Paint)
|
|
186
|
+
def _paint(
|
|
187
|
+
icon_id: int,
|
|
188
|
+
x: float,
|
|
189
|
+
y: float,
|
|
190
|
+
size: float,
|
|
191
|
+
rotation: float,
|
|
192
|
+
z: float,
|
|
193
|
+
a: float,
|
|
194
|
+
) -> None:
|
|
195
|
+
raise NotImplementedError()
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def show_instruction(inst: Instruction, /):
|
|
199
|
+
"""Show the given instruction text."""
|
|
200
|
+
_TutorialInstruction.text_id = inst.id
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def clear_instruction():
|
|
204
|
+
"""Clear the current instruction text."""
|
|
205
|
+
_TutorialInstruction.text_id = -1
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"""Internal scripting details.
|
|
2
|
-
|
|
3
|
-
These are internal details of scripting which typically should not be used directly
|
|
4
|
-
in engine code.
|
|
5
|
-
"""
|
|
1
|
+
"""Internal scripting details.
|
|
2
|
+
|
|
3
|
+
These are internal details of scripting which typically should not be used directly
|
|
4
|
+
in engine code.
|
|
5
|
+
"""
|