Skip to content

sonolus.script.project

BuildConfig dataclass

A configuration for building an engine package.

FAST_PASSES: optimize.OptimizationLevel = optimize.FAST_PASSES class-attribute

The fast optimization level for quicker builds (-O1).

MINIMAL_PASSES: optimize.OptimizationLevel = optimize.MINIMAL_PASSES class-attribute

The minimal optimization level (-O0).

STANDARD_PASSES: optimize.OptimizationLevel = optimize.STANDARD_PASSES class-attribute

The standard optimization level (-O2).

build_play: bool = True class-attribute instance-attribute

Whether to build the play package.

build_preview: bool = True class-attribute instance-attribute

Whether to build the preview package.

build_tutorial: bool = True class-attribute instance-attribute

Whether to build the tutorial package.

build_watch: bool = True class-attribute instance-attribute

Whether to build the watch package.

override_resource_level_engines: bool = True class-attribute instance-attribute

Whether to override any levels included in resources to use the engine of this project.

passes: optimize.OptimizationLevel = optimize.STANDARD_PASSES class-attribute instance-attribute

The optimization level to use.

runtime_checks: RuntimeChecks = RuntimeChecks.NONE class-attribute instance-attribute

Runtime error checking mode.

verbose: bool = False class-attribute instance-attribute

Whether to print full tracebacks for compilation errors instead of a simplified summary.

Project

A Sonolus.py project.

Parameters:

Name Type Description Default
engine Engine

The engine of the project.

required
levels Iterable[Level] | Callable[[], Iterable[Level]] | None

The levels of the project.

None
resources PathLike | None

The path to the resources of the project.

None
converters dict[str | None, Callable[[ExternalLevelData], LevelData | None]] | None

A dict mapping source engine names to functions converting the ExternalLevelData of levels included in the project's resources into LevelData. A converter may return None to leave a level unconverted. The converter under the None key, if present, is applied to every level, after the engine-specific ones.

None

levels: list[Level] property

The project's levels, loaded and cached on first access.

build(build_dir: PathLike, config: BuildConfig | None = None)

Build the project.

Parameters:

Name Type Description Default
build_dir PathLike

The path to the build directory.

required
config BuildConfig | None

The build configuration.

None

dev(build_dir: PathLike, port: int = 8080, config: BuildConfig | None = None)

Start a development server for the project.

Parameters:

Name Type Description Default
build_dir PathLike

The path to the build directory.

required
port int

The port of the development server.

8080
config BuildConfig | None

The build configuration. If unset, defaults to runtime checks that log, pause, and terminate on errors, unlike build's default of no checks.

None

schema() -> ProjectSchema

Generate the schema of the project.

Returns:

Type Description
ProjectSchema

The ProjectSchema of the project.

with_levels(levels: Iterable[Level] | Callable[[], Iterable[Level]] | None) -> Project

Create a new project with the specified levels.

Parameters:

Name Type Description Default
levels Iterable[Level] | Callable[[], Iterable[Level]] | None

The levels of the project.

required

Returns:

Type Description
Project

The new project.

ProjectSchema

Bases: TypedDict

The schema of a project, as returned by Project.schema.

lazy_loader(fn)

Lazily yield the levels produced by the given callable.