Project Architecture
The plugin architecture is layered to keep systems modular and testable while supporting flexible game integration.
Layer Overview
Section titled “Layer Overview”Layer | Contents | Notes |
---|---|---|
Resource Configuration | GBConfig, GBSettings, GBTemplates, GBMessages, rule resources | Editable in inspector; serialized with project |
Composition & Injection | GBCompositionContainer, GBInjectorSystem | Provides dependency injection & lazy construction |
Core Systems | Placement, Targeting, Building, Manipulation, Validation, Indicator | Each focuses on a single domain concern |
State Containers | GBStates (mode, targeting, building, manipulation) | Shared by injected nodes; supports multi-context |
Contexts | GBContexts (placement, systems, owner, level) | Encapsulate environment dependencies |
UI & Interaction | Action bar, selection lists, info displays | Driven by states & actions resources |
Testing Utilities | Factories, reports, test setups | Facilitate GdUnit coverage & deterministic assertions |
Dependency Injection Model
Section titled “Dependency Injection Model”Instead of global singletons, systems resolve dependencies from the injected composition container. Benefits:
- Multitenancy (multiple players/levels)
- Clear test seams (swap in a fresh container)
- Lazy provisioning (logger/settings only built when required)
Nodes opt‑in via resolve_gb_dependencies
pattern. See the Dependency Injection document.
How the Systems Work Together
Section titled “How the Systems Work Together”Instead of a complex diagram, let’s walk through how the Grid Building system works in simple steps:
The Basic Flow:
Section titled “The Basic Flow:”- You pick something to build: Click a placeable in the UI
- BuildingSystem wakes up:
enter_build_mode()
gets called with your choice - IndicatorManager provides feedback: Sets up live indicators as you target tiles
- GridTargetingSystem helps: Figures out where you’re pointing on the grid
- PlacementValidator checks rules: Makes sure you can build there (tile rules first)
- IndicatorManager shows feedback: Colors appear to show valid/invalid spots
- ManipulationSystem (optional): If enabled, lets you move/rotate the preview before placing
- You confirm placement:
BuildingSystem.try_build()
runs full validation - Object gets created: If everything checks out, your building appears in the world
- ManipulationSystem (again): Now you can move/rotate/delete the placed object
Key Points to Remember:
Section titled “Key Points to Remember:”- BuildingSystem is the “boss” - it starts and ends the building process
- IndicatorManager handles the live preview feedback
- ManipulationSystem has two jobs: preview adjustment (if enabled) and post-placement editing
- Validation happens twice: quick checks during preview, full checks when you confirm
- Everything is connected but each system has one clear job
Key Data Flows
Section titled “Key Data Flows”- UI Selection → User selects placeable from UI →
BuildingSystem.enter_build_mode(placeable)
is called - Build Mode Initialization: BuildingSystem prepares preview with selected placeable
- Targeting Setup: GridTargetingSystem tracks cursor/grid position
- Live Validation: PlacementValidator runs tile rules, IndicatorManager shows live feedback
- Preview Manipulation: If enabled in placeable settings, ManipulationSystem can move/rotate preview instances during placement
- Confirmation: User confirms placement,
BuildingSystem.try_build()
runs full rule validation (including non-tile rules) - Instantiation: If valid, BuildingSystem spawns PlaceableInstance with metadata for manipulation & save/load
- Post-Placement: ManipulationSystem handles move/rotate/delete operations on placed instances
Save / Load Considerations
Section titled “Save / Load Considerations”PlaceableInstance holds references back to originating Placeable enabling reconstruction. Systems should avoid storing raw scene node references across sessions; rely on IDs or resource paths.
Logging & Debug Controls
Section titled “Logging & Debug Controls”GBDebugSettings gates verbosity. High verbosity surfaces:
- Injection operations
- Indicator setup summaries
- Rule validation traces (future extension)
Extensibility Guidelines
Section titled “Extensibility Guidelines”- Favor composition (create a new rule resource) over conditionals inside existing rules.
- Keep resource scripts lean; complex logic belongs in systems.
- Add new UI affordances by observing states rather than polling systems directly.
Planned Evolutions
Section titled “Planned Evolutions”- Cross-context synchronization primitives (multiplayer scenarios).
- Performance profiling hooks (duration_ms in reports).
- Rule documentation tooling.
Core Architecture References
Section titled “Core Architecture References”- Context & State – Distinguishes long‑lived context objects from frequently mutating state containers; essential for understanding rule evaluation purity.
- Placement Chain – End‑to‑end flow from input to instantiated object.
- Dependency Injection – Container pattern enabling multi‑tenant/testable setup.
- Placement Rules Pipeline – Validation composition & indicator generation.
High-Level System Architecture
Section titled “High-Level System Architecture”Core Components:
- Configuration & Templates: GBConfig, GBTemplates, GBMessages
- Composition: GBCompositionContainer, GBInjectorSystem
- Core Systems: BuildingSystem, PlacementValidator, IndicatorManager, GridTargetingSystem, ManipulationSystem
- State Management: ModeState, BuildingState, ManipulationState, GridTargetingState
- UI: Selection/Action UI
Data Flow:
- UI → BuildingSystem → PlacementValidator → IndicatorManager
- GridTargetingSystem → IndicatorManager
- Configuration → CompositionContainer → InjectorSystem → BuildingSystem
- State components manage respective system states
- ManipulationSystem handles instantiated objects
Last updated: 2025-08-20