feat(ui): per-kind active-game limit lock on the New Game screen
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 12s
CI / integration (pull_request) Successful in 28s
CI / ui (pull_request) Successful in 1m11s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m46s

Carry the caller's per-tier active-game caps and each game's kind on the
wire (Profile.game_limits + GameView.kind, additive FBS + gateway transcode
+ client codec, committed regen). The New Game screen counts the player's
active games per kind from the lobby and locks a capped start: an outline
button with a lock that opens a funnel modal instead of a game -- a sign-in
prompt for a guest, a "finish a current game first" notice for a signed-in
account (native Telegram popup, in-app modal elsewhere). The lock lifts via
the existing profile refetch after a guest->durable upgrade.

Remove the lobby's old at_game_limit New-Game tab disable + notice: the flag
(now the random-kind cap) conflicted with the per-kind lock -- it hid the
screen where the lock lives and wrongly blocked an unfulfilled kind. The New
Game tab is always enabled; the per-kind start lock is the only gate. The
at_game_limit wire field stays (unused by the client) for a later cleanup.

Tests: client lock logic + codec kind/game_limits roundtrip + gateway
transcode encode + native popup builders (unit); a mock e2e for the lock
badge and the modal.
This commit is contained in:
Ilia Denisov
2026-07-10 10:09:45 +02:00
parent e45167041f
commit 3306a016a0
45 changed files with 811 additions and 130 deletions
+28 -3
View File
@@ -2,7 +2,11 @@
import { onMount } from 'svelte';
import Screen from '../components/Screen.svelte';
import Modal from '../components/Modal.svelte';
import GameLimitModal from '../components/GameLimitModal.svelte';
import PinPad, { type PinResult } from '../components/PinPad.svelte';
import { getLobby } from '../lib/lobbycache';
import { isKindLocked } from '../lib/gamelimits';
import { GameKind } from '../lib/model';
import { gateway } from '../lib/gateway';
import { app, handleError, showToast } from '../lib/app.svelte';
import { connection } from '../lib/connection.svelte';
@@ -51,6 +55,14 @@
// or a random human via auto-match. AI is the default.
let opponent = $state<'ai' | 'random'>('ai');
// Active-game limit lock: the auto-start kind (vs_ai or random by the opponent choice) tested
// against the caller's per-kind cap over the online lobby's active games. A capped start opens the
// funnel modal instead of enqueuing (the server also refuses it); offline never locks (local
// games are uncapped). The lock lifts when the profile is re-fetched after a guest→durable upgrade.
const autoKind = $derived(opponent === 'ai' ? GameKind.vsAi : GameKind.random);
const autoLocked = $derived(!offlineMode.active && isKindLocked(getLobby(false)?.games ?? [], app.profile?.gameLimits, autoKind));
let limitOpen = $state(false);
// --- auto-match ---
// Enqueue drops the player straight into a real game — a freshly opened one awaiting an
// opponent, or another player's open game they just joined — so we navigate into it at once
@@ -329,9 +341,16 @@
{#if opponent === 'random'}<p class="searchhint">{t('new.searchHint')}</p>{/if}
<button
class="invite"
disabled={!selectedAuto || (!connection.online && !offlineMode.active) || starting}
onclick={() => selectedAuto && find(selectedAuto)}
>{t('new.start')}</button>
class:locked={autoLocked}
disabled={(autoLocked ? false : !selectedAuto) || (!connection.online && !offlineMode.active) || starting}
onclick={() => (autoLocked ? (limitOpen = true) : selectedAuto && find(selectedAuto))}
>{#if autoLocked}🔒 {/if}{t('new.start')}</button>
<GameLimitModal
open={limitOpen}
{guest}
onclose={() => (limitOpen = false)}
onlogin={() => { limitOpen = false; navigate('/settings'); }}
/>
{:else if offlineMode.active}
<!-- Offline pass-and-play (hotseat): a device-local 2-4 human game. The host sets a master
PIN first (it gates the roster); each seat may add its own PIN. -->
@@ -660,6 +679,12 @@
.invite:disabled {
opacity: 0.5;
}
/* A capped start (the active-game limit): an outline instead of the filled CTA, with a 🔒, so it
reads as gated rather than ready. Tapping it opens the funnel modal, never a game. */
.invite.locked {
background: transparent;
color: var(--accent);
}
.searchhint {
margin: 0;
text-align: center;