Skip to main content

Module storage

Module storage 

Source
Expand description

Files of a game on the player’s computer: save slots, persistent settings and a small file system API. Everything lives under the game’s data folder (set by the host: %APPDATA%/<game> for a built game, <project>/.kvas/data while playing in the editor), so a script cannot touch other files by accident. external reads and writes anywhere, on purpose.

use kvas_engine::storage::Storage;
let dir = std::env::temp_dir().join(format!("kvas-storage-doc-{}", std::process::id()));
let s = Storage::new(&dir);
s.save("slot1", "Chapter 2", &serde_json::json!({"hp": 3})).unwrap();
assert_eq!(s.load("slot1").unwrap()["hp"], 3);
assert_eq!(s.slots()[0].title, "Chapter 2");
s.set_setting("volume", serde_json::json!(0.5)).unwrap();
assert_eq!(s.setting("volume"), Some(serde_json::json!(0.5)));
let _ = std::fs::remove_dir_all(dir);

Modules§

external
Unrestricted access to the computer’s file system (any absolute path). Use for tools, mods and import/export; prefer Storage for game data.

Structs§

SaveInfo
One save slot as listed by Storage::slots.
Storage
The game’s data folder.