Skip to main content

Module storage

Module storage 

Source
Expand description

Where the mod keeps its data (typed stores by scope, values kept with the world). Where the mod keeps its data — typed values in stores scoped the way web storage is (yog-storage), opened for this mod in the right folder:

ⓘ
use yog_api::storage;

storage::game().set("theme", &theme);              // the install, whatever world
if let Some(world) = storage::world() {            // this world, saved with it
    world.update("visits", |n: &mut u32| *n += 1);
}
storage::session().set("last_screen", &screen);    // while the game runs

Or a value kept for the mod, loaded when first used and saved with the world (WorldData, PlayerData, GameData):

ⓘ
static LABELS: WorldData<Vec<Label>> = WorldData::new("labels");
LABELS.with_mut(|labels| labels.push(label));

What’s kept with the world is written as the world is saved (server::life::Saving: an autosave, /save-all, the server stopping), so it’s saved with the world it belongs to.

Structs§

GameData
A value kept for the install, whatever world (<game>/yog-data/<mod>/game.ydata): written as it changes.
PlayerData
A value kept for each player of the world (<world>/yog-data/<mod>/player/<uuid>.ydata, at its key).
Store
A mod’s store of a scope: values of any Schema type by key, kept in memory and written when it’s flushed. Handles to one store share it.
WorldData
A value kept with the world (<world>/yog-data/<mod>/world.ydata, at its key): its default where there’s none yet; with no world open (a client of another’s server) it’s kept in memory only.

Enums§

Scope
What a store belongs to — under a root: the game’s folder for Scope::Game, the world’s for the rest (see the crate docs).

Functions§

chunk
This mod’s store for chunk cx, cz of dimension dim in the open world.
close_under
Writes and closes every store under root (the world closed: the next one opened reads its own).
dimension
This mod’s store for dimension dim of the open world.
entity
This mod’s store for entity uuid in the open world.
flush_all
Writes every store changed since it was last written; the first failure.
game
This mod’s store for the install, whatever world.
player
This mod’s store for player uuid in the open world.
session
This mod’s session store: kept while the game runs, never written.
world
This mod’s store for the open world.