StefanSchade / TaleForge

Text Adventure Logic Engine - A plattform to create immersive games without coding
0 stars 0 forks source link

TechDept: Title: Refactor Global Mutable State for Test Data Access #3

Open StefanSchade opened 3 months ago

StefanSchade commented 3 months ago

TODO: Eliminate Global Mutable State in Test Data Setup

Context:

In the current implementation of our text-based graphic adventure game, we've utilized a combination of lazy_static and Mutex to introduce a globally accessible mutable state. This state primarily holds the test instance of PlayerState and potentially other domain entities needed for initial development and testing. While this approach offers convenient and straightforward access to shared test data across various parts of the application, it contradicts Rust's best practices, particularly concerning safety and concurrency concerns inherent in global mutable state management.

The primary reason for adopting this temporary solution was to expedite early-stage development, allowing us to simulate state persistence and simplify access to shared test data without immediately implementing a more complex persistence layer (e.g., a database). It enabled quick prototyping and testing of game mechanics that require shared access to the mutable state, such as player movement and interaction within the game world.

Objective:

The goal now is to refactor this part of our codebase to eliminate the use of global mutable state, thereby aligning with Rust's safety guarantees and best practices for managing shared state. This refactor should introduce a more robust and flexible architecture for state management, possibly leveraging dependency injection or other patterns conducive to easy testing and future scalability.

Tasks:

Rationale:

Moving away from global mutable state not only adheres to Rust's design principles but also prepares our codebase for future complexity and growth. It enhances our application's maintainability, scalability, and testability, laying a solid foundation for further development and new features.