Skip to content

Saving and Loading

Isaac Robinson edited this page Oct 4, 2023 · 5 revisions

Playing the game

When playing the game saving and loading is automatic! Simply press the start button on the main menu to play and the game will automatically save. When you exit the game the "Load game" button will no longer be grey and pressing that will resume your current saved game. Pressing start again will override your current save file.

Technical Details

We save the current game area using the PlanetScreen.saveGame() method. This writes the current state of all entities and the GameState into .json files. The outline of how this method works is shown in the UML Representation.

The saving is implemented by having a file directory ("save/") that replicates the normal "levels/" file directory. If the game is every trying to load a game area or level it will attempt to load first from the save folder, but if that doesn't exist it will load the regular files from "levels/". The only difference in the actual contents is how entities are stored. In the normal "levels/" folder entities are stored in a folder, with each entity seperately stored. This makes it more readable but is uneccessary for saving, so the entities are all simply stored in a single "entities.json" file.

Saving game state

To save the game state we make use of the SaveableComponent. This is implemented for all entities and allows an easy implementation of saving where we use the EntityService to collate the saved config files and return a single file for the whole game area. The only additional step required is to save the gamestate from the GameStateObserverService. This is a simple map that can just be saved to a .json file.

UML Representation

Here we can see the sequence diagram of saving the game. SequenceSavingLoading

Clone this wiki locally