Add the Sokko TCG collectible card mini-game

Add the server-backed card game: Discord login, recharging pack openings,
album, trades, gifts, stardust shop, campaign codes and its administration,
stored in SQLite and disabled in production until configured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-05 17:47:35 +01:00
parent 243465720f
commit 5ce35cd7ba
193 changed files with 12159 additions and 28 deletions

View file

@ -0,0 +1,36 @@
// Rôle : garde une copie locale remplaçable de la collection pour la consultation hors connexion.
const DB_NAME = "sokkog-nebula-cards";
const STORE = "snapshots";
// Format de l'état mis en cache : une copie d'un autre format est ignorée (l'état serveur a changé de forme).
const SNAPSHOT_FORMAT = 2;
function openCache() {
return new Promise((resolve, reject) => {
const request = indexedDB.open(DB_NAME, 1);
request.onupgradeneeded = () => request.result.createObjectStore(STORE, { keyPath: "playerId" });
request.onsuccess = () => resolve(request.result);
request.onerror = () => reject(request.error);
});
}
async function transact(mode, callback) {
const database = await openCache();
return new Promise((resolve, reject) => {
const transaction = database.transaction(STORE, mode);
const request = callback(transaction.objectStore(STORE));
request.onsuccess = () => resolve(request.result);
request.onerror = () => reject(request.error);
transaction.oncomplete = () => database.close();
transaction.onabort = () => reject(transaction.error);
});
}
export function writeCardsCache(state, catalog) {
if (!state?.player?.id) return Promise.resolve();
return transact("readwrite", (store) => store.put({ playerId: state.player.id, format: SNAPSHOT_FORMAT, savedAt: Date.now(), state, catalog }));
}
export async function readLatestCardsCache() {
const entries = await transact("readonly", (store) => store.getAll());
return entries.filter((entry) => entry.format === SNAPSHOT_FORMAT).sort((left, right) => right.savedAt - left.savedAt)[0] || null;
}