threedog 0.2.1 → 0.5.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 (593) hide show
  1. package/CHANGELOG.md +290 -0
  2. package/README.md +9 -8
  3. package/core/Animator.js +15 -12
  4. package/core/Assets.js +71 -16
  5. package/core/Audio.js +45 -38
  6. package/core/Baked.js +32 -8
  7. package/core/Batching.js +102 -15
  8. package/core/Budget.js +39 -18
  9. package/core/Clock.js +40 -80
  10. package/core/DebugOverrides.js +45 -10
  11. package/core/Describe.js +104 -43
  12. package/core/Engine.js +183 -59
  13. package/core/Events.js +4 -1
  14. package/core/I18n.js +25 -13
  15. package/core/Input.js +168 -79
  16. package/core/Inspect.js +2 -2
  17. package/core/InspectMaterials.js +85 -0
  18. package/core/InspectPerf.js +61 -0
  19. package/core/InspectScene.js +13 -2
  20. package/core/Loading.js +2 -1
  21. package/core/Ops.js +50 -9
  22. package/core/Random.js +9 -2
  23. package/core/Rays.js +5 -5
  24. package/core/SaveStore.js +41 -9
  25. package/core/Saves.js +71 -15
  26. package/core/Stream.js +14 -10
  27. package/core/Threads.js +26 -7
  28. package/core/UrlState.js +25 -9
  29. package/core/Views.js +9 -6
  30. package/core/actor.js +1 -1
  31. package/core/adaptive.js +93 -0
  32. package/core/assetEntry.js +22 -5
  33. package/core/assetHot.js +176 -0
  34. package/core/assetLoad.js +38 -11
  35. package/core/assetManifest.js +48 -9
  36. package/core/assetReport.js +1 -1
  37. package/core/audioRules.js +13 -11
  38. package/core/audioVoice.js +69 -42
  39. package/core/canvasBox.js +1 -2
  40. package/core/catalog.js +5 -2
  41. package/core/cells.js +62 -0
  42. package/core/checks.js +10 -8
  43. package/core/chunkStream.js +87 -0
  44. package/core/control.js +149 -0
  45. package/core/copies.js +32 -0
  46. package/core/dayTime.js +12 -6
  47. package/core/debugView.js +82 -15
  48. package/core/describeRender.js +37 -17
  49. package/core/describeText.js +41 -21
  50. package/core/engineCamera.js +32 -0
  51. package/core/errorCodes.js +438 -19
  52. package/core/errorHints.js +37 -141
  53. package/core/errors.js +31 -8
  54. package/core/events.generated.js +12 -7
  55. package/core/gameLights.js +62 -0
  56. package/core/grayMap.js +20 -0
  57. package/core/grid.js +14 -13
  58. package/core/gridLoad.js +2 -1
  59. package/core/ground.js +6 -4
  60. package/core/headlessLoad.js +55 -0
  61. package/core/holds.js +78 -50
  62. package/core/inputContext.js +11 -7
  63. package/core/inputDefaults.js +24 -21
  64. package/core/inputPad.js +1 -1
  65. package/core/inputPointer.js +1 -1
  66. package/core/inputTouch.js +2 -2
  67. package/core/lifecycle.js +48 -12
  68. package/core/lightWatch.js +6 -4
  69. package/core/look/coreParts.js +137 -30
  70. package/core/look/part.js +175 -95
  71. package/core/look/points.js +255 -0
  72. package/core/look/report.js +34 -17
  73. package/core/look/shadowPart.js +63 -0
  74. package/core/look/state.js +45 -0
  75. package/core/look/write.js +12 -28
  76. package/core/loop.js +100 -41
  77. package/core/math.js +11 -3
  78. package/core/moduleSlots.js +75 -0
  79. package/core/moduleTypes.js +73 -0
  80. package/core/modules.js +145 -27
  81. package/core/movement.js +2 -2
  82. package/core/namedModel.js +70 -0
  83. package/core/opsCheck.js +3 -3
  84. package/core/opsFail.js +15 -6
  85. package/core/opsGuard.js +4 -4
  86. package/core/opsRun.js +4 -3
  87. package/core/owned.js +168 -0
  88. package/core/page.js +2 -1
  89. package/core/params.js +30 -8
  90. package/core/plugins.js +277 -0
  91. package/core/saveApply.js +99 -17
  92. package/core/saveFiles.js +8 -6
  93. package/core/saveValues.js +46 -0
  94. package/core/saveVersions.js +20 -3
  95. package/core/scatter.js +48 -19
  96. package/core/sceneDelta.js +203 -0
  97. package/core/sceneMethods.js +35 -30
  98. package/core/screenToGround.js +1 -1
  99. package/core/services.js +27 -11
  100. package/core/session.js +28 -25
  101. package/core/shaderCost.js +78 -0
  102. package/core/shadowTypes.js +2 -1
  103. package/core/sharedPoint.js +317 -0
  104. package/core/skip.js +36 -28
  105. package/core/stackFrames.js +34 -0
  106. package/core/stacks.js +166 -0
  107. package/core/startup.js +153 -11
  108. package/core/streamSources.js +0 -11
  109. package/core/styleParts.js +63 -47
  110. package/core/targeting.js +1 -1
  111. package/core/textureBytes.js +20 -0
  112. package/core/thingExplain.js +2 -2
  113. package/core/thingOps.js +29 -6
  114. package/core/things.js +21 -11
  115. package/core/threadPure.js +7 -3
  116. package/core/threePatches.js +47 -0
  117. package/core/tier.js +21 -10
  118. package/core/time.js +236 -0
  119. package/core/uiClock.js +25 -0
  120. package/core/util.js +7 -1
  121. package/core/validate.js +65 -86
  122. package/core/wrap.js +106 -0
  123. package/docs/AI.md +87 -100
  124. package/docs/API.md +32 -28
  125. package/docs/CODEMAP.md +220 -147
  126. package/docs/COMMANDS.md +56 -35
  127. package/docs/CONVENTIONS.md +90 -28
  128. package/docs/MIGRATING-0.3.md +248 -0
  129. package/docs/MIGRATING-0.4.md +228 -0
  130. package/docs/MIGRATING-0.5.md +68 -0
  131. package/docs/PERF.md +35 -7
  132. package/docs/THREE.md +79 -27
  133. package/docs/api/ambience.md +0 -1
  134. package/docs/api/assets.md +11 -9
  135. package/docs/api/audio.md +10 -14
  136. package/docs/api/calendar.md +41 -0
  137. package/docs/api/cameraRig.md +16 -5
  138. package/docs/api/characters.md +38 -23
  139. package/docs/api/clock.md +6 -5
  140. package/docs/api/collision.md +9 -6
  141. package/docs/api/content.md +6 -4
  142. package/docs/api/dialogue.md +9 -9
  143. package/docs/api/engine.md +63 -60
  144. package/docs/api/events.md +19 -14
  145. package/docs/api/grids.md +3 -3
  146. package/docs/api/ground.md +1 -1
  147. package/docs/api/hud.md +2 -2
  148. package/docs/api/i18n.md +1 -1
  149. package/docs/api/input.md +11 -6
  150. package/docs/api/interactions.md +7 -5
  151. package/docs/api/inventory.md +17 -16
  152. package/docs/api/level.md +0 -1
  153. package/docs/api/lightPool.md +3 -1
  154. package/docs/api/music.md +1 -1
  155. package/docs/api/nav.md +3 -0
  156. package/docs/api/openWorld.md +2 -1
  157. package/docs/api/particles.md +2 -2
  158. package/docs/api/photo.md +0 -2
  159. package/docs/api/pickups.md +15 -0
  160. package/docs/api/post.md +5 -4
  161. package/docs/api/quests.md +2 -3
  162. package/docs/api/rigid.md +16 -14
  163. package/docs/api/saves.md +6 -4
  164. package/docs/api/settings.md +2 -3
  165. package/docs/api/sky.md +11 -44
  166. package/docs/api/stream.md +1 -1
  167. package/docs/api/style.md +28 -26
  168. package/docs/api/terrain.md +9 -6
  169. package/docs/api/terrainLook.md +10 -0
  170. package/docs/api/timeline.md +3 -4
  171. package/docs/api/tools.md +29 -13
  172. package/docs/api/triggers.md +5 -10
  173. package/docs/api/vegetation.md +11 -8
  174. package/docs/api/vegetationLook.md +10 -0
  175. package/docs/api/water.md +4 -20
  176. package/docs/api/weather.md +5 -15
  177. package/docs/api/weatherLook.md +10 -0
  178. package/docs/api/world.md +2 -1
  179. package/docs/recipes/01-new-game.md +48 -34
  180. package/docs/recipes/02-npc.md +24 -7
  181. package/docs/recipes/03-items-pickups.md +35 -21
  182. package/docs/recipes/04-quests.md +12 -5
  183. package/docs/recipes/05-props-bake.md +151 -15
  184. package/docs/recipes/06-clock-events.md +100 -52
  185. package/docs/recipes/07-flow-scenes-pause.md +40 -9
  186. package/docs/recipes/08-weather-sky.md +145 -36
  187. package/docs/recipes/{09-style-pack.md → 09-style.md} +101 -52
  188. package/docs/recipes/10-blender-level.md +14 -2
  189. package/docs/recipes/11-vehicles.md +64 -7
  190. package/docs/recipes/13-animation.md +14 -6
  191. package/docs/recipes/14-custom-module.md +61 -29
  192. package/docs/recipes/15-perf.md +30 -9
  193. package/docs/recipes/16-dev-bridge.md +61 -37
  194. package/docs/recipes/18-world.md +16 -6
  195. package/docs/recipes/19-shooting-picking.md +6 -6
  196. package/docs/recipes/20-content-actions-save.md +55 -17
  197. package/docs/recipes/21-camera.md +49 -16
  198. package/docs/recipes/22-shop-gold.md +3 -3
  199. package/docs/recipes/23-ops.md +16 -10
  200. package/docs/recipes/26-ui-parts.md +61 -12
  201. package/docs/recipes/27-net.md +11 -5
  202. package/docs/recipes/28-terrain.md +34 -1
  203. package/docs/recipes/29-grid.md +34 -16
  204. package/docs/recipes/30-templates.md +64 -12
  205. package/docs/recipes/31-audio.md +20 -12
  206. package/docs/recipes/32-action-game.md +35 -2
  207. package/docs/recipes/34-environment-lighting.md +26 -3
  208. package/docs/recipes/35-style-from-reference.md +88 -19
  209. package/docs/recipes/36-sky-ground-plant-looks.md +18 -18
  210. package/docs/recipes/37-terrain-look-hooks.md +3 -2
  211. package/docs/recipes/38-environment-look-hooks.md +37 -26
  212. package/docs/recipes/40-scene.md +16 -13
  213. package/docs/recipes/41-thing-registry.md +11 -7
  214. package/docs/recipes/42-terrain-shape.md +2 -2
  215. package/docs/recipes/43-shader-patches-surface-looks.md +158 -76
  216. package/docs/recipes/44-water-weather-look-hooks.md +26 -17
  217. package/docs/recipes/45-cascaded-shadows.md +16 -7
  218. package/docs/recipes/47-island-snow-backdrop.md +7 -7
  219. package/docs/recipes/48-make-material.md +11 -6
  220. package/docs/recipes/49-game-module-contract.md +30 -17
  221. package/docs/recipes/50-own-renderer.md +2 -2
  222. package/docs/recipes/51-capability-catalog.md +3 -3
  223. package/docs/recipes/52-look.md +197 -61
  224. package/docs/recipes/53-ground-up-close.md +1 -1
  225. package/docs/recipes/54-three-idioms.md +88 -0
  226. package/docs/recipes/55-mods-time-wrap.md +112 -0
  227. package/docs/recipes/56-webgpu-tsl.md +260 -0
  228. package/docs/recipes/57-control.md +65 -0
  229. package/docs/recipes/58-input.md +57 -0
  230. package/docs/recipes/59-depth-post-effects.md +83 -0
  231. package/docs/recipes/60-judge-the-picture.md +55 -0
  232. package/examples/action/.threedog/content-index.json +1 -0
  233. package/examples/action/GAMEMAP.md +17 -13
  234. package/examples/action/assets.js +8 -0
  235. package/examples/action/content/actions.js +1 -1
  236. package/examples/action/content/audio.js +5 -5
  237. package/examples/action/look.js +1 -1
  238. package/examples/action/main.js +10 -14
  239. package/examples/action/models.js +24 -23
  240. package/examples/pullable.json +111 -0
  241. package/examples/rc2d/.threedog/content-index.json +1 -0
  242. package/examples/rc2d/GAMEMAP.md +83 -0
  243. package/examples/rc2d/README.md +52 -0
  244. package/examples/rc2d/main.js +63 -0
  245. package/examples/rc2d/rc2d.js +197 -0
  246. package/examples/rc2d/shaders.js +144 -0
  247. package/examples/sheepisland/.threedog/content-index.json +1 -0
  248. package/examples/sheepisland/GAMEMAP.md +13 -11
  249. package/examples/sheepisland/assets.js +5 -0
  250. package/examples/sheepisland/main.js +17 -12
  251. package/examples/sheepisland/style/index.js +6 -6
  252. package/examples/styletest/.threedog/content-index.json +1 -0
  253. package/examples/styletest/GAMEMAP.md +15 -16
  254. package/examples/styletest/assets.js +6 -0
  255. package/examples/styletest/content/templates.js +1 -1
  256. package/examples/styletest/content/vegetation.js +1 -1
  257. package/examples/styletest/look.js +1 -1
  258. package/examples/styletest/main.js +17 -16
  259. package/examples/styletest/models.js +1 -1
  260. package/examples/styletest/params.js +3 -3
  261. package/examples/techniques/contact-shadows/README.md +92 -0
  262. package/examples/techniques/contact-shadows/contactShadows.js +51 -0
  263. package/examples/techniques/contact-shadows/main.js +53 -0
  264. package/examples/techniques/day-night-grade/README.md +86 -0
  265. package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
  266. package/examples/techniques/day-night-grade/main.js +51 -0
  267. package/examples/techniques/interior-light/README.md +103 -0
  268. package/examples/techniques/interior-light/interiorLight.js +45 -0
  269. package/examples/techniques/interior-light/main.js +124 -0
  270. package/examples/techniques/modular-building/README.md +125 -0
  271. package/examples/techniques/modular-building/kit.js +426 -0
  272. package/examples/techniques/modular-building/main.js +47 -0
  273. package/examples/techniques/night-lights/README.md +94 -0
  274. package/examples/techniques/night-lights/main.js +70 -0
  275. package/examples/techniques/night-lights/nightLights.js +91 -0
  276. package/examples/techniques/outlines-and-rim/README.md +59 -0
  277. package/examples/techniques/outlines-and-rim/main.js +84 -0
  278. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  279. package/examples/techniques/procedural-animation/README.md +77 -0
  280. package/examples/techniques/procedural-animation/creature.js +44 -0
  281. package/examples/techniques/procedural-animation/main.js +45 -0
  282. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  283. package/examples/techniques/procedural-surface/README.md +67 -0
  284. package/examples/techniques/procedural-surface/main.js +103 -0
  285. package/examples/techniques/procedural-surface/surface.js +120 -0
  286. package/examples/techniques/stylized-shading/README.md +75 -0
  287. package/examples/techniques/stylized-shading/main.js +93 -0
  288. package/examples/techniques/stylized-shading/shading.js +131 -0
  289. package/examples/techniques/sun-and-key-light/README.md +135 -0
  290. package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
  291. package/examples/techniques/sun-and-key-light/main.js +95 -0
  292. package/examples/techniques/wet-road/README.md +99 -0
  293. package/examples/techniques/wet-road/main.js +68 -0
  294. package/examples/techniques/wet-road/wetRoad.js +209 -0
  295. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  296. package/examples/webgpu-tsl/GAMEMAP.md +84 -0
  297. package/examples/webgpu-tsl/README.md +42 -0
  298. package/examples/webgpu-tsl/main.js +21 -0
  299. package/examples/webgpu-tsl/tslScene.js +75 -0
  300. package/examples/world/.threedog/content-index.json +1 -0
  301. package/examples/world/GAMEMAP.md +22 -15
  302. package/examples/world/art/humanoid.js +42 -0
  303. package/examples/world/art/index.js +11 -0
  304. package/examples/world/art/models.js +58 -0
  305. package/examples/world/art/shapes.js +9 -0
  306. package/examples/world/assets.js +6 -0
  307. package/examples/world/content/audio.js +5 -5
  308. package/examples/world/content/npcs.js +1 -1
  309. package/examples/world/content/props.js +1 -1
  310. package/examples/world/content/rules.js +1 -1
  311. package/examples/world/content/templates.js +1 -1
  312. package/examples/world/content/vegetation.js +1 -1
  313. package/examples/world/main.js +17 -13
  314. package/examples/world/style/index.js +61 -0
  315. package/examples/world/style/plugins/10-bloom.js +5 -0
  316. package/index.d.ts +44 -45
  317. package/index.js +26 -22
  318. package/llms.txt +11 -4
  319. package/modules/ambience/Ambience.js +34 -23
  320. package/modules/calendar/Calendar.js +163 -0
  321. package/modules/calendar/contract.js +21 -0
  322. package/modules/calendar/index.js +81 -0
  323. package/modules/{sky → calendar}/schedule.js +17 -16
  324. package/modules/calendar/seasons.js +55 -0
  325. package/modules/camera/FirstPersonCamera.js +6 -15
  326. package/modules/camera/FixedCamera.js +33 -15
  327. package/modules/camera/FollowCamera.js +90 -16
  328. package/modules/camera/RtsCamera.js +18 -17
  329. package/modules/camera/common.js +70 -19
  330. package/modules/camera/contract.js +17 -0
  331. package/modules/camera/projection.js +11 -24
  332. package/modules/characters/Character.js +177 -42
  333. package/modules/characters/NPC.js +87 -36
  334. package/modules/characters/assetModel.js +4 -13
  335. package/modules/characters/behaviors.js +2 -1
  336. package/modules/characters/contract.js +13 -0
  337. package/modules/characters/footsteps.js +1 -1
  338. package/modules/characters/index.js +87 -49
  339. package/modules/characters/moveHelpers.js +4 -5
  340. package/modules/characters/movers/common.js +97 -19
  341. package/modules/characters/movers/manual.js +20 -0
  342. package/modules/characters/movers/rapier.js +19 -16
  343. package/modules/characters/movers/simple.js +14 -11
  344. package/modules/characters/movers/support.js +172 -0
  345. package/modules/characters/npcAvoid.js +47 -42
  346. package/modules/characters/npcSim.js +12 -8
  347. package/modules/characters/npcView.js +44 -16
  348. package/modules/characters/pathAsync.js +7 -3
  349. package/modules/characters/playerStrings.js +4 -3
  350. package/modules/characters/proceduralRig.js +2 -1
  351. package/modules/characters/useModel.js +1 -1
  352. package/modules/characters/vehicle.contract.js +21 -0
  353. package/modules/characters/walkTo.js +21 -7
  354. package/modules/collision/Collision.js +65 -25
  355. package/modules/collision/grid.js +8 -6
  356. package/modules/content/explain.js +2 -2
  357. package/modules/content/fields.js +102 -0
  358. package/modules/content/ids.js +8 -6
  359. package/modules/content/index.js +96 -27
  360. package/modules/content/loader.js +45 -33
  361. package/modules/content/models.js +11 -40
  362. package/modules/content/packs.js +6 -5
  363. package/modules/content/parts.js +41 -0
  364. package/modules/content/props.js +16 -9
  365. package/modules/content/rules.js +58 -0
  366. package/modules/content/stages.js +80 -0
  367. package/modules/content/templates.js +121 -30
  368. package/modules/debug/DebugPanel.js +24 -17
  369. package/modules/flow/contract.js +16 -0
  370. package/modules/flow/index.js +21 -15
  371. package/modules/gameplay/Container.js +41 -32
  372. package/modules/gameplay/Containers.js +30 -15
  373. package/modules/gameplay/Dialogue.js +113 -55
  374. package/modules/gameplay/Interactions.js +193 -67
  375. package/modules/gameplay/Inventory.js +69 -73
  376. package/modules/gameplay/Quests.js +75 -39
  377. package/modules/gameplay/boxOps.js +3 -3
  378. package/modules/gameplay/dialogue.contract.js +21 -0
  379. package/modules/gameplay/dialogueBox.js +4 -2
  380. package/modules/gameplay/dialogueBubbles.js +116 -0
  381. package/modules/gameplay/interactionPrompt.js +4 -1
  382. package/modules/gameplay/interactions.contract.js +16 -0
  383. package/modules/gameplay/inventory.contract.js +23 -0
  384. package/modules/gameplay/inventoryOps.js +18 -16
  385. package/modules/gameplay/pickups.js +268 -85
  386. package/modules/gameplay/questLog.js +4 -4
  387. package/modules/gameplay/quests.contract.js +17 -0
  388. package/modules/grid/Grid.js +92 -50
  389. package/modules/grid/Layer.js +14 -13
  390. package/modules/grid/index.js +60 -36
  391. package/modules/grid/ops.js +20 -18
  392. package/modules/grid/preview.js +15 -16
  393. package/modules/grid/strings.js +12 -0
  394. package/modules/grid/tiles.js +6 -5
  395. package/modules/hlod/index.js +51 -19
  396. package/modules/hud/index.js +35 -20
  397. package/modules/hud/parts.js +20 -7
  398. package/modules/level/heightfield.js +3 -1
  399. package/modules/level/index.js +45 -20
  400. package/modules/level/nodes.js +4 -3
  401. package/modules/lights/index.js +42 -18
  402. package/modules/music/Music.js +38 -21
  403. package/modules/music/rules.js +1 -1
  404. package/modules/nav/index.js +48 -42
  405. package/modules/net/Client.js +13 -6
  406. package/modules/net/Host.js +19 -5
  407. package/modules/net/Net.js +2 -1
  408. package/modules/net/index.js +13 -8
  409. package/modules/net/sync.js +9 -8
  410. package/modules/net/transports.js +77 -27
  411. package/modules/particles/Particles.js +23 -14
  412. package/modules/particles/contract.js +17 -0
  413. package/modules/particles/effect.js +39 -11
  414. package/modules/photo/Photo.js +53 -36
  415. package/modules/rigid/RigidBodies.js +194 -32
  416. package/modules/rigid/Vehicles.js +18 -15
  417. package/modules/rigid/sync.js +62 -17
  418. package/modules/settings/Settings.js +57 -52
  419. package/modules/settings/apply.js +38 -3
  420. package/modules/settings/sections.js +5 -3
  421. package/modules/settings/strings.js +3 -2
  422. package/modules/settings/view.js +5 -3
  423. package/modules/sky/Sky.js +88 -176
  424. package/modules/sky/cascades.js +86 -25
  425. package/modules/sky/cascades.tsl.js +82 -0
  426. package/modules/sky/clouds.js +34 -19
  427. package/modules/sky/domeLayers.js +30 -15
  428. package/modules/sky/environment.js +83 -13
  429. package/modules/sky/fog.js +140 -95
  430. package/modules/sky/frame.js +112 -44
  431. package/modules/sky/look.js +22 -19
  432. package/modules/sky/lookFog.js +48 -52
  433. package/modules/sky/lookShadow.js +53 -41
  434. package/modules/sky/lookSky.js +82 -21
  435. package/modules/sky/season.js +21 -0
  436. package/modules/sky/shader.js +41 -19
  437. package/modules/sky/shadow.js +44 -20
  438. package/modules/sky/skyModule.js +45 -33
  439. package/modules/sky/tint.js +61 -0
  440. package/modules/terrain/ChunkManager.js +175 -108
  441. package/modules/terrain/chunkJob.js +1 -1
  442. package/modules/terrain/chunkQueries.js +6 -4
  443. package/modules/terrain/index.js +105 -50
  444. package/modules/terrain/look.js +83 -0
  445. package/modules/terrain/lookGround.js +21 -16
  446. package/modules/terrain/terrainDefaults.js +1 -1
  447. package/modules/terrain/terrainEdit.js +18 -20
  448. package/modules/terrain/terrainGen.js +5 -3
  449. package/modules/terrain/terrainIsland.js +5 -4
  450. package/modules/terrain/terrainShape.js +12 -12
  451. package/modules/terrain/terrainShapeMain.js +8 -7
  452. package/modules/terrain/terrainTexture.js +21 -19
  453. package/modules/timeline/Timeline.js +95 -43
  454. package/modules/timeline/Tween.js +18 -10
  455. package/modules/timeline/letterbox.js +2 -2
  456. package/modules/timeline/shots.js +5 -1
  457. package/modules/triggers/index.js +107 -76
  458. package/modules/vegetation/Vegetation.js +186 -110
  459. package/modules/vegetation/densityMap.js +62 -0
  460. package/modules/vegetation/groundChunks.js +52 -58
  461. package/modules/vegetation/index.js +32 -11
  462. package/modules/vegetation/look.js +119 -0
  463. package/modules/vegetation/lookWind.js +71 -10
  464. package/modules/vegetation/modelGeometry.js +3 -2
  465. package/modules/vegetation/nearFade.js +8 -2
  466. package/modules/water/Water.js +65 -27
  467. package/modules/water/look.js +29 -18
  468. package/modules/water/surface.js +64 -25
  469. package/modules/water/surfaceDefaults.js +3 -0
  470. package/modules/weather/Weather.js +62 -104
  471. package/modules/weather/look.js +1 -2
  472. package/modules/weather/particles.js +24 -9
  473. package/modules/weather/strings.js +2 -2
  474. package/modules/weather/weatherLook.js +135 -0
  475. package/modules/world/World.js +24 -7
  476. package/modules/world/explain.js +1 -1
  477. package/modules/world/index.js +18 -4
  478. package/modules/world/persist.js +62 -2
  479. package/modules/world/pos.js +3 -2
  480. package/modules/world/records.js +8 -6
  481. package/modules/world/sim.js +60 -20
  482. package/modules/world/simFar.js +4 -3
  483. package/modules/world/state.js +3 -2
  484. package/modules/world/thingSource.js +1 -1
  485. package/modules/world/views.js +7 -5
  486. package/package.json +7 -3
  487. package/presets.js +41 -27
  488. package/render/PostFX.js +145 -120
  489. package/render/backend.js +440 -0
  490. package/render/detail.js +120 -39
  491. package/render/effects.js +130 -38
  492. package/render/engineUniforms.js +10 -1
  493. package/render/fuse.js +5 -4
  494. package/render/fx/cloudShadow.tsl.js +16 -0
  495. package/render/fx/detail.tsl.js +66 -0
  496. package/render/fx/index.js +26 -0
  497. package/render/fx/lighting.tsl.js +28 -0
  498. package/render/fx/nodeErrors.tsl.js +68 -0
  499. package/render/fx/noise.tsl.js +12 -0
  500. package/render/fx/objectOrigin.tsl.js +42 -0
  501. package/render/fx/particles.tsl.js +139 -0
  502. package/render/fx/patchNodes.tsl.js +403 -0
  503. package/render/fx/postWebGPU.tsl.js +158 -0
  504. package/render/fx/season.tsl.js +13 -0
  505. package/render/fx/sky.tsl.js +260 -0
  506. package/render/fx/uniforms.tsl.js +67 -0
  507. package/render/fx/water.tsl.js +53 -0
  508. package/render/fx/wind.tsl.js +22 -0
  509. package/render/fxNumbers.js +36 -0
  510. package/render/hotGlsl.js +24 -0
  511. package/render/lighting.js +66 -14
  512. package/render/lights.js +223 -4
  513. package/render/lookGlow.js +139 -0
  514. package/render/lookSurface.js +99 -36
  515. package/render/materials.js +71 -52
  516. package/render/modeling.js +73 -0
  517. package/render/ownFrame.js +76 -0
  518. package/render/patches.js +311 -34
  519. package/render/postLook.js +124 -46
  520. package/render/postWebGL.js +197 -0
  521. package/render/probes.js +231 -0
  522. package/render/shaderErrors.js +154 -0
  523. package/render/slots.js +165 -0
  524. package/render/surface.js +53 -17
  525. package/render/terms.js +211 -0
  526. package/render/uniformDecl.js +3 -2
  527. package/types/common.d.ts +2 -2
  528. package/types/core.d.ts +614 -240
  529. package/types/gameplay.d.ts +482 -312
  530. package/types/generated/core/Audio.d.ts +26 -42
  531. package/types/generated/core/Batching.d.ts +6 -2
  532. package/types/generated/core/Budget.d.ts +2 -8
  533. package/types/generated/core/DebugOverrides.d.ts +44 -3
  534. package/types/generated/core/I18n.d.ts +2 -2
  535. package/types/generated/core/Input.d.ts +102 -31
  536. package/types/generated/core/Ops.d.ts +31 -0
  537. package/types/generated/core/Random.d.ts +2 -2
  538. package/types/generated/core/Saves.d.ts +10 -2
  539. package/types/generated/core/Stream.d.ts +1 -1
  540. package/types/generated/core/Threads.d.ts +4 -1
  541. package/types/generated/core/Views.d.ts +0 -1
  542. package/types/generated/core/audioVoice.d.ts +17 -9
  543. package/types/generated/core/control.d.ts +55 -0
  544. package/types/generated/core/session.d.ts +2 -1
  545. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  546. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  547. package/types/generated/modules/calendar/index.d.ts +10 -0
  548. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  549. package/types/generated/modules/grid/Grid.d.ts +61 -25
  550. package/types/generated/modules/grid/Layer.d.ts +5 -5
  551. package/types/generated/modules/grid/index.d.ts +29 -17
  552. package/types/generated/modules/music/Music.d.ts +5 -3
  553. package/types/generated/modules/net/index.d.ts +3 -3
  554. package/types/generated/modules/net/transports.d.ts +12 -3
  555. package/types/generated/modules/particles/Particles.d.ts +1 -1
  556. package/types/generated/modules/sky/Sky.d.ts +12 -104
  557. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  558. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  559. package/types/generated/modules/weather/Weather.d.ts +17 -18
  560. package/types/generated/modules/weather/weatherLook.d.ts +12 -0
  561. package/types/generated/modules/world/World.d.ts +18 -3
  562. package/types/generated/render/PostFX.d.ts +67 -30
  563. package/types/generated/render/materials.d.ts +26 -20
  564. package/types/generated/render/modeling.d.ts +30 -0
  565. package/types/generated/render/patches.d.ts +16 -2
  566. package/types/generated/ui/UI.d.ts +6 -3
  567. package/types/nav.d.ts +6 -0
  568. package/types/physics.d.ts +137 -44
  569. package/types/style.d.ts +109 -81
  570. package/types/tsl.d.ts +86 -0
  571. package/types/world.d.ts +158 -110
  572. package/ui/Focus.js +25 -14
  573. package/ui/LoadingScreen.js +1 -1
  574. package/ui/Parts.js +27 -11
  575. package/ui/UI.js +20 -10
  576. package/ui/cursor.js +115 -0
  577. package/ui/defaults.js +15 -11
  578. package/ui/theme.js +9 -6
  579. package/ui/touchPart.js +1 -1
  580. package/core/claims.js +0 -51
  581. package/core/look/layers.js +0 -136
  582. package/core/renamed.js +0 -22
  583. package/docs/api/entities.md +0 -61
  584. package/examples/styletest/overrides.js +0 -33
  585. package/examples/styletest/panel.js +0 -135
  586. package/modules/entities/Entities.js +0 -243
  587. package/modules/entities/build.js +0 -25
  588. package/modules/entities/index.js +0 -4
  589. package/modules/sky/calendar.js +0 -80
  590. package/modules/sky/layers.js +0 -69
  591. package/modules/terrain/chunkLevels.js +0 -40
  592. package/modules/terrain/mountTerrain.js +0 -32
  593. package/modules/world/cells.js +0 -42
@@ -1,19 +1,19 @@
1
- // Gameplay modules: timeline, level, triggers, entities, world changes, particles, settings, music, characters/NPCs, interactions, dialogue, inventory,
1
+ // Gameplay modules: timeline, level, triggers, world changes, particles, settings, music, characters/NPCs, interactions, dialogue, inventory,
2
2
  // quests, photo mode, ambience, debug.
3
3
  import type { Object3D, Vector3, Vector2, Quaternion, Texture, ColorLike, Vec3Like, Ease, Handle, Range, XZ, Loose, PositionLike } from './common';
4
4
  import type { Engine } from './core';
5
5
  import type { Input } from './generated/core/Input';
6
- import type { Animator, AnimatorOptions, Vehicle } from './physics';
6
+ import type { Animator, AnimatorOptions, Rideable } from './physics';
7
7
  import type { WorldRecord } from './generated/modules/world/World';
8
8
 
9
9
  // ======================================================================
10
10
  // Timeline timeline()
11
11
  // ======================================================================
12
12
 
13
- /** Promise of a tween: await it to wait for the end; finish() jumps to the end now, cancel() stops at the current position */
13
+ /** Promise of a tween: await it to wait for the end; finish() jumps to the end now, remove() stops at the current position */
14
14
  export interface TweenPromise extends Promise<boolean> {
15
15
  finish(): void;
16
- cancel(): void;
16
+ remove(): void;
17
17
  task: any;
18
18
  }
19
19
  /** Tween target: 'dotted.path' -> target value. E.g. { 'position.y': 3, 'material.color': 0xffffff, scale: [2, 2, 2] }; a value can also be () => value */
@@ -60,20 +60,19 @@ export interface TimelinePlayOptions {
60
60
  skippable?: boolean;
61
61
  /** Letterbox bars, default false */
62
62
  letterbox?: boolean;
63
- /** Lock player input while playing, default true */
64
- lockInput?: boolean;
63
+ /**
64
+ * The characters the cutscene drives (their control slot on layer 'cutscene'; keys / walks / NPC behaviours pause and come back after).
65
+ * Default: [engine.player] when there is a player; [] drives nobody (a bubble scene the player walks through). A path step adds its character
66
+ */
67
+ actors?: any[];
65
68
  }
66
69
 
67
70
  // Timeline (engine.timeline) is generated from the JSDoc in modules/timeline/Timeline.js (npm run map); only the type is re-exported here
68
71
  import type { Timeline } from './generated/modules/timeline/Timeline';
69
72
  export type { Timeline };
70
- export interface TimelineOptions {
71
- /**
72
- * Keys that skip a cutscene, default ['Escape', 'Backspace'] (Esc is the back key, which the UI focus stack hands to the topmost cutscene; cutscenes
73
- * do not advance while frozen)
74
- */
75
- skipKeys?: string[];
76
- }
73
+ /** timeline() takes no options: the basic cancel key skips (the UI focus stack hands it to the topmost cutscene); bind the action 'skip'
74
+ * (context 'cutscene') for another key, e.g. createEngine({ bindings: { ...presets.bindings.cutsceneSkip } }) */
75
+ export interface TimelineOptions {}
77
76
 
78
77
  // ======================================================================
79
78
  // Level level()
@@ -121,8 +120,6 @@ export interface Level {
121
120
  spawn: Vector3;
122
121
  /** Heightfield (for debugging) */
123
122
  heightfield: any;
124
- /** Milliseconds spent building the heightfield */
125
- buildMs?: number;
126
123
  /** Whether loading is finished */
127
124
  readonly ready: boolean;
128
125
  /** Get a marker, null if none */
@@ -162,20 +159,26 @@ export interface TriggerOptions {
162
159
  height?: number;
163
160
  /** Box rotation around the Y axis (radians) */
164
161
  rotation?: number;
165
- /** Called on entering; who is the position that entered */
166
- onEnter?: ((t: Trigger, who: Vector3) => void) | null;
167
- /** Called on leaving */
168
- onExit?: ((t: Trigger, who: Vector3 | null) => void) | null;
162
+ /**
163
+ * Called on entering; who is the position that entered, id the world record id of who it is (engine.actor for the default who, an id given in who,
164
+ * object.userData.id, null for a bare position)
165
+ */
166
+ onEnter?: ((t: Trigger, who: Vector3, id: string | null) => void) | null;
167
+ /** Called on leaving; id = who was inside */
168
+ onExit?: ((t: Trigger, who: Vector3 | null, id: string | null) => void) | null;
169
169
  /** Called every fixed step while inside (dt in seconds) */
170
- onStay?: ((dt: number, t: Trigger, who: Vector3) => void) | null;
170
+ onStay?: ((dt: number, t: Trigger, who: Vector3, id: string | null) => void) | null;
171
171
  /** Fire on the first enter only (exit follows at once); the zone stays with used = true, and a new playthrough (engine.session) re-arms it */
172
172
  once?: boolean;
173
173
  /** false pauses detection */
174
174
  enabled?: boolean;
175
175
  /** Name (carried in events) */
176
176
  tag?: string;
177
- /** Who can trigger it: the player by default; or a position, an object (its position is used), or a function returning an array of positions */
178
- who?: Vector3 | Object3D | { x: number; y: number; z: number } | (() => Array<{ x: number; y: number; z: number }>) | null;
177
+ /**
178
+ * Who can trigger it: engine.actor by default; or an actor id, a position, an object (its position is used), or a function returning an array of those
179
+ * (several actors: () => [e.actor, ...e.net.peers.map(p => p.actor)])
180
+ */
181
+ who?: string | Vector3 | Object3D | { x: number; y: number; z: number } | (() => Array<string | Object3D | { x: number; y: number; z: number }>) | null;
179
182
  /** Seconds after leaving during which entering does not fire again, default 0 */
180
183
  cooldown?: number;
181
184
  /** Custom data */
@@ -205,22 +208,17 @@ export interface Trigger {
205
208
  /** Whether a point is inside */
206
209
  contains(p: { x: number; y: number; z: number }): boolean;
207
210
  }
208
- export interface TriggerEvent { tag: string; trigger: Trigger; who: Vector3 | null }
211
+ /** id = world record id of who entered / left (null for a bare position) */
212
+ export interface TriggerEvent { tag: string; trigger: Trigger; who: Vector3 | null; id: string | null }
209
213
  export interface TriggersOptions {
210
- /** Show the wireframes from the start */
211
- debug?: boolean;
212
- /** Action name that toggles the wireframes, default 'triggersDebug' */
214
+ /** Action name that toggles the debug view 'triggers' (engine.debug.view), default 'triggersDebug' */
213
215
  action?: string;
214
- /** Key that toggles the wireframes: default ['F4'] in dev builds, none in release builds */
215
- keys?: string[];
216
216
  }
217
217
 
218
218
  /** engine.triggers */
219
219
  export interface Triggers {
220
220
  /** All trigger zones (a new array) */
221
221
  list(): Trigger[];
222
- /** Whether wireframes are shown */
223
- debug: boolean;
224
222
  action: string;
225
223
  /** Add a trigger zone */
226
224
  add(opts?: TriggerOptions): Trigger;
@@ -230,129 +228,13 @@ export interface Triggers {
230
228
  byTag(tag: string): Trigger[];
231
229
  /** Every trigger_xxx marker in the level becomes a trigger zone with tag xxx; opts is shared by all of them */
232
230
  fromMarkers(opts?: TriggerOptions): Trigger[];
233
- /** Show / hide the wireframes */
234
- setDebug(on: boolean): void;
235
- }
236
-
237
- // ======================================================================
238
- // Entities entities()
239
- // ======================================================================
240
-
241
- /** Growth stage */
242
- export interface EntityStage {
243
- /** Stage name, e.g. 'seed' */
244
- name: string;
245
- /** How many game seconds to stay in this stage (leave out on the last one = stay here forever) */
246
- duration?: number;
247
- /** Model size multiplier */
248
- scale?: number;
249
- /** Swap the model */
250
- model?: (engine: Engine, ent: Entity) => Object3D;
251
- }
252
- /** Entity interaction settings (needs the interactions module) */
253
- export interface EntityInteract {
254
- /** Prompt text: an i18n key, plain text, or a function ent => text */
255
- label?: string | ((ent: Entity, engine: Engine) => string);
256
- /** Interaction action name, default 'interact' */
257
- action?: string;
258
- /** How close you must be to interact (meters), default 2.5 */
259
- radius?: number;
260
- /** How high the prompt floats (meters) */
261
- height?: number;
262
- /** Whether it can be interacted with */
263
- enabled?: (ent: Entity, engine: Engine) => boolean;
264
- /** When the interact key is pressed */
265
- onUse?: (ent: Entity, engine: Engine) => void;
266
- }
267
- /** Entity type definition: engine.entities.define('sapling', {...}) */
268
- export interface EntityDef<S = Record<string, any>> {
269
- /** Create the model (required), returns a THREE.Object3D */
270
- create: (engine: Engine, ent: Entity<S>) => Object3D;
271
- /** Default state (merged with the state given at spawn) */
272
- state?: S;
273
- /** Growth stages */
274
- stages?: EntityStage[];
275
- /** Growth stops when this returns false */
276
- canGrow?: (ent: Entity<S>, engine: Engine) => boolean;
277
- /** Called every fixed step (dt in seconds); runs only near the player, far away only growth is caught up */
278
- update?: (dt: number, ent: Entity<S>, engine: Engine) => void;
279
- /** Interaction */
280
- interact?: EntityInteract;
281
- /** Circular collision radius (meters, needs the collision module; follows the model, exists only near the player) */
282
- collider?: number;
283
- /** Collision height (meters), default 3 */
284
- colliderHeight?: number;
285
- /** Cleanup when the model is torn down (called both when walking away and on deletion; don't clear data while the data still exists) */
286
- dispose?: (ent: Entity<S>, engine: Engine) => void;
287
- /** false = not saved (temporary things, cleared on load), default true */
288
- save?: boolean;
289
- }
290
- /** Parameters of spawn() */
291
- export interface EntitySpawnData {
292
- /** Specify the id (generated automatically if omitted) */
293
- id?: string;
294
- /** Position: Vector3 / object / [x, y, z] / { x, z } ({ x, z } without y snaps to the ground), default origin */
295
- position?: PositionLike;
296
- /** Heading (radians) */
297
- rotation?: number;
298
- /** Initial state (merged onto the default state) */
299
- state?: Record<string, any>;
300
- /** Extra data (ent.data, saved) */
301
- extra?: Record<string, any>;
302
- }
303
- /** An entity: x / y / z / rotation / state / data read engine.world data directly (kind is 'entity:<type>'); object / visual exist only near the player */
304
- export interface Entity<S = Record<string, any>> {
305
- id: string;
306
- type: string;
307
- def: EntityDef<S>;
308
- /** Position (meters) */
309
- readonly x: number; readonly z: number; readonly y: number;
310
- readonly rotation: number;
311
- /** State (stage is the current stage index, stageAt the time it was entered); change values with ent.set() so that events fire */
312
- state: S & { stage?: number; stageAt?: number };
313
- /** Root node (heading and interactions hang on it); null when there is no model far away, built the frame after spawn */
314
- readonly object: Object3D | null;
315
- /** Model (a child of the root node) */
316
- readonly visual: Object3D | null;
317
- /** Extra data */
318
- readonly data: Record<string, any>;
319
- /** Change one state value (emits the entity:state event) */
320
- set(key: string, value: any): void;
321
- /** Delete this entity */
322
- remove(): boolean;
323
- /** Current stage name */
324
- readonly stageName: string | null;
325
- }
326
- export interface EntityStateEvent { ent: Entity; key: string; value: any; prev: any }
327
- export interface EntityStageEvent { ent: Entity; stage: number; name: string }
328
-
329
- /** engine.entities */
330
- export interface Entities {
331
- /** Type definitions */
332
- types: Map<string, EntityDef>;
333
- /** Game seconds (= engine.clock.now) */
334
- readonly now: number;
335
- /** Define an entity type */
336
- define<S = Record<string, any>>(type: string, def: EntityDef<S>): this;
337
- /** Spawn an entity (returns null if the type is not defined) */
338
- spawn(type: string, data?: EntitySpawnData): Entity | null;
339
- get(id: string): Entity | null;
340
- byType(type: string): Entity[];
341
- list(): Entity[];
342
- /** The entity nearest to position within radius meters (default 3) (type restricts to one type) */
343
- nearest(position: PositionLike, opts?: { radius?: number; type?: string | null }): Entity | null;
344
- remove(id: string): boolean;
345
- /** Delete all entities */
346
- clear(): void;
347
- /** Jump straight to a growth stage */
348
- setStage(ent: Entity, i: number): void;
349
231
  }
350
232
 
351
233
  // ======================================================================
352
234
  // Particles particles()
353
235
  // ======================================================================
354
236
 
355
- /** Particle effect parameters (style.particles[name] of the style pack uses the same format too). All optional */
237
+ /** Particle effect parameters (style.particles[name] of the style uses the same format too). All optional */
356
238
  export interface ParticleOptions {
357
239
  /** Maximum alive at once, default 120 (halved on low-end devices) */
358
240
  max?: number;
@@ -450,10 +332,8 @@ export interface SettingsSection {
450
332
  order?: number;
451
333
  }
452
334
  export interface SettingsOptions {
453
- /** Action name that opens the menu, default 'menu' */
335
+ /** Action that opens the menu, default the basic 'cancel' (Esc / pad B on an empty UI focus stack); another name is declared and the game binds it */
454
336
  action?: string;
455
- /** Key that opens the menu, default ['Escape'] */
456
- keys?: string[];
457
337
  /** Browser storage key */
458
338
  storageKey?: string;
459
339
  /** Override the graphics presets: { low: {...}, medium: {...}, high: {...} } */
@@ -489,8 +369,10 @@ export interface Settings {
489
369
  set(key: string, value: any, opts?: { save?: boolean }): void;
490
370
  /** Graphics preset: 'low' | 'medium' | 'high' */
491
371
  preset(name: 'low' | 'medium' | 'high' | (string & {})): void;
492
- /** Game-defined setting: default value + apply function (saved automatically) */
493
- define<T = any>(key: string, def: T, apply?: (value: T, e: Engine) => void): this;
372
+ /** Game-defined setting: default value + apply function (saved automatically), or { apply, limits }. limits names the shared value(s) the row
373
+ * 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),
374
+ * 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 */
375
+ define<T = any>(key: string, def: T, apply?: ((value: T, e: Engine) => void) | { apply?: (value: T, e: Engine) => void; limits?: string | string[] }): this;
494
376
  /** Add a tab of your own, or a built-in / optional one by name: addSection('camera') */
495
377
  addSection(id: string, section?: SettingsSection): this;
496
378
  removeSection(id: string): void;
@@ -557,6 +439,10 @@ export interface CharacterRig {
557
439
  joints?: Record<string, Object3D>;
558
440
  limbs?: { joint: Object3D; offset: number; amp: number; kind: 'arm' | 'leg'; side?: number }[];
559
441
  }
442
+ export type CharacterWater = 'swim' | 'block' | 'wade' | ((character: Character, at: { depth: number; x: number; z: number }) => 'swim' | 'block' | 'wade');
443
+ /** What the states hook sees: base is the state the mover chose (idle / walk / run / jump / fall / swim); water the water mode it is in (null on land) */
444
+ export interface CharacterFacts { base: string; speed: number; grounded: boolean; swimming: boolean; vy: number; water: 'swim' | 'block' | 'wade' | null }
445
+ export type CharacterStates = (character: Character, facts: CharacterFacts) => string | null | undefined;
560
446
  /** Character parameters (shared by the player and NPCs) */
561
447
  export interface CharacterOptions {
562
448
  /** Per-character part colors: recolor the body's meshes marked userData.part (a humanoid rig: body, skin, legs, hair); the style tints by material role */
@@ -567,9 +453,18 @@ export interface CharacterOptions {
567
453
  runSpeed?: number;
568
454
  /** Collision radius (meters), default 0.4 */
569
455
  radius?: number;
570
- /** Whether it can swim, default true */
571
- canSwim?: boolean;
572
- /** Water depth (meters) at which swimming starts, default 1 */
456
+ /**
457
+ * What water deeper than swimDepth does: 'swim' (default: floats, state 'swim') | 'block' (never enters it) | 'wade' (walks the bottom) | a function
458
+ * deciding per spot (a swim skill, a boat, depth). character:water fires on each change
459
+ */
460
+ water?: CharacterWater;
461
+ /**
462
+ * The game's own states on top of the built-in ones (crouch, climb, glide, dash, roll): run after the mover's state each step, return a state name
463
+ * or null to keep facts.base. The state picks the clip like any other (clips: { crouch: 'Crouch' }); speed changes stay engine.mod('move.speed')
464
+ * @example createPlayer({ ..., clips: { crouch: 'Crouch' }, states: (c, f) => f.grounded && engine.input.down('crouch') ? 'crouch' : null })
465
+ */
466
+ states?: CharacterStates | null;
467
+ /** Water depth (meters) at which water counts as deep, default 1 */
573
468
  swimDepth?: number;
574
469
  /** Swimming speed multiplier, default 0.45 */
575
470
  swimSpeed?: number;
@@ -587,8 +482,18 @@ export interface CharacterOptions {
587
482
  airControl?: number;
588
483
  /** How long after walking off an edge a jump is still allowed (seconds) */
589
484
  coyoteTime?: number;
590
- /** Whether it can jump, default true */
485
+ /** Whether it can jump, default true (stuns and cutscenes use engine.mod('move.canJump', { owner, id, set: 0 }) instead of writing it) */
591
486
  canJump?: boolean;
487
+ /** Jumps before landing again, default 1; 2 = double jump (jump() again in the air) */
488
+ maxJumps?: number;
489
+ /** Takeoff speed of an air jump (m/s), default jumpSpeed */
490
+ airJumpSpeed?: number;
491
+ /** How long a jump() pressed early waits for the ground (seconds), default 0.12 */
492
+ jumpBuffer?: number;
493
+ /** Falling out of the level: below belowY (or when belowY(character) is true) character:fall fires and, unless a listener calls preventDefault(), it returns to safeGround. false (default) = off */
494
+ fall?: false | { belowY: number | ((character: Character) => boolean) };
495
+ /** Time channel its movement and animation follow when the engine drives it (player default 'player', others 'world') */
496
+ channel?: string;
592
497
  /**
593
498
  * The body, one path for every kind: the name of a registered model asset, or what engine.assets.model() returned. A procedural builder name
594
499
  * (from an asset pack) is built at once; a file model name shows a gray capsule and swaps in a copy when it loads (Character.ready / whenReady,
@@ -599,12 +504,14 @@ export interface CharacterOptions {
599
504
  model?: Object3D | string | null;
600
505
  /** A ready procedural body (CharacterRig), used instead of model (a hand-built guard / pet) */
601
506
  rig?: CharacterRig | null;
507
+ /** Id for engine.mod / time.local entries of a character without a world record (read it back as character.id); the player is 'player', an NPC its record id */
508
+ id?: string;
602
509
  /** Action name mapping { idle, walk, run, swim, jump, fall } (shorthand for animation) */
603
510
  clips?: { idle?: string; walk?: string; run?: string; swim?: string; jump?: string; fall?: string; drive?: string } | null;
604
511
  /** Skeletal animation state machine config (states, blend trees, one-shot actions), see AnimatorOptions */
605
512
  animation?: AnimatorOptions | null;
606
- /** Movement method: 'simple' built into the engine (default) | 'rapier' Rapier character controller (needs the rigid module) */
607
- mover?: 'simple' | 'rapier';
513
+ /** Movement method: 'simple' built into the engine (default) | 'rapier' Rapier character controller (needs the rigid module) | 'manual' the game writes the position, move() only updates grounded / support / safeGround / fall */
514
+ mover?: 'simple' | 'rapier' | 'manual';
608
515
  /**
609
516
  * Which way it turns each move: 'move' (default, toward its velocity) | 'camera' (along cameraRig.forward()) | 'target' (toward faceTarget) | 'manual'
610
517
  * (only face() turns it)
@@ -615,50 +522,45 @@ export interface CharacterOptions {
615
522
  }
616
523
  /** Character facing mode, see CharacterOptions.faceMode */
617
524
  export type FaceMode = 'move' | 'camera' | 'target' | 'manual';
618
- /** What a player control function returns: world direction (length 0–1), run, speed override (m/s); null = stand still */
619
- export type MoveRequest = { x: number; z: number; run?: boolean; speed?: number } | null | undefined;
525
+ /** What a player control function returns: world direction (length 0–1 scales the speed), run; null = stand still. Speed changes: engine.mod('move.speed', { owner, id: 'player', ... }) */
526
+ export type MoveRequest = { x: number; z: number; run?: boolean } | null | undefined;
620
527
  /**
621
- * Who moves the player each fixed step: 'camera' movement keys relative to the camera | 'none' the game calls player.move() itself | function returns
622
- * the move request
528
+ * How the player's input steers it (the base holder of its control slot, owner 'player-input'): 'camera' movement keys relative to the camera |
529
+ * a function returning the move request. The game moving the player itself takes control: engine.control.take(player, { owner, layer: 'script', step })
623
530
  */
624
- export type PlayerControl = 'camera' | 'none' | ((player: Character, input: Input, dt: number) => MoveRequest);
531
+ export type PlayerControl = 'camera' | ((player: Character, input: Input, dt: number) => MoveRequest);
625
532
  /** Parameters of createPlayer() */
626
533
  export interface PlayerOptions extends CharacterOptions {
627
534
  /** Spawn point (meters, { x, z } / Vector3 / object); flat ground is found automatically if omitted */
628
535
  spawn?: PositionLike;
629
- /** Keys of the 'jump' action; none bound when omitted (player.jump() still works). presets.player.* use ['Space', 'PadA'] */
630
- jumpKeys?: string[];
631
- /** Keys of the 'run' action read by control 'camera' / moveInput(); none bound when omitted. presets.player.* use Shift / gamepad LB */
632
- runKeys?: string[];
633
536
  /**
634
- * Required, no default: 'camera' (keys relative to the camera) | 'none' (call player.move() yourself in onFixed) | (player, input, dt) => ({ x, z,
635
- * run?, speed? }). Also the runtime property player.control. presets.player.* fill it
537
+ * Required, no default: 'camera' (keys relative to the camera) | (player, input, dt) => ({ x, z, run? }) (null stands still). presets.player.*
538
+ * fill it. Given once: a game that steers the player for a while takes control (engine.control.take(player, { owner, layer: 'script', step }))
636
539
  */
637
540
  control: PlayerControl;
638
541
  /** true: the camera module follows the player (and back after a vehicle, and on a new session). Omitted with a camera installed warns in dev */
639
542
  cameraFollow?: boolean;
640
543
  }
641
- /** Character state */
642
- export type CharacterState = 'idle' | 'walk' | 'run' | 'swim' | 'jump' | 'fall' | 'drive';
544
+ /** Character state: the engine's own, or any name the game's `states` hook returns (crouch, climb, sit...) */
545
+ export type CharacterState = 'idle' | 'walk' | 'run' | 'swim' | 'jump' | 'fall' | 'drive' | (string & {});
643
546
 
644
547
  /** Character (player and NPCs) */
645
548
  export declare class Character {
646
549
  constructor(engine: Engine, opts?: CharacterOptions);
647
- engine: Engine;
648
550
  /** Root node (this is what gets added to the scene) */
649
551
  root: Object3D;
650
552
  /** Same as root: add children, change visible and scale on it */
651
553
  readonly object: Object3D;
652
554
  /** Position (= root.position) */
653
555
  readonly position: Vector3;
654
- /** Horizontal velocity (x, y map to world x, z) */
556
+ /** Horizontal velocity (x, y map to world x, z). Writable: a write is an impulse the mover steers back toward the input (lasting knockback: push(); full control: mover 'manual') */
655
557
  velocity: Vector2;
656
558
  /**
657
559
  * Heading (radians): 0 faces +Z, forward = (sin facing, cos facing); increasing turns toward +X (rotation about the Y axis, consistent with
658
560
  * root.rotation.y)
659
561
  */
660
562
  facing: number;
661
- /** Vertical velocity (m/s) */
563
+ /** Vertical velocity (m/s). Writable: setting it is an impulse (launch() does the same and also leaves the ground cleanly) */
662
564
  vy: number;
663
565
  /** Whether standing on the ground */
664
566
  grounded: boolean;
@@ -672,20 +574,47 @@ export declare class Character {
672
574
  faceMode: FaceMode;
673
575
  /** What faceMode 'target' faces */
674
576
  faceTarget: PositionLike | null;
675
- /** Player only: who moves it each fixed step (see PlayerOptions.control) */
676
- control?: PlayerControl;
677
577
  /** Player only: whether the camera module follows it (see PlayerOptions.cameraFollow) */
678
578
  cameraFollow?: boolean;
679
579
  /** Move at a fixed velocity (m/s) for seconds, ignoring move()'s direction and without turning (knockback, dodge roll); gravity and collision still apply */
680
580
  push(vx: number, vz: number, seconds: number): void;
681
- speed: number; runSpeed: number; radius: number; canSwim: boolean; swimDepth: number; swimSpeedFactor: number;
581
+ speed: number; runSpeed: number; radius: number; water: CharacterWater; states: CharacterStates | null; swimDepth: number; swimSpeedFactor: number;
682
582
  turnSpeed: number; acceleration: number; gravity: number; jumpSpeed: number; stepHeight: number; airControl: number; coyoteTime: number; canJump: boolean;
583
+ /** Base jump values (the game's; modifiers go through engine.mod('move.jumpSpeed')) */
584
+ maxJumps: number; airJumpSpeed: number | null; jumpBuffer: number;
585
+ /** Fall check (see CharacterOptions.fall); a plain property */
586
+ fall: false | { belowY: number | ((character: Character) => boolean) };
587
+ /** Time channel the engine drives it on (see CharacterOptions.channel) */
588
+ channel: string;
589
+ /** The character's id, the one form engine.mod / time.local take: its world record id ('player', an NPC's record id), else the id option, else a generated one */
590
+ readonly id: string;
591
+ /**
592
+ * A movement stat as the mover uses it now: the base field with every engine.mod('move.<name>') entry applied (canJump reads 1 / 0)
593
+ * @example engine.mod('move.speed', { owner: 'haste', id: 'player', mul: 1.2, for: 5 }); player.stat('speed') // 1.2 x player.speed
594
+ */
595
+ stat(name: 'speed' | 'runSpeed' | 'gravity' | 'jumpSpeed' | 'canJump'): number;
596
+ /** Give back n jumps for this airtime (pickup, wall touch) */
597
+ addJumps(n?: number): this;
598
+ /** All jumps back, as if it had landed */
599
+ resetJumps(): this;
600
+ /**
601
+ * Throw it upward at speed m/s (jump pad, spring): leaves the ground, ends coyote time, the ground jump counts as used (air jumps stay); emits character:launch
602
+ * @example player.launch(19, { owner: 'pad' })
603
+ */
604
+ launch(speed: number, opts?: { owner?: string }): this;
605
+ /** Jump state now, read-only */
606
+ jumpState(): { grounded: boolean; coyoteLeft: number; bufferLeft: number; jumpsUsed: number; jumpsLeft: number; vy: number };
607
+ /** What it stands on, read-only (reused object); 'platform' = a registered support (characters.support), which carries it */
608
+ readonly support: { kind: 'ground' | 'platform' | 'collider' | 'water' | null; object: any; id: string | null; safe: boolean; velocity: { x: number; y: number; z: number } };
609
+ /** Last spot it stood still on safe ground (where a fall returns it); null until it first stands. Saved with the motion */
610
+ safeGround: Vector3 | null;
683
611
  /** Called when a foot lands (the argument is the ground type underfoot) */
684
612
  onStep: ((groundType: string) => void) | null;
685
613
  /** Called on landing (the argument is the landing speed) */
686
614
  onLand: ((impact: number) => void) | null;
687
- /** Movement method; name is 'simple' | 'rapier', controller is the native Rapier character controller (when rapier) */
688
- mover: { name: 'simple' | 'rapier'; controller?: any; body?: any; collider?: any; move(dirX: number, dirZ: number, run: boolean, dt: number, speedOverride?: number): void; dispose?(): void };
615
+ /** How it walks now; name is 'simple' | 'rapier' | 'manual', controller is the native Rapier character controller (when rapier). Assign a name to switch: c.mover = 'manual' */
616
+ get mover(): { name: 'simple' | 'rapier' | 'manual'; controller?: any; body?: any; collider?: any; move(dirX: number, dirZ: number, run: boolean, dt: number): void; dispose?(): void };
617
+ set mover(name: 'simple' | 'rapier' | 'manual');
689
618
  /** Skeletal animation state machine (when there is a glTF model; null while a model named by asset is still loading) */
690
619
  anim: Animator | null;
691
620
  /** false while a model named by asset is loading (the placeholder body shows); true otherwise, also after a failed load (placeholder kept) */
@@ -696,10 +625,12 @@ export declare class Character {
696
625
  * npc.playAction('Wave');
697
626
  */
698
627
  readonly whenReady: Promise<void>;
699
- /** The vehicle being driven (null when not driving) */
700
- vehicle: Vehicle | null;
701
- /** Board a vehicle (the vehicle returned by rigid.addVehicle) */
702
- enter(vehicle: Vehicle): void;
628
+ /** The vehicle it sits in (null on foot) */
629
+ vehicle: Rideable | null;
630
+ /** Its seat in the vehicle: 0 drives, others ride; null on foot */
631
+ seat: number | null;
632
+ /** Board a vehicle (rigid.addWheeled's, or any object with the vehicle contract): the driver seat when free, else a free passenger seat; no-op when full */
633
+ enter(vehicle: Rideable): void;
703
634
  /** Exit the vehicle */
704
635
  exit(): void;
705
636
  /** Play a one-shot action (e.g. 'wave'); skipped if the model has no such clip */
@@ -714,8 +645,11 @@ export declare class Character {
714
645
  * (used by npcs.remove / removePlayer)
715
646
  */
716
647
  dispose(): void;
717
- /** Request a jump */
718
- jump(): void;
648
+ /**
649
+ * Request a jump (buffered for jumpBuffer s): the ground jump on the ground or in coyote time, else an air jump while maxJumps allows; air: false = ground only
650
+ * @example createPlayer({ ...presets.player.thirdPerson, maxJumps: 2 }) // double jump
651
+ */
652
+ jump(opts?: { air?: boolean }): this;
719
653
  /** Add to the scene */
720
654
  addTo(scene?: any): this;
721
655
  /** Put it on the ground at position (Vector3 / object / [x, y, z] / { x, z }) */
@@ -727,11 +661,17 @@ export declare class Character {
727
661
  syncRecord(): this;
728
662
  /**
729
663
  * Walk to a point along characters.findPath on fixed steps; never rejects. One walk per character: a new walkTo, dispose() or a save load ends the old
730
- * one with 'cancelled'. Transient: not saved, not fast-forwarded by engine.skip
664
+ * one with 'cancelled'. Transient: not saved, not fast-forwarded by engine.skip. Holds the character's control on layer 'script' (owner 'walkTo'):
665
+ * the player's keys / an NPC's schedule pause meanwhile, a cutscene pauses the walk, and another script owner on it is control-conflict
731
666
  */
732
667
  walkTo(target: Vector3 | { x: number; z: number } | [number, number, number], opts?: { speed?: number; arrive?: number; turnRate?: number; stuckSeconds?: number; maxRepaths?: number; run?: boolean }): Promise<{ status: 'arrived' | 'noPath' | 'stuck' | 'cancelled' }> & { remove(): void };
733
- /** Move in a direction (called once per fixed step): dirX/dirZ is the world direction (length 0–1), run to run, dt in seconds */
734
- move(dirX: number, dirZ: number, run: boolean, dt: number, speedOverride?: number): void;
668
+ /**
669
+ * Move in a direction (called once per fixed step): dirX/dirZ is the world direction (length 0–1 scales the speed), run to run, dt in seconds (used as
670
+ * given). Speed comes from the stats: engine.mod('move.speed', { owner, id: character.id, ... }) (the player: id 'player'), the one way to change speed.
671
+ * A character someone controls (engine.control.of(ch)) moves only through its holder: called from anywhere else it is control-bypass in dev;
672
+ * take control and use handle.move() / step instead
673
+ */
674
+ move(dirX: number, dirZ: number, run: boolean, dt: number): void;
735
675
  /** Ground type underfoot ('water' while swimming) */
736
676
  groundType(): string;
737
677
  /** Turn at once to a position, or to an angle in radians (0 = +Z) */
@@ -744,9 +684,14 @@ export declare class Character {
744
684
  /** Restore the motion state from the plain object of saveMotion */
745
685
  loadMotion(m: CharacterMotion | null | undefined): this;
746
686
  }
747
- /** Result of Character.saveMotion (plain values, can be saved) */
748
- /** facing is the same as Character.facing: 0 = +Z, forward (sin f, cos f) */
749
- export interface CharacterMotion { vx?: number; vz?: number; vy?: number; facing?: number; amount?: number; grounded?: boolean; swimming?: boolean; coyote?: number }
687
+ /** Result of Character.saveMotion (plain values, can be saved); facing is the same as Character.facing: 0 = +Z, forward (sin f, cos f) */
688
+ export interface CharacterMotion { vx?: number; vz?: number; vy?: number; facing?: number; amount?: number; grounded?: boolean; swimming?: boolean;
689
+ /** Jump state (world part version 4; older saves are migrated from the flat coyote field) */
690
+ jump?: { coyote: number; used: number };
691
+ /** safeGround as [x, y, z] */
692
+ safe?: [number, number, number] | null;
693
+ /** id of the support it rides (characters.support), found again on load */
694
+ support?: string | null }
750
695
 
751
696
  /** One schedule stop (the npcs.add form): at is when to set off, position the destination */
752
697
  export interface ScheduleStop {
@@ -757,6 +702,8 @@ export interface ScheduleStop {
757
702
  }
758
703
  /** One schedule stop (as stored in npc.schedule after install): at has been converted to 0–1, x/z is the destination (meters) */
759
704
  export interface ScheduleEntry { at: number; x: number; z: number }
705
+ /** An NPC's interact option: the op the interact key runs near it ({ npc: id, ...args }), its prompt label and reach */
706
+ export interface NpcInteract { op: string; args?: Record<string, any>; label?: string | (() => string); radius?: number }
760
707
  /** Parameters of engine.npcs.add({...}) */
761
708
  export interface NPCOptions extends CharacterOptions {
762
709
  /**
@@ -785,12 +732,14 @@ export interface NPCOptions extends CharacterOptions {
785
732
  * the position when wandering started) }
786
733
  */
787
734
  mind?: Record<string, any>;
788
- /** Dialogue script name (needs the dialogue and interactions modules), triggered by pressing the interact key when close */
789
- talk?: string | null;
790
- /** Prompt text (text is stored in the data; a function stays in memory only) */
791
- talkLabel?: string | (() => string);
792
- /** Dialogue distance (meters), default 3.2 */
793
- talkRadius?: number;
735
+ /**
736
+ * What the interact key does near it (needs interactions()): runs the op with { npc: id, ...args }. Dialogue is one such op: { op: 'npc.talk' }
737
+ * (script defaults to the NPC id; args: { script } names another, { channel: 'bubble' } plays it as lines over the NPC while play goes on). label: prompt text (a string is saved, a function stays in memory only);
738
+ * radius meters, default 3.2
739
+ * @example interact: { op: 'npc.talk' }
740
+ * @example interact: { label: 'Trade', op: 'shop.open', args: { shelf: 'tools' } }
741
+ */
742
+ interact?: NpcInteract | null;
794
743
  /** Pathfinding grid size (meters), default 2 */
795
744
  pathStep?: number;
796
745
  /** Seconds before re-pathfinding after getting stuck, default 2 */
@@ -817,8 +766,8 @@ export declare class NPC {
817
766
  readonly schedule: ScheduleEntry[];
818
767
  /** Current behavior name */
819
768
  readonly behavior: string;
820
- /** Dialogue id */
821
- readonly talk: string | null;
769
+ /** What the interact key does near it ({ label, op, args, radius } as saved), null when nothing */
770
+ readonly interact: { label: string | null; op: string; args: Record<string, any>; radius: number } | null;
822
771
  /** Animation state ('idle' / 'walk'...) */
823
772
  readonly state: string;
824
773
  /** In dialogue (stopped, not walking) */
@@ -861,6 +810,13 @@ export interface NPCManager {
861
810
  * seconds); selected through behavior in the data
862
811
  */
863
812
  behavior(name: string, impl: { near?: (rec: WorldRecord, dt: number, npc: NPC) => void; far?: (rec: WorldRecord, dt: number) => void }): this;
813
+ /**
814
+ * Near tiers for large crowds, off by default (every near NPC walks every fixed step). With tiers, NPCs within fullRadius m of the focus walk every
815
+ * step; the rest of the near zone takes a turn once every nearEvery seconds with the accumulated dt (deterministic, save-safe). On screen such NPCs
816
+ * move in visible jumps, so only turn this on for crowds of hundreds. tiers(null) turns it off.
817
+ * @example engine.npcs.tiers({ fullRadius: 30, nearEvery: 4 / 60 })
818
+ */
819
+ tiers(opts: { fullRadius: number; nearEvery: number } | null): this;
864
820
  /**
865
821
  * Nearby NPCs avoid each other (on by default): pushed apart to no less than the sum of their radii, the player counts as an obstacle (NPCs yield to
866
822
  * the player), then constrained back to walkable places by engine.collision; deterministic and cheap, with identical results after loading.
@@ -901,7 +857,14 @@ export interface CharactersApi {
901
857
  * The 'camera' player control as a value: keys / stick relative to the camera, the 'run' action if bound, input.autopilot. Reused object; call it
902
858
  * inside your own control function to wrap it
903
859
  */
904
- moveInput(): { x: number; z: number; run: boolean; speed?: number };
860
+ moveInput(): { x: number; z: number; run: boolean };
861
+ /**
862
+ * Something characters stand on and ride (moving platform, lift, raft). Move the object any way (onFixed before or after the player, a timeline,
863
+ * physics): riders follow how its matrix changed, so the order does not matter. safe: false = never a respawn spot; carry 'position+yaw' turns riders
864
+ * with it; inherit: false = jumping off keeps none of its speed. With mover 'rapier' give it a collider too.
865
+ * @example const lift = engine.characters.support(liftMesh); engine.onFixed(() => { liftMesh.position.y = 2 + Math.sin(engine.time.now('real')); });
866
+ */
867
+ support(object: any, opts?: { id?: string; safe?: boolean; carry?: 'position' | 'position+yaw'; inherit?: boolean }): { id: string; remove(): void };
905
868
  /**
906
869
  * Delete the current player (exits the vehicle first, stops responding to keys, fully deletes the model). The player save (key player) carries the
907
870
  * position and the vehicle; loading an on-foot save exits the vehicle first
@@ -938,14 +901,13 @@ export interface FindSpawnOptions { minH?: number; maxH?: number; maxSlope?: num
938
901
  export interface CharactersOptions {
939
902
  /** Whether to enable NPCs (engine.npcs), default true */
940
903
  npcs?: boolean;
941
- /** Brake key when driving (action brake, registered when rigid is installed), none by default (no brake while driving; one warning names the fix);
942
- * presets.keys.brake has ['KeyB'] (so it doesn't fight with Space for jump) */
943
- brakeKeys?: string[];
944
- /** Gamepad button for braking, none by default; presets.keys.brake has ['PadLT'] */
945
- brakePad?: string[];
946
- }
947
- /** Pathfinding options: step is the grid size (meters, A*), maxNodes the maximum cells searched (A*), radius the character radius (meters) */
948
- /** radius defaults to engine.movement.radius; for detailed see findPath */
904
+ /** Near tiers for large NPC crowds, off by default (every near NPC walks every fixed step); same as engine.npcs.tiers(opts) */
905
+ npcTiers?: { fullRadius: number; nearEvery: number };
906
+ }
907
+ /**
908
+ * Pathfinding options: step is the grid size (meters, A*), maxNodes the maximum cells searched (A*), radius the character radius (meters,
909
+ * default engine.movement.radius); for detailed see findPath
910
+ */
949
911
  export interface FindPathOptions { step?: number; maxNodes?: number; radius?: number; detailed?: boolean }
950
912
 
951
913
  // ======================================================================
@@ -955,29 +917,39 @@ export interface FindPathOptions { step?: number; maxNodes?: number; radius?: nu
955
917
  export interface InteractionOptions {
956
918
  /** Stable id for the op interaction.use { id } (default: the world record id it was built for, else a running number) */
957
919
  id?: string;
958
- /** Prompt text, or a function returning text */
959
- label?: string | (() => string);
920
+ /** Prompt text, or a function (object, { actor }) returning text; actor = world record id of who looks at it */
921
+ label?: string | ((object: Object3D, ctx: { actor: string }) => string);
960
922
  /** How close the actor must be (meters), default interactions({ radius }) = 2.5 */
961
923
  radius?: number;
962
924
  /** Key action name, default 'interact' (E key). Give one object a second verb by adding another interaction with another action */
963
925
  action?: string;
964
- /** Called when pressed */
965
- onUse?: (object: Object3D) => void;
926
+ /**
927
+ * Called when used, with who uses it (ctx.actor of interaction.use: the local user, a net peer, an NPC). Its return value is the op's value; { ok: false,
928
+ * code } fails the op with that code
929
+ */
930
+ onUse?: (object: Object3D, ctx: { actor: string }) => any;
966
931
  /**
967
932
  * When this returns false the whole prompt disappears (to show a state such as "growing", don't use enabled: have the label function return different
968
933
  * text by state and decide in onUse whether it can be used)
969
934
  */
970
- enabled?: () => boolean;
935
+ enabled?: (object: Object3D, ctx: { actor: string }) => boolean;
971
936
  /** How high the prompt floats above the object (meters) */
972
937
  height?: number;
938
+ /**
939
+ * Seconds the key must stay down before onUse runs (0 = a press). The engine counts it and interrupts it on release, leaving reach, enabled() false or
940
+ * locked input (interaction:hold / interaction:interrupt); the prompt gets progress 0-1. The op interaction.use itself is the completed use
941
+ */
942
+ hold?: number;
943
+ /** Walk the player there first (walkTo, stops 1.2 m away), then use it; with radius: Infinity it can be used from anywhere (point-and-click) */
944
+ approach?: boolean;
973
945
  }
974
946
  /** engine.interactions */
975
947
  export interface Interactions {
976
948
  action: string;
977
949
  /** How high the prompt floats (meters) */
978
950
  promptHeight: number;
979
- /** All interactions */
980
- items: any[];
951
+ /** All interactions in the order added (a fresh array each read; get(id) finds one without it) */
952
+ readonly items: any[];
981
953
  /** Default reach of add() in meters (2.5) */
982
954
  radius: number;
983
955
  /** How the one in front of the actor is chosen; can be changed at runtime */
@@ -986,6 +958,8 @@ export interface Interactions {
986
958
  current: any;
987
959
  /** One best interaction per key action this frame, for a prompt that lists several keys */
988
960
  options: { action: string; id: string; label: string }[];
961
+ /** The hold in progress (progress 0-1), null when none */
962
+ holding: { id: string; action: string; seconds: number; progress: number } | null;
989
963
  /**
990
964
  * Add an interaction: passing an object makes it follow the object, passing a position (Vector3 / [x, y, z] / { x, y, z }) makes a fixed point.
991
965
  * Returns a handle { remove() }
@@ -1014,8 +988,10 @@ export interface PromptView {
1014
988
  onScreen: boolean;
1015
989
  /** Use it (the op interaction.use) */
1016
990
  use(): void;
1017
- /** One best interaction per action this frame, for a prompt that lists several keys ("E · 浇水 F · 收获") */
991
+ /** One best interaction per action this frame, for a prompt that lists several keys ("E · Open F · Lock") */
1018
992
  options: { action: string; id: string; label: string }[];
993
+ /** A hold interaction: how far the hold is (0-1, 0 before it starts); null for a plain press */
994
+ progress: number | null;
1019
995
  }
1020
996
  /** A candidate handed to a pick function: an enabled interaction within its radius of the actor */
1021
997
  export interface InteractionCandidate { id: string; object: Object3D; action: string; label: string | (() => string); distance: number }
@@ -1037,8 +1013,6 @@ export interface InteractionsOptions {
1037
1013
  * keys: ['KeyE'], radius: 2 }) // first person
1038
1014
  */
1039
1015
  pick: InteractionPick;
1040
- /** Keys of the action; required unless the game bound the action already (createEngine({ bindings: { interact: [...] } }) or input.define) */
1041
- keys?: string[];
1042
1016
  }
1043
1017
 
1044
1018
  // ======================================================================
@@ -1081,8 +1055,18 @@ export interface DialogueNode {
1081
1055
  }
1082
1056
  /** Dialogue script: node name -> node, starting from 'start' */
1083
1057
  export type DialogueScript = Record<string, DialogueNode>;
1084
- /** Promise returned by say() (id is a temporary dialogue name) */
1085
- export interface SayPromise extends Promise<void> { id: string }
1058
+ /** Promise returned by say(): id is the temporary script name of a main-channel line (null for a plain bubble line); remove() ends the line now (it resolves) */
1059
+ export interface SayPromise extends Promise<void> { id: string | null; remove(): void }
1060
+ /** Which dialogue channel: 'main' the conversation the player reads (locks input, choices) · 'bubble' lines over their speakers while play goes on */
1061
+ export type DialogueChannel = 'main' | 'bubble';
1062
+ /**
1063
+ * Where a bubble line sits: an Object3D (it follows it), a position, an actor / world record id (engine.actorPosition), or null = a screen line (radio, intercom)
1064
+ */
1065
+ export type BubbleAt = Object3D | PositionLike | string | null;
1066
+ /** Bubble-channel options: seconds on screen (default holdSeconds + about 15 characters a second); queue false = replace this speaker's current line */
1067
+ export interface BubbleOptions { at?: BubbleAt; seconds?: number; queue?: boolean }
1068
+ /** What the 'dialogue.bubble' UI part (one per speaker) receives in update(view) every frame while its line shows */
1069
+ export interface BubbleView { speaker: string; text: string; x: number; y: number; onScreen: boolean; screen: boolean }
1086
1070
 
1087
1071
  /** engine.dialogue */
1088
1072
  export interface Dialogue {
@@ -1090,9 +1074,13 @@ export interface Dialogue {
1090
1074
  readonly state: DialogueState;
1091
1075
  /** All scripts */
1092
1076
  scripts: Map<string, DialogueScript>;
1093
- /** The dialogue in progress (null when none) */
1094
- active: { speaker: string; nodes: DialogueScript; node?: DialogueNode; onEnd: (() => void) | null; lock: boolean } | null;
1095
- /** The script currently speaking */
1077
+ /**
1078
+ * The dialogue in progress (null when none). speaker: the script name; node: the current node OBJECT (its fields: text, choices, data...);
1079
+ * id: that node's id string ('start', 'ask'); both are set once the first line shows. Read-only: drive it with start / end / the dialogue ops.
1080
+ * @example const atAsk = engine.dialogue.active?.id === 'ask'; // the node id; active.node.data holds the node's own fields
1081
+ */
1082
+ readonly active: { speaker: string; nodes: DialogueScript; node?: DialogueNode; id?: string; onEnd: (() => void) | null } | null;
1083
+ /** The script the main dialogue is playing */
1096
1084
  readonly speaking: string | null;
1097
1085
  /** Typing speed (characters/second) */
1098
1086
  cps: number;
@@ -1100,21 +1088,22 @@ export interface Dialogue {
1100
1088
  define(speaker: string, nodes: DialogueScript): void;
1101
1089
  /**
1102
1090
  * Start a dialogue: from node nodeId (default 'start'), onEnd is called when it ends.
1103
- * lock (default true) locks game input and takes Esc; lock: false lets the player keep playing (lines move on by themselves) and never cuts into a
1104
- * locking dialogue.
1105
- * onCancel: what the back key (Esc) does while this locking dialogue is on top of the UI focus stack (default: nothing).
1106
- * Ending the playthrough (engine.session newGame / load / quit) closes the dialogue without calling onEnd.
1107
- * @example engine.dialogue.start('guard', 'start', null, { lock: false })
1091
+ * Main channel (default): locks game input and takes Esc; its choices take the UI choice cursor. onCancel: what the back key (Esc) does while it is on
1092
+ * top of the UI focus stack (default: nothing). channel: 'bubble' plays the script as bubble lines over at (no lock, no choices; a running
1093
+ * conversation is untouched). Ending the playthrough (engine.session newGame / load / quit) closes it without calling onEnd.
1094
+ * @example engine.dialogue.start('guard', 'start', null, { channel: 'bubble', at: guard.root })
1108
1095
  */
1109
- start(speaker: string, nodeId?: string, onEnd?: (() => void) | null, opts?: { lock?: boolean; onCancel?: (() => void) | null }): void;
1096
+ start(speaker: string, nodeId?: string, onEnd?: (() => void) | null, opts?: { channel?: DialogueChannel; at?: BubbleAt; onCancel?: (() => void) | null }): void;
1110
1097
  /**
1111
- * Say a one-off line (no need to define first); the Promise resolves when it is done. lock: false = said while the player keeps playing (barks, radio
1112
- * chatter).
1098
+ * Say a one-off line (no need to define first); the Promise resolves when it is done. channel: 'bubble' = over at while the player keeps playing
1099
+ * (barks, shop chatter, radio); several speakers at once, queued per speaker.
1113
1100
  * When the playthrough ends (engine.session) the line is dropped and the Promise never resolves, so code awaiting it does not run in the next playthrough.
1114
- * @example await engine.dialogue.say('Reloading!', { speaker: 'Mira', lock: false })
1101
+ * @example await engine.dialogue.say('Reloading!', { speaker: 'Mira', channel: 'bubble', at: mira.root })
1115
1102
  */
1116
- say(text: string | DialogueScript, opts?: { speaker?: string; node?: string; lock?: boolean; onCancel?: (() => void) | null }): SayPromise;
1117
- /** End the current dialogue */
1103
+ say(text: string | DialogueScript, opts?: { speaker?: string; node?: string; channel?: DialogueChannel; onCancel?: (() => void) | null } & BubbleOptions): SayPromise;
1104
+ /** Lines on the bubble channel now */
1105
+ bubbles(): { speaker: string; text: string; queued: number }[];
1106
+ /** End the main dialogue */
1118
1107
  end(): void;
1119
1108
  // Advancing and choosing are ops: engine.ops.run('dialogue.advance') / engine.ops.run('dialogue.choose', { index })
1120
1109
  // (0-based; while typing it completes the line first)
@@ -1122,11 +1111,10 @@ export interface Dialogue {
1122
1111
  export interface DialogueOptions {
1123
1112
  /** Typing speed (characters/second, game time: advanced by engine.step), default 40 */
1124
1113
  charsPerSecond?: number;
1125
- /** Actions that advance the dialogue, default ['confirm', 'interact'] (interact only when the game bound it) */
1114
+ /** Actions that advance the dialogue, default ['confirm'] (a basic key); e.g. ['confirm', 'interact'] to also advance on the game's interact key.
1115
+ * Choices: the cursor, clicks, and the actions choice1..choice9 (context 'dialog', no keys of their own: presets.bindings.dialogNumbers binds 1-9) */
1126
1116
  advanceActions?: string[];
1127
- /** Number keys 1-9 pick choices (read only while a locking dialogue runs; rebind them as actions choice1...choice9), false = click / op only. Default true */
1128
- choiceKeys?: boolean;
1129
- /** A non-locking line (lock: false) moves on this many seconds after it is fully typed, default 2 */
1117
+ /** A bubble line stays this many seconds plus its reading time (about 15 characters a second) unless say() gives seconds, default 2 */
1130
1118
  holdSeconds?: number;
1131
1119
  }
1132
1120
  /**
@@ -1164,8 +1152,8 @@ export interface DialogueView {
1164
1152
  hint: string;
1165
1153
  /** The node's data (the game's own fields), {} when none */
1166
1154
  data: Record<string, any>;
1167
- /** false for a line said while the player keeps playing */
1168
- lock: boolean;
1155
+ /** The choice under the UI choice cursor (menu keys / d-pad / stick; confirm picks it), -1 when no choices show */
1156
+ selected: number;
1169
1157
  /** Run the op dialogue.advance (finish typing / next line) */
1170
1158
  advance(): any;
1171
1159
  /** Run the op dialogue.choose { index } (0-based among choices) */
@@ -1198,24 +1186,37 @@ export interface ItemDef {
1198
1186
  consume?: boolean;
1199
1187
  /** Color of the pickup on the ground */
1200
1188
  color?: ColorLike;
1189
+ /** Shape on the ground: a model name from an asset pack (file or generator; default: a model named 'pickup:<item id>', else 'pickup', else a gray box) */
1190
+ model?: string;
1201
1191
  [key: string]: any;
1202
1192
  }
1203
- /** id = item id, key = entry key ('arrow', or 'sword#3' for a piece with data), count = change, total = how many of the item now */
1204
- export interface ItemEvent { id: string; key: string; count: number; total: number }
1193
+ /**
1194
+ * Every container emits item:add / item:remove. container = which container changed (an actor's bag has the actor's id; the local one is engine.actor),
1195
+ * actor = who did it (the running op's actor, else engine.actor), id = item id, key = entry key ('arrow', or 'sword#3' for a piece with data),
1196
+ * count = change, total = how many of the item that container holds now
1197
+ */
1198
+ export interface ItemEvent { container: string; actor: string; id: string; key: string; count: number; total: number }
1205
1199
  /** inventory.use: who used which entry (data = that piece's data) */
1206
1200
  export interface ItemUseEvent { actor: string; item: string; key: string; data?: Record<string, any> }
1207
1201
  /** One entry of a container: plain items share one entry per kind (key = item id); items with data have their own key ('sword#3') */
1208
1202
  export interface ItemEntry { key: string; id: string; count: number; data?: Readonly<Record<string, any>>; def: ItemDef }
1209
- /** Change in a non-player container (the player inventory emits item:add / item:remove): container is the container id */
1210
- export interface ContainerEvent extends ItemEvent { container: string }
1211
- export interface PickupEvent { id: string; x: number; z: number }
1203
+ export interface PickupEvent { pickup: string; item: string | null; count: number; actor: string; x: number; z: number }
1204
+ /** What a give function gets: who takes it (world record id) and the pickup record */
1205
+ export interface PickupGiveContext { actor: string; pickup: WorldRecord }
1212
1206
  /**
1213
- * Handle returned by spawnPickup(): id is the item, worldId is the id of this record in engine.world, object is the current model (null when far away);
1207
+ * Handle returned by pickups.spawn(): id is the world record id, object is the current model (null when far away);
1214
1208
  * remove() deletes the pickup (data and model; a model passed in through opts.mesh is only taken off)
1215
1209
  */
1216
- export interface PickupHandle extends Handle { id: string; worldId: string; readonly object: Object3D | null }
1217
- /** Parameters of spawnPickup() */
1210
+ export interface PickupHandle extends Handle {
1211
+ /** The pickup's world record id (engine.world.get(id)), not the item id (0.2 meaning; the item is `give` when it is a string) */
1212
+ id: string; give: string | ((e: Engine, ctx: PickupGiveContext) => any); readonly object: Object3D | null }
1213
+ /** Parameters of pickups.spawn() */
1218
1214
  export interface PickupOptions {
1215
+ /**
1216
+ * What taking it does: an item id goes into the picker's container (inventory.of(actor); needs inventory()); a function (e, { actor, pickup }) => result is an
1217
+ * instant effect (no inventory needed; not saved data, so spawn it again on load). Returning { ok: false, code } leaves it on the ground
1218
+ */
1219
+ give: string | ((e: Engine, ctx: PickupGiveContext) => any);
1219
1220
  /**
1220
1221
  * Stable id of this record in world (saves recognize it by this); numbered automatically pickup#1... if omitted, and an existing record with the same
1221
1222
  * id is reused
@@ -1225,11 +1226,17 @@ export interface PickupOptions {
1225
1226
  count?: number;
1226
1227
  /** The piece's own data (a dropped sword keeps its durability) */
1227
1228
  data?: Record<string, any>;
1228
- /** Reach in meters, default inventory pickupRadius (2) */
1229
+ /** Name in the prompt ("Pick up {name}"), default the item's name */
1230
+ name?: string;
1231
+ /** Shape on the ground: a model name from an asset pack (default the item's model, else 'pickup:<item>', else 'pickup', else a gray box) */
1232
+ model?: string;
1233
+ /** Color of the gray placeholder / a geometry-only model (default the item's color, else style.pickup.color) */
1234
+ color?: ColorLike;
1235
+ /** Reach in meters, default pickups({ radius }) (2) */
1229
1236
  radius?: number;
1230
- /** Taken by walking into it (no key press, no prompt) */
1237
+ /** Taken by walking into it (no key press, no prompt), by every actor in pickups.takers */
1231
1238
  auto?: boolean;
1232
- /** Custom model (the style pack's style.pickup is used if omitted) */
1239
+ /** The game's own three.js object for this one pickup (only detached when it goes; otherwise the model name decides the shape) */
1233
1240
  mesh?: Object3D | null;
1234
1241
  /** Game seconds until it reappears, 0 = never reappears */
1235
1242
  respawnSeconds?: number;
@@ -1243,9 +1250,32 @@ export interface PickupOptions {
1243
1250
  /** Which zone it belongs to (a level name, see world.zone): the data stays across level changes (a picked-up one stays picked up) */
1244
1251
  zone?: string | null;
1245
1252
  }
1253
+ /** engine.pickups: things on the ground that give whoever takes them an item or an instant effect (op pickup.take, net: 'peer') */
1254
+ export interface Pickups {
1255
+ /** Reach of pickups that do not set their own (meters) */
1256
+ radius: number;
1257
+ /** Who walks into auto pickups: default engine.actor plus net peers on a host, none on a client */
1258
+ takers: (e: Engine) => string[];
1259
+ /**
1260
+ * Place a pickup on the ground at position; its y, if any, is the reference height on multi-layer ground (needs the interactions module unless auto):
1261
+ * spawn(v, { give: 'berry', count: 2 }). Returns a handle, remove() deletes it
1262
+ */
1263
+ spawn(position: PositionLike, opts: PickupOptions): PickupHandle;
1264
+ /** The data of the nearest pickup still on the ground to from (default engine.actorPosition()), of one item id or any; null if none */
1265
+ nearest(item?: string | null, from?: PositionLike): WorldRecord | null;
1266
+ }
1267
+ export interface PickupsOptions {
1268
+ /** Reach of pickups that do not set their own radius (meters), default 2 */
1269
+ radius?: number;
1270
+ /** Pickups have a model, float and spin only within this distance (meters) of the stream sources, default 60 */
1271
+ showDistance?: number;
1272
+ /** Who walks into auto pickups (actor ids); default engine.actor, plus net peers on a host */
1273
+ takers?: (e: Engine) => string[];
1274
+ }
1246
1275
 
1247
1276
  /**
1248
- * Container (inventory, chest, corpse, shelf): inventory.container(id, opts) gets or creates one; the player inventory is the one with id 'player'.
1277
+ * Container (inventory, chest, corpse, shelf, an actor's bag): inventory.container(id, opts) gets or creates one; an actor's bag has the actor's id
1278
+ * (inventory.of(actor)), the player inventory is the bag of engine.actor.
1249
1279
  * Every x is an item id or an entry key
1250
1280
  */
1251
1281
  export interface Container {
@@ -1268,17 +1298,17 @@ export interface Container {
1268
1298
  list(): ItemEntry[];
1269
1299
  /** How many more fit (Infinity = no limit), for an item without data, with this data, or like an existing entry key */
1270
1300
  room(x: string, data?: Record<string, any>): number;
1271
- /** Add n (default 1), optionally with data; returns the entry key, false if none fit; silent suppresses the toast (only the player inventory shows one) */
1301
+ /** Add n (default 1), optionally with data; returns the entry key, false if none fit; silent suppresses the toast (only the bag of engine.actor shows one) */
1272
1302
  add(id: string, n?: number, opts?: { data?: Record<string, any>; silent?: boolean }): string | false;
1273
1303
  /** Remove n (default 1) of an item or entry key, returns false if there are not enough */
1274
1304
  remove(x: string, n?: number): boolean;
1275
1305
  /**
1276
- * Atomic trade: take A (id or entry key) and give B in one all-or-nothing step; reason 'notEnough' | 'full'. Ops: inventory.trade, engine.ops.undo
1306
+ * Atomic trade: take A (id or entry key) and give B in one all-or-nothing step; failure code 'notEnough' | 'full'. Ops: inventory.trade, engine.ops.undo
1277
1307
  * reverses it
1278
1308
  */
1279
1309
  trade(
1280
1310
  take: string, give: string, opts?: { takeN?: number; giveN?: number; data?: Record<string, any>; silent?: boolean }
1281
- ): { ok: boolean; reason?: string; took?: { id: string; count: number; data?: any }[]; gave?: string; giveId?: string; giveN?: number };
1311
+ ): { ok: boolean; code?: string; facts?: any; nextActions?: any[]; took?: { id: string; count: number; data?: any }[]; gave?: string; giveId?: string; giveN?: number };
1282
1312
  /** Replace an entry's data (null = none) for n pieces (default all); returns the key now holding them */
1283
1313
  setData(key: string, data: Record<string, any> | null, n?: number): string;
1284
1314
  /** Listen for changes of this container, returns a handle */
@@ -1293,11 +1323,11 @@ export interface Inventory {
1293
1323
  defs: Map<string, ItemDef>;
1294
1324
  /** Slot limit of the player inventory */
1295
1325
  capacity: number;
1296
- /** Player inventory (= container('player')) */
1326
+ /** Player inventory: the bag of engine.actor (= of()) */
1297
1327
  readonly bag: Container;
1328
+ /** The bag of an actor (default engine.actor): the container with the actor's id, created empty on first use; inside an op pass ctx.actor */
1329
+ of(actor?: string): Container;
1298
1330
  defaultStack: number;
1299
- /** Reach of pickups that do not set their own (meters) */
1300
- pickupRadius: number;
1301
1331
  action: string;
1302
1332
  /** Define an item (chainable) */
1303
1333
  define(id: string, def: ItemDef): this;
@@ -1318,12 +1348,12 @@ export interface Inventory {
1318
1348
  /** Remove n (default 1) of an item or entry key, returns false if there are not enough */
1319
1349
  remove(x: string, n?: number): boolean;
1320
1350
  /**
1321
- * Atomic trade: take A (id or entry key) and give B in one all-or-nothing step; reason 'notEnough' | 'full'. Ops: inventory.trade, engine.ops.undo
1351
+ * Atomic trade: take A (id or entry key) and give B in one all-or-nothing step; failure code 'notEnough' | 'full'. Ops: inventory.trade, engine.ops.undo
1322
1352
  * reverses it
1323
1353
  */
1324
1354
  trade(
1325
1355
  take: string, give: string, opts?: { takeN?: number; giveN?: number; data?: Record<string, any>; silent?: boolean }
1326
- ): { ok: boolean; reason?: string; took?: { id: string; count: number; data?: any }[]; gave?: string; giveId?: string; giveN?: number };
1356
+ ): { ok: boolean; code?: string; facts?: any; nextActions?: any[]; took?: { id: string; count: number; data?: any }[]; gave?: string; giveId?: string; giveN?: number };
1327
1357
  /** Replace a player inventory entry's data for n pieces (default all); returns the key now holding them */
1328
1358
  setData(key: string, data: Record<string, any> | null, n?: number): string;
1329
1359
  /**
@@ -1338,31 +1368,20 @@ export interface Inventory {
1338
1368
  transfer(from: Container | string, to: Container | string, item: string, n?: number): number;
1339
1369
  /** Delete a container together with its contents ('player' cannot be deleted), returns whether one was deleted */
1340
1370
  removeContainer(id: string): boolean;
1341
- /**
1342
- * Place a pickup on the ground at position; its y, if any, is the reference height on multi-layer ground (needs the interactions module unless auto):
1343
- * spawnPickup('berry', v, { count: 2 }). Returns a handle, remove() deletes it
1344
- */
1345
- spawnPickup(id: string, position: PositionLike, opts?: PickupOptions): PickupHandle;
1346
- /** The data of the nearest pickup of an item still on the ground to from (default the player) (a world record of kind 'pickup'), null if none */
1347
- nearestPickup(id: string, from?: PositionLike): WorldRecord | null;
1371
+ /** Every container's items as plain data, the player bag included: { [containerId]: entries } (what setContents takes; net syncs through these two) */
1372
+ contents(): Record<string, any[]>;
1373
+ /** Replace containers' items from contents() data, silently like a save load; a null entry empties that container, only: true empties the rest too */
1374
+ setContents(data: Record<string, any[] | null>, opts?: { only?: boolean }): void;
1348
1375
  }
1349
1376
  export interface InventoryOptions {
1350
1377
  /** Action name that opens the inventory, default 'inventory' */
1351
1378
  action?: string;
1352
- /** Keys that open the bag: required unless createEngine({ bindings }) binds the action ([] = no key); presets.keys.inventory has ['KeyI'] */
1353
- keys?: string[];
1354
- /** Gamepad button, none by default; presets.keys.inventory has ['PadY'] */
1355
- pad?: string[];
1356
1379
  /** true: gameplay freezes (engine.freeze) while the inventory window is open, default false. Also settable at runtime: engine.inventory.pauseGame */
1357
1380
  pauseGame?: boolean;
1358
- /** Pickups float and spin only within this distance (meters) of the focus, default 60 */
1359
- bobDistance?: number;
1360
1381
  /** Slot limit of the player inventory, default Infinity (no limit) */
1361
1382
  capacity?: number;
1362
1383
  /** Weight limit of the player inventory, default Infinity */
1363
1384
  maxWeight?: number;
1364
- /** Reach of pickups that do not set their own radius (meters), default 2 */
1365
- pickupRadius?: number;
1366
1385
  /** Default stack limit, default 99 */
1367
1386
  defaultStack?: number;
1368
1387
  }
@@ -1408,14 +1427,16 @@ export interface QuestDef {
1408
1427
  /** engine.quests */
1409
1428
  export interface Quests {
1410
1429
  defs: Map<string, QuestDef>;
1411
- /** Quests in progress / completed / failed: id -> { step (current step), done, failed?, parts? } */
1412
- state: Record<string, { step: number; done: boolean; failed?: boolean; parts?: boolean[] }>;
1413
1430
  /** The quest log (UI part 'questLog'): open, toggle(on?), refresh() */
1414
1431
  win: { readonly open: boolean; toggle(on?: boolean): void; refresh(): void };
1415
1432
  /** Define a quest (chainable) */
1416
1433
  define(id: string, def: QuestDef): this;
1417
1434
  /** Start a quest */
1418
1435
  start(id: string): void;
1436
+ /** One quest's progress (a copy): step index, step count, done, failed, active; null before it starts */
1437
+ state(id: string): { step: number; steps: number; done: boolean; failed: boolean; active: boolean } | null;
1438
+ /** Finish the current step from code (its done() is not asked) and go on; the last step completes the quest. false when not active */
1439
+ advance(id: string): boolean;
1419
1440
  isDone(id: string): boolean;
1420
1441
  /** Started, not done and not failed */
1421
1442
  isActive(id: string): boolean;
@@ -1451,10 +1472,6 @@ export interface QuestLogView {
1451
1472
  export interface QuestsOptions {
1452
1473
  /** Action name that opens the quest log, default 'quests' */
1453
1474
  action?: string;
1454
- /** Keys that open the quest log: required unless createEngine({ bindings }) binds the action ([] = no key); presets.keys.quests has ['KeyJ'] */
1455
- keys?: string[];
1456
- /** Gamepad button, none by default; presets.keys.quests has ['PadSelect'] */
1457
- pad?: string[];
1458
1475
  /** Check interval (game seconds, checked in the fixed step; not checked while frozen / paused), default 0.5 */
1459
1476
  checkInterval?: number;
1460
1477
  /**
@@ -1484,18 +1501,14 @@ export interface PhotoTakeOptions {
1484
1501
  scale?: number;
1485
1502
  /** Shadow resolution (pixels), default 4096 */
1486
1503
  shadowMapSize?: number;
1487
- /** Turn bloom on when taking a photo */
1488
- bloom?: boolean;
1504
+ /** Bloom for the shot: null (default) keeps what the game's post has; true / false forces it for that shot only */
1505
+ bloom?: boolean | null;
1489
1506
  /** Image quality 0–1 */
1490
1507
  quality?: number;
1491
1508
  /** Image format, e.g. 'image/jpeg' */
1492
1509
  format?: string;
1493
1510
  }
1494
1511
  export interface PhotoOptions extends PhotoTakeOptions {
1495
- /** Photo key: required unless createEngine({ bindings }) binds 'photo' ([] = no key); presets.keys.photo has ['KeyP'] */
1496
- keys?: string[];
1497
- /** Gamepad button for taking a photo, none by default; presets.keys.photo has ['PadRB'] */
1498
- pad?: string[];
1499
1512
  /** How many photos the album keeps at most, default 50 */
1500
1513
  maxAlbum?: number;
1501
1514
  }
@@ -1538,10 +1551,12 @@ export interface UIWindow {
1538
1551
  refresh(): void;
1539
1552
  /** Open / close (toggle if no argument is passed) */
1540
1553
  toggle(on?: boolean): void;
1554
+ /** Remove the window: closed, its listeners and its element gone (a module passes the window to ctx.track instead) */
1555
+ remove(): void;
1541
1556
  }
1542
1557
  /** Parameters of makeWindow() */
1543
1558
  export interface WindowOptions {
1544
- /** Window name (also the style pack's template name) */
1559
+ /** Window name (also the style's template name) */
1545
1560
  id: string;
1546
1561
  /** Title */
1547
1562
  title: () => string;
@@ -1561,7 +1576,19 @@ export interface FocusHandle extends Handle {
1561
1576
  cancel: (() => void) | null;
1562
1577
  /** Just pushed this frame (the key press that opened it must not count as its own action) */
1563
1578
  readonly fresh: boolean;
1579
+ /** The selected control / choice (null until the cursor first runs) */
1580
+ index: number | null;
1581
+ /** The choice cursor used confirm on this entry this frame (the owner's own confirm handling skips this frame) */
1582
+ readonly consumed: boolean;
1583
+ /** Change the cursor's controls while pushed (the index starts over); null = no cursor */
1584
+ setNav(nav: FocusNav | null): void;
1564
1585
  }
1586
+ /**
1587
+ * The UI choice cursor's controls for a focus entry: moved by the menu keys (uiUp / uiDown / uiLeft / uiRight, d-pad, left stick), pressed by confirm.
1588
+ * A function returning an element = the controls inside it (button, input, select, [data-nav]) in screen layout, the selected one gets .is-cursor;
1589
+ * an object = a list the owner draws itself (any direction steps by one).
1590
+ */
1591
+ export type FocusNav = (() => Element | null) | { count(): number; confirm(index: number): void; moved?(index: number): void };
1565
1592
  /**
1566
1593
  * UI focus stack: windows, dialogue, cutscenes and the settings menu are pushed in the order they open, and the back key (action cancel) goes only to
1567
1594
  * the top; when the stack is empty it goes to the one registered by setRoot (the settings menu)
@@ -1571,8 +1598,10 @@ export interface UIFocus {
1571
1598
  readonly top: string | null;
1572
1599
  /** Names from bottom to top */
1573
1600
  list(): string[];
1574
- /** Push; without cancel = swallow the back key */
1575
- push(id: string, opts?: { cancel?: (() => void) | null }): FocusHandle;
1601
+ /** The top entry's choice cursor ({ id, index }) when it has a nav, else null */
1602
+ readonly cursor: { id: string; index: number } | null;
1603
+ /** Push; without cancel = swallow the back key; nav = the choice cursor's controls (see FocusNav) */
1604
+ push(id: string, opts?: { cancel?: (() => void) | null; nav?: FocusNav | null }): FocusHandle;
1576
1605
  /** What to do on the back key when the stack is empty (only one, a later registration replaces it) */
1577
1606
  setRoot(fn: () => void): Handle;
1578
1607
  }
@@ -1583,24 +1612,112 @@ export interface UIFocus {
1583
1612
  // ======================================================================
1584
1613
 
1585
1614
  /**
1586
- * engine.clock: game seconds and "after how long / every how long". Clock-time / season timers are on engine.sky (at / between / daily / onSeason). All
1615
+ * engine.clock: calendar seconds and "after how long / every how long". Clock-time / season timers are on engine.sky (at / between / daily / onSeason). All
1587
1616
  * timers return a handle { remove() }
1588
1617
  */
1589
1618
  export interface Clock {
1590
1619
  /**
1591
- * Game seconds = fixed-step seconds x clock.timeScale (the time scale is 1 without sky), does not advance while paused / frozen, saved with the game;
1592
- * one sky day = sky.dayLength game seconds
1620
+ * Calendar seconds = world-channel seconds x clock.rate, does not advance while paused / frozen, saved with the game;
1621
+ * one calendar day = calendar.dayLength calendar seconds
1622
+ */
1623
+ readonly now: number;
1624
+ /**
1625
+ * Calendar seconds per world-channel second (default 1; 0 stops the calendar, sky included). Read-only: change it with
1626
+ * `engine.mod('clock.rate', { owner: 'game', set: 60 })` (a minute per second); the handle's remove() undoes it
1627
+ */
1628
+ readonly rate: number;
1629
+ /** Calendar seconds per real second right now (rate x the world channel's speed) */
1630
+ readonly speed: number;
1631
+ /**
1632
+ * Call fn after seconds calendar seconds; if an event name is passed, the event is emitted when due (with data, can be saved).
1633
+ * { channel } counts that time channel's seconds instead (a poison tick that slows down in bullet time)
1634
+ */
1635
+ after(seconds: number, fnOrEvent: (() => void) | string, data?: any, opts?: { channel?: string }): Handle;
1636
+ /** Call once every seconds calendar seconds ({ channel }: 'real' or a time channel's seconds instead) */
1637
+ every(seconds: number, fn: () => void, opts?: { channel?: string }): Handle;
1638
+ }
1639
+
1640
+ /** The handle engine.mod / input.gate return: remove() ends only this owner's entry (a stale handle ends nothing) */
1641
+ export interface ModHandle {
1642
+ owner: string; remove(): void;
1643
+ /** Rewrite this entry's value in place (same op / layer): a per-frame contribution takes once and changes every frame. false when the handle is stale */
1644
+ change(value: any): boolean;
1645
+ }
1646
+ /** Shared-point layers, lowest first. Most code never passes one: game code and game modules are 'game'; effects (weather, bullet time) pass 'effect' */
1647
+ export type SharedLayer = 'engine' | 'style' | 'game' | 'effect' | 'system' | 'settings' | 'debug';
1648
+ /**
1649
+ * engine.mod options: exactly one of set / add / mul / clamp on a number point (set on a value point); none on a hold ('freeze') or a slot;
1650
+ * value on a 'top' point. Inside a layer: set, then add, then mul, then clamp; a higher layer's set hides what is below. Two owners setting one
1651
+ * point on one layer throw shared-conflict in development. The settings layer only restricts (clamp / mul; set false on a value point).
1652
+ */
1653
+ export interface ModOptions {
1654
+ owner: string;
1655
+ set?: any; add?: number; mul?: number; clamp?: { min?: number; max?: number };
1656
+ /** 'top' points (the camera): the holder's value; 'any' ones: optional data kept beside the hold */
1657
+ value?: any;
1658
+ /** Seconds until it ends by itself, on clock ('real' by default: fixed seconds, stop while frozen; or a time channel name) */
1659
+ for?: number; clock?: string;
1660
+ /** The record, for per-record points ('time.local', your own per: true ones) */
1661
+ id?: string;
1662
+ /** Default 'game'. settings / system / debug entries are not saved */
1663
+ layer?: SharedLayer;
1664
+ }
1665
+ /** One entry as describe and holders() show it; at = the code line that took it (development builds) */
1666
+ export interface ModHolder { owner: string; at?: string; op?: 'set' | 'add' | 'mul' | 'clamp'; value?: any; layer?: SharedLayer; left?: number; clock?: string; hidden?: boolean; }
1667
+ /** One describe().shared row: writer = the owner whose value the rest acts on ('default' when nobody set it; 'three (engine yielded)' after a direct three.js write) */
1668
+ export interface SharedRow { value: any; writer: string; layer?: SharedLayer; at?: string; how?: string; also: ModHolder[]; }
1669
+ /** One shared point (engine.stacks.get(name)): read it here; change it with engine.mod(name, { owner, ... }), the one way in. A settings row
1670
+ * restricts one with engine.settings.define(key, def, { limits: name }) */
1671
+ export interface Stack {
1672
+ readonly name: string; readonly kind: 'number' | 'value' | 'any' | 'top' | 'one';
1673
+ /** The describe().shared row */
1674
+ row(id?: string): SharedRow;
1675
+ /** Whoever applies this point to a three.js property saw an outside write: stop applying it (check yielded); describe says writer three */
1676
+ yieldToThree(at?: string | null): void;
1677
+ /** Hand a yielded point back to the layers */
1678
+ reclaim(): void;
1679
+ readonly yielded: boolean;
1680
+ /** The current value, always recomputed from base + the entries now present (a slot: the holder's name or null) */
1681
+ value(id?: string): any;
1682
+ holders(id?: string): ModHolder[];
1683
+ names(id?: string): string[];
1684
+ has(owner: string, id?: string): boolean;
1685
+ size(id?: string): number;
1686
+ /** End owner's entry; false when it held none */
1687
+ release(owner: string, opts?: { id?: string }): boolean;
1688
+ }
1689
+ /** engine.stacks: every shared point by name ('time.<channel>', 'time.local', 'clock.rate', 'freeze', 'pause', 'camera', 'debug.view', slots, your own) */
1690
+ export interface Stacks {
1691
+ /**
1692
+ * Define your own point: kind 'number' (default, base 1), 'value' (any data, set only), 'any' (true while held), 'top' (latest holder wins),
1693
+ * 'one' (exclusive slot); per: true = one value per record id; manual = the takeover call the conflict error offers
1593
1694
  */
1594
- now: number;
1695
+ define(name: string, opts?: { kind?: 'number' | 'value' | 'any' | 'top' | 'one'; base?: any; min?: number; max?: number; per?: boolean | 'optional'; save?: boolean; manual?: string }): Stack;
1696
+ get(name: string): Stack;
1697
+ has(name: string): boolean;
1698
+ list(): string[];
1699
+ mod(name: string, opts: ModOptions): ModHandle;
1700
+ /** describe().shared: one row per point with entries */
1701
+ describe(): Record<string, SharedRow>;
1702
+ /** Everything one owner changes now, e.g. ['time.world (mul 0.8, effect)', 'inventory (holds)'] */
1703
+ of(owner: string): string[];
1704
+ }
1705
+ /** engine.time: time channels (world, player, your own). Speeds change only through engine.mod('time.<channel>', ...) */
1706
+ export interface Time {
1707
+ /** Define a channel; parent (default 'world') multiplies its speed */
1708
+ channel(name: string, opts?: { parent?: string | null; stack?: string }): Time;
1709
+ channels(): string[];
1710
+ /** Effective speed: parent x the channel's stack (x the record's 'time.local' stack when id is given) */
1711
+ scale(name: string, id?: string): number;
1712
+ /** Fixed steps run this playthrough: the one time counter (= engine.tick); every other time is a read-only view of it */
1713
+ readonly tick: number;
1595
1714
  /**
1596
- * Game-time speed: game seconds per fixed-step second (default 1; the sky's time of day follows it). `engine.clock.timeScale = 60` makes a minute pass
1597
- * per second
1715
+ * Seconds on a view: 'real' (tick / 60, no scale, stops while frozen), 'ambient' (= uniforms.uTime, keeps moving while frozen),
1716
+ * 'calendar' (= engine.clock.now) or a channel ('world', 'player', your own)
1598
1717
  */
1599
- timeScale: number;
1600
- /** Call fn after seconds game seconds; if an event name is passed, the event is emitted when due (with data, can be saved) */
1601
- after(seconds: number, fnOrEvent: (() => void) | string, data?: any): Handle;
1602
- /** Call once every seconds game seconds */
1603
- every(seconds: number, fn: () => void): Handle;
1718
+ now(name: 'real' | 'ambient' | 'calendar' | 'world' | 'player' | (string & {})): number;
1719
+ /** This fixed step's dt on a channel (1/60 x scale). Change a speed with engine.mod('time.<channel>', { owner, set | mul }); timers: engine.clock.after(s, fn, data, { channel }) */
1720
+ dt(name: string, id?: string): number;
1604
1721
  }
1605
1722
  /** engine.vars: story flags and counters (autosaved) */
1606
1723
  export interface Vars {
@@ -1630,8 +1747,8 @@ export interface ContentConditionDef {
1630
1747
  ref?: ContentRef;
1631
1748
  /** One-line description */
1632
1749
  desc?: string;
1633
- /** Whether it holds: value is the value converted by ref, raw is the form written in the content */
1634
- test(e: Engine, value: any, raw?: any): boolean;
1750
+ /** Whether it holds: value is the value converted by ref, raw is the form written in the content, ctx.actor = who is asking (content.test's actor) */
1751
+ test(e: Engine, value: any, raw?: any, ctx?: { actor: string }): boolean;
1635
1752
  /** Write the value as human-readable text (for the game map) */
1636
1753
  describe?(value: any): string;
1637
1754
  }
@@ -1675,12 +1792,12 @@ export interface Content {
1675
1792
  * @example engine.content.load([baseContent, forestDlc], { places: { home } })
1676
1793
  */
1677
1794
  load(data: ContentPack | ContentPack[], opts?: ContentLoadOptions): this;
1678
- /** Register a custom condition, e.g. condition('timeAfter', { ref: 'clock', test: (e, t) => e.sky.timeOfDay >= t }) */
1795
+ /** Register a custom condition, e.g. condition('timeAfter', { ref: 'clock', test: (e, t) => e.calendar.timeOfDay >= t }) */
1679
1796
  condition(name: string, def: ContentConditionDef): this;
1680
- /** Whether a condition holds (object, array or function) */
1681
- test(cond: any): boolean;
1682
- /** Run an effect (object, array or function) */
1683
- run(effect: any): any;
1797
+ /** Whether a condition holds (object, array or function (e, { actor })); actor = whose bag has / lacks look in (default the running op's actor, else engine.actor) */
1798
+ test(cond: any, opts?: { actor?: string }): boolean;
1799
+ /** Run an effect (object, array or function (e, { actor })); actor = whose bag give / take change (default the running op's actor, else engine.actor) */
1800
+ run(effect: any, opts?: { actor?: string }): any;
1684
1801
  /** Place name -> position (load's places first, then level markers), null if none */
1685
1802
  place(name: string): XZ | null;
1686
1803
  /** Position form in content { place?, x?, z? } -> world coordinates */
@@ -1690,10 +1807,47 @@ export interface Content {
1690
1807
  * template('chest').container.capacity
1691
1808
  */
1692
1809
  template(name: string): Readonly<ContentTemplate>;
1810
+ /**
1811
+ * The fields one content entry may have (core/params.js spec format): what an editor panel lists and what content-check validates against.
1812
+ * name: a template name (placement fields plus its state fields, default = the value in state), an engine entry shape ('props', 'props.template',
1813
+ * 'props.grid', 'pickups', 'views'), a game kind that declares fields (content/rules.js kinds), or a world record id. Unknown names throw.
1814
+ * @example engine.content.fields('crop').stage // { type: 'int', optional: true, default: 0, min: 0, max: 4 }
1815
+ */
1816
+ fields(name: string): Record<string, ContentField>;
1817
+ /**
1818
+ * Place a new runtime instance of a content template (inside an op or a fixed step), saved whole; returns the world record (kind = template name,
1819
+ * id `<template>#<n>` unless fields.id is given). fields: id, rot, scale, y (height above ground), items (container start goods), state fields
1820
+ * (stage too, for a template with stages).
1821
+ * @example engine.ops.define('chest.build', { run: (e, { x, z }) => e.content.spawn('chest', { x, z }, { items: { stick: 3 } }).id })
1822
+ */
1823
+ spawn(name: string, at: any, fields?: { id?: string; rot?: number; scale?: number; y?: number; items?: Record<string, number>; [stateField: string]: any }): WorldRecord;
1824
+ }
1825
+ /** One stage of a template with stages: a named step it stays in for duration game seconds (clock.now), e.g. seed -> sprout -> ripe, cold -> armed */
1826
+ export interface ContentTemplateStage {
1827
+ name: string;
1828
+ /** Game seconds spent in this stage; only the last stage may leave it out (it stays there) */
1829
+ duration?: number;
1830
+ /** Multiplies the instance's scale while in this stage */
1831
+ scale?: number;
1832
+ /** Model name shown from this stage on (until a later stage names another); default the template's model */
1833
+ model?: string | any[];
1834
+ }
1835
+ /** template:stage event: a template instance entered a new stage by growing (several stages crossed at once give one event) */
1836
+ export interface TemplateStageEvent { id: string; template: string; stage: number; name: string }
1837
+ /** One field of a content entry (engine.content.fields): the core/params.js spec as plain data */
1838
+ export interface ContentField {
1839
+ type: 'string' | 'number' | 'int' | 'bool' | 'position' | 'id' | 'any' | 'object' | 'array' | 'function';
1840
+ optional?: boolean;
1841
+ /** Only for template state fields: the value written in state (never written inside fields) */
1842
+ default?: any;
1843
+ min?: number;
1844
+ max?: number;
1845
+ values?: any[];
1846
+ desc?: string;
1693
1847
  }
1694
1848
  /** A content template: shared definition of a reusable object (recipes/30-templates.md) */
1695
1849
  export interface ContentTemplate {
1696
- /** Model name (style pack generator or assets name); every instance clones one shared prototype */
1850
+ /** Model name (style generator or assets name); every instance clones one shared prototype */
1697
1851
  model: string | any[];
1698
1852
  /** Collision box or circle from the model's bounds; omitted = does not block */
1699
1853
  collide?: 'box' | 'circle';
@@ -1709,6 +1863,20 @@ export interface ContentTemplate {
1709
1863
  animate?: (rec: WorldRecord, obj: Object3D, dt: number) => void;
1710
1864
  /** Instance state fields and their defaults, copied onto each record (saved) */
1711
1865
  state?: Record<string, any>;
1866
+ /**
1867
+ * Range / allowed values / description of state fields, checked on every placement and engine.content.spawn (dev) and by content-check. No default here:
1868
+ * the default is the value in state. The type is inferred from that value when left out. e.g. { stage: { type: 'int', min: 0, max: 4 } }
1869
+ */
1870
+ fields?: Record<string, string | Omit<ContentField, 'default'>>;
1871
+ /**
1872
+ * Named stages over game time (a crop growing, a turret warming up, a building under construction). Each instance gets the state field stage
1873
+ * (default 0, int 0..n-1, placeable and saved) and stageAt (clock.now when it entered); it advances near and far, catching up after a load or a skip.
1874
+ */
1875
+ stages?: ContentTemplateStage[];
1876
+ /** Asked every step, near and far; false holds the current stage and the time blocked does not count (e.g. rec => rec.watered) */
1877
+ canGrow?: (rec: WorldRecord, e: Engine) => boolean;
1878
+ /** Gameplay per fixed step while near (world.simulate near); write record fields directly or with world.set, both are saved */
1879
+ update?: (rec: WorldRecord, dt: number, e: Engine) => void;
1712
1880
  }
1713
1881
 
1714
1882
  // ======================================================================
@@ -1807,17 +1975,19 @@ export interface HudMarker {
1807
1975
  /** Delete */
1808
1976
  remove(): void;
1809
1977
  }
1978
+ /** Screen corner / edge a counter or bar column sits at (default 'top-left'); each anchor stacks its own column */
1979
+ export type HudAnchor = 'top-left' | 'top' | 'top-right' | 'left' | 'right' | 'bottom-left' | 'bottom' | 'bottom-right';
1810
1980
  /** engine.hud: objective markers, counters, progress bars */
1811
1981
  export interface Hud {
1812
1982
  /** All markers */
1813
1983
  markers: HudMarker[];
1814
1984
  /** Add an objective marker: target is an object, position or place name */
1815
1985
  marker(target: HudTarget, opts?: HudMarkerOptions): HudMarker;
1816
- /** Counter (calling again with the same id = update; calling every frame is fine), e.g. counter('fish', { label: '鱼', value: 2, max: 5 }) */
1817
- counter(id: string, opts: { label?: string; icon?: string; value?: number; max?: number }): void;
1986
+ /** Counter or text status (calling again with the same id = update; calling every frame is fine): counter('fish', { label: '鱼', value: 2, max: 5 }), counter('clock', { value: '08:30' }); no value = the label alone */
1987
+ counter(id: string, opts: { label?: string; icon?: string; value?: number | string; max?: number; anchor?: HudAnchor }): void;
1818
1988
  /** Progress bar (calling again with the same id = update; calling every frame is fine, the DOM is untouched when the value is unchanged),
1819
1989
  * value/max 0–max */
1820
- bar(id: string, opts: { value: number; max?: number; label?: string }): void;
1990
+ bar(id: string, opts: { value: number; max?: number; label?: string; anchor?: HudAnchor }): void;
1821
1991
  /** Delete a counter or progress bar */
1822
1992
  remove(id: string): void;
1823
1993
  }