@zaisma/cli 0.43.0 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/skill/SKILL.md +97 -0
- package/skill/references/developer-api.md +1965 -0
- package/skill/references/errors.md +341 -0
- package/skill/references/game-server.md +599 -0
- package/skill/references/loading.md +29 -0
- package/skill/references/multiplayer.md +37 -0
- package/skill/references/naming.md +449 -0
- package/skill/references/phones.md +32 -0
- package/skill/references/saves.md +30 -0
- package/skill/references/sdk.md +2383 -0
- package/zaisma.mjs +116 -3
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Saves
|
|
2
|
+
|
|
3
|
+
Open this when the game keeps progress.
|
|
4
|
+
|
|
5
|
+
## What Zaisma does
|
|
6
|
+
|
|
7
|
+
Cloud saves need no code. The game saves in the browser as it always would, in `localStorage` or IndexedDB; for a signed-in player, Zaisma mirrors that to their account and puts it back before the game starts on any device. Guests' progress stays in their browser. A game turns cloud saves on or off with `update_game`, `cloud_saves_enabled`.
|
|
8
|
+
|
|
9
|
+
Zaisma keeps up to 5 earlier versions of each player's save: about once an hour while they play, and whenever progress was about to be lost (another device's progress replacing it, a save that shrank to under half). The developer and their AI read, change, reset and restore any player's save with `get_save`, `change_save`, `reset_save` and `restore_save_copy`.
|
|
10
|
+
|
|
11
|
+
## When to save
|
|
12
|
+
|
|
13
|
+
- **At the moments a player would be upset to lose:** finishing a level, buying or earning something, changing settings, reaching a checkpoint.
|
|
14
|
+
- **When the game is hidden or closing:** on `visibilitychange` when `document.hidden`, and on `pagehide`. Phones close background tabs without warning.
|
|
15
|
+
- **Not every frame.** Writing storage many times a second slows the game and adds nothing.
|
|
16
|
+
|
|
17
|
+
## What goes in a save
|
|
18
|
+
|
|
19
|
+
- **Progress and settings, not the world.** Unlocked levels, inventory, currency, options, the current checkpoint. Not every enemy's position, and nothing the game can rebuild.
|
|
20
|
+
- **A version number in it.** Store `saveFormatVersion: 1` (or similar) beside the data, and upgrade older saves when the game loads them, so an update never breaks a player's progress.
|
|
21
|
+
- **Small.** A save is up to 5 MB (`save_too_big`). Keep big caches out of it: IndexedDB databases with "cache" in their name are left out of saves.
|
|
22
|
+
- **Plain values.** `localStorage` holds text; keep the save's shape simple enough to read back after the game changes.
|
|
23
|
+
|
|
24
|
+
## Online games
|
|
25
|
+
|
|
26
|
+
What decides a match (scores, items won, rank) belongs on the game server and in its database, not in the player's browser save, which the player controls. Purchases come from Zaisma's records (`Zaisma.items.owns()`, `Zaisma.items.owned()`), never from a save.
|
|
27
|
+
|
|
28
|
+
## In the game
|
|
29
|
+
|
|
30
|
+
A game that draws its own save screens uses `Zaisma.saves`: `listCopies()`, `getCopy(saveCopyId)` and `restoreCopy(saveCopyId)` reach the player's earlier versions, `on("conflict")` hears when two devices' progress met and which one won, and `on("developerChange")` hears when the developer changed the save. `Zaisma.player.offerAccount()` picks the moment to ask a guest to make an account and keep their progress, like after their first win.
|