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>
18 lines
1.1 KiB
JavaScript
18 lines
1.1 KiB
JavaScript
// Rôle : présente les taux de tirage publiés sur chaque collection (`dropWeights`) et les poids recommandés.
|
|
|
|
// Poids recommandés des raretés, déclarés dans catalog.json.
|
|
export function recommendedWeights(rarities) {
|
|
return Object.fromEntries(rarities.map((rarity) => [rarity.id, rarity.recommendedWeight]));
|
|
}
|
|
|
|
// Pourcentage de chaque rareté pour une carte tirée, dans l'ordre des raretés du catalogue.
|
|
// `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) {
|
|
return `${value.toLocaleString("fr-FR", { maximumFractionDigits })} %`;
|
|
}
|