babylon.engine.scenarios.base
Scenario ABC + auto-registry — ADR-006.1 / Spec 059 US4.
Lifts the implicit “scenario builder” contract that 6 free functions duplicate
into an abstract base class with auto-registry via __init_subclass__.
Existing free-function names are preserved as thin shims in this package’s
__init__.py.
Usage:
class MyScenario(Scenario):
name = "my_scenario"
description = "Brief description"
def build(self) -> tuple[WorldState, SimulationConfig, GameDefines]:
# ... assemble territories, classes, relationships, return tuple
...
The subclass auto-registers via __init_subclass__; no manual registry
edit is required. Lookup via _SCENARIO_REGISTRY[name].
For the 6 historical builders, subclasses delegate build() to the
free-function implementations in _legacy.py / _legacy_wayne.py to
preserve byte-equality with the pre-Bundle-2 baseline (SC-007).
Functions
|
Look up a Scenario subclass by name. |
Return the names of all registered scenarios, sorted. |
Classes
|
Abstract base for scenario builders. |
- class babylon.engine.scenarios.base.Scenario[source]
Bases:
ABCAbstract base for scenario builders.
Subclasses MUST set
name(ClassVar str) anddescription(ClassVar str), and implementbuild(). They auto-register via__init_subclass__().Optional
build_territories/build_classes/build_relationshipsmethods are provided for the new-style composition pattern; subclasses MAY use them with a custombuild()that calls them, or overridebuild()directly (the pattern used by Bundle 2’s port of the 6 legacy builders).- abstractmethod build(*args, **kwargs)[source]
Build the scenario and return
(state, config, defines).- Return type:
- Parameters:
- classmethod __init_subclass__(**kwargs)[source]
Auto-register subclass in
_SCENARIO_REGISTRYkeyed oncls.name.- Raises:
ValueError – When two subclasses share the same
name(collision detection at import time, per US4 acceptance #2).- Return type:
- Parameters:
kwargs (Any)