Files
joywayer 35216f75e7 feat: integrate room framework and isolated subgame bundles
Complete room UI and protocol integration, move game definitions and resources behind bundle entries, publish authoritative version XML, and document single-game builds. Include all current resource changes and experiment artifacts.
2026-09-09 03:13:18 +08:00

16 lines
1.4 KiB
TypeScript

import {test} from 'node:test';
import assert from 'node:assert/strict';
import {GAME_DEFINITIONS} from '../fixtures/game-definitions.ts';
test('template module attaches only when opened and releases its view and subscription',()=>{
let unsubscribed=0;const commands:unknown[]=[];const views:unknown[]=[];
const snapshot={connection:{phase:'logged-in'},self:{playerId:1,seat:0},room:{roomcode:'123456',roomtype:[],stage:0,needprepare:0,infinite:0},seats:[]};
const game=GAME_DEFINITIONS.Game_Surface_3.createGame('g');const probe=game.entry.createModule();probe.dispose();
assert.throws(()=>game.mount({render:s=>views.push(s),close(){}}));
const module=game.entry.createModule();assert.equal(game.roomProjection,null);assert.equal(module.roomProjection,null);
module.attach({capabilities:{room:{getSnapshot:()=>snapshot,subscribe:()=>()=>unsubscribed++,prepare:()=>commands.push({type:'room.prepare'}),requestExit:()=>commands.push({type:'room.exit'})}}} as any);
let actions:any;game.mount({render:(s,a,projection)=>{assert.equal(projection,null);views.push(s);actions=a;},close:()=>views.push('closed')});
actions.exit();actions.prepare();assert.deepEqual(commands,[{type:'room.exit'},{type:'room.prepare'}]);
const deskinfo={nested:[1,2]};module.restore(deskinfo);assert.equal(game.restoredSnapshot,deskinfo);
module.dispose();assert.equal(unsubscribed,1);assert.equal(views[views.length - 1],'closed');assert.throws(()=>actions.exit());
});