threedog 1.0.1 → 1.2.0

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 (364) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/README.md +1 -1
  3. package/core/assets/Animator.js +41 -3
  4. package/core/assets/Assets.js +100 -24
  5. package/core/assets/assetEntry.js +73 -20
  6. package/core/assets/assetHot.js +68 -16
  7. package/core/assets/assetLoad.js +6 -6
  8. package/core/assets/assetLod.js +9 -2
  9. package/core/assets/assetManifest.js +12 -2
  10. package/core/assets/assetPart.js +54 -0
  11. package/core/assets/ik.js +271 -0
  12. package/core/assets/modelNeeds.js +37 -0
  13. package/core/assets/namedModel.js +102 -29
  14. package/core/assets/nodeVisibility.js +15 -0
  15. package/core/audio/Audio.js +36 -4
  16. package/core/audio/audioReverb.js +99 -0
  17. package/core/audio/audioRules.js +1 -1
  18. package/core/audio/audioVoice.js +1 -1
  19. package/core/base/Events.js +14 -4
  20. package/core/base/Random.js +1 -1
  21. package/core/base/Vars.js +1 -1
  22. package/core/base/docRef.js +51 -0
  23. package/core/base/errorCodes.js +178 -126
  24. package/core/base/errorHints.js +9 -7
  25. package/core/base/errors.js +25 -10
  26. package/core/base/events.generated.js +2 -0
  27. package/core/base/freeParts.js +76 -0
  28. package/core/base/math.js +28 -0
  29. package/core/base/sections.js +5 -5
  30. package/core/base/validate.js +31 -3
  31. package/core/engine/Engine.js +16 -6
  32. package/core/engine/Loading.js +5 -3
  33. package/core/engine/copies.js +1 -1
  34. package/core/engine/headlessLoad.js +4 -1
  35. package/core/engine/lifecycle.js +32 -16
  36. package/core/engine/loop.js +71 -27
  37. package/core/engine/moduleSlots.js +2 -2
  38. package/core/engine/moduleTypes.js +3 -3
  39. package/core/engine/modules.js +65 -39
  40. package/core/engine/page.js +6 -3
  41. package/core/engine/services.js +6 -5
  42. package/core/engine/startup.js +5 -5
  43. package/core/input/Input.js +28 -14
  44. package/core/input/inputContext.js +28 -16
  45. package/core/input/inputKeyboard.js +31 -3
  46. package/core/input/inputPad.js +4 -0
  47. package/core/input/inputPointer.js +2 -1
  48. package/core/input/inputSeat.js +1 -1
  49. package/core/inspect/Budget.js +109 -19
  50. package/core/inspect/DebugOverrides.js +28 -4
  51. package/core/inspect/Describe.js +17 -9
  52. package/core/inspect/Inspect.js +4 -2
  53. package/core/inspect/InspectMaterials.js +3 -1
  54. package/core/inspect/InspectPerf.js +19 -9
  55. package/core/inspect/InspectScene.js +32 -7
  56. package/core/inspect/MaterialInfo.js +19 -2
  57. package/core/inspect/UrlState.js +46 -27
  58. package/core/inspect/catalog.js +28 -9
  59. package/core/inspect/debugView.js +2 -1
  60. package/core/inspect/describeRender.js +25 -13
  61. package/core/inspect/describeText.js +14 -6
  62. package/core/inspect/lightWatch.js +1 -1
  63. package/core/inspect/metadata.generated.js +35 -17
  64. package/core/inspect/pictureChecks.js +148 -0
  65. package/core/inspect/pictureMenu.js +84 -0
  66. package/core/inspect/pictureWriters.js +26 -6
  67. package/core/inspect/textureBytes.js +12 -2
  68. package/core/inspect/toolDoor.js +2 -4
  69. package/core/ops/Ops.js +11 -4
  70. package/core/ops/holds.js +27 -10
  71. package/core/ops/opsAtomic.js +15 -7
  72. package/core/ops/opsGuard.js +2 -2
  73. package/core/ops/opsRun.js +8 -7
  74. package/core/ops/sharedPoint.js +72 -21
  75. package/core/ops/stacks.js +56 -16
  76. package/core/saves/SaveStore.js +9 -3
  77. package/core/saves/Saves.js +32 -23
  78. package/core/saves/saveApply.js +96 -44
  79. package/core/saves/saveIds.js +1 -1
  80. package/core/saves/saveVersions.js +7 -5
  81. package/core/saves/session.js +17 -8
  82. package/core/saves/stateReplace.js +34 -15
  83. package/core/scene/Rays.js +52 -10
  84. package/core/scene/Views.js +13 -7
  85. package/core/scene/adaptive.js +144 -21
  86. package/core/scene/drawOnly.js +17 -0
  87. package/core/scene/gameLights.js +44 -3
  88. package/core/scene/sceneMethods.js +13 -11
  89. package/core/scene/stepPoses.js +11 -3
  90. package/core/scene/targeting.js +5 -3
  91. package/core/scene/thingOps.js +1 -1
  92. package/core/scene/tier.js +15 -0
  93. package/core/stream/Batching.js +30 -7
  94. package/core/stream/Stream.js +26 -7
  95. package/core/stream/batchGroups.js +2 -2
  96. package/core/stream/chunkStream.js +7 -5
  97. package/core/stream/prepare.js +77 -0
  98. package/core/time/skip.js +3 -1
  99. package/core/time/time.js +4 -2
  100. package/docs/AI.md +82 -83
  101. package/docs/API.md +16 -16
  102. package/docs/CODEMAP.md +16 -11
  103. package/docs/COMMANDS.md +31 -33
  104. package/docs/CONVENTIONS.md +37 -49
  105. package/docs/MIGRATING-0.8.md +2 -2
  106. package/docs/MIGRATING-1.0.md +2 -2
  107. package/docs/THREE.md +28 -35
  108. package/docs/api/assets.md +3 -1
  109. package/docs/api/audio.md +4 -2
  110. package/docs/api/budget.md +5 -0
  111. package/docs/api/cameraRig.md +2 -2
  112. package/docs/api/characters.md +10 -8
  113. package/docs/api/collision.md +6 -4
  114. package/docs/api/engine.md +16 -16
  115. package/docs/api/events.md +3 -2
  116. package/docs/api/ground.md +6 -5
  117. package/docs/api/hud.md +4 -2
  118. package/docs/api/input.md +5 -5
  119. package/docs/api/particles.md +2 -1
  120. package/docs/api/photo.md +3 -0
  121. package/docs/api/post.md +7 -4
  122. package/docs/api/quests.md +2 -2
  123. package/docs/api/rays.md +1 -2
  124. package/docs/api/saves.md +7 -7
  125. package/docs/api/settings.md +2 -2
  126. package/docs/api/tools.md +3 -1
  127. package/docs/api/vars.md +1 -1
  128. package/docs/api/vegetation.md +4 -2
  129. package/docs/api/world.md +1 -1
  130. package/docs/recipes/01-new-game.md +16 -17
  131. package/docs/recipes/02-npc.md +22 -18
  132. package/docs/recipes/03-items-pickups.md +37 -35
  133. package/docs/recipes/04-quests.md +15 -10
  134. package/docs/recipes/05-props-bake.md +101 -95
  135. package/docs/recipes/06-clock-events.md +28 -28
  136. package/docs/recipes/07-flow-scenes-pause.md +29 -26
  137. package/docs/recipes/08-weather-sky.md +52 -64
  138. package/docs/recipes/09-materials-lights-models.md +26 -17
  139. package/docs/recipes/10-blender-level.md +15 -10
  140. package/docs/recipes/11-vehicles.md +12 -7
  141. package/docs/recipes/12-navmesh.md +44 -26
  142. package/docs/recipes/13-animation.md +56 -45
  143. package/docs/recipes/14-custom-module.md +21 -18
  144. package/docs/recipes/15-perf.md +61 -55
  145. package/docs/recipes/16-dev-bridge.md +23 -33
  146. package/docs/recipes/18-world.md +36 -42
  147. package/docs/recipes/19-shooting-picking.md +20 -15
  148. package/docs/recipes/20-content-actions-save.md +48 -56
  149. package/docs/recipes/21-camera.md +45 -54
  150. package/docs/recipes/22-shop-gold.md +12 -7
  151. package/docs/recipes/23-ops.md +25 -23
  152. package/docs/recipes/26-ui-parts.md +67 -47
  153. package/docs/recipes/27-net.md +12 -7
  154. package/docs/recipes/28-terrain.md +24 -21
  155. package/docs/recipes/29-grid.md +32 -27
  156. package/docs/recipes/30-templates.md +21 -20
  157. package/docs/recipes/31-audio.md +39 -22
  158. package/docs/recipes/32-action-game.md +19 -14
  159. package/docs/recipes/33-stream-sources.md +15 -11
  160. package/docs/recipes/34-environment-lighting.md +126 -70
  161. package/docs/recipes/35-picture-from-reference.md +8 -8
  162. package/docs/recipes/36-ground-plants.md +27 -21
  163. package/docs/recipes/40-scene.md +19 -28
  164. package/docs/recipes/43-shader-patches-surfaces.md +15 -12
  165. package/docs/recipes/44-water-weather-hooks.md +34 -31
  166. package/docs/recipes/45-cascaded-shadows.md +35 -26
  167. package/docs/recipes/46-blender-art-route.md +6 -1
  168. package/docs/recipes/49-game-module-contract.md +13 -8
  169. package/docs/recipes/50-own-renderer.md +6 -2
  170. package/docs/recipes/51-capability-catalog.md +15 -8
  171. package/docs/recipes/52-around-the-picture.md +34 -32
  172. package/docs/recipes/53-ground-up-close.md +6 -1
  173. package/docs/recipes/55-mods-time-wrap.md +27 -19
  174. package/docs/recipes/56-webgpu-tsl.md +74 -43
  175. package/docs/recipes/57-control.md +18 -13
  176. package/docs/recipes/58-input.md +26 -16
  177. package/docs/recipes/59-depth-post-effects.md +8 -3
  178. package/docs/recipes/60-judge-the-picture.md +9 -8
  179. package/docs/recipes/61-deploy.md +5 -0
  180. package/docs/recipes/62-picture-code.md +70 -79
  181. package/docs/recipes/63-third-person-start.md +47 -45
  182. package/docs/recipes/64-particles.md +22 -10
  183. package/docs/recipes/65-swarm.md +18 -13
  184. package/docs/recipes/66-common-tasks.md +38 -35
  185. package/examples/action/GAMEMAP.md +2 -3
  186. package/examples/action/main.js +3 -3
  187. package/examples/action/picture/lights.js +3 -1
  188. package/examples/perf-island/GAMEMAP.md +3 -3
  189. package/examples/perf-island/picture/lights.js +2 -1
  190. package/examples/plain-picture/GAMEMAP.md +1 -1
  191. package/examples/rc2d/GAMEMAP.md +1 -1
  192. package/examples/styletest/GAMEMAP.md +2 -2
  193. package/examples/styletest/main.js +1 -1
  194. package/examples/techniques/interior-light/README.md +3 -3
  195. package/examples/techniques/interior-light/interiorLight.js +2 -4
  196. package/examples/techniques/interior-light/picture/lights.js +2 -1
  197. package/examples/techniques/modular-building/picture/lights.js +3 -1
  198. package/examples/techniques/outlines-and-rim/picture/lights.js +3 -1
  199. package/examples/techniques/procedural-animation/README.md +1 -1
  200. package/examples/techniques/procedural-animation/main.js +1 -1
  201. package/examples/webgpu-tsl/GAMEMAP.md +1 -1
  202. package/examples/world/GAMEMAP.md +2 -3
  203. package/examples/world/art/humanoid.js +1 -1
  204. package/examples/world/main.js +6 -3
  205. package/index.d.ts +2 -2
  206. package/llms.txt +101 -0
  207. package/modules/ambience/Ambience.js +21 -5
  208. package/modules/calendar/index.js +9 -5
  209. package/modules/calendar/schedule.js +23 -8
  210. package/modules/camera/FirstPersonCamera.js +3 -1
  211. package/modules/camera/FollowCamera.js +10 -5
  212. package/modules/camera/RtsCamera.js +4 -3
  213. package/modules/camera/common.js +70 -8
  214. package/modules/camera/contract.js +1 -1
  215. package/modules/characters/Character.js +16 -10
  216. package/modules/characters/NPC.js +31 -19
  217. package/modules/characters/assetModel.js +14 -9
  218. package/modules/characters/astar.js +6 -1
  219. package/modules/characters/contract.js +2 -2
  220. package/modules/characters/index.js +34 -22
  221. package/modules/characters/movers/manual.js +1 -1
  222. package/modules/characters/movers/rapier.js +17 -2
  223. package/modules/characters/movers/simple.js +1 -1
  224. package/modules/characters/movers/support.js +16 -7
  225. package/modules/characters/npcAvoid.js +2 -2
  226. package/modules/characters/npcSim.js +3 -2
  227. package/modules/characters/pathAsync.js +24 -8
  228. package/modules/characters/pathJob.js +1 -1
  229. package/modules/characters/player.js +10 -9
  230. package/modules/characters/playerStrings.js +5 -5
  231. package/modules/characters/proceduralRig.js +5 -5
  232. package/modules/characters/useModel.js +6 -0
  233. package/modules/characters/walkTo.js +1 -1
  234. package/modules/collision/Collision.js +29 -18
  235. package/modules/collision/grid.js +22 -4
  236. package/modules/content/index.js +3 -1
  237. package/modules/content/loader.js +1 -1
  238. package/modules/content/models.js +82 -33
  239. package/modules/content/props.js +2 -1
  240. package/modules/content/rules.js +11 -5
  241. package/modules/content/templates.js +3 -3
  242. package/modules/content/words.js +2 -2
  243. package/modules/debug/DebugPanel.js +9 -9
  244. package/modules/flow/index.js +9 -6
  245. package/modules/gameplay/Dialogue.js +34 -20
  246. package/modules/gameplay/Interactions.js +19 -15
  247. package/modules/gameplay/Inventory.js +9 -4
  248. package/modules/gameplay/Quests.js +12 -10
  249. package/modules/gameplay/pickups.js +23 -11
  250. package/modules/grid/index.js +1 -1
  251. package/modules/grid/preview.js +2 -2
  252. package/modules/grid/tiles.js +1 -1
  253. package/modules/hlod/index.js +4 -1
  254. package/modules/hud/index.js +47 -10
  255. package/modules/hud/parts.js +28 -9
  256. package/modules/level/geometry.js +8 -3
  257. package/modules/level/index.js +10 -5
  258. package/modules/level/load.js +4 -2
  259. package/modules/lights/sources.js +1 -1
  260. package/modules/music/Music.js +22 -4
  261. package/modules/nav/index.js +20 -10
  262. package/modules/particles/Particles.js +31 -14
  263. package/modules/particles/effect.js +20 -5
  264. package/modules/particles/lit.js +72 -0
  265. package/modules/photo/Photo.js +72 -28
  266. package/modules/photo/pathTrace.js +106 -0
  267. package/modules/rigid/RigidBodies.js +23 -14
  268. package/modules/rigid/Vehicles.js +3 -13
  269. package/modules/rigid/sync.js +2 -1
  270. package/modules/settings/Settings.js +52 -20
  271. package/modules/settings/apply.js +23 -9
  272. package/modules/settings/sections.js +39 -6
  273. package/modules/settings/strings.js +2 -0
  274. package/modules/settings/view.js +19 -3
  275. package/modules/sky/dome.js +15 -3
  276. package/modules/sky/environment.js +28 -12
  277. package/modules/sky/fog.js +1 -1
  278. package/modules/sky/frame.js +6 -1
  279. package/modules/sky/shader.js +4 -3
  280. package/modules/sky/skyModule.js +8 -4
  281. package/modules/swarm/Swarm.js +1 -1
  282. package/modules/terrain/ChunkManager.js +61 -15
  283. package/modules/terrain/chunkJob.js +2 -2
  284. package/modules/terrain/index.js +20 -5
  285. package/modules/terrain/terrainEdit.js +8 -4
  286. package/modules/terrain/terrainTexture.js +4 -2
  287. package/modules/timeline/Timeline.js +4 -3
  288. package/modules/timeline/Tween.js +3 -0
  289. package/modules/timeline/letterbox.js +1 -0
  290. package/modules/triggers/index.js +36 -17
  291. package/modules/vegetation/Vegetation.js +81 -19
  292. package/modules/vegetation/densityMap.js +13 -8
  293. package/modules/vegetation/draw.js +147 -24
  294. package/modules/vegetation/groundChunks.js +20 -5
  295. package/modules/vegetation/index.js +3 -3
  296. package/modules/vegetation/modelGeometry.js +9 -4
  297. package/modules/water/Water.js +11 -8
  298. package/modules/weather/Weather.js +7 -2
  299. package/modules/weather/shaders.js +25 -5
  300. package/modules/weather/weatherDraw.js +20 -6
  301. package/modules/world/World.js +2 -1
  302. package/modules/world/index.js +2 -2
  303. package/modules/world/persist.js +6 -2
  304. package/modules/world/views.js +15 -2
  305. package/package.json +4 -1
  306. package/presets.js +5 -5
  307. package/render/PostFX.js +84 -41
  308. package/render/backend.js +137 -16
  309. package/render/cascades.js +3 -1
  310. package/render/cascades.tsl.js +2 -0
  311. package/render/daylight.js +7 -1
  312. package/render/detail.js +7 -4
  313. package/render/effects.js +27 -8
  314. package/render/fogLook.js +24 -0
  315. package/render/fuse.js +5 -2
  316. package/render/fx/detail.tsl.js +9 -7
  317. package/render/fx/index.js +7 -2
  318. package/render/fx/library.tsl.js +1 -0
  319. package/render/fx/lightShaft.tsl.js +114 -0
  320. package/render/fx/noise.tsl.js +25 -8
  321. package/render/fx/objectOrigin.tsl.js +39 -10
  322. package/render/fx/particles.tsl.js +23 -6
  323. package/render/fx/patchNodes.tsl.js +17 -12
  324. package/render/fx/pcss.tsl.js +51 -0
  325. package/render/fx/postWebGPU.tsl.js +89 -29
  326. package/render/fx/sky.tsl.js +3 -9
  327. package/render/fxNumbers.js +10 -4
  328. package/render/impostor.tsl.js +107 -0
  329. package/render/lighting.js +33 -1
  330. package/render/lightmap.js +42 -28
  331. package/render/lights.js +19 -3
  332. package/render/materials.js +6 -4
  333. package/render/mergeCommon.js +4 -1
  334. package/render/occlusion.js +14 -4
  335. package/render/patches.js +79 -41
  336. package/render/postRuns.js +32 -0
  337. package/render/postWebGL.js +97 -10
  338. package/render/probes.js +10 -14
  339. package/render/shaderErrors.js +2 -1
  340. package/render/shadowCache.tsl.js +33 -5
  341. package/render/shadows.js +42 -16
  342. package/render/slots.js +8 -5
  343. package/render/vertexInputs.js +52 -0
  344. package/types/core.d.ts +114 -46
  345. package/types/gameplay.d.ts +56 -23
  346. package/types/generated/core/audio/Audio.d.ts +27 -1
  347. package/types/generated/core/base/Random.d.ts +1 -1
  348. package/types/generated/core/input/Input.d.ts +6 -8
  349. package/types/generated/core/input/inputSeat.d.ts +1 -1
  350. package/types/generated/core/inspect/Budget.d.ts +26 -0
  351. package/types/generated/core/inspect/DebugOverrides.d.ts +0 -2
  352. package/types/generated/core/saves/Saves.d.ts +10 -7
  353. package/types/generated/core/saves/session.d.ts +8 -2
  354. package/types/generated/core/scene/Rays.d.ts +1 -3
  355. package/types/generated/modules/particles/Particles.d.ts +1 -1
  356. package/types/generated/modules/world/World.d.ts +2 -1
  357. package/types/generated/render/PostFX.d.ts +35 -9
  358. package/types/physics.d.ts +43 -11
  359. package/types/pixel.d.ts +1 -1
  360. package/types/tsl.d.ts +62 -1
  361. package/types/world.d.ts +12 -3
  362. package/ui/Focus.js +7 -5
  363. package/ui/Parts.js +1 -1
  364. package/ui/touchPart.js +6 -3
@@ -1,6 +1,9 @@
1
1
  # Starting a new game
2
2
 
3
- **In this recipe**: 0. One-command setup · 1. Creating the files by hand · 2. Verify · 3. Feel presets · 4. Canvas size
3
+ > **Covers:** a new game folder: page, modules, content data, tests.
4
+ > **Use when:** starting any game.
5
+ > **Shortest:** `npm run new-game -- my-game` (`npx threedog init` outside the repo).
6
+ > **Sections:** 0 One-command setup preferred) · 1 Creating the files · 2 Verify · 3 Feel presets opt-in) · 4 Canvas size full
4
7
 
5
8
  Goal: a game with its own page, modules, content data and tests. The engine's own example is `examples/world/` in the package.
6
9
 
@@ -63,7 +66,7 @@ The template's `tsconfig.json` checks the game files only (`checkJs`), with `lib
63
66
  // The opening stays as in recipe 63 §1: createEngine({ canvas, lights: false, ui, saveKey, bindings }), engine.use(createPicture()) after engine.use,
64
67
  // Object.assign(window, { engine, picture }) (tests, screenshots and the console rely on it), await engine.start().
65
68
  import { presets, openWorld, interactions, dialogue, inventory, pickups, quests, content } from 'threedog';
66
- import { terrainPreset } from '@threedog/terrain-noise'; // optional terrain generator (nor a world shape)
69
+ import { terrainPreset } from '@threedog/terrain-noise'; // optional terrain generator (nor a world shape)
67
70
  import data from './content/index.js';
68
71
 
69
72
  // keys: modules only declare actions, the game binds them (presets.bindings.* are ready-made maps); this goes in createEngine({ bindings })
@@ -75,8 +78,8 @@ engine.use(openWorld({ camera: 'follow', seed: 42, terrain: terrainPreset(), tim
75
78
  content());
76
79
  // the terrain is generated: find flat ground as "home" at the start (give your own height range to avoid beach and peaks)
77
80
  const home = engine.characters.findSpawn([0, 0, 0], { minH: 3, maxH: 14 });
78
- engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: home });
79
- engine.content.load(data, { places: { home } }); // on top of the names in content/places.js; content uses { place: 'home', x, z }, quests target: 'home'
81
+ engine.characters.addPlayer({ ...presets.player.thirdPerson, spawn: home });
82
+ engine.content.load(data, { places: { home } }); // on top of the names in content/places.js; content uses { place: 'home', x, z }, quests target: 'home'
80
83
  ```
81
84
  Every `openWorld` part takes `false` (leave it out) or its module's own options object, so you never have to drop the preset for one setting:
82
85
  `openWorld({ seed: 42, camera: 'follow', calendar: { seasons: ['wet', 'dry'], daysPerSeason: 28 }, characters: { npcs: false }, rigid: false, ambience:
@@ -87,9 +90,9 @@ false, debug: false })`;
87
90
  With `terrain: false` the game supplies its ground. Until it does, characters, props and pickups stand on an invisible flat plane at y = 0 (no
88
91
  warning): they look like they float over nothing. Draw the ground yourself, and if it is not flat at y = 0 tell the engine its height:
89
92
  ```js
90
- const floor = new THREE.Mesh(new THREE.PlaneGeometry(200, 200).rotateX(-Math.PI / 2), new THREE.MeshLambertMaterial({ color: 0x8c8c8c })); // what you see
93
+ const floor = new THREE.Mesh(new THREE.PlaneGeometry(200, 200).rotateX(-Math.PI / 2), new THREE.MeshLambertMaterial({ color: 0x8c8c8c })); // what you see
91
94
  floor.receiveShadow = true; engine.add(floor);
92
- engine.setGround({ height: (x, z) => 0 }); // what walking, placing and the camera read (a ramp, a raised floor: return its y here)
95
+ engine.setGround({ height: (x, z) => 0 }); // what walking, placing and the camera read (a ramp, a raised floor: return its y here)
93
96
  ```
94
97
  Walls and obstacles are `engine.collision.addBox(obj, { halfWidth, halfDepth })`; a Blender level brings its own ground (`level()`, next paragraph).
95
98
  `saveKey` must differ per game, otherwise saves overwrite each other. The UI language follows the player's browser (Chinese browser -> Chinese,
@@ -109,23 +112,19 @@ export default { items, startItems, places };
109
112
  1. `npm run map` -> generates `games/my-game/GAMEMAP.md`; check the "engine modules" and "page /" sections.
110
113
  2. `npm run check` -> content validation points out wrong file names, ids and clock-time formats; `npm run types` finds misused engine APIs.
111
114
  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".
112
- 4. `npm test -w games/my-game` -> without `tests/specs/` it runs a smoke test (the page opens, the engine is ready, the console has no errors); to
113
- test gameplay, write `games/my-game/tests/specs/<name>.mjs` in the style of the engine repository's `packages/engine/tests/specs/*.mjs`.
114
- 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
115
- `npm run dev -- my-game`) and open the printed address; read errors in `games/my-game/.threedog/errors.log`.
115
+ 4. `npm test -w games/my-game` -> without `tests/specs/` a smoke test runs; gameplay specs: `COMMANDS.md` §"Running one game only" (a minimal example).
116
+ 5. To see the picture: `npm run shot -- -w my-game /`; while developing `npm run dev -- my-game` and read errors in `games/my-game/.threedog/errors.log`.
116
117
 
117
118
 
118
119
  ## 3. Feel presets (opt-in)
119
- The engine applies no gameplay feel by itself: `weather()` alone has only a calm `clear`, `sky()` has no seasons, and the calls that need a feel
120
- refuse to guess: `createPlayer()` throws `[player-control]` without `control`, `interactions()` throws `[interaction-setup]` without `pick` and keys,
121
- `openWorld()` throws `[open-world-camera]` without `camera`. The core key table holds only movement and menu confirm / cancel; run, jump and interact
122
- keys come from the game. `presets` holds named option objects a game picks on purpose; each only bundles options you could write yourself, so spread
123
- and override:
120
+ The engine applies no gameplay feel by itself: `weather()` alone has only a calm `clear`, `sky()` no seasons, and calls that need a feel refuse to guess
121
+ (`addPlayer()` throws `[player-control]` without `control`, `interactions()` `[interaction-setup]` without `pick`, `openWorld()` `[open-world-camera]` without `camera`).
122
+ `presets` holds named option objects a game picks on purpose, bundling options you could write yourself, so spread and override:
124
123
  ```js fragment
125
124
  import { presets, weather, calendar, sky, followCamera, interactions } from 'threedog';
126
125
  engine.use(calendar(presets.calendar.fourSeasons), sky(), weather({ ...presets.weather.temperate, autoPool: ['clear', 'rain'] }), followCamera(presets.camera.overShoulder));
127
- engine.use(interactions({ ...presets.interactions.facing })); // nearest / facing / aim, each with E
128
- const player = engine.characters.createPlayer({ ...presets.player.lockOn, faceTarget: boss }); // none / thirdPerson / lockOn / aim / sideScroller
126
+ engine.use(interactions({ ...presets.interactions.facing })); // nearest / facing / aim, each with E
127
+ const player = engine.characters.addPlayer({ ...presets.player.lockOn, faceTarget: boss }); // none / thirdPerson / lockOn / aim / sideScroller
129
128
  ```
130
129
  The run / jump keys are `presets.bindings.walk`. No module or preset takes keys: every key comes from `createEngine({ bindings })` or `engine.input.bind(...)`.
131
130
 
@@ -1,6 +1,9 @@
1
1
  # Adding an NPC (schedule + dialogue)
2
2
 
3
- **In this recipe**: 1. Write data · 2. Add in code · NPC data and model · Custom behavior · Avoidance · A guard you build yourself · Dialogue choices · 3. Verify · Bubbles
3
+ > **Covers:** people with schedules, dialogue, avoidance and behavior of your own.
4
+ > **Use when:** a character the player meets or talks to.
5
+ > **Shortest:** an entry in content data plus `characters()`, `interactions()`, `dialogue()` (§1).
6
+ > **Sections:** 1 Write data recommended) · 2 Add in code · NPC data and model · Changing behavior / custom · Avoidance NPCs don't clump · A guard you build · Pick a dialogue choice · 3 Verify · Talking in a bubble
4
7
 
5
8
  Modules needed: `characters()` (NPCs on by default), `interactions({ ...presets.interactions.nearest })`, `dialogue()`; clock-time schedules need
6
9
  `calendar()` with a day cycle (`dayLength`, e.g. `presets.calendar.cycle`: without one the clock never moves and the NPC keeps to one stop). `openWorld()`
@@ -13,16 +16,16 @@ interactions({ ...presets.interactions.nearest }), dialogue(), content())`.
13
16
  export default {
14
17
  guard: {
15
18
  name: 'Gate guard',
16
- colors: { body: 0xc89a5a, legs: 0x5b4a3a, hair: 0x3a2a1a }, // omit to use the default colors
17
- start: { place: 'home', x: 6, z: -3 }, // starting position; omitted = the first stop of the schedule
18
- schedule: [ // at is a clock time 'HH:MM'; at that time the NPC walks there (pathfinding is automatic)
19
+ colors: { body: 0xc89a5a, legs: 0x5b4a3a, hair: 0x3a2a1a }, // omit to use the default colors
20
+ start: { place: 'home', x: 6, z: -3 }, // starting position; omitted = the first stop of the schedule
21
+ schedule: [ // at is a clock time 'HH:MM'; at that time the NPC walks there (pathfinding is automatic)
19
22
  { at: '07:00', place: 'home', x: 6, z: -3 },
20
23
  { at: '13:00', place: 'tower' },
21
24
  { at: '18:30', place: 'home', x: 2, z: 4 },
22
25
  ],
23
- interact: { op: 'npc.talk' }, // the interact key nearby talks: dialogue 'guard' (the NPC id) in dialogues.js
26
+ interact: { op: 'npc.talk' }, // the interact key nearby talks: dialogue 'guard' (the NPC id) in dialogues.js
24
27
  },
25
- cat: { name: 'Cat', start: { place: 'home' }, behavior: 'wander', mind: { radius: 6 } }, // no schedule: write behavior + start, omit schedule
28
+ cat: { name: 'Cat', start: { place: 'home' }, behavior: 'wander', mind: { radius: 6 } }, // no schedule: write behavior + start, omit schedule
26
29
  };
27
30
  ```
28
31
  A content NPC takes every `npcs.add` option (`speed`, `interact`, `arriveDistance`, `pathStep`, `repath`, `model`...) written as a
@@ -37,7 +40,7 @@ export default {
37
40
  speaker: 'Gate guard',
38
41
  nodes: {
39
42
  start: {
40
- text: [ // several variants: the first whose condition holds is used
43
+ text: [ // several variants: the first whose condition holds is used
41
44
  { if: { flag: 'metGuard' }, text: 'Back again?' },
42
45
  { text: 'Halt. First time here?' },
43
46
  ],
@@ -46,7 +49,7 @@ export default {
46
49
  },
47
50
  ask: { text: 'A pass costs one coin.', choices: [
48
51
  { text: 'Buy one', next: 'buy', if: { has: { coin: 1 } } },
49
- { text: 'No thanks' }, // a choice with no next = the dialogue ends; a plain node with no next waits for one more interact press, then ends
52
+ { text: 'No thanks' }, // a choice with no next = the dialogue ends; a plain node with no next waits for one more interact press, then ends
50
53
  ] },
51
54
  buy: { text: 'Move along.', do: [{ take: { coin: 1 } }, { give: { pass: 1 } }], next: 'end' },
52
55
  },
@@ -62,8 +65,8 @@ from a level marker (such as `npc_guard`). Add a new content file to `content/in
62
65
  ## 2. Add in code (temporary NPCs, dynamic schedules)
63
66
  ```js
64
67
  engine.dialogue.define('passerby', { start: { text: 'Nice day.', speaker: 'Passerby' } });
65
- const npc = engine.npcs.add({ id: 'passerby', name: 'Passerby', position: [10, 0, 5], schedule: [{ at: '08:00', position: [20, 0, 5] }], interact: { op: 'npc.talk' } }); // at: 'HH:MM' or 0-1; without id the name is used
66
- engine.npcs.remove('passerby'); // remove by id, name or handle
68
+ const npc = engine.npcs.add({ id: 'passerby', name: 'Passerby', position: [10, 0, 5], schedule: [{ at: '08:00', position: [20, 0, 5] }], interact: { op: 'npc.talk' } }); // at: 'HH:MM' or 0-1; without id the name is used
69
+ engine.npcs.remove('passerby'); // remove by id, name or handle
67
70
  ```
68
71
 
69
72
  **An NPC that stands still** (a quest giver): give `start` and omit both `schedule` and `behavior`; the default `schedule` behavior with no stops
@@ -82,6 +85,7 @@ you come near; changing level only removes the model, and it is rebuilt automati
82
85
  the model is built at the computed position; nearby it paths around obstacles as usual.
83
86
  - Add things to the model (a hat, a name tag) after every model build; don't call `npc.root.add(...)` right after add (the first model is built in the
84
87
  next fixed step; for one immediately use `engine.world.refresh()`).
88
+ - Looking at the player: `npc.character.anim.addAim({ bones: ['Neck', 'Head'], target: engine.player.root })`, added with the rest of its model ([13 §3e](13-animation.md)).
85
89
  - When two NPCs share a name, give each an `id` (without an id the name is the id, and in development a duplicate name throws). NPCs in content are
86
90
  the world's **initial data**: the save records only changes such as position and state; schedule and name follow the content.
87
91
  - Change data with `engine.world.set(npc.id, { mood: 'happy' })` (emits the world:change event); only plain values go in the data, models and
@@ -91,9 +95,9 @@ you come near; changing level only removes the model, and it is rebuilt automati
91
95
  What an NPC "does" is a swappable **behavior**: the `behavior` field in the data picks it, and the schedule (`'schedule'`, the default) is just one of
92
96
  them. Built in there is also `'wander'` (random wandering near home, using `engine.random`, same seed same result).
93
97
  ```js
94
- npc.setBehavior('wander', { radius: 12 }); // home = current position, wander within 12 meters (pause: [2, 6] pause seconds, home: { x, z } sets the center)
95
- npc.setBehavior('schedule'); // back to the schedule
96
- engine.npcs.add({ id: 'dog', name: 'Dog', position: [5, 0, 5], behavior: 'wander', mind: { radius: 8 } }); // wanders from the start
98
+ npc.setBehavior('wander', { radius: 12 }); // home = current position, wander within 12 meters (pause: [2, 6] pause seconds, home: { x, z } sets the center)
99
+ npc.setBehavior('schedule'); // back to the schedule
100
+ engine.npcs.add({ id: 'dog', name: 'Dog', position: [5, 0, 5], behavior: 'wander', mind: { radius: 8 } }); // wanders from the start
97
101
  ```
98
102
  The behavior name and `mind` (the behavior's parameters and memory) are in the NPC data and are saved; after changing behavior or loading, the NPC
99
103
  carries on with the new behavior. A wrong behavior name throws and lists the registered ones. NPCs in content can also write `behavior` + `mind`
@@ -112,8 +116,8 @@ or after loading.
112
116
  engine.npcs.behavior('chase', {
113
117
  near(rec, dt, npc) {
114
118
  const p = npc.position, t = engine.player.position, dx = t.x - p.x, dz = t.z - p.z, d = Math.hypot(dx, dz) || 1;
115
- npc.character?.move(d > 2 ? dx / d : 0, d > 2 ? dz / d : 0, false, dt); // no model: don't move
116
- engine.world.move(rec.id, npc.position); // write the position back to the data
119
+ npc.character?.move(d > 2 ? dx / d : 0, d > 2 ? dz / d : 0, false, dt); // no model: don't move
120
+ engine.world.move(rec.id, npc.position); // write the position back to the data
117
121
  },
118
122
  });
119
123
  npc.setBehavior('chase');
@@ -130,8 +134,8 @@ into walls. The built-in `schedule` and `wander` both avoid.
130
134
  `frameEvery` gives identical positions.
131
135
  - Tune or turn off:
132
136
  ```js
133
- engine.npcs.avoid.set({ radius: 0.6, strength: 2 }); // stand sparser (radius in meters), push slower (strength in meters/second)
134
- engine.npcs.avoid.set(false); // turn off (ghosts, crowds passing through); set(true) turns it on again
137
+ engine.npcs.avoid.set({ radius: 0.6, strength: 2 }); // stand sparser (radius in meters), push slower (strength in meters/second)
138
+ engine.npcs.avoid.set(false); // turn off (ghosts, crowds passing through); set(true) turns it on again
135
139
  ```
136
140
  - Far away (no model) NPCs are simulated from data without per-NPC avoidance; a few steps after a model is built on approach they get pushed apart.
137
141
  - `nav({ crowd: true })` replaces this push with Recast crowd agents: they route around obstacles along the navmesh but do not guarantee identical
@@ -157,7 +161,7 @@ const guard = new Character(engine, { rig: { root: myGuardMesh } });
157
161
  engine.add(guard.root);
158
162
  guard.placeAt(post);
159
163
  const walk = guard.walkTo(player.position, { arrive: 1.5 });
160
- if ((await walk).status === 'noPath') guard.face(player); // walk.remove() cancels
164
+ if ((await walk).status === 'noPath') guard.face(player); // walk.remove() cancels
161
165
  ```
162
166
 
163
167
  ## Pick a dialogue choice, advance, close a dialogue
@@ -1,12 +1,14 @@
1
1
  # Adding items and pickups
2
2
 
3
- **In this recipe**: Pick and count · 1. Write data · 2. In code · Single pieces · Limits · Using and dropping · The inventory window · Chests / corpses / shelves ·
4
- 3. Verify
3
+ > **Covers:** items, pickups, the inventory, single pieces, containers and shelves.
4
+ > **Use when:** things the player picks up, carries, uses or stores.
5
+ > **Shortest:** `engine.interactions.add(mesh, { id, label })` on your own mesh, or items as data (§1).
6
+ > **Sections:** Pick and count meshes · Items and pickups · 1 Write data recommended) · 2 In code dynamic · Single pieces durability, upgrade · Limits all optional, none · Using and dropping ops) · The inventory window UI · Chests / corpses / · 3 Verify
5
7
 
6
8
  ## Pick and count: meshes you built, no bag
7
9
  Shells on a beach, four kinds of flowers, letters to collect: things the player takes and a number goes up. `interactions()`, `hud()` and a key (`createEngine({ bindings: presets.bindings.interact })`: E) are enough:
8
10
  ```js fragment
9
- engine.hud.counter('shells', { label: 'Shells', value: 0, max: 4 }); // at setup, not on session:start
11
+ engine.hud.addCounter('shells', { label: 'Shells', value: 0, max: 4 }); // at setup, not on session:start
10
12
  shells.forEach((shell, i) => engine.interactions.add(shell, { id: `shell-${i}`, label: 'Pick up', once: true, counter: 'shells', onUse: () => engine.audio.sfx('pick') }));
11
13
  ```
12
14
  `once` hides the mesh after a use (`onUse` returning `{ ok: false }` leaves it; an async `onUse` is judged when it settles, and a throw leaves it too); `counter` adds 1 through `engine.hud.bump(name, n)`, and does nothing without
@@ -34,16 +36,16 @@ their own bag; inside an op use `inventory.of(ctx.actor)`, never a fixed `'playe
34
36
  // Items: id -> name, icon, description. stack = how many fit in one slot (default 99; more spill into further slots), weight (optional), color = color when dropped on the ground
35
37
  export default {
36
38
  mushroom: { name: 'Mushroom', icon: '🍄', desc: 'Found in the woods', color: 0xc0504d },
37
- coin: { name: 'Coin', icon: '🪙', stack: 99999 }, // currency: one slot however much you carry; full buying/selling in recipe 22
39
+ coin: { name: 'Coin', icon: '🪙', stack: 99999 }, // currency: one slot however much you carry; full buying/selling in recipe 22
38
40
  };
39
- export const startItems = { coin: 3 }; // what the inventory holds at the start (optional)
41
+ export const startItems = { coin: 3 }; // what the inventory holds at the start (optional)
40
42
  ```
41
43
  `content/pickups.js` (a list):
42
44
  ```js
43
45
  export default [
44
- { item: 'mushroom', place: 'home', x: 8, z: 3, respawn: 120 }, // respawn: after how many calendar seconds it grows back (omitted = never again)
45
- { item: 'coin', x: 40, z: -12, count: 5, auto: true }, // without place it is a world coordinate; count = how many at once; auto = taken by walking into it
46
- { item: 'sword', x: 12, z: 4, data: { durability: 60 } }, // data = this piece's own data (see "Single pieces"); radius = reach in meters (default 2)
46
+ { item: 'mushroom', place: 'home', x: 8, z: 3, respawn: 120 }, // respawn: after how many calendar seconds it grows back (omitted = never again)
47
+ { item: 'coin', x: 40, z: -12, count: 5, auto: true }, // without place it is a world coordinate; count = how many at once; auto = taken by walking into it
48
+ { item: 'sword', x: 12, z: 4, data: { durability: 60 } }, // data = this piece's own data (see "Single pieces"); radius = reach in meters (default 2)
47
49
  ];
48
50
  ```
49
51
  Remember to `import items, { startItems } from './items.js'` and `import pickups from './pickups.js'` in `content/index.js` and put them in the exported object.
@@ -57,13 +59,13 @@ and at that time (also when far away with no model) it returns to the ground. Pi
57
59
 
58
60
  ## 2. In code (dynamic drops, custom models, instant effects)
59
61
  ```js fragment
60
- engine.inventory.define('gem', { name: 'Gem', icon: '💎', color: 0x66ccff }); // shape: model: 'gemModel' (an asset name), else an asset named 'pickup:gem' / 'pickup', else a gray box (spawn { mesh } puts one object of the game's own down instead)
61
- const gem = engine.pickups.spawn(engine.player.position, { give: 'gem', count: 1 }); // returns a handle; gem.remove() deletes data and model together
62
+ engine.inventory.define('gem', { name: 'Gem', icon: '💎', color: 0x66ccff }); // shape: model: 'gemModel' (an asset name), else an asset named 'pickup:gem' / 'pickup', else a gray box (spawn { mesh } puts one object of the game's own down instead)
63
+ const gem = engine.pickups.spawn(engine.player.position, { give: 'gem', count: 1 }); // returns a handle; gem.remove() deletes data and model together
62
64
  // opts.id writes a stable id (spawning again with the same id reuses the existing one)
63
- engine.inventory.add('coin', 2); // the local bag; { ok: true, key: 'coin', added: 2 }, or { ok: false, code: 'full' } if none fit
64
- engine.pickups.spawn([8, 0, 2], { give: 'ammo', count: 30, auto: true, radius: 1.2 }); // taken on touch by whoever touches it (pickups.takers), no key, no prompt
65
- engine.pickups.spawn(p, { give: (e, { actor }) => e.ops.run('hp.heal', { n: 25 }, { actor }), name: 'Medkit', model: 'medkit', auto: true }); // instant effect, no inventory needed
66
- engine.events.on('pickup:take', ({ actor, x, z }) => engine.particles?.emit('dust', { x, y: engine.surface(x, z), z }, { count: 10 })); // also item:add / item:remove (with container, actor) / item:use
65
+ engine.inventory.add('coin', 2); // the local bag; { ok: true, key: 'coin', added: 2 }, or { ok: false, code: 'full' } if none fit
66
+ engine.pickups.spawn([8, 0, 2], { give: 'ammo', count: 30, auto: true, radius: 1.2 }); // taken on touch by whoever touches it (pickups.takers), no key, no prompt
67
+ engine.pickups.spawn(p, { give: (e, { actor }) => e.ops.run('hp.heal', { n: 25 }, { actor }), name: 'Medkit', model: 'medkit', auto: true }); // instant effect, no inventory needed
68
+ engine.events.on('pickup:take', ({ actor, x, z }) => engine.particles?.emit('dust', { x, y: engine.surface(x, z), z }, { count: 10 })); // also item:add / item:remove (with container, actor) / item:use
67
69
  ```
68
70
  The default reach is `pickups({ radius: 2 })`; each pickup can set its own `radius`. Reach is a sphere around the pickup, so a coin on a ledge less than `radius` above the player is taken from under it: give it a smaller `radius`. Taking one is the op `pickup.take { id }` (net: `'peer'`): the
69
71
  interact key, auto pickups, a net client's press (sent to the host, which puts the item into that peer's bag) and tests all run it as `ctx.actor`.
@@ -77,15 +79,15 @@ also takes a key.
77
79
  ```js
78
80
  const I = engine.inventory;
79
81
  I.define('sword', { name: 'Sword', stack: 1 });
80
- const { key } = I.add('sword', 1, { data: { durability: 80, level: 3 } }); // 'sword#7' (add returns { ok: false, code: 'full' } when it does not fit)
82
+ const { key } = I.add('sword', 1, { data: { durability: 80, level: 3 } }); // 'sword#7' (add returns { ok: false, code: 'full' } when it does not fit)
81
83
  // change it inside an op or fixed step (data objects are frozen: always pass a new one; the key stays the same)
82
84
  const s = I.get(key); I.setData(key, { ...s.data, durability: s.data.durability - 1 });
83
85
  I.container('chest-1', { capacity: 8 });
84
- I.transfer('player', 'chest-1', key); // exactly this sword; it keeps its data and key
85
- I.container('chest-1').remove(key); // exactly this one; I.remove('sword') takes plain ones first, then the oldest
86
+ I.transfer('player', 'chest-1', key); // exactly this sword; it keeps its data and key
87
+ I.container('chest-1').remove(key); // exactly this one; I.remove('sword') takes plain ones first, then the oldest
86
88
  I.define('tomato', { name: 'Tomato' });
87
- const t = I.add('tomato', 5, { data: { quality: 2 } }); // stackable: equal data joins the same entry
88
- I.setData(t.key, { quality: 1 }, 2); // only 2 of that stack change: they split off under a new key (returned)
89
+ const t = I.add('tomato', 5, { data: { quality: 2 } }); // stackable: equal data joins the same entry
90
+ I.setData(t.key, { quality: 1 }, 2); // only 2 of that stack change: they split off under a new key (returned)
89
91
  ```
90
92
  Data and keys are saved with the container. Which piece a player means is chosen by key (a click on a row of `list()`), so ops take `item` as an id or a key.
91
93
 
@@ -96,18 +98,18 @@ Data and keys are saved with the container. Which piece a player means is chosen
96
98
  ## Using and dropping (ops)
97
99
  ```js
98
100
  I.define('potion', { name: 'Potion', consume: true, use: (e, { actor, key, data }) => heal(actor, 30), canUse: (e, { actor }) => hp(actor) < 100 || 'full' });
99
- engine.ops.run('inventory.use', { item: 'potion' }); // runs canUse / use; consume removes one first; emits item:use
100
- engine.ops.run('inventory.drop', { item: 'sword#7' }); // a pickup at the actor's feet, keeps its data
101
+ engine.ops.run('inventory.use', { item: 'potion' }); // runs canUse / use; consume removes one first; emits item:use
102
+ engine.ops.run('inventory.drop', { item: 'sword#7' }); // a pickup at the actor's feet, keeps its data
101
103
  ```
102
104
  Both act on `ctx.actor`'s container (`'player'` by default).
103
105
 
104
106
  **Replace an item when the bag is full**: `inventory.trade` takes A and gives B as one all-or-nothing step (it checks that B fits once A is gone), and
105
107
  can be undone.
106
108
  ```js fragment
107
- const r = engine.ops.run('inventory.trade', { take: 'rusty_key', give: 'gold_key' }); // also takeN / giveN; take may be an entry key ('sword#3')
108
- if (!r.ok) say(r.code); // 'notEnough' (A missing) | 'full' (B does not fit even after A leaves)
109
- engine.ops.undo('inventory.trade', { take: 'rusty_key', give: 'gold_key' }, r.value); // gives A back (with its data), takes B away
110
- engine.inventory.trade('rusty_key', 'gold_key'); // the same from code; a container has .trade() too
109
+ const r = engine.ops.run('inventory.trade', { take: 'rusty_key', give: 'gold_key' }); // also takeN / giveN; take may be an entry key ('sword#3')
110
+ if (!r.ok) say(r.code); // 'notEnough' (A missing) | 'full' (B does not fit even after A leaves)
111
+ engine.ops.undo('inventory.trade', { take: 'rusty_key', give: 'gold_key' }, r.value); // gives A back (with its data), takes B away
112
+ engine.inventory.trade('rusty_key', 'gold_key'); // the same from code; a container has .trade() too
111
113
  ```
112
114
  **Why a pickup failed**: a pickup that does not fit fails `interaction.use` with code `full` (the item stays on the ground):
113
115
  `const r = engine.ops.run('interaction.use'); if (!r.ok) say(r.code); // 'full'`.
@@ -119,22 +121,22 @@ is open; default `false` (the world keeps running behind the window). Switchable
119
121
  The window is a UI part (recipe 26): the engine opens and closes it (the bound `inventory` key, Esc, input lock), the part only draws
120
122
  `{ title, hint, items: list(), capacity, used, weight, maxWeight }`.
121
123
  ```js
122
- engine.ui.set('inventory', false); // no window at all (the key does nothing, no DOM)
123
- engine.ui.set('inventory', { drop: true }); // default window plus a Drop button per row (Use appears for items with use)
124
- engine.ui.set('inventory', (engine) => { // your own: grid, drag and drop, anything; buttons run ops with an entry's key
124
+ engine.ui.set('inventory', false); // no window at all (the key does nothing, no DOM)
125
+ engine.ui.set('inventory', { drop: true }); // default window plus a Drop button per row (Use appears for items with use)
126
+ engine.ui.set('inventory', (engine) => { // your own: grid, drag and drop, anything; buttons run ops with an entry's key
125
127
  const el = document.createElement('div'); engine.uiRoot.appendChild(el);
126
128
  el.onclick = ev => { const key = ev.target.dataset.key; if (key) engine.ops.run('inventory.use', { item: key }); };
127
129
  const draw = d => { el.innerHTML = d.items.map(i => `<button data-key="${i.key}">${i.def.name} ×${i.count}</button>`).join(''); };
128
130
  return { show: d => { el.hidden = false; draw(d); }, update: draw, hide: () => { el.hidden = true; }, dispose: () => el.remove() };
129
131
  });
130
- engine.ui.open('inventory'); engine.ui.close('inventory'); // open / close from code
132
+ engine.ui.open('inventory'); engine.ui.close('inventory'); // open / close from code
131
133
  ```
132
134
  The shape of an item on the ground is a model name from an asset pack, built through the same path as content props (recipe 05 §1): the item's `model`,
133
135
  else a model named `pickup:<item id>`, else one named `pickup`, else a neutral gray box. A generator that returns bare geometry is drawn with
134
136
  `engine.pickups.material` in the item's own `color`.
135
137
  ```js
136
- engine.use(pickups({ color: 0xd8c070, size: 0.3, lift: 0.5 })); // default color, placeholder box, height above the ground
137
- engine.pickups.material = new THREE.MeshStandardMaterial({ metalness: 0.8, roughness: 0.3 }); // swaps every box and geometry-only model; used as given
138
+ engine.use(pickups({ color: 0xd8c070, size: 0.3, lift: 0.5 })); // default color, placeholder box, height above the ground
139
+ engine.pickups.material = new THREE.MeshStandardMaterial({ metalness: 0.8, roughness: 0.3 }); // swaps every box and geometry-only model; used as given
138
140
  ```
139
141
  A pickup or item with its own `color`, and a vertex-colored geometry, draw with a copy of that material carrying the color. For one object of the game's own pass
140
142
  `{ mesh }` (a three.js object cannot go into a save, so after loading it falls back to the item's model).
@@ -147,10 +149,10 @@ to get or create one (the same id returns the same one); it has the inventory's
147
149
  ```js
148
150
  const I = engine.inventory;
149
151
  const chest = I.container('chest-1', { capacity: 8 });
150
- chest.add('bandage', 2); // { ok: false, code: 'full' } if none fit; if part fits, that part goes in and `added` says how many
151
- I.transfer(chest, 'player', 'bandage', 1); // a container or a container id both work; returns how many were actually moved (fewer / 0 if the inventory is full)
152
- I.transfer('player', chest, 'coin', 5); // shelves and money boxes work the same way
153
- chest.on('remove', ({ id, count, actor }) => console.log(actor, 'took', id, count)); // every container emits item:add / item:remove with { container, actor, id, key, count, total }
152
+ chest.add('bandage', 2); // { ok: false, code: 'full' } if none fit; if part fits, that part goes in and `added` says how many
153
+ I.transfer(chest, 'player', 'bandage', 1); // a container or a container id both work; returns how many were actually moved (fewer / 0 if the inventory is full)
154
+ I.transfer('player', chest, 'coin', 5); // shelves and money boxes work the same way
155
+ chest.on('remove', ({ id, count, actor }) => console.log(actor, 'took', id, count)); // every container emits item:add / item:remove with { container, actor, id, key, count, total }
154
156
  ```
155
157
  - **Relation to world**: a container id can be a world record's id directly (for example `'prop:chest:3'`, a zombie's id). Containers do not depend on
156
158
  models: a far-away chest has no model but its contents still exist; contents are saved (containers that hold something, and those that were given
@@ -1,5 +1,10 @@
1
1
  # Adding quests (with HUD objective markers)
2
2
 
3
+ > **Covers:** quests as data or code, progress, objective markers.
4
+ > **Use when:** goals the player follows and checks off.
5
+ > **Shortest:** a quest entry in content data with `quests()` installed (§1).
6
+ > **Sections:** 1 Write data recommended) · 2 In code complex · 3 Verify · Reading and moving progress
7
+
3
8
  Modules needed: `quests()` (quest log; the game binds its `quests` action: `presets.bindings.quests` is J / gamepad Select, `quests: []` for
4
9
  none); objective markers need `hud()` (neither is in openWorld, add them yourself:
5
10
  `engine.use(openWorld({ camera: 'follow', ...}), quests(), hud())`).
@@ -13,10 +18,10 @@ export default {
13
18
  'restore-power': {
14
19
  title: 'Restore power',
15
20
  desc: 'The engineer needs three fuses to restart the relay.',
16
- startOn: 'engine:ready', // the event that starts it automatically (or use { startQuest: 'restore-power' } in a dialogue)
21
+ startOn: 'engine:ready', // the event that starts it automatically (or use { startQuest: 'restore-power' } in a dialogue)
17
22
  steps: [
18
- { id: 'talk', text: 'Talk to the engineer', done: { flag: 'metEngineer' }, target: { npc: 'engineer' } }, // the marker follows the NPC
19
- { id: 'gather', text: 'Find 3 fuses', done: { has: { fuse: 3 } }, target: 'storage' }, // a place name
23
+ { id: 'talk', text: 'Talk to the engineer', done: { flag: 'metEngineer' }, target: { npc: 'engineer' } }, // the marker follows the NPC
24
+ { id: 'gather', text: 'Find 3 fuses', done: { has: { fuse: 3 } }, target: 'storage' }, // a place name
20
25
  { id: 'return', text: 'Fit them at the relay', done: { flag: 'relayOn' }, target: { place: 'home', x: 0, z: 3 } },
21
26
  ],
22
27
  reward: [{ take: { fuse: 3 } }, { give: { coin: 5 } }, { toast: 'Power restored!' }],
@@ -43,13 +48,13 @@ Not every quest is a straight line. A step can hold several goals done in any or
43
48
  startOn: 'engine:ready',
44
49
  steps: [
45
50
  { text: 'Reach the camp', done: { flag: 'atCamp' }, target: 'camp' },
46
- { all: [ // text defaults to the required goals: "Hold the north gate / Hold the south gate"
51
+ { all: [ // text defaults to the required goals: "Hold the north gate / Hold the south gate"
47
52
  { text: 'Hold the north gate', done: { counter: { northWaves: 3 } }, target: 'northGate' },
48
53
  { text: 'Hold the south gate', done: { counter: { southWaves: 3 } }, target: 'southGate' },
49
- { text: 'No ally hurt', done: { notFlag: 'allyHurt' }, optional: true }, // a bonus: never blocks, shown done if met in time
54
+ { text: 'No ally hurt', done: { notFlag: 'allyHurt' }, optional: true }, // a bonus: never blocks, shown done if met in time
50
55
  ] },
51
56
  ],
52
- fail: { flag: 'campBurned' }, // checked while the quest is active
57
+ fail: { flag: 'campBurned' }, // checked while the quest is active
53
58
  onFail: [{ toast: 'The camp has fallen' }, { setFlag: 'mayRetryCamp' }],
54
59
  reward: { give: { coin: 20 } },
55
60
  },
@@ -62,18 +67,18 @@ Not every quest is a straight line. A step can hold several goals done in any or
62
67
  ```js
63
68
  engine.quests.define('slimes3', {
64
69
  title: 'Clear the cellar',
65
- steps: [{ text: 'Defeat 3 slimes', done: e => e.vars.counter('slimes') >= 3, target: () => engine.npcs.get('engineer')?.position }], // the function returns a position every frame: when the NPC is far away and has no model, root is null, so read position from the data
70
+ steps: [{ text: 'Defeat 3 slimes', done: e => e.vars.counter('slimes') >= 3, target: () => engine.npcs.get('engineer')?.position }], // the function returns a position every frame: when the NPC is far away and has no model, root is null, so read position from the data
66
71
  reward: e => e.inventory.add('coin', 3),
67
72
  });
68
73
  engine.quests.start('slimes3');
69
- engine.vars.bump('slimes'); // each time one is defeated
70
- engine.events.on('quest:done', ({ id }) => { /* quest completed */ }); // there are also quest:start, quest:step, quest:part and quest:fail
74
+ engine.vars.bump('slimes'); // each time one is defeated
75
+ engine.events.on('quest:done', ({ id }) => { /* quest completed */ }); // there are also quest:start, quest:step, quest:part and quest:fail
71
76
  ```
72
77
  A failed reward (full bag, refused `{ op }`, a function returning `{ ok: false, code }`) still finishes the quest and fires `quest:unpaid`. Items that did not fit stay owed (`quests.list()`, saved) until there is room, unless the game decides itself with `onUnpaid` (effect words, or `(e, answer) => ...`).
73
78
 
74
79
  To turn off automatic markers: `hud({ questMarkers: false })`. To add a marker by hand: `const m = engine.hud.marker('gate', { label: 'Gate' }); m.remove();`;
75
80
  content effects can add them too: `{ marker: 'gate' }` / `{ clearMarker: 'gate' }`. A counter in the screen corner:
76
- `engine.hud.counter('slimes', { label: 'Slimes', value: 2, max: 3 })`; `anchor: 'top-right'` (or `top`, `bottom`, `bottom-left`...) puts a counter
81
+ `engine.hud.addCounter('slimes', { label: 'Slimes', value: 2, max: 3 })`; `anchor: 'top-right'` (or `top`, `bottom`, `bottom-left`...) puts a counter
77
82
  or bar in that screen column.
78
83
 
79
84
  ## 3. Verify