threedog 0.2.1 → 0.7.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 (725) hide show
  1. package/CHANGELOG.md +371 -1
  2. package/README.md +21 -12
  3. package/core/Animator.js +15 -12
  4. package/core/Assets.js +92 -26
  5. package/core/Audio.js +45 -38
  6. package/core/Baked.js +30 -15
  7. package/core/Batching.js +102 -15
  8. package/core/Budget.js +40 -19
  9. package/core/Clock.js +40 -80
  10. package/core/DebugOverrides.js +75 -25
  11. package/core/Describe.js +105 -45
  12. package/core/Engine.js +203 -75
  13. package/core/Events.js +4 -1
  14. package/core/I18n.js +25 -13
  15. package/core/Input.js +175 -80
  16. package/core/Inspect.js +8 -5
  17. package/core/InspectMaterials.js +84 -0
  18. package/core/InspectPerf.js +68 -0
  19. package/core/InspectScene.js +13 -2
  20. package/core/Loading.js +2 -1
  21. package/core/MaterialInfo.js +7 -5
  22. package/core/Ops.js +50 -9
  23. package/core/Random.js +9 -2
  24. package/core/Rays.js +12 -7
  25. package/core/SaveStore.js +41 -9
  26. package/core/Saves.js +71 -15
  27. package/core/Stream.js +13 -10
  28. package/core/Threads.js +26 -7
  29. package/core/UrlState.js +69 -13
  30. package/core/Views.js +10 -6
  31. package/core/actor.js +1 -1
  32. package/core/adaptive.js +93 -0
  33. package/core/assetEntry.js +27 -7
  34. package/core/assetHot.js +176 -0
  35. package/core/assetLoad.js +44 -19
  36. package/core/assetManifest.js +53 -11
  37. package/core/assetReport.js +5 -5
  38. package/core/audioRules.js +13 -11
  39. package/core/audioVoice.js +69 -42
  40. package/core/batchGroups.js +9 -1
  41. package/core/canvasBox.js +1 -2
  42. package/core/catalog.js +21 -5
  43. package/core/cells.js +62 -0
  44. package/core/checks.js +10 -8
  45. package/core/chunkStream.js +87 -0
  46. package/core/control.js +149 -0
  47. package/core/copies.js +32 -0
  48. package/core/dayTime.js +12 -6
  49. package/core/debugView.js +85 -18
  50. package/core/describeRender.js +117 -21
  51. package/core/describeText.js +41 -21
  52. package/core/engineCamera.js +32 -0
  53. package/core/errorCodes.js +478 -32
  54. package/core/errorHints.js +41 -142
  55. package/core/errors.js +31 -8
  56. package/core/events.generated.js +13 -7
  57. package/core/gameLights.js +69 -0
  58. package/core/grayMap.js +20 -0
  59. package/core/grid.js +14 -13
  60. package/core/gridLoad.js +2 -1
  61. package/core/ground.js +6 -4
  62. package/core/headlessLoad.js +55 -0
  63. package/core/holds.js +78 -50
  64. package/core/inputContext.js +11 -7
  65. package/core/inputDefaults.js +24 -21
  66. package/core/inputPad.js +1 -1
  67. package/core/inputPointer.js +1 -1
  68. package/core/inputTouch.js +2 -2
  69. package/core/lifecycle.js +46 -12
  70. package/core/lightWatch.js +9 -5
  71. package/core/loop.js +109 -43
  72. package/core/math.js +18 -3
  73. package/core/moduleSlots.js +100 -0
  74. package/core/moduleTypes.js +86 -0
  75. package/core/modules.js +147 -29
  76. package/core/movement.js +2 -2
  77. package/core/namedModel.js +74 -0
  78. package/core/opsCheck.js +3 -3
  79. package/core/opsFail.js +15 -6
  80. package/core/opsGuard.js +4 -4
  81. package/core/opsRun.js +4 -3
  82. package/core/owned.js +171 -0
  83. package/core/page.js +44 -10
  84. package/core/params.js +30 -8
  85. package/core/pictureSlots.js +33 -0
  86. package/core/pictureWriters.js +343 -0
  87. package/core/plugins.js +245 -0
  88. package/core/saveApply.js +99 -17
  89. package/core/saveFiles.js +8 -6
  90. package/core/saveValues.js +46 -0
  91. package/core/saveVersions.js +20 -3
  92. package/core/scatter.js +48 -19
  93. package/core/sceneDelta.js +211 -0
  94. package/core/sceneMethods.js +31 -33
  95. package/core/screenToGround.js +1 -1
  96. package/core/services.js +27 -11
  97. package/core/session.js +28 -25
  98. package/core/shaderCost.js +78 -0
  99. package/core/shadowTypes.js +3 -2
  100. package/core/shadows.js +405 -0
  101. package/core/sharedPoint.js +303 -0
  102. package/core/skip.js +36 -28
  103. package/core/stackFrames.js +45 -0
  104. package/core/stacks.js +166 -0
  105. package/core/startup.js +153 -13
  106. package/core/streamSources.js +0 -11
  107. package/core/targeting.js +1 -1
  108. package/core/textureBytes.js +20 -0
  109. package/core/thingExplain.js +3 -3
  110. package/core/thingOps.js +29 -6
  111. package/core/things.js +22 -12
  112. package/core/threadPure.js +7 -3
  113. package/core/threePatches.js +47 -0
  114. package/core/tier.js +21 -10
  115. package/core/time.js +236 -0
  116. package/core/uiClock.js +25 -0
  117. package/core/util.js +8 -2
  118. package/core/validate.js +66 -87
  119. package/core/view.js +43 -0
  120. package/core/wrap.js +106 -0
  121. package/docs/AI.md +95 -104
  122. package/docs/API.md +35 -31
  123. package/docs/CODEMAP.md +231 -176
  124. package/docs/COMMANDS.md +63 -39
  125. package/docs/CONVENTIONS.md +99 -31
  126. package/docs/MIGRATING-0.3.md +248 -0
  127. package/docs/MIGRATING-0.4.md +320 -0
  128. package/docs/MIGRATING-0.5.md +68 -0
  129. package/docs/MIGRATING-0.6.md +126 -0
  130. package/docs/MIGRATING-0.7.md +39 -0
  131. package/docs/PERF.md +35 -7
  132. package/docs/THREE.md +82 -28
  133. package/docs/api/ambience.md +0 -1
  134. package/docs/api/assets.md +15 -11
  135. package/docs/api/audio.md +10 -14
  136. package/docs/api/budget.md +4 -0
  137. package/docs/api/calendar.md +41 -0
  138. package/docs/api/cameraRig.md +16 -5
  139. package/docs/api/characters.md +41 -24
  140. package/docs/api/clock.md +6 -5
  141. package/docs/api/collision.md +10 -7
  142. package/docs/api/content.md +6 -4
  143. package/docs/api/dialogue.md +9 -9
  144. package/docs/api/engine.md +95 -65
  145. package/docs/api/events.md +20 -14
  146. package/docs/api/grids.md +10 -3
  147. package/docs/api/ground.md +1 -1
  148. package/docs/api/hud.md +5 -2
  149. package/docs/api/i18n.md +1 -1
  150. package/docs/api/input.md +13 -7
  151. package/docs/api/interactions.md +10 -6
  152. package/docs/api/inventory.md +17 -17
  153. package/docs/api/level.md +0 -2
  154. package/docs/api/lightPool.md +3 -1
  155. package/docs/api/music.md +1 -1
  156. package/docs/api/nav.md +3 -0
  157. package/docs/api/occlusion.md +5 -0
  158. package/docs/api/openWorld.md +2 -1
  159. package/docs/api/particles.md +6 -3
  160. package/docs/api/photo.md +0 -2
  161. package/docs/api/pickups.md +21 -0
  162. package/docs/api/post.md +8 -5
  163. package/docs/api/quests.md +2 -3
  164. package/docs/api/rigid.md +16 -14
  165. package/docs/api/saves.md +6 -4
  166. package/docs/api/settings.md +2 -3
  167. package/docs/api/sky.md +18 -49
  168. package/docs/api/stream.md +1 -1
  169. package/docs/api/terrain.md +16 -7
  170. package/docs/api/terrainDraw.md +12 -0
  171. package/docs/api/timeline.md +3 -4
  172. package/docs/api/tools.md +32 -15
  173. package/docs/api/triggers.md +7 -10
  174. package/docs/api/vegetation.md +17 -9
  175. package/docs/api/vegetationDraw.md +10 -0
  176. package/docs/api/water.md +9 -21
  177. package/docs/api/weather.md +10 -15
  178. package/docs/api/weatherDraw.md +10 -0
  179. package/docs/api/world.md +3 -2
  180. package/docs/recipes/01-new-game.md +52 -42
  181. package/docs/recipes/02-npc.md +24 -7
  182. package/docs/recipes/03-items-pickups.md +57 -22
  183. package/docs/recipes/04-quests.md +12 -5
  184. package/docs/recipes/05-props-bake.md +174 -22
  185. package/docs/recipes/06-clock-events.md +100 -52
  186. package/docs/recipes/07-flow-scenes-pause.md +50 -10
  187. package/docs/recipes/08-weather-sky.md +134 -37
  188. package/docs/recipes/09-materials-lights-models.md +185 -0
  189. package/docs/recipes/10-blender-level.md +16 -4
  190. package/docs/recipes/11-vehicles.md +67 -10
  191. package/docs/recipes/13-animation.md +23 -9
  192. package/docs/recipes/14-custom-module.md +63 -29
  193. package/docs/recipes/15-perf.md +31 -10
  194. package/docs/recipes/16-dev-bridge.md +74 -40
  195. package/docs/recipes/18-world.md +26 -14
  196. package/docs/recipes/19-shooting-picking.md +12 -10
  197. package/docs/recipes/20-content-actions-save.md +60 -18
  198. package/docs/recipes/21-camera.md +55 -17
  199. package/docs/recipes/22-shop-gold.md +3 -3
  200. package/docs/recipes/23-ops.md +17 -11
  201. package/docs/recipes/26-ui-parts.md +86 -13
  202. package/docs/recipes/27-net.md +11 -5
  203. package/docs/recipes/28-terrain.md +36 -3
  204. package/docs/recipes/29-grid.md +46 -19
  205. package/docs/recipes/30-templates.md +72 -15
  206. package/docs/recipes/31-audio.md +20 -12
  207. package/docs/recipes/32-action-game.md +51 -4
  208. package/docs/recipes/34-environment-lighting.md +108 -21
  209. package/docs/recipes/35-picture-from-reference.md +147 -0
  210. package/docs/recipes/36-sky-ground-plants.md +158 -0
  211. package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -12
  212. package/docs/recipes/38-environment-hooks.md +67 -0
  213. package/docs/recipes/40-scene.md +114 -32
  214. package/docs/recipes/42-terrain-shape.md +2 -2
  215. package/docs/recipes/43-shader-patches-surfaces.md +206 -0
  216. package/docs/recipes/44-water-weather-hooks.md +191 -0
  217. package/docs/recipes/45-cascaded-shadows.md +130 -23
  218. package/docs/recipes/46-blender-art-route.md +17 -20
  219. package/docs/recipes/47-island-snow-backdrop.md +13 -15
  220. package/docs/recipes/49-game-module-contract.md +30 -17
  221. package/docs/recipes/50-own-renderer.md +4 -4
  222. package/docs/recipes/51-capability-catalog.md +3 -3
  223. package/docs/recipes/52-around-the-picture.md +181 -0
  224. package/docs/recipes/53-ground-up-close.md +12 -12
  225. package/docs/recipes/54-three-idioms.md +88 -0
  226. package/docs/recipes/55-mods-time-wrap.md +124 -0
  227. package/docs/recipes/56-webgpu-tsl.md +303 -0
  228. package/docs/recipes/57-control.md +104 -0
  229. package/docs/recipes/58-input.md +60 -0
  230. package/docs/recipes/59-depth-post-effects.md +83 -0
  231. package/docs/recipes/60-judge-the-picture.md +70 -0
  232. package/docs/recipes/61-deploy.md +27 -0
  233. package/docs/recipes/62-picture-code.md +244 -0
  234. package/docs/recipes/63-third-person-start.md +77 -0
  235. package/docs/recipes/64-particles.md +35 -0
  236. package/examples/action/.threedog/content-index.json +1 -0
  237. package/examples/action/GAMEMAP.md +20 -14
  238. package/examples/action/assets.js +8 -0
  239. package/examples/action/content/actions.js +1 -1
  240. package/examples/action/content/audio.js +5 -5
  241. package/examples/action/main.js +12 -15
  242. package/examples/action/models.js +23 -24
  243. package/examples/action/picture/index.js +13 -0
  244. package/examples/action/picture/lights.js +35 -0
  245. package/examples/action/picture/materials.js +8 -0
  246. package/examples/action/picture/palette.js +33 -0
  247. package/examples/plain-picture/.threedog/content-index.json +1 -0
  248. package/examples/plain-picture/FINDINGS.md +53 -0
  249. package/examples/plain-picture/GAMEMAP.md +90 -0
  250. package/examples/plain-picture/main.js +48 -0
  251. package/examples/plain-picture/picture/index.js +21 -0
  252. package/examples/plain-picture/picture/lights.js +54 -0
  253. package/examples/plain-picture/picture/materials.js +24 -0
  254. package/examples/plain-picture/picture/palette.js +16 -0
  255. package/examples/plain-picture/picture/sky.js +37 -0
  256. package/examples/pullable.json +133 -0
  257. package/examples/rc2d/.threedog/content-index.json +1 -0
  258. package/examples/rc2d/GAMEMAP.md +88 -0
  259. package/examples/rc2d/README.md +57 -0
  260. package/examples/rc2d/main.js +55 -0
  261. package/examples/rc2d/picture/index.js +18 -0
  262. package/examples/rc2d/picture/lights.js +11 -0
  263. package/examples/rc2d/picture/materials.js +18 -0
  264. package/examples/rc2d/picture/palette.js +15 -0
  265. package/examples/rc2d/picture/post.js +11 -0
  266. package/examples/rc2d/rc2d.js +187 -0
  267. package/examples/rc2d/shaders.js +144 -0
  268. package/examples/sheepisland/.threedog/content-index.json +1 -0
  269. package/examples/sheepisland/GAMEMAP.md +22 -17
  270. package/examples/sheepisland/assets.js +5 -0
  271. package/examples/sheepisland/content/templates.js +1 -1
  272. package/examples/sheepisland/content/vegetation.js +3 -1
  273. package/examples/sheepisland/main.js +29 -18
  274. package/examples/sheepisland/{style/models.js → models.js} +13 -24
  275. package/examples/sheepisland/picture/index.js +20 -0
  276. package/examples/sheepisland/picture/lights.js +34 -0
  277. package/examples/sheepisland/picture/materials.js +61 -0
  278. package/examples/sheepisland/picture/palette.js +60 -0
  279. package/examples/sheepisland/picture/sky.js +20 -0
  280. package/examples/sheepisland/views.js +1 -1
  281. package/examples/styletest/.threedog/content-index.json +1 -0
  282. package/examples/styletest/GAMEMAP.md +25 -22
  283. package/examples/styletest/assets.js +6 -0
  284. package/examples/styletest/content/templates.js +1 -1
  285. package/examples/styletest/content/vegetation.js +1 -1
  286. package/examples/styletest/main.js +25 -34
  287. package/examples/styletest/models.js +30 -30
  288. package/examples/styletest/params.js +2 -5
  289. package/examples/styletest/picture/env.js +38 -0
  290. package/examples/styletest/picture/index.js +16 -0
  291. package/examples/styletest/picture/lights.js +9 -0
  292. package/examples/styletest/picture/materials.js +28 -0
  293. package/examples/styletest/picture/palette.js +22 -0
  294. package/examples/techniques/contact-shadows/README.md +91 -0
  295. package/examples/techniques/contact-shadows/contactShadows.js +67 -0
  296. package/examples/techniques/contact-shadows/main.js +55 -0
  297. package/examples/techniques/contact-shadows/picture/index.js +14 -0
  298. package/examples/techniques/contact-shadows/picture/lights.js +34 -0
  299. package/examples/techniques/contact-shadows/picture/materials.js +12 -0
  300. package/examples/techniques/contact-shadows/picture/palette.js +17 -0
  301. package/examples/techniques/day-night-grade/README.md +83 -0
  302. package/examples/techniques/day-night-grade/main.js +41 -0
  303. package/examples/techniques/day-night-grade/picture/index.js +20 -0
  304. package/examples/techniques/day-night-grade/picture/lights.js +45 -0
  305. package/examples/techniques/day-night-grade/picture/materials.js +15 -0
  306. package/examples/techniques/day-night-grade/picture/palette.js +59 -0
  307. package/examples/techniques/day-night-grade/picture/post.js +25 -0
  308. package/examples/techniques/day-night-grade/picture/sky.js +33 -0
  309. package/examples/techniques/interior-light/README.md +106 -0
  310. package/examples/techniques/interior-light/interiorLight.js +47 -0
  311. package/examples/techniques/interior-light/main.js +87 -0
  312. package/examples/techniques/interior-light/picture/index.js +24 -0
  313. package/examples/techniques/interior-light/picture/lights.js +52 -0
  314. package/examples/techniques/interior-light/picture/materials.js +13 -0
  315. package/examples/techniques/interior-light/picture/palette.js +32 -0
  316. package/examples/techniques/interior-light/picture/sky.js +40 -0
  317. package/examples/techniques/modular-building/README.md +126 -0
  318. package/examples/techniques/modular-building/kit.js +426 -0
  319. package/examples/techniques/modular-building/main.js +39 -0
  320. package/examples/techniques/modular-building/picture/index.js +17 -0
  321. package/examples/techniques/modular-building/picture/lights.js +26 -0
  322. package/examples/techniques/modular-building/picture/materials.js +13 -0
  323. package/examples/techniques/modular-building/picture/palette.js +23 -0
  324. package/examples/techniques/night-lights/README.md +95 -0
  325. package/examples/techniques/night-lights/main.js +47 -0
  326. package/examples/techniques/night-lights/nightLights.js +95 -0
  327. package/examples/techniques/night-lights/picture/index.js +18 -0
  328. package/examples/techniques/night-lights/picture/lights.js +44 -0
  329. package/examples/techniques/night-lights/picture/materials.js +15 -0
  330. package/examples/techniques/night-lights/picture/palette.js +34 -0
  331. package/examples/techniques/night-lights/picture/post.js +9 -0
  332. package/examples/techniques/night-lights/picture/sky.js +36 -0
  333. package/examples/techniques/outlines-and-rim/README.md +59 -0
  334. package/examples/techniques/outlines-and-rim/main.js +61 -0
  335. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  336. package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
  337. package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
  338. package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
  339. package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
  340. package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
  341. package/examples/techniques/procedural-animation/README.md +79 -0
  342. package/examples/techniques/procedural-animation/creature.js +44 -0
  343. package/examples/techniques/procedural-animation/main.js +47 -0
  344. package/examples/techniques/procedural-animation/picture/index.js +15 -0
  345. package/examples/techniques/procedural-animation/picture/lights.js +35 -0
  346. package/examples/techniques/procedural-animation/picture/materials.js +10 -0
  347. package/examples/techniques/procedural-animation/picture/palette.js +16 -0
  348. package/examples/techniques/procedural-animation/picture/sky.js +31 -0
  349. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  350. package/examples/techniques/procedural-surface/README.md +69 -0
  351. package/examples/techniques/procedural-surface/main.js +65 -0
  352. package/examples/techniques/procedural-surface/picture/index.js +14 -0
  353. package/examples/techniques/procedural-surface/picture/lights.js +18 -0
  354. package/examples/techniques/procedural-surface/picture/materials.js +34 -0
  355. package/examples/techniques/procedural-surface/picture/palette.js +15 -0
  356. package/examples/techniques/procedural-surface/surface.js +120 -0
  357. package/examples/techniques/stylized-shading/README.md +74 -0
  358. package/examples/techniques/stylized-shading/main.js +62 -0
  359. package/examples/techniques/stylized-shading/picture/index.js +14 -0
  360. package/examples/techniques/stylized-shading/picture/lights.js +23 -0
  361. package/examples/techniques/stylized-shading/picture/materials.js +18 -0
  362. package/examples/techniques/stylized-shading/picture/palette.js +19 -0
  363. package/examples/techniques/stylized-shading/shading.js +131 -0
  364. package/examples/techniques/sun-and-key-light/README.md +133 -0
  365. package/examples/techniques/sun-and-key-light/keyLight.js +71 -0
  366. package/examples/techniques/sun-and-key-light/main.js +51 -0
  367. package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
  368. package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
  369. package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
  370. package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
  371. package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
  372. package/examples/techniques/three-looks/README.md +21 -0
  373. package/examples/techniques/three-looks/main.js +58 -0
  374. package/examples/techniques/three-looks/picture/cartoon.js +23 -0
  375. package/examples/techniques/three-looks/picture/cinematic.js +27 -0
  376. package/examples/techniques/three-looks/picture/comic.js +27 -0
  377. package/examples/techniques/three-looks/picture/index.js +14 -0
  378. package/examples/techniques/three-looks/picture/sun.js +23 -0
  379. package/examples/techniques/wet-road/README.md +102 -0
  380. package/examples/techniques/wet-road/main.js +48 -0
  381. package/examples/techniques/wet-road/picture/index.js +17 -0
  382. package/examples/techniques/wet-road/picture/lights.js +57 -0
  383. package/examples/techniques/wet-road/picture/materials.js +16 -0
  384. package/examples/techniques/wet-road/picture/palette.js +24 -0
  385. package/examples/techniques/wet-road/picture/sky.js +46 -0
  386. package/examples/techniques/wet-road/wetRoad.js +209 -0
  387. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  388. package/examples/webgpu-tsl/GAMEMAP.md +89 -0
  389. package/examples/webgpu-tsl/README.md +45 -0
  390. package/examples/webgpu-tsl/main.js +44 -0
  391. package/examples/webgpu-tsl/picture/index.js +18 -0
  392. package/examples/webgpu-tsl/picture/lights.js +25 -0
  393. package/examples/webgpu-tsl/picture/materials.js +36 -0
  394. package/examples/webgpu-tsl/picture/palette.js +23 -0
  395. package/examples/webgpu-tsl/picture/post.js +16 -0
  396. package/examples/webgpu-tsl/picture/sky.js +30 -0
  397. package/examples/world/.threedog/content-index.json +1 -0
  398. package/examples/world/GAMEMAP.md +31 -21
  399. package/examples/world/art/humanoid.js +38 -0
  400. package/examples/world/art/index.js +11 -0
  401. package/examples/world/art/models.js +57 -0
  402. package/examples/world/art/shapes.js +9 -0
  403. package/examples/world/assets.js +6 -0
  404. package/examples/world/content/audio.js +5 -5
  405. package/examples/world/content/items.js +1 -1
  406. package/examples/world/content/npcs.js +1 -1
  407. package/examples/world/content/props.js +1 -1
  408. package/examples/world/content/rules.js +1 -1
  409. package/examples/world/content/templates.js +1 -1
  410. package/examples/world/content/vegetation.js +1 -1
  411. package/examples/world/main.js +22 -18
  412. package/examples/world/models.js +17 -7
  413. package/examples/world/picture/index.js +20 -0
  414. package/examples/world/picture/lights.js +41 -0
  415. package/examples/world/picture/materials.js +34 -0
  416. package/examples/world/picture/palette.js +74 -0
  417. package/examples/world/picture/post.js +9 -0
  418. package/examples/world/picture/sky.js +39 -0
  419. package/index.d.ts +44 -54
  420. package/index.js +29 -25
  421. package/llms.txt +24 -15
  422. package/modules/ambience/Ambience.js +34 -23
  423. package/modules/calendar/Calendar.js +163 -0
  424. package/modules/calendar/contract.js +21 -0
  425. package/modules/calendar/index.js +82 -0
  426. package/modules/{sky → calendar}/schedule.js +17 -16
  427. package/modules/calendar/seasons.js +55 -0
  428. package/modules/camera/FirstPersonCamera.js +6 -15
  429. package/modules/camera/FixedCamera.js +33 -15
  430. package/modules/camera/FollowCamera.js +90 -16
  431. package/modules/camera/RtsCamera.js +18 -17
  432. package/modules/camera/common.js +73 -20
  433. package/modules/camera/contract.js +17 -0
  434. package/modules/camera/projection.js +11 -24
  435. package/modules/characters/Character.js +188 -48
  436. package/modules/characters/NPC.js +92 -41
  437. package/modules/characters/assetModel.js +8 -16
  438. package/modules/characters/behaviors.js +2 -1
  439. package/modules/characters/contract.js +13 -0
  440. package/modules/characters/footsteps.js +1 -1
  441. package/modules/characters/index.js +112 -49
  442. package/modules/characters/moveHelpers.js +4 -5
  443. package/modules/characters/movers/common.js +102 -19
  444. package/modules/characters/movers/manual.js +23 -0
  445. package/modules/characters/movers/rapier.js +19 -16
  446. package/modules/characters/movers/simple.js +14 -11
  447. package/modules/characters/movers/support.js +186 -0
  448. package/modules/characters/npcAvoid.js +47 -42
  449. package/modules/characters/npcSim.js +17 -9
  450. package/modules/characters/npcView.js +44 -16
  451. package/modules/characters/pathAsync.js +7 -3
  452. package/modules/characters/playerStrings.js +4 -3
  453. package/modules/characters/proceduralRig.js +19 -4
  454. package/modules/characters/useModel.js +2 -2
  455. package/modules/characters/vehicle.contract.js +21 -0
  456. package/modules/characters/walkTo.js +21 -7
  457. package/modules/collision/Collision.js +69 -27
  458. package/modules/collision/grid.js +8 -6
  459. package/modules/content/explain.js +2 -2
  460. package/modules/content/fields.js +102 -0
  461. package/modules/content/ids.js +8 -6
  462. package/modules/content/index.js +104 -27
  463. package/modules/content/loader.js +45 -33
  464. package/modules/content/models.js +58 -42
  465. package/modules/content/packs.js +6 -5
  466. package/modules/content/parts.js +41 -0
  467. package/modules/content/props.js +20 -11
  468. package/modules/content/rules.js +66 -0
  469. package/modules/content/stages.js +80 -0
  470. package/modules/content/templates.js +123 -30
  471. package/modules/debug/DebugPanel.js +24 -17
  472. package/modules/flow/contract.js +16 -0
  473. package/modules/flow/index.js +21 -15
  474. package/modules/gameplay/Container.js +41 -32
  475. package/modules/gameplay/Containers.js +30 -15
  476. package/modules/gameplay/Dialogue.js +113 -55
  477. package/modules/gameplay/Interactions.js +273 -72
  478. package/modules/gameplay/Inventory.js +72 -76
  479. package/modules/gameplay/Quests.js +75 -39
  480. package/modules/gameplay/boxOps.js +3 -3
  481. package/modules/gameplay/dialogue.contract.js +21 -0
  482. package/modules/gameplay/dialogueBox.js +4 -2
  483. package/modules/gameplay/dialogueBubbles.js +116 -0
  484. package/modules/gameplay/interactionPrompt.js +4 -1
  485. package/modules/gameplay/interactions.contract.js +16 -0
  486. package/modules/gameplay/inventory.contract.js +23 -0
  487. package/modules/gameplay/inventoryOps.js +19 -17
  488. package/modules/gameplay/pickups.js +306 -85
  489. package/modules/gameplay/questLog.js +6 -6
  490. package/modules/gameplay/quests.contract.js +17 -0
  491. package/modules/grid/Grid.js +92 -50
  492. package/modules/grid/Layer.js +27 -13
  493. package/modules/grid/index.js +96 -43
  494. package/modules/grid/ops.js +20 -18
  495. package/modules/grid/preview.js +37 -29
  496. package/modules/grid/strings.js +12 -0
  497. package/modules/grid/tiles.js +19 -22
  498. package/modules/hlod/index.js +52 -19
  499. package/modules/hud/index.js +48 -20
  500. package/modules/hud/parts.js +28 -13
  501. package/modules/level/heightfield.js +3 -1
  502. package/modules/level/index.js +49 -23
  503. package/modules/level/nodes.js +4 -3
  504. package/modules/lights/index.js +47 -19
  505. package/modules/music/Music.js +38 -21
  506. package/modules/music/rules.js +1 -1
  507. package/modules/nav/index.js +48 -42
  508. package/modules/net/Client.js +13 -6
  509. package/modules/net/Host.js +19 -5
  510. package/modules/net/Net.js +2 -1
  511. package/modules/net/index.js +13 -8
  512. package/modules/net/sync.js +9 -8
  513. package/modules/net/transports.js +77 -27
  514. package/modules/particles/Particles.js +58 -28
  515. package/modules/particles/contract.js +17 -0
  516. package/modules/particles/effect.js +54 -11
  517. package/modules/photo/Photo.js +56 -38
  518. package/modules/rigid/RigidBodies.js +194 -32
  519. package/modules/rigid/Vehicles.js +18 -15
  520. package/modules/rigid/sync.js +62 -17
  521. package/modules/settings/Settings.js +60 -55
  522. package/modules/settings/apply.js +38 -3
  523. package/modules/settings/sections.js +5 -3
  524. package/modules/settings/strings.js +3 -2
  525. package/modules/settings/view.js +5 -3
  526. package/modules/sky/Sky.js +132 -205
  527. package/modules/sky/clouds.js +37 -23
  528. package/modules/sky/dome.js +100 -0
  529. package/modules/sky/domeLayers.js +30 -15
  530. package/modules/sky/environment.js +45 -99
  531. package/modules/sky/fog.js +9 -139
  532. package/modules/sky/frame.js +60 -56
  533. package/modules/sky/season.js +21 -0
  534. package/modules/sky/shader.js +63 -35
  535. package/modules/sky/skyModule.js +52 -37
  536. package/modules/sky/tint.js +59 -0
  537. package/modules/terrain/ChunkManager.js +194 -110
  538. package/modules/terrain/chunkJob.js +1 -1
  539. package/modules/terrain/chunkQueries.js +6 -4
  540. package/modules/terrain/draw.js +154 -0
  541. package/modules/terrain/index.js +87 -54
  542. package/modules/terrain/terrainDefaults.js +2 -2
  543. package/modules/terrain/terrainEdit.js +18 -20
  544. package/modules/terrain/terrainGen.js +6 -4
  545. package/modules/terrain/terrainIsland.js +5 -4
  546. package/modules/terrain/terrainShape.js +12 -12
  547. package/modules/terrain/terrainShapeMain.js +8 -7
  548. package/modules/terrain/terrainTexture.js +21 -19
  549. package/modules/timeline/Timeline.js +95 -43
  550. package/modules/timeline/Tween.js +18 -10
  551. package/modules/timeline/letterbox.js +2 -2
  552. package/modules/timeline/shots.js +5 -1
  553. package/modules/triggers/index.js +111 -76
  554. package/modules/vegetation/Vegetation.js +229 -112
  555. package/modules/vegetation/densityMap.js +62 -0
  556. package/modules/vegetation/draw.js +191 -0
  557. package/modules/vegetation/groundChunks.js +52 -58
  558. package/modules/vegetation/index.js +32 -11
  559. package/modules/vegetation/modelGeometry.js +3 -2
  560. package/modules/vegetation/nearFade.js +8 -2
  561. package/modules/water/Water.js +157 -72
  562. package/modules/water/surface.js +86 -47
  563. package/modules/weather/Weather.js +96 -103
  564. package/modules/weather/particles.js +37 -14
  565. package/modules/weather/shaders.js +1 -1
  566. package/modules/weather/strings.js +2 -2
  567. package/modules/weather/weatherDraw.js +141 -0
  568. package/modules/world/World.js +26 -9
  569. package/modules/world/explain.js +1 -1
  570. package/modules/world/index.js +18 -4
  571. package/modules/world/persist.js +62 -2
  572. package/modules/world/pos.js +3 -2
  573. package/modules/world/records.js +8 -6
  574. package/modules/world/sim.js +60 -20
  575. package/modules/world/simFar.js +4 -3
  576. package/modules/world/state.js +3 -2
  577. package/modules/world/thingSource.js +1 -1
  578. package/modules/world/views.js +8 -6
  579. package/package.json +8 -3
  580. package/presets.js +43 -29
  581. package/render/PostFX.js +318 -135
  582. package/render/backend.js +486 -0
  583. package/render/cascades.js +195 -0
  584. package/render/cascades.tsl.js +96 -0
  585. package/render/daylight.js +39 -0
  586. package/render/detail.js +122 -41
  587. package/render/effects.js +155 -48
  588. package/render/engineUniforms.js +10 -1
  589. package/render/fuse.js +5 -4
  590. package/render/fx/cel.tsl.js +42 -0
  591. package/render/fx/cloudShadow.tsl.js +16 -0
  592. package/render/fx/detail.tsl.js +66 -0
  593. package/render/fx/index.js +28 -0
  594. package/render/fx/lighting.tsl.js +28 -0
  595. package/render/fx/nodeErrors.tsl.js +68 -0
  596. package/render/fx/noise.tsl.js +12 -0
  597. package/render/fx/objectOrigin.tsl.js +42 -0
  598. package/render/fx/particles.tsl.js +139 -0
  599. package/render/fx/patchNodes.tsl.js +403 -0
  600. package/render/fx/postWebGPU.tsl.js +181 -0
  601. package/render/fx/season.tsl.js +13 -0
  602. package/render/fx/sky.tsl.js +187 -0
  603. package/render/fx/uniforms.tsl.js +67 -0
  604. package/render/fx/water.tsl.js +53 -0
  605. package/render/fx/wind.tsl.js +22 -0
  606. package/render/fxNumbers.js +36 -0
  607. package/render/hotGlsl.js +24 -0
  608. package/render/layers.js +14 -0
  609. package/render/lighting.js +71 -18
  610. package/render/lightmap.js +142 -0
  611. package/render/lights.js +47 -6
  612. package/render/materials.js +55 -152
  613. package/render/modeling.js +73 -0
  614. package/render/neutral.js +23 -0
  615. package/render/occlusion.js +184 -0
  616. package/render/ownFrame.js +76 -0
  617. package/render/patches.js +317 -35
  618. package/render/postWebGL.js +205 -0
  619. package/render/probes.js +288 -0
  620. package/render/shaderErrors.js +154 -0
  621. package/render/slots.js +165 -0
  622. package/render/terms.js +163 -0
  623. package/render/uniformDecl.js +4 -3
  624. package/types/common.d.ts +2 -2
  625. package/types/core.d.ts +757 -346
  626. package/types/gameplay.d.ts +539 -330
  627. package/types/generated/core/Audio.d.ts +26 -42
  628. package/types/generated/core/Batching.d.ts +6 -2
  629. package/types/generated/core/Budget.d.ts +2 -8
  630. package/types/generated/core/DebugOverrides.d.ts +58 -9
  631. package/types/generated/core/I18n.d.ts +2 -2
  632. package/types/generated/core/Input.d.ts +110 -32
  633. package/types/generated/core/Ops.d.ts +31 -0
  634. package/types/generated/core/Random.d.ts +2 -2
  635. package/types/generated/core/Saves.d.ts +10 -2
  636. package/types/generated/core/Stream.d.ts +1 -1
  637. package/types/generated/core/Threads.d.ts +4 -1
  638. package/types/generated/core/Views.d.ts +0 -1
  639. package/types/generated/core/audioVoice.d.ts +17 -9
  640. package/types/generated/core/control.d.ts +55 -0
  641. package/types/generated/core/page.d.ts +9 -2
  642. package/types/generated/core/session.d.ts +2 -1
  643. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  644. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  645. package/types/generated/modules/calendar/index.d.ts +10 -0
  646. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  647. package/types/generated/modules/grid/Grid.d.ts +61 -25
  648. package/types/generated/modules/grid/Layer.d.ts +13 -5
  649. package/types/generated/modules/grid/index.d.ts +56 -20
  650. package/types/generated/modules/music/Music.d.ts +5 -3
  651. package/types/generated/modules/net/index.d.ts +3 -3
  652. package/types/generated/modules/net/transports.d.ts +12 -3
  653. package/types/generated/modules/particles/Particles.d.ts +13 -6
  654. package/types/generated/modules/sky/Sky.d.ts +85 -110
  655. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  656. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  657. package/types/generated/modules/water/Water.d.ts +50 -3
  658. package/types/generated/modules/weather/Weather.d.ts +44 -15
  659. package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
  660. package/types/generated/modules/world/World.d.ts +20 -5
  661. package/types/generated/render/PostFX.d.ts +109 -29
  662. package/types/generated/render/lighting.d.ts +29 -0
  663. package/types/generated/render/materials.d.ts +31 -50
  664. package/types/generated/render/modeling.d.ts +30 -0
  665. package/types/generated/render/occlusion.d.ts +13 -0
  666. package/types/generated/render/patches.d.ts +16 -2
  667. package/types/generated/ui/UI.d.ts +6 -3
  668. package/types/nav.d.ts +6 -0
  669. package/types/physics.d.ts +140 -45
  670. package/types/tsl.d.ts +94 -0
  671. package/types/world.d.ts +489 -122
  672. package/ui/Focus.js +35 -14
  673. package/ui/LoadingScreen.js +3 -3
  674. package/ui/Parts.js +35 -15
  675. package/ui/UI.js +27 -17
  676. package/ui/cursor.js +115 -0
  677. package/ui/defaults.js +15 -11
  678. package/ui/theme.js +36 -27
  679. package/ui/touchPart.js +2 -2
  680. package/core/claims.js +0 -51
  681. package/core/look/coreParts.js +0 -112
  682. package/core/look/layers.js +0 -136
  683. package/core/look/part.js +0 -173
  684. package/core/look/report.js +0 -79
  685. package/core/look/write.js +0 -86
  686. package/core/renamed.js +0 -22
  687. package/core/styleParts.js +0 -98
  688. package/docs/api/entities.md +0 -61
  689. package/docs/api/style.md +0 -134
  690. package/docs/recipes/09-style-pack.md +0 -169
  691. package/docs/recipes/35-style-from-reference.md +0 -84
  692. package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
  693. package/docs/recipes/38-environment-look-hooks.md +0 -88
  694. package/docs/recipes/41-thing-registry.md +0 -93
  695. package/docs/recipes/43-shader-patches-surface-looks.md +0 -135
  696. package/docs/recipes/44-water-weather-look-hooks.md +0 -135
  697. package/docs/recipes/48-make-material.md +0 -70
  698. package/docs/recipes/52-look.md +0 -146
  699. package/examples/action/look.js +0 -5
  700. package/examples/sheepisland/style/index.js +0 -79
  701. package/examples/styletest/look.js +0 -11
  702. package/examples/styletest/overrides.js +0 -33
  703. package/examples/styletest/panel.js +0 -135
  704. package/modules/entities/Entities.js +0 -243
  705. package/modules/entities/build.js +0 -25
  706. package/modules/entities/index.js +0 -4
  707. package/modules/sky/calendar.js +0 -80
  708. package/modules/sky/cascades.js +0 -125
  709. package/modules/sky/layers.js +0 -69
  710. package/modules/sky/look.js +0 -51
  711. package/modules/sky/lookFog.js +0 -80
  712. package/modules/sky/lookShadow.js +0 -50
  713. package/modules/sky/lookSky.js +0 -108
  714. package/modules/sky/shadow.js +0 -74
  715. package/modules/terrain/chunkLevels.js +0 -40
  716. package/modules/terrain/lookGround.js +0 -61
  717. package/modules/terrain/mountTerrain.js +0 -32
  718. package/modules/vegetation/lookWind.js +0 -37
  719. package/modules/water/look.js +0 -80
  720. package/modules/weather/look.js +0 -75
  721. package/modules/world/cells.js +0 -42
  722. package/render/lookSurface.js +0 -161
  723. package/render/postLook.js +0 -86
  724. package/render/surface.js +0 -69
  725. package/types/style.d.ts +0 -643
@@ -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
- import type { Object3D, Vector3, Vector2, Quaternion, Texture, ColorLike, Vec3Like, Ease, Handle, Range, XZ, Loose, PositionLike } from './common';
3
+ import type { Object3D, Vector3, Vector2, Quaternion, Texture, ColorLike, Vec3Like, Ease, Handle, Range, XZ, Loose, PositionLike, Material } 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()
@@ -113,16 +112,12 @@ export interface LevelLoadedEvent { root: Object3D; markers: Record<string, Leve
113
112
  export interface Level {
114
113
  /** Scene root node */
115
114
  root: Object3D | null;
116
- /** Same as root (the name consistent with player.object and ent.object) */
117
- readonly object: Object3D | null;
118
115
  /** All markers: name -> marker */
119
116
  markers: Record<string, LevelMarker>;
120
117
  /** Spawn point position */
121
118
  spawn: Vector3;
122
119
  /** Heightfield (for debugging) */
123
120
  heightfield: any;
124
- /** Milliseconds spent building the heightfield */
125
- buildMs?: number;
126
121
  /** Whether loading is finished */
127
122
  readonly ready: boolean;
128
123
  /** Get a marker, null if none */
@@ -162,20 +157,26 @@ export interface TriggerOptions {
162
157
  height?: number;
163
158
  /** Box rotation around the Y axis (radians) */
164
159
  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;
160
+ /**
161
+ * 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,
162
+ * object.userData.id, null for a bare position)
163
+ */
164
+ onEnter?: ((t: Trigger, who: Vector3, id: string | null) => void) | null;
165
+ /** Called on leaving; id = who was inside */
166
+ onExit?: ((t: Trigger, who: Vector3 | null, id: string | null) => void) | null;
169
167
  /** Called every fixed step while inside (dt in seconds) */
170
- onStay?: ((dt: number, t: Trigger, who: Vector3) => void) | null;
168
+ onStay?: ((dt: number, t: Trigger, who: Vector3, id: string | null) => void) | null;
171
169
  /** 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
170
  once?: boolean;
173
171
  /** false pauses detection */
174
172
  enabled?: boolean;
175
173
  /** Name (carried in events) */
176
174
  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;
175
+ /**
176
+ * 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
177
+ * (several actors: () => [e.actor, ...e.net.peers.map(p => p.actor)])
178
+ */
179
+ who?: string | Vector3 | Object3D | { x: number; y: number; z: number } | (() => Array<string | Object3D | { x: number; y: number; z: number }>) | null;
179
180
  /** Seconds after leaving during which entering does not fire again, default 0 */
180
181
  cooldown?: number;
181
182
  /** Custom data */
@@ -205,23 +206,21 @@ export interface Trigger {
205
206
  /** Whether a point is inside */
206
207
  contains(p: { x: number; y: number; z: number }): boolean;
207
208
  }
208
- export interface TriggerEvent { tag: string; trigger: Trigger; who: Vector3 | null }
209
+ /** id = world record id of who entered / left (null for a bare position) */
210
+ export interface TriggerEvent { tag: string; trigger: Trigger; who: Vector3 | null; id: string | null }
209
211
  export interface TriggersOptions {
210
- /** Show the wireframes from the start */
211
- debug?: boolean;
212
- /** Action name that toggles the wireframes, default 'triggersDebug' */
212
+ /** Action name that toggles the debug view 'triggers' (engine.debug.view), default 'triggersDebug' */
213
213
  action?: string;
214
- /** Key that toggles the wireframes: default ['F4'] in dev builds, none in release builds */
215
- keys?: string[];
214
+ /** Line color of the debug view 'triggers', default neutral gray */
215
+ debugColor?: ColorLike;
216
+ /** Line opacity of the debug view 'triggers', default 0.8 */
217
+ debugOpacity?: number;
216
218
  }
217
219
 
218
220
  /** engine.triggers */
219
221
  export interface Triggers {
220
222
  /** All trigger zones (a new array) */
221
223
  list(): Trigger[];
222
- /** Whether wireframes are shown */
223
- debug: boolean;
224
- action: string;
225
224
  /** Add a trigger zone */
226
225
  add(opts?: TriggerOptions): Trigger;
227
226
  /** Delete all (delete a single one with trigger.remove()) */
@@ -230,129 +229,13 @@ export interface Triggers {
230
229
  byTag(tag: string): Trigger[];
231
230
  /** Every trigger_xxx marker in the level becomes a trigger zone with tag xxx; opts is shared by all of them */
232
231
  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
232
  }
350
233
 
351
234
  // ======================================================================
352
235
  // Particles particles()
353
236
  // ======================================================================
354
237
 
355
- /** Particle effect parameters (style.particles[name] of the style pack uses the same format too). All optional */
238
+ /** Particle effect parameters (define(), and each entry of particles({ effects, default })). All optional */
356
239
  export interface ParticleOptions {
357
240
  /** Maximum alive at once, default 120 (halved on low-end devices) */
358
241
  max?: number;
@@ -406,7 +289,21 @@ export interface ParticleEmitter extends Handle {
406
289
  [key: string]: any;
407
290
  }
408
291
  /** A particle effect */
409
- export interface ParticleEffect { name: string; o: ParticleOptions; max: number; alive: number; points: Object3D; [key: string]: any }
292
+ export interface ParticleEffect {
293
+ name: string; o: ParticleOptions; max: number; alive: number; points: Object3D;
294
+ /** The plain three.js material drawn; set yours and it is drawn as given, null gives the engine's back */
295
+ material: Material | null;
296
+ /** The engine material's { value } objects (uMap, uHasMap, uScale, uMaxPx), written whichever material is drawn; a ShaderMaterial of yours can share them */
297
+ readonly uniforms: Record<string, { value: any }>;
298
+ [key: string]: any;
299
+ }
300
+ /** particles() options */
301
+ export interface ParticlesOptions {
302
+ /** Effect params by name: under what define() gives, and defined on the first emit / attach when define() never ran */
303
+ effects?: Record<string, ParticleOptions>;
304
+ /** Params every effect starts from */
305
+ default?: ParticleOptions;
306
+ }
410
307
 
411
308
  // Particles (engine.particles) is generated from the JSDoc in modules/particles/Particles.js (npm run map); only the type is re-exported here
412
309
  import type { Particles } from './generated/modules/particles/Particles';
@@ -450,10 +347,8 @@ export interface SettingsSection {
450
347
  order?: number;
451
348
  }
452
349
  export interface SettingsOptions {
453
- /** Action name that opens the menu, default 'menu' */
350
+ /** 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
351
  action?: string;
455
- /** Key that opens the menu, default ['Escape'] */
456
- keys?: string[];
457
352
  /** Browser storage key */
458
353
  storageKey?: string;
459
354
  /** Override the graphics presets: { low: {...}, medium: {...}, high: {...} } */
@@ -474,7 +369,6 @@ export interface SettingsOptions {
474
369
 
475
370
  /** engine.settings */
476
371
  export interface Settings {
477
- action: string;
478
372
  /** All current setting values */
479
373
  values: Record<string, any>;
480
374
  /** Graphics presets */
@@ -489,8 +383,10 @@ export interface Settings {
489
383
  set(key: string, value: any, opts?: { save?: boolean }): void;
490
384
  /** Graphics preset: 'low' | 'medium' | 'high' */
491
385
  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;
386
+ /** Game-defined setting: default value + apply function (saved automatically), or { apply, limits }. limits names the shared value(s) the row
387
+ * 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),
388
+ * 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 */
389
+ define<T = any>(key: string, def: T, apply?: ((value: T, e: Engine) => void) | { apply?: (value: T, e: Engine) => void; limits?: string | string[] }): this;
494
390
  /** Add a tab of your own, or a built-in / optional one by name: addSection('camera') */
495
391
  addSection(id: string, section?: SettingsSection): this;
496
392
  removeSection(id: string): void;
@@ -557,9 +453,13 @@ export interface CharacterRig {
557
453
  joints?: Record<string, Object3D>;
558
454
  limbs?: { joint: Object3D; offset: number; amp: number; kind: 'arm' | 'leg'; side?: number }[];
559
455
  }
456
+ export type CharacterWater = 'swim' | 'block' | 'wade' | ((character: Character, at: { depth: number; x: number; z: number }) => 'swim' | 'block' | 'wade');
457
+ /** 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) */
458
+ export interface CharacterFacts { base: string; speed: number; grounded: boolean; swimming: boolean; vy: number; water: 'swim' | 'block' | 'wade' | null }
459
+ export type CharacterStates = (character: Character, facts: CharacterFacts) => string | null | undefined;
560
460
  /** Character parameters (shared by the player and NPCs) */
561
461
  export interface CharacterOptions {
562
- /** 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 */
462
+ /** Per-character part colors: recolor the body's meshes marked userData.part (a humanoid rig: body, skin, legs, hair) */
563
463
  colors?: { body?: ColorLike; skin?: ColorLike; legs?: ColorLike; hair?: ColorLike };
564
464
  /** Walking speed (m/s), default 4.5 */
565
465
  speed?: number;
@@ -567,9 +467,18 @@ export interface CharacterOptions {
567
467
  runSpeed?: number;
568
468
  /** Collision radius (meters), default 0.4 */
569
469
  radius?: number;
570
- /** Whether it can swim, default true */
571
- canSwim?: boolean;
572
- /** Water depth (meters) at which swimming starts, default 1 */
470
+ /**
471
+ * What water deeper than swimDepth does: 'swim' (default: floats, state 'swim') | 'block' (never enters it) | 'wade' (walks the bottom) | a function
472
+ * deciding per spot (a swim skill, a boat, depth). character:water fires on each change
473
+ */
474
+ water?: CharacterWater;
475
+ /**
476
+ * 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
477
+ * or null to keep facts.base. The state picks the clip like any other (clips: { crouch: 'Crouch' }); speed changes stay engine.mod('move.speed')
478
+ * @example createPlayer({ ..., clips: { crouch: 'Crouch' }, states: (c, f) => f.grounded && engine.input.down('crouch') ? 'crouch' : null })
479
+ */
480
+ states?: CharacterStates | null;
481
+ /** Water depth (meters) at which water counts as deep, default 1 */
573
482
  swimDepth?: number;
574
483
  /** Swimming speed multiplier, default 0.45 */
575
484
  swimSpeed?: number;
@@ -587,8 +496,18 @@ export interface CharacterOptions {
587
496
  airControl?: number;
588
497
  /** How long after walking off an edge a jump is still allowed (seconds) */
589
498
  coyoteTime?: number;
590
- /** Whether it can jump, default true */
499
+ /** Whether it can jump, default true (stuns and cutscenes use engine.mod('move.canJump', { owner, id, set: 0 }) instead of writing it) */
591
500
  canJump?: boolean;
501
+ /** Jumps before landing again, default 1; 2 = double jump (jump() again in the air) */
502
+ maxJumps?: number;
503
+ /** Takeoff speed of an air jump (m/s), default jumpSpeed */
504
+ airJumpSpeed?: number;
505
+ /** How long a jump() pressed early waits for the ground (seconds), default 0.12 */
506
+ jumpBuffer?: number;
507
+ /** 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 */
508
+ fall?: false | { belowY: number | ((character: Character) => boolean) };
509
+ /** Time channel its movement and animation follow when the engine drives it (player default 'player', others 'world') */
510
+ channel?: string;
592
511
  /**
593
512
  * 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
513
  * (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 +518,14 @@ export interface CharacterOptions {
599
518
  model?: Object3D | string | null;
600
519
  /** A ready procedural body (CharacterRig), used instead of model (a hand-built guard / pet) */
601
520
  rig?: CharacterRig | null;
521
+ /** 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 */
522
+ id?: string;
602
523
  /** Action name mapping { idle, walk, run, swim, jump, fall } (shorthand for animation) */
603
524
  clips?: { idle?: string; walk?: string; run?: string; swim?: string; jump?: string; fall?: string; drive?: string } | null;
604
525
  /** Skeletal animation state machine config (states, blend trees, one-shot actions), see AnimatorOptions */
605
526
  animation?: AnimatorOptions | null;
606
- /** Movement method: 'simple' built into the engine (default) | 'rapier' Rapier character controller (needs the rigid module) */
607
- mover?: 'simple' | 'rapier';
527
+ /** 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 */
528
+ mover?: 'simple' | 'rapier' | 'manual';
608
529
  /**
609
530
  * Which way it turns each move: 'move' (default, toward its velocity) | 'camera' (along cameraRig.forward()) | 'target' (toward faceTarget) | 'manual'
610
531
  * (only face() turns it)
@@ -615,50 +536,45 @@ export interface CharacterOptions {
615
536
  }
616
537
  /** Character facing mode, see CharacterOptions.faceMode */
617
538
  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;
539
+ /** 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', ... }) */
540
+ export type MoveRequest = { x: number; z: number; run?: boolean } | null | undefined;
620
541
  /**
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
542
+ * How the player's input steers it (the base holder of its control slot, owner 'player-input'): 'camera' movement keys relative to the camera |
543
+ * a function returning the move request. The game moving the player itself takes control: engine.control.take(player, { owner, layer: 'script', step })
623
544
  */
624
- export type PlayerControl = 'camera' | 'none' | ((player: Character, input: Input, dt: number) => MoveRequest);
545
+ export type PlayerControl = 'camera' | ((player: Character, input: Input, dt: number) => MoveRequest);
625
546
  /** Parameters of createPlayer() */
626
547
  export interface PlayerOptions extends CharacterOptions {
627
548
  /** Spawn point (meters, { x, z } / Vector3 / object); flat ground is found automatically if omitted */
628
549
  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
550
  /**
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
551
+ * Required, no default: 'camera' (keys relative to the camera) | (player, input, dt) => ({ x, z, run? }) (null stands still). presets.player.*
552
+ * fill it. Given once: a game that steers the player for a while takes control (engine.control.take(player, { owner, layer: 'script', step }))
636
553
  */
637
554
  control: PlayerControl;
638
555
  /** 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
556
  cameraFollow?: boolean;
640
557
  }
641
- /** Character state */
642
- export type CharacterState = 'idle' | 'walk' | 'run' | 'swim' | 'jump' | 'fall' | 'drive';
558
+ /** Character state: the engine's own, or any name the game's `states` hook returns (crouch, climb, sit...) */
559
+ export type CharacterState = 'idle' | 'walk' | 'run' | 'swim' | 'jump' | 'fall' | 'drive' | (string & {});
643
560
 
644
561
  /** Character (player and NPCs) */
645
562
  export declare class Character {
646
563
  constructor(engine: Engine, opts?: CharacterOptions);
647
- engine: Engine;
648
564
  /** Root node (this is what gets added to the scene) */
649
565
  root: Object3D;
650
566
  /** Same as root: add children, change visible and scale on it */
651
567
  readonly object: Object3D;
652
568
  /** Position (= root.position) */
653
569
  readonly position: Vector3;
654
- /** Horizontal velocity (x, y map to world x, z) */
570
+ /** 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
571
  velocity: Vector2;
656
572
  /**
657
573
  * Heading (radians): 0 faces +Z, forward = (sin facing, cos facing); increasing turns toward +X (rotation about the Y axis, consistent with
658
574
  * root.rotation.y)
659
575
  */
660
576
  facing: number;
661
- /** Vertical velocity (m/s) */
577
+ /** Vertical velocity (m/s). Writable: setting it is an impulse (launch() does the same and also leaves the ground cleanly) */
662
578
  vy: number;
663
579
  /** Whether standing on the ground */
664
580
  grounded: boolean;
@@ -672,20 +588,47 @@ export declare class Character {
672
588
  faceMode: FaceMode;
673
589
  /** What faceMode 'target' faces */
674
590
  faceTarget: PositionLike | null;
675
- /** Player only: who moves it each fixed step (see PlayerOptions.control) */
676
- control?: PlayerControl;
677
591
  /** Player only: whether the camera module follows it (see PlayerOptions.cameraFollow) */
678
592
  cameraFollow?: boolean;
679
593
  /** 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
594
  push(vx: number, vz: number, seconds: number): void;
681
- speed: number; runSpeed: number; radius: number; canSwim: boolean; swimDepth: number; swimSpeedFactor: number;
595
+ speed: number; runSpeed: number; radius: number; water: CharacterWater; states: CharacterStates | null; swimDepth: number; swimSpeedFactor: number;
682
596
  turnSpeed: number; acceleration: number; gravity: number; jumpSpeed: number; stepHeight: number; airControl: number; coyoteTime: number; canJump: boolean;
597
+ /** Base jump values (the game's; modifiers go through engine.mod('move.jumpSpeed')) */
598
+ maxJumps: number; airJumpSpeed: number | null; jumpBuffer: number;
599
+ /** Fall check (see CharacterOptions.fall); a plain property */
600
+ fall: false | { belowY: number | ((character: Character) => boolean) };
601
+ /** Time channel the engine drives it on (see CharacterOptions.channel) */
602
+ channel: string;
603
+ /** 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 */
604
+ readonly id: string;
605
+ /**
606
+ * A movement stat as the mover uses it now: the base field with every engine.mod('move.<name>') entry applied (canJump reads 1 / 0)
607
+ * @example engine.mod('move.speed', { owner: 'haste', id: 'player', mul: 1.2, for: 5 }); player.stat('speed') // 1.2 x player.speed
608
+ */
609
+ stat(name: 'speed' | 'runSpeed' | 'gravity' | 'jumpSpeed' | 'canJump'): number;
610
+ /** Give back n jumps for this airtime (pickup, wall touch) */
611
+ addJumps(n?: number): this;
612
+ /** All jumps back, as if it had landed */
613
+ resetJumps(): this;
614
+ /**
615
+ * 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
616
+ * @example player.launch(19, { owner: 'pad' })
617
+ */
618
+ launch(speed: number, opts?: { owner?: string }): this;
619
+ /** Jump state now, read-only */
620
+ jumpState(): { grounded: boolean; coyoteLeft: number; bufferLeft: number; jumpsUsed: number; jumpsLeft: number; vy: number };
621
+ /** What it stands on, read-only (reused object); 'platform' = a registered support (characters.support), which carries it */
622
+ readonly support: { kind: 'ground' | 'platform' | 'collider' | 'water' | null; object: any; id: string | null; safe: boolean; velocity: { x: number; y: number; z: number } };
623
+ /** Last spot it stood still on safe ground (where a fall returns it); null until it first stands. Saved with the motion */
624
+ safeGround: Vector3 | null;
683
625
  /** Called when a foot lands (the argument is the ground type underfoot) */
684
626
  onStep: ((groundType: string) => void) | null;
685
627
  /** Called on landing (the argument is the landing speed) */
686
628
  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 };
629
+ /** 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' */
630
+ get mover(): { name: 'simple' | 'rapier' | 'manual'; controller?: any; body?: any; collider?: any; move(dirX: number, dirZ: number, run: boolean, dt: number): void; dispose?(): void };
631
+ set mover(name: 'simple' | 'rapier' | 'manual');
689
632
  /** Skeletal animation state machine (when there is a glTF model; null while a model named by asset is still loading) */
690
633
  anim: Animator | null;
691
634
  /** false while a model named by asset is loading (the placeholder body shows); true otherwise, also after a failed load (placeholder kept) */
@@ -696,10 +639,12 @@ export declare class Character {
696
639
  * npc.playAction('Wave');
697
640
  */
698
641
  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;
642
+ /** The vehicle it sits in (null on foot) */
643
+ vehicle: Rideable | null;
644
+ /** Its seat in the vehicle: 0 drives, others ride; null on foot */
645
+ seat: number | null;
646
+ /** 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 */
647
+ enter(vehicle: Rideable): void;
703
648
  /** Exit the vehicle */
704
649
  exit(): void;
705
650
  /** Play a one-shot action (e.g. 'wave'); skipped if the model has no such clip */
@@ -714,8 +659,11 @@ export declare class Character {
714
659
  * (used by npcs.remove / removePlayer)
715
660
  */
716
661
  dispose(): void;
717
- /** Request a jump */
718
- jump(): void;
662
+ /**
663
+ * 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
664
+ * @example createPlayer({ ...presets.player.thirdPerson, maxJumps: 2 }) // double jump
665
+ */
666
+ jump(opts?: { air?: boolean }): this;
719
667
  /** Add to the scene */
720
668
  addTo(scene?: any): this;
721
669
  /** Put it on the ground at position (Vector3 / object / [x, y, z] / { x, z }) */
@@ -727,11 +675,17 @@ export declare class Character {
727
675
  syncRecord(): this;
728
676
  /**
729
677
  * 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
678
+ * one with 'cancelled'. Transient: not saved, not fast-forwarded by engine.skip. Holds the character's control on layer 'script' (owner 'walkTo'):
679
+ * 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
680
  */
732
681
  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;
682
+ /**
683
+ * 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
684
+ * given). Speed comes from the stats: engine.mod('move.speed', { owner, id: character.id, ... }) (the player: id 'player'), the one way to change speed.
685
+ * A character someone controls (engine.control.of(ch)) moves only through its holder: called from anywhere else it is control-bypass in dev;
686
+ * take control and use handle.move() / step instead
687
+ */
688
+ move(dirX: number, dirZ: number, run: boolean, dt: number): void;
735
689
  /** Ground type underfoot ('water' while swimming) */
736
690
  groundType(): string;
737
691
  /** Turn at once to a position, or to an angle in radians (0 = +Z) */
@@ -744,9 +698,14 @@ export declare class Character {
744
698
  /** Restore the motion state from the plain object of saveMotion */
745
699
  loadMotion(m: CharacterMotion | null | undefined): this;
746
700
  }
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 }
701
+ /** Result of Character.saveMotion (plain values, can be saved); facing is the same as Character.facing: 0 = +Z, forward (sin f, cos f) */
702
+ export interface CharacterMotion { vx?: number; vz?: number; vy?: number; facing?: number; amount?: number; grounded?: boolean; swimming?: boolean;
703
+ /** Jump state (world part version 4; older saves are migrated from the flat coyote field) */
704
+ jump?: { coyote: number; used: number };
705
+ /** safeGround as [x, y, z] */
706
+ safe?: [number, number, number] | null;
707
+ /** id of the support it rides (characters.support), found again on load */
708
+ support?: string | null }
750
709
 
751
710
  /** One schedule stop (the npcs.add form): at is when to set off, position the destination */
752
711
  export interface ScheduleStop {
@@ -757,6 +716,8 @@ export interface ScheduleStop {
757
716
  }
758
717
  /** One schedule stop (as stored in npc.schedule after install): at has been converted to 0–1, x/z is the destination (meters) */
759
718
  export interface ScheduleEntry { at: number; x: number; z: number }
719
+ /** An NPC's interact option: the op the interact key runs near it ({ npc: id, ...args }), its prompt label and reach */
720
+ export interface NpcInteract { op: string; args?: Record<string, any>; label?: string | (() => string); radius?: number }
760
721
  /** Parameters of engine.npcs.add({...}) */
761
722
  export interface NPCOptions extends CharacterOptions {
762
723
  /**
@@ -785,12 +746,14 @@ export interface NPCOptions extends CharacterOptions {
785
746
  * the position when wandering started) }
786
747
  */
787
748
  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;
749
+ /**
750
+ * What the interact key does near it (needs interactions()): runs the op with { npc: id, ...args }. Dialogue is one such op: { op: 'npc.talk' }
751
+ * (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);
752
+ * radius meters, default 3.2
753
+ * @example interact: { op: 'npc.talk' }
754
+ * @example interact: { label: 'Trade', op: 'shop.open', args: { shelf: 'tools' } }
755
+ */
756
+ interact?: NpcInteract | null;
794
757
  /** Pathfinding grid size (meters), default 2 */
795
758
  pathStep?: number;
796
759
  /** Seconds before re-pathfinding after getting stuck, default 2 */
@@ -817,8 +780,8 @@ export declare class NPC {
817
780
  readonly schedule: ScheduleEntry[];
818
781
  /** Current behavior name */
819
782
  readonly behavior: string;
820
- /** Dialogue id */
821
- readonly talk: string | null;
783
+ /** What the interact key does near it ({ label, op, args, radius } as saved), null when nothing */
784
+ readonly interact: { label: string | null; op: string; args: Record<string, any>; radius: number } | null;
822
785
  /** Animation state ('idle' / 'walk'...) */
823
786
  readonly state: string;
824
787
  /** In dialogue (stopped, not walking) */
@@ -861,6 +824,13 @@ export interface NPCManager {
861
824
  * seconds); selected through behavior in the data
862
825
  */
863
826
  behavior(name: string, impl: { near?: (rec: WorldRecord, dt: number, npc: NPC) => void; far?: (rec: WorldRecord, dt: number) => void }): this;
827
+ /**
828
+ * 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
829
+ * 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
830
+ * move in visible jumps, so only turn this on for crowds of hundreds. tiers(null) turns it off.
831
+ * @example engine.npcs.tiers({ fullRadius: 30, nearEvery: 4 / 60 })
832
+ */
833
+ tiers(opts: { fullRadius: number; nearEvery: number } | null): this;
864
834
  /**
865
835
  * 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
836
  * the player), then constrained back to walkable places by engine.collision; deterministic and cheap, with identical results after loading.
@@ -887,6 +857,12 @@ export interface NPCManager {
887
857
  }
888
858
  /** engine.characters */
889
859
  export interface CharactersApi {
860
+ /**
861
+ * The three.js material of every placeholder capsule. Set it to swap the look of all of them at once; used as given, with no patches added. A character
862
+ * with colors.body draws with a copy of it in that color. A model's own materials are the model's.
863
+ * @example engine.characters.material = new THREE.MeshToonMaterial({ color: 0xd9a066 });
864
+ */
865
+ material: Material;
890
866
  /**
891
867
  * Find a spawn point: searches outward from position (default origin) for walkable (not steep, no obstacle), non-water ground, without assuming
892
868
  * terrain height; e.g. findSpawn(v, { minH: 3, maxH: 20 }). Returns a Vector3 (y is the ground height)
@@ -901,7 +877,14 @@ export interface CharactersApi {
901
877
  * 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
878
  * inside your own control function to wrap it
903
879
  */
904
- moveInput(): { x: number; z: number; run: boolean; speed?: number };
880
+ moveInput(): { x: number; z: number; run: boolean };
881
+ /**
882
+ * Something characters stand on and ride (moving platform, lift, raft). Move the object any way (onFixed before or after the player, a timeline,
883
+ * physics): riders follow how its matrix changed, so the order does not matter. safe: false = never a respawn spot; carry 'position+yaw' turns riders
884
+ * with it; inherit: false = jumping off keeps none of its speed. With mover 'rapier' give it a collider too.
885
+ * @example const lift = engine.characters.support(liftMesh); engine.onFixed(() => { liftMesh.position.y = 2 + Math.sin(engine.time.now('real')); });
886
+ */
887
+ support(object: any, opts?: { id?: string; safe?: boolean; carry?: 'position' | 'position+yaw'; inherit?: boolean }): { id: string; remove(): void };
905
888
  /**
906
889
  * Delete the current player (exits the vehicle first, stops responding to keys, fully deletes the model). The player save (key player) carries the
907
890
  * position and the vehicle; loading an on-foot save exits the vehicle first
@@ -938,14 +921,15 @@ export interface FindSpawnOptions { minH?: number; maxH?: number; maxSlope?: num
938
921
  export interface CharactersOptions {
939
922
  /** Whether to enable NPCs (engine.npcs), default true */
940
923
  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 */
924
+ /** Near tiers for large NPC crowds, off by default (every near NPC walks every fixed step); same as engine.npcs.tiers(opts) */
925
+ npcTiers?: { fullRadius: number; nearEvery: number };
926
+ /** What every character's Animator starts from, e.g. { fade: 0.15 }; a model's manifest mapping and the character's own animation win over it */
927
+ animation?: AnimatorOptions;
928
+ }
929
+ /**
930
+ * Pathfinding options: step is the grid size (meters, A*), maxNodes the maximum cells searched (A*), radius the character radius (meters,
931
+ * default engine.movement.radius); for detailed see findPath
932
+ */
949
933
  export interface FindPathOptions { step?: number; maxNodes?: number; radius?: number; detailed?: boolean }
950
934
 
951
935
  // ======================================================================
@@ -955,29 +939,42 @@ export interface FindPathOptions { step?: number; maxNodes?: number; radius?: nu
955
939
  export interface InteractionOptions {
956
940
  /** Stable id for the op interaction.use { id } (default: the world record id it was built for, else a running number) */
957
941
  id?: string;
958
- /** Prompt text, or a function returning text */
959
- label?: string | (() => string);
960
- /** How close the actor must be (meters), default interactions({ radius }) = 2.5 */
942
+ /** Prompt text, or a function (object, { actor }) returning text; actor = world record id of who looks at it */
943
+ label?: string | ((object: Object3D, ctx: { actor: string }) => string);
944
+ /** How close the actor must be (meters), measured from the object's origin in 3D, not its edge, so a large object (a boat, a house) needs a larger radius or a small marker object at the spot to use. Default interactions({ radius }) = 2.5 */
961
945
  radius?: number;
962
946
  /** Key action name, default 'interact' (E key). Give one object a second verb by adding another interaction with another action */
963
947
  action?: string;
964
- /** Called when pressed */
965
- onUse?: (object: Object3D) => void;
948
+ /**
949
+ * 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,
950
+ * code } fails the op with that code
951
+ */
952
+ onUse?: (object: Object3D, ctx: { actor: string }) => any;
966
953
  /**
967
954
  * 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
955
  * text by state and decide in onUse whether it can be used)
969
956
  */
970
- enabled?: () => boolean;
957
+ enabled?: (object: Object3D, ctx: { actor: string }) => boolean;
971
958
  /** How high the prompt floats above the object (meters) */
972
959
  height?: number;
960
+ /**
961
+ * 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
962
+ * locked input (interaction:hold / interaction:interrupt); the prompt gets progress 0-1. The op interaction.use itself is the completed use
963
+ */
964
+ hold?: number;
965
+ /** 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) */
966
+ approach?: boolean;
967
+ /** Hide the object after a use and allow no second one (onUse returning { ok: false } leaves it). Saved under id, else the object's name; development throws when it has neither */
968
+ once?: boolean;
969
+ /** Name of a HUD counter each use adds 1 to (hud.add; nothing without hud()). Saved; read the total with hud.value(name) */
970
+ counter?: string;
973
971
  }
974
972
  /** engine.interactions */
975
973
  export interface Interactions {
976
- action: string;
977
974
  /** How high the prompt floats (meters) */
978
975
  promptHeight: number;
979
- /** All interactions */
980
- items: any[];
976
+ /** All interactions in the order added (a fresh array each read; get(id) finds one without it) */
977
+ readonly items: any[];
981
978
  /** Default reach of add() in meters (2.5) */
982
979
  radius: number;
983
980
  /** How the one in front of the actor is chosen; can be changed at runtime */
@@ -986,6 +983,8 @@ export interface Interactions {
986
983
  current: any;
987
984
  /** One best interaction per key action this frame, for a prompt that lists several keys */
988
985
  options: { action: string; id: string; label: string }[];
986
+ /** The hold in progress (progress 0-1), null when none */
987
+ holding: { id: string; action: string; seconds: number; progress: number } | null;
989
988
  /**
990
989
  * 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
990
  * Returns a handle { remove() }
@@ -1002,10 +1001,10 @@ export interface Interactions {
1002
1001
  export interface PromptView {
1003
1002
  /** Interaction id */
1004
1003
  id: string;
1005
- /** Action that uses it ('interact') and its key label ('E') */
1004
+ /** Action that uses it ('interact') and its key label ('E'; 'No key' when the action needs one and has none, '' when it has none on purpose) */
1006
1005
  action: string;
1007
1006
  key: string;
1008
- /** The interaction's label, and the default text 'E · label' */
1007
+ /** The interaction's label, and the default text 'E · label' ('label' alone with an empty key) */
1009
1008
  label: string;
1010
1009
  text: string;
1011
1010
  /** Screen pixels above the target */
@@ -1014,8 +1013,10 @@ export interface PromptView {
1014
1013
  onScreen: boolean;
1015
1014
  /** Use it (the op interaction.use) */
1016
1015
  use(): void;
1017
- /** One best interaction per action this frame, for a prompt that lists several keys ("E · 浇水 F · 收获") */
1016
+ /** One best interaction per action this frame, for a prompt that lists several keys ("E · Open F · Lock") */
1018
1017
  options: { action: string; id: string; label: string }[];
1018
+ /** A hold interaction: how far the hold is (0-1, 0 before it starts); null for a plain press */
1019
+ progress: number | null;
1019
1020
  }
1020
1021
  /** A candidate handed to a pick function: an enabled interaction within its radius of the actor */
1021
1022
  export interface InteractionCandidate { id: string; object: Object3D; action: string; label: string | (() => string); distance: number }
@@ -1037,8 +1038,6 @@ export interface InteractionsOptions {
1037
1038
  * keys: ['KeyE'], radius: 2 }) // first person
1038
1039
  */
1039
1040
  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
1041
  }
1043
1042
 
1044
1043
  // ======================================================================
@@ -1081,8 +1080,18 @@ export interface DialogueNode {
1081
1080
  }
1082
1081
  /** Dialogue script: node name -> node, starting from 'start' */
1083
1082
  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 }
1083
+ /** 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) */
1084
+ export interface SayPromise extends Promise<void> { id: string | null; remove(): void }
1085
+ /** Which dialogue channel: 'main' the conversation the player reads (locks input, choices) · 'bubble' lines over their speakers while play goes on */
1086
+ export type DialogueChannel = 'main' | 'bubble';
1087
+ /**
1088
+ * 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)
1089
+ */
1090
+ export type BubbleAt = Object3D | PositionLike | string | null;
1091
+ /** Bubble-channel options: seconds on screen (default holdSeconds + about 15 characters a second); queue false = replace this speaker's current line */
1092
+ export interface BubbleOptions { at?: BubbleAt; seconds?: number; queue?: boolean }
1093
+ /** What the 'dialogue.bubble' UI part (one per speaker) receives in update(view) every frame while its line shows */
1094
+ export interface BubbleView { speaker: string; text: string; x: number; y: number; onScreen: boolean; screen: boolean }
1086
1095
 
1087
1096
  /** engine.dialogue */
1088
1097
  export interface Dialogue {
@@ -1090,9 +1099,13 @@ export interface Dialogue {
1090
1099
  readonly state: DialogueState;
1091
1100
  /** All scripts */
1092
1101
  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 */
1102
+ /**
1103
+ * The dialogue in progress (null when none). speaker: the script name; node: the current node OBJECT (its fields: text, choices, data...);
1104
+ * 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.
1105
+ * @example const atAsk = engine.dialogue.active?.id === 'ask'; // the node id; active.node.data holds the node's own fields
1106
+ */
1107
+ readonly active: { speaker: string; nodes: DialogueScript; node?: DialogueNode; id?: string; onEnd: (() => void) | null } | null;
1108
+ /** The script the main dialogue is playing */
1096
1109
  readonly speaking: string | null;
1097
1110
  /** Typing speed (characters/second) */
1098
1111
  cps: number;
@@ -1100,21 +1113,22 @@ export interface Dialogue {
1100
1113
  define(speaker: string, nodes: DialogueScript): void;
1101
1114
  /**
1102
1115
  * 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 })
1116
+ * 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
1117
+ * top of the UI focus stack (default: nothing). channel: 'bubble' plays the script as bubble lines over at (no lock, no choices; a running
1118
+ * conversation is untouched). Ending the playthrough (engine.session newGame / load / quit) closes it without calling onEnd.
1119
+ * @example engine.dialogue.start('guard', 'start', null, { channel: 'bubble', at: guard.root })
1108
1120
  */
1109
- start(speaker: string, nodeId?: string, onEnd?: (() => void) | null, opts?: { lock?: boolean; onCancel?: (() => void) | null }): void;
1121
+ start(speaker: string, nodeId?: string, onEnd?: (() => void) | null, opts?: { channel?: DialogueChannel; at?: BubbleAt; onCancel?: (() => void) | null }): void;
1110
1122
  /**
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).
1123
+ * 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
1124
+ * (barks, shop chatter, radio); several speakers at once, queued per speaker.
1113
1125
  * 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 })
1126
+ * @example await engine.dialogue.say('Reloading!', { speaker: 'Mira', channel: 'bubble', at: mira.root })
1115
1127
  */
1116
- say(text: string | DialogueScript, opts?: { speaker?: string; node?: string; lock?: boolean; onCancel?: (() => void) | null }): SayPromise;
1117
- /** End the current dialogue */
1128
+ say(text: string | DialogueScript, opts?: { speaker?: string; node?: string; channel?: DialogueChannel; onCancel?: (() => void) | null } & BubbleOptions): SayPromise;
1129
+ /** Lines on the bubble channel now */
1130
+ bubbles(): { speaker: string; text: string; queued: number }[];
1131
+ /** End the main dialogue */
1118
1132
  end(): void;
1119
1133
  // Advancing and choosing are ops: engine.ops.run('dialogue.advance') / engine.ops.run('dialogue.choose', { index })
1120
1134
  // (0-based; while typing it completes the line first)
@@ -1122,11 +1136,10 @@ export interface Dialogue {
1122
1136
  export interface DialogueOptions {
1123
1137
  /** Typing speed (characters/second, game time: advanced by engine.step), default 40 */
1124
1138
  charsPerSecond?: number;
1125
- /** Actions that advance the dialogue, default ['confirm', 'interact'] (interact only when the game bound it) */
1139
+ /** Actions that advance the dialogue, default ['confirm'] (a basic key); e.g. ['confirm', 'interact'] to also advance on the game's interact key.
1140
+ * Choices: the cursor, clicks, and the actions choice1..choice9 (context 'dialog', no keys of their own: presets.bindings.dialogNumbers binds 1-9) */
1126
1141
  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 */
1142
+ /** A bubble line stays this many seconds plus its reading time (about 15 characters a second) unless say() gives seconds, default 2 */
1130
1143
  holdSeconds?: number;
1131
1144
  }
1132
1145
  /**
@@ -1164,8 +1177,8 @@ export interface DialogueView {
1164
1177
  hint: string;
1165
1178
  /** The node's data (the game's own fields), {} when none */
1166
1179
  data: Record<string, any>;
1167
- /** false for a line said while the player keeps playing */
1168
- lock: boolean;
1180
+ /** The choice under the UI choice cursor (menu keys / d-pad / stick; confirm picks it), -1 when no choices show */
1181
+ selected: number;
1169
1182
  /** Run the op dialogue.advance (finish typing / next line) */
1170
1183
  advance(): any;
1171
1184
  /** Run the op dialogue.choose { index } (0-based among choices) */
@@ -1198,24 +1211,37 @@ export interface ItemDef {
1198
1211
  consume?: boolean;
1199
1212
  /** Color of the pickup on the ground */
1200
1213
  color?: ColorLike;
1214
+ /** 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) */
1215
+ model?: string;
1201
1216
  [key: string]: any;
1202
1217
  }
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 }
1218
+ /**
1219
+ * 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),
1220
+ * 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),
1221
+ * count = change, total = how many of the item that container holds now
1222
+ */
1223
+ export interface ItemEvent { container: string; actor: string; id: string; key: string; count: number; total: number }
1205
1224
  /** inventory.use: who used which entry (data = that piece's data) */
1206
1225
  export interface ItemUseEvent { actor: string; item: string; key: string; data?: Record<string, any> }
1207
1226
  /** 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
1227
  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 }
1228
+ export interface PickupEvent { pickup: string; item: string | null; count: number; actor: string; x: number; z: number }
1229
+ /** What a give function gets: who takes it (world record id) and the pickup record */
1230
+ export interface PickupGiveContext { actor: string; pickup: WorldRecord }
1212
1231
  /**
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);
1232
+ * Handle returned by pickups.spawn(): id is the world record id, object is the current model (null when far away);
1214
1233
  * remove() deletes the pickup (data and model; a model passed in through opts.mesh is only taken off)
1215
1234
  */
1216
- export interface PickupHandle extends Handle { id: string; worldId: string; readonly object: Object3D | null }
1217
- /** Parameters of spawnPickup() */
1235
+ export interface PickupHandle extends Handle {
1236
+ /** 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) */
1237
+ id: string; give: string | ((e: Engine, ctx: PickupGiveContext) => any); readonly object: Object3D | null }
1238
+ /** Parameters of pickups.spawn() */
1218
1239
  export interface PickupOptions {
1240
+ /**
1241
+ * 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
1242
+ * instant effect (no inventory needed; not saved data, so spawn it again on load). Returning { ok: false, code } leaves it on the ground
1243
+ */
1244
+ give: string | ((e: Engine, ctx: PickupGiveContext) => any);
1219
1245
  /**
1220
1246
  * 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
1247
  * id is reused
@@ -1225,11 +1251,17 @@ export interface PickupOptions {
1225
1251
  count?: number;
1226
1252
  /** The piece's own data (a dropped sword keeps its durability) */
1227
1253
  data?: Record<string, any>;
1228
- /** Reach in meters, default inventory pickupRadius (2) */
1254
+ /** Name in the prompt ("Pick up {name}"), default the item's name */
1255
+ name?: string;
1256
+ /** 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) */
1257
+ model?: string;
1258
+ /** Color of the gray placeholder / a geometry-only model (default the item's color, else pickups({ color })) */
1259
+ color?: ColorLike;
1260
+ /** Reach in meters, default pickups({ radius }) (2) */
1229
1261
  radius?: number;
1230
- /** Taken by walking into it (no key press, no prompt) */
1262
+ /** Taken by walking into it (no key press, no prompt), by every actor in pickups.takers */
1231
1263
  auto?: boolean;
1232
- /** Custom model (the style pack's style.pickup is used if omitted) */
1264
+ /** The game's own three.js object for this one pickup (only detached when it goes; otherwise the model name decides the shape) */
1233
1265
  mesh?: Object3D | null;
1234
1266
  /** Game seconds until it reappears, 0 = never reappears */
1235
1267
  respawnSeconds?: number;
@@ -1243,9 +1275,48 @@ export interface PickupOptions {
1243
1275
  /** 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
1276
  zone?: string | null;
1245
1277
  }
1278
+ /** engine.pickups: things on the ground that give whoever takes them an item or an instant effect (op pickup.take, net: 'peer') */
1279
+ export interface Pickups {
1280
+ /** Reach of pickups that do not set their own (meters) */
1281
+ radius: number;
1282
+ /** Who walks into auto pickups: default engine.actor plus net peers on a host, none on a client */
1283
+ takers: (e: Engine) => string[];
1284
+ /**
1285
+ * The three.js material of every placeholder box and geometry-only model. Set it to swap all of them at once; used as given. A pickup with its own color or a
1286
+ * vertex-colored geometry draws with a copy of it carrying that color
1287
+ * @example engine.pickups.material = new THREE.MeshStandardMaterial({ color: 0xffd24a, metalness: 0.8 })
1288
+ */
1289
+ material: Material;
1290
+ /** Edge of the placeholder box (meters), read when one is built */
1291
+ size: number;
1292
+ /** Height above the ground new pickups float at (meters) */
1293
+ lift: number;
1294
+ /**
1295
+ * 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):
1296
+ * spawn(v, { give: 'berry', count: 2 }). Returns a handle, remove() deletes it
1297
+ */
1298
+ spawn(position: PositionLike, opts: PickupOptions): PickupHandle;
1299
+ /** The data of the nearest pickup still on the ground to from (default engine.actorPosition()), of one item id or any; null if none */
1300
+ nearest(item?: string | null, from?: PositionLike): WorldRecord | null;
1301
+ }
1302
+ export interface PickupsOptions {
1303
+ /** Reach of pickups that do not set their own radius (meters), default 2 */
1304
+ radius?: number;
1305
+ /** Pickups have a model, float and spin only within this distance (meters) of the stream sources, default 60 */
1306
+ showDistance?: number;
1307
+ /** Who walks into auto pickups (actor ids); default engine.actor, plus net peers on a host */
1308
+ takers?: (e: Engine) => string[];
1309
+ /** Color of the placeholder box and geometry-only models when the pickup and its item set none, default 0xcccccc */
1310
+ color?: ColorLike;
1311
+ /** Edge of the placeholder box (meters), default 0.25 */
1312
+ size?: number;
1313
+ /** Height above the ground a pickup floats at (meters), default 0.4 */
1314
+ lift?: number;
1315
+ }
1246
1316
 
1247
1317
  /**
1248
- * Container (inventory, chest, corpse, shelf): inventory.container(id, opts) gets or creates one; the player inventory is the one with id 'player'.
1318
+ * 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
1319
+ * (inventory.of(actor)), the player inventory is the bag of engine.actor.
1249
1320
  * Every x is an item id or an entry key
1250
1321
  */
1251
1322
  export interface Container {
@@ -1268,17 +1339,17 @@ export interface Container {
1268
1339
  list(): ItemEntry[];
1269
1340
  /** How many more fit (Infinity = no limit), for an item without data, with this data, or like an existing entry key */
1270
1341
  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) */
1342
+ /** 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
1343
  add(id: string, n?: number, opts?: { data?: Record<string, any>; silent?: boolean }): string | false;
1273
1344
  /** Remove n (default 1) of an item or entry key, returns false if there are not enough */
1274
1345
  remove(x: string, n?: number): boolean;
1275
1346
  /**
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
1347
+ * 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
1348
  * reverses it
1278
1349
  */
1279
1350
  trade(
1280
1351
  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 };
1352
+ ): { ok: boolean; code?: string; facts?: any; nextActions?: any[]; took?: { id: string; count: number; data?: any }[]; gave?: string; giveId?: string; giveN?: number };
1282
1353
  /** Replace an entry's data (null = none) for n pieces (default all); returns the key now holding them */
1283
1354
  setData(key: string, data: Record<string, any> | null, n?: number): string;
1284
1355
  /** Listen for changes of this container, returns a handle */
@@ -1289,15 +1360,13 @@ export interface Container {
1289
1360
  export interface Inventory {
1290
1361
  /** true: gameplay freezes while the inventory window is open (set from inventory({ pauseGame }) or at runtime) */
1291
1362
  pauseGame: boolean;
1292
- /** Item definitions */
1293
- defs: Map<string, ItemDef>;
1294
1363
  /** Slot limit of the player inventory */
1295
1364
  capacity: number;
1296
- /** Player inventory (= container('player')) */
1365
+ /** Player inventory: the bag of engine.actor (= of()) */
1297
1366
  readonly bag: Container;
1367
+ /** 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 */
1368
+ of(actor?: string): Container;
1298
1369
  defaultStack: number;
1299
- /** Reach of pickups that do not set their own (meters) */
1300
- pickupRadius: number;
1301
1370
  action: string;
1302
1371
  /** Define an item (chainable) */
1303
1372
  define(id: string, def: ItemDef): this;
@@ -1318,12 +1387,12 @@ export interface Inventory {
1318
1387
  /** Remove n (default 1) of an item or entry key, returns false if there are not enough */
1319
1388
  remove(x: string, n?: number): boolean;
1320
1389
  /**
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
1390
+ * 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
1391
  * reverses it
1323
1392
  */
1324
1393
  trade(
1325
1394
  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 };
1395
+ ): { ok: boolean; code?: string; facts?: any; nextActions?: any[]; took?: { id: string; count: number; data?: any }[]; gave?: string; giveId?: string; giveN?: number };
1327
1396
  /** Replace a player inventory entry's data for n pieces (default all); returns the key now holding them */
1328
1397
  setData(key: string, data: Record<string, any> | null, n?: number): string;
1329
1398
  /**
@@ -1338,31 +1407,20 @@ export interface Inventory {
1338
1407
  transfer(from: Container | string, to: Container | string, item: string, n?: number): number;
1339
1408
  /** Delete a container together with its contents ('player' cannot be deleted), returns whether one was deleted */
1340
1409
  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;
1410
+ /** Every container's items as plain data, the player bag included: { [containerId]: entries } (what setContents takes; net syncs through these two) */
1411
+ contents(): Record<string, any[]>;
1412
+ /** Replace containers' items from contents() data, silently like a save load; a null entry empties that container, only: true empties the rest too */
1413
+ setContents(data: Record<string, any[] | null>, opts?: { only?: boolean }): void;
1348
1414
  }
1349
1415
  export interface InventoryOptions {
1350
1416
  /** Action name that opens the inventory, default 'inventory' */
1351
1417
  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
1418
  /** true: gameplay freezes (engine.freeze) while the inventory window is open, default false. Also settable at runtime: engine.inventory.pauseGame */
1357
1419
  pauseGame?: boolean;
1358
- /** Pickups float and spin only within this distance (meters) of the focus, default 60 */
1359
- bobDistance?: number;
1360
1420
  /** Slot limit of the player inventory, default Infinity (no limit) */
1361
1421
  capacity?: number;
1362
1422
  /** Weight limit of the player inventory, default Infinity */
1363
1423
  maxWeight?: number;
1364
- /** Reach of pickups that do not set their own radius (meters), default 2 */
1365
- pickupRadius?: number;
1366
1424
  /** Default stack limit, default 99 */
1367
1425
  defaultStack?: number;
1368
1426
  }
@@ -1407,15 +1465,16 @@ export interface QuestDef {
1407
1465
  }
1408
1466
  /** engine.quests */
1409
1467
  export interface Quests {
1410
- 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
1468
  /** The quest log (UI part 'questLog'): open, toggle(on?), refresh() */
1414
1469
  win: { readonly open: boolean; toggle(on?: boolean): void; refresh(): void };
1415
1470
  /** Define a quest (chainable) */
1416
1471
  define(id: string, def: QuestDef): this;
1417
1472
  /** Start a quest */
1418
1473
  start(id: string): void;
1474
+ /** One quest's progress (a copy): step index, step count, done, failed, active; null before it starts */
1475
+ state(id: string): { step: number; steps: number; done: boolean; failed: boolean; active: boolean } | null;
1476
+ /** Finish the current step from code (its done() is not asked) and go on; the last step completes the quest. false when not active */
1477
+ advance(id: string): boolean;
1419
1478
  isDone(id: string): boolean;
1420
1479
  /** Started, not done and not failed */
1421
1480
  isActive(id: string): boolean;
@@ -1451,10 +1510,6 @@ export interface QuestLogView {
1451
1510
  export interface QuestsOptions {
1452
1511
  /** Action name that opens the quest log, default 'quests' */
1453
1512
  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
1513
  /** Check interval (game seconds, checked in the fixed step; not checked while frozen / paused), default 0.5 */
1459
1514
  checkInterval?: number;
1460
1515
  /**
@@ -1484,18 +1539,14 @@ export interface PhotoTakeOptions {
1484
1539
  scale?: number;
1485
1540
  /** Shadow resolution (pixels), default 4096 */
1486
1541
  shadowMapSize?: number;
1487
- /** Turn bloom on when taking a photo */
1488
- bloom?: boolean;
1542
+ /** Bloom for the shot: null (default) keeps what the game's post has; true / false forces it for that shot only */
1543
+ bloom?: boolean | null;
1489
1544
  /** Image quality 0–1 */
1490
1545
  quality?: number;
1491
1546
  /** Image format, e.g. 'image/jpeg' */
1492
1547
  format?: string;
1493
1548
  }
1494
1549
  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
1550
  /** How many photos the album keeps at most, default 50 */
1500
1551
  maxAlbum?: number;
1501
1552
  }
@@ -1538,10 +1589,12 @@ export interface UIWindow {
1538
1589
  refresh(): void;
1539
1590
  /** Open / close (toggle if no argument is passed) */
1540
1591
  toggle(on?: boolean): void;
1592
+ /** Remove the window: closed, its listeners and its element gone (a module passes the window to ctx.track instead) */
1593
+ remove(): void;
1541
1594
  }
1542
1595
  /** Parameters of makeWindow() */
1543
1596
  export interface WindowOptions {
1544
- /** Window name (also the style pack's template name) */
1597
+ /** Window name (also the style's template name) */
1545
1598
  id: string;
1546
1599
  /** Title */
1547
1600
  title: () => string;
@@ -1553,6 +1606,8 @@ export interface WindowOptions {
1553
1606
  data?: () => any;
1554
1607
  /** What to do on the back key (Esc), default closes the window (an open window is on the UI focus stack, and Esc goes only to the topmost) */
1555
1608
  onCancel?: () => void;
1609
+ /** false: no close button and Esc does nothing, so only the game's own buttons end it (a win or lose window must not drop the player back into the game). Default true */
1610
+ closable?: boolean;
1556
1611
  }
1557
1612
  /** An entry of the UI focus stack (returned by uiFocus(engine).push) */
1558
1613
  export interface FocusHandle extends Handle {
@@ -1561,7 +1616,19 @@ export interface FocusHandle extends Handle {
1561
1616
  cancel: (() => void) | null;
1562
1617
  /** Just pushed this frame (the key press that opened it must not count as its own action) */
1563
1618
  readonly fresh: boolean;
1619
+ /** The selected control / choice (null until the cursor first runs) */
1620
+ index: number | null;
1621
+ /** The choice cursor used confirm on this entry this frame (the owner's own confirm handling skips this frame) */
1622
+ readonly consumed: boolean;
1623
+ /** Change the cursor's controls while pushed (the index starts over); null = no cursor */
1624
+ setNav(nav: FocusNav | null): void;
1564
1625
  }
1626
+ /**
1627
+ * 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.
1628
+ * A function returning an element = the controls inside it (button, input, select, [data-nav]) in screen layout, the selected one gets .is-cursor;
1629
+ * an object = a list the owner draws itself (any direction steps by one).
1630
+ */
1631
+ export type FocusNav = (() => Element | null) | { count(): number; confirm(index: number): void; moved?(index: number): void };
1565
1632
  /**
1566
1633
  * 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
1634
  * the top; when the stack is empty it goes to the one registered by setRoot (the settings menu)
@@ -1571,8 +1638,10 @@ export interface UIFocus {
1571
1638
  readonly top: string | null;
1572
1639
  /** Names from bottom to top */
1573
1640
  list(): string[];
1574
- /** Push; without cancel = swallow the back key */
1575
- push(id: string, opts?: { cancel?: (() => void) | null }): FocusHandle;
1641
+ /** The top entry's choice cursor ({ id, index }) when it has a nav, else null */
1642
+ readonly cursor: { id: string; index: number } | null;
1643
+ /** Push; without cancel = swallow the back key; nav = the choice cursor's controls (see FocusNav) */
1644
+ push(id: string, opts?: { cancel?: (() => void) | null; nav?: FocusNav | null }): FocusHandle;
1576
1645
  /** What to do on the back key when the stack is empty (only one, a later registration replaces it) */
1577
1646
  setRoot(fn: () => void): Handle;
1578
1647
  }
@@ -1583,24 +1652,107 @@ export interface UIFocus {
1583
1652
  // ======================================================================
1584
1653
 
1585
1654
  /**
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
1655
+ * 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
1656
  * timers return a handle { remove() }
1588
1657
  */
1589
1658
  export interface Clock {
1590
1659
  /**
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
1660
+ * Calendar seconds = world-channel seconds x clock.rate, does not advance while paused / frozen, saved with the game;
1661
+ * one calendar day = calendar.dayLength calendar seconds
1662
+ */
1663
+ readonly now: number;
1664
+ /**
1665
+ * Calendar seconds per world-channel second (default 1; 0 stops the calendar, sky included). Read-only: change it with
1666
+ * `engine.mod('clock.rate', { owner: 'game', set: 60 })` (a minute per second); the handle's remove() undoes it
1593
1667
  */
1594
- now: number;
1668
+ readonly rate: number;
1669
+ /** Calendar seconds per real second right now (rate x the world channel's speed) */
1670
+ readonly speed: number;
1595
1671
  /**
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
1672
+ * Call fn after seconds calendar seconds; if an event name is passed, the event is emitted when due (with data, can be saved).
1673
+ * { channel } counts that time channel's seconds instead (a poison tick that slows down in bullet time)
1598
1674
  */
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;
1675
+ after(seconds: number, fnOrEvent: (() => void) | string, data?: any, opts?: { channel?: string }): Handle;
1676
+ /** Call once every seconds calendar seconds ({ channel }: 'real' or a time channel's seconds instead) */
1677
+ every(seconds: number, fn: () => void, opts?: { channel?: string }): Handle;
1678
+ }
1679
+
1680
+ /** The handle engine.mod / input.gate return: remove() ends only this owner's entry (a stale handle ends nothing) */
1681
+ export interface ModHandle {
1682
+ owner: string; remove(): void;
1683
+ /** 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 */
1684
+ change(value: any): boolean;
1685
+ }
1686
+ /** Shared-point layers, lowest first. Most code never passes one: game code and game modules are 'game'; effects (weather, bullet time) pass 'effect' */
1687
+ export type SharedLayer = 'engine' | 'game' | 'effect' | 'system' | 'settings' | 'debug';
1688
+ /**
1689
+ * 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;
1690
+ * 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
1691
+ * point on one layer throw shared-conflict in development. The settings layer only restricts (clamp / mul; set false on a value point).
1692
+ */
1693
+ export interface ModOptions {
1694
+ owner: string;
1695
+ set?: any; add?: number; mul?: number; clamp?: { min?: number; max?: number };
1696
+ /** 'top' points (the camera): the holder's value; 'any' ones: optional data kept beside the hold */
1697
+ value?: any;
1698
+ /** Seconds until it ends by itself, on clock ('real' by default: fixed seconds, stop while frozen; or a time channel name) */
1699
+ for?: number; clock?: string;
1700
+ /** The record, for per-record points ('time.local', your own per: true ones) */
1701
+ id?: string;
1702
+ /** Default 'game'. settings / system / debug entries are not saved */
1703
+ layer?: SharedLayer;
1704
+ }
1705
+ /** One entry as describe and holders() show it; at = the code line that took it (development builds) */
1706
+ export interface ModHolder { owner: string; at?: string; op?: 'set' | 'add' | 'mul' | 'clamp'; value?: any; layer?: SharedLayer; left?: number; clock?: string; hidden?: boolean; }
1707
+ /** 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) */
1708
+ export interface SharedRow { value: any; writer: string; layer?: SharedLayer; at?: string; how?: string; also: ModHolder[]; }
1709
+ /** One shared point (engine.stacks.get(name)): read it here; change it with engine.mod(name, { owner, ... }), the one way in. A settings row
1710
+ * restricts one with engine.settings.define(key, def, { limits: name }) */
1711
+ export interface Stack {
1712
+ readonly name: string; readonly kind: 'number' | 'value' | 'any' | 'top' | 'one';
1713
+ /** The describe().shared row */
1714
+ row(id?: string): SharedRow;
1715
+ /** The current value, always recomputed from base + the entries now present (a slot: the holder's name or null) */
1716
+ value(id?: string): any;
1717
+ holders(id?: string): ModHolder[];
1718
+ names(id?: string): string[];
1719
+ has(owner: string, id?: string): boolean;
1720
+ size(id?: string): number;
1721
+ /** End owner's entry; false when it held none */
1722
+ release(owner: string, opts?: { id?: string }): boolean;
1723
+ }
1724
+ /** engine.stacks: every shared point by name ('time.<channel>', 'time.local', 'clock.rate', 'freeze', 'pause', 'camera', 'debug.view', slots, your own) */
1725
+ export interface Stacks {
1726
+ /**
1727
+ * Define your own point: kind 'number' (default, base 1), 'value' (any data, set only), 'any' (true while held), 'top' (latest holder wins),
1728
+ * 'one' (exclusive slot); per: true = one value per record id; manual = the takeover call the conflict error offers
1729
+ */
1730
+ define(name: string, opts?: { kind?: 'number' | 'value' | 'any' | 'top' | 'one'; base?: any; min?: number; max?: number; per?: boolean | 'optional'; save?: boolean; manual?: string }): Stack;
1731
+ get(name: string): Stack;
1732
+ has(name: string): boolean;
1733
+ list(): string[];
1734
+ mod(name: string, opts: ModOptions): ModHandle;
1735
+ /** describe().shared: one row per point with entries */
1736
+ describe(): Record<string, SharedRow>;
1737
+ /** Everything one owner changes now, e.g. ['time.world (mul 0.8, effect)', 'inventory (holds)'] */
1738
+ of(owner: string): string[];
1739
+ }
1740
+ /** engine.time: time channels (world, player, your own). Speeds change only through engine.mod('time.<channel>', ...) */
1741
+ export interface Time {
1742
+ /** Define a channel; parent (default 'world') multiplies its speed */
1743
+ channel(name: string, opts?: { parent?: string | null; stack?: string }): Time;
1744
+ channels(): string[];
1745
+ /** Effective speed: parent x the channel's stack (x the record's 'time.local' stack when id is given) */
1746
+ scale(name: string, id?: string): number;
1747
+ /** Fixed steps run this playthrough: the one time counter (= engine.tick); every other time is a read-only view of it */
1748
+ readonly tick: number;
1749
+ /**
1750
+ * Seconds on a view: 'real' (tick / 60, no scale, stops while frozen), 'ambient' (= uniforms.uTime, keeps moving while frozen),
1751
+ * 'calendar' (= engine.clock.now) or a channel ('world', 'player', your own)
1752
+ */
1753
+ now(name: 'real' | 'ambient' | 'calendar' | 'world' | 'player' | (string & {})): number;
1754
+ /** 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 }) */
1755
+ dt(name: string, id?: string): number;
1604
1756
  }
1605
1757
  /** engine.vars: story flags and counters (autosaved) */
1606
1758
  export interface Vars {
@@ -1630,8 +1782,8 @@ export interface ContentConditionDef {
1630
1782
  ref?: ContentRef;
1631
1783
  /** One-line description */
1632
1784
  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;
1785
+ /** 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) */
1786
+ test(e: Engine, value: any, raw?: any, ctx?: { actor: string }): boolean;
1635
1787
  /** Write the value as human-readable text (for the game map) */
1636
1788
  describe?(value: any): string;
1637
1789
  }
@@ -1656,8 +1808,8 @@ export interface PropDef {
1656
1808
  /** Rotation about the Y axis (radians) */
1657
1809
  rot?: number;
1658
1810
  scale?: number;
1659
- /** Collision: 'box' cuboid, 'circle' cylinder, false none (default) */
1660
- collide?: 'box' | 'circle' | false;
1811
+ /** Collision: 'box' cuboid of the bounds, 'circle' cylinder on the model's base, { circle, occluder } the same with its radius in model meters (scales with the prop) and occluder: false so the follow camera passes it; false none (default) */
1812
+ collide?: 'box' | 'circle' | false | { circle: number; occluder?: boolean };
1661
1813
  /** Register for ray acceleration (engine.raycast can hit it), default true */
1662
1814
  static?: boolean;
1663
1815
  /** false: never drawn through engine.batching (default: repeated props batch automatically) */
@@ -1675,12 +1827,12 @@ export interface Content {
1675
1827
  * @example engine.content.load([baseContent, forestDlc], { places: { home } })
1676
1828
  */
1677
1829
  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 }) */
1830
+ /** Register a custom condition, e.g. condition('timeAfter', { ref: 'clock', test: (e, t) => e.calendar.timeOfDay >= t }) */
1679
1831
  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;
1832
+ /** 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) */
1833
+ test(cond: any, opts?: { actor?: string }): boolean;
1834
+ /** Run an effect (object, array or function (e, { actor })); actor = whose bag give / take change (default the running op's actor, else engine.actor) */
1835
+ run(effect: any, opts?: { actor?: string }): any;
1684
1836
  /** Place name -> position (load's places first, then level markers), null if none */
1685
1837
  place(name: string): XZ | null;
1686
1838
  /** Position form in content { place?, x?, z? } -> world coordinates */
@@ -1690,13 +1842,50 @@ export interface Content {
1690
1842
  * template('chest').container.capacity
1691
1843
  */
1692
1844
  template(name: string): Readonly<ContentTemplate>;
1845
+ /**
1846
+ * The fields one content entry may have (core/params.js spec format): what an editor panel lists and what content-check validates against.
1847
+ * name: a template name (placement fields plus its state fields, default = the value in state), an engine entry shape ('props', 'props.template',
1848
+ * 'props.grid', 'pickups', 'views'), a game kind that declares fields (content/rules.js kinds), or a world record id. Unknown names throw.
1849
+ * @example engine.content.fields('crop').stage // { type: 'int', optional: true, default: 0, min: 0, max: 4 }
1850
+ */
1851
+ fields(name: string): Record<string, ContentField>;
1852
+ /**
1853
+ * 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,
1854
+ * id `<template>#<n>` unless fields.id is given). fields: id, rot, scale, y (height above ground), items (container start goods), state fields
1855
+ * (stage too, for a template with stages).
1856
+ * @example engine.ops.define('chest.build', { run: (e, { x, z }) => e.content.spawn('chest', { x, z }, { items: { stick: 3 } }).id })
1857
+ */
1858
+ spawn(name: string, at: any, fields?: { id?: string; rot?: number; scale?: number; y?: number; items?: Record<string, number>; [stateField: string]: any }): WorldRecord;
1859
+ }
1860
+ /** 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 */
1861
+ export interface ContentTemplateStage {
1862
+ name: string;
1863
+ /** Game seconds spent in this stage; only the last stage may leave it out (it stays there) */
1864
+ duration?: number;
1865
+ /** Multiplies the instance's scale while in this stage */
1866
+ scale?: number;
1867
+ /** Model name shown from this stage on (until a later stage names another); default the template's model */
1868
+ model?: string | any[];
1869
+ }
1870
+ /** template:stage event: a template instance entered a new stage by growing (several stages crossed at once give one event) */
1871
+ export interface TemplateStageEvent { id: string; template: string; stage: number; name: string }
1872
+ /** One field of a content entry (engine.content.fields): the core/params.js spec as plain data */
1873
+ export interface ContentField {
1874
+ type: 'string' | 'number' | 'int' | 'bool' | 'position' | 'id' | 'any' | 'object' | 'array' | 'function';
1875
+ optional?: boolean;
1876
+ /** Only for template state fields: the value written in state (never written inside fields) */
1877
+ default?: any;
1878
+ min?: number;
1879
+ max?: number;
1880
+ values?: any[];
1881
+ desc?: string;
1693
1882
  }
1694
1883
  /** A content template: shared definition of a reusable object (recipes/30-templates.md) */
1695
1884
  export interface ContentTemplate {
1696
- /** Model name (style pack generator or assets name); every instance clones one shared prototype */
1885
+ /** Model name (style generator or assets name); every instance clones one shared prototype */
1697
1886
  model: string | any[];
1698
- /** Collision box or circle from the model's bounds; omitted = does not block */
1699
- collide?: 'box' | 'circle';
1887
+ /** Collision: 'box' cuboid of the bounds, 'circle' cylinder on the model's base, { circle, occluder } the same with its radius in model meters (scales with the instance) and occluder: false so the follow camera passes it; omitted or false = does not block */
1888
+ collide?: 'box' | 'circle' | false | { circle: number; occluder?: boolean };
1700
1889
  /** false = not registered for rays */
1701
1890
  static?: boolean;
1702
1891
  /** Interaction: using an instance runs op with { id } */
@@ -1709,6 +1898,20 @@ export interface ContentTemplate {
1709
1898
  animate?: (rec: WorldRecord, obj: Object3D, dt: number) => void;
1710
1899
  /** Instance state fields and their defaults, copied onto each record (saved) */
1711
1900
  state?: Record<string, any>;
1901
+ /**
1902
+ * Range / allowed values / description of state fields, checked on every placement and engine.content.spawn (dev) and by content-check. No default here:
1903
+ * 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 } }
1904
+ */
1905
+ fields?: Record<string, string | Omit<ContentField, 'default'>>;
1906
+ /**
1907
+ * Named stages over game time (a crop growing, a turret warming up, a building under construction). Each instance gets the state field stage
1908
+ * (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.
1909
+ */
1910
+ stages?: ContentTemplateStage[];
1911
+ /** Asked every step, near and far; false holds the current stage and the time blocked does not count (e.g. rec => rec.watered) */
1912
+ canGrow?: (rec: WorldRecord, e: Engine) => boolean;
1913
+ /** Gameplay per fixed step while near (world.simulate near); write record fields directly or with world.set, both are saved */
1914
+ update?: (rec: WorldRecord, dt: number, e: Engine) => void;
1712
1915
  }
1713
1916
 
1714
1917
  // ======================================================================
@@ -1807,17 +2010,23 @@ export interface HudMarker {
1807
2010
  /** Delete */
1808
2011
  remove(): void;
1809
2012
  }
2013
+ /** Screen corner / edge a counter or bar column sits at (default 'top-left'); each anchor stacks its own column */
2014
+ export type HudAnchor = 'top-left' | 'top' | 'top-right' | 'left' | 'right' | 'bottom-left' | 'bottom' | 'bottom-right';
1810
2015
  /** engine.hud: objective markers, counters, progress bars */
1811
2016
  export interface Hud {
1812
2017
  /** All markers */
1813
2018
  markers: HudMarker[];
1814
2019
  /** Add an objective marker: target is an object, position or place name */
1815
2020
  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;
2021
+ /** 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 */
2022
+ counter(id: string, opts: { label?: string; icon?: string; value?: number | string; max?: number; anchor?: HudAnchor }): void;
2023
+ /** Add n (default 1) to a number counter, return the new value; one not declared yet starts at 0 with its id as the label */
2024
+ add(id: string, n?: number): number;
2025
+ /** Current value of a counter or bar (number or text), undefined when there is none; reads what interactions.add({ counter }) has added up */
2026
+ value(id: string): number | string | undefined;
1818
2027
  /** Progress bar (calling again with the same id = update; calling every frame is fine, the DOM is untouched when the value is unchanged),
1819
2028
  * value/max 0–max */
1820
- bar(id: string, opts: { value: number; max?: number; label?: string }): void;
2029
+ bar(id: string, opts: { value: number; max?: number; label?: string; anchor?: HudAnchor }): void;
1821
2030
  /** Delete a counter or progress bar */
1822
2031
  remove(id: string): void;
1823
2032
  }