Development ⚠️ GridPlacement 6.0 documentation is in active development. APIs and content may change, and the site may be temporarily unstable.

Service-Based Architecture

GridBuilding v6.0 introduces a robust Service-Based Architecture implemented in pure C#. This architecture separates data (State), logic (Services), and engine integration (Godot Layers) to provide a testable, maintainable, and performant foundation.

🎯 Core Design Pattern

The architecture follows a strict unidirectional data flow pattern:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Godot Layer   β”‚    β”‚  Service Layer  β”‚    β”‚   State Layer   β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ User Input      │───▢│ InputService   │───▢│ UserState       β”‚
β”‚ (Mouse/Key)     β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ UI Updates      │◀───│ BuildingEvents │◀───│ BuildingState   β”‚
β”‚ (Visuals)       β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ Godot Nodes     │───▢│ BuildingService│───▢│ BuildingState   β”‚
β”‚ (Scene/Nodes)   β”‚    β”‚                 β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Components

  1. State Layer (Pure Data)

    • Contains only data and data-manipulation methods.
    • Serializable and completely decoupled from the game engine.
    • Examples: BuildingState, UserState, GridState.
  2. Service Layer (Business Logic)

    • Handles all game logic and rules.
    • Dispatches events when state changes.
    • Accepts commands from the Engine Layer.
    • Examples: BuildingService, InputService, ValidationService.
  3. Engine Layer (Integration)

    • Handles user input, rendering, and scene management.
    • Calls Services to perform actions.
    • Listens to Service events to update the view.
    • Examples: BuildingSystem (Node), GridVisualizer.

πŸ”„ Communication Flow

  1. Godot β†’ Service: The engine calls methods on services (e.g., BuildingService.SelectPlaceable()).
  2. Service β†’ State: The service updates the state (e.g., sets the current placeable).
  3. Service β†’ Godot: The service fires an event (e.g., OnPlaceableSelected).
  4. Godot Updates: The engine listens to the event and updates the UI or visuals.

Crucially, the Engine Layer never modifies the State directly.

πŸ“‚ System Structure

The Core logic is organized by Systems, reflecting the domain model of grid building:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Core/
β”œβ”€β”€ Systems/
β”‚   β”œβ”€β”€ Building/              # Building orchestration
β”‚   β”œβ”€β”€ Collision/             # Collision rules and detection
β”‚   β”œβ”€β”€ Grid/                  # Grid math and management
β”‚   β”œβ”€β”€ Input/                 # Input handling
β”‚   β”œβ”€β”€ Manipulation/          # Moving/Rotating objects
β”‚   β”œβ”€β”€ Placement/             # Placement validation
β”‚   β”œβ”€β”€ State/                 # State containers
β”‚   └── Validation/            # Rule validation logic

Service Interfaces

All interaction happens through interfaces, allowing for easy mocking and testing:

  • IBuildingService: Manage build mode and placement.
  • IManipulationService: Handle object transformations.
  • IInputService: Process input commands.
  • IValidationService: Check placement rules.

πŸš€ Benefits for Developers

  • Testability: Logic can be tested without running Godot.
  • Stability: Strict separation prevents “spaghetti code” state mutations.
  • Performance: Pure C# logic runs independently of the engine’s node overhead.