threedog 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/README.md +4 -4
  2. package/core/Animator.js +1 -0
  3. package/core/Assets.js +28 -0
  4. package/core/DebugOverrides.js +143 -0
  5. package/core/Describe.js +14 -3
  6. package/core/Engine.js +44 -72
  7. package/core/Events.js +59 -1
  8. package/core/I18n.js +2 -2
  9. package/core/Inspect.js +12 -32
  10. package/core/InspectScene.js +7 -3
  11. package/core/MaterialInfo.js +32 -0
  12. package/core/Ops.js +43 -59
  13. package/core/Saves.js +5 -4
  14. package/core/UrlState.js +3 -2
  15. package/core/Vars.js +1 -0
  16. package/core/Views.js +49 -0
  17. package/core/actor.js +2 -2
  18. package/core/assetReport.js +83 -0
  19. package/core/catalog.js +169 -0
  20. package/core/checks.js +67 -0
  21. package/core/claims.js +51 -0
  22. package/core/debugView.js +76 -0
  23. package/core/describeRender.js +51 -0
  24. package/core/describeText.js +11 -4
  25. package/core/errorCodes.js +33 -0
  26. package/core/errorHints.js +6 -1
  27. package/core/grid.js +127 -0
  28. package/core/gridLoad.js +19 -0
  29. package/core/holds.js +106 -0
  30. package/core/lifecycle.js +1 -0
  31. package/core/lightWatch.js +23 -3
  32. package/core/look/coreParts.js +112 -0
  33. package/core/look/layers.js +136 -0
  34. package/core/look/part.js +173 -0
  35. package/core/look/report.js +79 -0
  36. package/core/look/write.js +86 -0
  37. package/core/loop.js +22 -16
  38. package/core/modules.js +19 -5
  39. package/core/opsAtomic.js +31 -0
  40. package/core/opsCheck.js +25 -14
  41. package/core/opsFail.js +20 -0
  42. package/core/opsHistory.js +6 -6
  43. package/core/opsRun.js +77 -0
  44. package/core/params.js +132 -0
  45. package/core/renamed.js +22 -0
  46. package/core/saveApply.js +2 -2
  47. package/core/sceneMethods.js +9 -34
  48. package/core/services.js +73 -0
  49. package/core/startup.js +3 -1
  50. package/core/styleParts.js +11 -9
  51. package/core/thingExplain.js +68 -0
  52. package/core/thingOps.js +35 -24
  53. package/core/things.js +15 -1
  54. package/core/util.js +11 -0
  55. package/core/validate.js +23 -7
  56. package/docs/AI.md +93 -114
  57. package/docs/API.md +8 -9
  58. package/docs/CODEMAP.md +67 -53
  59. package/docs/COMMANDS.md +21 -7
  60. package/docs/CONVENTIONS.md +22 -11
  61. package/docs/THREE.md +3 -3
  62. package/docs/api/assets.md +3 -0
  63. package/docs/api/characters.md +5 -2
  64. package/docs/api/collision.md +4 -0
  65. package/docs/api/content.md +1 -0
  66. package/docs/api/engine.md +23 -14
  67. package/docs/api/events.md +5 -1
  68. package/docs/api/post.md +5 -4
  69. package/docs/api/saves.md +2 -1
  70. package/docs/api/sky.md +3 -3
  71. package/docs/api/style.md +8 -8
  72. package/docs/api/tools.md +5 -2
  73. package/docs/api/vegetation.md +1 -0
  74. package/docs/api/weather.md +1 -1
  75. package/docs/recipes/01-new-game.md +41 -43
  76. package/docs/recipes/02-npc.md +38 -22
  77. package/docs/recipes/03-items-pickups.md +4 -4
  78. package/docs/recipes/04-quests.md +23 -23
  79. package/docs/recipes/05-props-bake.md +5 -5
  80. package/docs/recipes/06-clock-events.md +13 -0
  81. package/docs/recipes/07-flow-scenes-pause.md +6 -2
  82. package/docs/recipes/08-weather-sky.md +6 -6
  83. package/docs/recipes/09-style-pack.md +35 -100
  84. package/docs/recipes/12-navmesh.md +22 -0
  85. package/docs/recipes/13-animation.md +25 -6
  86. package/docs/recipes/14-custom-module.md +6 -7
  87. package/docs/recipes/15-perf.md +9 -1
  88. package/docs/recipes/16-dev-bridge.md +52 -18
  89. package/docs/recipes/18-world.md +5 -2
  90. package/docs/recipes/19-shooting-picking.md +9 -8
  91. package/docs/recipes/20-content-actions-save.md +10 -10
  92. package/docs/recipes/21-camera.md +51 -2
  93. package/docs/recipes/22-shop-gold.md +16 -16
  94. package/docs/recipes/23-ops.md +46 -10
  95. package/docs/recipes/27-net.md +3 -3
  96. package/docs/recipes/28-terrain.md +2 -2
  97. package/docs/recipes/29-grid.md +47 -27
  98. package/docs/recipes/34-environment-lighting.md +11 -10
  99. package/docs/recipes/35-style-from-reference.md +41 -46
  100. package/docs/recipes/36-sky-ground-plant-looks.md +22 -20
  101. package/docs/recipes/37-terrain-look-hooks.md +34 -13
  102. package/docs/recipes/38-environment-look-hooks.md +49 -42
  103. package/docs/recipes/40-scene.md +29 -0
  104. package/docs/recipes/41-thing-registry.md +29 -0
  105. package/docs/recipes/42-terrain-shape.md +1 -1
  106. package/docs/recipes/43-shader-patches-surface-looks.md +37 -20
  107. package/docs/recipes/44-water-weather-look-hooks.md +11 -9
  108. package/docs/recipes/45-cascaded-shadows.md +2 -2
  109. package/docs/recipes/46-blender-art-route.md +26 -4
  110. package/docs/recipes/47-island-snow-backdrop.md +4 -3
  111. package/docs/recipes/48-make-material.md +70 -0
  112. package/docs/recipes/49-game-module-contract.md +71 -0
  113. package/docs/recipes/50-own-renderer.md +12 -0
  114. package/docs/recipes/51-capability-catalog.md +63 -0
  115. package/docs/recipes/52-look.md +146 -0
  116. package/docs/recipes/53-ground-up-close.md +58 -0
  117. package/examples/action/GAMEMAP.md +7 -7
  118. package/examples/action/content/index.js +2 -1
  119. package/examples/action/content/views.js +6 -0
  120. package/examples/action/main.js +3 -2
  121. package/examples/sheepisland/GAMEMAP.md +3 -4
  122. package/examples/styletest/GAMEMAP.md +3 -3
  123. package/examples/styletest/content/npcs.js +1 -1
  124. package/examples/styletest/main.js +2 -2
  125. package/examples/styletest/panel.js +3 -3
  126. package/examples/world/GAMEMAP.md +3 -3
  127. package/examples/world/content/npcs.js +1 -1
  128. package/examples/world/main.js +1 -1
  129. package/index.d.ts +35 -2
  130. package/index.js +6 -3
  131. package/llms.txt +13 -7
  132. package/modules/ambience/Ambience.js +5 -2
  133. package/modules/camera/FirstPersonCamera.js +3 -5
  134. package/modules/camera/FixedCamera.js +19 -12
  135. package/modules/camera/FollowCamera.js +14 -8
  136. package/modules/camera/RtsCamera.js +3 -5
  137. package/modules/camera/common.js +40 -10
  138. package/modules/camera/index.js +1 -1
  139. package/modules/camera/projection.js +34 -0
  140. package/modules/characters/Character.js +45 -31
  141. package/modules/characters/assetModel.js +35 -7
  142. package/modules/characters/astar.js +14 -7
  143. package/modules/characters/index.js +6 -3
  144. package/modules/characters/movers/simple.js +6 -1
  145. package/modules/characters/npcSim.js +8 -2
  146. package/modules/characters/pathAsync.js +12 -6
  147. package/modules/characters/pathJob.js +2 -1
  148. package/modules/characters/proceduralRig.js +50 -11
  149. package/modules/characters/useModel.js +22 -0
  150. package/modules/characters/walkTo.js +58 -0
  151. package/modules/collision/Collision.js +102 -4
  152. package/modules/content/explain.js +13 -0
  153. package/modules/content/index.js +3 -1
  154. package/modules/content/loader.js +3 -0
  155. package/modules/content/rules.js +1 -0
  156. package/modules/debug/DebugPanel.js +11 -5
  157. package/modules/entities/Entities.js +6 -2
  158. package/modules/flow/index.js +5 -2
  159. package/modules/gameplay/Dialogue.js +5 -2
  160. package/modules/gameplay/Interactions.js +12 -2
  161. package/modules/gameplay/Inventory.js +21 -11
  162. package/modules/gameplay/Quests.js +13 -3
  163. package/modules/gameplay/pickups.js +6 -4
  164. package/modules/grid/Layer.js +1 -1
  165. package/modules/grid/index.js +1 -1
  166. package/modules/grid/tiles.js +9 -5
  167. package/modules/hlod/index.js +5 -2
  168. package/modules/hud/index.js +5 -2
  169. package/modules/level/index.js +5 -3
  170. package/modules/lights/index.js +5 -2
  171. package/modules/music/Music.js +6 -2
  172. package/modules/nav/index.js +5 -3
  173. package/modules/net/Client.js +4 -3
  174. package/modules/net/Host.js +2 -2
  175. package/modules/net/index.js +5 -3
  176. package/modules/particles/Particles.js +1 -1
  177. package/modules/photo/Photo.js +10 -7
  178. package/modules/rigid/RigidBodies.js +5 -2
  179. package/modules/settings/Settings.js +6 -3
  180. package/modules/settings/apply.js +2 -1
  181. package/modules/sky/Sky.js +21 -19
  182. package/modules/sky/cascades.js +6 -6
  183. package/modules/sky/domeLayers.js +1 -1
  184. package/modules/sky/environment.js +39 -13
  185. package/modules/sky/fog.js +9 -6
  186. package/modules/sky/frame.js +4 -3
  187. package/modules/sky/look.js +3 -2
  188. package/modules/sky/lookFog.js +80 -0
  189. package/modules/sky/lookShadow.js +50 -0
  190. package/modules/sky/lookSky.js +108 -0
  191. package/modules/sky/shader.js +2 -2
  192. package/modules/sky/shadow.js +4 -10
  193. package/modules/sky/skyModule.js +4 -3
  194. package/modules/terrain/ChunkManager.js +2 -33
  195. package/modules/terrain/chunkLevels.js +40 -0
  196. package/modules/terrain/index.js +10 -2
  197. package/modules/terrain/lookGround.js +61 -0
  198. package/modules/timeline/Timeline.js +7 -3
  199. package/modules/timeline/Tween.js +3 -7
  200. package/modules/timeline/shots.js +6 -4
  201. package/modules/triggers/index.js +9 -2
  202. package/modules/vegetation/Vegetation.js +17 -4
  203. package/modules/vegetation/index.js +7 -4
  204. package/modules/vegetation/lookWind.js +37 -0
  205. package/modules/vegetation/nearFade.js +39 -0
  206. package/modules/water/Water.js +19 -3
  207. package/modules/water/look.js +80 -0
  208. package/modules/weather/Weather.js +22 -31
  209. package/modules/weather/look.js +75 -0
  210. package/modules/weather/particles.js +1 -1
  211. package/modules/weather/strings.js +15 -0
  212. package/modules/world/explain.js +11 -0
  213. package/modules/world/index.js +11 -4
  214. package/modules/world/thingSource.js +44 -0
  215. package/package.json +2 -1
  216. package/render/PostFX.js +48 -51
  217. package/render/detail.js +39 -15
  218. package/render/effects.js +4 -2
  219. package/render/fuse.js +12 -0
  220. package/render/lights.js +4 -2
  221. package/render/lookSurface.js +161 -0
  222. package/render/materials.js +27 -10
  223. package/render/postLook.js +86 -0
  224. package/render/surface.js +3 -1
  225. package/types/core.d.ts +223 -29
  226. package/types/gameplay.d.ts +22 -6
  227. package/types/generated/core/DebugOverrides.d.ts +52 -0
  228. package/types/generated/core/Events.d.ts +43 -0
  229. package/types/generated/core/Ops.d.ts +62 -21
  230. package/types/generated/core/Saves.d.ts +1 -0
  231. package/types/generated/core/Views.d.ts +33 -0
  232. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  233. package/types/generated/modules/grid/Layer.d.ts +1 -0
  234. package/types/generated/modules/sky/Sky.d.ts +10 -17
  235. package/types/generated/modules/weather/Weather.d.ts +5 -15
  236. package/types/generated/render/PostFX.d.ts +20 -23
  237. package/types/generated/render/materials.d.ts +10 -0
  238. package/types/physics.d.ts +8 -0
  239. package/types/style.d.ts +35 -20
  240. package/types/world.d.ts +7 -1
  241. package/ui/Parts.js +6 -2
  242. package/ui/UI.js +1 -1
  243. package/ui/defaults.js +1 -1
  244. package/docs/api/debug.md +0 -10
@@ -57,6 +57,7 @@ Conditions are used in quest step done, dialogue option if and line variant if;
57
57
  - `props.js` props (list: model, position, facing, collision; or { template, x, z } = an instance of a template; or { id, grid, item, cell } = a grid item), streamed in on demand
58
58
  - `templates.js` reusable objects (name -> model, collide, interact, container, sound, animate, state defaults, physics body); shared read-only definitions
59
59
  - `audio.js` sounds by asset name, ambience and music rules as data, footsteps (sounds, ambience, music: { tracks, rules }, footsteps)
60
+ - `views.js` named fixed camera views (name -> { position: [x, y, z], target?: [x, y, z], fov? }); engine.views.show(name), ?view=name, npm run shot -- -w game --view name
60
61
  - `grids.js` placement grids (name -> { cell, origin, size, zone?, flat? }); layout rules, not saved
61
62
  - `renames.js` renamed or deleted authored ids (old id -> new id, or null = deleted on purpose): the player's saved changes follow the new id
62
63
  - `rules.js` condition words added by the game ({ conditions }); actions are ops, not effect words
@@ -2,14 +2,15 @@
2
2
 
3
3
  - `createEngine(opts: EngineOptions) → Engine` — Create an engine (core only). canvas is required; style is the style pack
4
4
  - Options `EngineOptions`:
5
- - `canvas: HTMLCanvasElement | HTMLElement` Canvas element (required), e.g. document.getElementById('view')
6
- - `style?: StyleInput` Style pack (looks only: materials, sky, lighting, post, UI look), e.g. import lowpoly from '@threedog/style-lowpoly', or a list of parts deep-merged left to right: [lowpoly, { sky: { sunSize: 600 } }]. Without one: neutral gray placeholders
5
+ - `canvas?: HTMLCanvasElement | HTMLElement` Canvas element (required unless renderer is given), e.g. document.getElementById('view')
6
+ - `renderer?: any` A ready three.js renderer (WebGLRenderer or compatible) to use instead of creating one; canvas then defaults to renderer.domElement. The engine configures (pixel ratio, size, tone mapping, shadows) only a renderer it created itself. WebGL is the fully supported path; WebGPU-style renderers may not run shader patches or post effects (recipe 48)
7
+ - `style?: StyleInput` Style pack (looks only: materials, sky, lighting, post, UI look), a pack you made or installed (import basePack from 'your-pack'), or a list of parts deep-merged left to right: [basePack, { sky: { sunSize: 600 } }]. Without one: neutral gray placeholders
7
8
  - `shadows?: boolean` Real-time shadows, default true
8
- - `shadowType?: 'basic' | 'pcf' | 'vsm'` Shadow filter: 'basic' (hard edge) / 'pcf' / 'vsm' (softest, costliest), default 'pcf'. Change later with engine.sky.setShadow({ type })
9
+ - `shadowType?: 'basic' | 'pcf' | 'vsm'` Shadow filter: 'basic' (hard edge) / 'pcf' / 'vsm' (softest, costliest), default 'pcf'. Change later with engine.look.shadow.set({ type })
9
10
  - `antialias?: boolean` MSAA anti-aliasing (kept with post effects on), default style.antialias, else on for desktop and off for low-tier devices
10
11
  - `post?: Record<string, boolean>` Turn style post effects on or off by name at startup, e.g. { bloom: false }; default: each effect's own setting (costly ones off on low-tier devices)
11
- - `pixelRatio?: number` Render resolution, default min(device pixel ratio, 1.5)
12
- - `adaptiveResolution?: boolean` Automatically lower resolution when the frame rate is too low, default true
12
+ - `pixelRatio?: number` Render resolution, default min(device pixel ratio, 1.5); the low tier uses at least 0.75 x device pixel ratio (never below 1). describe().render.scale reports it
13
+ - `adaptiveResolution?: boolean` Automatically lower resolution when the frame rate is too low, default true. Never silent: a dev warning once, and describe().render.scale.autoLowered
13
14
  - `targetFps?: number` Target frame rate for automatic resolution lowering, default 55
14
15
  - `ui?: Record<string, UIPartValue>` UI parts: replace or turn off any piece of screen UI (loading, toast, title, hud.marker, hud.counter, hud.bar). Default title screen is off. Example: `createEngine({ canvas, ui: { loading: { title: 'My Game' }, title: { title: 'My Game' }, toast: false } })`
15
16
  - `audio?: AudioConfig` Volume of each channel, 0–1
@@ -31,10 +32,13 @@
31
32
  - `movement?: Partial<MovementProfile>` Shared "can walk there" parameters (meters / degrees): collision, the Rapier capsule, navigation and level steps all read them by default. Default { radius: 0.4, height: 1.8, maxSlope: 48, stepHeight: 0.45 }
32
33
  - `threads?: 'auto' | number | false` (experimental) Worker pool size for engine.threads: 'auto' (default: cores - 1, at most 4), a worker count, or false (all on the main thread, same results, no workers created)
33
34
  - `pauseOnBlur?: boolean` Gameplay waits while the window is in the background or the tab is hidden; default true (engine.page)
35
+ - `lights?: boolean` false: no default lights in the scene at all (engine.lights.sun / hemi still exist, detached, so sky and describe never see undefined); the game adds its own. Default true
34
36
  - `batching?: false | BatchingOptions` Automatic instancing of repeated static models (engine.batching): false turns it off; default { minCount: 8, cell: engine.stream.cellSize }
35
37
 
36
38
  ## engine methods
37
39
  - `engine.actorPosition(id?: string) → { x, y, z } | null` — Where an actor is now (default engine.actor): the player's position for 'player' (engine.focus without a player), else its model or world record position; null when unknown. Example: `engine.actor = 'boat_1'; engine.actorPosition()`
40
+ - `engine.catalog(id?: string | { find?: string }) → any` — What this game can do, read from the existing registrations (modules, ops, save parts, describe, params schemas). No argument: short list; a module id / op name: that entry expanded (null if unknown); { find }: the short list filtered. recipes/51-capability-catalog.md. Example: `engine.catalog('shop').ops[0].failures // ['soldOut', 'noMoney']`
41
+ - `engine.takeCamera(owner: string | ({ owner: string } & Partial<CameraOverride>), opts?: Partial<CameraOverride>) → OwnerHandle` — Take the camera over (camera modules leave it alone) until remove(); the latest holder is in charge, releasing hands it back to the previous one
38
42
  - `engine.setCamera(kind: CameraKind, opts?: object) → CameraRig` — Switch the camera at runtime (only exists with a camera module installed): the target and horizontal heading carry over; the first-person camera hides the character body automatically (the shadow stays) and locks / releases the mouse; the camera switched out is kept, with its parameters, for switching back. Passing opts rebuilds this kind of camera with the new parameters. A wrong kind throws and lists the available options. Example: `engine.onFrame(() => { if (engine.input.pressedRaw('toggleView')) engine.setCamera(engine.cameraRig.kind === 'follow' ? 'firstPerson' : 'follow'); });`
39
43
  - `engine.use(...mods: ModuleInput[])` — Install one or more modules (in order; dependencies must be installed first)
40
44
  - `engine.has(name: string) → boolean` — Whether a module is installed
@@ -56,20 +60,21 @@
56
60
  - `engine.setPixelRatio(p: number)` — Render resolution
57
61
  - `engine.setShadows(on: boolean)` — Shadow toggle
58
62
  - `engine.setFogFar(d: number)` — Fog distance (meters), also adjusts the camera far plane
59
- - `engine.setToneMapping(kind: 'aces' | 'agx' | 'neutral' | 'none')` — Tone mapping at run time ('aces' / 'agx' / 'neutral' / 'none'); materials recompile on their next draw, so not every frame
60
- - `engine.setExposure(v: number | [number, number][] | ((sky: any) => number))` — Exposure at run time: a number, [[time 0-1, exposure], ...] over the day or (sky) => number (both evaluated by the sky module each frame); replaces style.exposure. Example: `engine.setExposure(1.4); engine.setExposure(sky => sky.isDay ? 1 : 1.5);`
61
63
  - `engine.raycast(origin: Vec3Like, dir: Vec3Like, opts?: RaycastOptions) → RayHit | null` — Ray: shoot from origin along dir, returns the nearest hit or null (by default only registered static objects are hit)
62
64
  - `engine.pick(ndcX: number, ndcY: number, opts?: RaycastOptions) → RayHit | null` — Shoot a ray through the camera from screen coordinates (-1..1, e.g. input.pointer.ndcX/ndcY)
63
65
  - `engine.spawn(name: string, at: any, fields?: { id?, rot?, scale?, y?, items?, … }) → import('./generated/modules/world…` — New runtime instance of a content template (inside an op or fixed step), saved whole; returns the world record (kind = template name). Needs content(). e.g. engine.spawn('chest', { x: 10, z: 4 }, { opened: true })
64
66
  - `engine.applyState(params: StateParams) → Promise<void>` — Set up a scenario: time of day, weather, player position, load a save, advance time, skip cutscenes; emits state:applied when done
65
67
  - `engine.defineState(name: string, params: StateParams)` — Name a group of scenario parameters, then use applyState({ state: name }) or URL ?state=name
66
68
  - `engine.start() → Promise<this>` — Start: initialize modules, preload assets, wait for the world to be ready
67
- - `engine.pause()` — Pause the real-time loop: the picture stops and even rendering stops, only step() advances (for tests and screenshots). Use freeze() for a game menu pause
68
- - `engine.resume()` — Resume the real-time loop
69
- - `engine.freeze(owner?: string)` — Gameplay pause (menu, flow's paused): fixed steps are skipped entirely (onFixed, module fixed, the game clock and engine.elapsed all stop), frame hooks and rendering continue and the UI works. So gameplay logic (movement, timing, quest checks, cutscene waits) belongs in fixed, or check engine.frozen first in frame. owner is the freezer's name, default 'game'
70
- - `engine.unfreeze(owner?: string)` — Release the freeze of owner (gameplay resumes only when all freezers are released)
69
+ - `engine.pause(owner?: string | { owner?, kind? }, opts?: { kind?: 'test' }) → ChainedHandle` — Pause the real-time loop: the picture stops and even rendering stops, only step() advances (for tests and screenshots). Use freeze() for a game menu pause
70
+ - `engine.resume(owner?: string | { owner?: string })` — Resume the real-time loop (only this owner's pause)
71
+ - `engine.nextFixed(fn: () => T) → Promise<T>` — Run fn at the start of the next fixed step (via commits); a Promise of fn's value
72
+ - `engine.freeze(owner?: string | { owner?, kind? }, opts?: { kind?: 'title' }) → ChainedHandle` — Gameplay pause (menu, flow's paused): fixed steps are skipped entirely (onFixed, module fixed, the game clock and engine.elapsed all stop), frame hooks and rendering continue and the UI works. So gameplay logic (movement, timing, quest checks, cutscene waits) belongs in fixed, or check engine.frozen first in frame. owner is the freezer's name, default 'game'
73
+ - `engine.unfreeze(owner?: string | { owner?: string })` — Release the freeze of owner (gameplay resumes only when all freezers are released)
71
74
  - `engine.step(seconds: number, opts?: { render?, frameEvery?, describe? }) → GameState | null` — Advance seconds of fixed-step time synchronously; seconds must be a finite number >= 0: 0 advances nothing (no step, no render), negative or non-finite throws (code step-seconds), any positive value runs at least one fixed step (60Hz; when timeScale is not 1, game seconds clock.now and sky time of day run faster or slower than it; frame hooks run once every frameEvery fixed steps, default 2; describe: false returns null instead of building describe()). jobs ignore real time and finish every frame; results of stream's synchronous build are attached to the scene before returning. When render is true (default) one frame is rendered at the end. Returns the describe() result after advancing
72
75
  - `engine.skip(opts: SkipOptions) → Promise<{ seconds: number; clock:…` — Skip game time forward (sleep until morning, wait an hour) without stepping every fixed step. clock.after / every, sky.at / daily / between, day:start and season:change fire in time order as if stepped (each crossing once); world records with far catch up the span in one far(rec, dt). onFixed, module fixed hooks, physics and near simulation do not run; engine.elapsed does not move. Input is locked and gameplay frozen during the skip; emits time:skip. fade 0 (default): the time has moved when skip returns. fade > 0: fade out, jump, save, fade in; the Promise resolves after the fade in (it needs frames). session.newGame / load / quit cancel a running skip: it resolves null. Example: `await engine.skip({ to: '06:00' })`
76
+ - `engine.checkSkip(seconds: number, opts?: { ignore?: string[] }) → Promise<{ ok: boolean; diffs: { p…` — Consistency check: engine.skip({ seconds }) vs stepping the same span in fixed steps; compares the saved state. Leaves the world at the stepped state (use a scratch playthrough or a test). Example: `const r = await engine.checkSkip(600); if (!r.ok) console.log(r.diffs);`
77
+ - `engine.checkSave(opts?: { ignore?: string[] }) → Promise<{ ok: boolean; diffs: { p…` — Consistency check: save -> load gives the same saved state back (nothing is written to the browser). Example: `const r = await engine.checkSave(); if (!r.ok) console.log(r.diffs);`
73
78
  - `engine.describeText(opts?: { radius?, full?, path? }) → string` — The same information as English text, summary first: at most 30 lines (standard lines, the 5 nearest things, one line per module with its key counts), ending with how to expand. { path: 'world.byKind' } returns one part of describe() as JSON; { full: true } returns everything (all nearby things, every module's full data). Example: `engine.describeText() engine.describeText({ path: 'quests' }) engine.describeText({ full: true })`
74
79
  - `engine.explain(q: { op, args?, actor? } | Record<string, any>) → { ok, reason?, text, detail?, recent?, events?, … }` — Why something is the way it is. { op, args?, actor? }: text says whether it can run now, and if not the reason and the op's note on fixing it (reason first); detail has the last attempt and the events around it; recent / events are the raw last 5 attempts and event names within a step of the last one. Other keys are answered by modules (definition field explain: { key(e, value, query) { return { ok, text } } }); the quests module answers { quest: id }. Example: `engine.explain({ op: 'shop.buy', args: { shop: 'bakery', item: 'bread' } }).text // 'shop.buy {...} cannot run now: noMoney (Not enough gold)'`
75
80
  - `engine.profile(on: boolean)` / `profile() → Record<string, number> | null` — Module hook timing: pass true to turn on, false to turn off (returns the engine); with no argument returns { moduleName: average milliseconds per rendered frame } and resets, or null when not on
@@ -86,7 +91,7 @@
86
91
  - `camera: import('three').PerspectiveCamera` three.js perspective camera
87
92
  - `focus: Vector3` Camera focus, updated every frame by the camera module: terrain, models etc. load around it. The center of gameplay simulation is world.anchor (the player by default), which does not follow the camera
88
93
  - `shadows: boolean` Whether shadows are on
89
- - `shadowType: 'basic' | 'pcf' | 'vsm'` Shadow filter in use; change it with sky.setShadow({ type })
94
+ - `shadowType: 'basic' | 'pcf' | 'vsm'` Shadow filter in use; change it with look.shadow.set({ type })
90
95
  - `ground: Ground` Current ground
91
96
  - `movement: Readonly<MovementProfile>` Shared parameters for whether a character can walk somewhere (set by createEngine({ movement }), read-only); same-named options of individual modules are only overrides
92
97
  - `player: Character | null` The player (exists only after characters.createPlayer()). Its position belongs to the character's mover: other systems request movement (placeAt / move / vehicle enter), don't modify position directly
@@ -112,11 +117,13 @@
112
117
  - `assets: Assets` Assets
113
118
  - `loading: Loading` Observable loading: every asset load, module init / isReady and track() step as a task (phase, error, source manifest)
114
119
  - `post: PostFX` Post-processing: named effects in slots (add / get / enable / list)
120
+ - `look: Look` Every look in one place: engine.look.<part>.set / patch / replace (recipes/52-look.md)
115
121
  - `ui: UIParts` UI parts: every piece of screen UI is replaceable or off (see recipes/26-ui-parts.md)
116
122
  - `adaptive: AdaptiveState` Automatic resolution state
117
123
  - `cpuMs: number` Main-thread CPU milliseconds of the last real-time frame: input, fixed steps, frame hooks, render submission and afterRender hooks (not GPU time, not the wait for the next frame). Only the real-time loop updates it; step() does not.
118
124
  - `cpuPhases: { fixed, frame, render, afterRender }` cpuMs split by phase (last frame): fixed = input + fixed steps, frame = frame hooks incl. stream / jobs, render = draw submission, afterRender = its hooks
119
- - `cameraOverride: CameraOverride | null` Camera takeover (for cutscenes), null when unused
125
+ - `cameraOverride: CameraOverride | null` The camera holder in charge (latest engine.takeCamera claim), null when nobody holds it. Assigning { owner } / null is the old alias of takeCamera
126
+ - `runState: RunState` Why the page is (not) advancing; the dev bridge and MCP tools copy it as-is
120
127
  - `decoders: string` Draco/KTX2 decoder directory
121
128
  - `clock: Clock` Game clock: game seconds now, after / every (clock-time / season timers are on engine.sky)
122
129
  - `vars: Vars` Story flags and counters (autosaved)
@@ -126,6 +133,7 @@
126
133
  - `commits: Commits` Background results that affect gameplay take effect on a fixed tick (chunk collision, spread jobs with apply...), see Commits
127
134
  - `threads: Threads` (experimental) Worker pool (createEngine({ threads })): lane() for your own worker script, pure() for self-contained functions, array() for shared typed arrays. Results that affect gameplay go through commits
128
135
  - `ops: Ops` One entry point for actions players and NPCs decide to do: define / run / can / list / recent, see Ops and recipes/23-ops.md
136
+ - `views: Views` Named fixed camera views for repeatable screenshots: define / show / release (recipes/46-blender-art-route.md)
129
137
  - `tick: number` Fixed-step count (the gameplay timeline: does not advance while frozen; commits due times, event history and the operation log use it)
130
138
  - `random: Random` Seeded random numbers (use for gameplay randomness: reproducible and saved with the game)
131
139
  - `stream: Stream` Spatial stream-in and the stream sources (where the world is loaded: terrain, colliders, models, stream entries; built-in player and camera sources, add one for a teleport destination)
@@ -134,7 +142,8 @@
134
142
  - `elapsed: number` Run seconds: unaffected by the sky time scale, does not advance while frozen or paused; for presentation animation (swaying, floating). The other two "times": game seconds engine.clock.now (= fixed-step seconds x clock.timeScale, saved); sky time of day engine.sky.timeOfDay (0–1, one day = dayLength game seconds)
135
143
  - `uniforms: EngineUniforms` This engine's shader uniforms, read by the built-in effects (wind, clouds, season, water, sky, rain). Share these objects in your own ShaderMaterial or patch instead of making your own uTime. Weather and sky write them; uTime follows engine.elapsed. Example: `new THREE.ShaderMaterial({ uniforms: { uTime: engine.uniforms.uTime }, vertexShader, fragmentShader });`
136
144
  - `waterLevel: number` Global water level (meters); -Infinity when there is no water
137
- - `exposureDriver: ((sky: any) => number) | null` Exposure per frame from style.exposure / setExposure keyframes or function, null for a plain number; the sky module calls it with engine.sky
145
+ - `debug: DebugOverrides & { panel: DebugPanel | null }` Diagnostic overrides and view modes with an owner (override / clear / view: core, always there); panel is the F3 panel, null without the debug() module
146
+ - `exposureDriver: ((sky: any) => number) | null` Exposure per frame from style.exposure / look.tone keyframes or function, null for a plain number; the sky module calls it with engine.sky
138
147
  - `stateApplied: boolean` Scenario is ready: start() completed, and the URL parameters / the latest applyState have all been applied. Tests and screenshots wait for it: page.waitForFunction(() => window.engine?.stateApplied)
139
148
  - `headless: boolean` Whether in headless mode (createEngine({ headless: true }))
140
149
  - `paused: boolean` Whether paused (headless mode is paused by default, only step() advances)
@@ -1,11 +1,15 @@
1
1
  # engine.events (Events) — engine.events: the event bus; modules "shout" and whoever cares listens
2
2
 
3
+ - `events.traceFocus(id: string | null)` — Verbose trace for one object (needs traceSize > 0): perception queries and state checks that name `obj` === id are recorded in full (misses too), the rest of the world only records what changed. null clears. For "why did this guard not see me": traceFocus('guard-1'), play, then read trace('sight'). Example: `engine.events.traceSize = 300; engine.events.traceFocus('guard-1');`
4
+ - `events.note(name: string, info?: { code?, obj?, data?, verbose?, parent? }) → string | null` — Add one entry to the cause trace (no-op while traceSize is 0; check `events.traceSize > 0` first to skip building info). Returns its parent id (`ev:<n>`) to pass as info.parent of follow-ups, or null. info: code (failure code), obj (world record id it is about), data (small plain values), verbose (true = only recorded while traceFocus(obj)), parent (default: the event or op running now). The engine notes failed ops (`op:<name>`), collision.lineClear (`sight`) and NPC state changes (`npc:state`); a game's behaviors can note their own, e.g. 'npc:mode' patrol -> investigate. Example: `if (e.events.traceSize > 0) e.events.note('npc:mode', { obj: rec.id, data: { from: 'patrol', to: 'investigate' } });`
5
+ - `events.trace(name?: string) → { id, tick, name, parent, chain, code?, … }[]` — Cause chains (needs traceSize > 0): each emitted event is recorded with parent = the event (`ev:<id>`) or op (`op:<name>#<seq>`) whose handler emitted it, null when it came from outside any. chain lists the causes from the nearest to the root (as far as the ring still holds). For "why did this fire". Example: `engine.events.traceSize = 200; engine.ops.run('shop.buy', { item: 'bread' }); engine.events.trace('item:add').at(-1).chain; // ['op:shop.buy#12']`
3
6
  - `events.recent(name?: string) → { tick, name, data }[]` — Recent events (old -> new); with name, only that kind: { tick = which fixed step, name, data = summary (simple values only; objects become '…') }. For "why did it not fire", first check whether it happened at all. Example: `engine.events.recent('item:add');`
4
7
  - `events.on(name: K, fn: (args) => void) → Handle` — Listen to an event; returns a handle { remove() }. Example: `const h = engine.events.on('item:add', ({ id, count }) => console.log(id, count)); h.remove();`
5
8
  - `events.once(name: K, fn: (args) => void) → Handle` — Listen once; returns a handle { remove() } (can be removed before it fires)
6
9
  - `events.emit(name: K, ...args: EventArgs<K & string>)` — Emit an event. Example: `engine.events.emit('item:add', { id: 'fish', count: 1 });`
7
10
  - Properties:
8
11
  - `historySize: number` How many history entries to keep, default 200; 0 records nothing
12
+ - `traceSize: number` Cause trace ring size, default 0 = off (no cost). Set e.g. 200 in dev to record which event or op caused which follow-up event; read with trace()
9
13
 
10
14
  ## Event table (engine.events.on(name, (args…) => …), the [] lists the callback arguments)
11
15
  - `engine:ready` [] Loading finished; the world is playable
@@ -74,7 +78,7 @@
74
78
  - `net:open` [{}] Client (net): connected to the host (the first snapshot follows)
75
79
  - `net:close` [{}] Client (net): connection lost
76
80
  - `net:sync` [{ tick: number; full: boolean }] Client (net): host state applied (full: a whole snapshot, else a diff); redraw UI from state here
77
- - `net:result` [{ seq: number; name: string; ok: boolean; reason: string | null; val… Client (net): the host's answer to an op request (seq from ops.run's return value; tick is the host's), sent after the state it caused
81
+ - `net:result` [{ seq: number; name: string; ok: boolean; code: string | null; value… Client (net): the host's answer to an op request (seq from ops.run's return value; tick is the host's), sent after the state it caused
78
82
  - `engine:error` [EngineError] A gameplay error in development / testing; gameplay is frozen (error severity levels, see engine.error)
79
83
  - `module:disabled` [{ name: string; message: string }] A presentation module errored and was disabled (the game continues)
80
84
  - `vehicle:enter` [{ character: Character; vehicle: Vehicle }] A character boarded a vehicle
package/docs/api/post.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # engine.post (PostFX)
2
2
 
3
- - `post.add(effect: PostEffect, { slot, order, enabled }?: { slot?, order?, enabled? }) → PostHandle` — (experimental) Add a named effect; returns its handle. Slot and order come from the effect unless given here. Example: `import { RenderPixelatedPass } from 'three/addons/postprocessing/RenderPixelatedPass.js'; const pixels = engine.post.add({ name: 'pixelate', slot: 'scene', params: { size: 4 }, create: ({ scene, camera, width, height, params }) => new RenderPixelatedPass(params.size, scene, camera), update: (pass, p) => pass.setPixelSize(p.size) }); pixels.set({ size: 6 }); pixels.enable(false); pixels.remove();`
4
- - `post.get(name: string) → PostHandle | undefined` — (experimental) Handle of an added effect, or undefined: engine.post.get('bloom')?.set({ strength: 0.6 })
5
- - `post.enable(name: string, on: boolean) → boolean` — (experimental) Turn an effect, or 'antialias' (MSAA), on or off; false (and a dev warning naming the effects) when no such effect is added. Example: `engine.post.enable('bloom', false); engine.post.enable('antialias', true);`
3
+ - `post.add(_effect: PostEffect, _opts?: { slot?, order?, enabled? }) → never` — (experimental) Renamed in 0.2: throws and names the new call (engine.look.post.patch / engine.look.post.replace, recipes/52-look.md)
4
+ - `post.get(name: string) → PostHandle | undefined` — (experimental) Read-only record of an added effect (name, slot, order, enabled, params), or undefined. Change one with engine.look.post.set({ 'bloom.strength': 0.6 })
5
+ - `post.enable(_name: string, _on: boolean) → never` — (experimental) Renamed in 0.2: throws and names the new call (engine.look.post.set({ 'bloom.enabled': on }); MSAA: engine.post.setAntialias(on))
6
+ - `post.setAntialias(on: boolean)` — (experimental) Turn MSAA (antialiasing of the post chain) on or off. It is a render target setting, not a look part. Example: `engine.post.setAntialias(false);`
6
7
  - `post.list() → { name, slot, order, enabled }[]` — (experimental) Effects in render order: [{ name, slot, order, enabled }]
7
8
  - Properties:
8
- - `antialias: boolean` MSAA on (read-only; switch with post.enable('antialias', on))
9
+ - `antialias: boolean` MSAA on (read-only; switch with post.setAntialias(on))
9
10
  - `active: boolean` Whether any post work runs (antialias or an enabled effect)
package/docs/api/saves.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # engine.saves (Saves) — engine.saves handles saving
2
2
 
3
- - `saves.register(key: string, provider: SaveProvider)` — Register "how to save and load"; key is this part's name in the save. Parts with first: true load first (the level); a load returning a Promise makes later parts wait. version (default 1): raise it by 1 whenever what save() returns changes shape, and add migrate[oldVersion] = data => newData; load sees only the current shape. A save whose part is newer than this build's version is refused as a whole (load returns false, the save is kept). A part registered after a save was loaded (a module installed later) is handed its data from that save at once. Example: `engine.saves.register('garden', { save: () => garden.toJSON(), load: d => garden.fromJSON(d) }); // later the format gains beds: version 2, and a step that upgrades version-1 data engine.saves.register('garden', { version: 2, migrate: { 1: d => ({ ...d, beds: [] }) }, save: () => garden.toJSON(), load: d => garden.fromJSON(d) });`
3
+ - `saves.register(key: string, provider: SaveProvider)` — Register "how to save and load"; key is this part's name in the save. Parts with first: true load first (the level); a load returning a Promise makes later parts wait. version (default 1): raise it by 1 whenever what save() returns changes shape, and add migrate[oldVersion] = data => newData; load sees only the current shape. A save whose part is newer than this build's version is refused as a whole (load returns false, the save is kept). A part registered after a save was loaded (a module installed later) is handed its data from that save at once. atomic: true joins this part to atomic ops: it is copied before an atomic op runs and put back if the op fails (plain data only; afterLoad does not run on rollback). Example: `engine.saves.register('garden', { save: () => garden.toJSON(), load: d => garden.fromJSON(d) }); // later the format gains beds: version 2, and a step that upgrades version-1 data engine.saves.register('garden', { version: 2, migrate: { 1: d => ({ ...d, beds: [] }) }, save: () => garden.toJSON(), load: d => garden.fromJSON(d) });`
4
4
  - `saves.queue(fn: () => Promise<T>) → Promise<T>` — Queue a disk write (runs in call order once storage is ready; flush waits for it; used by attachments such as photos).
5
5
  - `saves.flush() → Promise<void>` — Wait for all queued disk writes to finish (for tests and before the page closes)
6
6
  - `saves.collect() → { format, savedAt, versions, parts }` — Collect the data of every part (does not write to the browser): { format, savedAt, versions, parts }. A part whose save() throws is left out and reported (engine.error in dev); save() instead refuses to write such a save.
@@ -27,5 +27,6 @@
27
27
  - `save: () => any`
28
28
  - `load: (data: any) => void | Promise<void>`
29
29
  - `first?: boolean` Load before the other parts (such as the level)
30
+ - `atomic?: boolean` Join atomic ops: copied before an atomic op runs, put back if it fails (plain data; afterLoad does not run on rollback)
30
31
  - `version?: number` This part's format version, default 1: raise it by 1 when what save() returns changes shape. A save with a newer version is refused
31
32
  - `migrate?: Record<number, (data: any, save: { parts: Record<string, an…` Upgrade steps: old version -> data => data in the next version's shape, e.g. { 1: d => ({ ...d, beds: [] }) }. The second argument is the whole save as read ({ parts, versions }, read only), for a step that depends on another part
package/docs/api/sky.md CHANGED
@@ -19,9 +19,9 @@ Sky, day/night, calendar (sky() module)
19
19
  - `sky.between(from: string | number, to: string | number, opts: SkyBetweenOptions) → Handle` — Time-range switch: on() while clock time is in [from, to), otherwise off() (from > to wraps midnight). Aligns once immediately on registration, new game, load, applying a scenario and time rewind; afterwards it calls on/off when crossing a boundary. Example: `engine.sky.between('18:00', '06:00', { on: () => lamp.on(), off: () => lamp.off() })`
20
20
  - `sky.daily(fn: (day: number) => void, opts?: SkyAtOptions) → Handle` — Call fn(day) at the start of each day (00:00)
21
21
  - `sky.onSeason(name: string, fn: (season: string) => void) → Handle` — Call fn(seasonName) on entering season name
22
- - `sky.setShadow(opts?: Partial<SkyShadowParams>)` — Change shadow params (only the given fields): bias / normalBias prevent banding; updateEvery updates shadows every N frames (1 = every frame); snap snap = shadow center snap grid (meters, or 'texel' to snap to shadow pixels); ahead = meters to shift the shadow center in front of the view; type = 'basic' (hard edge) / 'pcf' / 'vsm' (soft, costlier; switching rebuilds the shadow map and recompiles materials, so do it rarely); radius = edge softness (pcf, vsm; no effect on basic); blurSamples = blur quality (vsm only); cascades 2-4 = cascaded shadows, 1 = off (recipes/45)
22
+ - `sky.setShadow(_opts?: Partial<SkyShadowParams>) → never` — Renamed in 0.2: throws and names the new call, engine.look.shadow.set(opts) (fields: bias, normalBias, updateEvery, snap, ahead, type, radius, blurSamples, cascades; recipes/45)
23
23
  - `sky.setShadowMapSize(n: number)` — Change shadow resolution (raise temporarily for photo mode)
24
- - `sky.setEnvironment(opts?: { source?, intensity?, rotation?, interval? } | null)` — Environment lighting (scene.environment), separate from the background and off by default. source 'sky' builds it from the procedural sky (rebuilt at most every `interval` seconds, only when the sky changed); an asset name or path (.hdr, .jpg, .ktx2) is an equirectangular panorama. intensity scales the light (default 1), rotation turns it around Y (radians). Given fields change, the rest stay; null turns it off. Lambert surfaces get soft ambient light from it (no reflections); lower the hemisphere ambient when you turn it on (recipes/09). Example: `engine.sky.setEnvironment({ source: 'sky', intensity: 0.8 }); engine.sky.setEnvironment(null);`
24
+ - `sky.setEnvironment(_opts?: { source?, intensity?, rotation?, interval? } | null) → never` — Renamed in 0.2: throws and names the new call, engine.look.env.replace(source) then engine.look.env.set({ intensity, rotation, interval })
25
25
  - Properties:
26
26
  - `timeOfDay: number` Sky time of day: 0-1 (0 midnight, 0.25 6am, 0.5 noon, 0.75 6pm); one day = dayLength game seconds (the unit of engine.clock.now). Fixed-step seconds (unaffected by timeScale) are engine.elapsed
27
27
  - `dayLength: number` Game seconds per day (1 sky hour = dayLength / 24 game seconds; at timeScale 1 game seconds equal fixed-step seconds); Infinity = the time of day never moves
@@ -33,7 +33,7 @@ Sky, day/night, calendar (sky() module)
33
33
  - `sun: any` Sun directional light (engine.lights.sun driven by the sky; moonlight at night, shadows live on it)
34
34
  - `sunDir: THREE.Vector3` Sun direction (unit vector toward the sun)
35
35
  - `orbit: { tilt: number; sway: number; distance: number }` Sun orbit: tilt = north-south tilt, sway = east-west swing, distance = light distance (meters)
36
- - `shadow: SkyShadowParams` Current shadow params (change via setShadow)
36
+ - `shadow: SkyShadowParams` Current shadow params (change via look.shadow.set)
37
37
  - `csm: any` three's CSM (addons/csm) while shadow.cascades > 1, else null; its lights[0] is sun (recipes/45)
38
38
  - `hoursPerDay: number` Hours per day
39
39
  - `modifiers: SkyModifiers` Composite of all modifier layers (read-only; use modify to adjust brightness)
package/docs/api/style.md CHANGED
@@ -1,24 +1,24 @@
1
- # Style pack Style — createEngine({ style }), all the look (example: @threedog/style-lowpoly, packages/styles/lowpoly/index.js)
1
+ # Style pack Style — createEngine({ style }), all the look (any style pack: a folder with index.js; recipes/09-style-pack.md)
2
2
 
3
3
  - **Style** fields (all optional):
4
4
  - `name?: string` Style pack name
5
- - `exposure?: number | number[][] | ((sky: any) => number)` Exposure, default 1 (lowpoly: 1.05): a number, or over the day [[time 0-1, exposure], ...] (sorted, wraps across midnight) or (sky) => number, evaluated by the sky module every frame. engine.setExposure changes it at run time. Example: `exposure: [[0, 1.6], [0.3, 1], [0.75, 1.1]] // brighter nights`
6
- - `toneMapping?: Loose<'aces' | 'agx' | 'neutral' | 'none'>` Tone mapping, default 'neutral' (lowpoly: 'aces')
5
+ - `exposure?: number | number[][] | ((sky: any) => number)` Exposure, default 1: a number, or over the day [[time 0-1, exposure], ...] (sorted, wraps across midnight) or (sky) => number, evaluated by the sky module every frame. engine.look.tone.set changes it at run time. Example: `exposure: [[0, 1.6], [0.3, 1], [0.75, 1.1]] // brighter nights`
6
+ - `toneMapping?: Loose<'aces' | 'agx' | 'neutral' | 'none'>` Tone mapping. Engine default 'none' (no style pack, no tone mapping); the style pack picks the look
7
7
  - `background?: ColorLike` Background color (when there is no sky module)
8
8
  - `post?: (Omit<import('./generate… & { slot? })[]` Post effects registered at startup, in any order (slot and order decide where each runs), e.g. [outline({ enabled: true }), bloom()] from '@threedog/post-effects'
9
9
  - `materials?: Record<string, MaterialSpec | import('three').Material | ((…` Material per role (default, terrain, vegetation, character, water, building, pickup…): a spec, a three.js Material instance (cloned per use), or a function (params, purpose) => Material
10
10
  - `antialias?: boolean` Anti-aliasing: true = MSAA (also inside post-processing), false = off (pixel art, sharp edges). Default: on for desktop, off for low tier; createEngine({ antialias }) wins
11
11
  - `lighting?: MaterialLighting` Light shaping for every lit material of the pack (shadow tint, rim, wrap, glsl); a material's `lighting` wins, `lighting: false` opts out
12
12
  - `seasons?: StyleSeasons` Seasonal tint: { spring: { foliage, ground }, ... }. mode 'multiply' (default) multiplies the color onto the surface (pick tints near white: orange times green is muddy); 'mix' moves the surface `strength` (0-1, default 0.5) of the way to the color. Season names are the other keys, so none can be called mode or strength
13
- - `clouds?: { shadow?: number; scale?: number; speed?: number[] }` Cloud shadow: shadow darkest level 0–1 (default 0 = no cloud shadows; lowpoly 0.55), scale cloud size (smaller means bigger clouds), speed [x, z]
14
- - `palette?: Record<string, ColorLike>` Named colors the procedural model generators read (trees, rocks, grass: a generator written with `function` gets them as this.palette; lowpoly keys: bark, pine, leaf, rock, grassTip...). One place to retint all of them, e.g. style: [lowpoly, { palette: { leaf: 0xd98a3a } }]; keys left out keep the pack's values
13
+ - `clouds?: { shadow?: number; scale?: number; speed?: number[] }` Cloud shadow: shadow darkest level 0–1 (default 0 = no cloud shadows), scale cloud size (smaller means bigger clouds), speed [x, z]
14
+ - `palette?: Record<string, ColorLike>` Named colors the procedural model generators read (trees, rocks, grass: a generator written with `function` gets them as this.palette; a pack may use keys like bark, pine, leaf, rock, grassTip...). One place to retint all of them, e.g. style: [basePack, { palette: { leaf: 0xd98a3a } }]; keys left out keep the pack's values
15
15
  - `wind?: StyleWind` Wind: frequency sway frequency multiplier
16
16
  - `terrain?: StyleTerrain` Terrain colors etc.
17
17
  - `sky?: StyleSky` Sky
18
18
  - `weather?: StyleWeather` Weather look
19
19
  - `water?: StyleWater` Water look
20
20
  - `pickup?: { color?, size?, lift?, model? }` Default look of pickups on the ground: color (the item's own color wins), size (meters), lift height above ground (meters), model(item, { color, size }, engine) builds the shape (a geometry gets materials.pickup; make materials with engine.makeMaterial; without model a plain box)
21
- - `character?: { model?, colors?, create?, animation? }` Default character: colors palette; create(engine, colors) returns the procedural character (without it a gray capsule); model names a registered model asset every character uses unless it passes its own model (the procedural body shows until it loads); animation.fade skeletal animation transition seconds
21
+ - `character?: { animation?: { fade?: number } }` How character motion looks: animation.fade skeletal animation transition seconds. Bodies are assets, not style ({ model: 'yourBody' } from an asset pack); a style tints body parts through materials roles (cloth, skin, trousers, hair). create / model / colors here throw renamed-api
22
22
  - `ui?: StyleUI` UI colors, fonts, templates
23
23
  - `particles?: Record<string, ParticleOptions>` Particle presets: name → parameters; default is the fallback for all effects
24
24
  - `triggers?: { debugColor?: ColorLike; debugOpacity?: number }` Trigger zone debug wireframe
@@ -43,7 +43,7 @@
43
43
  - `clouds?: StyleSkyClouds` Clouds in the sky (cloud cover follows the weather); see StyleSkyClouds
44
44
  - `skybox?: string` Panorama (equirectangular) replacing the gradient sky, asset name or path
45
45
  - `shadow?: StyleShadow` Shadows: mapSize resolution (pixels), extent coverage (meters), etc., see StyleShadow
46
- - `environment?: StyleEnvironment` Environment lighting (scene.environment), off unless a source is given; see Sky.setEnvironment. A pack can give defaults, sky({ environment }) overrides
46
+ - `environment?: StyleEnvironment` Environment lighting (scene.environment), off unless a source is given; see engine.look.env. A pack can give defaults, sky({ environment }) overrides
47
47
  - `fog?: StyleFog` Fog model and color (default: linear fog in the horizon color); see StyleFog
48
48
  - `layers?: StyleSkyLayer[]` Extra dome layers drawn after the clouds and stars (rainbow, aurora), default none; see StyleSkyLayer
49
49
  - **StyleShadow**
@@ -99,7 +99,7 @@
99
99
  - `variation?: { blend?, jitter?, patches? }` How ground colors vary (plain data, sent to the terrain workers). Every default is the original look; set only what you want to change. blend: the two-color noise (size = wavelength in meters, default 33; strength = contrast, default 1). Example: `variation: { blend: { size: 14 }, jitter: { range: 0.04 }, patches: { size: 60, strength: 0.25, levels: 4, tint: 0xb59a5a } }`
100
100
  - `config?: { shading?, colorResolution?, normals?, normalFn? }` Looks of the ground mesh only. shading: 'flat' one color and normal per triangle (facets) / 'smooth' (engine default) / 'texture' (per-chunk color map, colors independent of the mesh); colorResolution: color map pixels per chunk edge; normals: 'smooth' / 'flat' lighting in texture mode; normalFn: custom grid-point normal.
101
101
  - `material?: Material | ((engine: Engine) => Material)` Whole ground material: a Material or (engine) => Material (uv = world xz / chunk size; terrain({ material }) wins)
102
- - `detail?: { texture: string; scale?: number; strength?: number }` Ground detail texture: texture asset name, scale repeats per meter, strength 0–1
102
+ - `detail?: MaterialDetail` Detail layer over the ground, the same object as a material spec's `detail`: a noise ('grain' / 'paper' / 'stroke' / 'dabs'), a texture asset name, or your own `glsl`; plus scale, strength, fade ... (top-down world projection by default). Live: look.ground.set({ detail }). See recipes/53-ground-up-close.md
103
103
  - **StyleUI**
104
104
  - `bg?: string` Background color
105
105
  - `fg?: string` Text color
package/docs/api/tools.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Utility functions (imported from threedog)
2
2
 
3
- - `postAdd(...effects: PostEffect[]) → Style` — A style part that adds post effects to the ones before it (a plain { post: [...] } would replace the whole list); an effect with the same name replaces that one in place. Style parts with it: createEngine({ style: [lowpoly, postAdd(myGrain, bloom({ strength: 0.6 }))] })
4
- - `postRemove(...names: string[]) → Style` — A style part that removes post effects by name from the ones before it: createEngine({ style: [lowpoly, postRemove('ao', 'outline')] })
3
+ - `postAdd(...effects: PostEffect[]) → Style` — A style part that adds post effects to the ones before it (a plain { post: [...] } would replace the whole list); an effect with the same name replaces that one in place. Style parts with it: createEngine({ style: [basePack, postAdd(myGrain, bloom({ strength: 0.6 }))] })
4
+ - `postRemove(...names: string[]) → Style` — A style part that removes post effects by name from the ones before it: createEngine({ style: [basePack, postRemove('ao', 'outline')] })
5
5
  - `presets: { weather, calendar, player, interactions, keys, camera }` — Opt-in gameplay presets: named option objects a game picks on purpose (the engine never applies one itself). Each only bundles options the game could write; spread and override: weather({ ...presets.weather.temperate, autoPool: ['clear', 'rain'] })
6
6
  - `world(opts?: { cellSize?, radius?, farEvery?, farMaxPerTick?, buildPerFrame? }) → import("../../../core").ModuleDef…` — World data module: installed as engine.world. Put things here that must be saved, survive level changes and keep changing while far away; models are only built while nearby
7
7
  - `net(opts?: { role, transport, sync?, syncEvery?, keepAlive?, rate?, … }) → import("../../../core").ModuleDef…` — (experimental) Optional co-op multiplayer: one host owns the state, clients mirror it and ask for changes through ops. Installed as engine.net. Host: peers' requests run as `ops.run(name, args, { source: 'net', actor })` only for ops defined with net: 'peer', with the op's args shape checked, the optional owner check, and a per-peer rate limit; the result comes back after the state diff that contains it. State: world records, containers, vars and the other save parts are sent as a snapshot on join and as diffs every syncEvery steps. Client: ops.run of a peer op returns { ok: true, pending: true, seq } (watch state or the net:result event, not the return value); its own avatar moves locally and is sent to the host (clamped to maxSpeed); other avatars glide between updates.
@@ -10,8 +10,11 @@
10
10
  - `grids() → import("../../../core").ModuleDef…` — (experimental) Grid placement module: installed as engine.grids. Needs world(). Adds the ops grid.place / grid.remove / grid.move and the save key 'grids' (layers).
11
11
  - `screenToGround(engine: Engine, ndcX: number, ndcY: number, opts?: { maxDistance?: number }) → Vector3 | null` — Screen coordinates (-1..1) -> point on the ground; null if the ray misses the ground
12
12
  - `EASINGS: Record<EaseName, (t: number) => number>` — All easing functions: name -> function
13
+ - `sampleGrid(data: ArrayLike<number>, opts: { width, height, cellSize?, size?, origin?, interp?, … }) → (x: number, z: number) => number` — A grid of numbers (height, moisture, density, walkable...) as a function (x, z) -> value. data[j * width + i] sits at origin + (i, j) * cell. interp 'nearest' = flat steps, 'linear' (default) = bilinear, 'cubic' = smooth (clamp: true avoids overshoot). Outside: edge value, or `outside`.
13
14
  - `ease(e: Ease) → (t: number) => number` — Name or function -> easing function
14
15
  - `checkOptions(where: string, opts: object | null | undefined, known: string[], flags?: { loose?: boolean })` — Warn (once, in development) about unknown keys in an options object, with a "did you mean" hint. For your own modules. where names the call ('stamina()'); known lists the keys your code reads; loose only warns on near-misses (data with game-specific fields).
16
+ - `readParams(where: string, schema: Record<string, ParamSpec>, opts?: object) → T` — Module options read through a params schema: unknown keys and wrong types throw in dev with the fix, defaults are filled in. Also put params / options on the module definition so engine.catalog(name) shows them (recipes/51-capability-catalog.md).
17
+ - `defineLookPart(engine: any, spec: { id, group?, module?, object?, params?, style?, … }) → LookPart` — Register a module's own look part: engine.look.<id> with set / patch / replace, engine.catalog('look.<id>') and describe().look (recipes/52-look.md). Every param needs a default; a default that changes the picture also needs why and off (or neutral: true).
15
18
  - `createTerrain(cfg?: Partial<TerrainConfig>) → TerrainGen` — Pure terrain computation (no engine needed), for previewing heights before start: createTerrain({ seed, ...terrainPreset() }).surface(x, z)
16
19
  - `terrainMaterial(base?: THREE.Material | null, engine?: { style: any; assets: any }) → THREE.Material` — Terrain material: base (default the style's 'terrain' role with vertex colors) + cloud shadows + season tint + optional detail texture (style.terrain.detail). Pass the engine so its style pack and assets are used.
17
20
  - `mergeColored(parts: [THREE.BufferGeometry, ColorLike][], { flat }?: { flat?: boolean }) → THREE.BufferGeometry` — Merge several geometries into one vertex-colored geometry (a tree = trunk + canopy in one draw call): [[geometry, color], ...]. flat (default true): one normal per triangle, the faceted low-poly look; false keeps each part's own (smooth) normals. UVs are kept when every part has them, so the merged model can still take a texture.
@@ -27,6 +27,7 @@ Vegetation (vegetation() module; grows on terrain or on any ground provider)
27
27
  - `wind?: number` Wind sway amplitude, 0 = still
28
28
  - `nearOnly?: boolean` Only generated near the player (grass, flowers)
29
29
  - `maxRing?: number` No longer drawn beyond this many rings
30
+ - `fade?: false | { start?: number; end?: number }` Distance fade of a near-only species (grass, flowers, pebbles, debris ...): instances shrink out over a band in metres from the player instead of popping per chunk at the ring edge. Default for nearOnly: end = maxRing x chunk size, start = 65% of it. `false` keeps the hard ring edge (also the default for species that are not nearOnly).
30
31
  - `lodRing?: number` Switch to the low-detail model beyond this many rings, default 1
31
32
  - `castShadow?: boolean` Cast shadows
32
33
  - `shadowRing?: number` Cast shadows within this many rings
@@ -13,7 +13,7 @@ Weather (weather() module, needs sky)
13
13
  - `area?: number` Rain / snow coverage (meters)
14
14
 
15
15
  ## Methods and properties
16
- - `weather.define(field: string, spec?: import("../../../style").StyleWeath…) → { field, object, uniforms }` — Draw particles for a field of this game's weather table (its amount is weather.current[field], so they fade with the weather). spec takes the keys of style.weather.rain (shape, color, size, speed, sway, density, glsl...) or create(engine, { area, count }) => { object, update } for a system of your own. The same field again replaces it, rain and snow included. See recipes/44-water-weather-look-hooks.md. Example: `engine.weather.define('ash', { shape: 'soft', color: 0x555555, size: 14, speed: 0.8, sway: 3 }); // types: { ashfall: { ash: 1, grey: 0.5 } }`
16
+ - `weather.define(_field: string, _spec?: import("../../../style").StyleWeath…) → never` — Renamed in 0.2: throws and names the new call, engine.look.weather.replace({ [field]: spec }) (recipes/44-water-weather-look-hooks.md)
17
17
  - `weather.setAuto(on: boolean)` — Automatic weather on/off
18
18
  - `weather.set(name: WeatherName, seconds?: number)` — Switch weather. seconds: transition seconds, default 15
19
19
  - `weather.label(name?: string) → string` — Display name of a weather (string table weather.<name>, falls back to the name itself); defaults to the current weather
@@ -1,52 +1,50 @@
1
1
  # Starting a new game (a workspace under games/)
2
2
 
3
- Goal: create `games/farm/` (pick your own name) with its own page, modules, content data and tests, independent of other games. Start from the
4
- template (`npx threedog new-game farm`, section 0); the engine's own example is `examples/world/` in the package.
3
+ Goal: create `games/my-game/` (pick your own name) with its own page, modules, content data and tests, independent of other games. Start from the
4
+ template (`npx threedog new-game my-game`, section 0); the engine's own example is `examples/world/` in the package.
5
5
 
6
6
  ## 0. One-command setup (preferred)
7
7
  ```
8
- npm run new-game my-farm # minimal open world
9
- npm run new-game my-farm --blank # flat ground, a player and a follow camera only
8
+ npm run new-game -- my-game # clean start: ground, player, follow camera, sky; no gameplay
9
+ npm run new-game -- my-game --example # the sample: hp / hunger, a rest op, apples, a searchable stash, a HUD counter
10
+ npm run new-game -- my-game --style ./packs/mine # a style pack of your own (path) or a published one (package name) instead of the empty style/ folder
10
11
  ```
11
- (npm treats `--blank` as its own config and the script reads it from the `npm_config_blank` environment variable, so write it exactly like this,
12
- without `-- --blank`. The CLI form takes the flag directly: `npx threedog new-game my-farm --blank`.)
12
+ (The `--` matters: without it npm swallows the flags. The CLI form takes them directly: `npx threedog new-game my-game --example`. `--example` uses engine placeholders (gray box, capsule), so it works with any style.)
13
13
  The name may only contain lowercase letters, digits and dashes; an existing directory under `games/` with the same name is refused. What it does:
14
- 1. Copies `packages/tools/templates/game/` to `games/my-farm/` (`__NAME__` in the files is replaced by the name).
15
- 2. Creates the `node_modules/@threedog/my-farm` link and updates the workspace entry in `package-lock.json` (if offline, only a warning).
14
+ 1. Copies `packages/tools/templates/game/` to `games/my-game/` (`__NAME__` in the files is replaced by the name); `--example` copies `templates/example/` over it first.
15
+ 2. Creates the `node_modules/@threedog/my-game` link and updates the workspace entry in `package-lock.json` (if offline, only a warning).
16
16
  3. Runs `map` (generates GAMEMAP.md), `check` and the game's smoke test in turn. Any failing step stops and says why.
17
17
 
18
- The generated game is a minimal open world: `openWorld` + `interactions / inventory / content / hud`, 3 apples on the ground and one stash (a template
19
- in `content/templates.js` placed by `content/props.js`, searched through the op `stash.search`); its `main.js` also shows the game's own state
20
- registered with `describe.add` and `saves.register`, an op with `can` / `run`, and the `onFixed` / `onFrame` split; `--blank` copies the same template
21
- without `content/` and replaces `main.js` with `templates/blank/main.js` (no inventory, no content). The structure is the same as the manual one below.
22
- **Start clean from the full template** (when you did not use `--blank`): keep `createEngine`, `openWorld`, `start` and `window.engine`; replace the
23
- contents of `content/items.js pickups.js props.js templates.js actions.js`; in `main.js` delete the `game` object (hp / hunger), the
24
- `player.rest` op, the `onFixed` hunger timer, the HP counter in `onFrame` and the `stash.search` op; remove `sky: presets.calendar.cycle` if the
25
- game has no day cycle. `spawn` and `places` take any `{ x, z }` (or `{ x, y, z }`); `findSpawn` is only for generated terrain.
18
+ The default game is deliberately empty: `openWorld` (terrain, follow camera, sky) + `content()`, a player, content files that are empty arrays / objects (each
19
+ has one comment line saying what goes there and which recipe teaches it), and an empty style pack in `style/index.js` (every section is a commented-out stub;
20
+ with it empty the engine shows gray placeholders; fill it with your own art using recipes 09 and 52). `CLAUDE.md` says "This game has no gameplay yet; build what DESIGN.md describes".
21
+ `--example` adds the patterns: `interactions / inventory / hud`, 3 apples on the ground and one stash (a template in `content/templates.js` placed by
22
+ `content/props.js`, searched through the op `stash.search`); its `main.js` shows the game's own state registered with `describe.add` and `saves.register`, an op
23
+ with `can` / `run`, and the `onFixed` / `onFrame` split. `spawn` and `places` take any `{ x, z }` (or `{ x, y, z }`); `findSpawn` is only for generated terrain.
26
24
  To change the camera: `openWorld({ camera: 'firstPerson' })` (`follow` / `firstPerson` / `rts` / `fixed`, or pass a camera module directly; there is
27
25
  no default).
28
26
  - The comments in `main.js` list further gameplay modules you can add; usage is in `../api/<module>.md`.
29
- - To change the starting point of new games, edit the real files in `packages/tools/templates/game/`.
27
+ - To change the starting point of new games, edit the real files in `packages/tools/templates/game/` (and `templates/example/` for the sample).
30
28
  - `DESIGN.md` is an empty template: write your gameplay ideas there. `CLAUDE.md` only points the way (read `node_modules/threedog/docs/AI.md` first,
31
29
  then GAMEMAP, DESIGN) and does not copy engine rules.
32
- - There is no `tests/`: when `tests/specs.mjs` does not exist, `npm test -w games/my-farm` runs a smoke test automatically.
30
+ - There is no `tests/`: when `tests/specs.mjs` does not exist, `npm test -w games/my-game` runs a smoke test automatically.
33
31
 
34
32
  ## 1. Creating the files by hand (to learn what each file is, or when the template doesn't fit)
35
33
  | File | Content |
36
34
  |---|---|
37
- | `games/farm/package.json` | Copy `package.json` from the game template (or run `npx threedog new-game farm`) and set `name` to `@threedog/farm` (dependencies `threedog`, `@threedog/tools`, plus `@threedog/style-lowpoly` (it needs `@threedog/post-effects` too) and `@threedog/terrain-noise` when `main.js` imports them; scripts dev/build/preview/test/check/map) |
38
- | `games/farm/vite.config.js` | One line: `export default gameConfig(import.meta.dirname)` (imported from `@threedog/tools/vite`); *.html files in the directory are bundled automatically, no `input` needed. Without `@threedog/tools`, a plain vite config needs `worker: { format: 'es' }` (the engine's Workers are ES modules) or `vite build` fails; `threedog dev / build` on a folder with no vite config uses the preset |
39
- | `games/farm/index.html` | The page: one `<canvas id="view">` with a CSS size + `/main.js` (for more pages put `xxx.html` in the same directory); see §5 for embedding |
40
- | `games/farm/main.js` | Install modules, compute places, `content.load`, game-specific logic |
41
- | `games/farm/content/index.js` | Combines the content files into one object |
42
- | `games/farm/content/*.js` | Only these names are read: items pickups containers npcs dialogues quests actions places triggers level vegetation props templates audio grids renames rules, plus the game's own kinds (rules.js) |
43
- | `games/farm/DESIGN.md` | Hand-written design decisions (a few lines of `- **decision**: reason`), copied into GAMEMAP.md |
44
- | `games/farm/CLAUDE.md` | A few lines: read `node_modules/threedog/docs/AI.md`, then this directory's GAMEMAP.md and DESIGN.md (copy the template's) |
45
- | `games/farm/public/` | This game's art assets (URL `/models/...`); keep Blender source files in `games/farm/art/models/`, `npm run assets -- -w farm` compresses them over |
35
+ | `games/my-game/package.json` | Copy `package.json` from the game template (or run `npx threedog new-game my-game`) and set `name` to `@threedog/my-game` (dependencies `threedog`, `@threedog/tools`, plus `@threedog/terrain-noise`, and your style pack (and `@threedog/post-effects` if the pack uses it) only when `main.js` imports it; the default style is the game's own `style/index.js`; scripts dev/build/preview/test/check/map) |
36
+ | `games/my-game/vite.config.js` | One line: `export default gameConfig(import.meta.dirname)` (imported from `@threedog/tools/vite`); *.html files in the directory are bundled automatically, no `input` needed. Without `@threedog/tools`, a plain vite config needs `worker: { format: 'es' }` (the engine's Workers are ES modules) or `vite build` fails; `threedog dev / build` on a folder with no vite config uses the preset |
37
+ | `games/my-game/index.html` | The page: one `<canvas id="view">` with a CSS size + `/main.js` (for more pages put `xxx.html` in the same directory); see §5 for embedding |
38
+ | `games/my-game/main.js` | Install modules, compute places, `content.load`, game-specific logic |
39
+ | `games/my-game/content/index.js` | Combines the content files into one object |
40
+ | `games/my-game/content/*.js` | Only these names are read: items pickups containers npcs dialogues quests actions places triggers level vegetation props templates audio grids renames rules, plus the game's own kinds (rules.js) |
41
+ | `games/my-game/DESIGN.md` | Hand-written design decisions (a few lines of `- **decision**: reason`), copied into GAMEMAP.md |
42
+ | `games/my-game/CLAUDE.md` | A few lines: read `node_modules/threedog/docs/AI.md`, then this directory's GAMEMAP.md and DESIGN.md (copy the template's) |
43
+ | `games/my-game/public/` | This game's art assets (URL `/models/...`); keep Blender source files in `games/my-game/art/models/`, `npm run assets -- -w my-game` compresses them over |
46
44
 
47
45
  After creating them, run `npm install` once at the repository root (this links the new game into the workspaces so `threedog` can find it).
48
46
 
49
- Outside the engine repository, a game installs `threedog` and `three` (plus `@threedog/style-lowpoly` + `@threedog/post-effects` / `@threedog/terrain-noise` if it imports them,
47
+ Outside the engine repository, a game installs `threedog` and `three` (plus your style pack, `@threedog/post-effects` / `@threedog/terrain-noise` if it imports them,
50
48
  and `@threedog/tools` as a dev dependency for the CLI and the vite preset). To use an engine folder on disk instead of npm, install it with
51
49
  `npm install --install-links <folder>`: a plain link skips the engine's own dependencies (Rapier, Recast) and the build cannot resolve them.
52
50
 
@@ -56,23 +54,23 @@ In a game's own repository, `threedog check`, `types` and `map` read only the ga
56
54
  The template's `tsconfig.json` checks the game files only (`checkJs`), with `lib` ESNext + DOM (dependency typings such as Rapier's use
57
55
  `Symbol.dispose`) and `skipLibCheck: true`; without a tsconfig, `threedog types` writes the same settings to `.threedog/tsconfig.types.json`.
58
56
 
59
- `games/farm/index.html` (minimal; the template's `index.html` has the same page with loading styles):
57
+ `games/my-game/index.html` (minimal; the template's `index.html` has the same page with loading styles):
60
58
  ```html
61
59
  <!doctype html>
62
- <html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
63
- <title>农场</title><style>html,body{height:100%;margin:0;overflow:hidden;background:#141a17}#view{position:fixed;inset:0;width:100%;height:100%;display:block;outline:none}</style>
60
+ <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
61
+ <title>My game</title><style>html,body{height:100%;margin:0;overflow:hidden;background:#141a17}#view{position:fixed;inset:0;width:100%;height:100%;display:block;outline:none}</style>
64
62
  </head><body><canvas id="view" tabindex="0"></canvas><script type="module" src="/main.js"></script></body></html>
65
63
  ```
66
64
 
67
- `games/farm/main.js`:
65
+ `games/my-game/main.js`:
68
66
  ```js
69
- // Farm example: ... (this first comment line appears in the file table of GAMEMAP.md)
67
+ // my-game: ... (this first comment line appears in the file table of GAMEMAP.md)
70
68
  import { createEngine, presets, openWorld, interactions, dialogue, inventory, quests, entities, content } from 'threedog';
71
- import lowpoly from '@threedog/style-lowpoly'; // optional style pack (the engine ships no art)
69
+ import style from './style/index.js'; // the game's own style pack (the engine ships no art)
72
70
  import { terrainPreset } from '@threedog/terrain-noise'; // optional terrain generator (nor a world shape)
73
71
  import data from './content/index.js';
74
72
 
75
- const engine = createEngine({ canvas: document.getElementById('view'), style: lowpoly, ui: { loading: { title: '农场' } }, saveKey: 'farm' });
73
+ const engine = createEngine({ canvas: document.getElementById('view'), style, ui: { loading: { title: 'My game' } }, saveKey: 'my-game' });
76
74
  // the preset only covers world and environment; the debug panel is installed in dev builds only (debug: true forces it in release too)
77
75
  engine.use(openWorld({ camera: 'follow', seed: 42, terrain: terrainPreset(), time: 0.3 }),
78
76
  // add gameplay modules as the game needs (a shooter has no inventory)
@@ -97,7 +95,7 @@ otherwise English) unless you set `createEngine({ locale })`. A game without ter
97
95
  the level generator function under `models` in `engine.assets.manifest({ name, models })`, use `level({ url: name })` and pick your own modules, then
98
96
  create the player and install content in `level:loaded`.
99
97
 
100
- `games/farm/content/index.js`:
98
+ `games/my-game/content/index.js`:
101
99
  ```js
102
100
  import items, { startItems } from './items.js';
103
101
  import places from './places.js';
@@ -106,13 +104,13 @@ export default { items, startItems, places };
106
104
  `content/places.js`: `export default { home: 'flat ground found at the start (coordinates computed in main.js)' };`
107
105
 
108
106
  ## 2. Verify
109
- 1. `npm run map` -> generates `games/farm/GAMEMAP.md`; check the "engine modules" and "page /" sections.
107
+ 1. `npm run map` -> generates `games/my-game/GAMEMAP.md`; check the "engine modules" and "page /" sections.
110
108
  2. `npm run check` -> content validation points out wrong file names, ids and clock-time formats; `npm run types` finds misused engine APIs.
111
- 3. `npm run shot -- -w farm / --describe-only` -> the text has a `player` line with its position, the module list, and no "still loading".
112
- 4. `npm test -w games/farm` -> without `tests/specs.mjs` it runs a smoke test (the page opens, the engine is ready, the console has no errors); to
113
- test gameplay, write `games/farm/tests/specs.mjs` in the style of the engine repository's `packages/engine/tests/specs.mjs`.
114
- 5. To see the picture: `npm run shot -- -w farm /` (one image in `games/farm/.threedog/shots/`); while developing run `npm run dev -w games/farm` (or
115
- `npm run dev -- farm`) and open the printed address; read errors in `games/farm/.threedog/errors.log`.
109
+ 3. `npm run shot -- -w my-game / --describe-only` -> the text has a `player` line with its position, the module list, and no "still loading".
110
+ 4. `npm test -w games/my-game` -> without `tests/specs.mjs` it runs a smoke test (the page opens, the engine is ready, the console has no errors); to
111
+ test gameplay, write `games/my-game/tests/specs.mjs` in the style of the engine repository's `packages/engine/tests/specs.mjs`.
112
+ 5. To see the picture: `npm run shot -- -w my-game /` (one image in `games/my-game/.threedog/shots/`); while developing run `npm run dev -w games/my-game` (or
113
+ `npm run dev -- my-game`) and open the printed address; read errors in `games/my-game/.threedog/errors.log`.
116
114
 
117
115
  ## 3. Preset parts
118
116
  Every `openWorld()` part takes `false` or its module's options object, for example
@@ -145,4 +143,4 @@ root is laid exactly over it. So the layout decides:
145
143
  <section style="position:relative;width:640px;height:360px"><canvas id="view" style="width:100%;height:100%;display:block"></canvas></section> <!-- in a page -->
146
144
  ```
147
145
  A canvas with no CSS size takes its size from its own pixel buffer, which would grow on every resize; the engine then sizes it to the window and warns
148
- once in dev. The pixel ratio (`createEngine({ pixelRatio })`, adaptive resolution) works as before on top of the CSS size.
146
+ once in dev. The pixel ratio (`createEngine({ pixelRatio })`, adaptive resolution) applies on top of the CSS size.