본문으로 건너뛰기
cccskills
무료GitHub에 공개

pixi-vn-saves

Use when implementing save/load in a Pixi'VN game — Game.exportGameState()/restoreGameState()/jsonToGameState(), what the exported GameState contains, and how to persist it (save slots, quick-save, auto-save-on-refresh, downloadable JSON). Load this before writing any save-file, save-slot, or "continue game" feature.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

실행 점수 미검증

설치 방법 보기

포함된 파일(1)

  • SKILL.md5.8 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Pixi'VN Saves: exporting, restoring, and persisting game state

Official docs: pixi-vn.com/start/save.

When to use this skill

Use this skill whenever a task involves saving/loading the game: a save-file format, save slots, a quick-save shortcut, "continue where I left off" after a page refresh, or exporting/importing a save as a file. This skill does not cover the module-level details of what's inside a save (storage variables — pixi-vn-storage; canvas element state — pixi-vn-canvas; step/backlog history — pixi-vn-history) — only the save/load flow itself and how those pieces fit together.

The core trio

import { Game } from "@drincs/pixi-vn";

Game.exportGameState(): GameState
Game.restoreGameState(data: GameState): Promise<void>
Game.jsonToGameState(json: string): GameState
  • Game.exportGameState() returns a plain GameState object — version info plus the current storage, canvas, sound, and history data — suitable for JSON.stringify.
  • Game.restoreGameState(data) restores everything from a previously exported GameState, using whatever navigate function was set via Game.onNavigate/Game.init's navigate option — it no longer takes a navigate function as a second argument.
  • Game.jsonToGameState(json) just parses a JSON string back into a GameState — a thin wrapper around JSON.parse with the right type, for symmetry with exportGameState.
const json = JSON.stringify(Game.exportGameState());
// ... later, possibly after a page reload ...
await Game.restoreGameState(Game.jsonToGameState(json));

What's inside a GameState

A GameState bundles every module's current state: storage variables, the canvas's saved element/layer state (if the canvas was initialized), sound's channel/media state, and go-back history (capped by stepHistory.stepLimitSaved, default 20 — see pixi-vn-history for what that limit means for how far a player can go back after loading). Game.exportGameState/ restoreGameState is the layer application code should use — there's no need to go through any individual module directly for a full game save.

Real-world persistence convention (official React template)

Game.exportGameState() says nothing about where that payload lives or what metadata a save-slot UI needs (title, timestamp, thumbnail). That part is entirely up to the app. The official React+TS template (npm create pixi-vn@latest, source at src/models/GameSaveData.ts / src/lib/utils/save-utility.ts) shows one concrete way to close that gap — this is the template's convention, not a library requirement:

interface GameSaveData {
  saveData: GameState; // the raw Game.exportGameState() output
  gameVersion: string;
  date: Date;
  name: string;
  image?: string; // thumbnail, e.g. canvas.extractImage() — see pixi-vn-canvas
}

function createGameSave(options?: { image?: string; name?: string }): GameSaveData {
  return {
    saveData: Game.exportGameState(),
    gameVersion: __APP_VERSION__,
    date: new Date(),
    name: options?.name ?? "",
    image: options?.image,
  };
}

async function loadSave(saveData: GameSaveData) {
  await Game.restoreGameState(saveData.saveData);
}

The pattern: wrap exportGameState()'s return value in an app-level object carrying save metadata, and pass the inner saveData field back into restoreGameState() when loading.

From there, the template persists that wrapped GameSaveData object (not the raw game state alone) through several concrete mechanisms — illustrative, not exhaustive:

  • Numbered save slots via IndexedDB (saveGameToIndexDB/getSaveFromIndexDB/ deleteSaveFromIndexDB), auto-incrementing from 0.
  • Quick save slots, also via IndexedDB (quickSaveGameToIndexDB), reserved to a fixed negative-id range below the numbered saves (e.g. ids -2..-7 for 6 slots) so they never collide with manual saves. Each quick-save fills the first empty slot, then cycles by overwriting the least-recently-used slot once all slots are full.
  • An "auto exit save" (addAutoExitSave, paired with a useAutoSaveOnPageClose hook bound to the beforeunload and visibilitychange events) stringified straight into localStorage under its own key — not through IndexedDB — so an accidental tab close or reload doesn't lose progress.
  • A "Continue" button: getLastSaveFromIndexDB powers a main-menu "Continue" action by comparing the latest numbered IndexedDB save against the auto exit save and returning whichever is newer (synthesizing id -1 for the auto exit save for that comparison) — null if neither exists, to disable the button; the result feeds straight into loadSave.
  • A downloadable/importable JSON file (downloadGameSave/loadGameSaveFromFile) for backing up or sharing a save outside the app.

None of this is prescribed by @drincs/pixi-vn — treat it as one worked example of gluing exportGameState/restoreGameState to a real persistence layer, not the only way to do it.

Related skills

  • pixi-vn — Game.init/Game.onNavigate and the rest of the top-level Game API.
  • pixi-vn-storage — variables/flags/stored classes that end up inside a save, and reserved keys.
  • pixi-vn-history — stepHistory.stepLimitSaved and what survives a save/load for "go back".
  • pixi-vn-canvas — canvas.extractImage() for save thumbnails, and what canvas state gets saved.
  • pixi-vn-migration — renames affecting this area (getSaveData → Game.exportGameState, etc.).

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

pixi-vn

무료

Index and entry point of the Pixi'VN skill set — start here for any task on a @drincs/pixi-vn project, then follow the skill map to the right skill (narration, canvas, characters, assets, sound, storage, saves, history, ui, minigames, testing, migration). Use when setting up a new or existing project, wiring the main.ts entry point, or calling the top-level Game API (Game.init, Game.start, Game.onEnd, Game.addOnError, Game.onNavigate, Game.clear) — every Pixi'VN project needs this before touching canvas, narration, sound, storage, or history.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

DRincs-Productions/pixi-vn1542026년 10월 22일 업데이트

Use when adding, organizing, registering, or loading non-code files (images, audio, video) in a Pixi'VN project — local assets processed by PixiJS AssetPack vs. online/remote-hosted assets, the AssetsManifest/bundle/alias system, where to edit the manifest for each case, and when to load bundles (at startup, in the background, per-label, per-route). Load this before writing any code that references an image/sound/video path directly, or before adding entries to a manifest.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

DRincs-Productions/pixi-vn1542026년 10월 22일 업데이트

Use when adding, moving, or removing images, sprites, text, or video on the Pixi'VN game canvas, or when applying or creating transitions (dissolve, fade, move, zoom, push, wipe, iris, split, flash, blur, pixelate, or a custom one built on `canvas.animate`/`filters.animate`), shake/animation effects, or ticker-based animations built on PixiJS. Covers the `canvas` singleton exported from `@drincs/pixi-vn`. For UI layers (HTML or PixiJS) mounted on top of the canvas, see `pixi-vn-ui` instead.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

DRincs-Productions/pixi-vn1542026년 10월 22일 업데이트

Use when defining visual novel characters for a @drincs/pixi-vn game — creating a character with a name, color, icon and other props, registering it so it can be looked up by id, and referencing it from dialogue/narration. Load this before writing any `CharacterBaseModel` or `RegisteredCharacters` code.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

DRincs-Productions/pixi-vn1542026년 10월 22일 업데이트

Use when implementing "go back" / "rewind" / step-navigation features in a Pixi'VN game, or when you need to read the player-facing dialogue/choice history (e.g. for a backlog or "history log" UI) — covers the History module's `stepHistory` API and the "step" vs "paragraph" goBackMode.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

DRincs-Productions/pixi-vn1542026년 10월 22일 업데이트

Use when upgrading an existing @drincs/pixi-vn project to a newer version, or when a runtime/type error matches a known breaking change. Covers every breaking change between versions with before/after code.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

DRincs-Productions/pixi-vn1542026년 10월 22일 업데이트

DRincs-Productions의 스킬 모두 보기

이 스킬의 문제 신고