Add Aniimo elemental matchup calculator
This commit is contained in:
parent
72b3b15c7e
commit
243465720f
15 changed files with 518 additions and 10 deletions
73
website/src/features/games/aniimo/AniimoElements.jsx
Normal file
73
website/src/features/games/aniimo/AniimoElements.jsx
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
// Rôle : regroupe les affinités Aniimo par multiplicateur après sélection d'un ou deux éléments.
|
||||
import { useState } from "react";
|
||||
import { GameBreadcrumb } from "../GameBreadcrumb.jsx";
|
||||
import { aniimoAsset, aniimoLabel } from "./utils.js";
|
||||
import { calculateElementMatchups } from "./elementMatchups.js";
|
||||
|
||||
const formatMultiplier = (value) => `×${value.toLocaleString("fr-FR", { maximumFractionDigits: 6 })}`;
|
||||
|
||||
function ElementLabel({ element, t, size = 40, compact = false }) {
|
||||
const label = t(element);
|
||||
return <span className="aniimo-matchup-element" title={compact ? label : undefined}>
|
||||
<img src={aniimoAsset(element)} width={size} height={size} alt="" />
|
||||
<span>{label}</span>
|
||||
</span>;
|
||||
}
|
||||
|
||||
function MatchupGroups({ entries, prefix, defense = false, content, t }) {
|
||||
const groups = new Map();
|
||||
for (const { element, multiplier } of entries) {
|
||||
if (!groups.has(multiplier)) groups.set(multiplier, []);
|
||||
groups.get(multiplier).push(element);
|
||||
}
|
||||
const Heading = defense ? "h3" : "h4";
|
||||
return <div className="aniimo-matchup-groups" data-mode={defense ? "defense" : "attack"}>
|
||||
{[...groups].sort(([left], [right]) => right - left).map(([value, elements]) => {
|
||||
const favorable = defense ? value < 1 : value > 1;
|
||||
const band = value > 1.6 ? "veryHigh" : value > 1 ? "high" : value === 1 ? "normal" : value < 0.625 ? "veryLow" : "low";
|
||||
const label = (defense ? content.defenseBands : content.attackBands)[band];
|
||||
const titleId = `${prefix}-${value}`;
|
||||
return <section key={value} className="nds-card aniimo-matchup-box" aria-labelledby={titleId}>
|
||||
<div className="aniimo-matchup-box-heading">
|
||||
<Heading id={titleId}>{label}</Heading>
|
||||
<span className="nds-badge aniimo-multiplier" data-variant={value === 1 ? "neutral" : favorable ? "success" : "danger"}>{formatMultiplier(value)}</span>
|
||||
</div>
|
||||
<ul className="aniimo-matchup-members">{elements.map((element) => <li key={element}><ElementLabel element={element} t={t} size={24} compact /></li>)}</ul>
|
||||
</section>;
|
||||
})}
|
||||
</div>;
|
||||
}
|
||||
|
||||
export function AniimoElements({ game, aniimo, content }) {
|
||||
const [selected, setSelected] = useState([]);
|
||||
const chart = aniimo.elementChart;
|
||||
const t = (key) => aniimoLabel(aniimo.translations, key);
|
||||
const results = calculateElementMatchups(chart, selected);
|
||||
const toggle = (element) => setSelected((current) => current.includes(element) ? current.filter((value) => value !== element) : current.length < 2 ? [...current, element] : current);
|
||||
|
||||
return <>
|
||||
<section className="page-heading game-heading"><div><GameBreadcrumb game={game} /><h1>{content.title}</h1><p>{content.description}</p></div></section>
|
||||
<section className="aniimo-elements-guide">
|
||||
<section className="nds-panel aniimo-element-picker" aria-labelledby="aniimo-element-selection">
|
||||
<div className="aniimo-element-picker-heading"><h2 id="aniimo-element-selection">{content.selection}</h2><button className="nds-button" data-variant="ghost" data-size="sm" type="button" disabled={!selected.length} onClick={() => setSelected([])}>{content.reset}</button></div>
|
||||
<div className="aniimo-element-options" role="group" aria-labelledby="aniimo-element-selection" aria-describedby="aniimo-element-help">
|
||||
{chart.elements.map((element) => <button key={element} className="nds-button" data-variant="secondary" type="button" aria-pressed={selected.includes(element)} disabled={selected.length === 2 && !selected.includes(element)} onClick={() => toggle(element)}><ElementLabel element={element} t={t} size={48} /></button>)}
|
||||
</div>
|
||||
<p id="aniimo-element-help" className="aniimo-matchup-help" role="status">{selected.length === 2 ? content.limit : content.hint}</p>
|
||||
</section>
|
||||
{results ? <div className="aniimo-matchup-panels">
|
||||
<section className="nds-panel aniimo-matchup-panel" aria-labelledby="aniimo-attack-title">
|
||||
<h2 id="aniimo-attack-title">{content.attack}</h2><p>{content.attackHelp}</p>
|
||||
{selected.map((element, index) => <section key={element} className="aniimo-attack-element" aria-labelledby={`aniimo-attack-${element}`}>
|
||||
<h3 id={`aniimo-attack-${element}`} className="nds-section-heading aniimo-skill-heading"><span className="aniimo-skill-label">{content.skill}</span><span className="nds-badge aniimo-skill-element" data-variant="gold"><ElementLabel element={element} t={t} size={28} /></span></h3>
|
||||
<MatchupGroups entries={results.map((row) => ({ element: row.element, multiplier: row.attack[index].multiplier }))} prefix={`aniimo-attack-${element}-band`} content={content} t={t} />
|
||||
</section>)}
|
||||
</section>
|
||||
<section className="nds-panel aniimo-matchup-panel" aria-labelledby="aniimo-defense-title">
|
||||
<h2 id="aniimo-defense-title">{content.defense}</h2><p>{content.defenseHelp}</p>
|
||||
<MatchupGroups entries={results.map((row) => ({ element: row.element, multiplier: row.defense }))} prefix="aniimo-defense-band" defense content={content} t={t} />
|
||||
</section>
|
||||
</div> : <p className="nds-empty-state">{content.empty}</p>}
|
||||
</section>
|
||||
</>;
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// Rôle : assemble l'accueil Aniimo et la grille filtrable de ses variantes.
|
||||
// Rôle : assemble l'accueil Aniimo, ses guides et la grille filtrable de ses variantes.
|
||||
import { useMemo } from "react";
|
||||
import { CopyChecklistItemsButton } from "../CopyChecklistItemsButton.jsx";
|
||||
import { GuideChecklistPageControls } from "../GuideChecklistControls.jsx";
|
||||
|
|
@ -8,6 +8,7 @@ import { GameBreadcrumb } from "../GameBreadcrumb.jsx";
|
|||
import { AniimoCard } from "./AniimoCard.jsx";
|
||||
import { AniimoFilters } from "./AniimoFilters.jsx";
|
||||
import { AniimoLists } from "./AniimoLists.jsx";
|
||||
import { AniimoElements } from "./AniimoElements.jsx";
|
||||
import { getAniimoStatsMax, aniimoLabel, filterAniimoVariants, groupAniimoVariants } from "./utils.js";
|
||||
|
||||
function AniimoListing({ game, aniimo, filters, setFilters, content }) {
|
||||
|
|
@ -61,14 +62,16 @@ export function AniimoPage({ category, game, aniimo, filters, setFilters, siteCo
|
|||
if (aniimo.error) return <section className="empty nds-empty-state" role="alert"><h1>{content.error}</h1><p>{aniimo.error}</p><button className="nds-button" data-size="sm" data-variant="primary" type="button" onClick={aniimo.retry}>{siteContent.gamesPage.retryLabel}</button></section>;
|
||||
return <AniimoLists game={game} aniimo={aniimo} linkedToolboxId={links?.[game.id] || ""} actions={actions} />;
|
||||
}
|
||||
if (category !== "aniimos") return <>
|
||||
if (!["aniimos", "elements"].includes(category)) return <>
|
||||
<section className="game-hero" style={{ "--game-hero-image": `url("${game.images.heroBg}")` }}><div><p className="eyebrow">{game.eyebrow}</p><h1>{game.title}</h1><p>{game.summary}</p></div></section>
|
||||
<section className="game-home-grid">
|
||||
<a className="feature game-home-card aniimo-home-card" href="#/games/aniimo/aniimos"><img src={game.images.aniimosCover} alt="" /><strong>{content.title}</strong><span>{content.homeDescription}</span></a>
|
||||
<a className="feature game-home-card" href="#/games/aniimo/elements"><span className="game-home-card-icon" aria-hidden="true"><span className="aniimo-elements-home-icon"><img src="/static/img/aniimo/fire.webp" alt="" /><img src="/static/img/aniimo/water.webp" alt="" /><img src="/static/img/aniimo/grass.webp" alt="" /></span></span><strong>{content.elementCalculator.title}</strong><span>{content.elementCalculator.homeDescription}</span></a>
|
||||
<a className="feature game-home-card" href="#/games/aniimo/lists"><span className="game-home-card-icon" aria-hidden="true"><span className="module-icon-svg module-icon-checklist" /></span><strong>Listes</strong><span>Données copiables au format checklist pour préparer vos suivis.</span></a>
|
||||
</section>
|
||||
</>;
|
||||
if (aniimo.loading || !aniimo.loaded) return <section className="empty nds-empty-state" aria-busy="true"><h1>{content.loading}</h1></section>;
|
||||
if (aniimo.error) return <section className="empty nds-empty-state" role="alert"><h1>{content.error}</h1><p>{aniimo.error}</p><button className="nds-button" data-size="sm" data-variant="primary" type="button" onClick={aniimo.retry}>{siteContent.gamesPage.retryLabel}</button></section>;
|
||||
if (category === "elements") return <AniimoElements game={game} aniimo={aniimo} content={content.elementCalculator} />;
|
||||
return <AniimoListing game={game} aniimo={aniimo} filters={filters} setFilters={setFilters} content={content} />;
|
||||
}
|
||||
|
|
|
|||
14
website/src/features/games/aniimo/elementMatchups.js
Normal file
14
website/src/features/games/aniimo/elementMatchups.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Rôle : calcule les affinités offensives et défensives pour un ou deux éléments Aniimo.
|
||||
export function calculateElementMatchups(chart, selected) {
|
||||
const elements = [...new Set(selected)];
|
||||
if (!elements.length) return null;
|
||||
if (elements.length > 2 || elements.some((element) => !chart.elements.includes(element))) {
|
||||
throw new RangeError("Select one or two known Aniimo elements.");
|
||||
}
|
||||
return chart.elements.map((element) => ({
|
||||
element,
|
||||
// Chaque compétence conserve son propre élément en attaque.
|
||||
attack: elements.map((attacker) => ({ element: attacker, multiplier: chart.matchups[attacker][element] })),
|
||||
defense: Number(elements.reduce((value, defender) => value * chart.matchups[element][defender], 1).toFixed(6))
|
||||
}));
|
||||
}
|
||||
|
|
@ -143,10 +143,11 @@ export async function loadAniimoData(signal) {
|
|||
fetch("/data/aniimo/aniimos.json", { signal }),
|
||||
fetch("/data/aniimo/i18n/fr.json", { signal }),
|
||||
fetch("/data/aniimo/i18n/en.json", { signal }),
|
||||
fetch("/data/aniimo/lists/index.json", { signal })
|
||||
fetch("/data/aniimo/lists/index.json", { signal }),
|
||||
fetch("/data/aniimo/elements.json", { signal })
|
||||
]);
|
||||
if (responses.some((response) => !response.ok)) throw new Error("Les données Aniimo sont indisponibles.");
|
||||
const [aniimos, translations, englishTranslations, listIndex] = await Promise.all(responses.map((response) => response.json()));
|
||||
const [aniimos, translations, englishTranslations, listIndex, elementChart] = await Promise.all(responses.map((response) => response.json()));
|
||||
const lists = await loadGameLists("aniimo", listIndex, signal);
|
||||
return { loaded: true, loading: false, error: "", translations, englishTranslations, lists, ...prepareAniimoData(aniimos, translations, englishTranslations) };
|
||||
return { loaded: true, loading: false, error: "", translations, englishTranslations, lists, elementChart, ...prepareAniimoData(aniimos, translations, englishTranslations) };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,69 @@
|
|||
// Rôle : adapte les filtres et cartes Aniimo aux portraits verticaux et aux variantes.
|
||||
// Rôle : adapte les filtres, cartes et groupes d'affinités Aniimo.
|
||||
@use "design-system/surfaces";
|
||||
|
||||
.aniimo-home-card img { padding: 0 15%; object-fit: cover; object-position: 50% 38%; }
|
||||
.aniimo-elements-home-icon { position: relative; display: block; width: 116px; height: 90px; }
|
||||
.game-home-card .aniimo-elements-home-icon img {
|
||||
position: absolute;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
object-fit: contain;
|
||||
filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.34));
|
||||
&:first-child { top: 0; left: 34px; }
|
||||
&:nth-child(2) { right: 0; bottom: 0; }
|
||||
&:last-child { bottom: 0; left: 0; }
|
||||
}
|
||||
.aniimo-elements-guide { display: grid; gap: var(--space-5); }
|
||||
.aniimo-element-picker { display: grid; gap: var(--space-3); padding: var(--space-5); }
|
||||
.aniimo-element-picker-heading { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--space-3); }
|
||||
.aniimo-element-picker h2, .aniimo-matchup-panel h2 { margin: 0; font-size: var(--font-size-lg); }
|
||||
.aniimo-element-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: var(--space-3); }
|
||||
.aniimo-element-options .nds-button { min-width: 0; min-height: 96px; padding: var(--space-3) var(--space-2); }
|
||||
.aniimo-matchup-element { display: inline-flex; align-items: center; gap: var(--space-2); }
|
||||
.aniimo-matchup-element img { flex-shrink: 0; object-fit: contain; }
|
||||
.aniimo-element-options .aniimo-matchup-element, .aniimo-matchup-members .aniimo-matchup-element { flex-direction: column; }
|
||||
.aniimo-matchup-help { margin: 0; color: var(--color-text-secondary); font-size: var(--font-size-sm); }
|
||||
.aniimo-matchup-panels { display: grid; gap: var(--space-6); align-items: start; }
|
||||
.aniimo-matchup-panel {
|
||||
min-width: 0;
|
||||
padding: var(--space-5);
|
||||
container-type: inline-size;
|
||||
> p { color: var(--color-text-secondary); font-size: var(--font-size-sm); margin: var(--space-1) 0 var(--space-3); }
|
||||
}
|
||||
.aniimo-attack-element + .aniimo-attack-element { margin-top: var(--space-4); }
|
||||
.nds-section-heading.aniimo-skill-heading {
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
gap: var(--space-3);
|
||||
margin: 0 0 var(--space-2);
|
||||
padding: var(--space-2) var(--space-3);
|
||||
border-left: 2px solid var(--color-accent-gold);
|
||||
border-radius: var(--radius-md);
|
||||
background: linear-gradient(90deg, rgba(246, 196, 83, 0.08), rgba(139, 92, 246, 0.08));
|
||||
}
|
||||
.aniimo-skill-label { color: var(--color-text-secondary); font-size: var(--font-size-xs); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
|
||||
.aniimo-skill-element { flex-shrink: 0; }
|
||||
.aniimo-skill-element .aniimo-matchup-element { gap: 6px; color: var(--color-text-primary); font-size: var(--font-size-sm); }
|
||||
.aniimo-matchup-groups { display: grid; align-items: stretch; gap: var(--space-2); }
|
||||
.aniimo-matchup-groups[data-mode="attack"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
||||
.aniimo-matchup-groups[data-mode="defense"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
||||
.aniimo-matchup-box { min-width: 0; min-height: 112px; height: 100%; padding: var(--space-2); }
|
||||
.aniimo-matchup-box-heading { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: var(--space-1); padding: var(--space-1) var(--space-1) 0; }
|
||||
.aniimo-matchup-box-heading :is(h3, h4) { margin: 0; font-size: var(--font-size-sm); }
|
||||
.aniimo-matchup-members { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-2) var(--space-1); list-style: none; margin: var(--space-2) 0 0; padding: 0; }
|
||||
.aniimo-matchup-members .aniimo-matchup-element { width: 100%; min-width: 0; gap: var(--space-1); }
|
||||
.aniimo-matchup-members .aniimo-matchup-element > span { width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.aniimo-matchup-members li { min-width: 0; text-align: center; font-size: 10px; }
|
||||
.aniimo-multiplier { white-space: nowrap; font-variant-numeric: tabular-nums; font-size: var(--font-size-xs); }
|
||||
@media (min-width: 1100px) {
|
||||
.aniimo-matchup-panels { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
}
|
||||
@container (max-width: 460px) {
|
||||
.aniimo-matchup-groups[data-mode] { grid-template-columns: 1fr; }
|
||||
}
|
||||
.aniimo-layout .game-results { min-width: 0; }
|
||||
.aniimo-filters { min-width: 0; }
|
||||
.aniimo-filters .nds-filter-advanced-options { flex: 1 1 auto; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue