Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

save-systems

БесплатноБез исполняемых скриптовНе проверен

Engine-neutral save and load with Godot and Python code: what to serialize, slots and autosave, atomic writes and versioned migration. Use for save/load or a…

gamedev-skillsот gamedev-skills★ 12 656 звёзд на GitHub

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

Save systems

A save file is a serialized snapshot of game state that must survive crashes, restarts and patches. The hard parts are choosing what to save, writing it so a crash mid-save cannot destroy it, and reading old saves after an update. This skill owns the file: format, writes, versioning, slots and location. Genre skills decide what goes in it.

When to use

  • Persisting progress: stats, inventory ids, world flags, settings, positions, seeds.
  • Save slots, quicksave, autosave, crash-safe writes, backups.
  • Old saves failing after a code or content change.

Not this skill: Roblox cloud persistence (roblox-datastores), the data model itself (godot-resources, unity-scriptableobjects), rebinding data shape (input-systems), save screens and rollback in a visual novel (visual-novel).

Core workflow

  1. Find what exists. Grep for the current save code (FileAccess, ConfigFile, ResourceSaver, PlayerPrefs, SaveGameToSlot, persistentDataPath) and any shipped saves. If players already have saves, every change below needs a migration.
  2. Save data, not objects. Ids, numbers, flags and the RNG seed; rebuild nodes and objects from that data on load. Live references and node paths do not survive a refactor.
  3. Stamp an integer version in every save from the first release.
  4. Start with JSON (readable, diffable, easy to migrate); move to binary only for size or speed you have measured.
  5. Write atomically: temp file, keep the previous save as .bak, rename into place.
  6. Load defensively: parse, read version, refuse newer saves, migrate older ones step by step, validate, then apply. Fall back to the backup on failure and tell the player.
  7. Autosave at safe boundaries (checkpoint, level change), throttled, into its own slot.
  8. Run the checks below, then ask the user for the quit-and-relaunch test.

Patterns

1. State as plain data

func capture_state() -> Dictionary:
    return {
        "version": SAVE_VERSION,
        "player": { "hp": player.hp, "pos": [player.position.x, player.position.y] },
        "inventory": player.inventory.to_array(),  # ids + counts, not Item nodes
        "flags": world.flags,
        "seed": world.seed,                        # regenerate procedural content
    }

func apply_state(data: Dictionary) -> void:        # rebuild from data; no live references
    player.hp = int(data["player"]["hp"])
    player.position = Vector2(data["player"]["pos"][0], data["player"]["pos"][1])
    player.inventory.from_array(data["inventory"])
    world.flags = data["flags"]

2. Atomic, crash-safe write (temp + rename)

# Godot 4.7. Write a temp file, keep the previous save as .bak, then rename.
func save_atomic(path: String, data: Dictionary) -> Error:
    var tmp := path + ".tmp"
    var f := FileAccess.open(tmp, FileAccess.WRITE)
    if f == null:
        return FileAccess.get_open_error()       # disk full, read-only, no permission...
    if not f.store_string(JSON.stringify(data)):
        return ERR_FILE_CANT_WRITE
    f.close()                                    # flushes Godot's buffer to the OS
    if FileAccess.file_exists(path):
        DirAccess.rename_absolute(path, path + ".bak")   # keep the last good save
    return DirAccess.rename_absolute(tmp, path)

func load_save(path: String) -> Dictionary:      # empty = nothing loadable
    for p in [path, path + ".bak"]:              # .bak covers a crash between renames
        if FileAccess.file_exists(p):
            var data = JSON.parse_string(FileAccess.get_file_as_string(p))
            if data is Dictionary and data.has("version"):
                data["version"] = int(data["version"])   # JSON numbers load as float
                return data
    return {}
# WRONG: opening `path` directly and writing in place — a crash mid-write leaves a
# truncated, unloadable save and destroys the player's progress.

A crash leaves the old save, the new one, or (between the two renames) only the .bak, which the loader tries next. rename() replaces the target atomically on POSIX within one volume, but Godot's Windows rename_absolute deletes the target and then moves, so Windows relies on the .bak as well. Neither flush() nor close() calls fsync, so a power cut right after a save can still lose the newest file. Check every returned Error and tell the player when a save fails.

3. Versioned load with migration

SAVE_VERSION = 3

def load_save(raw_bytes):
    data = parse(raw_bytes)                  # JSON/binary -> dict
    v = int(data.get("version", 1))          # no field = the first shipped schema
    if v > SAVE_VERSION:
        raise NewerSaveError(v)              # save is from a newer build; refuse
    while v < SAVE_VERSION:                   # apply migrations in order, v -> v+1
        data = MIGRATIONS[v](data)
        v += 1
        data["version"] = v
    validate(data)
Полный SKILL.md на GitHub

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

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

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

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

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

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

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

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

references/versioning-and-migration.md

FAQ

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

Engine-neutral save and load with Godot and Python code: what to serialize, slots and autosave, atomic writes and versioned migration. Use for save/load or a continue button, or saves that corrupt after a crash or break after a patch. Not for Roblox DataStores (`roblox-datastores`), data assets (`godot-resources`, `unity-scriptableobjects`) or genre save screens (`rpg`, `visual-novel`).

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

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

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

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

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

Сравнить save-systems с