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★ 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
SecurityErrorwhen the player blocks site data (often by blocking cookies) and onfile:anddata: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 handleonblockedand close the database inonversionchange.openSaveDbcloses it and calls youronVersionChange, 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.
- Write the current version on every save. Upgrades are one-way: once a save is migrated and written, the old build cannot read it.
- Keep a bounded window.
minLoadableis 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. - 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.
- Validate after migrating, against the current shape only.
loadSavetakes avalidatefunction shaped like a Zod.safeParse()
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- 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 запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…