sokko-g/website/src/features/cards/dropRates.js
Shinuwa 166790245f Turn the comments that describe functions into JSDoc so the editor shows them on hover
The 669 // comments sitting right above a function, method or hook become
/** */ blocks, unchanged in wording; eslint directives stay right above the
line they target. website/AGENTS.md now asks for JSDoc on function comments
and // inside function bodies. ExpeditionPlanner.jsx grew past 300 lines and
gets its full header, as the header test requires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 11:51:47 +01:00

22 lines
1.1 KiB
JavaScript

/**
* @file 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 })} %`;
}