Обе сцены собраны через Code Mode, не руками. - loader: поднимает модули, прогревает арт карт, уходит в lobby - lobby: обе UI-ветки в одной сцене (по ARCHITECTURE.md), матч — это смена видимого корня, а не загрузка сцены - GameScreen рисует текущее состояние и доводит узлы твинами, а не проигрывает поток событий: узел карты живёт вместе со своей картой, поэтому "шестёрка ушла из руки на стол" не требует отдельного случая - один тап = ход целиком; логика вынесена в core/rules/intent.ts и покрыта тестами, в том числе проверкой, что она никогда не предложит ход, который правила отвергнут - арт карт переехал в assets/resources: .pac — это инструкция упаковки на сборке, а не рантайм-ассет, и без ссылок на кадры в сборку не попадало ничего. Теперь все 37 спрайтов в одной текстуре 2048x2048 - клики кнопок подписываются в коде, а не через clickEvents сцены - строки интерфейса собраны в одном файле Сборка web-mobile проходит чисто, все ссылки в сцене проверены. Вживую не запускалось: браузер в этом окружении не поднимает главный цикл движка. Подробности — в docs/TECHNICAL.md. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
83 lines
2.4 KiB
TypeScript
83 lines
2.4 KiB
TypeScript
import { _decorator, Button, Component, Label, Node } from 'cc';
|
|
import { App } from '../../app/App';
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/**
|
|
* The lobby, per LOBBY.md: one button that starts a game, and — since the save
|
|
* module is already keeping them — the player's record.
|
|
*
|
|
* It owns no game logic. Starting a match is reported to `MainFlow` through
|
|
* `onStartRequested`, which keeps the lobby ignorant of what a match even is.
|
|
*/
|
|
@ccclass('LobbyScreen')
|
|
export class LobbyScreen extends Component {
|
|
@property(Label)
|
|
playedLabel: Label | null = null;
|
|
|
|
@property(Label)
|
|
wonLabel: Label | null = null;
|
|
|
|
@property(Label)
|
|
lostLabel: Label | null = null;
|
|
|
|
@property(Label)
|
|
streakLabel: Label | null = null;
|
|
|
|
@property(Node)
|
|
statsPanel: Node | null = null;
|
|
|
|
@property(Button)
|
|
newGameButton: Button | null = null;
|
|
|
|
/** Set by `MainFlow`. */
|
|
onStartRequested: (() => void) | null = null;
|
|
|
|
onLoad(): void {
|
|
// Clicks are subscribed here rather than through the scene's clickEvents
|
|
// list: the wiring stays visible in the source, and a renamed handler
|
|
// becomes a compile error instead of a button that silently does nothing.
|
|
this.newGameButton?.node.on(Button.EventType.CLICK, this.startGame, this);
|
|
}
|
|
|
|
onDestroy(): void {
|
|
this.newGameButton?.node.off(Button.EventType.CLICK, this.startGame, this);
|
|
}
|
|
|
|
onEnable(): void {
|
|
this.refresh();
|
|
}
|
|
|
|
/** Re-reads the saved statistics. Called whenever the lobby comes back into view. */
|
|
refresh(): void {
|
|
if (!App.exists) {
|
|
return;
|
|
}
|
|
const stats = App.instance.stats;
|
|
|
|
setText(this.playedLabel, `${stats.played}`);
|
|
setText(this.wonLabel, `${stats.won}`);
|
|
setText(this.lostLabel, `${stats.lost}`);
|
|
setText(this.streakLabel, stats.bestStreak > 0
|
|
? `${stats.streak} (best ${stats.bestStreak})`
|
|
: `${stats.streak}`);
|
|
|
|
// Nothing to show before the first game — an empty table of zeroes is
|
|
// worse than no table at all.
|
|
if (this.statsPanel) {
|
|
this.statsPanel.active = stats.played > 0;
|
|
}
|
|
}
|
|
|
|
/** Wired to the New Game button in the scene. */
|
|
startGame(): void {
|
|
this.onStartRequested?.();
|
|
}
|
|
}
|
|
|
|
function setText(label: Label | null, text: string): void {
|
|
if (label) {
|
|
label.string = text;
|
|
}
|
|
}
|