sonolus.py 0.1.5__py3-none-any.whl → 0.1.6__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/build/cli.py +14 -3
- sonolus/build/project.py +30 -1
- sonolus/script/archetype.py +10 -1
- sonolus/script/project.py +51 -0
- sonolus/script/sprite.py +1 -3
- {sonolus_py-0.1.5.dist-info → sonolus_py-0.1.6.dist-info}/METADATA +1 -1
- {sonolus_py-0.1.5.dist-info → sonolus_py-0.1.6.dist-info}/RECORD +10 -10
- {sonolus_py-0.1.5.dist-info → sonolus_py-0.1.6.dist-info}/WHEEL +0 -0
- {sonolus_py-0.1.5.dist-info → sonolus_py-0.1.6.dist-info}/entry_points.txt +0 -0
- {sonolus_py-0.1.5.dist-info → sonolus_py-0.1.6.dist-info}/licenses/LICENSE +0 -0
sonolus/build/cli.py
CHANGED
|
@@ -2,6 +2,7 @@ import argparse
|
|
|
2
2
|
import contextlib
|
|
3
3
|
import http.server
|
|
4
4
|
import importlib
|
|
5
|
+
import json
|
|
5
6
|
import shutil
|
|
6
7
|
import socket
|
|
7
8
|
import socketserver
|
|
@@ -11,7 +12,7 @@ from time import perf_counter
|
|
|
11
12
|
|
|
12
13
|
from sonolus.build.engine import package_engine
|
|
13
14
|
from sonolus.build.level import package_level_data
|
|
14
|
-
from sonolus.build.project import build_project_to_collection
|
|
15
|
+
from sonolus.build.project import build_project_to_collection, get_project_schema
|
|
15
16
|
from sonolus.script.project import Project
|
|
16
17
|
|
|
17
18
|
|
|
@@ -147,6 +148,14 @@ def main():
|
|
|
147
148
|
dev_parser.add_argument("--build-dir", type=str, default="./build")
|
|
148
149
|
dev_parser.add_argument("--port", type=int, default=8000)
|
|
149
150
|
|
|
151
|
+
schema_parser = subparsers.add_parser("schema")
|
|
152
|
+
schema_parser.add_argument(
|
|
153
|
+
"module",
|
|
154
|
+
type=str,
|
|
155
|
+
nargs="?",
|
|
156
|
+
help="Module path (e.g., 'module.name'). If omitted, will auto-detect if only one module exists.",
|
|
157
|
+
)
|
|
158
|
+
|
|
150
159
|
args = parser.parse_args()
|
|
151
160
|
|
|
152
161
|
if not args.module:
|
|
@@ -161,16 +170,18 @@ def main():
|
|
|
161
170
|
if project is None:
|
|
162
171
|
sys.exit(1)
|
|
163
172
|
|
|
164
|
-
build_dir = Path(args.build_dir)
|
|
165
|
-
|
|
166
173
|
if args.command == "build":
|
|
174
|
+
build_dir = Path(args.build_dir)
|
|
167
175
|
start_time = perf_counter()
|
|
168
176
|
build_project(project, build_dir)
|
|
169
177
|
end_time = perf_counter()
|
|
170
178
|
print(f"Project built successfully to '{build_dir.resolve()}' in {end_time - start_time:.2f}s")
|
|
171
179
|
elif args.command == "dev":
|
|
180
|
+
build_dir = Path(args.build_dir)
|
|
172
181
|
start_time = perf_counter()
|
|
173
182
|
build_collection(project, build_dir)
|
|
174
183
|
end_time = perf_counter()
|
|
175
184
|
print(f"Build finished in {end_time - start_time:.2f}s")
|
|
176
185
|
run_server(build_dir / "site", port=args.port)
|
|
186
|
+
elif args.command == "schema":
|
|
187
|
+
print(json.dumps(get_project_schema(project), indent=2))
|
sonolus/build/project.py
CHANGED
|
@@ -5,7 +5,7 @@ from sonolus.build.engine import package_engine
|
|
|
5
5
|
from sonolus.build.level import package_level_data
|
|
6
6
|
from sonolus.script.engine import Engine
|
|
7
7
|
from sonolus.script.level import Level
|
|
8
|
-
from sonolus.script.project import Project
|
|
8
|
+
from sonolus.script.project import Project, ProjectSchema
|
|
9
9
|
|
|
10
10
|
BLANK_PNG = (
|
|
11
11
|
b"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x01\x00\x00\x00\x007n\xf9$"
|
|
@@ -92,3 +92,32 @@ def load_resources_files_to_collection(base_path: Path) -> Collection:
|
|
|
92
92
|
collection.load_from_scp(path)
|
|
93
93
|
collection.load_from_source(base_path)
|
|
94
94
|
return collection
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def get_project_schema(project: Project) -> ProjectSchema:
|
|
98
|
+
by_archetype: dict[str, dict[str, bool]] = {}
|
|
99
|
+
for archetype in project.engine.data.play.archetypes:
|
|
100
|
+
fields = by_archetype.setdefault(archetype.name, {})
|
|
101
|
+
# If a field is exported, we should exclude it if it's imported in watch mode
|
|
102
|
+
for field in archetype._exported_keys_:
|
|
103
|
+
fields[field] = False
|
|
104
|
+
for field in archetype._imported_keys_:
|
|
105
|
+
fields[field] = True
|
|
106
|
+
for archetype in project.engine.data.watch.archetypes:
|
|
107
|
+
fields = by_archetype.setdefault(archetype.name, {})
|
|
108
|
+
for field in archetype._imported_keys_:
|
|
109
|
+
if field not in fields:
|
|
110
|
+
fields[field] = True
|
|
111
|
+
for archetype in project.engine.data.preview.archetypes:
|
|
112
|
+
fields = by_archetype.setdefault(archetype.name, {})
|
|
113
|
+
for field in archetype._imported_keys_:
|
|
114
|
+
fields[field] = True
|
|
115
|
+
return {
|
|
116
|
+
"archetypes": [
|
|
117
|
+
{
|
|
118
|
+
"name": name,
|
|
119
|
+
"fields": [*fields],
|
|
120
|
+
}
|
|
121
|
+
for name, fields in by_archetype.items()
|
|
122
|
+
]
|
|
123
|
+
}
|
sonolus/script/archetype.py
CHANGED
|
@@ -5,7 +5,7 @@ from collections.abc import Callable
|
|
|
5
5
|
from dataclasses import dataclass
|
|
6
6
|
from enum import Enum, StrEnum
|
|
7
7
|
from types import FunctionType
|
|
8
|
-
from typing import Annotated, Any, ClassVar, Self, get_origin
|
|
8
|
+
from typing import Annotated, Any, ClassVar, Self, TypedDict, get_origin
|
|
9
9
|
|
|
10
10
|
from sonolus.backend.ir import IRConst, IRInstr
|
|
11
11
|
from sonolus.backend.mode import Mode
|
|
@@ -307,6 +307,11 @@ class _ArchetypeLevelData:
|
|
|
307
307
|
type _ArchetypeData = _ArchetypeSelfData | _ArchetypeReferenceData | _ArchetypeLevelData
|
|
308
308
|
|
|
309
309
|
|
|
310
|
+
class ArchetypeSchema(TypedDict):
|
|
311
|
+
name: str
|
|
312
|
+
fields: list[str]
|
|
313
|
+
|
|
314
|
+
|
|
310
315
|
class _BaseArchetype:
|
|
311
316
|
_is_comptime_value_ = True
|
|
312
317
|
|
|
@@ -401,6 +406,10 @@ class _BaseArchetype:
|
|
|
401
406
|
data.extend(field.type._accept_(bound.arguments[field.name] or zeros(field.type))._to_list_())
|
|
402
407
|
native_call(Op.Spawn, archetype_id, *(Num(x) for x in data))
|
|
403
408
|
|
|
409
|
+
@classmethod
|
|
410
|
+
def schema(cls) -> ArchetypeSchema:
|
|
411
|
+
return {"name": cls.name or "unnamed", "fields": list(cls._imported_fields_)}
|
|
412
|
+
|
|
404
413
|
def _level_data_entries(self, level_refs: dict[Any, int] | None = None):
|
|
405
414
|
if not isinstance(self._data_, _ArchetypeLevelData):
|
|
406
415
|
raise RuntimeError("Entity is not level data")
|
sonolus/script/project.py
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
from os import PathLike
|
|
2
4
|
from pathlib import Path
|
|
5
|
+
from typing import Self, TypedDict
|
|
3
6
|
|
|
7
|
+
from sonolus.script.archetype import ArchetypeSchema
|
|
4
8
|
from sonolus.script.engine import Engine
|
|
5
9
|
from sonolus.script.level import Level
|
|
6
10
|
|
|
@@ -23,3 +27,50 @@ class Project:
|
|
|
23
27
|
self.engine = engine
|
|
24
28
|
self.levels = levels or []
|
|
25
29
|
self.resources = Path(resources or "resources")
|
|
30
|
+
|
|
31
|
+
def with_levels(self, levels: list[Level]) -> Self:
|
|
32
|
+
"""Create a new project with the specified levels.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
levels: The levels of the project.
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
The new project.
|
|
39
|
+
"""
|
|
40
|
+
return Project(self.engine, levels, self.resources)
|
|
41
|
+
|
|
42
|
+
def dev(self, build_dir: PathLike, port: int = 8080):
|
|
43
|
+
"""Start a development server for the project.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
build_dir: The path to the build directory.
|
|
47
|
+
port: The port of the development server.
|
|
48
|
+
"""
|
|
49
|
+
from sonolus.build.cli import build_collection, run_server
|
|
50
|
+
|
|
51
|
+
build_collection(self, Path(build_dir))
|
|
52
|
+
run_server(Path(build_dir) / "site", port=port)
|
|
53
|
+
|
|
54
|
+
def build(self, build_dir: PathLike):
|
|
55
|
+
"""Build the project.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
build_dir: The path to the build directory.
|
|
59
|
+
"""
|
|
60
|
+
from sonolus.build.cli import build_project
|
|
61
|
+
|
|
62
|
+
build_project(self, Path(build_dir))
|
|
63
|
+
|
|
64
|
+
def schema(self) -> ProjectSchema:
|
|
65
|
+
"""Generate the schema of the project.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
The schema of the project.
|
|
69
|
+
"""
|
|
70
|
+
from sonolus.build.project import get_project_schema
|
|
71
|
+
|
|
72
|
+
return get_project_schema(self)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class ProjectSchema(TypedDict):
|
|
76
|
+
archetypes: list[ArchetypeSchema]
|
sonolus/script/sprite.py
CHANGED
|
@@ -353,9 +353,7 @@ class StandardSprite:
|
|
|
353
353
|
SIMULTANEOUS_CONNECTION_PURPLE = Annotated[Sprite, sprite("#SIMULTANEOUS_CONNECTION_PURPLE")]
|
|
354
354
|
SIMULTANEOUS_CONNECTION_CYAN = Annotated[Sprite, sprite("#SIMULTANEOUS_CONNECTION_CYAN")]
|
|
355
355
|
|
|
356
|
-
SIMULTANEOUS_CONNECTION_NEUTRAL_SEAMLESS = Annotated[
|
|
357
|
-
Sprite, sprite("#SIMULTANEOUS_CONNECTION_NEUTRAL_SEAMLESS")
|
|
358
|
-
]
|
|
356
|
+
SIMULTANEOUS_CONNECTION_NEUTRAL_SEAMLESS = Annotated[Sprite, sprite("#SIMULTANEOUS_CONNECTION_NEUTRAL_SEAMLESS")]
|
|
359
357
|
SIMULTANEOUS_CONNECTION_RED_SEAMLESS = Annotated[Sprite, sprite("#SIMULTANEOUS_CONNECTION_RED_SEAMLESS")]
|
|
360
358
|
SIMULTANEOUS_CONNECTION_GREEN_SEAMLESS = Annotated[Sprite, sprite("#SIMULTANEOUS_CONNECTION_GREEN_SEAMLESS")]
|
|
361
359
|
SIMULTANEOUS_CONNECTION_BLUE_SEAMLESS = Annotated[Sprite, sprite("#SIMULTANEOUS_CONNECTION_BLUE_SEAMLESS")]
|
|
@@ -26,15 +26,15 @@ sonolus/backend/optimize/passes.py,sha256=OPzcpFUU7qbQFSrgr84UuzDg_vB1GYkZj2K2aq
|
|
|
26
26
|
sonolus/backend/optimize/simplify.py,sha256=Tz4RftjH5TpIxoIOwiZuLchsrwzI9GaS_exdjAW6HKk,7927
|
|
27
27
|
sonolus/backend/optimize/ssa.py,sha256=D3CQm3s3gcuU0_k_0pXVrwirm4xjAZsX6corrTDS1Co,9013
|
|
28
28
|
sonolus/build/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
|
-
sonolus/build/cli.py,sha256=
|
|
29
|
+
sonolus/build/cli.py,sha256=12sFalCUJmn0Dg3f8ipNIkPmZ_djG15gldqWzDG7AYo,6241
|
|
30
30
|
sonolus/build/collection.py,sha256=IsDgedsAJ-foHzQ4LnQ9zSVXSz5wVVt4sgqiUICBvCU,10573
|
|
31
31
|
sonolus/build/compile.py,sha256=wBiRX6rnq8Op4_vVXJ-bPLtffgV4ppNBa9M9hIe9twI,3579
|
|
32
32
|
sonolus/build/engine.py,sha256=TAJCdSWOsEcTq9o6jfR3A2JZ8gOoc9YQx6FC_qW-dFw,6766
|
|
33
33
|
sonolus/build/level.py,sha256=3sdGPvIZ4a15u3-JdITnB6rznp6a2E3k6A0gB8A15JA,610
|
|
34
34
|
sonolus/build/node.py,sha256=jwsVWt6Brh4M9MypUt3Nqnxfm7fXrCMRWYQGwBTAszI,1162
|
|
35
|
-
sonolus/build/project.py,sha256=
|
|
35
|
+
sonolus/build/project.py,sha256=QukkCVQBGxnp1F2jQjaAkTg3TutwhWqKGXAfQZDMk1c,5162
|
|
36
36
|
sonolus/script/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
37
|
-
sonolus/script/archetype.py,sha256=
|
|
37
|
+
sonolus/script/archetype.py,sha256=cQDoNVO7dUHYQ7RlAHiyoEnUYt0seCnFPD_bPzo0BNE,34114
|
|
38
38
|
sonolus/script/array.py,sha256=KJxyL4I7A-CNFQW1RbZYQGVI527XZmoesDR-q6BurB8,9339
|
|
39
39
|
sonolus/script/array_like.py,sha256=OVOLMadS-Jj941S-EgoxlFPdaQLT6ZrHzaMnKtB6PfU,8346
|
|
40
40
|
sonolus/script/bucket.py,sha256=ZNlNeBZ1FzRLQ49bTuuJDmnYZ-_sjQEvosySx3ESxQc,6944
|
|
@@ -53,11 +53,11 @@ sonolus/script/options.py,sha256=nTOuoRC2p_qoMx4ngOVDY2WZDooTxwwGTGKyb994v2A,751
|
|
|
53
53
|
sonolus/script/particle.py,sha256=K06ArT9tstRNdbuGIviDmDDWcK3-ieA53LHg0Xvizow,8304
|
|
54
54
|
sonolus/script/pointer.py,sha256=pOh5vCSl6xR7mDm5PMOhBc_wf4O-b938DE0LtZWBmPc,1119
|
|
55
55
|
sonolus/script/print.py,sha256=mNYu9QWiacBBGZrnePZQMVwbbguoelUps9GiOK_aVRU,2096
|
|
56
|
-
sonolus/script/project.py,sha256=
|
|
56
|
+
sonolus/script/project.py,sha256=DhmBuH0CkFKmF27o1V9XhIOsywXDi57i-Wpwyd-70LM,2040
|
|
57
57
|
sonolus/script/quad.py,sha256=SVMcfRYx8Bv5t7A2vhus9QUiw-1V-qtRhldr3DnnNWw,7693
|
|
58
58
|
sonolus/script/record.py,sha256=rOVlo-eUUvFG_Ee-wKrgX_ZwOqWKWtS7s8m-juM70yE,11216
|
|
59
59
|
sonolus/script/runtime.py,sha256=xeiLJFeqkCev1x6pBiM5afyvi3GWdpLJ5OYRg9M9nwo,18562
|
|
60
|
-
sonolus/script/sprite.py,sha256
|
|
60
|
+
sonolus/script/sprite.py,sha256=FOozsPtaQnInnm-QshtYznnC66_8jb1D2sHmo7nFEsY,15718
|
|
61
61
|
sonolus/script/text.py,sha256=IsoINZJXefjReYDjJFwVaFsUCdgeQvPBDeywljM2dWo,13025
|
|
62
62
|
sonolus/script/timing.py,sha256=ZR0ypV2PIoDCMHHGOMfCeezStCsBQdzomdqaz5VKex0,2981
|
|
63
63
|
sonolus/script/transform.py,sha256=hH6KSRQC8vV-Z10CRCrGewMYqQwUMH3mQIEmniuC2Zw,10760
|
|
@@ -82,8 +82,8 @@ sonolus/script/internal/range.py,sha256=lrTanQFHU7RuQxSSPwDdoC30Y8FnHGxcP1Ahditu
|
|
|
82
82
|
sonolus/script/internal/transient.py,sha256=pSDFGu0m26zVsp6owmNTeSPue-osDd1JahjJSijW8t0,1520
|
|
83
83
|
sonolus/script/internal/tuple_impl.py,sha256=vjXmScLVdeTkDn3t9fgIRqtW31iwngnaP2rmA6nlsLw,3431
|
|
84
84
|
sonolus/script/internal/value.py,sha256=ik9sMKl0TbsH_C6QNxD4WfpAnmBFISgmmlazWwh3kY0,4308
|
|
85
|
-
sonolus_py-0.1.
|
|
86
|
-
sonolus_py-0.1.
|
|
87
|
-
sonolus_py-0.1.
|
|
88
|
-
sonolus_py-0.1.
|
|
89
|
-
sonolus_py-0.1.
|
|
85
|
+
sonolus_py-0.1.6.dist-info/METADATA,sha256=FBVX2Rg8O7Z0tikPOsj5wEziwbk4MSLsRxxBhJeTDrY,216
|
|
86
|
+
sonolus_py-0.1.6.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
|
87
|
+
sonolus_py-0.1.6.dist-info/entry_points.txt,sha256=oTYspY_b7SA8TptEMTDxh4-Aj-ZVPnYC9f1lqH6s9G4,54
|
|
88
|
+
sonolus_py-0.1.6.dist-info/licenses/LICENSE,sha256=JEKpqVhQYfEc7zg3Mj462sKbKYmO1K7WmvX1qvg9IJk,1067
|
|
89
|
+
sonolus_py-0.1.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|