Open <name>.json (name: 1–64 of a-z 0-9 -). A file that cannot be
parsed or fails validate is renamed <name>.json.bad-<timestamp> and
defaults is used. Writes go to a temporary file, then a rename. Disposal
(and stopping the plugin) flushes first.
The file is read synchronously on creation; debounceMs defaults to
300. Files are created with mode 0600. invalid for a bad name.
The plugin remembers whether to resume and the last ten files across
restarts. json reads settings.json from the data directory at once
(or uses defaults when it is missing or fails validate); save
replaces the value and writes the file 300 ms later, and stopping the
plugin writes a pending save first.
type Settings = { resume: boolean; recent: string[] };
const store = plugin.storage.json<Settings>("settings", {
defaults: { resume: true, recent: [] },
validate: (v): v is Settings =>
typeof v === "object" && v !== null && typeof (v as Settings).resume === "boolean",
});
// Only `save` writes: changing `store.value` in place is not saved.
store.save({ ...store.value, recent: [path, ...store.value.recent].slice(0, 10) });
ReadonlysessionValues the player keeps in its memory for this plugin until the player quits: they survive a restart of the plugin's process (reload, upgrade, crash, failed start) but not the player. See SessionStorage.
plugin.storage: JSON settings files.Remarks
Two kinds of storage, both private to the plugin. Storage.json keeps settings in JSON files in the plugin's data directory: they last across player restarts and upgrades, and are written by the plugin's own process. Storage.session keeps values in the player's memory for one player run: they survive a restart of the plugin's process but not of the player. Secrets belong in Secrets, never in either.
Example: Keep a setting across restarts and a queue for this run
The plugin's step size survives a restart of the player; its work queue survives a reload of the plugin but starts empty with the next player run. The JSON store reads its file at once and writes it shortly after each
save; session values live in the player process.See
Store a plugin's data, Open a tool window and remember its state
Since
1.0.0