threedog 0.7.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (593) hide show
  1. package/CHANGELOG.md +411 -1
  2. package/README.md +8 -11
  3. package/core/{Animator.js → assets/Animator.js} +30 -18
  4. package/core/{Assets.js → assets/Assets.js} +131 -56
  5. package/core/{Baked.js → assets/Baked.js} +4 -4
  6. package/core/assets/assetEntry.js +302 -0
  7. package/core/{assetHot.js → assets/assetHot.js} +9 -7
  8. package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
  9. package/core/assets/assetLod.js +113 -0
  10. package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
  11. package/core/{assetReport.js → assets/assetReport.js} +7 -14
  12. package/core/{namedModel.js → assets/namedModel.js} +17 -13
  13. package/core/{Audio.js → audio/Audio.js} +47 -25
  14. package/core/{audioRules.js → audio/audioRules.js} +8 -5
  15. package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
  16. package/core/{Events.js → base/Events.js} +3 -3
  17. package/core/{I18n.js → base/I18n.js} +15 -12
  18. package/core/{Random.js → base/Random.js} +7 -4
  19. package/core/{Vars.js → base/Vars.js} +14 -4
  20. package/core/{easing.js → base/easing.js} +1 -1
  21. package/core/{errorCodes.js → base/errorCodes.js} +151 -125
  22. package/core/{errorHints.js → base/errorHints.js} +17 -10
  23. package/core/{errors.js → base/errors.js} +12 -10
  24. package/core/{events.generated.js → base/events.generated.js} +11 -0
  25. package/core/base/follows.js +26 -0
  26. package/core/base/math.js +66 -0
  27. package/core/{params.js → base/params.js} +5 -6
  28. package/core/base/saveValues.js +81 -0
  29. package/core/base/sections.js +97 -0
  30. package/core/base/spelling.js +32 -0
  31. package/core/base/util.js +32 -0
  32. package/core/{validate.js → base/validate.js} +34 -34
  33. package/core/{Engine.js → engine/Engine.js} +137 -91
  34. package/core/{Loading.js → engine/Loading.js} +34 -5
  35. package/core/{copies.js → engine/copies.js} +4 -4
  36. package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
  37. package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
  38. package/core/{loop.js → engine/loop.js} +88 -49
  39. package/core/engine/moduleSlots.js +176 -0
  40. package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
  41. package/core/engine/modules.js +503 -0
  42. package/core/{page.js → engine/page.js} +59 -29
  43. package/core/{plugins.js → engine/plugins.js} +21 -12
  44. package/core/{services.js → engine/services.js} +50 -40
  45. package/core/{startup.js → engine/startup.js} +66 -54
  46. package/core/{Input.js → input/Input.js} +67 -39
  47. package/core/{inputContext.js → input/inputContext.js} +14 -5
  48. package/core/input/inputKeyboard.js +39 -0
  49. package/core/{inputPad.js → input/inputPad.js} +24 -3
  50. package/core/{inputPointer.js → input/inputPointer.js} +11 -3
  51. package/core/input/inputSeat.js +66 -0
  52. package/core/{inputTouch.js → input/inputTouch.js} +24 -7
  53. package/core/{Budget.js → inspect/Budget.js} +21 -20
  54. package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
  55. package/core/{Describe.js → inspect/Describe.js} +34 -26
  56. package/core/{Inspect.js → inspect/Inspect.js} +39 -10
  57. package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
  58. package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
  59. package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
  60. package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
  61. package/core/{UrlState.js → inspect/UrlState.js} +60 -24
  62. package/core/{catalog.js → inspect/catalog.js} +15 -8
  63. package/core/{checks.js → inspect/checks.js} +7 -5
  64. package/core/{debugView.js → inspect/debugView.js} +4 -4
  65. package/core/{describeRender.js → inspect/describeRender.js} +24 -22
  66. package/core/{describeText.js → inspect/describeText.js} +17 -8
  67. package/core/inspect/geometryWatch.js +38 -0
  68. package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
  69. package/core/inspect/metadata.generated.js +4140 -0
  70. package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
  71. package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
  72. package/core/inspect/toolDoor.js +21 -0
  73. package/core/inspect/valueHistory.js +35 -0
  74. package/core/{Ops.js → ops/Ops.js} +44 -14
  75. package/core/{control.js → ops/control.js} +57 -31
  76. package/core/ops/holds.js +140 -0
  77. package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
  78. package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
  79. package/core/{opsFail.js → ops/opsFail.js} +5 -7
  80. package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
  81. package/core/{opsRun.js → ops/opsRun.js} +9 -6
  82. package/core/{owned.js → ops/owned.js} +33 -19
  83. package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
  84. package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
  85. package/core/{stacks.js → ops/stacks.js} +34 -15
  86. package/core/{wrap.js → ops/wrap.js} +8 -6
  87. package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
  88. package/core/{Saves.js → saves/Saves.js} +171 -54
  89. package/core/saves/saveApply.js +312 -0
  90. package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
  91. package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
  92. package/core/saves/session.js +231 -0
  93. package/core/saves/stateReplace.js +184 -0
  94. package/core/{Rays.js → scene/Rays.js} +44 -30
  95. package/core/{Views.js → scene/Views.js} +16 -8
  96. package/core/{adaptive.js → scene/adaptive.js} +19 -9
  97. package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
  98. package/core/scene/compositeGround.js +72 -0
  99. package/core/scene/floor.js +17 -0
  100. package/core/{gameLights.js → scene/gameLights.js} +17 -7
  101. package/core/{grayMap.js → scene/grayMap.js} +8 -2
  102. package/core/{grid.js → scene/grid.js} +6 -4
  103. package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
  104. package/core/scene/ground.contract.js +14 -0
  105. package/core/scene/ground.js +139 -0
  106. package/core/{movement.js → scene/movement.js} +3 -3
  107. package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
  108. package/core/scene/pixel.js +154 -0
  109. package/core/scene/pixelRatio.js +167 -0
  110. package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
  111. package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
  112. package/core/scene/stepPoses.js +60 -0
  113. package/core/{targeting.js → scene/targeting.js} +4 -5
  114. package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
  115. package/core/{thingOps.js → scene/thingOps.js} +25 -16
  116. package/core/{things.js → scene/things.js} +18 -5
  117. package/core/{threePatches.js → scene/threePatches.js} +1 -1
  118. package/core/{tier.js → scene/tier.js} +10 -0
  119. package/core/scene/view.js +161 -0
  120. package/core/{Batching.js → stream/Batching.js} +85 -28
  121. package/core/{Stream.js → stream/Stream.js} +80 -38
  122. package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
  123. package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
  124. package/core/{scatter.js → stream/scatter.js} +7 -4
  125. package/core/{streamSources.js → stream/streamSources.js} +14 -8
  126. package/core/{Commits.js → threads/Commits.js} +17 -11
  127. package/core/{Jobs.js → threads/Jobs.js} +25 -13
  128. package/core/{Threads.js → threads/Threads.js} +21 -18
  129. package/core/{threadPure.js → threads/threadPure.js} +7 -5
  130. package/core/{threadServe.js → threads/threadServe.js} +3 -3
  131. package/core/{Clock.js → time/Clock.js} +20 -11
  132. package/core/{dayTime.js → time/dayTime.js} +5 -1
  133. package/core/{skip.js → time/skip.js} +28 -21
  134. package/core/{time.js → time/time.js} +32 -20
  135. package/core/{uiClock.js → time/uiClock.js} +4 -4
  136. package/docs/AI.md +92 -72
  137. package/docs/API.md +33 -28
  138. package/docs/CODEMAP.md +121 -200
  139. package/docs/COMMANDS.md +77 -70
  140. package/docs/CONVENTIONS.md +167 -24
  141. package/docs/MIGRATING-0.8.md +171 -0
  142. package/docs/MIGRATING-1.0.md +101 -0
  143. package/docs/THREE.md +140 -38
  144. package/docs/api/assets.md +12 -13
  145. package/docs/api/audio.md +6 -5
  146. package/docs/api/budget.md +4 -4
  147. package/docs/api/calendar.md +10 -11
  148. package/docs/api/cameraRig.md +32 -29
  149. package/docs/api/characters.md +35 -24
  150. package/docs/api/clock.md +1 -1
  151. package/docs/api/collider3d.md +9 -0
  152. package/docs/api/collision.md +12 -9
  153. package/docs/api/content.md +18 -17
  154. package/docs/api/dialogue.md +5 -4
  155. package/docs/api/engine.md +58 -54
  156. package/docs/api/events.md +17 -6
  157. package/docs/api/flow.md +1 -1
  158. package/docs/api/grids.md +1 -1
  159. package/docs/api/ground.md +6 -7
  160. package/docs/api/hud.md +2 -2
  161. package/docs/api/i18n.md +6 -6
  162. package/docs/api/input.md +9 -8
  163. package/docs/api/interactions.md +5 -5
  164. package/docs/api/inventory.md +10 -10
  165. package/docs/api/jobs.md +5 -5
  166. package/docs/api/level.md +10 -9
  167. package/docs/api/lightPool.md +1 -6
  168. package/docs/api/music.md +3 -3
  169. package/docs/api/nav.md +14 -12
  170. package/docs/api/openWorld.md +1 -1
  171. package/docs/api/particles.md +10 -7
  172. package/docs/api/photo.md +4 -2
  173. package/docs/api/pickups.md +3 -3
  174. package/docs/api/post.md +21 -5
  175. package/docs/api/quests.md +7 -5
  176. package/docs/api/rays.md +7 -7
  177. package/docs/api/rigid.md +29 -19
  178. package/docs/api/saves.md +13 -11
  179. package/docs/api/settings.md +9 -8
  180. package/docs/api/sky.md +8 -7
  181. package/docs/api/stream.md +8 -9
  182. package/docs/api/swarm.md +34 -0
  183. package/docs/api/terrain.md +6 -8
  184. package/docs/api/terrainDraw.md +2 -2
  185. package/docs/api/timeline.md +4 -4
  186. package/docs/api/tools.md +27 -22
  187. package/docs/api/triggers.md +2 -0
  188. package/docs/api/vars.md +1 -1
  189. package/docs/api/vegetation.md +4 -3
  190. package/docs/api/vegetationDraw.md +2 -2
  191. package/docs/api/water.md +7 -3
  192. package/docs/api/weather.md +27 -12
  193. package/docs/api/weatherDraw.md +4 -4
  194. package/docs/api/world.md +6 -6
  195. package/docs/recipes/01-new-game.md +28 -43
  196. package/docs/recipes/02-npc.md +21 -23
  197. package/docs/recipes/03-items-pickups.md +37 -53
  198. package/docs/recipes/04-quests.md +5 -4
  199. package/docs/recipes/05-props-bake.md +34 -44
  200. package/docs/recipes/06-clock-events.md +31 -22
  201. package/docs/recipes/07-flow-scenes-pause.md +30 -32
  202. package/docs/recipes/08-weather-sky.md +91 -37
  203. package/docs/recipes/09-materials-lights-models.md +25 -39
  204. package/docs/recipes/10-blender-level.md +22 -11
  205. package/docs/recipes/11-vehicles.md +44 -24
  206. package/docs/recipes/12-navmesh.md +60 -15
  207. package/docs/recipes/13-animation.md +70 -22
  208. package/docs/recipes/14-custom-module.md +33 -20
  209. package/docs/recipes/15-perf.md +51 -28
  210. package/docs/recipes/16-dev-bridge.md +39 -58
  211. package/docs/recipes/18-world.md +49 -28
  212. package/docs/recipes/19-shooting-picking.md +7 -4
  213. package/docs/recipes/20-content-actions-save.md +55 -40
  214. package/docs/recipes/21-camera.md +47 -25
  215. package/docs/recipes/22-shop-gold.md +21 -16
  216. package/docs/recipes/23-ops.md +28 -24
  217. package/docs/recipes/26-ui-parts.md +25 -14
  218. package/docs/recipes/27-net.md +3 -5
  219. package/docs/recipes/28-terrain.md +119 -23
  220. package/docs/recipes/29-grid.md +3 -3
  221. package/docs/recipes/30-templates.md +63 -30
  222. package/docs/recipes/31-audio.md +7 -7
  223. package/docs/recipes/32-action-game.md +21 -11
  224. package/docs/recipes/33-stream-sources.md +6 -3
  225. package/docs/recipes/34-environment-lighting.md +72 -25
  226. package/docs/recipes/35-picture-from-reference.md +20 -23
  227. package/docs/recipes/36-ground-plants.md +106 -0
  228. package/docs/recipes/40-scene.md +18 -21
  229. package/docs/recipes/43-shader-patches-surfaces.md +27 -48
  230. package/docs/recipes/44-water-weather-hooks.md +56 -50
  231. package/docs/recipes/45-cascaded-shadows.md +41 -20
  232. package/docs/recipes/46-blender-art-route.md +9 -10
  233. package/docs/recipes/49-game-module-contract.md +7 -6
  234. package/docs/recipes/50-own-renderer.md +3 -2
  235. package/docs/recipes/51-capability-catalog.md +14 -8
  236. package/docs/recipes/52-around-the-picture.md +56 -100
  237. package/docs/recipes/53-ground-up-close.md +61 -24
  238. package/docs/recipes/55-mods-time-wrap.md +17 -20
  239. package/docs/recipes/56-webgpu-tsl.md +28 -15
  240. package/docs/recipes/57-control.md +39 -12
  241. package/docs/recipes/58-input.md +15 -2
  242. package/docs/recipes/59-depth-post-effects.md +1 -1
  243. package/docs/recipes/60-judge-the-picture.md +30 -25
  244. package/docs/recipes/62-picture-code.md +129 -39
  245. package/docs/recipes/63-third-person-start.md +19 -5
  246. package/docs/recipes/64-particles.md +54 -5
  247. package/docs/recipes/65-swarm.md +140 -0
  248. package/docs/recipes/66-common-tasks.md +313 -0
  249. package/examples/action/.threedog/content-index.json +1 -1
  250. package/examples/action/GAMEMAP.md +5 -5
  251. package/examples/perf-island/.threedog/content-index.json +1 -0
  252. package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
  253. package/examples/{sheepisland → perf-island}/assets.js +1 -1
  254. package/examples/{sheepisland → perf-island}/main.js +8 -8
  255. package/examples/{sheepisland → perf-island}/models.js +1 -1
  256. package/examples/{sheepisland → perf-island}/params.js +1 -1
  257. package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
  258. package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
  259. package/examples/{sheepisland → perf-island}/views.js +1 -1
  260. package/examples/plain-picture/GAMEMAP.md +4 -1
  261. package/examples/rc2d/GAMEMAP.md +4 -3
  262. package/examples/rc2d/main.js +1 -3
  263. package/examples/rc2d/rc2d.js +1 -1
  264. package/examples/styletest/.threedog/content-index.json +1 -1
  265. package/examples/styletest/GAMEMAP.md +6 -5
  266. package/examples/techniques/contact-shadows/contactShadows.js +1 -1
  267. package/examples/techniques/contact-shadows/main.js +1 -1
  268. package/examples/techniques/interior-light/main.js +1 -1
  269. package/examples/techniques/modular-building/README.md +7 -6
  270. package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
  271. package/examples/techniques/procedural-animation/README.md +1 -1
  272. package/examples/webgpu-tsl/GAMEMAP.md +2 -1
  273. package/examples/world/.threedog/content-index.json +1 -1
  274. package/examples/world/GAMEMAP.md +9 -7
  275. package/examples/world/main.js +3 -3
  276. package/examples/world/picture/sky.js +1 -1
  277. package/index.d.ts +16 -12
  278. package/index.js +53 -32
  279. package/llms.txt +11 -14
  280. package/modules/ambience/Ambience.js +16 -11
  281. package/modules/calendar/Calendar.js +19 -19
  282. package/modules/calendar/index.js +18 -16
  283. package/modules/calendar/schedule.js +11 -6
  284. package/modules/calendar/seasons.js +7 -7
  285. package/modules/camera/FirstPersonCamera.js +5 -5
  286. package/modules/camera/FixedCamera.js +43 -30
  287. package/modules/camera/FollowCamera.js +24 -15
  288. package/modules/camera/RtsCamera.js +12 -11
  289. package/modules/camera/common.js +72 -37
  290. package/modules/camera/contract.js +1 -0
  291. package/modules/camera/pixelSnap.js +62 -0
  292. package/modules/characters/Character.js +166 -70
  293. package/modules/characters/NPC.js +84 -44
  294. package/modules/characters/assetModel.js +16 -12
  295. package/modules/characters/astar.js +48 -27
  296. package/modules/characters/behaviors.js +4 -5
  297. package/modules/characters/character.contract.js +21 -0
  298. package/modules/characters/contract.js +17 -3
  299. package/modules/characters/index.js +240 -226
  300. package/modules/characters/moveHelpers.js +88 -12
  301. package/modules/characters/mover.contract.js +14 -0
  302. package/modules/characters/movers/common.js +22 -18
  303. package/modules/characters/movers/manual.js +1 -1
  304. package/modules/characters/movers/rapier.js +18 -10
  305. package/modules/characters/movers/simple.js +26 -13
  306. package/modules/characters/movers/support.js +24 -13
  307. package/modules/characters/npcAvoid.js +19 -16
  308. package/modules/characters/npcSim.js +88 -32
  309. package/modules/characters/npcView.js +19 -11
  310. package/modules/characters/pathAsync.js +81 -29
  311. package/modules/characters/pathJob.js +38 -21
  312. package/modules/characters/pathWorker.js +1 -1
  313. package/modules/characters/player.js +120 -0
  314. package/modules/characters/playerStrings.js +2 -2
  315. package/modules/characters/proceduralRig.js +2 -2
  316. package/modules/characters/seat.js +56 -0
  317. package/modules/characters/useModel.js +3 -3
  318. package/modules/characters/vehicle.contract.js +8 -5
  319. package/modules/characters/walkTo.js +40 -33
  320. package/modules/collision/Collision.js +69 -45
  321. package/modules/collision/contract.js +15 -0
  322. package/modules/collision/grid.js +6 -1
  323. package/modules/content/explain.js +2 -3
  324. package/modules/content/fields.js +24 -3
  325. package/modules/content/ids.js +5 -3
  326. package/modules/content/index.js +132 -114
  327. package/modules/content/loader.js +117 -140
  328. package/modules/content/markers.js +25 -0
  329. package/modules/content/models.js +54 -17
  330. package/modules/content/packs.js +5 -4
  331. package/modules/content/parts.js +2 -2
  332. package/modules/content/places.js +36 -0
  333. package/modules/content/props.js +22 -17
  334. package/modules/content/rules.js +47 -61
  335. package/modules/content/stages.js +7 -7
  336. package/modules/content/templates.js +80 -49
  337. package/modules/content/words.js +47 -0
  338. package/modules/debug/DebugPanel.js +14 -45
  339. package/modules/flow/contract.js +2 -1
  340. package/modules/flow/index.js +30 -16
  341. package/modules/gameplay/Container.js +17 -13
  342. package/modules/gameplay/Containers.js +23 -6
  343. package/modules/gameplay/Dialogue.js +93 -34
  344. package/modules/gameplay/Interactions.js +93 -51
  345. package/modules/gameplay/Inventory.js +64 -22
  346. package/modules/gameplay/Quests.js +146 -30
  347. package/modules/gameplay/boxOps.js +8 -1
  348. package/modules/gameplay/dialogueBubbles.js +16 -12
  349. package/modules/gameplay/inventoryOps.js +11 -8
  350. package/modules/gameplay/pickups.js +63 -37
  351. package/modules/gameplay/questLog.js +4 -2
  352. package/modules/gameplay/questSave.js +9 -4
  353. package/modules/gameplay/quests.contract.js +1 -1
  354. package/modules/grid/Grid.js +2 -2
  355. package/modules/grid/Layer.js +12 -8
  356. package/modules/grid/index.js +28 -23
  357. package/modules/grid/ops.js +43 -46
  358. package/modules/grid/preview.js +7 -7
  359. package/modules/grid/tiles.js +6 -6
  360. package/modules/hlod/index.js +42 -57
  361. package/modules/hud/index.js +22 -14
  362. package/modules/hud/parts.js +8 -8
  363. package/modules/level/contract.js +16 -0
  364. package/modules/level/heightfield.js +29 -31
  365. package/modules/level/index.js +113 -161
  366. package/modules/level/load.js +196 -0
  367. package/modules/level/meshes.js +65 -0
  368. package/modules/level/nodes.js +40 -23
  369. package/modules/lights/index.js +33 -183
  370. package/modules/lights/slots.js +93 -0
  371. package/modules/lights/sources.js +90 -0
  372. package/modules/music/Music.js +34 -28
  373. package/modules/music/rules.js +1 -1
  374. package/modules/nav/contract.js +16 -0
  375. package/modules/nav/index.js +180 -49
  376. package/modules/nav/navPath.js +45 -10
  377. package/modules/net/Client.js +7 -7
  378. package/modules/net/Host.js +7 -7
  379. package/modules/net/Net.js +1 -1
  380. package/modules/net/index.js +6 -5
  381. package/modules/net/sync.js +2 -2
  382. package/modules/net/transports.js +2 -2
  383. package/modules/particles/Particles.js +95 -29
  384. package/modules/particles/effect.js +86 -32
  385. package/modules/particles/shaders.js +19 -1
  386. package/modules/photo/Photo.js +23 -23
  387. package/modules/rigid/RigidBodies.js +255 -89
  388. package/modules/rigid/Vehicles.js +17 -8
  389. package/modules/rigid/collider3d.contract.js +26 -0
  390. package/modules/rigid/ragdoll.js +298 -0
  391. package/modules/rigid/ragdollBones.js +209 -0
  392. package/modules/rigid/refresh.js +10 -0
  393. package/modules/rigid/sync.js +51 -20
  394. package/modules/settings/Settings.js +177 -61
  395. package/modules/settings/apply.js +20 -13
  396. package/modules/settings/sections.js +19 -14
  397. package/modules/settings/strings.js +2 -2
  398. package/modules/settings/view.js +3 -3
  399. package/modules/sky/Sky.js +29 -22
  400. package/modules/sky/clouds.js +7 -7
  401. package/modules/sky/dome.js +33 -20
  402. package/modules/sky/domeLayers.js +9 -9
  403. package/modules/sky/environment.js +6 -6
  404. package/modules/sky/frame.js +19 -10
  405. package/modules/sky/season.js +7 -1
  406. package/modules/sky/shader.js +24 -25
  407. package/modules/sky/skyModule.js +17 -28
  408. package/modules/sky/tint.js +1 -1
  409. package/modules/swarm/Swarm.js +356 -0
  410. package/modules/swarm/draw.js +68 -0
  411. package/modules/swarm/grid.js +63 -0
  412. package/modules/terrain/ChunkManager.js +71 -59
  413. package/modules/terrain/chunkQueries.js +7 -24
  414. package/modules/terrain/chunkWorker.js +1 -1
  415. package/modules/terrain/draw.js +14 -11
  416. package/modules/terrain/index.js +42 -42
  417. package/modules/terrain/terrainColorMap.js +6 -3
  418. package/modules/terrain/terrainDefaults.js +2 -1
  419. package/modules/terrain/terrainEdit.js +45 -29
  420. package/modules/terrain/terrainGen.js +19 -12
  421. package/modules/terrain/terrainIsland.js +2 -2
  422. package/modules/terrain/terrainMesh.js +7 -6
  423. package/modules/terrain/terrainShape.js +8 -10
  424. package/modules/terrain/terrainShapeMain.js +3 -3
  425. package/modules/timeline/Timeline.js +83 -43
  426. package/modules/timeline/Tween.js +25 -19
  427. package/modules/timeline/shots.js +24 -17
  428. package/modules/triggers/index.js +95 -28
  429. package/modules/vegetation/Vegetation.js +34 -26
  430. package/modules/vegetation/densityMap.js +4 -7
  431. package/modules/vegetation/draw.js +39 -18
  432. package/modules/vegetation/groundChunks.js +21 -38
  433. package/modules/vegetation/index.js +37 -12
  434. package/modules/vegetation/modelGeometry.js +3 -6
  435. package/modules/vegetation/nearFade.js +1 -1
  436. package/modules/water/Water.js +20 -16
  437. package/modules/water/surface.js +3 -3
  438. package/modules/weather/Weather.js +52 -40
  439. package/modules/weather/particles.js +8 -8
  440. package/modules/weather/weatherDraw.js +28 -23
  441. package/modules/world/World.js +28 -15
  442. package/modules/world/explain.js +1 -1
  443. package/modules/world/index.js +30 -17
  444. package/modules/world/persist.js +90 -27
  445. package/modules/world/pos.js +5 -5
  446. package/modules/world/records.js +37 -11
  447. package/modules/world/sim.js +78 -27
  448. package/modules/world/simFar.js +2 -2
  449. package/modules/world/state.js +43 -11
  450. package/modules/world/thingSource.js +20 -5
  451. package/modules/world/views.js +27 -14
  452. package/package.json +48 -7
  453. package/presets.js +1 -3
  454. package/render/PostFX.js +83 -53
  455. package/render/backend.js +31 -33
  456. package/render/cascades.js +17 -12
  457. package/render/cascades.tsl.js +5 -8
  458. package/render/daylight.js +20 -3
  459. package/render/detail.js +8 -7
  460. package/render/effects.js +28 -25
  461. package/render/fuse.js +3 -3
  462. package/render/fx/cloudShadow.tsl.js +3 -3
  463. package/render/fx/detail.tsl.js +1 -1
  464. package/render/fx/index.js +5 -10
  465. package/render/fx/library.tsl.js +11 -0
  466. package/render/fx/lighting.tsl.js +2 -1
  467. package/render/fx/nodeErrors.tsl.js +2 -2
  468. package/render/fx/objectOrigin.tsl.js +1 -2
  469. package/render/fx/particles.tsl.js +8 -6
  470. package/render/fx/patchNodes.tsl.js +5 -15
  471. package/render/fx/postWebGPU.tsl.js +30 -26
  472. package/render/fx/sky.tsl.js +15 -17
  473. package/render/fx/uniforms.tsl.js +4 -4
  474. package/render/fx/wind.tsl.js +1 -1
  475. package/render/fxNumbers.js +3 -0
  476. package/render/layers.js +2 -2
  477. package/render/lighting.js +5 -3
  478. package/render/lightmap.js +41 -21
  479. package/render/lights.js +6 -6
  480. package/render/lit.js +24 -0
  481. package/render/materials.js +8 -7
  482. package/render/mergeCommon.js +22 -0
  483. package/render/modeling.js +2 -2
  484. package/render/occlusion.js +62 -15
  485. package/render/ownFrame.js +4 -4
  486. package/render/patches.js +15 -15
  487. package/render/postWebGL.js +15 -12
  488. package/render/probes.js +41 -19
  489. package/render/recordSweep.js +117 -0
  490. package/render/shaderErrors.js +10 -9
  491. package/render/shadowCache.tsl.js +107 -0
  492. package/render/shadowTypes.js +9 -0
  493. package/{core → render}/shadows.js +59 -13
  494. package/render/slots.js +7 -7
  495. package/render/terms.js +22 -24
  496. package/render/uniformDecl.js +1 -1
  497. package/types/core.d.ts +336 -202
  498. package/types/gameplay.d.ts +254 -130
  499. package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
  500. package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
  501. package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
  502. package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
  503. package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
  504. package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
  505. package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
  506. package/types/generated/core/input/inputSeat.d.ts +26 -0
  507. package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
  508. package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
  509. package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
  510. package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
  511. package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
  512. package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
  513. package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
  514. package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
  515. package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
  516. package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
  517. package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
  518. package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
  519. package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
  520. package/types/generated/modules/calendar/Calendar.d.ts +10 -11
  521. package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
  522. package/types/generated/modules/grid/Grid.d.ts +1 -0
  523. package/types/generated/modules/grid/Layer.d.ts +1 -1
  524. package/types/generated/modules/grid/index.d.ts +3 -3
  525. package/types/generated/modules/music/Music.d.ts +7 -5
  526. package/types/generated/modules/particles/Particles.d.ts +5 -4
  527. package/types/generated/modules/sky/Sky.d.ts +21 -10
  528. package/types/generated/modules/swarm/Swarm.d.ts +80 -0
  529. package/types/generated/modules/timeline/Timeline.d.ts +7 -5
  530. package/types/generated/modules/water/Water.d.ts +1 -0
  531. package/types/generated/modules/weather/Weather.d.ts +14 -16
  532. package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
  533. package/types/generated/modules/world/World.d.ts +11 -7
  534. package/types/generated/render/PostFX.d.ts +21 -23
  535. package/types/generated/render/materials.d.ts +1 -0
  536. package/types/generated/render/occlusion.d.ts +9 -0
  537. package/types/generated/render/patches.d.ts +1 -0
  538. package/types/generated/ui/Focus.d.ts +1 -0
  539. package/types/generated/ui/UI.d.ts +1 -0
  540. package/types/nav.d.ts +47 -15
  541. package/types/physics.d.ts +150 -73
  542. package/types/pixel.d.ts +75 -0
  543. package/types/tsl.d.ts +37 -4
  544. package/types/world.d.ts +48 -75
  545. package/ui/Focus.js +10 -9
  546. package/ui/Parts.js +13 -5
  547. package/ui/UI.js +7 -7
  548. package/ui/defaults.js +3 -2
  549. package/ui/theme.js +7 -5
  550. package/core/assetEntry.js +0 -109
  551. package/core/engineCamera.js +0 -32
  552. package/core/ground.js +0 -104
  553. package/core/holds.js +0 -134
  554. package/core/math.js +0 -48
  555. package/core/moduleSlots.js +0 -100
  556. package/core/modules.js +0 -314
  557. package/core/saveApply.js +0 -210
  558. package/core/saveValues.js +0 -46
  559. package/core/session.js +0 -174
  560. package/core/shadowTypes.js +0 -16
  561. package/core/util.js +0 -17
  562. package/core/view.js +0 -43
  563. package/docs/MIGRATING-0.3.md +0 -248
  564. package/docs/MIGRATING-0.4.md +0 -320
  565. package/docs/MIGRATING-0.5.md +0 -68
  566. package/docs/MIGRATING-0.6.md +0 -126
  567. package/docs/PERF.md +0 -245
  568. package/docs/recipes/36-sky-ground-plants.md +0 -158
  569. package/docs/recipes/37-terrain-hooks.md +0 -115
  570. package/docs/recipes/38-environment-hooks.md +0 -67
  571. package/docs/recipes/42-terrain-shape.md +0 -64
  572. package/docs/recipes/47-island-snow-backdrop.md +0 -43
  573. package/docs/recipes/54-three-idioms.md +0 -88
  574. package/examples/plain-picture/FINDINGS.md +0 -53
  575. package/examples/sheepisland/.threedog/content-index.json +0 -1
  576. package/modules/camera/projection.js +0 -21
  577. /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
  578. /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
  579. /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
  580. /package/core/{actor.js → ops/actor.js} +0 -0
  581. /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
  582. /package/core/{saveIds.js → saves/saveIds.js} +0 -0
  583. /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
  584. /package/core/{cells.js → stream/cells.js} +0 -0
  585. /package/core/{streamCells.js → stream/streamCells.js} +0 -0
  586. /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
  587. /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
  588. /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
  589. /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
  590. /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
  591. /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
  592. /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
  593. /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
@@ -1,13 +1,13 @@
1
1
  # engine.inventory — inventory(opts?: InventoryOptions)
2
2
 
3
- Inventory (inventory() module)
3
+ Inventory (inventory() module). Items, counts and containers, saved with the game. Install: engine.use(inventory()); undefined until installed. add() answers { ok }, read .ok
4
4
 
5
5
  - Options `InventoryOptions`:
6
6
  - `action?: string` Action name that opens the inventory, default 'inventory'
7
7
  - `pauseGame?: boolean` true: gameplay freezes (engine.freeze) while the inventory window is open, default false. Also settable at runtime: engine.inventory.pauseGame
8
8
  - `capacity?: number` Slot limit of the player inventory, default Infinity (no limit)
9
9
  - `maxWeight?: number` Weight limit of the player inventory, default Infinity
10
- - `defaultStack?: number` Default stack limit, default 99
10
+ - `defaultStack?: number` (experimental) Default stack limit, default 99
11
11
 
12
12
  ## Methods and properties
13
13
  - `inventory.of(actor?: string) → Container` — 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
@@ -16,21 +16,21 @@ Inventory (inventory() module)
16
16
  - `inventory.count(x: string) → number` — How many of an item, or of one entry key
17
17
  - `inventory.has(x: string, n?: number) → boolean` — Whether there are at least n (default 1)
18
18
  - `inventory.list() → ItemEntry[]` — Player inventory entries (for custom UI)
19
- - `inventory.get(key: string) → ItemEntry | null` — One player inventory entry by key, or null
20
- - `inventory.add(id: string, n?: number, opts?: { data?, silent? }) → string | false` — Add n to the player inventory (default 1), opts { data, silent }; returns the entry key, false if it does not fit
19
+ - `inventory.get(key: string) → ItemEntry | undefined` — One player inventory entry by key, or undefined
20
+ - `inventory.add(id: string, n?: number, opts?: { data?, silent? }) → ItemAddResult` — Add n to the player inventory (default 1), opts { data, silent }; returns { ok: true, key, added }, or { ok: false, code: 'full' } when none fit
21
21
  - `inventory.remove(x: string, n?: number) → boolean` — Remove n (default 1) of an item or entry key, returns false if there are not enough
22
22
  - `inventory.trade(take: string, give: string, opts?: { takeN?, giveN?, data?, silent? }) → { ok, code?, facts?, nextActions?, took?, gave?, … }` — 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 reverses it
23
23
  - `inventory.setData(key: string, data: Record<string, any> | null, n?: number) → string` — Replace a player inventory entry's data for n pieces (default all); returns the key now holding them
24
24
  - `inventory.container(id: string, opts?: { capacity?, maxWeight?, items? }) → Container` — Get or create a container (chest, corpse, shelf...); the id can be the id of a world record, and the contents are saved. A second call returns the same one; deleting the world record does not delete the container automatically
25
25
  - `inventory.transfer(from: Container | string, to: Container | string, item: string, n?: number) → number` — Move n (default 1) of an item or one entry key between containers (pieces keep data and key); moves fewer if the target cannot hold them all, returns how many were actually moved
26
26
  - `inventory.removeContainer(id: string) → boolean` — Delete a container together with its contents ('player' cannot be deleted), returns whether one was deleted
27
- - `inventory.contents() → Record<string, any[]>` — Every container's items as plain data, the player bag included: { [containerId]: entries } (what setContents takes; net syncs through these two)
28
- - `inventory.setContents(data: Record<string, any[] | null>, opts?: { only?: boolean })` — Replace containers' items from contents() data, silently like a save load; a null entry empties that container, only: true empties the rest too
27
+ - `inventory.contents() → Record<string, any[]>` — (experimental) Every container's items as plain data, the player bag included: { [containerId]: entries } (what setContents takes; net syncs through these two)
28
+ - `inventory.setContents(data: Record<string, any[] | null>, opts?: { only?: boolean })` — (experimental) Replace containers' items from contents() data, silently like a save load; a null entry empties that container, only: true empties the rest too
29
29
  - Properties:
30
30
  - `pauseGame: boolean` true: gameplay freezes while the inventory window is open (set from inventory({ pauseGame }) or at runtime)
31
- - `capacity: number` Slot limit of the player inventory
32
- - `bag: Container` Player inventory: the bag of engine.actor (= of())
33
- - `slotsUsed: number` Slots used
31
+ - `capacity: number` (experimental) Slot limit of the player inventory
32
+ - `bag: Container` (experimental) Player inventory: the bag of engine.actor (= of())
33
+ - `defaultStack: number` (experimental)
34
34
 
35
35
  ## Data structures
36
36
  - **ItemDef** Item definition
@@ -56,7 +56,7 @@ Inventory (inventory() module)
56
56
  - `radius?: number` Reach in meters, default pickups({ radius }) (2)
57
57
  - `auto?: boolean` Taken by walking into it (no key press, no prompt), by every actor in pickups.takers
58
58
  - `mesh?: Object3D | null` The game's own three.js object for this one pickup (only detached when it goes; otherwise the model name decides the shape)
59
- - `respawnSeconds?: number` Game seconds until it reappears, 0 = never reappears
59
+ - `respawnSeconds?: number` Calendar seconds until it reappears, 0 = never reappears
60
60
  - `bob?: boolean` Bob up and down and rotate, default true
61
61
  - `initial?: boolean` Pickup authored in content (needs an id): the initial record of world; saves record only being picked up / waiting to respawn, with identical results whether the load comes before or after this spawn
62
62
  - `zone?: string | null` Which zone it belongs to (a level name, see world.zone): the data stays across level changes (a picked-up one stays picked up)
package/docs/api/jobs.md CHANGED
@@ -3,8 +3,8 @@
3
3
  - `jobs.add(work: (() => T) | (() => Generator<any, T, a…) | Generator<any, T, any> | …, opts?: { priority?, apply?, lag?, valid? }) → Promise<T>` — Add a job: a plain function runs in one go, a generator may pause at each yield until the next frame; higher priority runs first; returns the job's result. A job that changes gameplay state passes apply: the result takes effect on a fixed tick via engine.commits (lag fixed steps later, default 30), and is finished on the spot if not done by then, so machine speed does not affect gameplay. Such a job must be a plain function or generator (it cannot return a Promise). With apply, the returned Promise resolves when the work finishes, before apply may have run; put logic that needs "state already changed" inside apply. A step over slowStepMs warns in dev to slice it with yield. Example: `await engine.jobs.add(function* () { for (const p of props) { place(p); yield; } }, { priority: 10 });`
4
4
  - `jobs.run(opts?: { deterministic?: boolean })` — Run the queue (the engine calls this each frame): by millisecond budget by default; deterministic: true ignores real time and drains it (used by step)
5
5
  - Properties:
6
- - `budgetMs: number` Milliseconds allowed per frame, default 3
7
- - `loadingMs: number` Milliseconds allowed per frame while the loading screen is up, default 12
8
- - `maxSteps: number` Max steps per deterministic run (stops jobs that keep adding jobs from hanging), default 100000
9
- - `slowStepMs: number` A step slower than this many ms warns in dev (default 8)
10
- - `pending: number` Number of jobs not yet finished
6
+ - `budgetMs: number` (experimental) Milliseconds allowed per frame, default 3
7
+ - `loadingMs: number` (experimental) Milliseconds allowed per frame while the loading screen is up, default 12
8
+ - `maxSteps: number` (experimental) Max steps per deterministic run (stops jobs that keep adding jobs from hanging), default 100000
9
+ - `slowStepMs: number` (experimental) A step slower than this many ms warns in dev (default 8)
10
+ - `pending: number` (experimental) Number of jobs not yet finished
package/docs/api/level.md CHANGED
@@ -10,24 +10,25 @@ Hand-built level (level() module)
10
10
  - `cellSize?: number` Heightfield cell size (meters), default 0.5
11
11
  - `outside?: number` Ground height outside the level (meters), default 0
12
12
  - `waterLevel?: number` Water surface height (meters), default no water
13
- - `colliderPad?: number` Expand the collision box outward by this much (meters)
14
- - `colliderHeight?: number` Minimum height of the collision box (meters)
15
- - `sharpEdge?: number` Treat it as a step edge when the height difference between adjacent grid points exceeds this (meters), default 0.6
16
- - `hideMarkers?: boolean` Hide the marker placeholder meshes, default true
17
- - `addToScene?: boolean` Add the scene to engine.scene, default true
13
+ - `colliderPad?: number` (experimental) Expand the collision box outward by this much (meters)
14
+ - `colliderHeight?: number` (experimental) Minimum height of the collision box (meters)
15
+ - `sharpEdge?: number` (experimental) Treat it as a step edge when the height difference between adjacent grid points exceeds this (meters), default 0.6
16
+ - `hideMarkers?: boolean` (experimental) Hide the marker placeholder meshes, default true
17
+ - `part?: boolean` true: do not take the ground slot; compositeGround({ parts: [{ of: 'level' }] }) does and reads level.ground
18
+ - `addToScene?: boolean` (experimental) Add the scene to engine.scene, default true
18
19
 
19
20
  ## Methods and properties
20
21
  - `level.marker(name: string) → LevelMarker | null` — Get a marker, null if none
21
22
  - `level.markersWith(prefix: string) → LevelMarker[]` — Get all markers whose names start with prefix, e.g. markersWith('npc_')
22
- - `level.unload()` — Unload the level (the scene is fully deleted with engine.remove; collision, ray registrations and things registered with track are removed together)
23
- - `level.load(urlOrScene: string | Object3D) → Promise<void>` — Change level: unload the current one, load the new one (glTF path/asset name, or a THREE object), and emit level:loaded when done. When a load changes level, the save system waits for it
23
+ - `level.unload()` — (experimental) Unload the level (the scene is fully deleted with engine.remove; collision, ray registrations and things registered with track are removed together)
24
+ - `level.load(urlOrScene: string | Object3D, opts?: { turn?: SaveTurn }) → Promise<void>` — Change level (glTF path/asset name, or a THREE object). The new level is built first and replaces the old one only when that worked: level:loaded fires then. On failure the old level stays, level:failed fires and the Promise rejects. When a load changes level, the save system waits for it, and a level that fails rolls the save back. A load overtaken by a newer one or an unload resolves without a level. During a save load it waits for that load to end; a part's load() or an afterLoad passes the turn it got, and it goes at once
24
25
  - `level.track(handle: T) → T` — Register things that belong to the current level and need not be kept (the { remove() } handles of triggers...); they are deleted automatically on level change / unload; returns the same handle. world data that keeps state (NPCs, pickups, props) needs no registration: with a zone, a level change only tears down the model
25
26
  - Properties:
26
27
  - `root: Object3D | null` Scene root node
27
28
  - `markers: Record<string, LevelMarker>` All markers: name -> marker
28
29
  - `spawn: Vector3` Spawn point position
29
- - `heightfield: any` Heightfield (for debugging)
30
- - `ready: boolean` Whether loading is finished
30
+ - `heightfield: any` (experimental) Heightfield (for debugging)
31
+ - `ready: boolean` The level's state is committed and nothing is loading; level:loaded fires at this moment, level:playable once every module and required nearby build settled too. After unload() it is true with no level, since nothing is loading: root says whether a level stands
31
32
 
32
33
  ## Data structures
33
34
  - **LevelMarker** Markers in the level (spawn, npc_*, trigger_*, marker_*), in world coordinates
@@ -12,14 +12,13 @@ Light pool: many light sources, a fixed number of real lights (lightPool() modul
12
12
 
13
13
  ## Methods and properties
14
14
  - `lightPool.add(position: PositionLike, opts?: LightSourceOptions) → LightSource` — Register a light source at a position (an Object3D: it follows that object every frame). Example: `const torch = engine.lightPool.add(torchMesh, { color: 0xffa040, intensity: 4, distance: 8, glow: haloSprite }); torch.set({ intensity: 0 }); // put out: its light goes to another torch`
15
- - `lightPool.usage() → LightPoolUsage` — What the pool is doing now (also in describe().lightPool)
16
15
  - Properties:
17
16
  - `lights: Object3D[]` The real three.js lights, created once at install and never added, removed or hidden (the pool sets their position, color, intensity)
18
17
  - `focus: PositionLike | null` Distance is measured from this object / position; null = the camera
19
18
 
20
19
  ## Data structures
21
20
  - **LightSourceOptions** Options of lightPool.add(position, opts): one light source (a torch, lamp, campfire, muzzle flash...)
22
- - `name?: string` Name shown in lightPool.usage()
21
+ - `name?: string` Name shown in describe().lightPool
23
22
  - `type?: 'point' | 'spot'` 'point' (default) or 'spot' (needs lightPool({ spot: n }))
24
23
  - `color?: ColorLike` Light color, default white
25
24
  - `intensity?: number` three.js intensity, default 1; 0 = off (gives its light away). With decay 2 a surface d m away gets intensity / d^2: pick it for the distance to what it lights (one that pools on a street 4 m below blows a wall 1 m away to white). Example values are no targets: threedog shot / snap name a light that glares.
@@ -52,7 +51,3 @@ Light pool: many light sources, a fixed number of real lights (lightPool() modul
52
51
  - `weight: number` How much of its light it has now, 0-1
53
52
  - `set(patch: LightSourcePatch) → LightSource` — Change the source; returns the same handle
54
53
  - `remove()` — Unregister: its light fades out and moves on, the stand-in is put back (safe to call twice)
55
- - **LightPoolUsage** lightPool.usage(): what the pool is doing now
56
- - `sources: number` Registered sources
57
- - `lit: number` Real lights lighting a source now
58
- - `slots: { type, shadow, source, weight }[]` One per real light: its kind, whether it casts shadows, the source it holds (name or number, null = idle) and its fade 0-1
package/docs/api/music.md CHANGED
@@ -7,12 +7,12 @@ Background music (music() module)
7
7
  - `rules?: MusicRule[]` Auto track rules (same as engine.music.rules(list))
8
8
  - `fade?: number` Default crossfade seconds, default 2
9
9
  - `duckDialogue?: number | false` Duck the music bus during dialogue to this (0-1, e.g. 0.35); default false = no duck (the game opts in)
10
- - `duckFade?: number` Fade seconds for the ducking
10
+ - `duckFade?: number` (experimental) Fade seconds for the ducking
11
11
  - `hold?: number` Rule debounce seconds, default 2
12
12
  - `interval?: number` Rule check interval (seconds), default 1
13
13
 
14
14
  ## Methods and properties
15
- - `music.addTracks(map: Record<string, MusicTrack>)` — Register tracks: { name: url / { url, volume, loop, stems } }
15
+ - `music.define(name: string, track: MusicTrack)` — Define a track: a url, or { url, volume, loop, stems }. The same name again replaces it. Example: `engine.music.define('town', '/music/town.ogg')`
16
16
  - `music.play(name: string | null, opts?: { fade?: number; force?: boolean })` — Play a track (cross-fade over fade seconds). Does nothing if it is already playing; force replays it
17
17
  - `music.stop(opts?: { fade?: number })` — Fade out and stop (fade over fade seconds; default the music({ fade }) option). An options object like play's: stop(3) throws in dev
18
18
  - `music.stinger(name: string, opts?: { duck?: number; volume?: number })` — Layer a one-shot piece (victory, discovered place...); the background dips to `duck` while it plays
@@ -24,7 +24,7 @@ Background music (music() module)
24
24
  - `current: string | null` Name of the track playing (or wanted)
25
25
  - `intensity: number` 0-1: how loud each stem of the playing track is (see the stems `at` range); fades in about half a second
26
26
  - `ready: boolean` Whether audio is usable
27
- - `ruled: boolean` Auto track rules are in use
27
+ - `ruled: boolean` (experimental) Auto track rules are in use
28
28
  - `state: { current, playing, pending, override, intensity, gain, … }` State (for debugging and tests): gain is the playing track's fade level, stems each stem's level
29
29
 
30
30
  ## Data structures
package/docs/api/nav.md CHANGED
@@ -4,26 +4,28 @@ Navmesh (nav() module)
4
4
 
5
5
  - Options `NavOptions`:
6
6
  - `cellSize?: number` Voxel cell size (meters), default 0.3; smaller is more accurate but slower to build
7
- - `agentRadius?: number` Character radius (meters), default reads engine.movement.radius (this is an override)
7
+ - `agentRadius?: number` Character radius (meters), default reads engine.movement.radius (this is an override). The mesh built at load; a path with another radius gets a mesh of its own, on first ask
8
8
  - `agentHeight?: number` Character height (meters), default reads engine.movement.height
9
9
  - `maxClimb?: number` Step height that can be climbed (meters), default reads engine.movement.stepHeight
10
10
  - `maxSlope?: number` Max walkable slope (degrees), default reads engine.movement.maxSlope
11
- - `tileSize?: number` Tile size (in cells), default 32
11
+ - `tileSize?: number` (experimental) Tile size (in cells), default 32
12
12
  - `crowd?: boolean` NPCs use Recast crowd avoidance, default false
13
13
  - `debug?: boolean` Show the navmesh (debug), default false
14
- - `maxObstacles?: number` Most TileCache obstacles (collision boxes are cut into several), default 1024
15
- - `maxAgents?: number` Most crowd agents (with crowd: true), default 128
14
+ - `maxObstacles?: number` (experimental) Most TileCache obstacles (collision boxes are cut into several), default 1024
15
+ - `maxAgents?: number` (experimental) Most crowd agents (with crowd: true), default 128
16
16
  - `arrive?: number` Meters past the character's radius a path may end short of its goal and still count as arrived, default 0.6
17
+ - `links?: NavLink[]` (experimental) Places joined by a jump or a climb instead of walking (Recast off-mesh connections); walkers cross them straight unless the game says otherwise
17
18
 
18
19
  ## Methods and properties
19
- - `nav.findPath(from: PositionLike, to: PositionLike, opts?: { radius?, detailed? }) → XZ[] | null` / `findPath(from: PositionLike, to: PositionLike, opts: { radius?: number; detailed: true }) → { status, path }` — Path from from to to [{ x, z }…] (meters); null if not ready or unreachable. Usually use engine.characters.findPath
20
+ - `nav.findPath(from: PositionLike, to: PositionLike, opts?: { radius?, detailed? }) → NavPathPoint[] | null` / `findPath(from: PositionLike, to: PositionLike, opts: { radius?: number; detailed: true }) → { status, path }` — Path from from to to [{ x, y, z }…] (meters); null if not ready or unreachable; radius: the body it must fit, default agentRadius. Usually use engine.characters.findPath
20
21
  - `nav.dispose()` — Unload the navmesh (frees native objects); characters.findPath then falls back to A*
21
22
  - Properties:
22
23
  - `ready: boolean` The navmesh has been generated
23
- - `navMesh: any` Native Recast NavMesh (null until ready)
24
- - `query: any` Native Recast NavMeshQuery
25
- - `tileCache: any` Native Recast TileCache (for dynamic obstacles)
26
- - `crowd: any` Native Recast Crowd (only when crowd: true)
27
- - `helper: any` three.js object for the debug display (only when debug: true)
28
- - `version: number` +1 on rebuild / unload: code that cached native objects (crowd agents etc.) must recreate them when it changes
29
- - `agent: { radius, height, maxClimb, maxSlope } | null` Character size actually in effect (from engine.movement, or the override in nav())
24
+ - `links: readonly { id: string | number; from: { x: number; y: numbe…` (experimental) The links in effect, ends in 3D, in the order given to nav({ links }); empty until the mesh is built
25
+ - `navMesh: any` (experimental) Native Recast NavMesh (null until ready)
26
+ - `query: any` (experimental) Native Recast NavMeshQuery
27
+ - `tileCache: any` (experimental) Native Recast TileCache (for dynamic obstacles)
28
+ - `crowd: any` (experimental) Native Recast Crowd (only when crowd: true)
29
+ - `helper: any` (experimental) three.js object for the debug display (only when debug: true)
30
+ - `version: number` (experimental) +1 on rebuild / unload: code that cached native objects (crowd agents etc.) must recreate them when it changes
31
+ - `agent: { radius, height, maxClimb, maxSlope } | null` (experimental) Character size actually in effect (from engine.movement, or the override in nav())
@@ -7,7 +7,7 @@
7
7
  - `density?: number` Vegetation density multiplier
8
8
  - `flatten?: FlattenZone[]` Flatten a plot (for a house)
9
9
  - `time?: number` Start time 0-1
10
- - `dayLength?: number` Game seconds per day (default 360)
10
+ - `dayLength?: number` Calendar seconds per day (default 360)
11
11
  - `weather?: WeatherName | (string & {}) | Part<typeof weather>` Starting weather name, false (no weather module) or weather() options
12
12
  - `autoWeather?: boolean` Automatic weather changes
13
13
  - `camera: 'follow' | 'firstPerson' | 'rts' | 'fixed' | ModuleDef | false` Required, no default: 'follow' / 'firstPerson' / 'rts' / 'fixed', a camera module with options (e.g. followCamera(presets.camera.overShoulder)), or false
@@ -9,16 +9,16 @@ Particles (particles() module)
9
9
  ## Methods and properties
10
10
  - `particles.define(name: string, opts?: ParticleOptions) → ParticleEffect` — Define an effect (same name replaces it, and emitters attached to it move to the new definition); params sit on top of particles({ effects, default }). Returns the effect object: .points is its THREE.Points (a Sprite on WebGPURenderer); .material is its plain three.js material (set your own and it is drawn as given, null gives the engine's back); .uniforms are the engine material's { value } objects (uMap, uHasMap, uScale, uMaxPx), which a ShaderMaterial of yours can share. A material of yours lasts until the effect is defined again. Example: `engine.particles.define('sparks', { blending: 'additive' }).material = myMaterial;`
11
11
  - `particles.has(name: string) → boolean` — Whether this effect has been defined
12
- - `particles.emit(name: string, position: PositionLike, opts?: { count?, overrides? })` — Burst: emit count particles at once (default 10) at position (Vector3 / Object3D / [x, y, z] / {x, y, z}). overrides affect this batch only (color, speed, direction...; max/texture/blending cannot be changed temporarily)
13
- - `particles.attach(name: string, object3d: THREE.Object3D, opts?: { rate?, offset?, overrides? }) → ParticleEmitter` — Keep emitting while following an object: rate per second, offset in the object's local coordinates [x, y, z] (meters). Returns a handle { remove(), rate, active } (active = false pauses)
12
+ - `particles.emit(name: string, position: PositionLike, opts?: { count?, overrides? })` — Burst: emit count particles at once (default 10) at position (Vector3 / Object3D / [x, y, z] / {x, y, z}). overrides affect this batch only (color, speed, direction...; max/texture/blending/soft cannot be changed temporarily)
13
+ - `particles.attach(name: string, object3d: THREE.Object3D, opts?: { rate?, ratePerMeter?, offset?, overrides? }) → ParticleEmitter` — Keep emitting while following an object: rate per second, ratePerMeter per meter it moves (spread along the path, on top of rate), offset in the object's local coordinates [x, y, z] (meters). Returns a handle { remove(), rate, ratePerMeter, active } (active = false pauses)
14
14
  - `particles.count(name?: string) → number` — Live particle count (no name = all)
15
15
  - `particles.clear(name?: string)` — Clear one effect's (or all) particles
16
16
  - Properties:
17
- - `effects: Map<string, ParticleEffect>` Defined effects
17
+ - `effects: Map<string, ParticleEffect>` (experimental) Defined effects
18
18
 
19
19
  ## Data structures
20
20
  - **ParticleOptions** Particle effect parameters (define(), and each entry of particles({ effects, default })). All optional
21
- - `max?: number` Maximum alive at once, default 120 (halved on low-end devices)
21
+ - `max?: number` Maximum alive at once, default 120 (60 on low-tier devices; a number the game gives stands)
22
22
  - `lifetime?: Range` Seconds each particle lives [min, max]
23
23
  - `rate?: number` Default particles per second for attach
24
24
  - `speed?: Range` Initial speed (m/s) [min, max]
@@ -29,16 +29,19 @@ Particles (particles() module)
29
29
  - `drag?: number` Air drag (fraction of speed lost per second)
30
30
  - `wind?: number` How much wind affects it
31
31
  - `windDir?: number[]` Wind direction [x, y, z]
32
- - `size?: Range` Size at birth / at death (meters)
33
- - `color?: ColorLike | ColorLike[]` Color at birth / at death (one color, or [birth, death]; an array, not a tuple, so a plain JS literal [0xffffff, 0xdddddd] type-checks)
34
- - `opacity?: Range` Opacity at birth / at death, 0–1
32
+ - `size?: Range | number[][]` Size at birth / at death (meters), or stops over life: evenly spaced [a, b, c] or timed [[0, a], [0.2, b], [1, c]] (0 birth, 1 death)
33
+ - `color?: ColorLike | ColorLike[] | ColorLike[][]` Color at birth / at death (one color, or [birth, death]; an array, not a tuple, so a plain JS literal [0xffffff, 0xdddddd] type-checks), or stops over life as for size
34
+ - `opacity?: Range | number[][]` Opacity at birth / at death, 0–1, or stops over life as for size: [[0, 0], [0.1, 0.8], [1, 0]] fades in, then out
35
35
  - `texture?: string | Texture | null` Texture (asset name, path or THREE.Texture); a soft round dot if omitted
36
36
  - `blending?: Loose<'normal' | 'additive'>` 'normal' / 'additive' (glowing blend, for sparks)
37
37
  - `spin?: number` Texture rotation speed (radians/second)
38
38
  - `worldSpace?: boolean` With attach, whether particles stay in the world (true) or the emission direction rotates with the object (false)
39
39
  - `fog?: boolean` Affected by fog, default true
40
40
  - `maxPixels?: number` Largest on-screen size of one particle in pixels (smoke drifting past the camera stays bounded), default 512
41
+ - `ratePerMeter?: number` (experimental) Default particles per meter the emitter moves for attach, on top of rate, spread along the path it moved; default 0
42
+ - `soft?: number` (experimental) Meters over which a particle fades where it meets what writes depth; default 0, off. Set at define, not in overrides. On WebGLRenderer it costs one depth-only draw of the scene per render while such an effect is on screen
41
43
  - **ParticleEmitter** (extends Handle) Continuous emitter returned by attach() (a handle)
42
44
  - `rate: number` Particles per second (can be changed at any time)
45
+ - `ratePerMeter: number` (experimental) Particles per meter the object moves, on top of rate (can be changed at any time)
43
46
  - `active: boolean` false pauses
44
47
  - `remove()` — Stop and remove (also removed automatically when the object leaves the scene)
package/docs/api/photo.md CHANGED
@@ -3,11 +3,13 @@
3
3
  Photo mode (photo() module)
4
4
 
5
5
  - Options `PhotoOptions` (also includes the fields of PhotoTakeOptions):
6
- - `maxAlbum?: number` How many photos the album keeps at most, default 50
6
+ - `maxAlbum?: number` (experimental) How many photos the album keeps at most, default 50
7
7
 
8
8
  ## Methods and properties
9
9
  - `photo.take(opts?: PhotoTakeOptions) → PhotoShot` — Capture a photo now without checks. Gameplay takes photos through the op: engine.ops.run('photo.take') (checks canTake, logged)
10
- - `photo.subject() → { name, kind, distance } | null` — What is in the middle of the frame (NPC, entity, named object, vegetation), null if nothing; this is the subject of take()
10
+ - `photo.subject() → { name, kind, distance } | null` — (experimental) What is in the middle of the frame (NPC, entity, named object, vegetation), null if nothing; this is the subject of take()
11
11
  - Properties:
12
12
  - `album: PhotoShot[]` Album (newest first)
13
13
  - `canTake: () => boolean | string` The op photo.take's can: return true, or false / a reason string to refuse (e.g. () => engine.inventory.has('film') // 'noFilm')
14
+ - `format: string` (experimental)
15
+ - `maxAlbum: number` (experimental)
@@ -1,10 +1,10 @@
1
1
  # engine.pickups — pickups(opts?: PickupsOptions)
2
2
 
3
- pickups()
3
+ pickups(). Things on the ground that go in the bag. Install: engine.use(pickups()) with inventory() and interactions(); undefined until installed. A full bag leaves the item on the ground
4
4
 
5
5
  - Options `PickupsOptions`:
6
6
  - `radius?: number` Reach of pickups that do not set their own radius (meters), default 2
7
- - `showDistance?: number` Pickups have a model, float and spin only within this distance (meters) of the stream sources, default 60
7
+ - `showDistance?: number` (experimental) Pickups have a model, float and spin only within this distance (meters) of the stream sources, default 60
8
8
  - `takers?: (e: Engine) => string[]` Who walks into auto pickups (actor ids); default engine.actor, plus net peers on a host
9
9
  - `color?: ColorLike` Color of the placeholder box and geometry-only models when the pickup and its item set none, default 0xcccccc
10
10
  - `size?: number` Edge of the placeholder box (meters), default 0.25
@@ -18,4 +18,4 @@ pickups()
18
18
  - `takers: (e: Engine) => string[]` Who walks into auto pickups: default engine.actor plus net peers on a host, none on a client
19
19
  - `material: Material` 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 vertex-colored geometry draws with a copy of it carrying that color. Example: `engine.pickups.material = new THREE.MeshStandardMaterial({ color: 0xffd24a, metalness: 0.8 })`
20
20
  - `size: number` Edge of the placeholder box (meters), read when one is built
21
- - `lift: number` Height above the ground new pickups float at (meters)
21
+ - `lift: number` (experimental) Height above the ground new pickups float at (meters)
package/docs/api/post.md CHANGED
@@ -1,13 +1,29 @@
1
1
  # engine.post (PostFX)
2
2
 
3
- - `post.object() → any` — The three.js EffectComposer the chain runs in, for reading (pass list, sizes, its targets), or null while no post work has run yet (built the first time an effect or MSAA is on; it is not built here, so asking never costs a half-float target). Read-only by rule, not by lock: the engine owns it, rebuilds composer.passes whenever the chain changes and disposes it with the engine. To add a pass use post.add, to own the whole chain post.own() (recipe 52). Why public: a game reading the chain had to dig into an internal field (review 2026-11-03)
4
- - `post.targets() → { renderTarget1, renderTarget2, readBuffer, writeBuffer } | null | …` — The composer's render targets, for reading (sample the last frame's color or depth in a game pass, check formats / samples), or null while there is no composer. renderTarget1 / renderTarget2 are the ping-pong pair. During the chain readBuffer is a pass's input and writeBuffer its output; EffectComposer swaps them after every pass with needsSwap (most passes; the scene RenderPass does not). The last pass draws to the canvas and still swaps, so after the frame (engine.onRender(fn, { when: 'after' })) neither target holds the final picture: writeBuffer holds the input of that last pass (readBuffer when the last pass does not swap) and readBuffer is stale. For the final image, render into a target of your own. Owned by the engine like object(): it resizes them, changes samples on setAntialias and adds a depth texture when an effect needs depth; do not dispose them or swap their textures.
3
+ - `post.object() → any` — (experimental) What the chain runs in, for reading, or null while no post work has run yet (built the first time an effect is on; it is not built here, so asking never costs a render target). WebGLRenderer: the three.js EffectComposer (pass list, sizes, its targets). WebGPURenderer: { pipeline, scenePass }, three's RenderPipeline and the scene's pass() node. Read-only by rule, not by lock: the engine owns it, rebuilds the chain whenever the list changes and disposes it with the engine. To add a pass use post.add, to own the whole chain post.own() (recipe 52). Why public: a game reading the chain had to dig into an internal field (review 2026-11-03)
4
+ - `post.targets() → { renderTarget1, renderTarget2, readBuffer, writeBuffer } | null | …` — (experimental) The composer's render targets, for reading (sample the last frame's color or depth in a game pass, check formats / samples), or null while there is no composer, and always on WebGPURenderer (its pass nodes own their targets: post.object().scenePass). renderTarget1 / renderTarget2 are the ping-pong pair. During the chain readBuffer is a pass's input and writeBuffer its output; EffectComposer swaps them after every pass with needsSwap (most passes; the scene RenderPass does not). The last pass draws to the canvas and still swaps, so after the frame (engine.onRender(fn, { when: 'after' })) neither target holds the final picture: writeBuffer holds the input of that last pass (readBuffer when the last pass does not swap) and readBuffer is stale. For the final image, render into a target of your own.
5
5
  - `post.add(x: any, o?: { name?, slot?, order? }) → PostHandle` — The one way to add a post effect. x is a three.js Pass (WebGL), a TSL node function (input, ctx) => node (WebGPU), or an effect { name, create / node / fuse, slot, order, params, needsDepth, needsBuffers, backend, skipOnLowTier, facts } (both renderers when it gives create and node, or a fuse). A wrong shape throws with nothing added. needsDepth, needsBuffers ('normal' / 'diffuse' / 'velocity', WebGPU), backend ('webgpu': not on the WebGL2 backend), skipOnLowTier (held when engine.tier is 'low') and facts (shown by describe().render.post) are explained on PostEffect. A Pass that draws engine.scene takes the 'scene' slot, FXAA / SMAA / TAA 'final', any other 'hdr' after the effects already there, or 'ldr' once an OutputPass was added. A RenderPass of engine.scene and an OutputPass are the engine's own stages: skipped and said once (an OutputPass still marks where display color starts). Example: `const glow = engine.post.add(new UnrealBloomPass(size, 0.6, 0.4, 0.85), { name: 'glow' }); glow.enabled = false;`
6
6
  - `post.get(name: string) → PostHandle | undefined` — (experimental) An added effect's handle (as add() returns it), or undefined. Example: `engine.post.get('bloom').set({ strength: 0.6 });`
7
7
  - `post.own(on?: boolean)` — (experimental) Hand the built chain to the game: the engine stops rebuilding it, so the composer's passes (post.object().passes) or the WebGPU pipeline's outputNode are the game's to edit. own(false) gives it back and rebuilds from the list. describe().owned shows who has it. Example: `engine.post.own(); engine.post.object().passes.reverse();`
8
- - `post.setAntialias(on: boolean)` — (experimental) Turn MSAA on or off. It is a render setting, not a drawing part. With no effect on, the start value is the canvas's own MSAA (free: no post chain); the other value, and any effect, draws through the chain, whose render targets carry the MSAA. Example: `engine.post.setAntialias(false);`
9
8
  - `post.list() → { name, slot, order, enabled }[]` — (experimental) Effects in render order: [{ name, slot, order, enabled }]
10
9
  - `post.render(dt: number, target?: any)` — Draw the frame through the chain. target: a render target to draw the finished picture into instead of the canvas (engine.renderOnce(target)); it gets the canvas's pixels (tone mapped, output color space). Why a target argument and not "set the render target first": the WebGL chain's last pass always writes to the canvas (EffectComposer renderToScreen); the WebGPU pipeline draws into whatever target is set.
11
10
  - Properties:
12
- - `antialias: boolean` MSAA on (read-only; switch with post.setAntialias(on))
13
- - `active: boolean` Whether the post chain runs: an effect is on, or antialias differs from the canvas's own MSAA (fixed when the renderer was made, so a runtime switch away from it goes through the chain's targets)
11
+ - `antialias: boolean` (experimental) MSAA on or off in the post chain's render targets, for what runs through the chain. It is a render setting, not a drawing part. With no effect on nothing runs through the chain: the canvas's own MSAA shows, fixed when the context was made (createEngine({ antialias })). Example: `engine.post.antialias = false;`
12
+ - `active: boolean` Whether the post chain runs: an effect is on
13
+
14
+ ## Data structures
15
+ - **PostEffect** An effect as data, the form post.add() takes. node (WebGPURenderer): returns the effect's output color node built on input (the color node so far); called again only when a param that is not a number, boolean, color or vector changes (those are live in ctx.p). An effect with only create cannot run on WebGPURenderer (it throws by name). create: builds the implementation the first time the effect is on (WebGL: a three.js postprocessing Pass); optional when fuse is given. fuse: see PostFuse; effects with a fuse in the same slot next to each other are merged (never in slot 'scene'), their params update in place (no update() needed). slot: a PostSlot; typed as any string too because a slot in a plain JS object (an effect returned from a function) is a string to TypeScript, and the chain throws on an unknown slot naming the valid ones.
16
+ - `name: string`
17
+ - `create?: (ctx: PostContext) => object`
18
+ - `node?: (input: any, ctx: PostNodeContext) => any`
19
+ - `fuse?: PostFuse`
20
+ - `slot?: PostSlot | (string & {})`
21
+ - `order?: number`
22
+ - `enabled?: boolean`
23
+ - `needsDepth?: boolean`
24
+ - `needsBuffers?: ("normal" | "diffuse" | "velocity")[]`
25
+ - `backend?: "webgpu"`
26
+ - `skipOnLowTier?: boolean`
27
+ - `facts?: () => Record<string, any> | null`
28
+ - `params?: Record<string, any>`
29
+ - `update?: (impl: any, params: Record<string, any>) => void`
@@ -4,19 +4,19 @@ Quests (quests() module)
4
4
 
5
5
  - Options `QuestsOptions`:
6
6
  - `action?: string` Action name that opens the quest log, default 'quests'
7
- - `checkInterval?: number` Check interval (game seconds, checked in the fixed step; not checked while frozen / paused), default 0.5
7
+ - `checkInterval?: number` (experimental) Check interval (real seconds, checked in the fixed step; not checked while frozen / paused), default 0.5
8
8
  - `notify?: boolean | ((msg) => void)` Messages on quest start / step / done: true a toast with kind 'quest' (default) · false none · a function to show them your way. Example: `quests({ notify: false }) quests({ notify: ({ type, text }) => type === 'done' && myBanner(text) })`
9
9
 
10
10
  ## Methods and properties
11
11
  - `quests.define(id: string, def: QuestDef)` — Define a quest (chainable)
12
12
  - `quests.start(id: string)` — Start a quest
13
- - `quests.state(id: string) → { step, steps, done, failed, active } | null` — One quest's progress (a copy): step index, step count, done, failed, active; null before it starts
13
+ - `quests.state(id: string) → { step, steps, done, failed, active, visited } | null` — One quest's progress (a copy): step index, step count, done, failed, active; null before it starts
14
14
  - `quests.advance(id: string) → boolean` — Finish the current step from code (its done() is not asked) and go on; the last step completes the quest. false when not active
15
+ - `quests.isDone(id: string) → boolean` — (experimental)
15
16
  - `quests.isActive(id: string) → boolean` — Started, not done and not failed
16
- - `quests.isFailed(id: string) → boolean` — Its fail condition held (start(id) begins it again)
17
+ - `quests.isFailed(id: string) → boolean` — (experimental) Its fail condition held (start(id) begins it again)
17
18
  - `quests.check()` — Check completion conditions once immediately
18
19
  - `quests.list() → { id, title, desc?, done, failed, steps }[]` — Quest list (for custom UI)
19
- - Also: `quests.isDone(id: string) → boolean`
20
20
  - Properties:
21
21
  - `win: { open, toggle, refresh }` The quest log (UI part 'questLog'): open, toggle(on?), refresh()
22
22
 
@@ -25,11 +25,13 @@ Quests (quests() module)
25
25
  - `title: string` Title
26
26
  - `desc?: string` Description
27
27
  - `steps: (QuestStep | QuestParallelStep)[]` Steps (completed in order); a step may be parallel goals { all: [...] }
28
- - `reward?: (e: Engine) => void` Called on completion (give rewards)
28
+ - `reward?: (e: Engine) => any` Called on completion (give rewards). Returning a failure ({ ok: false, code }, e.g. what e.content.run or e.inventory.add answer) means it was not paid: see onUnpaid
29
+ - `onUnpaid?: (e, answer) => void` The game's decision for a reward not given, with the failure as answer. Without it the items that did not fit stay owed (list().owed, saved) and go into the bag when there is room
29
30
  - `fail?: (e: Engine) => boolean` Checked while active; true fails the quest (quest:fail; start(id) can begin it again). Example: `fail: e => e.vars.flag('caravanLost')`
30
31
  - `onFail?: (e: Engine) => void` Called when the quest fails
31
32
  - **QuestStep** One quest step: text is the displayed text, done the completion condition (checked every half second), target the objective (a marker is shown when hud is installed)
32
33
  - `id?: string` Stable id: saves store progress by it, so steps can be inserted or reordered later (default: the step's position)
33
34
  - `text: string`
34
35
  - `done: (e: Engine) => boolean`
36
+ - `next?: string | false | ((e: Engine) => string | false | undefined)` The step after this one: a step id, or e => id asked when this step is done (a branch); false finishes the quest here. Default: the next step in the list. steps already passed are in quests.state(id).visited
35
37
  - `target?: HudTarget` Objective: a place name (content.place), object, character, { x, z }, { nearest: itemId } or a function returning an objective; with the hud module the current step shows a marker automatically
package/docs/api/rays.md CHANGED
@@ -1,13 +1,11 @@
1
1
  # engine.rays (Rays) — engine.rays is the ray registry (engine.raycast hits whatever is registered here)
2
2
 
3
- - `rays.addStatic(obj: THREE.Object3D | THREE.Object3D[], opts?: { occluder?: boolean }) → Handle` — Register a static object and every mesh under it (an array also works; meshes over 256 triangles get a BVH); occluder: true also blocks the camera. Returns a handle { remove() }. Only visible objects are hit; hiding that just swaps in something else on screen (such as the far-away hlod original) is marked userData.rayVisible = true and is still hit. Unregisters automatically on geometry dispose or engine.remove. Example: `engine.rays.addStatic(house, { occluder: true });`
4
- - `rays.forget(obj: THREE.Object3D)` — Unregister every mesh under the object (engine.remove calls this automatically)
5
- - `rays.addProvider(fn: RayProvider) → Handle` — A module merges its own hits (rigid adds rigid bodies; asked only when targets is 'all'). Returns a handle { remove() }
6
- - `rays.cast(origin: Vec3Like, dir: Vec3Like, opts?: RaycastOptions) → RayHit | null` — Cast a ray from origin along dir and return the nearest hit or null (same as engine.raycast).
7
- - `rays.pick(ndcX: number, ndcY: number, opts?: RaycastOptions) → RayHit | null` — Cast from screen coordinates (-1..1) through the camera (same as engine.pick).
3
+ - `rays.addStatic(obj: THREE.Object3D | THREE.Object3D[], opts?: { occluder?: boolean }) → Handle` — Register a static object and every mesh under it (an array also works; meshes over 256 triangles get a BVH); occluder: true also blocks the camera. Returns a handle { remove() }. Only visible objects are hit. Something that is merely not drawn is still hit: batched originals, far hlod originals and the full model of a far assets.lod sit on a reserved layer, with their visible true. Unregisters automatically on geometry dispose or engine.remove. Example: `engine.rays.addStatic(house, { occluder: true });`
4
+ - `rays.forget(obj: THREE.Object3D)` — (experimental) Unregister every mesh under the object (engine.remove calls this automatically)
5
+ - `rays.addProvider(fn: RayProvider) → Handle` — (experimental) A module merges its own hits (rigid adds rigid bodies; asked only when targets is 'all'). Returns a handle { remove() }
8
6
  - Properties:
9
- - `statics: Map<THREE.Object3D, { refs: number; occ: number }>` Registered mesh -> { refs: registration count, occ: camera-blocker registration count }
10
- - `ray: any` The three.js Raycaster (firstHitOnly is on)
7
+ - `statics: Map<THREE.Object3D, { refs: number; occ: number }>` (experimental) Registered mesh -> { refs: registration count, occ: camera-blocker registration count }
8
+ - `ray: any` (experimental) The three.js Raycaster (firstHitOnly is on)
11
9
 
12
10
  ## Data structures
13
11
  - **RaycastOptions** Parameters of engine.raycast()
@@ -21,6 +19,8 @@
21
19
  - `normal: Vector3 | null`
22
20
  - `object: Object3D | null`
23
21
  - `face: any`
22
+ - `instanceId?: number` Which instance of an InstancedMesh was hit, as in a three.js intersection
23
+ - `batchId?: number` Which item of a BatchedMesh was hit, as in a three.js intersection
24
24
  - `entry?: any`
25
25
  - `kind?: string`
26
26
  - `thing?: HitThing` Point -> thing, computed when read: the world record the hit belongs to (a batched instance resolves to its original), where it was authored and what to edit. Example: `const t = engine.pick(0, 0)?.thing; // { id: 'chest-home', kind: 'chest', template: 'chest', definedAt: 'content/props.js:14', ... }`
package/docs/api/rigid.md CHANGED
@@ -4,32 +4,42 @@ Real physics, Rapier (rigid() module, needs collision)
4
4
 
5
5
  - Options `RigidOptions`:
6
6
  - `gravity?: number` Gravity (m/s², negative points down), default -9.81
7
- - `terrainRing?: number` How many rings of chunks around the player get terrain colliders, default 1
7
+ - `terrainRing?: number` How many rings of chunks around the player get terrain colliders, default 1. A body outside them freezes until the player comes near (entry.enabled false, describe().rigid.frozen), because it would fall through the ground: raise this for a car or ball that must keep moving far away
8
8
  - `buoyancy?: boolean` Whether there is buoyancy, default true
9
- - `buoyancyForce?: number` Buoyancy strength (1 = just floats), default 1.6
10
- - `waterDrag?: number` Drag in water, default 2.5
11
- - `floatLine?: number` Buoyancy "waterline": an object starts floating when its center is this many meters below the water surface, default 0.3
12
- - `floatDepth?: number` Buoyancy reaches its maximum this many meters further down, default 0.8
13
- - `treeColliderHeight?: number` Height (meters) of vegetation collision pillars (tree trunks), default 6
14
- - `treeRadius?: number` Trunks get collision cylinders only in chunks within this many meters of the player or a moving rigid body (the rest are covered by engine.collision for characters), default 16
15
- - `playerCapsule?: { halfHeight: number; radius: number }` Player capsule size (meters), default computed from engine.movement radius / height
9
+ - `buoyancyForce?: number` (experimental) Buoyancy strength (1 = just floats), default 1.6
10
+ - `waterDrag?: number` (experimental) Drag in water, default 2.5
11
+ - `floatLine?: number` (experimental) Buoyancy "waterline": an object starts floating when its center is this many meters below the water surface, default 0.3
12
+ - `floatDepth?: number` (experimental) Buoyancy reaches its maximum this many meters further down, default 0.8
13
+ - `treeColliderHeight?: number` (experimental) Height (meters) of vegetation collision pillars (tree trunks), default 6
14
+ - `treeRadius?: number` (experimental) Trunks get collision cylinders only in chunks within this many meters of the player or a moving rigid body (the rest are covered by engine.collision for characters), default 16
15
+ - `playerCapsule?: { halfHeight: number; radius: number }` (experimental) Player capsule size (meters), default computed from engine.movement radius / height
16
+ - `fallbackFloor?: boolean` The flat plane at y = 0 when the ground has no collision of its own, default true. false: only your own bodies and colliders are there (a sky of islands)
16
17
 
17
18
  ## Methods and properties
18
19
  - `rigid.addBox(mesh: Object3D, opts?: RigidBoxOptions) → RigidEntry | null` — Add a box (crate). Physics is ready after engine.start() (or on engine:ready): called before, it throws in development, a release build warns once and returns null
19
- - `rigid.addBall(mesh: Object3D, opts?: RigidBallOptions) → RigidEntry | null` — Add a ball
20
- - `rigid.addHull(mesh: Object3D, opts?: RigidBodyOptions) → RigidEntry | null` — Add a convex hull (irregular objects such as rocks and barrels)
20
+ - `rigid.addBall(mesh: Object3D, opts?: RigidBallOptions) → RigidEntry | null` — (experimental) Add a ball; null only as in addBox: a release build, called before physics is ready
21
+ - `rigid.addHull(mesh: Object3D, opts?: RigidBodyOptions) → RigidEntry | null` — (experimental) Add a convex hull (irregular objects such as rocks and barrels); null only as in addBox: a release build, called before physics is ready
22
+ - `rigid.ragdoll(who: any, opts?: RagdollOptions) → Ragdoll | null` — (experimental) Turn a skinned character limp in one call; rd.remove() returns it to animation. who: a Character, an NPC handle, a character id or a skinned Object3D. Its mover, animator, capsule and camera yield until then; calling again on the same one pushes it again and returns the same ragdoll. Not saved: any load ends it. A skeleton it cannot read throws, naming the missing parts. The rule 'ragdoll.graph' (per character id) gives the parts: 'humanoid' (default), Record<string, RagdollPart> for any other body, a function (facts: { character, root, mesh }, engine) => one of those, or false for no ragdoll (returns null).
21
23
  - `rigid.impulse(entry: RigidEntry, impulse: Vec3Like)` — Give it a push: impulse vector impulse (Vector3 / [x, y, z] / { x, y, z }), e.g. impulse(ball, [0, 3, 5])
22
24
  - `rigid.setPosition(entry: RigidEntry, position: PositionLike)` — Teleport to position (velocity is zeroed)
23
- - `rigid.groundReady(position: PositionLike) → boolean` — Is the physics ground under position built (always true without chunked terrain; with mover: 'rapier' and not yet built, 'simple' is used temporarily)
24
25
  - `rigid.addWheeled(mesh: Object3D, opts: VehicleOptions) → Vehicle | null` — Turn a model into a wheeled vehicle (Rapier ray-cast vehicle controller: cars, karts, carts); remove it with vehicle.remove() (anyone inside gets out first). Before physics is ready it throws in development (release: warns, null), like addBox. Boats, mounts and mechs are the game's own objects with the same seat interface
25
26
  - Properties:
26
27
  - `ready: boolean` Is the physics engine ready (downloaded and initialized at start())
27
28
  - `bodies: RigidEntry[]` All physics bodies
28
- - `R: any` Rapier library
29
- - `world: any` Rapier world
30
- - `playerBody: any` The player's Rapier kinematic body and capsule collider (follow the player position every step; used for collision when mover: 'rapier'; the capsule is off while driving)
31
- - `playerCapsule: { halfHeight: number; radius: number }` Player capsule size (meters)
32
- - `vehicles: Vehicle[]` All vehicles
29
+ - `terrainRing: number` (experimental)
30
+ - `buoyancy: boolean` (experimental)
31
+ - `buoyancyForce: number` (experimental)
32
+ - `waterDrag: number` (experimental)
33
+ - `floatLine: number` (experimental)
34
+ - `floatDepth: number` (experimental)
35
+ - `treeColliderHeight: number` (experimental)
36
+ - `treeRadius: number` (experimental)
37
+ - `rapier: any` (experimental) The Rapier library itself: its shape follows the Rapier version
38
+ - `world: any` (experimental) The Rapier world: its shape follows the Rapier version
39
+ - `playerBody: any` (experimental) The player's Rapier kinematic body and capsule collider (follow the player position every step; used for collision when mover: 'rapier'; the capsule is off while driving)
40
+ - `playerCollider: any` (experimental) The capsule collider on playerBody
41
+ - `playerCapsule: { halfHeight: number; radius: number }` (experimental) Player capsule size (meters)
42
+ - `vehicles: Vehicle[]` (experimental) All vehicles
33
43
  - `stats: { bodies: number; active: number; colliders: number }` Statistics
34
44
 
35
45
  ## Data structures
@@ -46,8 +56,8 @@ Real physics, Rapier (rigid() module, needs collision)
46
56
  - `body: any` Rapier rigid body (translation(), mass(), setLinvel()…); newGame / a load rebuild the world, so read entry.body again instead of keeping it
47
57
  - `collider: any` Rapier collider
48
58
  - `mesh: Object3D` The matching three.js model (position is written by physics every step)
49
- - `object: Object3D` Same as mesh (the name consistent with player.object, ent.object)
50
- - `enabled: boolean` Whether it is being simulated (frozen when too far from the player)
59
+ - `object: Object3D` Same as mesh
60
+ - `enabled: boolean` Whether it is being simulated: false while it is outside the terrain colliders (rigid({ terrainRing })), where it would fall through the ground
51
61
  - `volume: number` Volume (cubic meters, used for buoyancy)
52
62
  - `damping: number`
53
63
  - `angularDamping: number`
@@ -83,4 +93,4 @@ Real physics, Rapier (rigid() module, needs collision)
83
93
  - `passengers: Character[]`
84
94
  - `hideDriver: boolean`
85
95
  - `seatPosition(seat?: number) → Vector3` — World position of a seat (default 0, the driver's)
86
- - `exitPosition(seat?: number) → Vector3` — Where to get out of a seat (outside the door on that seat's side, world coordinates)
96
+ - `exitPosition(seat?: number, n?: number) → Vector3` — Where to get out of a seat (outside the door on that seat's side, world coordinates)
package/docs/api/saves.md CHANGED
@@ -1,23 +1,25 @@
1
1
  # engine.saves (Saves) — engine.saves handles saving
2
2
 
3
- - `saves.register(key: string, provider: SaveProvider)` — Register "how to save and load"; key is this part's name in the save. Parts with first: true load first (the level); a load returning a Promise makes later parts wait. version (default 1): raise it by 1 whenever what save() returns changes shape, and add migrate[oldVersion] = data => newData; load sees only the current shape. A save whose part is newer than this build's version is refused as a whole (load returns false, the save is kept). A part registered after a save was loaded (a module installed later) is handed its data from that save at once. movedFrom: { oldPart: data => newData } when this part's data used to be saved under another part's name (a module split in two: the calendar's time and day were part 'sky'); an old save without this part but with oldPart hands that data, converted, to this part, and oldPart is dropped (unless a registered part still owns that name). Example: `engine.saves.register('garden', { save: () => garden.toJSON(), load: d => garden.fromJSON(d) }); // later the format gains beds: version 2, and a step that upgrades version-1 data engine.saves.register('garden', { version: 2, migrate: { 1: d => ({ ...d, beds: [] }) }, save: () => garden.toJSON(), load: d => garden.fromJSON(d) });`
4
- - `saves.queue(fn: () => Promise<T>) → Promise<T>` — Queue a disk write (runs in call order once storage is ready; flush waits for it; used by attachments such as photos).
3
+ - `saves.register(key: string, provider: SaveProvider) → { remove }` — Register "how to save and load"; key is this part's name in the save. Parts with first: true load first (the level); a load returning a Promise makes later parts wait. version (default 1): raise it by 1 whenever what save() returns changes shape, and add migrate[oldVersion] = data => newData; load sees only the current shape. A save whose part is newer than this build's version is refused as a whole (load returns false, the save is kept). load(data, turn): turn is this replacement's identity. Pass it on, level.load(x, { turn }) or content.load(x, { turn }): those wait for a running load to end, except with its turn. A part registered after a save was loaded (a module installed later) is handed its data from that save: at once when idle, else right after the replacement under way. Example: `engine.saves.register('garden', { save: () => garden.toJSON(), load: d => garden.fromJSON(d) }); // later the format gains beds: version 2, and a step that upgrades version-1 data engine.saves.register('garden', { version: 2, migrate: { 1: d => ({ ...d, beds: [] }) }, save: () => garden.toJSON(), load: d => garden.fromJSON(d) });`
4
+ - `saves.putAttachment(group: string, id: string, blob: Blob | (() => Promise<Blob>), meta?: any) → Promise<void>` — (experimental) Store a binary attachment outside the world save (a photo, a replay). It rides in the queue of save writes, so flush() waits for it, and exportFile() carries it. Pass a function to make the bytes when the write runs: flush() then waits for that too. Without IndexedDB it is not kept. Rejects with save-stale, changing nothing, when another tab wrote this id since this tab last saw it; attachments(group) is how a tab looks. Example: `await engine.saves.putAttachment('replay', 'run-1', blob, { score: 12 });`
5
+ - `saves.removeAttachment(group: string, id: string) → Promise<void>` — (experimental) Delete an attachment; no such id is fine. Rejects with save-stale as putAttachment does
6
+ - `saves.attachments(group: string) → Promise<{ group: string; id: stri…` — (experimental) The attachments of a group, once storage is ready. Empty without IndexedDB.
7
+ - `saves.storageKey(name: string) → string` — A localStorage key for what belongs to this game but is not a save (settings, a last-used tab): it shares the game's name, so two games on one site stay apart, and stays out of list(). Example: `localStorage.setItem(engine.saves.storageKey('lastTab'), 'map');`
5
8
  - `saves.flush() → Promise<void>` — Wait for all queued disk writes to finish (for tests and before the page closes)
6
- - `saves.collect() → { format, savedAt, versions, parts }` — Collect the data of every part (does not write to the browser): { format, savedAt, versions, parts }. A part whose save() throws is left out and reported (engine.error in dev); save() instead refuses to write such a save.
9
+ - `saves.collect() → { format, savedAt, versions, parts }` — Collect the data of every part (does not write to the browser): { format, savedAt, versions, parts }. A part whose save() throws is left out and reported (engine.error in dev); save() instead refuses to write such a save. Throws while a load is under way: what it would return is half of each state. saves.save waits instead.
7
10
  - `saves.check(slot?: string) → null | "missing" | "corrupt" | "tooNew" | "migrate"` — Can this slot be loaded? null when it can, else why not (checked without touching the game): 'missing' / 'corrupt' (unreadable) / 'tooNew' (a newer save format or part) / 'migrate' (an upgrade step is missing or throws). Example: `if (engine.saves.check('slot1') === 'tooNew') showUpdateHint();`
8
11
  - `saves.apply(data: any, slot?: string) → Promise<boolean>` — Apply a save's data (an object from collect(), or save text) onto the running game. Resolves true when every part loaded. Refused before anything changes (false, toast) when the data is corrupt, from a newer build or cannot be migrated. After every part loaded it runs the modules' afterLoad hooks (gameplay frozen until they resolve), for saves.load, session.newGame / quit and direct calls alike. If a part's load throws, a listener of an event it emits while loading (world:load) throws, or a module's afterLoad throws, the game is rolled back to how it was before (every part reloads its pre-load state) and it resolves false; the error goes through the error tiers. "While loading" lasts until the result settles, past every await of an async load(); a listener that throws in that window for any reason fails this load.
9
- - `saves.save(slot?: string) → Promise<boolean>` — Save into a slot (default 'auto'). Returns Promise<boolean> (resolves after the write to IndexedDB: true on success, false with a toast and console error on failure). The in-memory save updates immediately, so a following load / list / export sees it at once; the 'save:written' event fires only after the write succeeds. If any part's save() throws, nothing is written and the slot keeps its previous save (false). A failed write keeps the previous save too. Show "saved" only after the result is true. Example: `if (await engine.saves.save('slot1')) toast(engine, 'Saved'); // on false the engine already showed why`
12
+ - `saves.save(slot?: string) → Promise<boolean>` — Save into a slot (default 'auto'). Returns Promise<boolean> (resolves after the write to IndexedDB: true on success, false with a toast and console error on failure). The in-memory save updates immediately, so a following load / list / export sees it at once; the 'save:written' event fires only after the write succeeds. Asked for while a load, newGame or quit is under way, it waits for that to end and saves the result: a save never holds half of each state. If any part's save() throws, or its data holds NaN or Infinity at any depth (the message names the part and the path), nothing is written and the slot keeps its previous save (false). A failed write keeps the previous save too. Show "saved" only after the result is true. Example: `if (await engine.saves.save('slot1')) toast(engine, 'Saved'); // on false the engine already showed why`
10
13
  - `saves.load(slot?: string) → Promise<boolean>` — Load a slot onto the running playthrough (a quick load: what the game added during play stays) and resolve true on success; the 'save:loaded' event fires on success. A missing slot resolves false; a corrupt / too new / unmigratable save resolves false with a toast and changes nothing; a part whose load throws rolls the game back. To continue or retry with nothing of the current playthrough left over, use engine.session.load(slot). Example: `if (!(await engine.saves.load('quick'))) toast(engine, 'No quick save');`
11
14
  - `saves.list() → { slot: string; savedAt: number }[]` — All slots, newest first (synchronous, reads the in-memory index)
12
- - `saves.remove(slot: string) → Promise<void>` — Delete a slot. Returns a Promise (disk write done); awaiting is optional
13
- - `saves.export(slot?: string) → string` — Export as a piece of text (can be copied as a backup; synchronous, without binary attachments)
15
+ - `saves.remove(slot: string) → Promise<void>` — Delete a slot. Returns a Promise (disk write done); awaiting is optional. A newer save another tab wrote meanwhile is kept: the slot lists again, with a toast (save-stale). A delete the store refused lists the slot again too, with a toast.
16
+ - `saves.export(slot?: string) → string` — (experimental) Export as a piece of text (can be copied as a backup; synchronous, without binary attachments)
14
17
  - `saves.import(text: string, slot?: string) → Promise<boolean>` — Import text from export() into a slot (default 'imported'); checked like importFile and written before it resolves. Resolves true once stored (save:imported fires), false when the text is not a save or the write failed. It does not load the slot.
15
- - `saves.exportFile(slot?: string, opts?: { files?: boolean }) → Promise<boolean>` — Download a save file (.json): the save plus every binary attachment (as data: text, so the file is larger; { files: false } exports the save only). Restores everything when browser data is wiped on a phone. Returns Promise<boolean>. Example: `engine.saves.exportFile('slot1');`
18
+ - `saves.exportFile(slot?: string, opts?: { files?: boolean }) → Promise<boolean>` — (experimental) Download a save file (.json): the save plus every binary attachment (as data: text, so the file is larger; { files: false } exports the save only). Restores everything when browser data is wiped on a phone. Returns Promise<boolean>. Example: `engine.saves.exportFile('slot1');`
16
19
  - `saves.importFile(file?: Blob, slot?: string) → Promise<string | null>` — Restore from a save file into slot (default 'imported', so a shared file never overwrites 'auto'). file is a File / Blob; omit it to open a file picker. Everything is checked first (file marker and format, the save inside, attachments must be data: URLs: nothing is fetched). Returns the slot name on success, and null if cancelled, the file is invalid or the write failed (a toast was already shown). It restores the slot only and does not load it.
17
20
  - `saves.autosave(minutes?: number) → { remove(): void }` — Autosave into 'auto' every `minutes` minutes of play: counted in fixed seconds, so it waits while paused, frozen or in a menu that freezes the game, and it never saves while no playthrough runs (the title screen, during newGame / load / quit) or after a gameplay error. Returns a handle; remove() stops it. Calling it again replaces the previous autosave. Example: `engine.saves.autosave(3); // once at boot: it waits by itself while no playthrough runs`
18
21
  - Properties:
19
- - `prefix: string` Save name prefix (start of the key names in the localStorage fallback, and of the IndexedDB database name)
20
- - `store: { mode, blobs, putBlob, deleteBlob }` Storage layer: saves in the IndexedDB slots store, attachments (by group, e.g. 'photo') in the blobs store; mode 'localStorage' without IndexedDB.
22
+ - `store: { mode, blobs, putBlob, deleteBlob }` (experimental) Storage layer: saves in the IndexedDB slots store, attachments (by group, e.g. 'photo') in the blobs store; mode 'localStorage' without IndexedDB.
21
23
  - `ready: boolean` Has the save index been read into memory? (start() waits for it; game code rarely needs to care)
22
24
  - `whenReady: Promise<void>` Resolves once the save index is in memory; await it only to list / load before start()
23
25
  - `versions: Record<string, number>` The save versions this build reads, per part: { world: 1, clock: 1, ... }. A save whose part is newer is refused; an older one is migrated.
@@ -25,10 +27,10 @@
25
27
  ## Data structures
26
28
  - **SaveProvider** Save provider: save() returns JSON-able data, load(data) reads it back (may return a Promise, e.g. for changing level; later parts wait for it to finish before loading). first: true providers load first (parts such as the level, where the rest only makes sense after it is loaded)
27
29
  - `save: () => any` This part's data now: plain data (structuredClone can copy it; no functions, DOM nodes or three objects). It may be the live object the part keeps: the engine copies it for its rollback point before a load, so a load() that writes into that same object can still be undone.
28
- - `load: (data: any) => void | Promise<void>` Read data back; may return a Promise (later parts wait). Listener errors of events it emits count as the load throwing, also after an await
30
+ - `load: (data: any, turn: SaveTurn) => void | Promise<void>` Read data back; may return a Promise (later parts wait). Listener errors of events it emits count as the load throwing, also after an await. turn: this replacement's identity. Pass it on as level.load(x, { turn }) / content.load(x, { turn }): awaited without it, those wait for this load, so for ever (dev warns after 3 s, save-nested)
29
31
  - `first?: boolean` Load before the other parts (such as the level)
30
32
  - `atomic?: boolean` Join atomic ops: copied before an atomic op runs, put back if it fails (plain data; afterLoad does not run on rollback)
33
+ - `notAtomic?: string` Why an atomic op leaves this part alone. Every engine part gives atomic: true or this (rule R66); a game's part may
31
34
  - `checkNewGame?: (data: any) => void` Dev only: called once start() finished with this part's data in the new-game state, to warn about what should not be there yet (world: records placed by code)
32
35
  - `version?: number` This part's format version, default 1: raise it by 1 when what save() returns changes shape. A save with a newer version is refused
33
36
  - `migrate?: Record<number, (data: any, save: { parts: Record<string, an…` Upgrade steps: old version -> data => data in the next version's shape, e.g. { 1: d => ({ ...d, beds: [] }) }. The second argument is the whole save as read ({ parts, versions }, read only), for a step that depends on another part
34
- - `movedFrom?: Record<string, (data: any) => any>` This part's data used to be saved under another part's name: { oldPart: data => newData } (newData in this version's shape). An old save without this part but with oldPart loads it here; oldPart is then dropped unless a registered part still owns that name