Skip to content

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.

  1. 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.
  2. Make src/main.ts a short runHost({ game: () => import('./game'), instance: MyInstance, ... }) call, importing from gameable/game-host. Make src/instance.ts a GameInstance subclass with the template's defaults and the game's custom hooks. For race, follow its runSessions / raceSession shape so leaving and rejoining dispose the previous session.
  3. Move each custom page behaviour using this map. Copy the exact signatures from the template or engine GameInstance.
Old main.ts codeDestination
LightssetupLights
Scene, place, world or collider setupsetupScene (retain required base setup)
HUD / DOM wiring after guest bootafterAttach
Play reactions / pointer lockonStart / pointerLockOnStart
Browser test hooksinstallTestHooks
Page modulespageModules
Physics optionsphysicsOptions
Wait until the page is drawablereadiness (return null until ready)
Failure handlingEngine-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.