/** * The path the site is served under: the editor, the play page, the API and every data file. It * is the folder of the open page, so one build answers at https://nockal.com/feuerwerk/ and at * https://feuerwerk.nockal.com/ alike. Away from a page (Node, the tests) it is the nginx path. */ export const SITE_PATH = sitePath(typeof location === 'undefined' ? undefined : location.pathname); /** The folder of a page path: `/feuerwerk/play.html` and `/feuerwerk/` give `/feuerwerk/`. */ export function sitePath(pagePath: string | undefined): string { if (pagePath === undefined) return '/feuerwerk/'; return pagePath.slice(0, pagePath.lastIndexOf('/') + 1); } /** The API's one entry point. */ export const API_ENDPOINT = `${SITE_PATH}api/index.php`; /** Where the uploaded files of one kind are served, e.g. `dataPath('textures')`. */ export function dataPath(kind: string): string { return `${SITE_PATH}data/${kind}`; } /** The prefix of every `localStorage` key while the editor was called Game Maker. */ const OLD_KEY_PREFIX = 'game-maker.'; const KEY_PREFIX = 'feuerwerk.'; type KeyStore = Pick; /** * Moves what a browser kept under the old name to the new one: settings, panel sizes, folds and * saves survive the rename. A key the new name already has keeps its value. Answers how many moved. */ export function moveOldStoredKeys(storage: KeyStore): number { const old: string[] = []; for (let i = 0; i < storage.length; i++) { const key = storage.key(i); if (key?.startsWith(OLD_KEY_PREFIX)) old.push(key); } let moved = 0; for (const key of old) { const value = storage.getItem(key); const renamed = KEY_PREFIX + key.slice(OLD_KEY_PREFIX.length); if (value !== null && storage.getItem(renamed) === null) { storage.setItem(renamed, value); moved++; } storage.removeItem(key); } return moved; }