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>
86 lines
4.3 KiB
JavaScript
86 lines
4.3 KiB
JavaScript
// Rôle : boutique du joueur ; affiche le solde de poussière d'étoiles et achète des ouvertures de paquet.
|
||
import { useState } from "react";
|
||
import { buyOpening, buyShopPack } from "./cardsApi.js";
|
||
import { DashboardAside } from "./CardsDashboard.jsx";
|
||
import { CollectionCardBack } from "./CollectionCardBack.jsx";
|
||
import { formatStardust } from "./stardustFormat.js";
|
||
|
||
export function StardustBalance({ value }) {
|
||
return <span className="nebula-stardust" aria-label={`${formatStardust(value)} d’étoiles`}><span aria-hidden="true">✦</span>{value.toLocaleString("fr-FR")}</span>;
|
||
}
|
||
|
||
function StardustWallet({ wallet }) {
|
||
return <div className="nds-panel nebula-shop-wallet">
|
||
<div><span>Votre poussière d’étoiles</span><StardustBalance value={wallet.stardust} /></div>
|
||
</div>;
|
||
}
|
||
|
||
// Illustrations des articles, partagées avec le réglage des prix dans l'administration.
|
||
export function ShopPackCover({ collection }) {
|
||
return <div className="nds-card-cover nebula-shop-item-cover"><span className="nebula-shop-item-back"><CollectionCardBack collection={collection} /></span></div>;
|
||
}
|
||
|
||
export function ShopOpeningCover() {
|
||
return <div className="nds-card-cover nebula-shop-item-cover"><img src="/static/img/cards/shop/pack.webp" alt="" loading="lazy" /></div>;
|
||
}
|
||
|
||
export function ShopPanel({ catalog, state, runMutation, busy, content, onOpenPacks }) {
|
||
const [notice, setNotice] = useState("");
|
||
const { wallet, shop } = state;
|
||
const price = shop.openingPrice;
|
||
const missing = Math.max(0, price - wallet.stardust);
|
||
|
||
const shopPack = catalog.collections.find((collection) => collection.packCategory === "shop" && collection.active);
|
||
const packMissing = Math.max(0, shop.shopPackPrice - wallet.stardust);
|
||
|
||
// L'ouverture attribuée s'affiche dans la section Paquets, qui gère la révélation.
|
||
async function buyPack() {
|
||
setNotice("");
|
||
const result = await runMutation(() => buyShopPack());
|
||
if (result?.opening) onOpenPacks();
|
||
}
|
||
|
||
async function buy() {
|
||
setNotice("");
|
||
const result = await runMutation(() => buyOpening());
|
||
if (result?.player) setNotice("Ouverture achetée : utilisez-la depuis la section Paquets.");
|
||
}
|
||
|
||
return <div className="nebula-shop">
|
||
<div className="nds-section-heading nebula-section-heading">
|
||
<div><p className="eyebrow">Poussière d’étoiles</p><h2>Boutique</h2></div>
|
||
</div>
|
||
<DashboardAside><StardustWallet wallet={wallet} /></DashboardAside>
|
||
{notice && <p className="nds-inline-notice" data-variant="success" role="status">{notice}</p>}
|
||
|
||
<section aria-label="Articles de la boutique">
|
||
<div className="nebula-shop-grid">
|
||
{shopPack && <article className="nds-card nebula-shop-item" data-item="pack">
|
||
<ShopPackCover collection={shopPack} />
|
||
<div className="nds-card-body nebula-shop-item-body">
|
||
<h4>{shopPack.name}</h4>
|
||
<p className="nebula-form-help">{content.packDescription}</p>
|
||
<div className="nds-card-actions nebula-shop-item-actions">
|
||
<StardustBalance value={shop.shopPackPrice} />
|
||
<button className="nds-button" data-size="sm" data-variant="primary" type="button" disabled={busy || packMissing > 0 || Boolean(state.pendingOpening)} onClick={buyPack}>{content.packAction}</button>
|
||
</div>
|
||
{packMissing > 0 && <p className="nebula-form-help">Il vous manque {formatStardust(packMissing)}.</p>}
|
||
{state.pendingOpening && <p className="nebula-form-help">{content.packPending}</p>}
|
||
</div>
|
||
</article>}
|
||
<article className="nds-card nebula-shop-item">
|
||
<ShopOpeningCover />
|
||
<div className="nds-card-body nebula-shop-item-body">
|
||
<h4>Ouverture de paquet</h4>
|
||
<p className="nebula-form-help">À utiliser sur le paquet de votre choix, en plus de votre réserve.</p>
|
||
<div className="nds-card-actions nebula-shop-item-actions">
|
||
<StardustBalance value={price} />
|
||
<button className="nds-button" data-size="sm" data-variant="primary" type="button" disabled={busy || missing > 0} onClick={buy}>Acheter</button>
|
||
</div>
|
||
{missing > 0 && <p className="nebula-form-help">Il vous manque {formatStardust(missing)}.</p>}
|
||
</div>
|
||
</article>
|
||
</div>
|
||
</section>
|
||
</div>;
|
||
}
|