Skip to content

Commit

Permalink
feat: new option to not autosave on specific labels
Browse files Browse the repository at this point in the history
  • Loading branch information
liana-p committed Aug 30, 2024
1 parent bdb9f5b commit 8dea6b1
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 3 deletions.
29 changes: 29 additions & 0 deletions docs/features/save-and-load.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ saves:
mode: manual
slots: 10
runOnReload: 'game_reload'
autosaveDisabledOnLabels:
- test_no_autosave
# disabled: true
notifyOnSave: true
```

Then for example in the game code:
Expand Down Expand Up @@ -134,3 +138,28 @@ saves:
Setting the `disabled` option to true in the saves config will remove the continue/load button, and remove the warning about erasing save slots when clicking on new game.

The game will still be saving in the background, but the player won't be able to load the save.

## Save notification

The game automatically adds a notification on screen when autosaving. This can be disabled in the save config:

```yaml
saves:
notifyOnSave: false
```

## Disabling autosave on specific labels

There are cases where you might want your game to _not_ autosave on specific labels. For example if there is a choice in your game that might softlock the player, you might want to prevent the player from autosaving after that choice.

To do that, add the `autosaveDisabledOnLabels` option to the saves config and list all the labels that should _not_ trigger an autosave.

```yaml
saves:
autosaveDisabledOnLabels:
- no_autosave
- dont_save_this_label
- please_dont_save_me
- this_really_shouldnt_be_saved
- no_dont_save_this_label_senpai_yamete_kudasai
```
5 changes: 5 additions & 0 deletions packages/narrat/src/application/saving.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
} from '@/utils/save-helpers';
import { getPlayTime } from '@/utils/time-helpers';
import { error } from '@/utils/error-handling';
import { useNotifications } from '@/stores/notification-store';
import { getCommonConfig } from '@/config';

export function autoSaveGame({
slotId,
Expand All @@ -25,6 +27,9 @@ export function autoSaveGame({
name,
extractedSave: extractSaveData(),
});
if (getCommonConfig().saves.notifyOnSave !== false) {
useNotifications().addNotification('Game Saved');
}
}

export function setupLoadedData(save: ExtractedSave) {
Expand Down
2 changes: 2 additions & 0 deletions packages/narrat/src/config/common-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export const SavesConfigSchema = Type.Object({
slots: Type.Number(),
runOnReload: Type.Optional(Type.String()),
disabled: Type.Optional(Type.Boolean()),
autosaveDisabledOnLabels: Type.Optional(Type.Array(Type.String())),
notifyOnSave: Type.Optional(Type.Boolean()),
});
export type SavesConfig = Static<typeof SavesConfigSchema>;

Expand Down
7 changes: 7 additions & 0 deletions packages/narrat/src/examples/default/config/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ saves:
mode: manual
slots: 10
runOnReload: 'test_label_reload'
autosaveDisabledOnLabels:
- test_no_autosave
# disabled: true
notifyOnSave: true

notifications:
timeOnScreen: 2.5
alsoPrintInDialogue: false

hudStats:
money:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dev_test:
run test_dialog
run test_saves
run test_dialog
run test_conditions
run test_js
run test_arrays
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test_saves:
"hello saves"
jump test_no_autosave
jump test_save_bug
"Let's try a save prompt"
set data.save_test 1
Expand Down Expand Up @@ -36,4 +38,7 @@ test_save_bug_3:
jump test_save_bug_4

test_save_bug_4:
"after jump"
"after jump"

test_no_autosave:
"this label shouldn't autosave"
10 changes: 9 additions & 1 deletion packages/narrat/src/stores/vm-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,15 @@ export const useVM = defineStore('vm', {
}
this.hasJumped = true;
this.setStack(target);
await autoSaveGame({});
const autoSaveDisabledOnLabels =
getCommonConfig().saves.autosaveDisabledOnLabels;
if (
!autoSaveDisabledOnLabels ||
!autoSaveDisabledOnLabels.includes(target.label)
) {
// Don't autosave if we're on a label that's not supposed to
await autoSaveGame({});
}
result = await this.runFrame();
}
if (result === STOP_SIGNAL) {
Expand Down

0 comments on commit 8dea6b1

Please sign in to comment.