npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@yagejs/save

v0.7.0

Published

Save and load game state for YAGE

Downloads

371

Readme

@yagejs/save

Persistence for the YAGE 2D game engine — typed reactive stores plus a snapshot path for full-scene quicksave.

Install

npm install @yagejs/save

Stores + Save instance (primary path)

Most save data is intentional — settings, save slots, world facts, progression. Define typed stores at module scope, construct one Save instance, register it via the plugin.

import { Engine, createStore, createRecord, createSet } from "@yagejs/core";
import {
  createSave, SavePlugin, localStorageAdapter,
} from "@yagejs/save";

interface RunData { chapter: number; position: { x: number; y: number } }

// Compound store — bundles many typed leaves into one save document.
const game = createStore((s) => ({
  run: s.record<RunData>({
    default: () => ({ chapter: 1, position: { x: 0, y: 0 } }),
  }),
  opened: s.set<string>(),
}));

// Leaf factory for one-offs (different save target — separate document).
const settings = createRecord<{ music: number; sfx: number }>({
  default: () => ({ music: 0.8, sfx: 1.0 }),
});

const save = createSave({ adapter: localStorageAdapter() });

await Promise.all([
  save.restore("saves", game),
  save.restore("settings", settings),
]);
save.autoPersist("saves", game);
save.autoPersist("settings", settings);

const engine = new Engine();
engine.use(new SavePlugin({ save }));

In-game components resolve the registered Save through SaveServiceKey:

import { SaveServiceKey } from "@yagejs/save";

class CheckpointOnRest extends Component {
  setup() {
    this.entity.on(Rested, async () => {
      const save = this.use(SaveServiceKey);
      await save.saveSlot("saves", "auto", game);
    });
  }
}

Save slots with typed metadata:

interface RunMeta { location: string; playtime: number }
await save.saveSlot<unknown, RunMeta>("saves", "manual-1", game, {
  metadata: { /* … */ },
});
const slots = await save.listSlots<RunMeta>("saves");
await save.loadSlot("saves", "manual-1", game);

Snapshot path (advanced)

Full-scene serialization via @serializable decorators. Use for quicksave that captures every entity, component, and active process.

import { serializable } from "@yagejs/core";
import { SnapshotPlugin, SnapshotServiceKey } from "@yagejs/save";

@serializable
class Player extends Entity { /* ... */ }

engine.use(new SnapshotPlugin());
const snap = engine.context.resolve(SnapshotServiceKey);
snap.saveSnapshot("slot-1");
await snap.loadSnapshot("slot-1");

What's in the box

  • State factories — compound createStore + leaf createRecord, createValue, createSet, createMap, createCounter, createList (live in @yagejs/core).
  • SavecreateSave({ adapter }) with persist(id, thing), restore(id, thing, opts?), saveSlot(id, slot, thing, opts?), loadSlot(id, slot, thing, opts?), listSlots(id), deleteSlot(id, slot), autoPersist(id, thing, opts?).
  • AdapterslocalStorageAdapter, memoryAdapter. Implement SaveAdapter for IndexedDB, files, cloud, etc.
  • CodecsjsonCodec, setCodec, mapCodec, dateCodec.
  • Snapshot systemSnapshotPlugin, SnapshotService, @serializable decorator (in @yagejs/core), snapshot contributors.

Docs

Full documentation at yage.dev.

License

MIT