Hide unrevealed Cards pulls and show the odds players really get

Keep a pending opening's cards out of the home highlight and collection until
they are revealed, and refuse transfers meanwhile. Odds now ignore rarities a
pack cannot give. Stable files gain an ETag so card images revalidate instead
of downloading again, and logging out clears the local collection copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-05 18:00:32 +01:00
parent b2e46b1d2a
commit 155187d01f
11 changed files with 167 additions and 26 deletions

View file

@ -2,7 +2,7 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { navigate } from "../../router/hashRouter.js";
import { AdminPanel } from "./admin/AdminPanel.jsx";
import { readLatestCardsCache, writeCardsCache } from "./cardCache.js";
import { clearCardsCache, readLatestCardsCache, writeCardsCache } from "./cardCache.js";
import { devLogin, loadCardsSession, loadCardsState, logoutCards } from "./cardsApi.js";
import { CardsAccount, CardsDashboardLayout } from "./CardsDashboard.jsx";
import { CardsHomePanel } from "./CardsHomePanel.jsx";
@ -61,6 +61,7 @@ export function CardsPage({ siteContent, cardsConfig, playerSection = "", adminM
const session = await loadCardsSession();
if (!active) return;
if (!session.authenticated) {
void clearCardsCache().catch(() => {});
setStatus("anonymous");
return;
}
@ -184,6 +185,7 @@ export function CardsPage({ siteContent, cardsConfig, playerSection = "", adminM
async function logout() {
await logoutCards();
await clearCardsCache().catch(() => {});
setState(null);
setStatus("anonymous");
}

View file

@ -106,7 +106,7 @@ function OpeningOdds({ catalog, opening, collection, content, shopShare }) {
if (collection?.packCategory === "shop") details.push(`${shopShare} % ${content.shopShare} ${collection.name}`);
return <section className="nds-panel nebula-opening-odds" aria-labelledby="nebula-opening-odds-title">
<h3 id="nebula-opening-odds-title">{content.probabilities}</h3>
<ul className="nebula-shop-rates" aria-labelledby="nebula-opening-odds-title">{rarityPercentages(catalog.rarities, weights).map(({ rarity, percent }) => <li key={rarity.id} data-rarity={rarity.id}><span>{rarity.label}</span><strong>{formatPercent(percent)}</strong></li>)}</ul>
<ul className="nebula-shop-rates" aria-labelledby="nebula-opening-odds-title">{rarityPercentages(catalog.rarities, weights, collection?.drawableRarities).map(({ rarity, percent }) => <li key={rarity.id} data-rarity={rarity.id}><span>{rarity.label}</span><strong>{formatPercent(percent)}</strong></li>)}</ul>
{details.length > 0 && <p className="nebula-form-help">{details.join(" · ")}</p>}
</section>;
}

View file

@ -30,6 +30,11 @@ export function writeCardsCache(state, catalog) {
return transact("readwrite", (store) => store.put({ playerId: state.player.id, format: SNAPSHOT_FORMAT, savedAt: Date.now(), state, catalog }));
}
// La copie locale n'appartient qu'au joueur connecté : un autre utilisateur du navigateur ne doit pas la retrouver.
export function clearCardsCache() {
return transact("readwrite", (store) => store.clear());
}
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;

View file

@ -6,9 +6,11 @@ export function recommendedWeights(rarities) {
}
// Pourcentage de chaque rareté pour une carte tirée, dans l'ordre des raretés du catalogue.
export function rarityPercentages(rarities, weights = {}) {
const total = rarities.reduce((sum, rarity) => sum + (Number(weights[rarity.id]) || 0), 0);
return rarities.map((rarity) => ({ rarity, weight: Number(weights[rarity.id]) || 0, percent: total ? (Number(weights[rarity.id]) || 0) / total * 100 : 0 }));
// `drawable` : raretés que le paquet peut réellement donner, les autres ne comptent pas dans le tirage. Sans cette liste, les poids sont pris tels quels.
export function rarityPercentages(rarities, weights = {}, drawable = null) {
const weightOf = (rarity) => (!drawable || drawable.includes(rarity.id) ? Number(weights[rarity.id]) || 0 : 0);
const total = rarities.reduce((sum, rarity) => sum + weightOf(rarity), 0);
return rarities.map((rarity) => ({ rarity, weight: weightOf(rarity), percent: total ? weightOf(rarity) / total * 100 : 0 }));
}
export function formatPercent(value, maximumFractionDigits = 2) {