threedog 1.1.0 → 1.3.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 (370) hide show
  1. package/CHANGELOG.md +893 -798
  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 +187 -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 +17 -7
  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 +8 -7
  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 +50 -28
  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 +36 -15
  85. package/core/scene/adaptive.js +144 -21
  86. package/core/scene/drawOnly.js +17 -0
  87. package/core/scene/gameLights.js +47 -4
  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 +17 -11
  103. package/docs/COMMANDS.md +139 -142
  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 +30 -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/characters.md +10 -8
  112. package/docs/api/collision.md +6 -4
  113. package/docs/api/engine.md +16 -16
  114. package/docs/api/events.md +3 -2
  115. package/docs/api/ground.md +6 -5
  116. package/docs/api/hud.md +4 -2
  117. package/docs/api/input.md +5 -5
  118. package/docs/api/particles.md +2 -1
  119. package/docs/api/photo.md +3 -0
  120. package/docs/api/post.md +7 -4
  121. package/docs/api/quests.md +2 -2
  122. package/docs/api/rays.md +1 -2
  123. package/docs/api/saves.md +7 -7
  124. package/docs/api/settings.md +2 -2
  125. package/docs/api/tools.md +3 -1
  126. package/docs/api/vars.md +1 -1
  127. package/docs/api/vegetation.md +4 -2
  128. package/docs/api/world.md +1 -1
  129. package/docs/recipes/01-new-game.md +16 -17
  130. package/docs/recipes/02-npc.md +22 -18
  131. package/docs/recipes/03-items-pickups.md +37 -35
  132. package/docs/recipes/04-quests.md +15 -10
  133. package/docs/recipes/05-props-bake.md +101 -95
  134. package/docs/recipes/06-clock-events.md +28 -28
  135. package/docs/recipes/07-flow-scenes-pause.md +29 -26
  136. package/docs/recipes/08-weather-sky.md +52 -64
  137. package/docs/recipes/09-materials-lights-models.md +26 -17
  138. package/docs/recipes/10-blender-level.md +15 -10
  139. package/docs/recipes/11-vehicles.md +12 -7
  140. package/docs/recipes/12-navmesh.md +44 -26
  141. package/docs/recipes/13-animation.md +56 -45
  142. package/docs/recipes/14-custom-module.md +21 -18
  143. package/docs/recipes/15-perf.md +61 -55
  144. package/docs/recipes/16-dev-bridge.md +24 -33
  145. package/docs/recipes/18-world.md +36 -42
  146. package/docs/recipes/19-shooting-picking.md +20 -15
  147. package/docs/recipes/20-content-actions-save.md +48 -56
  148. package/docs/recipes/21-camera.md +45 -54
  149. package/docs/recipes/22-shop-gold.md +12 -7
  150. package/docs/recipes/23-ops.md +25 -23
  151. package/docs/recipes/26-ui-parts.md +67 -47
  152. package/docs/recipes/27-net.md +12 -7
  153. package/docs/recipes/28-terrain.md +24 -21
  154. package/docs/recipes/29-grid.md +32 -27
  155. package/docs/recipes/30-templates.md +21 -20
  156. package/docs/recipes/31-audio.md +39 -22
  157. package/docs/recipes/32-action-game.md +19 -14
  158. package/docs/recipes/33-stream-sources.md +15 -11
  159. package/docs/recipes/34-environment-lighting.md +126 -70
  160. package/docs/recipes/35-picture-from-reference.md +8 -8
  161. package/docs/recipes/36-ground-plants.md +27 -21
  162. package/docs/recipes/40-scene.md +19 -28
  163. package/docs/recipes/43-shader-patches-surfaces.md +15 -12
  164. package/docs/recipes/44-water-weather-hooks.md +34 -31
  165. package/docs/recipes/45-cascaded-shadows.md +35 -26
  166. package/docs/recipes/46-blender-art-route.md +7 -2
  167. package/docs/recipes/49-game-module-contract.md +13 -8
  168. package/docs/recipes/50-own-renderer.md +6 -2
  169. package/docs/recipes/51-capability-catalog.md +15 -8
  170. package/docs/recipes/52-around-the-picture.md +34 -32
  171. package/docs/recipes/53-ground-up-close.md +6 -1
  172. package/docs/recipes/55-mods-time-wrap.md +27 -19
  173. package/docs/recipes/56-webgpu-tsl.md +75 -43
  174. package/docs/recipes/57-control.md +18 -13
  175. package/docs/recipes/58-input.md +26 -16
  176. package/docs/recipes/59-depth-post-effects.md +8 -3
  177. package/docs/recipes/60-judge-the-picture.md +10 -9
  178. package/docs/recipes/61-deploy.md +5 -0
  179. package/docs/recipes/62-picture-code.md +72 -79
  180. package/docs/recipes/63-third-person-start.md +48 -45
  181. package/docs/recipes/64-particles.md +22 -10
  182. package/docs/recipes/65-swarm.md +18 -13
  183. package/docs/recipes/66-common-tasks.md +38 -35
  184. package/examples/action/.threedog/content-index.json +1 -1
  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/.threedog/content-index.json +1 -1
  189. package/examples/perf-island/GAMEMAP.md +3 -3
  190. package/examples/perf-island/picture/lights.js +2 -1
  191. package/examples/plain-picture/GAMEMAP.md +1 -1
  192. package/examples/rc2d/GAMEMAP.md +1 -1
  193. package/examples/styletest/.threedog/content-index.json +1 -1
  194. package/examples/styletest/GAMEMAP.md +2 -2
  195. package/examples/styletest/main.js +1 -1
  196. package/examples/techniques/interior-light/README.md +3 -3
  197. package/examples/techniques/interior-light/interiorLight.js +2 -4
  198. package/examples/techniques/interior-light/picture/lights.js +2 -1
  199. package/examples/techniques/modular-building/picture/lights.js +3 -1
  200. package/examples/techniques/outlines-and-rim/picture/lights.js +3 -1
  201. package/examples/techniques/procedural-animation/README.md +1 -1
  202. package/examples/techniques/procedural-animation/main.js +1 -1
  203. package/examples/webgpu-tsl/GAMEMAP.md +1 -1
  204. package/examples/world/.threedog/content-index.json +1 -1
  205. package/examples/world/GAMEMAP.md +2 -3
  206. package/examples/world/art/humanoid.js +1 -1
  207. package/examples/world/main.js +6 -3
  208. package/index.d.ts +2 -2
  209. package/llms.txt +101 -0
  210. package/modules/ambience/Ambience.js +21 -5
  211. package/modules/calendar/index.js +9 -5
  212. package/modules/calendar/schedule.js +23 -8
  213. package/modules/camera/FirstPersonCamera.js +3 -1
  214. package/modules/camera/FollowCamera.js +10 -5
  215. package/modules/camera/RtsCamera.js +4 -3
  216. package/modules/camera/common.js +70 -8
  217. package/modules/camera/contract.js +1 -1
  218. package/modules/characters/Character.js +16 -10
  219. package/modules/characters/NPC.js +31 -19
  220. package/modules/characters/assetModel.js +14 -9
  221. package/modules/characters/astar.js +6 -1
  222. package/modules/characters/contract.js +2 -2
  223. package/modules/characters/index.js +34 -22
  224. package/modules/characters/movers/manual.js +1 -1
  225. package/modules/characters/movers/rapier.js +17 -2
  226. package/modules/characters/movers/simple.js +1 -1
  227. package/modules/characters/movers/support.js +16 -7
  228. package/modules/characters/npcAvoid.js +2 -2
  229. package/modules/characters/npcSim.js +3 -2
  230. package/modules/characters/pathAsync.js +24 -8
  231. package/modules/characters/pathJob.js +1 -1
  232. package/modules/characters/player.js +10 -9
  233. package/modules/characters/playerStrings.js +5 -5
  234. package/modules/characters/proceduralRig.js +5 -5
  235. package/modules/characters/useModel.js +6 -0
  236. package/modules/characters/walkTo.js +1 -1
  237. package/modules/collision/Collision.js +29 -18
  238. package/modules/collision/grid.js +22 -4
  239. package/modules/content/index.js +3 -1
  240. package/modules/content/loader.js +1 -1
  241. package/modules/content/models.js +82 -33
  242. package/modules/content/props.js +2 -1
  243. package/modules/content/rules.js +11 -5
  244. package/modules/content/templates.js +3 -3
  245. package/modules/content/words.js +2 -2
  246. package/modules/debug/DebugPanel.js +9 -9
  247. package/modules/flow/index.js +9 -6
  248. package/modules/gameplay/Dialogue.js +34 -20
  249. package/modules/gameplay/Interactions.js +19 -15
  250. package/modules/gameplay/Inventory.js +9 -4
  251. package/modules/gameplay/Quests.js +12 -10
  252. package/modules/gameplay/pickups.js +23 -11
  253. package/modules/grid/index.js +1 -1
  254. package/modules/grid/preview.js +2 -2
  255. package/modules/grid/tiles.js +1 -1
  256. package/modules/hlod/index.js +4 -1
  257. package/modules/hud/index.js +47 -10
  258. package/modules/hud/parts.js +28 -9
  259. package/modules/level/geometry.js +8 -3
  260. package/modules/level/index.js +10 -5
  261. package/modules/level/load.js +4 -2
  262. package/modules/lights/sources.js +1 -1
  263. package/modules/music/Music.js +22 -4
  264. package/modules/nav/index.js +20 -10
  265. package/modules/particles/Particles.js +31 -14
  266. package/modules/particles/effect.js +20 -5
  267. package/modules/particles/lit.js +72 -0
  268. package/modules/photo/Photo.js +72 -28
  269. package/modules/photo/pathTrace.js +106 -0
  270. package/modules/rigid/RigidBodies.js +23 -14
  271. package/modules/rigid/Vehicles.js +3 -13
  272. package/modules/rigid/sync.js +2 -1
  273. package/modules/settings/Settings.js +52 -20
  274. package/modules/settings/apply.js +23 -9
  275. package/modules/settings/sections.js +39 -6
  276. package/modules/settings/strings.js +2 -0
  277. package/modules/settings/view.js +19 -3
  278. package/modules/sky/dome.js +15 -3
  279. package/modules/sky/environment.js +28 -12
  280. package/modules/sky/fog.js +1 -1
  281. package/modules/sky/frame.js +6 -1
  282. package/modules/sky/shader.js +4 -3
  283. package/modules/sky/skyModule.js +8 -4
  284. package/modules/swarm/Swarm.js +1 -1
  285. package/modules/terrain/ChunkManager.js +61 -15
  286. package/modules/terrain/chunkJob.js +2 -2
  287. package/modules/terrain/index.js +20 -5
  288. package/modules/terrain/terrainEdit.js +8 -4
  289. package/modules/terrain/terrainTexture.js +4 -2
  290. package/modules/timeline/Timeline.js +4 -3
  291. package/modules/timeline/Tween.js +3 -0
  292. package/modules/timeline/letterbox.js +1 -0
  293. package/modules/triggers/index.js +36 -17
  294. package/modules/vegetation/Vegetation.js +81 -19
  295. package/modules/vegetation/densityMap.js +13 -8
  296. package/modules/vegetation/draw.js +147 -24
  297. package/modules/vegetation/groundChunks.js +20 -5
  298. package/modules/vegetation/index.js +3 -3
  299. package/modules/vegetation/modelGeometry.js +9 -4
  300. package/modules/water/Water.js +11 -8
  301. package/modules/weather/Weather.js +7 -2
  302. package/modules/weather/shaders.js +25 -5
  303. package/modules/weather/weatherDraw.js +20 -6
  304. package/modules/world/World.js +2 -1
  305. package/modules/world/index.js +2 -2
  306. package/modules/world/persist.js +6 -2
  307. package/modules/world/views.js +15 -2
  308. package/package.json +5 -1
  309. package/presets.js +5 -5
  310. package/render/PostFX.js +102 -42
  311. package/render/backend.js +142 -16
  312. package/render/bindingLimits.js +59 -0
  313. package/render/cascades.js +3 -1
  314. package/render/cascades.tsl.js +2 -0
  315. package/render/daylight.js +7 -1
  316. package/render/detail.js +7 -4
  317. package/render/effects.js +27 -8
  318. package/render/fogLook.js +24 -0
  319. package/render/fuse.js +5 -2
  320. package/render/fx/compareLevel.tsl.js +23 -0
  321. package/render/fx/detail.tsl.js +9 -7
  322. package/render/fx/index.js +9 -2
  323. package/render/fx/library.tsl.js +1 -0
  324. package/render/fx/lightShaft.tsl.js +114 -0
  325. package/render/fx/noise.tsl.js +25 -8
  326. package/render/fx/objectOrigin.tsl.js +39 -10
  327. package/render/fx/particles.tsl.js +23 -6
  328. package/render/fx/patchNodes.tsl.js +17 -12
  329. package/render/fx/pcss.tsl.js +51 -0
  330. package/render/fx/postWebGPU.tsl.js +104 -29
  331. package/render/fx/sky.tsl.js +3 -9
  332. package/render/fxNumbers.js +10 -4
  333. package/render/impostor.tsl.js +107 -0
  334. package/render/lighting.js +33 -1
  335. package/render/lightmap.js +42 -28
  336. package/render/lights.js +19 -3
  337. package/render/materials.js +6 -4
  338. package/render/mergeCommon.js +4 -1
  339. package/render/occlusion.js +14 -4
  340. package/render/patches.js +79 -41
  341. package/render/postRuns.js +32 -0
  342. package/render/postWebGL.js +97 -10
  343. package/render/probes.js +10 -14
  344. package/render/shaderErrors.js +44 -7
  345. package/render/shadowCache.tsl.js +33 -5
  346. package/render/shadows.js +42 -16
  347. package/render/slots.js +8 -5
  348. package/render/vertexInputs.js +52 -0
  349. package/types/core.d.ts +115 -47
  350. package/types/gameplay.d.ts +56 -23
  351. package/types/generated/core/audio/Audio.d.ts +27 -1
  352. package/types/generated/core/base/Random.d.ts +1 -1
  353. package/types/generated/core/input/Input.d.ts +6 -8
  354. package/types/generated/core/input/inputSeat.d.ts +1 -1
  355. package/types/generated/core/inspect/Budget.d.ts +26 -0
  356. package/types/generated/core/inspect/DebugOverrides.d.ts +0 -2
  357. package/types/generated/core/saves/Saves.d.ts +10 -7
  358. package/types/generated/core/saves/session.d.ts +8 -2
  359. package/types/generated/core/scene/Rays.d.ts +1 -3
  360. package/types/generated/core/scene/Views.d.ts +17 -3
  361. package/types/generated/modules/particles/Particles.d.ts +1 -1
  362. package/types/generated/modules/world/World.d.ts +2 -1
  363. package/types/generated/render/PostFX.d.ts +35 -9
  364. package/types/physics.d.ts +796 -764
  365. package/types/pixel.d.ts +1 -1
  366. package/types/tsl.d.ts +62 -1
  367. package/types/world.d.ts +12 -3
  368. package/ui/Focus.js +7 -5
  369. package/ui/Parts.js +1 -1
  370. package/ui/touchPart.js +6 -3
@@ -13,7 +13,7 @@ Settings menu (settings() module)
13
13
  - `settings.get(key: string) → any` — Read a setting, e.g. get('vol.music')
14
14
  - `settings.set(key: string, value: any, opts?: { save?: boolean })` — Change a setting (takes effect immediately + saved)
15
15
  - `settings.preset(name: 'low' | 'medium' | 'high' | (string & {}))` — (experimental) Graphics preset: 'low' / 'medium' / 'high'
16
- - `settings.define(key: string, def: T, apply?: ((value, e) => void) | { apply?, limits? })` — Game-defined setting: default value + apply function (saved automatically), or { apply, limits }. limits names the shared value(s) the row restricts on the settings layer, like the built-in shadows row: off holds it off (the scene, weather or a cutscene cannot turn it back on), on allows what the scene chose; a number row from 0 to 1 is a factor on a number value. Define it after the effect exists
16
+ - `settings.define(key: string, def: T, apply?: ((value, e) => void) | { apply?, limits?, menu?, label?, options?, min?, … } | …)` — Game-defined setting: default value + apply function (saved automatically), or { apply, limits }. limits names the shared value(s) the row restricts on the settings layer, like the built-in shadows row: off holds it off (the scene, weather or a cutscene cannot turn it back on), on allows what the scene chose; a number row from 0 to 1 is a factor on a number value. Define it after the effect exists. The menu draws the row itself in the tab menu names (default 'options', shown while it has a row): a switch for true/false, a slider for a number (min/max; a limits row has 0..1), buttons for options. label: an i18n key or text, else the key. menu: false when your own tab draws it; a row the menu cannot draw, a missing tab or a row drawn twice warns once
17
17
  - `settings.addSection(id: string, section?: SettingsSection)` — Add a tab of your own, or a built-in / optional one by name: addSection('camera')
18
18
  - `settings.reset(key?: string)` — Put one setting (or all, with no key) back to its default: the engine's start value, or the default the game gave define(). Keys: resetBindings
19
19
  - `settings.resetBindings()` — (experimental) Restore all keys to defaults
@@ -25,7 +25,7 @@ Settings menu (settings() module)
25
25
  - `values: Record<string, any>` All current setting values, read only (set() changes one). pixelRatio is the renderer's real ratio
26
26
  - `presets: Record<string, QualityPreset>` Graphics presets
27
27
  - `sections: Map<string, any>` (experimental) Tabs
28
- - `isOpen: boolean` (experimental) Whether the menu is open
28
+ - `isOpen: boolean` Whether the menu is open
29
29
 
30
30
  ## Data structures
31
31
  - **SettingsSection** One settings tab
package/docs/api/tools.md CHANGED
@@ -65,7 +65,7 @@
65
65
  - `season(color: Node, kind: Node | 0 | 1) → Node` — (experimental) GLSL vec3 threedogSeason(vec3 color, int kind): kind 0 foliage, 1 ground; tints by uFoliageTint / uGroundTint (mix mode when uFoliageMix / uGroundMix > 0). A vec4 color is read as its rgb.
66
66
  - `objectOrigin() → Node` — (experimental) World position of the drawn object's origin (an InstancedMesh: of each instance), vec3. Works for any Mesh / InstancedMesh sharing the material; BatchedMesh throws [tsl-misuse].
67
67
  - `instanceOffset(offset: Node) → Node` — (experimental) An object-space offset carried through the drawn instance's rotation and scale (a plain Mesh: the offset as it is). A positionNode runs after the instance transform, so an offset meant for before it, like wind()'s, goes through this. BatchedMesh throws [tsl-misuse].
68
- - `hash(p: Node) → Node` — (experimental) GLSL float threedogHash(vec2 p): a repeatable random number 0-1 from a 2D position.
68
+ - `hash(p: Node) → Node` — (experimental) GLSL float threedogHash(vec2 p): a repeatable random number 0-1 from a 2D position (an integer hash of its bits: the same on WebGL and WebGPU).
69
69
  - `noise(p: Node) → Node` — (experimental) GLSL float threedogNoise(vec2 p): smooth value noise 0-1, the one behind the engine's clouds and cloud shadows. No uniforms.
70
70
  - `uniforms(engine: { uniforms: object }) → Record<string, Node>` — (experimental) engine.uniforms as TSL uniform nodes (uTime, uWind, uWeatherCloud, uFoliageTint, uSunDir, uDaylight ...), cached per engine. They read the same { value } objects, so engine.uniforms.uWind.value = 2 changes GLSL and TSL materials alike.
71
71
  - `detailNoise(p: Node, kind: Node | 0 | 1 | 2 | 3, octaves: Node | number) → Node` — (experimental) GLSL vec4 threedogDetailNoise(vec2 p, int kind, float octaves): kind 0 grain, 1 paper, 2 stroke, 3 dabs; returns (gray rgb, height 0-1). No uniforms: p is any 2D pattern position you choose (world xz times a scale, a uv...). octaves: up to 4 (dabs: 3).
@@ -74,7 +74,9 @@
74
74
  - `shadowTint(ambient: Node, tint: Node, strength: Node | number, soft: Node | number, nl: Node, shadow: Node | number) → Node` — (experimental) GLSL vec3 threedogShadowTint(vec3 ambient, vec3 tint, float strength, float soft, float nl, float shadow): the ambient with the shaded side's hue moved toward tint (brightness kept). shadow: 1 lit / 0 shadowed (the sun's lightNode.shadowNode); soft: terminator width in n.l.
75
75
  - `rim(normal: Node, viewDir: Node, color: Node, strength: Node | number, power: Node | number, shadowSide: Node | number, nl: Node) → Node` — (experimental) GLSL vec3 threedogRim(vec3 normal, vec3 viewDir, vec3 color, float strength, float power, float shadowSide, float nl): edge light to add (viewDir from the surface to the eye, e.g. normalView and positionViewDirection); shadowSide 1 = only on the side facing away from the sun.
76
76
  - `celLighting() → import('three/webgpu').LightingMo…` — (experimental) The lighting model for cel bands with colored ramps: assign it to a MeshToonNodeMaterial, whose gradientMap holds the ramp (rampTexture). A shadowed pixel reads the dark end of the ramp, so a cast shadow takes the same flat band and color as the side turned away. Without a gradientMap: two levels, as three's toon.
77
+ - `pcss(o?: { lightSize?, samples?, maxDistance? }) → any` — (experimental) A shadow filter for a DirectionalLight whose edge softens with the distance from caster to receiver (PCSS). The game assigns it before the first frame; it reaches the engine's cascades too. lightSize: edge width per world unit of that distance; samples: filter taps; maxDistance: where the edge stops growing. A spot or point light throws by name.
77
78
  - `waterWave(p: Node, t: Node | number) → Node` — (experimental) GLSL float threedogWaterWave(vec3 p, float t): the built-in wave sum (height before waveHeight). p = world position * waveScale, t = time * waveSpeed.
78
79
  - `waterSurface(spec?: { depth?, foam?, waveMax? }) → (base, wave, facing, worldPos, time) => Node` — (experimental) The built-in water surface as TSL: returns a function with the GLSL signature threedogWaterSurface(base, wave, facing, worldPos, time) -> vec4 (rgb, opacity). Only the parts given exist (depth: shallow / deep by viewing angle or wave height; foam on crests); values are numbers / colors or nodes. wave is waterWave's height, facing = 1 looking straight down.
79
80
  - `waterFresnel(color: Node, normal: Node, viewDir: Node, strength: Node | number, towards: Node) → Node` — (experimental) The water's fresnel blend: color mixed toward `towards` (the engine uses the fog color) by pow(1 - /viewDir . normal/, 3) * strength, view space
81
+ - `lightShaft(engine: { renderer, uniforms, tier }, opts?: LightShaftOptions) → LightShaft` — (experimental) A cheap visible light beam (ceiling hole, window, stage light): an additive open cone, top at the mesh origin pointing down -Y, sides softened by view angle, faded where it meets geometry and near the camera, dimmed (not tinted) by scene fog. Occluders do not cut it (for that: sunShafts / lightVolumes). WebGPURenderer only (both backends); WebGLRenderer throws by name. Add / move / remove it like any mesh; engine.remove frees it.
80
82
  - `serve(handler: (msg: any) => any)` — Start answering lane messages in a worker. handler is the same function the lane's local() returns on the main thread.
package/docs/api/vars.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # engine.vars (Vars) — engine.vars: story flags and counters (autosaved)
2
2
 
3
3
  - `vars.flag(key: string) → any` — Read a flag
4
- - `vars.setFlag(key: string, value?: any)` — (experimental) Set a flag (default true)
4
+ - `vars.setFlag(key: string, value?: any)` — Set a flag (default true)
5
5
  - `vars.counter(key: string) → number` — Read a counter (0 if none)
6
6
  - `vars.bump(key: string, n?: number) → number` — Counter +n (default 1), returns the new value
7
7
  - Properties:
@@ -16,10 +16,11 @@ Vegetation (vegetation() module; grows on terrain or on any ground provider)
16
16
  - `vegetation.rebuild()` — Place every chunk again: after changing the ground behind the same provider (a ground function reading game state). A new setGround or level is followed automatically
17
17
  - `vegetation.setShadowRing(name: string, ring: number)` — Change at runtime how far a vegetation kind casts shadows: within `ring` chunk rings of the player (0 = only the chunk you stand in, 1 = the default, larger = further and dearer). Takes effect at once; the define() option shadowRing is only the starting value. An unknown name warns with the known ones. Example: `engine.vegetation.setShadowRing('tree', 0); // graphics setting "shadows: low": trees shadow only the nearest chunk`
18
18
  - `vegetation.define(name: string, opts: VegetationOptions) → Species | Promise<Species>` — Define a kind of vegetation (a model name in model / lodGeometry: resolves first, so the result is a Promise of the species)
19
- - `vegetation.isRemoved(species: string, cx: number, cz: number, id: number) → boolean` — (experimental)
19
+ - `vegetation.isRemoved(species: string, cx: number, cz: number, id: number) → boolean` — Was this instance removed (removeInstance) and not restored
20
20
  - `vegetation.removeInstance(species: string, cx: number, cz: number, id: number, opts?: { regrowSeconds?: number }) → string` — Remove one (chop a tree). regrowSeconds: grows back after this many calendar seconds, 0 = permanent. The record is saved with the save (save key 'vegetation'). Returns the entry name
21
- - `vegetation.restoreInstance(species: string, cx: number, cz: number, id: number)` — (experimental) Restore one
21
+ - `vegetation.restoreInstance(species: string, cx: number, cz: number, id: number)` — Restore one removed instance
22
22
  - `vegetation.instanceAt(position: PositionLike, opts?: { radius?, species? }) → VegetationHit | null` — The one nearest to position within radius meters (default 2) (species restricts to one kind), null if none
23
+ - `vegetation.plantOf(hit: { object?, instanceId? } | null | undefined) → VegetationHit | null` — The plant a ray hit, read from the hit itself (no spatial guess): the same VegetationHit instanceAt returns (goes to removeInstance), null if not vegetation or a far impostor card
23
24
  - Also: `vegetation.get(name: string) → Species | undefined`, `vegetation.list() → Species[]`
24
25
  - Properties:
25
26
  - `material: Material | null` The shared default material: species with no material or model of their own draw it, as given, planted ones too; null gives the neutral default back. Until set, reading gives the neutral source of each species' own copy (only .color written there reaches them all). Throws when a game module drew the plants instead (replaces: 'vegetation-draw').
@@ -38,6 +39,7 @@ Vegetation (vegetation() module; grows on terrain or on any ground provider)
38
39
  - `maxRing?: number` No longer drawn beyond this many rings
39
40
  - `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).
40
41
  - `lodRing?: number` Switch to the low-detail model beyond this many rings, default 1
42
+ - `impostor?: boolean | { views?: number; size?: number }` Beyond lodRing, draw camera-facing cards baked from this species' own model and materials: one draw for all far chunks, lit through baked normals, no shadow there. views around the plant (default 8), size in pixels per view (default 128). Not with lodGeometry. WebGPU only (WebGL draws the mesh and warns)
41
43
  - `castShadow?: boolean` Cast shadows
42
44
  - `shadowRing?: number` Cast shadows within this many rings
43
45
  - `receiveShadow?: boolean` Receive shadows, default true
package/docs/api/world.md CHANGED
@@ -13,7 +13,7 @@ World data (world() module): things that must be saved, survive level changes an
13
13
  - `world.remove(id: string)` — Remove a record (its model is torn down too) and emit the world:remove event. Does nothing if the id does not exist. Removing an initial record is saved, so it stays gone after loading
14
14
  - `world.query(opts?: { kind?, near?, radius?, where?, zone? }) → WorldRecord[]` — Query records; returns an array. With near only nearby cells are scanned and results are sorted nearest first (radius defaults to 30 m); where filters further. For neighbor queries every step use forEachNear. Example: `engine.world.query({ kind: 'zombie', near: engine.player, radius: 30, where: z => !z.dead })`
15
15
  - `world.forEachNear(center: any, radius: number, fn: (rec, d2) => void)` — Call fn(rec, d2) for each record within radius meters (horizontal distance) of center; d2 is the squared distance. Unsorted, no allocation: use it for per-step neighbor queries (hundreds of zombies avoiding each other). Don't add / remove / move in the callback (moving into a cell not yet visited visits it again): record the change and apply it after the loop. Example: `engine.world.forEachNear(rec.position, 5, (o, d2) => { if (o !== rec && o.kind === 'zombie') n++; })`
16
- - `world.present(kind: string, opts: { build, update?, dispose?, show?, radius?, positionFrom? }) → { remove(): void }` — Register how a kind of thing looks: models are built automatically within radius meters of any full-detail stream source (engine.stream: player, camera focus, teleport destination) and torn down when far from all of them (radius × 1.25); tearing down never touches the record. Callbacks: build(rec) → three.js object (may be async). world adds it to the scene and places it at rec.position; if it throws / fails / returns a non-object: reported once, does not block ready, retried when you leave and come back. update(rec, obj, dt): called every frame for records that have a model (change the picture from the data, e.g. an opened chest swaps texture). dispose(rec, obj): called on teardown (record first, model second); if omitted, engine.remove(obj). show(rec) → false: this record has no model right now (picked up, waiting to respawn); re-evaluated when world.set changes records of this kind. Example: `engine.world.present('chest', { build: rec => new THREE.Mesh(boxGeo, new THREE.MeshStandardMaterial()), dispose: (rec, obj) => engine.remove(obj), show: rec => !rec.looted })`
16
+ - `world.present(kind: string, opts: { build, update?, dispose?, show?, radius?, positionFrom? }) → { remove(): void }` — Register how a kind of thing looks: models are built automatically within radius meters of any full-detail stream source (engine.stream: player, camera focus, teleport destination) and torn down when far from all of them (radius × 1.25); tearing down never touches the record. Callbacks: build(rec) → three.js object (may be async). world adds it to the scene and places it at rec.position; if it throws / fails / returns a non-object: reported once, does not block ready, retried when you leave and come back. Only the position is world's: rec.rot / rec.scale are the build's to apply (rotate the root or a child, in its own units) and update's to follow. update(rec, obj, dt): called every frame for records that have a model (change the picture from the data, e.g. an opened chest swaps texture). dispose(rec, obj): called on teardown (record first, model second); if omitted, engine.remove(obj). Example: `engine.world.present('chest', { build: rec => new THREE.Mesh(boxGeo, new THREE.MeshStandardMaterial()), dispose: (rec, obj) => engine.remove(obj), show: rec => !rec.looted })`
17
17
  - `world.view(id: string) → any` — The current model of this record (only exists nearby; null if not built yet or far away)
18
18
  - `world.refresh()` — Build / tear down models for the stream sources right now (normally automatic every frame, with a per-frame limit). Use it right after add when you need the model: sync builds are available via view(id) after the call, for async ones also await world.whenReady. Example: `engine.world.add({ id: 'gate', kind: 'gate', position: p }); engine.world.refresh(); engine.world.view('gate')`
19
19
  - `world.simulate(kind: string, opts: { near?, far?, farEvery?, radius?, fullRadius?, nearEvery?, … }) → { remove(): void }` — Register how a kind of thing changes (gameplay logic goes here, runs in the fixed step); near / far is split by distance from world.anchor (default: the player): near(rec, dt, obj): within radius, once per fixed step (obj is the model, may be null if not built yet; gameplay must not depend on it); far(rec, dt): farther away, once every farEvery seconds; dt is the seconds accumulated since the last simulation (can catch up a long time at once); on the far → near step, far runs first to pay back the owed time. With only far (crops), near also advances via far; with only near, far records are not simulated and owed time is not made up. Both dt are accumulated real (fixed-step) seconds (not multiplied by clock.rate). For things measured in game clock (grows over days) store engine.clock.now and compare. Example: `engine.world.simulate('zombie', { near: (rec, dt) => chase(rec, dt), far: (rec, dt) => wander(rec, dt), farEvery: 2 })`
@@ -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