-
Notifications
You must be signed in to change notification settings - Fork 81
0.a. Detailed Project Architecture
This page provides an in-depth look at the architecture of our Tactical RPG framework, explaining how Models and Modules work together to create a robust and scalable system.
We use a modular architecture that separates:
- Nodes and their respective script (Modules)
- Data containers and specialized logic services (Models)
This architecture enforces separation of concerns ("what is this script responsible for handling?"), better maintainability, scalability, and reusability of our (and soon your!) code.
Models are located in the /data/models/
directory.
They house:
-
Data containers and interfaces (Resource Scripts)
- Resources are interfaces leveraged by the Godot nodes.
- They contain our object-state's single-source-of-truth and easy access to decoupled areas of the code.
- They fire signals that connect decoupled areas of the code.
- Resources are interfaces leveraged by the Godot nodes.
-
Logic structures (Service scripts)
- Services are reusable specialized utilities leveraged on-demand by Godot nodes.
-
service.gd
is our master service. Its parent folder informs you of its purpose (e.g./camera/tactics/service/service.gd
handles only the TacticsCamera logic).- When the service is basic, all of our logic might happen inside the master Service script. No need for extreme fragmentation of our code!
- When the service is complex, our master Service script is used as a router that directs the engine towards our smaller sub-services. In this case, it organises our logic and dispatches requests to the appropriate sub-service.
-
- Services are reusable specialized utilities leveraged on-demand by Godot nodes.
/models/
manifest as standalone, single-responsibility entities that can be leveraged by our Modules.
For instance:
- Global configurations
- Player Stats definition & handling
- Reusable utility services etc.
- Resource Scripts (.gd files): Define the structure and behavior of resources
- Resources (.tres files): Define data and configurations for various game elements
- Service Scripts (.gd files): Logic and behaviour definition and handling. Contains code that shouldn't live directly inside its Node Module.
-
config/
: Global configuration & debug files -
view/camera/
: Camera behaviour logic -
view/control/
: Input and game control logic -
world/combat
: Combat logic, from Arena to Participant handling -
world/stats
: Stats definition and handling for our game actors -
world/utilities/
: Utility scripts and helper functions (calculations, etc.)
Modules are located in the /data/modules/
directory.
They contain the main game logic, scenes, and initiator scripts that bring the Models to life.
-
stats/
: Handles game statistics and player stats- This is a good example to study if you want to understand how Modules translate in the Godot editor. Take a look at our Level scene under
/assets/maps/level/
:test_level.tscn
. Once opened, you can see our pawns all have anexpertise
node:
It was added by drag & dropping our
expertise.tscn
scene and contains theexpertise.gd
script. - This is a good example to study if you want to understand how Modules translate in the Godot editor. Take a look at our Level scene under
-
tactics/
: Contains tactical gameplay elements-
camera/
: Camera logic and scene -
controls/
: Input handling and UI controls -
level/
: Level-related logic and scenes
-
-
ui/
: User interface elements
- Scene Scripts (.gd files): Contain the main logic for each module
- Scene Files (.tscn): Define the structure and Godot components of each module
-
Module Scene (module.tscn)
- The Godot scene file that defines the structure of the module
- Located alongside the module script, under its
/data/modules/[category]/[module]
subfolders
-
Module Scene Script (module.gd)
- The main script for the module's scene
- Interacts with the Resource Model and Master Service
- Located in
/data/modules/[category]/[module]
-
Resource Model (module_res.gd)
- Contains signals and data for the parent module
- Handles interfacing with the rest of the codebase on a per-request basis
- Located in
/data/models/[category]/[model]
- Sometimes has a default instance saved as a Resource file in
/data/models/[category]/[model]/model.tres
-
Master Service (service.gd)
- Contains methods for the parent module's inner logic
- Organizes all requests and dispatches responsibilities across specialized sub-services as needed
- Located in
res://data/models/[category]/[model]/service/
-
Sub Services (subservice_name.gd)
- Hold specialized logic that cover specific aspects of the parent module's responsibilities
- Located alongside the master service
- The Module Scene Script instantiates the Resource Model and Master Service.
- User input or game events trigger methods in the Module Scene Script.
- The Module Scene Script calls appropriate methods on the Master Service.
- The Master Service processes the request, using Subservices as needed.
- The Master Service updates the Resource Model with any changes.
- The Resource Model emits signals to notify the Module Scene Script of changes.
- The Module Scene Script updates the scene based on the changes in the Resource Model.
Let's look at how the camera system is implemented using this architecture:
-
Resource Model:
res://data/models/view/camera/tactics/t_cam_res.gd
- Defines camera attributes like movement speed, zoom levels, and rotation angles
- Contains signals for camera actions (move, rotate, zoom)
-
Master Service:
res://data/models/view/camera/tactics/service/service.gd
- Manages overall camera behavior
- Dispatches specific tasks to sub-services
-
Sub Services:
-
movement.gd
: Handles camera movement -
rotation.gd
: Manages camera rotation -
zoom.gd
: Controls camera zooming -
panning.gd
: Handles edge panning
-
-
Module Scene Script:
res://data/modules/tactics/camera/camera.gd
- Initializes the camera resource and service
- Processes input and updates camera state
- Calls service methods in response to game events
-
Module Scene:
res://data/modules/tactics/camera/camera.tscn
- Defines the structure of the camera object in the game world
This architecture allows for easy extension and modification of the camera system. For example, adding a new camera feature would involve creating a new sub-service and integrating it into the master service, without needing to modify the core camera logic.