Move an edited game onto the engine host
The engine now owns boot, guest loading, start, readiness, failure UI and session cleanup through gameable/game-host. Older games copied that runtime into their page. Preserve the game's custom choices by moving them into hooks.
Read the game's template in the engine build: /opt/engine/templates/<t>/src/. Its main.ts and instance.ts are the reference; use that template's options, imports and hook signatures rather than inventing a new bootstrap.
- Read the game's existing host edits and the template's
host.json. Save the custom behaviour before replacing anything. An automatic upgrade is safe only if every owned and retired host file is untouched since the game's first commit. Replace owned files and remove retired files as one group. An edited host needs this migration; do not partially overwrite it. - Make
src/main.tsa shortrunHost({ game: () => import('./game'), instance: MyInstance, ... })call, importing fromgameable/game-host. Makesrc/instance.tsaGameInstancesubclass with the template's defaults and the game's custom hooks. For race, follow itsrunSessions/raceSessionshape so leaving and rejoining dispose the previous session. - Move each custom page behaviour using this map. Copy the exact signatures from the template or engine
GameInstance.
| Old main.ts code | Destination |
|---|---|
| Lights | setupLights |
| Scene, place, world or collider setup | setupScene (retain required base setup) |
| HUD / DOM wiring after guest boot | afterAttach |
| Play reactions / pointer lock | onStart / pointerLockOnStart |
| Browser test hooks | installTestHooks |
| Page modules | pageModules |
| Physics options | physicsOptions |
| Wait until the page is drawable | readiness (return null until ready) |
| Failure handling | Engine-owned; onFailure only if the game must react |
Keep Play routed through startGame({ reason: 'player' }) from gameable/host; the host registers start handling. Capture and playtest starts must skip pointer lock. Register per-session resources with this.use(...), following the template. If overriding onFailure to react, retain super.onFailure(error) so the host still displays the failure and cleans up.
Delete copied fail(), window error / unhandledrejection listeners, createEngine, manual adapter/sandbox/loop boot, __AOS_READY__ publication and cleanup, and copied sandbox.ts / pageErrors.ts (plus the template's other retired files). Use the engine host's loading and failure handling. Do not recreate it in game code.
Never change gameplay for this migration: keep src/game.ts, systems, actors, prefabs, levels, asset manifests and gameplay-only modules intact. Preserve custom scene and HUD behaviour when transferring page edits into hooks.
Run the game's check stages in order: typecheck, unit, build, using its existing check runner or package scripts. Fix host integration errors and rerun the failed stage. Then play once, exercise Play and any room leave/rejoin, and verify capture/test readiness and the failure UI. Check the final diff for accidental gameplay edits.