feat: New theme + wire price adjustement

This commit is contained in:
gauvainboiche
2026-10-08 12:25:45 +02:00
parent aa9721ac2a
commit 1734487f1e
19 changed files with 348 additions and 88 deletions
+26 -11
View File
@@ -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) {