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.luacallsSaveManager.luato load saved data. - It initializes managers like
QuestManager.luaandContestManager.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.luaretrieves saved data and passes it toGameManager.lua. - During gameplay, systems like
QuestManager.luacallSaveManager.luato update quest states. - On game exit,
SaveManager.luawrites 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.luato persist quest progress.
-
Example Workflow:
- A player interacts with an NPC, triggering
DialogManager.lua. - If a quest is accepted,
QuestManager.luaadds it to the active quests list. - Upon completion,
QuestManager.luamarks 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.luato persist player contest participation and results.
-
Example Workflow:
- Players submit contest entries via
UIContest.lua. ContestManager.luaupdates the contest state with the new entry.- After the contest ends,
ContestManager.luacalculates 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.luaprovides the UI for customizing characters.OutfitUtils.luamanages 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.luapersists the new outfit data.
- A player customizes their character in
Data Flow Diagram
Initialization
GameManager.luainitializes core systems.SaveManager.lualoads 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.luafor persistence.
Persistence
- On game exit,
SaveManager.luawrites 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.
Updated 12 months ago