sokko-g/website/src/features/cards/rewardText.js
Shinuwa 5ce35cd7ba 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>
2026-11-05 17:47:35 +01:00

50 lines
2.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Rôle : décrit en français une récompense distribuée par code (cartes, paquets et leurs options).
const editionLabel = (catalog, editionId) => {
const edition = catalog.editions.find((item) => item.id === editionId);
const card = catalog.cards.find((item) => item.id === edition?.cardId);
if (!edition || !card) return "carte inconnue";
const rarity = catalog.rarities.find((item) => item.id === edition.rarity)?.label || edition.rarity;
const finish = edition.finishIds.map((id) => catalog.finishes.find((item) => item.id === id)?.label).filter((label) => label && label !== "Standard").join(" · ");
return `${card.name} (${[rarity, finish].filter(Boolean).join(" · ")})`;
};
// Détails d'un paquet offert : taux et garantie, sous forme de courtes phrases.
export function packDetails(options, catalog) {
const details = [];
if (options?.rarityWeights) details.push("taux personnalisés");
if (options?.guarantee?.type === "rarity") {
const rarity = catalog.rarities.find((item) => item.id === options.guarantee.rarity)?.label?.toLocaleLowerCase("fr") || options.guarantee.rarity;
const best = catalog.rarities.at(-1)?.id === options.guarantee.rarity;
details.push(`au moins ${options.guarantee.count} carte${options.guarantee.count > 1 ? "s" : ""} ${rarity}${best ? "" : " ou mieux"} garantie${options.guarantee.count > 1 ? "s" : ""}`);
}
if (options?.guarantee?.type === "edition") details.push(`${editionLabel(catalog, options.guarantee.editionId)} garantie`);
return details;
}
// Un élément de récompense : « 2 × Carte … » ou « Paquet … · garantie ».
export function describeRewardItem(item, catalog) {
const prefix = item.quantity > 1 ? `${item.quantity} × ` : "";
if (item?.type === "card") return `${prefix}Carte ${editionLabel(catalog, item.editionId)}`;
if (item?.type === "pack") {
const collection = catalog.collections.find((entry) => entry.id === item.collectionId)?.name || item.collectionId;
return `${prefix}${[`Paquet ${collection}`, ...packDetails(item, catalog)].join(" · ")}`;
}
return "Élément inconnu";
}
export function describeReward(reward, catalog) {
return (reward?.items || []).map((item) => describeRewardItem(item, catalog)).join(" + ") || "Récompense vide";
}
const SUMMARY_MAX_ITEMS = 3;
// Version courte pour les listes : le détail complet jusqu'à trois éléments, sinon « 12 cartes + 2 paquets ».
export function summarizeReward(reward, catalog) {
const items = reward?.items || [];
if (items.length <= SUMMARY_MAX_ITEMS) return describeReward(reward, catalog);
const count = (type) => items.filter((item) => item.type === type).reduce((total, item) => total + (item.quantity || 1), 0);
const cards = count("card");
const packs = count("pack");
return [cards && `${cards} carte${cards > 1 ? "s" : ""}`, packs && `${packs} paquet${packs > 1 ? "s" : ""}`].filter(Boolean).join(" + ");
}