feat: New theme + wire price adjustement
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
// Persistence in browser cookies.
|
||||
//
|
||||
// A cookie holds ~4 KB, so a save is base64url-encoded and split in chunks:
|
||||
// ic_save_<theme>_n -> number of chunks
|
||||
// ic_save_<theme>_0.. -> the chunks
|
||||
// Each theme has its own save slot. Preferences (theme, language) are stored
|
||||
// in a single small cookie.
|
||||
// ic_game_n -> number of chunks
|
||||
// ic_game_0.. -> the chunks
|
||||
// There is ONE game, shared by every theme (a theme is only a skin).
|
||||
// Preferences (theme, language) are stored in a single small cookie.
|
||||
|
||||
import { readCookie, removeCookie, writeCookie } from './cookies.js';
|
||||
|
||||
const CHUNK_SIZE = 3000;
|
||||
const MAX_CHUNKS = 6;
|
||||
const PREFS_KEY = 'ic_prefs';
|
||||
const saveKey = (themeId) => `ic_save_${themeId}`;
|
||||
const GAME_KEY = 'ic_game';
|
||||
const legacyKey = (themeId) => `ic_save_${themeId}`; // v1: one save per theme
|
||||
|
||||
// ------------------------------------------------------------------ encoding
|
||||
|
||||
@@ -79,16 +80,30 @@ export function cookiesAvailable() {
|
||||
}
|
||||
|
||||
/** Throws if the save does not fit in cookies. */
|
||||
export function saveGameText(themeId, text) {
|
||||
writeChunked(saveKey(themeId), text);
|
||||
export function saveGameText(text) {
|
||||
writeChunked(GAME_KEY, text);
|
||||
}
|
||||
|
||||
export function loadGameText(themeId) {
|
||||
return readChunked(saveKey(themeId));
|
||||
export function loadGameText() {
|
||||
return readChunked(GAME_KEY);
|
||||
}
|
||||
|
||||
export function deleteGame(themeId) {
|
||||
removeChunked(saveKey(themeId));
|
||||
export function deleteGame() {
|
||||
removeChunked(GAME_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves from the first version (one per theme). Returns their texts and
|
||||
* removes those cookies, so the caller can merge them into the shared game.
|
||||
*/
|
||||
export function takeLegacySaves(themeIds) {
|
||||
const texts = [];
|
||||
for (const id of themeIds) {
|
||||
const text = readChunked(legacyKey(id));
|
||||
if (text) texts.push(text);
|
||||
removeChunked(legacyKey(id));
|
||||
}
|
||||
return texts;
|
||||
}
|
||||
|
||||
export function savePrefs(prefs) {
|
||||
|
||||
Reference in New Issue
Block a user