Architecture Overview
Key Classes
State Management (in resources/states/ and systems/*/ subdirectories)
- GBStates (resources/states/) - Container for all state
- ModeState (mode/) - Current building mode (OFF, BUILD, MANIPULATE)
- GridTargetingState (systems/grid_targeting/) - Targeting information
- BuildingState (systems/building/) - Placement parent, builder ownership
- ManipulationState (systems/manipulation/) - Active manipulation parent
Scene Context Nodes
- GBLevelContext (components/) - Exports target_map, maps, objects_parent
- GBOwner (user/) - Registers the active owner
- GBContexts (context/) - Holds indicator, owner, systems contexts
- GBSystemsContext (context/) - Holds BuildingSystem, GridTargetingSystem, ManipulationSystem
- IndicatorContext (context/) - Holds reference to IndicatorManager
- GBOwnerContext (user/) - Internal refcounted holding the GBOwner reference
Placement Rules
- PlacementRule - Base class for all placement rules
- TileCheckRule - Base class for rules evaluating tile/indicator state
- CollisionsCheckRule - Checks for overlapping physics bodies
- WithinTilemapBoundsRule - Validates placement within tilemap bounds
- ValidPlacementTileRule - Basic placement validity check
- SpendMaterialsRuleGeneric - Consumes inventory/materials after placement
Runtime Boundary
- Godot nodes + scripts
- Own most runtime behavior.
- Expose the practical runtime API through exports, methods, and shared state objects.
- Composition container + injector
- Wire contexts, states, logger, actions, templates, and settings into nodes.
- State-first coordination
- Many listeners consume shared state directly instead of receiving small isolated payload objects.
High-Level Shape
| |
Data Flow
- Initialization
GBInjectorSystemreadscomposition_container.- It injects any node with
resolve_gb_dependencies(...).
- Scene context application
GBLevelContextappliestarget_map,maps, andobjects_parent.GBOwnerapplies the active owner.
- Input and targeting
GridPositioner2Dprocesses mouse/keyboard input and moves to tile centers.TargetingShapeCast2DupdatesGridTargetingState.target.
- Placement start
- UI or game code calls
BuildingSystem.enter_build_mode(placeable). - Preview/rules/setup are created from the selected
Placeable.
- UI or game code calls
- Validation and commit
- Base rules from
GBSettings.placement_rulesand placeable-specific rules are evaluated. BuildingSystem.try_build()commits placement if validation succeeds.
- Base rules from
- Manipulation
ManipulationSystemmanages move/manipulation workflow.ManipulationParentowns the visual rotation/flip parent hierarchy.
What Plugin Users Should Rely On
- Inspector-driven setup for level wiring and settings.
- Method-based DI via
resolve_gb_dependencies(...). - State-based coordination through
GBStatesandGBContexts. - System entry points such as
enter_build_mode(...),try_build(), and manipulation APIs.
Essential Integration Invariant
The plugin is only fully ready after all of these are true:
GBInjectorSystem.composition_containeris assigned.GBLevelContextis in the scene withtarget_map,maps, andobjects_parentassigned.GBOwneris in the scene withowner_rootassigned.- Systems (BuildingSystem, GridTargetingSystem, ManipulationSystem) are registered via
GBSystemsContext.set_system(). IndicatorContext.indicator_manageris assigned if using indicators.- Runtime validation passes once your level and owner context are actually available.