Let players choose how their cards spend level points with vocations or free points, and sell the Parchemin d'oubli
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
18bcf435b5
commit
7d331d1a3f
24 changed files with 473 additions and 60 deletions
78
website/src/features/cards/CardPlan.jsx
Normal file
78
website/src/features/cards/CardPlan.jsx
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
// Rôle : plan de progression d'une carte depuis sa fiche : ses points de niveau suivent sa collection, une vocation (la stat d'un rôle)
|
||||
// ou la répartition du joueur. Aperçu des stats avant de valider ; le premier choix est gratuit, les changements suivants coûtent
|
||||
// un Parchemin d'oubli (ajouter des points en libre reste gratuit).
|
||||
import { useState } from "react";
|
||||
import { setCardPlan } from "./cardsApi.js";
|
||||
import { MaskIcon } from "./ExpeditionLabels.jsx";
|
||||
|
||||
const STATS = [["bravoure", "Bravoure"], ["endurance", "Endurance"], ["fortune", "Fortune"], ["orientation", "Orientation"]];
|
||||
const PLANS = [
|
||||
{ id: "collection", label: "Sa collection", help: "Les points suivent le profil de la collection de la carte." },
|
||||
{ id: "leader", stat: "bravoure", label: "Meneur", help: "Faite pour la place de Meneur : surtout de la Bravoure." },
|
||||
{ id: "guardian", stat: "endurance", label: "Gardien", help: "Faite pour la place de Gardien : surtout de l’Endurance." },
|
||||
{ id: "seeker", stat: "fortune", label: "Chercheur", help: "Faite pour la place de Chercheur : surtout de la Fortune." },
|
||||
{ id: "navigator", stat: "orientation", label: "Navigateur", help: "Faite pour la place de Navigateur : surtout de l’Orientation." },
|
||||
{ id: "free", label: "Libre", help: "Vous placez vous-même chaque point." }
|
||||
];
|
||||
const total = (stats) => Object.values(stats).reduce((sum, value) => sum + value, 0);
|
||||
const toDraft = (allocation) => Object.fromEntries(STATS.map(([stat]) => [stat, String(allocation?.[stat] ?? 0)]));
|
||||
|
||||
function StatPreview({ before, after }) {
|
||||
return <ul className="nebula-card-plan-preview" aria-label="Stats de la carte avec ce plan, hors équipement">{STATS.map(([stat, label]) => {
|
||||
const delta = after[stat] - before[stat];
|
||||
return <li key={stat} data-trend={delta > 0 ? "up" : delta < 0 ? "down" : undefined}>
|
||||
<span><MaskIcon name={stat} />{label}</span>
|
||||
<strong>{delta ? <>{before[stat]} → {after[stat]}</> : after[stat]}</strong>
|
||||
</li>;
|
||||
})}</ul>;
|
||||
}
|
||||
|
||||
// `locked` : la carte est en expédition, son plan ne change pas avant son retour.
|
||||
export function CardPlan({ progress, oblivions, locked = false, busy, runMutation }) {
|
||||
const plan = progress.plan;
|
||||
const [choice, setChoice] = useState(plan.id);
|
||||
const [draft, setDraft] = useState(() => toDraft(plan.allocation));
|
||||
const free = choice === "free";
|
||||
const allocation = Object.fromEntries(STATS.map(([stat]) => [stat, Math.max(0, Number.parseInt(draft[stat], 10) || 0)]));
|
||||
const left = plan.points - total(allocation);
|
||||
const placed = plan.allocation || toDraft(null);
|
||||
const unchanged = choice === plan.id && (!free || STATS.every(([stat]) => allocation[stat] === Number(placed[stat])));
|
||||
const onlyAdds = free && plan.id === "free" && STATS.every(([stat]) => allocation[stat] >= Number(placed[stat]));
|
||||
const paid = plan.paid && !onlyAdds;
|
||||
const preview = free ? Object.fromEntries(STATS.map(([stat]) => [stat, plan.levelBase[stat] + allocation[stat]])) : plan.previews[choice];
|
||||
const chosen = PLANS.find((item) => item.id === choice);
|
||||
// Un point de plus ne dépasse ni le plafond d'une stat, ni les points restants.
|
||||
const setPoints = (stat, raw) => {
|
||||
const limit = Math.min(plan.maxStatPoints, allocation[stat] + left);
|
||||
setDraft((current) => ({ ...current, [stat]: raw !== "" && Number(raw) > limit ? String(limit) : raw }));
|
||||
};
|
||||
|
||||
return <section className="nebula-card-plan" aria-labelledby="nebula-card-plan-title">
|
||||
<h4 id="nebula-card-plan-title">Plan de progression</h4>
|
||||
<p className="nebula-form-help">{plan.points
|
||||
? `Ses ${plan.points} points de niveau se répartissent selon ce plan, au plus ${plan.maxStatPoints} dans une même stat.`
|
||||
: "Chaque amélioration donne des points de stats, répartis selon ce plan."}</p>
|
||||
<div role="group" aria-label="Plan de progression" className="nds-toolbar nebula-card-plan-choices">{PLANS.map((item) => <button key={item.id} type="button" className="nds-button" data-size="sm"
|
||||
data-variant={item.id === choice ? "primary" : "secondary"} aria-pressed={item.id === choice} disabled={busy} onClick={() => setChoice(item.id)}>
|
||||
{item.stat && <MaskIcon name={item.stat} />}{item.label}
|
||||
</button>)}</div>
|
||||
<p className="nebula-form-help">{chosen.help}</p>
|
||||
{free && <div className="nebula-card-plan-points">
|
||||
{STATS.map(([stat, label]) => <label key={stat}><span><MaskIcon name={stat} />{label}</span>
|
||||
<input className="nds-input" type="number" inputMode="numeric" min="0" max={plan.maxStatPoints} step="1" value={draft[stat]} disabled={busy || !plan.points}
|
||||
onChange={(event) => setPoints(stat, event.target.value)} onBlur={() => { if (draft[stat] === "") setDraft((current) => ({ ...current, [stat]: "0" })); }} />
|
||||
</label>)}
|
||||
<p className="nebula-form-help" role="status">{!plan.points ? "Aucun point à placer pour l’instant : améliorez la carte." : left > 0 ? `${left} point${left > 1 ? "s" : ""} à placer.` : "Tous les points sont placés."}</p>
|
||||
</div>}
|
||||
<StatPreview before={progress.baseStats} after={preview} />
|
||||
{!unchanged && <p className="nebula-form-help">{paid
|
||||
? `Coûte 1 Parchemin d’oubli : vous en avez ${oblivions}.${oblivions < 1 ? " Ils s’achètent dans la Boutique." : ""}`
|
||||
: plan.id === "collection" ? "Premier choix gratuit : ensuite, changer de plan coûtera un Parchemin d’oubli." : "Placer de nouveaux points est gratuit."}</p>}
|
||||
{locked && <p className="nebula-form-help">Cette carte est en expédition : son plan pourra changer à son retour.</p>}
|
||||
<div className="nds-toolbar">
|
||||
<button className="nds-button" data-variant="primary" type="button" disabled={busy || locked || unchanged || (paid && oblivions < 1)}
|
||||
onClick={() => runMutation(() => setCardPlan(progress.editionId, choice, free ? allocation : null))}>{free ? "Valider les points" : "Choisir ce plan"}</button>
|
||||
{!unchanged && <button className="nds-button" data-variant="secondary" type="button" disabled={busy} onClick={() => { setChoice(plan.id); setDraft(toDraft(plan.allocation)); }}>Annuler</button>}
|
||||
</div>
|
||||
</section>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue