Skip to content

EN Save Settings Lifecycle

Cavanshirpro edited this page Sep 20, 2026 · 2 revisions

Save, Settings and Lifecycle — LeoMiniGames v0.7.0

LeoMiniGames deliberately separates preferences, durable gameplay state, statistics/achievements and lifecycle events. Mixing them is a common source of lost progress and migration bugs.

GameSettings / QSettings

Global application preferences use host SettingsManager/QSettings. Plugin preferences use GameSettings, which prefixes keys with games/<gameId>/settings/.

Good settings: difficulty preference, SFX/music preference, sensitivity, hints, control layout, particles, camera shake. Not settings: level, coins, inventory, campaign/quest/world state, save slots, factory/character progress, high scores or achievements.

GameSave

Durable gameplay state belongs to GameSave. Each game is sandboxed under saves/<gameId>/; slot names are restricted tokens. .lmgsave uses the LMGSAVE� magic, a big-endian CBOR-header length, a CBOR header containing identity/version/schema/timestamp/checksum information, then a CBOR map payload.

Writes use QSaveFile for atomic commit. Before replacing a valid primary save, a .bak copy is created. Load verifies magic, game namespace, format, CBOR structure and SHA-256. restoreBackup() validates and restores the backup bytes rather than silently relabeling schema metadata.

Migration

Save migrations are an ordered registered chain. A missing migration fails closed; an old save is not simply relabeled as a new schema. Register migrations before loading a slot that may need them.

Lifecycle

The public external game context is Lifecycle. Relevant boundaries include load/start/pause/resume/background/foreground/save/close/unload. Missing lifecycle handlers are legal for legacy packages.

The host treats background/close/quit as durability boundaries. Application state transitions call lifecycle pause/background/save and GameSave.forceSave() before pausing audio; foreground resumes lifecycle/audio. Game close and application quit include force-save safety nets.

Correct persistence test

Do not consider save support complete because GameSave.set() appears in code. Test:

state change
→ save/autosave/forced lifecycle save
→ bytes committed to disk
→ application/game unload
→ reload slot
→ restore/migrate
→ same gameplay state

Repeat with “close immediately after important action” and background/foreground. Include nested/list/QVariant data that the game actually stores.

Offline progression

Time-based games should persist a trusted-enough timestamp/state basis and compute elapsed offline time in a bounded batch. Do not replay thousands of per-frame QML property updates merely to simulate hours of offline progress.

Canonical sources: docs/SAVE_SYSTEM.md, docs/SETTINGS_SYSTEM.md and lifecycle wiring in src/main.cpp.

Clone this wiki locally