Skip to content

@web-engine-dev/save

Save/load system with serialization, save slots, auto-save, and cloud integration.

Features

  • Save Slots: Multiple save game slots
  • Auto-Save: Automatic periodic saving
  • Serialization: ECS world serialization
  • Cloud Sync: Optional cloud save support
  • Compression: Compressed save files
  • Validation: Save file integrity checking

Installation

bash
npm install @web-engine-dev/save
# or
pnpm add @web-engine-dev/save

Quick Start

typescript
import { SaveManager, SaveSlot } from '@web-engine-dev/save';

// Create save manager
const saves = new SaveManager({
  maxSlots: 10,
  autoSave: true,
  autoSaveInterval: 60000, // 1 minute
});

// Save game
await saves.save('slot1', {
  player: serializePlayer(),
  world: serializeWorld(),
  progress: gameProgress,
});

// Load game
const data = await saves.load('slot1');
restorePlayer(data.player);
restoreWorld(data.world);

// List saves
const slots = await saves.list();

API Overview

Save Manager

MethodDescription
save(slot, data)Save to slot
load(slot)Load from slot
delete(slot)Delete save slot
list()List all save slots
exists(slot)Check if slot exists
getMetadata(slot)Get save metadata

Save Slot Metadata

typescript
const slots = await saves.list();
for (const slot of slots) {
  console.log(slot.name);
  console.log(slot.timestamp);
  console.log(slot.playtime);
  console.log(slot.thumbnail);
}

Auto-Save

typescript
const saves = new SaveManager({
  autoSave: true,
  autoSaveInterval: 60000,
  autoSaveSlot: 'autosave',
  maxAutoSaves: 3, // Rotating autosaves
});

// Trigger manual autosave
saves.triggerAutoSave();

// Disable temporarily
saves.pauseAutoSave();
saves.resumeAutoSave();

Cloud Sync

typescript
const saves = new SaveManager({
  cloudProvider: new CloudSaveProvider({
    apiUrl: 'https://api.game.com/saves',
  }),
  syncOnSave: true,
  syncOnLoad: true,
});

// Manual sync
await saves.syncToCloud('slot1');
await saves.syncFromCloud('slot1');

ECS Integration

typescript
import { WorldSerializer } from '@web-engine-dev/save';

const serializer = new WorldSerializer(world, {
  include: [Player, Inventory, Progress],
  exclude: [Particle, Temporary],
});

// Serialize
const data = serializer.serialize();

// Deserialize
serializer.deserialize(data);

Proprietary software. All rights reserved.