Data Flow & State Management
This document explains how data flows through the game and how various systems manage state. Understanding data flow is critical for maintaining the game's logic and ensuring a seamless player experience.
Overview
The game relies on a centralized system to manage and share data between different modules. Key elements of data flow include:
- Initialization: Data is loaded and initialized at game startup.
- Runtime Updates: Systems modify and exchange data during gameplay.
- Persistence: Player progress and game state are saved and loaded using
SaveManager.lua
.
Data Flow Components
1. GameManager.lua
The GameManager.lua
script is the central hub for initializing and managing game-wide data.
-
Responsibilities:
- Initializes core systems (e.g.,
QuestManager.lua
,ContestManager.lua
). - Maintains global variables for game state.
- Coordinates data flow between subsystems.
- Initializes core systems (e.g.,
-
Example Workflow:
- At startup,
GameManager.lua
callsSaveManager.lua
to load saved data. - It initializes managers like
QuestManager.lua
andContestManager.lua
, passing relevant data. - During gameplay, it updates and tracks global states like active quests or contests.
- At startup,
2. SaveManager.lua
The SaveManager.lua
script is responsible for persisting player progress and game data.
-
Responsibilities:
- Saves player data, including outfits, quest progress, and rewards.
- Loads saved data during initialization.
- Provides utility functions for other scripts to read or write data.
-
Example Workflow:
- When the game starts,
SaveManager.lua
retrieves saved data and passes it toGameManager.lua
. - During gameplay, systems like
QuestManager.lua
callSaveManager.lua
to update quest states. - On game exit,
SaveManager.lua
writes the current state to storage.
- When the game starts,
3. QuestManager.lua
The QuestManager.lua
script handles quest-related data and integrates with other systems.
-
Responsibilities:
- Tracks active, completed, and available quests.
- Updates quest states based on player actions.
- Communicates with
SaveManager.lua
to persist quest progress.
-
Example Workflow:
- A player interacts with an NPC, triggering
DialogManager.lua
. - If a quest is accepted,
QuestManager.lua
adds it to the active quests list. - Upon completion,
QuestManager.lua
marks the quest as completed and updatesSaveManager.lua
.
- A player interacts with an NPC, triggering
4. ContestManager.lua
The ContestManager.lua
script manages data related to dress-up contests.
-
Responsibilities:
- Tracks contest entries, voting progress, and results.
- Updates player rankings and rewards.
- Communicates with
SaveManager.lua
to persist player contest participation and results.
-
Example Workflow:
- Players submit contest entries via
UIContest.lua
. ContestManager.lua
updates the contest state with the new entry.- After the contest ends,
ContestManager.lua
calculates results and rewards, updatingSaveManager.lua
.
- Players submit contest entries via
5. UIDressUp.lua and OutfitUtils.lua
These scripts handle character customization and manage outfit data.
-
Responsibilities:
UIDressUp.lua
provides the UI for customizing characters.OutfitUtils.lua
manages outfit data and ensures compatibility across systems.- Updates customization data in
SaveManager.lua
.
-
Example Workflow:
- A player customizes their character in
UIDressUp.lua
. - The updated outfit data is saved using
OutfitUtils.lua
. SaveManager.lua
persists the new outfit data.
- A player customizes their character in
Data Flow Diagram
Initialization
GameManager.lua
initializes core systems.SaveManager.lua
loads saved data.- Data is distributed to
QuestManager.lua
,ContestManager.lua
, andUIDressUp.lua
.
Runtime Updates
- Systems exchange data as events occur (e.g., quests, contests).
- Updated data is passed back to
SaveManager.lua
for persistence.
Persistence
- On game exit,
SaveManager.lua
writes all data to storage.
Key Considerations
- Data Consistency: Ensure systems update shared data consistently to avoid conflicts.
- Error Handling: Implement fallback mechanisms for corrupted or missing save data.
- Extensibility: Modularize data flow to allow new features to integrate seamlessly.