Let players finish a daily quest game started before midnight instead of being sent back to the start
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c3e494b8a6
commit
4a44306e30
24 changed files with 327 additions and 81 deletions
|
|
@ -39,6 +39,8 @@ export function DailyPanel({ catalog, state, runMutation, busy, content }) {
|
|||
const [guess, setGuess] = useState("");
|
||||
const [notice, setNotice] = useState("");
|
||||
const [now, setNow] = useState(() => Date.now());
|
||||
// Le serveur a refusé un coup sur une partie trop ancienne (page restée ouverte plus d'un jour) : il faut recharger.
|
||||
const [refused, setRefused] = useState(false);
|
||||
const inputRef = useRef(null);
|
||||
const [refocus, setRefocus] = useState(0);
|
||||
const day = daily?.day || "";
|
||||
|
|
@ -61,7 +63,7 @@ export function DailyPanel({ catalog, state, runMutation, busy, content }) {
|
|||
if (!day || cardShown) return undefined;
|
||||
let active = true;
|
||||
let url = "";
|
||||
loadDailyImage()
|
||||
loadDailyImage(day)
|
||||
.then((objectUrl) => {
|
||||
url = objectUrl;
|
||||
if (active) setImage({ day, url: objectUrl, failed: false });
|
||||
|
|
@ -100,6 +102,8 @@ export function DailyPanel({ catalog, state, runMutation, busy, content }) {
|
|||
|
||||
const expired = now >= daily.nextAt;
|
||||
const finished = daily.status !== "playing";
|
||||
// Commencée avant minuit, la partie se termine sur son jour : seule une partie finie (ou refusée) laisse place à la suivante.
|
||||
const finishing = expired && !finished && !refused;
|
||||
const owned = answer && readCollection(state).ownedCardIds.has(answer.card.id);
|
||||
const imageUrl = image.day === daily.day ? image.url : "";
|
||||
const imageFailed = image.day === daily.day && image.failed;
|
||||
|
|
@ -118,7 +122,10 @@ export function DailyPanel({ catalog, state, runMutation, busy, content }) {
|
|||
}
|
||||
});
|
||||
if (result?.daily) setDaily((current) => ({ ...current, ...result.daily }));
|
||||
else if (result?.dailyError?.code === "DAILY_EXPIRED") setNow(daily.nextAt);
|
||||
else if (result?.dailyError?.code === "DAILY_EXPIRED") {
|
||||
setRefused(true);
|
||||
setNow(Math.max(Date.now(), daily.nextAt));
|
||||
}
|
||||
else if (result?.dailyError) setNotice(result.dailyError.message);
|
||||
return Boolean(result?.daily);
|
||||
}
|
||||
|
|
@ -154,7 +161,8 @@ export function DailyPanel({ catalog, state, runMutation, busy, content }) {
|
|||
<a className="nds-button" data-size="sm" data-variant="secondary" href={cardsHref("guild")}>{content.back}</a>
|
||||
</div>
|
||||
</div>
|
||||
{expired && <div className="nds-inline-notice nebula-daily-expired" data-variant="warning" role="status"><span>{content.expired}</span><button className="nds-button" data-size="sm" data-variant="primary" type="button" onClick={() => { setNow(Date.now()); setReloadKey((key) => key + 1); }}>{content.reload}</button></div>}
|
||||
{finishing && <div className="nds-inline-notice nebula-daily-expired" data-variant="warning" role="status"><span>{content.expiredPlaying}</span></div>}
|
||||
{expired && !finishing && <div className="nds-inline-notice nebula-daily-expired" data-variant="warning" role="status"><span>{content.expired}</span><button className="nds-button" data-size="sm" data-variant="primary" type="button" onClick={() => { setNow(Date.now()); setRefused(false); setReloadKey((key) => key + 1); }}>{content.reload}</button></div>}
|
||||
<div className="nebula-daily-layout" data-finished={finished || undefined}>
|
||||
<div className="nds-panel nebula-daily-stage">
|
||||
{answer ? <>
|
||||
|
|
@ -171,13 +179,13 @@ export function DailyPanel({ catalog, state, runMutation, busy, content }) {
|
|||
</div>
|
||||
<DailyTrack daily={daily} content={content} />
|
||||
<div className="nebula-daily-form-row">
|
||||
<CategoryAutocompleteInput ref={inputRef} id="nebula-daily-guess" name="guess" options={options} keywords={keywords} usedOptions={guessedNames} searchTexts={content.search} value={guess} placeholder={content.guessPlaceholder} maxOptions={MAX_SUGGESTIONS} disabled={busy || expired} onChange={(event) => { setGuess(event.target.value); setNotice(""); }} />
|
||||
<button className="nds-button" data-variant="primary" type="submit" disabled={busy || expired || !chosen}>{content.guessAction}</button>
|
||||
<CategoryAutocompleteInput ref={inputRef} id="nebula-daily-guess" name="guess" options={options} keywords={keywords} usedOptions={guessedNames} searchTexts={content.search} value={guess} placeholder={content.guessPlaceholder} maxOptions={MAX_SUGGESTIONS} disabled={busy || refused} onChange={(event) => { setGuess(event.target.value); setNotice(""); }} />
|
||||
<button className="nds-button" data-variant="primary" type="submit" disabled={busy || refused || !chosen}>{content.guessAction}</button>
|
||||
</div>
|
||||
{notice && <p className="nds-inline-notice" data-variant="warning" role="status">{notice}</p>}
|
||||
<div className="nebula-daily-aside" aria-live="polite">{tried ? <DailyFeedback catalog={catalog} daily={daily} content={content} /> : <DailyRules content={content} />}</div>
|
||||
</form>}
|
||||
{!finished && <DailyHints catalog={catalog} daily={daily} busy={busy || expired} content={content} onUse={openHint} />}
|
||||
{!finished && <DailyHints catalog={catalog} daily={daily} busy={busy || refused} content={content} onUse={openHint} />}
|
||||
<DailyGuesses catalog={catalog} daily={daily} content={content} />
|
||||
</div>
|
||||
</section>;
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ export function DailyResult({ catalog, card, daily, content, now, busy = false,
|
|||
</ul>}
|
||||
<div className="nebula-daily-result-actions">
|
||||
<button className="nds-button" data-variant="primary" type="button" onClick={share}>{copied ? content.shared : content.share}</button>
|
||||
<span>{fillTemplate(content.next, { time: formatCountdown(daily.nextAt - now) })}</span>
|
||||
{/* Partie de la veille finie après minuit : la carte suivante est déjà là, le bandeau propose de la charger. */}
|
||||
{daily.nextAt > now && <span>{fillTemplate(content.next, { time: formatCountdown(daily.nextAt - now) })}</span>}
|
||||
</div>
|
||||
</section>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue