wobblyhead hg > minor_monsters
view game/js/storage.js @ 34:83e8b0e0f010 0.10.1
homepage link on splash does not open a new tab anymore
| author | ark |
|---|---|
| date | 2026-10-20 19:54 +0200 |
| parents | 2c4fed8baed9 |
| children |
line wrap: on
line source
// settings kept in the browser (architecture.md, persistence). one // localStorage entry holds all of them, with a format version. every access // is wrapped, so the game still runs when storage is unavailable, for // example in private browsing; settings are then not kept. window.MM = window.MM || {}; MM.storage = (function () { "use strict"; var KEY = "minor_monsters"; var VERSION = 1; var settings = {}; // an entry of another version is ignored and replaced on the next set() try { var entry = JSON.parse(window.localStorage.getItem(KEY)); if (entry && entry.version === VERSION && entry.settings) settings = entry.settings; } catch (e) { settings = {}; } // the stored value of a setting, or fallback when it was never set function get(name, fallback) { return Object.prototype.hasOwnProperty.call(settings, name) ? settings[name] : fallback; } function set(name, value) { settings[name] = value; try { window.localStorage.setItem(KEY, JSON.stringify({ version: VERSION, settings: settings })); } catch (e) { // storage unavailable or full: the setting holds until a reload } } return { get: get, set: set }; })();
