threedog 0.7.0 → 0.8.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 (544) hide show
  1. package/CHANGELOG.md +196 -1
  2. package/README.md +6 -9
  3. package/core/{Animator.js → assets/Animator.js} +28 -18
  4. package/core/{Assets.js → assets/Assets.js} +98 -54
  5. package/core/{Baked.js → assets/Baked.js} +4 -4
  6. package/core/assets/assetEntry.js +237 -0
  7. package/core/{assetHot.js → assets/assetHot.js} +7 -6
  8. package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
  9. package/core/assets/assetLod.js +113 -0
  10. package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
  11. package/core/{assetReport.js → assets/assetReport.js} +6 -12
  12. package/core/{namedModel.js → assets/namedModel.js} +17 -13
  13. package/core/{Audio.js → audio/Audio.js} +26 -23
  14. package/core/{audioRules.js → audio/audioRules.js} +8 -5
  15. package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
  16. package/core/{Events.js → base/Events.js} +3 -3
  17. package/core/{I18n.js → base/I18n.js} +10 -10
  18. package/core/{Random.js → base/Random.js} +5 -4
  19. package/core/{easing.js → base/easing.js} +1 -1
  20. package/core/{errorCodes.js → base/errorCodes.js} +98 -110
  21. package/core/{errorHints.js → base/errorHints.js} +5 -9
  22. package/core/{errors.js → base/errors.js} +6 -6
  23. package/core/{events.generated.js → base/events.generated.js} +1 -0
  24. package/core/{math.js → base/math.js} +15 -4
  25. package/core/{params.js → base/params.js} +3 -4
  26. package/core/base/util.js +32 -0
  27. package/core/{validate.js → base/validate.js} +28 -7
  28. package/core/{Engine.js → engine/Engine.js} +80 -77
  29. package/core/{Loading.js → engine/Loading.js} +4 -2
  30. package/core/{copies.js → engine/copies.js} +4 -4
  31. package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
  32. package/core/{lifecycle.js → engine/lifecycle.js} +14 -12
  33. package/core/{loop.js → engine/loop.js} +68 -47
  34. package/core/{moduleSlots.js → engine/moduleSlots.js} +6 -6
  35. package/core/{moduleTypes.js → engine/moduleTypes.js} +13 -14
  36. package/core/{modules.js → engine/modules.js} +14 -11
  37. package/core/{page.js → engine/page.js} +36 -23
  38. package/core/{plugins.js → engine/plugins.js} +6 -9
  39. package/core/{services.js → engine/services.js} +47 -40
  40. package/core/{startup.js → engine/startup.js} +26 -24
  41. package/core/{Input.js → input/Input.js} +30 -22
  42. package/core/{inputContext.js → input/inputContext.js} +14 -5
  43. package/core/{inputPad.js → input/inputPad.js} +1 -1
  44. package/core/{inputPointer.js → input/inputPointer.js} +8 -2
  45. package/core/{inputTouch.js → input/inputTouch.js} +1 -1
  46. package/core/{Budget.js → inspect/Budget.js} +21 -20
  47. package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +30 -16
  48. package/core/{Describe.js → inspect/Describe.js} +26 -22
  49. package/core/{Inspect.js → inspect/Inspect.js} +9 -7
  50. package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
  51. package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
  52. package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
  53. package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
  54. package/core/{UrlState.js → inspect/UrlState.js} +52 -20
  55. package/core/{catalog.js → inspect/catalog.js} +3 -3
  56. package/core/{checks.js → inspect/checks.js} +7 -5
  57. package/core/{debugView.js → inspect/debugView.js} +4 -4
  58. package/core/{describeRender.js → inspect/describeRender.js} +21 -20
  59. package/core/{describeText.js → inspect/describeText.js} +11 -6
  60. package/core/inspect/geometryWatch.js +38 -0
  61. package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
  62. package/core/{pictureWriters.js → inspect/pictureWriters.js} +15 -16
  63. package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
  64. package/core/{Ops.js → ops/Ops.js} +16 -11
  65. package/core/{control.js → ops/control.js} +13 -12
  66. package/core/ops/holds.js +139 -0
  67. package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
  68. package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
  69. package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
  70. package/core/{opsRun.js → ops/opsRun.js} +7 -4
  71. package/core/{owned.js → ops/owned.js} +14 -17
  72. package/core/{sharedPoint.js → ops/sharedPoint.js} +8 -8
  73. package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
  74. package/core/{stacks.js → ops/stacks.js} +12 -14
  75. package/core/{wrap.js → ops/wrap.js} +8 -6
  76. package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
  77. package/core/{Saves.js → saves/Saves.js} +58 -36
  78. package/core/{saveApply.js → saves/saveApply.js} +13 -9
  79. package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
  80. package/core/{saveValues.js → saves/saveValues.js} +20 -3
  81. package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
  82. package/core/{session.js → saves/session.js} +31 -17
  83. package/core/{Rays.js → scene/Rays.js} +23 -25
  84. package/core/{Views.js → scene/Views.js} +14 -6
  85. package/core/{adaptive.js → scene/adaptive.js} +15 -8
  86. package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
  87. package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
  88. package/core/{gameLights.js → scene/gameLights.js} +17 -7
  89. package/core/{grayMap.js → scene/grayMap.js} +8 -2
  90. package/core/{grid.js → scene/grid.js} +4 -4
  91. package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
  92. package/core/{ground.js → scene/ground.js} +9 -9
  93. package/core/{movement.js → scene/movement.js} +3 -3
  94. package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
  95. package/core/{sceneDelta.js → scene/sceneDelta.js} +2 -2
  96. package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -13
  97. package/core/scene/stepPoses.js +55 -0
  98. package/core/{targeting.js → scene/targeting.js} +4 -5
  99. package/core/{thingExplain.js → scene/thingExplain.js} +6 -5
  100. package/core/{thingOps.js → scene/thingOps.js} +4 -3
  101. package/core/{things.js → scene/things.js} +18 -5
  102. package/core/{threePatches.js → scene/threePatches.js} +1 -1
  103. package/core/{view.js → scene/view.js} +17 -16
  104. package/core/{Batching.js → stream/Batching.js} +85 -27
  105. package/core/{Stream.js → stream/Stream.js} +60 -30
  106. package/core/{batchGroups.js → stream/batchGroups.js} +10 -9
  107. package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
  108. package/core/{scatter.js → stream/scatter.js} +2 -2
  109. package/core/{streamSources.js → stream/streamSources.js} +12 -7
  110. package/core/{Commits.js → threads/Commits.js} +6 -5
  111. package/core/{Jobs.js → threads/Jobs.js} +12 -10
  112. package/core/{Threads.js → threads/Threads.js} +16 -16
  113. package/core/{threadPure.js → threads/threadPure.js} +7 -5
  114. package/core/{threadServe.js → threads/threadServe.js} +3 -3
  115. package/core/{Clock.js → time/Clock.js} +17 -10
  116. package/core/{dayTime.js → time/dayTime.js} +5 -1
  117. package/core/{skip.js → time/skip.js} +18 -17
  118. package/core/{time.js → time/time.js} +18 -12
  119. package/core/{uiClock.js → time/uiClock.js} +4 -4
  120. package/docs/AI.md +22 -19
  121. package/docs/API.md +24 -23
  122. package/docs/CODEMAP.md +76 -183
  123. package/docs/COMMANDS.md +66 -58
  124. package/docs/CONVENTIONS.md +54 -14
  125. package/docs/MIGRATING-0.8.md +169 -0
  126. package/docs/THREE.md +78 -29
  127. package/docs/api/assets.md +12 -13
  128. package/docs/api/audio.md +6 -5
  129. package/docs/api/budget.md +4 -4
  130. package/docs/api/calendar.md +10 -11
  131. package/docs/api/cameraRig.md +29 -29
  132. package/docs/api/characters.md +23 -18
  133. package/docs/api/clock.md +1 -1
  134. package/docs/api/collision.md +12 -9
  135. package/docs/api/content.md +6 -6
  136. package/docs/api/dialogue.md +3 -3
  137. package/docs/api/engine.md +45 -43
  138. package/docs/api/events.md +3 -2
  139. package/docs/api/flow.md +1 -1
  140. package/docs/api/grids.md +1 -1
  141. package/docs/api/ground.md +4 -5
  142. package/docs/api/hud.md +2 -2
  143. package/docs/api/i18n.md +6 -6
  144. package/docs/api/input.md +7 -7
  145. package/docs/api/interactions.md +4 -4
  146. package/docs/api/inventory.md +9 -9
  147. package/docs/api/jobs.md +5 -5
  148. package/docs/api/level.md +7 -7
  149. package/docs/api/lightPool.md +1 -6
  150. package/docs/api/music.md +3 -3
  151. package/docs/api/nav.md +10 -10
  152. package/docs/api/openWorld.md +1 -1
  153. package/docs/api/particles.md +2 -2
  154. package/docs/api/photo.md +4 -2
  155. package/docs/api/pickups.md +2 -2
  156. package/docs/api/post.md +20 -3
  157. package/docs/api/quests.md +3 -3
  158. package/docs/api/rays.md +5 -7
  159. package/docs/api/rigid.md +27 -18
  160. package/docs/api/saves.md +8 -7
  161. package/docs/api/settings.md +9 -8
  162. package/docs/api/sky.md +8 -7
  163. package/docs/api/stream.md +7 -7
  164. package/docs/api/swarm.md +34 -0
  165. package/docs/api/terrain.md +7 -8
  166. package/docs/api/terrainDraw.md +1 -1
  167. package/docs/api/timeline.md +2 -2
  168. package/docs/api/tools.md +25 -22
  169. package/docs/api/vars.md +1 -1
  170. package/docs/api/vegetation.md +4 -3
  171. package/docs/api/vegetationDraw.md +1 -1
  172. package/docs/api/water.md +1 -1
  173. package/docs/api/weather.md +9 -9
  174. package/docs/api/weatherDraw.md +3 -3
  175. package/docs/api/world.md +5 -5
  176. package/docs/recipes/01-new-game.md +25 -40
  177. package/docs/recipes/02-npc.md +19 -20
  178. package/docs/recipes/03-items-pickups.md +27 -43
  179. package/docs/recipes/04-quests.md +3 -4
  180. package/docs/recipes/05-props-bake.md +29 -39
  181. package/docs/recipes/06-clock-events.md +27 -18
  182. package/docs/recipes/07-flow-scenes-pause.md +12 -17
  183. package/docs/recipes/08-weather-sky.md +88 -34
  184. package/docs/recipes/09-materials-lights-models.md +22 -36
  185. package/docs/recipes/10-blender-level.md +6 -7
  186. package/docs/recipes/11-vehicles.md +30 -22
  187. package/docs/recipes/12-navmesh.md +9 -8
  188. package/docs/recipes/13-animation.md +39 -17
  189. package/docs/recipes/14-custom-module.md +14 -13
  190. package/docs/recipes/15-perf.md +49 -26
  191. package/docs/recipes/16-dev-bridge.md +32 -52
  192. package/docs/recipes/18-world.md +36 -23
  193. package/docs/recipes/19-shooting-picking.md +4 -2
  194. package/docs/recipes/20-content-actions-save.md +30 -35
  195. package/docs/recipes/21-camera.md +33 -5
  196. package/docs/recipes/22-shop-gold.md +0 -4
  197. package/docs/recipes/23-ops.md +10 -10
  198. package/docs/recipes/26-ui-parts.md +22 -12
  199. package/docs/recipes/27-net.md +0 -2
  200. package/docs/recipes/28-terrain.md +117 -21
  201. package/docs/recipes/29-grid.md +2 -2
  202. package/docs/recipes/30-templates.md +55 -19
  203. package/docs/recipes/31-audio.md +5 -5
  204. package/docs/recipes/32-action-game.md +15 -6
  205. package/docs/recipes/33-stream-sources.md +2 -2
  206. package/docs/recipes/34-environment-lighting.md +67 -19
  207. package/docs/recipes/35-picture-from-reference.md +10 -17
  208. package/docs/recipes/36-ground-plants.md +105 -0
  209. package/docs/recipes/40-scene.md +7 -11
  210. package/docs/recipes/43-shader-patches-surfaces.md +20 -41
  211. package/docs/recipes/44-water-weather-hooks.md +48 -43
  212. package/docs/recipes/45-cascaded-shadows.md +39 -17
  213. package/docs/recipes/46-blender-art-route.md +7 -8
  214. package/docs/recipes/49-game-module-contract.md +5 -5
  215. package/docs/recipes/50-own-renderer.md +2 -2
  216. package/docs/recipes/52-around-the-picture.md +54 -98
  217. package/docs/recipes/53-ground-up-close.md +61 -24
  218. package/docs/recipes/55-mods-time-wrap.md +12 -16
  219. package/docs/recipes/56-webgpu-tsl.md +16 -14
  220. package/docs/recipes/57-control.md +9 -2
  221. package/docs/recipes/58-input.md +2 -2
  222. package/docs/recipes/59-depth-post-effects.md +1 -1
  223. package/docs/recipes/60-judge-the-picture.md +29 -24
  224. package/docs/recipes/62-picture-code.md +49 -17
  225. package/docs/recipes/63-third-person-start.md +17 -4
  226. package/docs/recipes/64-particles.md +1 -1
  227. package/docs/recipes/65-swarm.md +140 -0
  228. package/examples/action/.threedog/content-index.json +1 -1
  229. package/examples/action/GAMEMAP.md +2 -2
  230. package/examples/{sheepisland → perf-island}/.threedog/content-index.json +1 -1
  231. package/examples/{sheepisland → perf-island}/GAMEMAP.md +12 -11
  232. package/examples/{sheepisland → perf-island}/assets.js +1 -1
  233. package/examples/{sheepisland → perf-island}/main.js +8 -8
  234. package/examples/{sheepisland → perf-island}/models.js +1 -1
  235. package/examples/{sheepisland → perf-island}/params.js +1 -1
  236. package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
  237. package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
  238. package/examples/{sheepisland → perf-island}/views.js +1 -1
  239. package/examples/plain-picture/GAMEMAP.md +1 -0
  240. package/examples/rc2d/GAMEMAP.md +3 -2
  241. package/examples/rc2d/main.js +1 -3
  242. package/examples/styletest/.threedog/content-index.json +1 -1
  243. package/examples/styletest/GAMEMAP.md +3 -2
  244. package/examples/techniques/contact-shadows/contactShadows.js +1 -1
  245. package/examples/techniques/contact-shadows/main.js +1 -1
  246. package/examples/techniques/interior-light/main.js +1 -1
  247. package/examples/techniques/modular-building/README.md +7 -6
  248. package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
  249. package/examples/techniques/procedural-animation/README.md +1 -1
  250. package/examples/webgpu-tsl/GAMEMAP.md +1 -0
  251. package/examples/world/.threedog/content-index.json +1 -1
  252. package/examples/world/GAMEMAP.md +4 -3
  253. package/examples/world/picture/sky.js +1 -1
  254. package/index.d.ts +8 -7
  255. package/index.js +31 -31
  256. package/llms.txt +9 -13
  257. package/modules/ambience/Ambience.js +11 -8
  258. package/modules/calendar/Calendar.js +19 -19
  259. package/modules/calendar/index.js +13 -13
  260. package/modules/calendar/schedule.js +11 -6
  261. package/modules/calendar/seasons.js +7 -7
  262. package/modules/camera/FirstPersonCamera.js +2 -2
  263. package/modules/camera/FixedCamera.js +14 -15
  264. package/modules/camera/FollowCamera.js +4 -4
  265. package/modules/camera/RtsCamera.js +11 -11
  266. package/modules/camera/common.js +48 -24
  267. package/modules/camera/contract.js +1 -0
  268. package/modules/camera/projection.js +2 -2
  269. package/modules/characters/Character.js +33 -30
  270. package/modules/characters/NPC.js +27 -19
  271. package/modules/characters/assetModel.js +14 -10
  272. package/modules/characters/astar.js +7 -5
  273. package/modules/characters/behaviors.js +4 -5
  274. package/modules/characters/contract.js +2 -2
  275. package/modules/characters/index.js +168 -214
  276. package/modules/characters/moveHelpers.js +14 -3
  277. package/modules/characters/movers/common.js +16 -14
  278. package/modules/characters/movers/manual.js +1 -1
  279. package/modules/characters/movers/rapier.js +7 -6
  280. package/modules/characters/movers/simple.js +3 -3
  281. package/modules/characters/movers/support.js +8 -8
  282. package/modules/characters/npcAvoid.js +4 -4
  283. package/modules/characters/npcSim.js +23 -17
  284. package/modules/characters/npcView.js +6 -5
  285. package/modules/characters/pathAsync.js +12 -10
  286. package/modules/characters/pathWorker.js +1 -1
  287. package/modules/characters/player.js +108 -0
  288. package/modules/characters/playerStrings.js +2 -2
  289. package/modules/characters/proceduralRig.js +2 -2
  290. package/modules/characters/useModel.js +3 -3
  291. package/modules/characters/walkTo.js +11 -17
  292. package/modules/collision/Collision.js +26 -20
  293. package/modules/collision/contract.js +15 -0
  294. package/modules/content/explain.js +1 -2
  295. package/modules/content/fields.js +24 -3
  296. package/modules/content/ids.js +2 -2
  297. package/modules/content/index.js +61 -99
  298. package/modules/content/loader.js +14 -17
  299. package/modules/content/markers.js +25 -0
  300. package/modules/content/models.js +10 -7
  301. package/modules/content/packs.js +3 -3
  302. package/modules/content/parts.js +2 -2
  303. package/modules/content/places.js +35 -0
  304. package/modules/content/props.js +17 -14
  305. package/modules/content/rules.js +25 -21
  306. package/modules/content/stages.js +7 -7
  307. package/modules/content/templates.js +20 -20
  308. package/modules/content/words.js +34 -0
  309. package/modules/debug/DebugPanel.js +10 -43
  310. package/modules/flow/contract.js +1 -1
  311. package/modules/flow/index.js +11 -7
  312. package/modules/gameplay/Container.js +12 -11
  313. package/modules/gameplay/Containers.js +14 -5
  314. package/modules/gameplay/Dialogue.js +13 -11
  315. package/modules/gameplay/Interactions.js +37 -24
  316. package/modules/gameplay/Inventory.js +8 -9
  317. package/modules/gameplay/Quests.js +16 -9
  318. package/modules/gameplay/boxOps.js +1 -1
  319. package/modules/gameplay/dialogueBubbles.js +3 -4
  320. package/modules/gameplay/inventoryOps.js +0 -1
  321. package/modules/gameplay/pickups.js +22 -23
  322. package/modules/gameplay/questSave.js +3 -3
  323. package/modules/grid/Grid.js +1 -1
  324. package/modules/grid/Layer.js +4 -4
  325. package/modules/grid/index.js +7 -8
  326. package/modules/grid/preview.js +7 -7
  327. package/modules/grid/tiles.js +6 -6
  328. package/modules/hlod/index.js +37 -55
  329. package/modules/hud/index.js +17 -11
  330. package/modules/hud/parts.js +4 -4
  331. package/modules/level/contract.js +16 -0
  332. package/modules/level/heightfield.js +12 -10
  333. package/modules/level/index.js +47 -152
  334. package/modules/level/load.js +79 -0
  335. package/modules/level/meshes.js +65 -0
  336. package/modules/level/nodes.js +6 -7
  337. package/modules/lights/index.js +28 -181
  338. package/modules/lights/slots.js +93 -0
  339. package/modules/lights/sources.js +88 -0
  340. package/modules/music/Music.js +30 -26
  341. package/modules/music/rules.js +1 -1
  342. package/modules/nav/contract.js +14 -0
  343. package/modules/nav/index.js +11 -10
  344. package/modules/net/Client.js +7 -7
  345. package/modules/net/Host.js +7 -7
  346. package/modules/net/Net.js +1 -1
  347. package/modules/net/index.js +5 -4
  348. package/modules/net/sync.js +2 -2
  349. package/modules/net/transports.js +2 -2
  350. package/modules/particles/Particles.js +11 -8
  351. package/modules/particles/effect.js +7 -5
  352. package/modules/particles/shaders.js +2 -1
  353. package/modules/photo/Photo.js +15 -17
  354. package/modules/rigid/RigidBodies.js +66 -43
  355. package/modules/rigid/Vehicles.js +2 -3
  356. package/modules/rigid/ragdoll.js +287 -0
  357. package/modules/rigid/ragdollBones.js +159 -0
  358. package/modules/rigid/sync.js +6 -6
  359. package/modules/settings/Settings.js +108 -39
  360. package/modules/settings/apply.js +6 -6
  361. package/modules/settings/sections.js +16 -14
  362. package/modules/settings/view.js +3 -3
  363. package/modules/sky/Sky.js +29 -22
  364. package/modules/sky/clouds.js +7 -7
  365. package/modules/sky/dome.js +33 -20
  366. package/modules/sky/domeLayers.js +9 -9
  367. package/modules/sky/environment.js +6 -6
  368. package/modules/sky/frame.js +19 -10
  369. package/modules/sky/season.js +7 -1
  370. package/modules/sky/shader.js +24 -25
  371. package/modules/sky/skyModule.js +14 -27
  372. package/modules/sky/tint.js +1 -1
  373. package/modules/swarm/Swarm.js +346 -0
  374. package/modules/swarm/draw.js +68 -0
  375. package/modules/swarm/grid.js +63 -0
  376. package/modules/terrain/ChunkManager.js +70 -52
  377. package/modules/terrain/chunkQueries.js +7 -24
  378. package/modules/terrain/chunkWorker.js +1 -1
  379. package/modules/terrain/draw.js +14 -11
  380. package/modules/terrain/index.js +28 -34
  381. package/modules/terrain/terrainColorMap.js +6 -3
  382. package/modules/terrain/terrainDefaults.js +2 -1
  383. package/modules/terrain/terrainEdit.js +32 -27
  384. package/modules/terrain/terrainGen.js +17 -12
  385. package/modules/terrain/terrainIsland.js +2 -2
  386. package/modules/terrain/terrainMesh.js +7 -6
  387. package/modules/terrain/terrainShape.js +8 -10
  388. package/modules/terrain/terrainShapeMain.js +3 -3
  389. package/modules/timeline/Timeline.js +27 -19
  390. package/modules/timeline/Tween.js +6 -6
  391. package/modules/timeline/shots.js +5 -7
  392. package/modules/triggers/index.js +9 -9
  393. package/modules/vegetation/Vegetation.js +30 -23
  394. package/modules/vegetation/densityMap.js +4 -7
  395. package/modules/vegetation/draw.js +23 -18
  396. package/modules/vegetation/groundChunks.js +11 -31
  397. package/modules/vegetation/index.js +8 -6
  398. package/modules/vegetation/modelGeometry.js +3 -6
  399. package/modules/vegetation/nearFade.js +1 -1
  400. package/modules/water/Water.js +16 -16
  401. package/modules/water/surface.js +3 -3
  402. package/modules/weather/Weather.js +41 -30
  403. package/modules/weather/particles.js +8 -8
  404. package/modules/weather/weatherDraw.js +22 -18
  405. package/modules/world/World.js +8 -8
  406. package/modules/world/explain.js +1 -1
  407. package/modules/world/index.js +18 -12
  408. package/modules/world/persist.js +73 -25
  409. package/modules/world/pos.js +4 -4
  410. package/modules/world/records.js +28 -8
  411. package/modules/world/sim.js +4 -4
  412. package/modules/world/state.js +12 -5
  413. package/modules/world/thingSource.js +4 -2
  414. package/modules/world/views.js +11 -9
  415. package/package.json +42 -7
  416. package/presets.js +1 -3
  417. package/render/PostFX.js +39 -27
  418. package/render/backend.js +26 -32
  419. package/render/cascades.js +17 -12
  420. package/render/cascades.tsl.js +5 -8
  421. package/render/daylight.js +20 -3
  422. package/render/detail.js +8 -7
  423. package/render/effects.js +28 -25
  424. package/render/fuse.js +3 -3
  425. package/render/fx/cloudShadow.tsl.js +3 -3
  426. package/render/fx/detail.tsl.js +1 -1
  427. package/render/fx/index.js +5 -10
  428. package/render/fx/library.tsl.js +11 -0
  429. package/render/fx/lighting.tsl.js +2 -1
  430. package/render/fx/nodeErrors.tsl.js +2 -2
  431. package/render/fx/objectOrigin.tsl.js +1 -2
  432. package/render/fx/patchNodes.tsl.js +5 -15
  433. package/render/fx/postWebGPU.tsl.js +27 -23
  434. package/render/fx/sky.tsl.js +15 -17
  435. package/render/fx/uniforms.tsl.js +4 -4
  436. package/render/fx/wind.tsl.js +1 -1
  437. package/render/fxNumbers.js +3 -0
  438. package/render/layers.js +1 -1
  439. package/render/lighting.js +5 -3
  440. package/render/lightmap.js +20 -20
  441. package/render/lights.js +6 -6
  442. package/render/lit.js +24 -0
  443. package/render/materials.js +8 -7
  444. package/render/mergeCommon.js +22 -0
  445. package/render/modeling.js +2 -2
  446. package/render/occlusion.js +20 -4
  447. package/render/ownFrame.js +4 -4
  448. package/render/patches.js +13 -13
  449. package/render/postWebGL.js +12 -10
  450. package/render/probes.js +16 -19
  451. package/render/recordSweep.js +117 -0
  452. package/render/shaderErrors.js +10 -9
  453. package/render/shadowCache.tsl.js +107 -0
  454. package/render/shadowTypes.js +9 -0
  455. package/{core → render}/shadows.js +57 -11
  456. package/render/slots.js +7 -7
  457. package/render/terms.js +22 -24
  458. package/render/uniformDecl.js +1 -1
  459. package/types/core.d.ts +200 -153
  460. package/types/gameplay.d.ts +163 -91
  461. package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
  462. package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
  463. package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
  464. package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +7 -15
  465. package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
  466. package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
  467. package/types/generated/core/{Input.d.ts → input/Input.d.ts} +12 -8
  468. package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
  469. package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +2 -2
  470. package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
  471. package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
  472. package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
  473. package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
  474. package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
  475. package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
  476. package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
  477. package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
  478. package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
  479. package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
  480. package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
  481. package/types/generated/modules/calendar/Calendar.d.ts +10 -11
  482. package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
  483. package/types/generated/modules/grid/Layer.d.ts +1 -1
  484. package/types/generated/modules/grid/index.d.ts +3 -3
  485. package/types/generated/modules/music/Music.d.ts +7 -5
  486. package/types/generated/modules/particles/Particles.d.ts +1 -1
  487. package/types/generated/modules/sky/Sky.d.ts +21 -10
  488. package/types/generated/modules/swarm/Swarm.d.ts +80 -0
  489. package/types/generated/modules/timeline/Timeline.d.ts +2 -1
  490. package/types/generated/modules/water/Water.d.ts +1 -0
  491. package/types/generated/modules/weather/Weather.d.ts +16 -12
  492. package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
  493. package/types/generated/modules/world/World.d.ts +5 -3
  494. package/types/generated/render/PostFX.d.ts +17 -11
  495. package/types/generated/render/materials.d.ts +1 -0
  496. package/types/generated/render/occlusion.d.ts +9 -0
  497. package/types/generated/render/patches.d.ts +1 -0
  498. package/types/generated/ui/Focus.d.ts +1 -0
  499. package/types/generated/ui/UI.d.ts +1 -0
  500. package/types/nav.d.ts +11 -11
  501. package/types/physics.d.ts +99 -70
  502. package/types/tsl.d.ts +37 -4
  503. package/types/world.d.ts +38 -71
  504. package/ui/Focus.js +10 -9
  505. package/ui/Parts.js +4 -3
  506. package/ui/UI.js +7 -7
  507. package/ui/defaults.js +3 -2
  508. package/ui/theme.js +5 -3
  509. package/core/assetEntry.js +0 -109
  510. package/core/holds.js +0 -134
  511. package/core/shadowTypes.js +0 -16
  512. package/core/util.js +0 -17
  513. package/docs/MIGRATING-0.3.md +0 -248
  514. package/docs/MIGRATING-0.4.md +0 -320
  515. package/docs/MIGRATING-0.5.md +0 -68
  516. package/docs/MIGRATING-0.6.md +0 -126
  517. package/docs/PERF.md +0 -245
  518. package/docs/recipes/36-sky-ground-plants.md +0 -158
  519. package/docs/recipes/37-terrain-hooks.md +0 -115
  520. package/docs/recipes/38-environment-hooks.md +0 -67
  521. package/docs/recipes/42-terrain-shape.md +0 -64
  522. package/docs/recipes/47-island-snow-backdrop.md +0 -43
  523. package/docs/recipes/54-three-idioms.md +0 -88
  524. package/examples/plain-picture/FINDINGS.md +0 -53
  525. /package/core/{Vars.js → base/Vars.js} +0 -0
  526. /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
  527. /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
  528. /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
  529. /package/core/{actor.js → ops/actor.js} +0 -0
  530. /package/core/{opsFail.js → ops/opsFail.js} +0 -0
  531. /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
  532. /package/core/{saveIds.js → saves/saveIds.js} +0 -0
  533. /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
  534. /package/core/{tier.js → scene/tier.js} +0 -0
  535. /package/core/{cells.js → stream/cells.js} +0 -0
  536. /package/core/{streamCells.js → stream/streamCells.js} +0 -0
  537. /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
  538. /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
  539. /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
  540. /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
  541. /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
  542. /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
  543. /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
  544. /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
@@ -1,9 +1,10 @@
1
- # Starting a new game (a workspace under games/)
1
+ # Starting a new game
2
2
 
3
- **In this recipe**: 0. One-command setup · 1. Creating the files by hand · 2. Verify · 3. Preset parts · 4. Feel presets · 5. Canvas size
3
+ **In this recipe**: 0. One-command setup · 1. Creating the files by hand · 2. Verify · 3. Feel presets · 4. Canvas size
4
4
 
5
- Goal: create `games/my-game/` (pick your own name) with its own page, modules, content data and tests, independent of other games. Start from the
6
- template (`threedog new-game my-game`, section 0); the engine's own example is `examples/world/` in the package.
5
+ Goal: a game with its own page, modules, content data and tests. The engine's own example is `examples/world/` in the package.
6
+
7
+ In a folder of your own, installed from npm: run `npx threedog init` (add `--open-world` for the second form below), then `npm install`. In the engine repository: `npm run new-game -- my-game` creates `games/my-game/`. The rest of this page uses the repository form; read `games/my-game/` as your folder and `new-game` as `init`.
7
8
 
8
9
  ## 0. One-command setup (preferred)
9
10
  ```
@@ -18,37 +19,34 @@ The name may only contain lowercase letters, digits and dashes; an existing dire
18
19
  2. Creates the `node_modules/my-game` link (the path npm gives a workspace named `my-game`). It builds nothing and leaves `package-lock.json` alone; it runs `npm install` only when a dependency of the template is not installed yet, and says so.
19
20
  3. Runs `map` (generates GAMEMAP.md) and `check`. Any failing step stops and says why. The smoke test (`threedog test -w games/my-game`) builds, so it is left to you.
20
21
 
21
- The default game has no genre: `world()` + `content()`, what nearly every game needs (a start screen with Continue / Start, autosave, Esc = pause + settings menu; delete a line if the game does not want it), the engine's camera placed by hand (a plain `THREE.PerspectiveCamera`) and the gray
22
- starting picture in `picture/` (a sun, an ambient light, the tone curve, written by the game); no ground, sky, player or camera rig, because which of those a game needs depends on its genre (a character walking around a place you built: recipe 63, about twenty lines)
23
- (a card table, a puzzle room, a side-scroller and an open world start differently). Content files are empty arrays / objects (each
24
- has one comment line saying what goes there and which recipe teaches it), and `picture/`: `index.js` (wiring), `palette.js` (colors and key values), `lights.js`, `materials.js`, plain three.js
25
- that is yours to change or replace (recipe 62). `CLAUDE.md` says "This game has no gameplay yet; build what DESIGN.md describes".
22
+ The default game has no genre: `world()` + `content()`, what nearly every game needs (a start screen with Continue / Start, autosave, Esc = pause + settings menu; delete a line if the game does not want it), a plain `THREE.PerspectiveCamera` placed by hand and the gray starting picture. No ground, sky, player or camera rig: a card table, a puzzle room, a side-scroller and an open world start differently (a character walking around a place you built: recipe 63, about twenty lines).
23
+ Content files start empty, a comment in each saying what goes there, except `props.js`, whose `marker-1` shows the shape. `picture/` (`index.js` wiring, `palette.js`, `lights.js`, `materials.js`) is plain three.js, yours to change or replace (recipe 62).
26
24
  `--open-world` swaps `main.js` for `openWorld` (generated terrain from `@threedog/terrain-noise`, vegetation, a day/night sky, weather, water, collision, a
27
25
  follow camera) and a player at a flat spot, with `sky()` giving the signals and `picture/` writing the lights; it adds `@threedog/terrain-noise` to `package.json`. `spawn` and `places` take any `{ x, z }` (or `{ x, y, z }`); `findSpawn` is only for generated terrain.
28
- In an open-world start, to change the camera: `openWorld({ camera: 'firstPerson' })` (`follow` / `firstPerson` / `rts` / `fixed`, or pass a camera module directly; there is
29
- no default).
26
+ The canvas is the one you gave `createEngine({ canvas })`, also `engine.renderer.domElement`; the engine keeps no canvas property of its own.
27
+
30
28
  - The comments in `main.js` list further gameplay modules you can add; usage is in `../api/<module>.md`.
31
29
  - To change the starting point of new games, edit the real files in `packages/tools/templates/game/` (`templates/openworld/` for `--open-world`).
32
- - `DESIGN.md` is an empty template: write your gameplay ideas there. `CLAUDE.md` only points the way (read `node_modules/threedog/docs/AI.md` first,
33
- then GAMEMAP, DESIGN) and does not copy engine rules.
30
+ - `DESIGN.md` is a form to fill in with the game's design, `STATUS.md` holds progress, and `CLAUDE.md` holds the working rules, a table cut from AI.md and the reading order.
34
31
  - There is no `tests/`: when `tests/specs/` does not exist, `npm test -w games/my-game` runs a smoke test automatically.
35
32
 
36
33
  ## 1. Creating the files by hand (to learn what each file is, or when the template doesn't fit)
37
34
  | File | Content |
38
35
  |---|---|
39
- | `games/my-game/package.json` | Copy `package.json` from the game template (or run `threedog new-game my-game`) and set `name` to `my-game` (the plain game name, in this repository and in a game repo of its own; `@threedog/` is the engine's packages; dependencies `threedog`, `@threedog/tools`, plus `@threedog/terrain-noise` only for an open-world start, and your style (and `@threedog/post-effects` if the pack uses it) only when `main.js` imports it; the game's picture is its own `picture/` folder; scripts dev/build/preview/test/check/map) |
36
+ | `games/my-game/package.json` | Copy the template's and set `name` to `my-game` (the plain game name; `@threedog/` is the engine's packages). Dependencies `threedog`, `@threedog/tools`, plus `@threedog/terrain-noise` only for an open-world start and `@threedog/post-effects` only when the game imports it |
40
37
  | `games/my-game/vite.config.js` | One line: `export default gameConfig(import.meta.dirname)` (imported from `@threedog/tools/vite`); *.html files in the directory are bundled automatically, no `input` needed. Without `@threedog/tools`, a plain vite config needs `worker: { format: 'es' }` (the engine's Workers are ES modules) or `vite build` fails; `threedog dev / build` on a folder with no vite config uses the preset |
41
- | `games/my-game/index.html` | The page: one `<canvas id="view">` with a CSS size + `/main.js` (for more pages put `xxx.html` in the same directory); see §5 for embedding |
42
- | `games/my-game/main.js` | Install modules, compute places, `content.load`, game-specific logic |
38
+ | `games/my-game/index.html` | The page: one `<canvas id="view">` with a CSS size + `/main.js` (for more pages put `xxx.html` in the same directory); see §4 for embedding |
39
+ | `games/my-game/main.js` | Install modules, compute places, `content.load`, wire the game's systems (template `CLAUDE.md`, "Content vs code") |
43
40
  | `games/my-game/content/index.js` | Combines the content files into one object |
44
- | `games/my-game/content/*.js` | Only these names are read: items pickups containers npcs dialogues quests actions places triggers level vegetation props templates audio grids renames rules, plus the game's own kinds (rules.js) |
45
- | `games/my-game/DESIGN.md` | Hand-written design decisions (a few lines of `- **decision**: reason`), copied into GAMEMAP.md |
46
- | `games/my-game/CLAUDE.md` | A few lines: read `node_modules/threedog/docs/AI.md`, then this directory's GAMEMAP.md and DESIGN.md (copy the template's) |
47
- | `games/my-game/public/` | This game's art assets (URL `/models/...`); keep Blender source files in `games/my-game/art/models/`, `npm run assets -- -w my-game` compresses them into `public/optimized/` |
41
+ | `games/my-game/content/*.js` | Only these names are read: items pickups containers npcs dialogues quests actions places triggers level vegetation props templates audio views grids renames rules, plus the game's own kinds (rules.js) |
42
+ | `games/my-game/DESIGN.md` | The design as a form (copy the template's), copied into GAMEMAP.md |
43
+ | `games/my-game/STATUS.md` | Progress and what comes next (copy the template's) |
44
+ | `games/my-game/CLAUDE.md` | Working rules and reading order (copy the template's) |
45
+ | `games/my-game/public/` | This game's art assets (URL `/models/...`); keep Blender source files in `games/my-game/art/models/`, `npm run assets -- optimize -w my-game` compresses them into `public/optimized/` |
48
46
 
49
47
  After creating them, run `npm install` once at the repository root (this links the new game into the workspaces so `threedog` can find it).
50
48
 
51
- Outside the engine repository, a game installs `threedog` and `three` (plus your style, `@threedog/post-effects` / `@threedog/terrain-noise` if it imports them,
49
+ Outside the engine repository, a game installs `threedog` and `three` (plus `@threedog/post-effects` / `@threedog/terrain-noise` if it imports them,
52
50
  and `@threedog/tools` as a dev dependency for the CLI and the vite preset). To use an engine folder on disk instead of npm, install it with
53
51
  `npm install --install-links <folder>`: a plain link skips the engine's own dependencies (Rapier, Recast) and the build cannot resolve them.
54
52
 
@@ -58,13 +56,6 @@ In a game's own repository, `threedog check`, `types` and `map` read only the ga
58
56
  The template's `tsconfig.json` checks the game files only (`checkJs`), with `lib` ESNext + DOM (dependency typings such as Rapier's use
59
57
  `Symbol.dispose`) and `skipLibCheck: true`; without a tsconfig, `threedog types` writes the same settings to `.threedog/tsconfig.types.json`.
60
58
 
61
- `games/my-game/index.html` (minimal; the template's `index.html` has the same page with loading styles):
62
- ```html
63
- <!doctype html>
64
- <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
65
- <title>My game</title><style>html,body{height:100%;margin:0;overflow:hidden;background:#141a17}#view{position:fixed;inset:0;width:100%;height:100%;display:block;outline:none}</style>
66
- </head><body><canvas id="view" tabindex="0"></canvas><script type="module" src="/main.js"></script></body></html>
67
- ```
68
59
 
69
60
  `games/my-game/main.js`: the opening lines are written out once, in [recipe 63](63-third-person-start.md) §1 (the blank template's `main.js` has the same opening with `world(), content(), settings()` and the camera placed by hand). What an open-world game with a few gameplay modules changes in it:
70
61
  ```js
@@ -85,7 +76,7 @@ engine.use(openWorld({ camera: 'follow', seed: 42, terrain: terrainPreset(), tim
85
76
  // the terrain is generated: find flat ground as "home" at the start (give your own height range to avoid beach and peaks)
86
77
  const home = engine.characters.findSpawn([0, 0, 0], { minH: 3, maxH: 14 });
87
78
  engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: home });
88
- engine.content.load(data, { places: { ...data.places, home } }); // content/places.js names + this one; content uses { place: 'home', x, z }, quests target: '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'
89
80
  ```
90
81
  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:
91
82
  `openWorld({ seed: 42, camera: 'follow', calendar: { seasons: ['wet', 'dry'], daysPerSeason: 28 }, characters: { npcs: false }, rigid: false, ambience:
@@ -102,7 +93,7 @@ engine.setGround({ height: (x, z) => 0 }); // what walking, placing and the ca
102
93
  ```
103
94
  Walls and obstacles are `engine.collision.addBox(obj, { halfWidth, halfDepth })`; a Blender level brings its own ground (`level()`, next paragraph).
104
95
  `saveKey` must differ per game, otherwise saves overwrite each other. The UI language follows the player's browser (Chinese browser -> Chinese,
105
- otherwise English) unless you set `createEngine({ locale: 'zh-CN' })` (`'zh'` and `'en-US'` match too; a language with no strings warns). A game without terrain (the city test page in the engine repository does this): register
96
+ otherwise English) unless you set `createEngine({ locale: 'zh-CN' })` (`'zh'` and `'en-US'` match too; a language with no strings warns). A game on a level built in code: register
106
97
  the level generator function under `models` in `engine.assets.manifest({ name, models })`, use `level({ url: name })` and pick your own modules, then
107
98
  create the player and install content in `level:loaded`.
108
99
 
@@ -112,7 +103,7 @@ import items, { startItems } from './items.js';
112
103
  import places from './places.js';
113
104
  export default { items, startItems, places };
114
105
  ```
115
- `content/places.js`: `export default { home: 'flat ground found at the start (coordinates computed in main.js)' };`
106
+ `content/places.js`: `export default { farm: { x: 12, z: -4 }, home: 'flat ground found at the start' };`. `content.load` reads a place written with coordinates from the data; a text entry only declares the name for `threedog check` and waits for `content.load(data, { places })`.
116
107
 
117
108
  ## 2. Verify
118
109
  1. `npm run map` -> generates `games/my-game/GAMEMAP.md`; check the "engine modules" and "page /" sections.
@@ -123,12 +114,8 @@ export default { items, startItems, places };
123
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
124
115
  `npm run dev -- my-game`) and open the printed address; read errors in `games/my-game/.threedog/errors.log`.
125
116
 
126
- ## 3. Preset parts
127
- Every `openWorld()` part takes `false` or its module's options object, for example
128
- `openWorld({ camera: 'follow', calendar: { seasons: ['wet', 'dry'], daysPerSeason: 28 }, debug: false })`. Gameplay modules (interactions, dialogue,
129
- inventory, quests) are not in the preset: add them with `engine.use`. The debug panel is dev-only by default.
130
117
 
131
- ## 4. Feel presets (opt-in)
118
+ ## 3. Feel presets (opt-in)
132
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
133
120
  refuse to guess: `createPlayer()` throws `[player-control]` without `control`, `interactions()` throws `[interaction-setup]` without `pick` and keys,
134
121
  `openWorld()` throws `[open-world-camera]` without `camera`. The core key table holds only movement and menu confirm / cancel; run, jump and interact
@@ -140,11 +127,9 @@ engine.use(calendar(presets.calendar.fourSeasons), sky(), weather({ ...presets.w
140
127
  engine.use(interactions({ ...presets.interactions.facing })); // nearest / facing / aim, each with E
141
128
  const player = engine.characters.createPlayer({ ...presets.player.lockOn, faceTarget: boss }); // none / thirdPerson / lockOn / aim / sideScroller
142
129
  ```
143
- `presets.player.thirdPerson` is `{ control: 'camera', faceMode: 'move', cameraFollow: true }`; the run / jump keys are
144
- `presets.bindings.walk` (`{ run: ['ShiftLeft', 'ShiftRight', 'PadLB'], jump: ['Space', 'PadA'] }`). No module or preset takes keys: every key
145
- comes from `createEngine({ bindings })` or `engine.input.bind(...)`.
130
+ The run / jump keys are `presets.bindings.walk`. No module or preset takes keys: every key comes from `createEngine({ bindings })` or `engine.input.bind(...)`.
146
131
 
147
- ## 5. Canvas size: full window, a page section, a split layout or an editor panel
132
+ ## 4. Canvas size: full window, a page section, a split layout or an editor panel
148
133
  The engine follows the canvas's own CSS box (a `ResizeObserver` on the canvas), not the window: renderer size, camera aspect, `input.pointer` (`x / y`
149
134
  pixels and `ndcX / ndcY` relative to the canvas), `engine.pick`, `screenToGround`, `worldToScreen` and the HUD all use that box, and the engine's UI
150
135
  root is laid exactly over it. So the layout decides:
@@ -1,10 +1,11 @@
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
4
+
3
5
  Modules needed: `characters()` (NPCs on by default), `interactions({ ...presets.interactions.nearest })`, `dialogue()`; clock-time schedules need
4
- `sky()` with a day cycle (`dayLength`, e.g. `presets.calendar.cycle`: without one the clock never moves and the NPC keeps to one stop). The
5
- `openWorld()` preset already installs `characters()` and `sky()` but not `interactions({ ...presets.interactions.nearest })` or `dialogue()`, so add
6
- them yourself: `engine.use(openWorld({ camera: 'follow', calendar: presets.calendar.cycle, ...}), interactions({ ...presets.interactions.nearest }),
7
- dialogue(), content())`.
6
+ `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()`
7
+ installs `characters()` and the calendar but not the other two: `engine.use(openWorld({ camera: 'follow', calendar: presets.calendar.cycle, ...}),
8
+ interactions({ ...presets.interactions.nearest }), dialogue(), content())`.
8
9
 
9
10
  ## 1. Write data (recommended)
10
11
  `games/<game>/content/npcs.js`:
@@ -12,7 +13,7 @@ dialogue(), content())`.
12
13
  export default {
13
14
  guard: {
14
15
  name: 'Gate guard',
15
- colors: { body: 0xc89a5a, legs: 0x5b4a3a, hair: 0x3a2a1a }, // omit to use the style's default colors
16
+ colors: { body: 0xc89a5a, legs: 0x5b4a3a, hair: 0x3a2a1a }, // omit to use the default colors
16
17
  start: { place: 'home', x: 6, z: -3 }, // starting position; omitted = the first stop of the schedule
17
18
  schedule: [ // at is a clock time 'HH:MM'; at that time the NPC walks there (pathfinding is automatic)
18
19
  { at: '07:00', place: 'home', x: 6, z: -3 },
@@ -52,10 +53,10 @@ export default {
52
53
  },
53
54
  };
54
55
  ```
55
- The words usable in conditions / effects are in the comment at the top of `modules/content/rules.js` (flag notFlag has lacks counter can / setFlag
56
+ The words usable in conditions / effects are in the last section of `../api/content.md` (flag notFlag has lacks counter can / setFlag
56
57
  give take bump startQuest toast particles marker clearMarker op). A game's own action is an op, always written as a pair `[name, args]` (a bare
57
58
  name string is rejected): `do: { op: ['delivery.done', { parcel: 'p1' }] }` (`23-ops.md`).
58
- The items used (coin, pass) must be defined in `items.js`, otherwise validation fails. A `place` name comes from `content.load(data, { places })` or
59
+ The items used (coin, pass) must be defined in `items.js`, otherwise validation fails. A `place` name comes from `content/places.js`, `content.load(data, { places })` or
59
60
  from a level marker (such as `npc_guard`). Add a new content file to `content/index.js`.
60
61
 
61
62
  ## 2. Add in code (temporary NPCs, dynamic schedules)
@@ -119,26 +120,24 @@ engine.npcs.behavior('chase', {
119
120
  npc.setBehavior('chase');
120
121
  ```
121
122
  To path around obstacles, use `engine.characters.findPath(from, to)` to get waypoints and walk them one by one (the schedule behavior does exactly
122
- this, see `goTo` in `modules/characters/npcSim.js`).
123
+ this).
123
124
 
124
125
  ## Avoidance (NPCs don't clump or pass through each other)
125
126
  NPCs with models nearby avoid each other by default: when closer than the sum of two radii (`engine.movement.radius` x 2, about 0.8 meters) they push
126
127
  each other apart, harder the more they overlap, at most 3 meters per second; the player counts as an obstacle that only NPCs yield to, and the
127
128
  player's position is never pushed. After pushing, `engine.collision` (if installed) constrains them back to walkable ground, so they are not pushed
128
129
  into walls. The built-in `schedule` and `wander` both avoid.
129
- - Deterministic and cheap: done only in the fixed step, no random numbers, neighbors computed from "the positions at the start of this step", so after
130
- save and load, or with a different `frameEvery`, positions are identical bit for bit; 400 NPCs with models cost less than 1 ms per step (a tight
131
- clump only a few ms).
130
+ - Deterministic: done only in the fixed step, no random numbers, neighbors computed from the positions at the start of the step, so a load or a different
131
+ `frameEvery` gives identical positions.
132
132
  - Tune or turn off:
133
133
  ```js
134
134
  engine.npcs.avoid.set({ radius: 0.6, strength: 2 }); // stand sparser (radius in meters), push slower (strength in meters/second)
135
135
  engine.npcs.avoid.set(false); // turn off (ghosts, crowds passing through); set(true) turns it on again
136
136
  ```
137
137
  - 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.
138
- - Difference from `nav({ crowd: true })`: when crowd is installed the Recast crowd agents take over and this is not applied on top. Crowd routes more
139
- cleverly (around obstacles along the navmesh, yields to others) but does not guarantee identical results after loading; the simple push here does
140
- not route around anything and only keeps NPCs from overlapping, with results identical after loading. For save replay and determinism use this; for
141
- crowds going around big obstacles use crowd.
138
+ - `nav({ crowd: true })` replaces this push with Recast crowd agents: they route around obstacles along the navmesh but do not guarantee identical
139
+ results after a load. The push routes around nothing and only keeps NPCs from overlapping. For replays and saves use the push; for crowds going
140
+ around big obstacles use crowd.
142
141
  - Behaviors you write are not avoided automatically: after your own `character.move`, call `engine.npcs.avoid.push(rec, npc.character, dt)` once
143
142
  (inside `near`, before writing back to the data).
144
143
 
@@ -146,7 +145,7 @@ engine.npcs.avoid.set(false); // turn off (ghosts, cro
146
145
  ## A guard you build yourself (`Character` + `walkTo`)
147
146
 
148
147
  For a one-off (guard, pet, follower) that `schedule` / `wander` do not cover: `new Character(engine, { rig })` takes a ready body
149
- (`{ root, body?, head?, limbs?, joints? }`), or `{ model: 'humanoid' }` picks a body asset like any character ([13-animation](13-animation.md)); call `character.animate(dt)` each frame.
148
+ (`{ root, body?, head?, limbs?, joints? }`), or `{ model: 'villager' }` / `{ model: ['villager', 0xcc8844] }` names a body your own asset pack registers (none ships with the engine; `humanoid` in other pages is such a name) like any character ([13-animation](13-animation.md)); call `character.animate(dt)` each frame.
150
149
  `character.walkTo(target, { speed, arrive, turnRate, run })` follows `characters.findPath` on fixed steps (turns at `turnRate` rad/s, skips passed
151
150
  points, re-plans when it makes no progress for `stuckSeconds`, up to `maxRepaths`). It returns a promise of `{ status }`: `'arrived'` | `'noPath'` |
152
151
  `'stuck'` | `'cancelled'` (never rejects), with `remove()` to cancel.
@@ -155,7 +154,8 @@ walk, and an escort quest that wants the same NPC takes control itself (`engine.
155
154
  editing its record.
156
155
 
157
156
  ```js
158
- const guard = new Character(engine, { rig: { root: myGuardMesh } }).addTo();
157
+ const guard = new Character(engine, { rig: { root: myGuardMesh } });
158
+ engine.add(guard.root);
159
159
  guard.placeAt(post);
160
160
  const walk = guard.walkTo(player.position, { arrive: 1.5 });
161
161
  if ((await walk).status === 'noPath') guard.face(player); // walk.remove() cancels
@@ -172,12 +172,11 @@ The dialogue's keys go through two ops, so code, tests and the dev bridge drive
172
172
  `npm run map` it shows up in the NPC table and dialogue graph of GAMEMAP.md.
173
173
  - State: `npm run shot -- / --time 13:10 --wait 20 --describe-only`; the "nearby" list has an entry for `Gate guard` tagged as an NPC with its distance in
174
174
  meters (only listed within 30 meters; add `--pos x,z` to stand by the tower).
175
- - Console / tests: `engine.npcs.get('guard').position`, `.currentStop()`; during a dialogue `engine.describe().ui.dialogue` = `{ speaker, text, typing, choices: [labels], lock }` (absent when no dialogue runs; the text version prints it as a `Dialogue:` line). `describe` does NOT expose the node id or the NPC id: `speaker` is the display name; to inspect the node, read the content file or listen to `engine.events.on("dialogue:line", ({ script, node, speaker, text }) => ...)` (also `dialogue:start` / `dialogue:end`).
175
+ - Console / tests: `engine.npcs.get('guard').position`, `.currentStop()`; during a dialogue `engine.describe().ui.dialogue` = `{ speaker, text, typing, choices: [labels], selected, advance }`. `describe` shows no node or NPC id: to inspect the node, listen to `engine.events.on("dialogue:line", ({ script, node, speaker, text }) => ...)` (also `dialogue:start` / `dialogue:end`).
176
+ - E opens a conversation; only confirm (Space / Enter) advances it, unless `dialogue({ advanceActions })` adds a key. `describe().ui.dialogue.advance` names the keys. While it is open game input is locked, so E on anything else does nothing: the press is logged as a refused `interaction.use` (`inputLocked`) in `engine.ops.recent()` and `threedog test` prints it under a failed spec.
176
177
  - Advancing a dialogue in a headless test (typing and "keys ignored right after opening" both run on game time): press E when near -> `engine.step(1)`
177
178
  to finish typing -> press a number key or run `engine.ops.run('dialogue.choose', { index: i })` (while typing it completes the sentence first) ->
178
179
  `engine.step(0.3)`. No real-time waiting.
179
- - Related tests: `npm test -- 小城` (the shopkeeper's schedule and dialogue), `npm test -- "S1 NPC"` (far-away simulation, changing level, saving,
180
- identical results after loading).
181
180
 
182
181
  ## Talking in a bubble instead of a conversation
183
182
  `interact: { op: 'npc.talk', args: { channel: 'bubble' } }` (code or content) makes the interact key play the NPC's script as bubble lines over its head while the player keeps
@@ -9,9 +9,9 @@ Shells on a beach, four kinds of flowers, letters to collect: things the player
9
9
  engine.hud.counter('shells', { label: 'Shells', value: 0, max: 4 }); // at setup, not on session:start
10
10
  shells.forEach((shell, i) => engine.interactions.add(shell, { id: `shell-${i}`, label: 'Pick up', once: true, counter: 'shells', onUse: () => engine.audio.sfx('pick') }));
11
11
  ```
12
- `once` hides the mesh after a use (`onUse` returning `{ ok: false }` leaves it); `counter` adds 1 through `engine.hud.add(name, n)`, and does nothing without
12
+ `once` hides the mesh after a use (`onUse` returning `{ ok: false }` leaves it); `counter` adds 1 through `engine.hud.bump(name, n)`, and does nothing without
13
13
  `hud()`. Both are saved and go back on a new game. The save knows a thing by `id`, else `mesh.name`: development throws when it has neither, or shares one with another once item.
14
- A hidden mesh is only hidden: a collider it had is yours to remove in `onUse`. To add up without a thing to take, call `engine.hud.add('score', 10)` yourself.
14
+ A hidden mesh is only hidden: a collider it had is yours to remove in `onUse`. To add up without a thing to take, call `engine.hud.bump('score', 10)` yourself.
15
15
 
16
16
  | Use | When |
17
17
  |---|---|
@@ -19,10 +19,9 @@ A hidden mesh is only hidden: a collider it had is yours to remove in `onUse`. T
19
19
  | `pickups.spawn` (below) | it goes in a bag, respawns, is taken by walking into it (`auto`), is laid out in `content/`, or a net host must decide who got it |
20
20
 
21
21
  ## Items and pickups
22
- Modules needed: `inventory()` (inventory; the window is the UI part `inventory`, opened with the key the game gives:
23
- `inventory()`; its open key is the game's: `presets.bindings.inventory` is I / gamepad Y, `inventory: []` none; no module binds a key by itself) +
24
- `pickups()` (things lying on the ground; needs `world()`, which `openWorld()` includes) + `interactions({ ...presets.interactions.nearest })` (walk up
25
- to a pickup and press E). "Already picked up / how long until it grows back" is data in world and is saved with the game.
22
+ Modules needed: `inventory()` (its window is the UI part `inventory`; the open key is the game's: `presets.bindings.inventory` is I / gamepad Y,
23
+ `inventory: []` none) + `pickups()` (things lying on the ground; needs `world()`, which `openWorld()` includes) +
24
+ `interactions({ ...presets.interactions.nearest })` (walk up to a pickup and press E). "Already picked up / how long until it grows back" is data in world and is saved with the game.
26
25
 
27
26
  **Every actor has its own bag**: the container whose id is the actor's id (`inventory.of(actor)`): `'player'` for the local user, each net peer's actor
28
27
  id on the host, an NPC's id. "The player inventory" (`inventory.add / count / list ...`) is the bag of `engine.actor`. Whoever takes a pickup gets it in
@@ -42,7 +41,7 @@ export const startItems = { coin: 3 }; // what the inventory holds at t
42
41
  `content/pickups.js` (a list):
43
42
  ```js
44
43
  export default [
45
- { item: 'mushroom', place: 'home', x: 8, z: 3, respawn: 120 }, // respawn: after how many game seconds it grows back (omitted = never again)
44
+ { item: 'mushroom', place: 'home', x: 8, z: 3, respawn: 120 }, // respawn: after how many calendar seconds it grows back (omitted = never again)
46
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
47
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)
48
47
  ];
@@ -54,26 +53,21 @@ is built only near the player and removed when far.
54
53
  Id: if you write an `id` it is used; otherwise it is `pickup:<item>:<index in the pickups array>`, the same every time for the same content, and
55
54
  distinguishes the same item placed at the same coordinates. **Write an `id` if the content will keep changing** (inserting a new one in the middle
56
55
  shifts the later indices).
57
- When picked up, the record is removed from world; one with `respawn` stays and gets an `until` (respawn time, game seconds); while waiting it has no
58
- model, and at that time (also when far away with no model) `until` is cleared and it returns to the ground.
59
- Pickups in content are the world's **initial data**: the save records only what was picked up and what is waiting to respawn; it makes no difference
60
- whether `content.load` runs before or after loading, and picked-up items do not reappear; positions that use a level marker carry a `zone`, so after
61
- changing level and coming back they are still picked up.
56
+ When picked up, the record is removed from world; one with `respawn` stays and gets an `until` (calendar seconds); while waiting it has no model,
57
+ and at that time (also when far away with no model) it returns to the ground. Pickups in content are initial data, like props (recipe 18 §4).
62
58
  `engine.world.remove(id)` deletes one directly.
63
59
 
64
60
  ## 2. In code (dynamic drops, custom models, instant effects)
65
61
  ```js
66
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)
67
63
  const gem = engine.pickups.spawn(engine.player.position, { give: 'gem', count: 1 }); // returns a handle; gem.remove() deletes data and model together
68
- // handle: { id: id in world, give, object: current model (null when far), remove() }; opts.id lets you write a stable id (spawning again with the same id reuses the existing one)
69
- engine.inventory.add('coin', 2); // give directly to the local bag; returns the entry key ('coin'), false if it doesn't fit
70
- engine.inventory.remove('coin', 1); // returns false if there isn't enough
71
- engine.inventory.has('coin', 2); // at least 2?
64
+ // opts.id writes a stable id (spawning again with the same id reuses the existing one)
65
+ engine.inventory.add('coin', 2); // the local bag; { ok: true, key: 'coin', added: 2 }, or { ok: false, code: 'full' } if none fit
72
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
73
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
74
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
75
69
  ```
76
- The default reach is `pickups({ radius: 2 })`; each pickup can set its own `radius`. Taking one is the op `pickup.take { id }` (net: `'peer'`): the
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
77
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`.
78
72
  A give function is not saved data: code that spawns one spawns it again on load (content and setup code do); a runtime drop gives an item id.
79
73
 
@@ -85,10 +79,7 @@ also takes a key.
85
79
  ```js
86
80
  const I = engine.inventory;
87
81
  I.define('sword', { name: 'Sword', stack: 1 });
88
- const key = /** @type {string} */ (I.add('sword', 1, { data: { durability: 80, level: 3 } })); // 'sword#7' (add returns false when it does not fit)
89
- I.count('sword'); // every sword, with or without data
90
- I.get(key); // { key, id: 'sword', count: 1, data: { durability: 80, level: 3 }, def }
91
- I.list(); // every entry: [{ key, id, count, data, def }] for your own UI
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)
92
83
  // change it inside an op or fixed step (data objects are frozen: always pass a new one; the key stays the same)
93
84
  const s = I.get(key); I.setData(key, { ...s.data, durability: s.data.durability - 1 });
94
85
  I.transfer('player', 'chest-1', key); // exactly this sword; it keeps its data and key
@@ -100,8 +91,7 @@ Data and keys are saved with the container. Which piece a player means is chosen
100
91
 
101
92
  ## Limits (all optional, none by default)
102
93
  `inventory({ capacity, maxWeight })` for the player and `inventory.container(id, { capacity, maxWeight })` for others:
103
- `capacity` = slots (an entry uses `ceil(count / stack)`), `maxWeight` = sum of item `weight` × count. `room(item)` says how many more fit; `weight`
104
- and `slotsUsed` read the totals. Locks, prices and "only one equipped" are game rules: check them in your op's `can`.
94
+ `capacity` = slots (an entry uses `ceil(count / stack)`), `maxWeight` = sum of item `weight` × count.
105
95
 
106
96
  ## Using and dropping (ops)
107
97
  ```js
@@ -131,19 +121,17 @@ The window is a UI part (recipe 26): the engine opens and closes it (the bound `
131
121
  ```js
132
122
  engine.ui.set('inventory', false); // no window at all (the key does nothing, no DOM)
133
123
  engine.ui.set('inventory', { drop: true }); // default window plus a Drop button per row (Use appears for items with use)
134
- engine.ui.set('inventory', (engine) => { // your own: grid, drag and drop, anything
124
+ engine.ui.set('inventory', (engine) => { // your own: grid, drag and drop, anything; buttons run ops with an entry's key
135
125
  const el = document.createElement('div'); engine.uiRoot.appendChild(el);
136
- el.onclick = ev => { const key = ev.target.dataset.key; if (key) engine.ops.run('inventory.use', { item: key }); }; // buttons run ops
137
- return { show: d => { el.hidden = false; el.innerHTML = d.items.map(i => `<button data-key="${i.key}">${i.def.name} ×${i.count}</button>`).join(''); },
138
- update: d => { el.innerHTML = d.items.map(i => `<button data-key="${i.key}">${i.def.name} ×${i.count}</button>`).join(''); },
139
- hide: () => { el.hidden = true; }, dispose: () => el.remove() };
126
+ el.onclick = ev => { const key = ev.target.dataset.key; if (key) engine.ops.run('inventory.use', { item: key }); };
127
+ const draw = d => { el.innerHTML = d.items.map(i => `<button data-key="${i.key}">${i.def.name} ×${i.count}</button>`).join(''); };
128
+ return { show: d => { el.hidden = false; draw(d); }, update: draw, hide: () => { el.hidden = true; }, dispose: () => el.remove() };
140
129
  });
141
130
  engine.ui.open('inventory'); engine.ui.close('inventory'); // open / close from code
142
131
  ```
143
- The shape of an item on the ground is a model name from an asset pack, built through the same path as content props and templates (one build per
144
- name, cached / baked, the same shadow rule): the item's `model`, else a model named `pickup:<item id>`, else one named `pickup`, else a neutral gray
145
- box. A generator that returns bare geometry is drawn with `engine.pickups.material` in the item's own `color` (a coin, a gem, a medkit or a paper
146
- note are all just models).
132
+ 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
+ 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
+ `engine.pickups.material` in the item's own `color`.
147
135
  ```js
148
136
  engine.use(pickups({ color: 0xd8c070, size: 0.3, lift: 0.5 })); // default color, placeholder box, height above the ground
149
137
  engine.pickups.material = new THREE.MeshStandardMaterial({ metalness: 0.8, roughness: 0.3 }); // swaps every box and geometry-only model; used as given
@@ -154,13 +142,12 @@ To give / take items in content use the effect words: `{ give: { coin: 2 } }`, `
154
142
  `{ has: { mushroom: 3 } }`, `{ lacks: { coin: 1 } }`.
155
143
 
156
144
  ## Chests / corpses / shelves (multiple containers)
157
- The player inventory is just one container (the bag of `engine.actor`, id `'player'` locally). Chests, corpses, shelves and ammo boxes all use `inventory.container(id, { capacity })` to
158
- get or create one (calling again with the same id returns the same one); limits as above. A container has the same
159
- `add / remove / count / has / get / list / setData` as the inventory, plus `room(id)` (how many more fit) and `on('add' | 'remove', fn)` (returns a handle).
145
+ The player inventory is just one container (the bag of `engine.actor`). Chests, corpses, shelves and ammo boxes use `inventory.container(id, { capacity })`
146
+ to get or create one (the same id returns the same one); it has the inventory's methods plus `room(id)` and `on('add' | 'remove', fn)`.
160
147
  ```js
161
148
  const I = engine.inventory;
162
149
  const chest = I.container('chest-1', { capacity: 8 });
163
- chest.add('bandage', 2); // returns false if it doesn't fit (if part fits, that part is added)
150
+ chest.add('bandage', 2); // { ok: false, code: 'full' } if none fit; if part fits, that part goes in and `added` says how many
164
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)
165
152
  I.transfer('player', chest, 'coin', 5); // shelves and money boxes work the same way
166
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 }
@@ -170,13 +157,10 @@ chest.on('remove', ({ id, count, actor }) => console.log(actor, 'took', id, coun
170
157
  initial goods). Loading creates the containers first, and a later `container(id, { capacity })` in code just fills in the slot count, in either order.
171
158
  - **Deleting a world record does not delete its container automatically** (whether to keep a searched corpse is up to the game). To clear both:
172
159
  `engine.events.on('world:remove', ({ id }) => I.removeContainer(id))`.
173
- - **Pre-filled contents (initial semantics)**: goods are placed only the **first** time; on load the save wins, and a searched-empty container is not
174
- refilled after loading. Write `content/containers.js` in content (`export default { 'chest-1': { capacity: 8, items: { bandage: 2 } } }`, and put it
175
- in the export of `content/index.js`), or in code `I.container('chest-1', { capacity: 8, items: { bandage: 2 } })`. For an already existing container
176
- (created first by loading, or already created this session) `items` is not placed again; a container that was given goods goes into the save even
177
- when searched empty (`{}`), so after a refresh and load it is empty and not refilled. Don't fill with `container(id).add(...)` at startup: a
178
- container with nothing in it is not saved, so after a refresh it would be treated as new and filled again. A container id is any string and all are
179
- saved ('shop-bakery' and 'prop:chest:3' alike).
160
+ - **Pre-filled contents**: goods are placed only the **first** time; on load the save wins, and a searched-empty container is not refilled. Write
161
+ `content/containers.js` (`export default { 'chest-1': { capacity: 8, items: { bandage: 2 } } }`, exported from `content/index.js`), or in code
162
+ `I.container('chest-1', { capacity: 8, items: { bandage: 2 } })`. Don't fill with `container(id).add(...)` at startup: a container with nothing in it is
163
+ not saved, so after a refresh it would be treated as new and filled again.
180
164
  - **UI**: the engine only makes the player inventory window; for a chest UI draw `chest.list()` yourself, and clicking an entry runs
181
165
  `engine.ops.run('inventory.transfer', { from: 'chest-1', to: 'player', item: entry.key })`.
182
166
  - Non-empty containers appear in `describe()` under `inventory.containers`.
@@ -23,7 +23,7 @@ export default {
23
23
  },
24
24
  };
25
25
  ```
26
- `target` forms: a place name (its coordinates come from `engine.content.load(data, { places })` or a level marker, recipe 01), `{ place, x, z }`, `{ x, z }` (world coordinates; any of these may add `floor` / `y` for a storey on multi-layer ground,
26
+ `target` forms: a place name (its coordinates come from `content/places.js`, `engine.content.load(data, { places })` or a level marker, recipe 01), `{ place, x, z }`, `{ x, z }` (world coordinates; any of these may add `floor` / `y` for a storey on multi-layer ground,
27
27
  as in props), `{ npc: 'id in npcs.js' }`, `{ nearest: 'itemId' }` (the closest not-yet-picked-up pickup of that kind to the player; hidden
28
28
  automatically once picked up).
29
29
  In code you can also write a function `target: () => target or null` (evaluated every frame); to change the target of a manual marker use
@@ -81,10 +81,9 @@ or bar in that screen column.
81
81
  `quests: {...}` line).
82
82
  In more detail: `engine.quests.list()` (each step has `current/done/target`), `engine.quests.isActive(id)`; story flags in `engine.vars.flags`.
83
83
  - Objective markers: `describe().hud.markers` has `{ label: quest title, distance: meters, onScreen }`; counters are in `describe().hud.counters`.
84
- - After advancing a condition you don't have to wait: `engine.quests.check()` checks immediately. Related test: `npm test -- 目标指示`.
84
+ - After advancing a condition you don't have to wait: `engine.quests.check()` checks immediately.
85
85
 
86
86
  ## Reading and moving progress from code
87
- `engine.quests.state(id)` gives `{ step, steps, done, failed, active }` (or null before it starts): a copy, so read it, never write it.
88
- A step the game finishes from its own code (a cutscene ended, a boss fell) can skip its condition: `engine.quests.advance(id)` moves to the next step
87
+ A step the game finishes from its own code (a cutscene ended, a fight was won) can skip its condition: `engine.quests.advance(id)` moves to the next step
89
88
  and completes the quest after the last one (reward, `quest:done`); call it from an op or a fixed step. A replacement quests module meets
90
89
  `modules/gameplay/quests.contract.js` (define / start / advance / state / list, events quest:start / quest:step / quest:done, save key quests).