Skip to content

PlayerSnapshot Saving System

William Kelly edited this page Oct 6, 2026 · 1 revision

Player Snapshot 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

Architecture

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
  }
Loading

Intended Usage

Necessary Entity Components

The PlayerSnapshot functionality works on any Entity that has the following Components:

  • CombatStatsComponent
  • InventoryComponent

With potential for more components to be added.

Usage

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.

Testing Plan

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

Clone this wiki locally