M5-M7: сцены, лобби, экран игры и цикл матча
Обе сцены собраны через 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>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { CocosStorage } from '../modules/save/CocosStorage';
|
||||
import { SaveManager } from '../modules/save/SaveManager';
|
||||
import { StatsSection } from '../modules/save/StatsSection';
|
||||
|
||||
/**
|
||||
* The application's services, created once by the loader scene.
|
||||
*
|
||||
* Cocos components are built by the engine, so there is nowhere to inject
|
||||
* dependencies through a constructor; a small explicit locator is the honest
|
||||
* alternative to every component reaching for its own singleton. Everything it
|
||||
* holds is engine-independent apart from the storage adapter, so a test can
|
||||
* build one over `MemoryStorage` and drive the whole thing headlessly.
|
||||
*/
|
||||
export class App {
|
||||
private static _instance: App | null = null;
|
||||
|
||||
readonly save: SaveManager;
|
||||
readonly stats: StatsSection;
|
||||
|
||||
private constructor(save: SaveManager, stats: StatsSection) {
|
||||
this.save = save;
|
||||
this.stats = stats;
|
||||
}
|
||||
|
||||
/** Builds the services and loads saved progress. Called once, from `Bootstrap`. */
|
||||
static create(): App {
|
||||
if (App._instance) {
|
||||
return App._instance;
|
||||
}
|
||||
|
||||
const stats = new StatsSection();
|
||||
const save = new SaveManager(new CocosStorage());
|
||||
save.register(stats);
|
||||
save.load();
|
||||
|
||||
App._instance = new App(save, stats);
|
||||
return App._instance;
|
||||
}
|
||||
|
||||
static get instance(): App {
|
||||
if (!App._instance) {
|
||||
throw new Error('App.create() has not run — is the loader scene the start scene?');
|
||||
}
|
||||
return App._instance;
|
||||
}
|
||||
|
||||
static get exists(): boolean {
|
||||
return App._instance !== null;
|
||||
}
|
||||
|
||||
/** Records the result of a match and writes it out immediately. */
|
||||
recordMatch(outcome: 'win' | 'loss' | 'draw'): void {
|
||||
this.stats.recordResult(outcome);
|
||||
this.save.save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "982035ad-66a6-428b-bba3-4fe31ed7a095",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { _decorator, Component, director, game, resources, SpriteFrame } from 'cc';
|
||||
import { App } from './App';
|
||||
import { CARDS_DIR } from '../ui/game/CardLibrary';
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
* The loader scene, per ARCHITECTURE.md: bring the modules up, then hand over
|
||||
* to the lobby. Everything that must exist before any gameplay runs belongs
|
||||
* here, and nowhere else.
|
||||
*/
|
||||
@ccclass('Bootstrap')
|
||||
export class Bootstrap extends Component {
|
||||
@property({ tooltip: 'Scene to open once the modules are ready.' })
|
||||
nextScene = 'lobby';
|
||||
|
||||
start(): void {
|
||||
// A phone that throttles to 30 fps makes the card animations stutter;
|
||||
// asking for 60 up front is cheap and the engine falls back on its own.
|
||||
game.frameRate = 60;
|
||||
|
||||
App.create();
|
||||
|
||||
// Warm the card art here rather than on the first deal: thirty-seven
|
||||
// sprites are the only sizeable load in the game, and a loader scene is
|
||||
// exactly where a player expects to wait for it.
|
||||
resources.loadDir(CARDS_DIR, SpriteFrame, (error) => {
|
||||
if (error) {
|
||||
console.error('[bootstrap] could not preload the card art', error);
|
||||
}
|
||||
this._openLobby();
|
||||
});
|
||||
}
|
||||
|
||||
private _openLobby(): void {
|
||||
director.loadScene(this.nextScene, (error) => {
|
||||
if (error) {
|
||||
console.error(`[bootstrap] could not open '${this.nextScene}'`, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "c91dd91e-e180-44f4-98d1-b58cd4db0169",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user