Repository navigation
PlayerSnapshot Saving System
The PlayerSnapshot system is a method for saving/storing key player information when switching between game screens. For example, after level 1 the cyclops minigame appears via a cutscene. This minigame and cutscene are separate screens in the game, so all entities (including the player) are discarded in the switching of screens. This system aims to prevent that by saving data like gold, health and items that the player currently has and updating a newly generated player when the next level appear.s
classDiagram
class GdxGame{
-PlayerSnapshot playerSnapshot
+savePlayerState(Entity player) void
+restorePlayerState(Entity player) void
}
class PlayerSnapshot{
-int health
-int gold
-List~InventorySlot~ inventory
-PlayerSnapshot(int health, int gold, List~Inventory~ inventory)
+static capture(Entity player) PlayerSnapshot$
+applyTo(Entity player) void
}
The PlayerSnapshot functionality works on any Entity that has the following Components:
- CombatStatsComponent
- InventoryComponent
With potential for more components to be added.
To save a player's information for use in another game screen:
game.savePlayer(Entity player)is the function to call with the given player to save. Keeping it in the GdxGame.java class, which is only disposed of when the entire game is exited.
Then to restore the saved player data on a new player entity you call:
game.restorePlayerState(Entity player)This updates specific necessary components to the saved values.
Restoring the player state can be called in any level to check for a saved player, as if there is no stored PlayerSnapshot then the function does nothing.
Currently no tests are available for this system.
Manual testing needs to be employed:
- Pickup items, take damage and collect gold.
- Change to the CyclopsMinigame (
cyclopsMinigame load- in terminal) - Complete minigame (or switch back to Level Screens)
- See if the items, health, and gold are the same as in the previous level
Entities and Components
Input Handling
Arrow Selection Wheel Arrow Selection Wheel — Sprint 3