# ModTrick host (game side)

**Methodology:** the game is a **ModRuntime host**. Everything runtime is a mod  
(META · GENESIS · SHADOW · MGS). Couple mods through a **host bus**, not private imports.

Law: [/docs/EVERYTHING-IS-A-MOD.md](../docs/EVERYTHING-IS-A-MOD.md)  
Reference wiring: [/game/outpost/](../game/outpost/)  

Copy these files into your game (or import from a vendored path).

## Files

| File | Role |
|------|------|
| `mod-runtime.js` | Load `mod.json`, GENESIS factories, tick, dispose, SHADOW log |
| `frame-context.js` | Host-owned bus (`sunDir`, `playerPos`, etc.) for coupling |

## Quick start (three.js)

```html
<script type="importmap">
{
  "imports": {
    "three": "https://cdn.jsdelivr.net/npm/three@0.170.0/build/three.module.js"
  }
}
</script>
<script type="module">
  import * as THREE from "three";
  import { ModRuntime } from "./host/mod-runtime.js";

  const scene = new THREE.Scene();
  const camera = new THREE.PerspectiveCamera(55, innerWidth / innerHeight, 0.5, 8000);
  const renderer = new THREE.WebGLRenderer({ antialias: true });
  // ... mount renderer, camera.position, etc.

  const BASE = "https://modtrick.com"; // or your vendored /mods
  const runtime = new ModRuntime({ scene, camera, renderer, THREE });

  await runtime.loadAll([
    { url: `${BASE}/mods/threejs-sky/mod.json`, baseUrl: `${BASE}/mods/threejs-sky/` },
    { url: `${BASE}/mods/threejs-ocean/mod.json`, baseUrl: `${BASE}/mods/threejs-ocean/` },
  ]);

  const clock = new THREE.Clock();
  function frame() {
    const t = clock.getElapsedTime();
    const dt = clock.getDelta();
    runtime.tick(t, dt);
    renderer.render(scene, camera);
    requestAnimationFrame(frame);
  }
  frame();
</script>
```

## MGS order on the host

1. **install** — copy host + vendor mods  
2. **tune** — pass options; use `runtime.setDefaults(id, opts)` + `runtime.configure(id, partial)`  
3. **verify** — each mod’s `asec.mgs.verify` (Outpost: `window.__OUTPOST__.checks`)  
4. **maintain** — `runtime.tick` / `runtime.render` each frame; `dispose` on teardown  

### Configuration

```js
runtime.setDefaults("threejs-collectibles", { preset: "coins" });
await runtime.loadManifestUrl(...);
runtime.configure("threejs-third-person", { speed: 10, distance: 5 });
runtime.getConfig("threejs-health");
runtime.list(); // [{ id, export, config }]
```

Host fields `camera` / `renderer` / `domElement` are **auto-injected** into factories when loaded via ModRuntime.

See [/docs/MOD-CONFIG.md](../docs/MOD-CONFIG.md) and [/agents/mod-catalog.json](../agents/mod-catalog.json).

Agent bootstrap: [/docs/agents/ONBOARD.md](../docs/agents/ONBOARD.md) · paste prompt: [/docs/agents/ADD-MODDING-TO-GAME.md](../docs/agents/ADD-MODDING-TO-GAME.md).
