Skip to content

Commit

Permalink
Improve documentation of savegames
Browse files Browse the repository at this point in the history
- Use java instead of text for the syntax highlighting in fenced code
  blocks
- Fix indentation in one code snippet
- Remove trailing whitespaces
  • Loading branch information
Josef-Friedrich authored and nightm4re94 committed Apr 23, 2024
1 parent 1478fe5 commit 11ed971
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions savegames.md
Expand Up @@ -6,13 +6,13 @@ description: How to save and load player progress

### XML savegames

Let's have a look at an example where we store and load savegames using XML files.
Let's have a look at an example where we store and load savegames using XML files.
We need one class representing the savegame, as well as one method for saving and one method for loading the savegame.

Let's have a look at an example used in a legacy version of _Dr. Lepus._
Let's have a look at an example used in a legacy version of _Dr. Lepus._
This is what the `SaveGame` itself would look like:

```text
```java
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
Expand Down Expand Up @@ -119,10 +119,10 @@ public class SaveGame {
}
```

We can save the game state to the system user's directory with the `saveGame()`-method. Make sure that things like the player inventory and active upgrades / skills / traits are also serializable.
We can save the game state to the system user's directory with the `saveGame()`-method. Make sure that things like the player inventory and active upgrades / skills / traits are also serializable.

```text
public static void saveGame() {
```java
public static void saveGame() {
Level level = GameOrchestrator.getCurrentLevel();
if (level == null) {
return;
Expand All @@ -136,7 +136,7 @@ public static void saveGame() {
SaveGame saveGame = new SaveGame(level.getChapter(), level.getPart(), GameOrchestrator.getCurrentSpawn(), SAVE_FILE_NAME);
saveGame.setUpgrades(Upgrades.save());
saveGame.setInventory(Lepus.instance().getInventory());

String dir = System.getProperty("user.home") + "/.drlepus/savefiles/";
File dirFile = new File(dir);
dirFile.mkdirs();
Expand All @@ -147,7 +147,7 @@ public static void saveGame() {

To load the savegame, we will call `loadSavedGameFile()`.

```text
```java
public static void loadSavedGameFile() {
String path = System.getProperty("user.home") + "/.drlepus/savefiles/" + SAVE_FILE_NAME + ".xml";
final SaveGame saveGame = XmlUtilities.read(SaveGame.class, Resources.getLocation(path));
Expand All @@ -163,4 +163,3 @@ To load the savegame, we will call `loadSavedGameFile()`.
```

Remember, this is just one specific example how to load and save player progress. You can pick whatever information you like, in whichever format you like, and wherever you would like to store it. Get creative!

0 comments on commit 11ed971

Please sign in to comment.