Command Palette

Search for a command to run...

Назад к скиллам
скилл № 49466

game-save-load

Saving and loading a browser game's progress: where the save lives (browser storage or the server), a versioned save format with migrations and validation…

БесплатноЗапускает вложенные скрипты
fcsouzaот fcsouza★ 29 звёзд на GitHub

Установить game-save-load в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Game save and load

Target stack: browser client, Bun server, Postgres through Drizzle 0.45, Redis. Database setup and migrations come from postgres-game-schema; this skill adds only the save table and the save rules.

Decide where the save lives

The save holds Store it Why
Currency, items, ranked progress, anything another player or the shop cares about Normalized server tables (postgres-game-schema), written by server logic The client is under the player's control. The server decides and stores state; the client sends inputs only.
Single-player progress the player would be upset to lose Server save slot (boilerplate/server-save.ts) plus a local copy Browser storage can be deleted without asking (next section). The server copy also roams between devices.
Settings, key bindings, a guest session before sign-in Browser only (boilerplate/browser-save-store.ts) Losing it costs little.

Rules that follow from the table:

  • A server save slot stores state the server does not need to trust. Never accept currency, items or rewards inside an uploaded save; the server computes those itself. Keep them out of the payload, so the slot never becomes one JSON blob for all game state.
  • Redis is not the save of record. With RDB snapshots alone Redis can lose the last minutes of writes; with AOF at the default fsync of every second, about one second. Write durable progress to Postgres. Redis holds live session state (redis-game-patterns).
  • The player id on a server save comes from the session (betterauth-integration), never from the request body.
  • Client tamper protection (obfuscation, signed saves) does not replace this design. For an offline single-player game, accept that a local save can be edited.

Browser storage

  • Use IndexedDB for saves. Not localStorage: it is synchronous and blocks the main thread, holds strings only, is capped at about 5 MiB per origin, and does not exist in workers.
  • Browser storage is best-effort. Under storage pressure the browser evicts the least recently used origins, and it deletes all of an origin's data at once (IndexedDB, Cache API and the rest). A backup slot in the same origin dies with the main slot.
  • With cross-site tracking prevention on, Safari deletes all script-written storage of a site after seven days of browser use with no click or tap on that site. A web app added to the home screen keeps its own counter.
  • Call navigator.storage.persist() when the player first saves, inside the click handler of the save button. Chrome grants or refuses by engagement without a prompt; Firefox shows a permission prompt. A persistent origin is not evicted under pressure.
  • Quotas differ: Chromium allows up to 60% of the disk per origin; Firefox best-effort storage, 10% of the disk or 10 GiB per site group; Safari about 60% for browser apps and about 15% for embedded web views. Plan saves in kilobytes, not gigabytes.
  • Every write can throw QuotaExceededError. Catch it, tell the player, and offer to delete old slots or export the save.
  • localStorage access throws SecurityError when the player blocks site data (often by blocking cookies) and on file: and data: origins. Wrap it if you use it for settings.
  • In private browsing, localStorage is cleared when the last private tab closes and IndexedDB lives in memory. Tell the player progress will not survive; signing in and saving to the server is the fix.
  • IndexedDB store and index changes happen only in onupgradeneeded. A tab still on the old version blocks the upgrade until it closes its connection, so handle onblocked and close the database in onversionchange. openSaveDb closes it and calls your onVersionChange, so the game can tell the player to reload the tab. Store layout versions and save payload versions are separate numbers.
  • An export file is optional. showSaveFilePicker() needs HTTPS and a click, and MDN marks it experimental and not Baseline: check the compatibility table and fall back to a download link.

Save format

Copy boilerplate/save-envelope.ts. Each save is an envelope: format, version, savedAt, playedMs, sha256, and the payload as a JSON string. loadSave reads an envelope; migrateAndValidate runs the same version window, migrations and validation on bare data, such as a server row.

  1. Write the current version on every save. Upgrades are one-way: once a save is migrated and written, the old build cannot read it.
  2. Keep a bounded window. minLoadable is the oldest version this build migrates; older saves get a clear "too old" message, not a guess. Raise it when old migrations cost more than they are worth.
  3. Migrations go from version n to n + 1, one function each. A save at version 2 in a build at version 5 runs steps 2, 3 and 4 in order. Never edit a shipped step; add a new one.
  4. Validate after migrating, against the current shape only. loadSave takes a validate function shaped like a Zod .safeParse()
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • boilerplate/browser-save-store.ts
  • boilerplate/save-envelope.ts
  • boilerplate/server-save.ts
  • references/sources.md

FAQ

Что делает скилл game-save-load?

Saving and loading a browser game's progress: where the save lives (browser storage or the server), a versioned save format with migrations and validation, atomic writes, slots and backups, autosave, cross-device conflicts and corruption checks. Use when a game needs save slots, autosave or cloud saves, when players lose progress or saves break after a patch, or when two devices overwrite each other's progress.

Как установить скилл game-save-load?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл game-save-load запускает скрипты?

Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.

Похожие скиллы

Сравнить game-save-load с