threedog 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (544) hide show
  1. package/CHANGELOG.md +196 -1
  2. package/README.md +6 -9
  3. package/core/{Animator.js → assets/Animator.js} +28 -18
  4. package/core/{Assets.js → assets/Assets.js} +98 -54
  5. package/core/{Baked.js → assets/Baked.js} +4 -4
  6. package/core/assets/assetEntry.js +237 -0
  7. package/core/{assetHot.js → assets/assetHot.js} +7 -6
  8. package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
  9. package/core/assets/assetLod.js +113 -0
  10. package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
  11. package/core/{assetReport.js → assets/assetReport.js} +6 -12
  12. package/core/{namedModel.js → assets/namedModel.js} +17 -13
  13. package/core/{Audio.js → audio/Audio.js} +26 -23
  14. package/core/{audioRules.js → audio/audioRules.js} +8 -5
  15. package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
  16. package/core/{Events.js → base/Events.js} +3 -3
  17. package/core/{I18n.js → base/I18n.js} +10 -10
  18. package/core/{Random.js → base/Random.js} +5 -4
  19. package/core/{easing.js → base/easing.js} +1 -1
  20. package/core/{errorCodes.js → base/errorCodes.js} +98 -110
  21. package/core/{errorHints.js → base/errorHints.js} +5 -9
  22. package/core/{errors.js → base/errors.js} +6 -6
  23. package/core/{events.generated.js → base/events.generated.js} +1 -0
  24. package/core/{math.js → base/math.js} +15 -4
  25. package/core/{params.js → base/params.js} +3 -4
  26. package/core/base/util.js +32 -0
  27. package/core/{validate.js → base/validate.js} +28 -7
  28. package/core/{Engine.js → engine/Engine.js} +80 -77
  29. package/core/{Loading.js → engine/Loading.js} +4 -2
  30. package/core/{copies.js → engine/copies.js} +4 -4
  31. package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
  32. package/core/{lifecycle.js → engine/lifecycle.js} +14 -12
  33. package/core/{loop.js → engine/loop.js} +68 -47
  34. package/core/{moduleSlots.js → engine/moduleSlots.js} +6 -6
  35. package/core/{moduleTypes.js → engine/moduleTypes.js} +13 -14
  36. package/core/{modules.js → engine/modules.js} +14 -11
  37. package/core/{page.js → engine/page.js} +36 -23
  38. package/core/{plugins.js → engine/plugins.js} +6 -9
  39. package/core/{services.js → engine/services.js} +47 -40
  40. package/core/{startup.js → engine/startup.js} +26 -24
  41. package/core/{Input.js → input/Input.js} +30 -22
  42. package/core/{inputContext.js → input/inputContext.js} +14 -5
  43. package/core/{inputPad.js → input/inputPad.js} +1 -1
  44. package/core/{inputPointer.js → input/inputPointer.js} +8 -2
  45. package/core/{inputTouch.js → input/inputTouch.js} +1 -1
  46. package/core/{Budget.js → inspect/Budget.js} +21 -20
  47. package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +30 -16
  48. package/core/{Describe.js → inspect/Describe.js} +26 -22
  49. package/core/{Inspect.js → inspect/Inspect.js} +9 -7
  50. package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
  51. package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
  52. package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
  53. package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
  54. package/core/{UrlState.js → inspect/UrlState.js} +52 -20
  55. package/core/{catalog.js → inspect/catalog.js} +3 -3
  56. package/core/{checks.js → inspect/checks.js} +7 -5
  57. package/core/{debugView.js → inspect/debugView.js} +4 -4
  58. package/core/{describeRender.js → inspect/describeRender.js} +21 -20
  59. package/core/{describeText.js → inspect/describeText.js} +11 -6
  60. package/core/inspect/geometryWatch.js +38 -0
  61. package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
  62. package/core/{pictureWriters.js → inspect/pictureWriters.js} +15 -16
  63. package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
  64. package/core/{Ops.js → ops/Ops.js} +16 -11
  65. package/core/{control.js → ops/control.js} +13 -12
  66. package/core/ops/holds.js +139 -0
  67. package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
  68. package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
  69. package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
  70. package/core/{opsRun.js → ops/opsRun.js} +7 -4
  71. package/core/{owned.js → ops/owned.js} +14 -17
  72. package/core/{sharedPoint.js → ops/sharedPoint.js} +8 -8
  73. package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
  74. package/core/{stacks.js → ops/stacks.js} +12 -14
  75. package/core/{wrap.js → ops/wrap.js} +8 -6
  76. package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
  77. package/core/{Saves.js → saves/Saves.js} +58 -36
  78. package/core/{saveApply.js → saves/saveApply.js} +13 -9
  79. package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
  80. package/core/{saveValues.js → saves/saveValues.js} +20 -3
  81. package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
  82. package/core/{session.js → saves/session.js} +31 -17
  83. package/core/{Rays.js → scene/Rays.js} +23 -25
  84. package/core/{Views.js → scene/Views.js} +14 -6
  85. package/core/{adaptive.js → scene/adaptive.js} +15 -8
  86. package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
  87. package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
  88. package/core/{gameLights.js → scene/gameLights.js} +17 -7
  89. package/core/{grayMap.js → scene/grayMap.js} +8 -2
  90. package/core/{grid.js → scene/grid.js} +4 -4
  91. package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
  92. package/core/{ground.js → scene/ground.js} +9 -9
  93. package/core/{movement.js → scene/movement.js} +3 -3
  94. package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
  95. package/core/{sceneDelta.js → scene/sceneDelta.js} +2 -2
  96. package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -13
  97. package/core/scene/stepPoses.js +55 -0
  98. package/core/{targeting.js → scene/targeting.js} +4 -5
  99. package/core/{thingExplain.js → scene/thingExplain.js} +6 -5
  100. package/core/{thingOps.js → scene/thingOps.js} +4 -3
  101. package/core/{things.js → scene/things.js} +18 -5
  102. package/core/{threePatches.js → scene/threePatches.js} +1 -1
  103. package/core/{view.js → scene/view.js} +17 -16
  104. package/core/{Batching.js → stream/Batching.js} +85 -27
  105. package/core/{Stream.js → stream/Stream.js} +60 -30
  106. package/core/{batchGroups.js → stream/batchGroups.js} +10 -9
  107. package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
  108. package/core/{scatter.js → stream/scatter.js} +2 -2
  109. package/core/{streamSources.js → stream/streamSources.js} +12 -7
  110. package/core/{Commits.js → threads/Commits.js} +6 -5
  111. package/core/{Jobs.js → threads/Jobs.js} +12 -10
  112. package/core/{Threads.js → threads/Threads.js} +16 -16
  113. package/core/{threadPure.js → threads/threadPure.js} +7 -5
  114. package/core/{threadServe.js → threads/threadServe.js} +3 -3
  115. package/core/{Clock.js → time/Clock.js} +17 -10
  116. package/core/{dayTime.js → time/dayTime.js} +5 -1
  117. package/core/{skip.js → time/skip.js} +18 -17
  118. package/core/{time.js → time/time.js} +18 -12
  119. package/core/{uiClock.js → time/uiClock.js} +4 -4
  120. package/docs/AI.md +22 -19
  121. package/docs/API.md +24 -23
  122. package/docs/CODEMAP.md +76 -183
  123. package/docs/COMMANDS.md +66 -58
  124. package/docs/CONVENTIONS.md +54 -14
  125. package/docs/MIGRATING-0.8.md +169 -0
  126. package/docs/THREE.md +78 -29
  127. package/docs/api/assets.md +12 -13
  128. package/docs/api/audio.md +6 -5
  129. package/docs/api/budget.md +4 -4
  130. package/docs/api/calendar.md +10 -11
  131. package/docs/api/cameraRig.md +29 -29
  132. package/docs/api/characters.md +23 -18
  133. package/docs/api/clock.md +1 -1
  134. package/docs/api/collision.md +12 -9
  135. package/docs/api/content.md +6 -6
  136. package/docs/api/dialogue.md +3 -3
  137. package/docs/api/engine.md +45 -43
  138. package/docs/api/events.md +3 -2
  139. package/docs/api/flow.md +1 -1
  140. package/docs/api/grids.md +1 -1
  141. package/docs/api/ground.md +4 -5
  142. package/docs/api/hud.md +2 -2
  143. package/docs/api/i18n.md +6 -6
  144. package/docs/api/input.md +7 -7
  145. package/docs/api/interactions.md +4 -4
  146. package/docs/api/inventory.md +9 -9
  147. package/docs/api/jobs.md +5 -5
  148. package/docs/api/level.md +7 -7
  149. package/docs/api/lightPool.md +1 -6
  150. package/docs/api/music.md +3 -3
  151. package/docs/api/nav.md +10 -10
  152. package/docs/api/openWorld.md +1 -1
  153. package/docs/api/particles.md +2 -2
  154. package/docs/api/photo.md +4 -2
  155. package/docs/api/pickups.md +2 -2
  156. package/docs/api/post.md +20 -3
  157. package/docs/api/quests.md +3 -3
  158. package/docs/api/rays.md +5 -7
  159. package/docs/api/rigid.md +27 -18
  160. package/docs/api/saves.md +8 -7
  161. package/docs/api/settings.md +9 -8
  162. package/docs/api/sky.md +8 -7
  163. package/docs/api/stream.md +7 -7
  164. package/docs/api/swarm.md +34 -0
  165. package/docs/api/terrain.md +7 -8
  166. package/docs/api/terrainDraw.md +1 -1
  167. package/docs/api/timeline.md +2 -2
  168. package/docs/api/tools.md +25 -22
  169. package/docs/api/vars.md +1 -1
  170. package/docs/api/vegetation.md +4 -3
  171. package/docs/api/vegetationDraw.md +1 -1
  172. package/docs/api/water.md +1 -1
  173. package/docs/api/weather.md +9 -9
  174. package/docs/api/weatherDraw.md +3 -3
  175. package/docs/api/world.md +5 -5
  176. package/docs/recipes/01-new-game.md +25 -40
  177. package/docs/recipes/02-npc.md +19 -20
  178. package/docs/recipes/03-items-pickups.md +27 -43
  179. package/docs/recipes/04-quests.md +3 -4
  180. package/docs/recipes/05-props-bake.md +29 -39
  181. package/docs/recipes/06-clock-events.md +27 -18
  182. package/docs/recipes/07-flow-scenes-pause.md +12 -17
  183. package/docs/recipes/08-weather-sky.md +88 -34
  184. package/docs/recipes/09-materials-lights-models.md +22 -36
  185. package/docs/recipes/10-blender-level.md +6 -7
  186. package/docs/recipes/11-vehicles.md +30 -22
  187. package/docs/recipes/12-navmesh.md +9 -8
  188. package/docs/recipes/13-animation.md +39 -17
  189. package/docs/recipes/14-custom-module.md +14 -13
  190. package/docs/recipes/15-perf.md +49 -26
  191. package/docs/recipes/16-dev-bridge.md +32 -52
  192. package/docs/recipes/18-world.md +36 -23
  193. package/docs/recipes/19-shooting-picking.md +4 -2
  194. package/docs/recipes/20-content-actions-save.md +30 -35
  195. package/docs/recipes/21-camera.md +33 -5
  196. package/docs/recipes/22-shop-gold.md +0 -4
  197. package/docs/recipes/23-ops.md +10 -10
  198. package/docs/recipes/26-ui-parts.md +22 -12
  199. package/docs/recipes/27-net.md +0 -2
  200. package/docs/recipes/28-terrain.md +117 -21
  201. package/docs/recipes/29-grid.md +2 -2
  202. package/docs/recipes/30-templates.md +55 -19
  203. package/docs/recipes/31-audio.md +5 -5
  204. package/docs/recipes/32-action-game.md +15 -6
  205. package/docs/recipes/33-stream-sources.md +2 -2
  206. package/docs/recipes/34-environment-lighting.md +67 -19
  207. package/docs/recipes/35-picture-from-reference.md +10 -17
  208. package/docs/recipes/36-ground-plants.md +105 -0
  209. package/docs/recipes/40-scene.md +7 -11
  210. package/docs/recipes/43-shader-patches-surfaces.md +20 -41
  211. package/docs/recipes/44-water-weather-hooks.md +48 -43
  212. package/docs/recipes/45-cascaded-shadows.md +39 -17
  213. package/docs/recipes/46-blender-art-route.md +7 -8
  214. package/docs/recipes/49-game-module-contract.md +5 -5
  215. package/docs/recipes/50-own-renderer.md +2 -2
  216. package/docs/recipes/52-around-the-picture.md +54 -98
  217. package/docs/recipes/53-ground-up-close.md +61 -24
  218. package/docs/recipes/55-mods-time-wrap.md +12 -16
  219. package/docs/recipes/56-webgpu-tsl.md +16 -14
  220. package/docs/recipes/57-control.md +9 -2
  221. package/docs/recipes/58-input.md +2 -2
  222. package/docs/recipes/59-depth-post-effects.md +1 -1
  223. package/docs/recipes/60-judge-the-picture.md +29 -24
  224. package/docs/recipes/62-picture-code.md +49 -17
  225. package/docs/recipes/63-third-person-start.md +17 -4
  226. package/docs/recipes/64-particles.md +1 -1
  227. package/docs/recipes/65-swarm.md +140 -0
  228. package/examples/action/.threedog/content-index.json +1 -1
  229. package/examples/action/GAMEMAP.md +2 -2
  230. package/examples/{sheepisland → perf-island}/.threedog/content-index.json +1 -1
  231. package/examples/{sheepisland → perf-island}/GAMEMAP.md +12 -11
  232. package/examples/{sheepisland → perf-island}/assets.js +1 -1
  233. package/examples/{sheepisland → perf-island}/main.js +8 -8
  234. package/examples/{sheepisland → perf-island}/models.js +1 -1
  235. package/examples/{sheepisland → perf-island}/params.js +1 -1
  236. package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
  237. package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
  238. package/examples/{sheepisland → perf-island}/views.js +1 -1
  239. package/examples/plain-picture/GAMEMAP.md +1 -0
  240. package/examples/rc2d/GAMEMAP.md +3 -2
  241. package/examples/rc2d/main.js +1 -3
  242. package/examples/styletest/.threedog/content-index.json +1 -1
  243. package/examples/styletest/GAMEMAP.md +3 -2
  244. package/examples/techniques/contact-shadows/contactShadows.js +1 -1
  245. package/examples/techniques/contact-shadows/main.js +1 -1
  246. package/examples/techniques/interior-light/main.js +1 -1
  247. package/examples/techniques/modular-building/README.md +7 -6
  248. package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
  249. package/examples/techniques/procedural-animation/README.md +1 -1
  250. package/examples/webgpu-tsl/GAMEMAP.md +1 -0
  251. package/examples/world/.threedog/content-index.json +1 -1
  252. package/examples/world/GAMEMAP.md +4 -3
  253. package/examples/world/picture/sky.js +1 -1
  254. package/index.d.ts +8 -7
  255. package/index.js +31 -31
  256. package/llms.txt +9 -13
  257. package/modules/ambience/Ambience.js +11 -8
  258. package/modules/calendar/Calendar.js +19 -19
  259. package/modules/calendar/index.js +13 -13
  260. package/modules/calendar/schedule.js +11 -6
  261. package/modules/calendar/seasons.js +7 -7
  262. package/modules/camera/FirstPersonCamera.js +2 -2
  263. package/modules/camera/FixedCamera.js +14 -15
  264. package/modules/camera/FollowCamera.js +4 -4
  265. package/modules/camera/RtsCamera.js +11 -11
  266. package/modules/camera/common.js +48 -24
  267. package/modules/camera/contract.js +1 -0
  268. package/modules/camera/projection.js +2 -2
  269. package/modules/characters/Character.js +33 -30
  270. package/modules/characters/NPC.js +27 -19
  271. package/modules/characters/assetModel.js +14 -10
  272. package/modules/characters/astar.js +7 -5
  273. package/modules/characters/behaviors.js +4 -5
  274. package/modules/characters/contract.js +2 -2
  275. package/modules/characters/index.js +168 -214
  276. package/modules/characters/moveHelpers.js +14 -3
  277. package/modules/characters/movers/common.js +16 -14
  278. package/modules/characters/movers/manual.js +1 -1
  279. package/modules/characters/movers/rapier.js +7 -6
  280. package/modules/characters/movers/simple.js +3 -3
  281. package/modules/characters/movers/support.js +8 -8
  282. package/modules/characters/npcAvoid.js +4 -4
  283. package/modules/characters/npcSim.js +23 -17
  284. package/modules/characters/npcView.js +6 -5
  285. package/modules/characters/pathAsync.js +12 -10
  286. package/modules/characters/pathWorker.js +1 -1
  287. package/modules/characters/player.js +108 -0
  288. package/modules/characters/playerStrings.js +2 -2
  289. package/modules/characters/proceduralRig.js +2 -2
  290. package/modules/characters/useModel.js +3 -3
  291. package/modules/characters/walkTo.js +11 -17
  292. package/modules/collision/Collision.js +26 -20
  293. package/modules/collision/contract.js +15 -0
  294. package/modules/content/explain.js +1 -2
  295. package/modules/content/fields.js +24 -3
  296. package/modules/content/ids.js +2 -2
  297. package/modules/content/index.js +61 -99
  298. package/modules/content/loader.js +14 -17
  299. package/modules/content/markers.js +25 -0
  300. package/modules/content/models.js +10 -7
  301. package/modules/content/packs.js +3 -3
  302. package/modules/content/parts.js +2 -2
  303. package/modules/content/places.js +35 -0
  304. package/modules/content/props.js +17 -14
  305. package/modules/content/rules.js +25 -21
  306. package/modules/content/stages.js +7 -7
  307. package/modules/content/templates.js +20 -20
  308. package/modules/content/words.js +34 -0
  309. package/modules/debug/DebugPanel.js +10 -43
  310. package/modules/flow/contract.js +1 -1
  311. package/modules/flow/index.js +11 -7
  312. package/modules/gameplay/Container.js +12 -11
  313. package/modules/gameplay/Containers.js +14 -5
  314. package/modules/gameplay/Dialogue.js +13 -11
  315. package/modules/gameplay/Interactions.js +37 -24
  316. package/modules/gameplay/Inventory.js +8 -9
  317. package/modules/gameplay/Quests.js +16 -9
  318. package/modules/gameplay/boxOps.js +1 -1
  319. package/modules/gameplay/dialogueBubbles.js +3 -4
  320. package/modules/gameplay/inventoryOps.js +0 -1
  321. package/modules/gameplay/pickups.js +22 -23
  322. package/modules/gameplay/questSave.js +3 -3
  323. package/modules/grid/Grid.js +1 -1
  324. package/modules/grid/Layer.js +4 -4
  325. package/modules/grid/index.js +7 -8
  326. package/modules/grid/preview.js +7 -7
  327. package/modules/grid/tiles.js +6 -6
  328. package/modules/hlod/index.js +37 -55
  329. package/modules/hud/index.js +17 -11
  330. package/modules/hud/parts.js +4 -4
  331. package/modules/level/contract.js +16 -0
  332. package/modules/level/heightfield.js +12 -10
  333. package/modules/level/index.js +47 -152
  334. package/modules/level/load.js +79 -0
  335. package/modules/level/meshes.js +65 -0
  336. package/modules/level/nodes.js +6 -7
  337. package/modules/lights/index.js +28 -181
  338. package/modules/lights/slots.js +93 -0
  339. package/modules/lights/sources.js +88 -0
  340. package/modules/music/Music.js +30 -26
  341. package/modules/music/rules.js +1 -1
  342. package/modules/nav/contract.js +14 -0
  343. package/modules/nav/index.js +11 -10
  344. package/modules/net/Client.js +7 -7
  345. package/modules/net/Host.js +7 -7
  346. package/modules/net/Net.js +1 -1
  347. package/modules/net/index.js +5 -4
  348. package/modules/net/sync.js +2 -2
  349. package/modules/net/transports.js +2 -2
  350. package/modules/particles/Particles.js +11 -8
  351. package/modules/particles/effect.js +7 -5
  352. package/modules/particles/shaders.js +2 -1
  353. package/modules/photo/Photo.js +15 -17
  354. package/modules/rigid/RigidBodies.js +66 -43
  355. package/modules/rigid/Vehicles.js +2 -3
  356. package/modules/rigid/ragdoll.js +287 -0
  357. package/modules/rigid/ragdollBones.js +159 -0
  358. package/modules/rigid/sync.js +6 -6
  359. package/modules/settings/Settings.js +108 -39
  360. package/modules/settings/apply.js +6 -6
  361. package/modules/settings/sections.js +16 -14
  362. package/modules/settings/view.js +3 -3
  363. package/modules/sky/Sky.js +29 -22
  364. package/modules/sky/clouds.js +7 -7
  365. package/modules/sky/dome.js +33 -20
  366. package/modules/sky/domeLayers.js +9 -9
  367. package/modules/sky/environment.js +6 -6
  368. package/modules/sky/frame.js +19 -10
  369. package/modules/sky/season.js +7 -1
  370. package/modules/sky/shader.js +24 -25
  371. package/modules/sky/skyModule.js +14 -27
  372. package/modules/sky/tint.js +1 -1
  373. package/modules/swarm/Swarm.js +346 -0
  374. package/modules/swarm/draw.js +68 -0
  375. package/modules/swarm/grid.js +63 -0
  376. package/modules/terrain/ChunkManager.js +70 -52
  377. package/modules/terrain/chunkQueries.js +7 -24
  378. package/modules/terrain/chunkWorker.js +1 -1
  379. package/modules/terrain/draw.js +14 -11
  380. package/modules/terrain/index.js +28 -34
  381. package/modules/terrain/terrainColorMap.js +6 -3
  382. package/modules/terrain/terrainDefaults.js +2 -1
  383. package/modules/terrain/terrainEdit.js +32 -27
  384. package/modules/terrain/terrainGen.js +17 -12
  385. package/modules/terrain/terrainIsland.js +2 -2
  386. package/modules/terrain/terrainMesh.js +7 -6
  387. package/modules/terrain/terrainShape.js +8 -10
  388. package/modules/terrain/terrainShapeMain.js +3 -3
  389. package/modules/timeline/Timeline.js +27 -19
  390. package/modules/timeline/Tween.js +6 -6
  391. package/modules/timeline/shots.js +5 -7
  392. package/modules/triggers/index.js +9 -9
  393. package/modules/vegetation/Vegetation.js +30 -23
  394. package/modules/vegetation/densityMap.js +4 -7
  395. package/modules/vegetation/draw.js +23 -18
  396. package/modules/vegetation/groundChunks.js +11 -31
  397. package/modules/vegetation/index.js +8 -6
  398. package/modules/vegetation/modelGeometry.js +3 -6
  399. package/modules/vegetation/nearFade.js +1 -1
  400. package/modules/water/Water.js +16 -16
  401. package/modules/water/surface.js +3 -3
  402. package/modules/weather/Weather.js +41 -30
  403. package/modules/weather/particles.js +8 -8
  404. package/modules/weather/weatherDraw.js +22 -18
  405. package/modules/world/World.js +8 -8
  406. package/modules/world/explain.js +1 -1
  407. package/modules/world/index.js +18 -12
  408. package/modules/world/persist.js +73 -25
  409. package/modules/world/pos.js +4 -4
  410. package/modules/world/records.js +28 -8
  411. package/modules/world/sim.js +4 -4
  412. package/modules/world/state.js +12 -5
  413. package/modules/world/thingSource.js +4 -2
  414. package/modules/world/views.js +11 -9
  415. package/package.json +42 -7
  416. package/presets.js +1 -3
  417. package/render/PostFX.js +39 -27
  418. package/render/backend.js +26 -32
  419. package/render/cascades.js +17 -12
  420. package/render/cascades.tsl.js +5 -8
  421. package/render/daylight.js +20 -3
  422. package/render/detail.js +8 -7
  423. package/render/effects.js +28 -25
  424. package/render/fuse.js +3 -3
  425. package/render/fx/cloudShadow.tsl.js +3 -3
  426. package/render/fx/detail.tsl.js +1 -1
  427. package/render/fx/index.js +5 -10
  428. package/render/fx/library.tsl.js +11 -0
  429. package/render/fx/lighting.tsl.js +2 -1
  430. package/render/fx/nodeErrors.tsl.js +2 -2
  431. package/render/fx/objectOrigin.tsl.js +1 -2
  432. package/render/fx/patchNodes.tsl.js +5 -15
  433. package/render/fx/postWebGPU.tsl.js +27 -23
  434. package/render/fx/sky.tsl.js +15 -17
  435. package/render/fx/uniforms.tsl.js +4 -4
  436. package/render/fx/wind.tsl.js +1 -1
  437. package/render/fxNumbers.js +3 -0
  438. package/render/layers.js +1 -1
  439. package/render/lighting.js +5 -3
  440. package/render/lightmap.js +20 -20
  441. package/render/lights.js +6 -6
  442. package/render/lit.js +24 -0
  443. package/render/materials.js +8 -7
  444. package/render/mergeCommon.js +22 -0
  445. package/render/modeling.js +2 -2
  446. package/render/occlusion.js +20 -4
  447. package/render/ownFrame.js +4 -4
  448. package/render/patches.js +13 -13
  449. package/render/postWebGL.js +12 -10
  450. package/render/probes.js +16 -19
  451. package/render/recordSweep.js +117 -0
  452. package/render/shaderErrors.js +10 -9
  453. package/render/shadowCache.tsl.js +107 -0
  454. package/render/shadowTypes.js +9 -0
  455. package/{core → render}/shadows.js +57 -11
  456. package/render/slots.js +7 -7
  457. package/render/terms.js +22 -24
  458. package/render/uniformDecl.js +1 -1
  459. package/types/core.d.ts +200 -153
  460. package/types/gameplay.d.ts +163 -91
  461. package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
  462. package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
  463. package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
  464. package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +7 -15
  465. package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
  466. package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
  467. package/types/generated/core/{Input.d.ts → input/Input.d.ts} +12 -8
  468. package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
  469. package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +2 -2
  470. package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
  471. package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
  472. package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
  473. package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
  474. package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
  475. package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
  476. package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
  477. package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
  478. package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
  479. package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
  480. package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
  481. package/types/generated/modules/calendar/Calendar.d.ts +10 -11
  482. package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
  483. package/types/generated/modules/grid/Layer.d.ts +1 -1
  484. package/types/generated/modules/grid/index.d.ts +3 -3
  485. package/types/generated/modules/music/Music.d.ts +7 -5
  486. package/types/generated/modules/particles/Particles.d.ts +1 -1
  487. package/types/generated/modules/sky/Sky.d.ts +21 -10
  488. package/types/generated/modules/swarm/Swarm.d.ts +80 -0
  489. package/types/generated/modules/timeline/Timeline.d.ts +2 -1
  490. package/types/generated/modules/water/Water.d.ts +1 -0
  491. package/types/generated/modules/weather/Weather.d.ts +16 -12
  492. package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
  493. package/types/generated/modules/world/World.d.ts +5 -3
  494. package/types/generated/render/PostFX.d.ts +17 -11
  495. package/types/generated/render/materials.d.ts +1 -0
  496. package/types/generated/render/occlusion.d.ts +9 -0
  497. package/types/generated/render/patches.d.ts +1 -0
  498. package/types/generated/ui/Focus.d.ts +1 -0
  499. package/types/generated/ui/UI.d.ts +1 -0
  500. package/types/nav.d.ts +11 -11
  501. package/types/physics.d.ts +99 -70
  502. package/types/tsl.d.ts +37 -4
  503. package/types/world.d.ts +38 -71
  504. package/ui/Focus.js +10 -9
  505. package/ui/Parts.js +4 -3
  506. package/ui/UI.js +7 -7
  507. package/ui/defaults.js +3 -2
  508. package/ui/theme.js +5 -3
  509. package/core/assetEntry.js +0 -109
  510. package/core/holds.js +0 -134
  511. package/core/shadowTypes.js +0 -16
  512. package/core/util.js +0 -17
  513. package/docs/MIGRATING-0.3.md +0 -248
  514. package/docs/MIGRATING-0.4.md +0 -320
  515. package/docs/MIGRATING-0.5.md +0 -68
  516. package/docs/MIGRATING-0.6.md +0 -126
  517. package/docs/PERF.md +0 -245
  518. package/docs/recipes/36-sky-ground-plants.md +0 -158
  519. package/docs/recipes/37-terrain-hooks.md +0 -115
  520. package/docs/recipes/38-environment-hooks.md +0 -67
  521. package/docs/recipes/42-terrain-shape.md +0 -64
  522. package/docs/recipes/47-island-snow-backdrop.md +0 -43
  523. package/docs/recipes/54-three-idioms.md +0 -88
  524. package/examples/plain-picture/FINDINGS.md +0 -53
  525. /package/core/{Vars.js → base/Vars.js} +0 -0
  526. /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
  527. /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
  528. /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
  529. /package/core/{actor.js → ops/actor.js} +0 -0
  530. /package/core/{opsFail.js → ops/opsFail.js} +0 -0
  531. /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
  532. /package/core/{saveIds.js → saves/saveIds.js} +0 -0
  533. /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
  534. /package/core/{tier.js → scene/tier.js} +0 -0
  535. /package/core/{cells.js → stream/cells.js} +0 -0
  536. /package/core/{streamCells.js → stream/streamCells.js} +0 -0
  537. /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
  538. /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
  539. /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
  540. /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
  541. /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
  542. /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
  543. /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
  544. /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
@@ -1,8 +1,9 @@
1
- // Models of placed content records: clone the shared prototype of a model name (core/namedModel.js protoOf, the one path every system uses),
1
+ // Models of placed content records: clone the shared prototype of a model name (core/assets/namedModel.js protoOf, the one path every system uses),
2
2
  // align it and its collision to the record (props and template instances).
3
- import { protoOf } from '../../core/namedModel.js';
3
+ import { protoOf } from '../../core/assets/namedModel.js';
4
+ import { wrapLod } from '../../core/assets/assetLod.js';
4
5
  import { Vector3 } from 'three';
5
- import { list } from './rules.js';
6
+ import { list } from '../../core/base/util.js';
6
7
 
7
8
  const BASE_BAND = 0.2; // the share of the model's height above the ground that counts as its base
8
9
 
@@ -52,7 +53,7 @@ export function baseOf(proto) {
52
53
  */
53
54
  export function settle(e, rec, o, solid, mul = 1) {
54
55
  const { x, z } = rec.position, rot = rec.rot ?? 0, scale = (rec.scale ?? 1) * mul, ud = o.userData;
55
- ud.fit = fitKey(rec, mul);
56
+ ud.fit = { x, z, rot, scale };
56
57
  rec.position.y = e.surface(x, z, rec.floor) + (rec.offsetY ?? 0);
57
58
  o.position.y = rec.position.y; o.rotation.y = rot; o.scale.setScalar(scale);
58
59
  ud.unstatic?.remove(); ud.unstatic = null;
@@ -68,12 +69,14 @@ export function settle(e, rec, o, solid, mul = 1) {
68
69
  ? e.collision.addCircle({ x: cx, z: cz }, { radius: (set?.circle ?? base.width / 2) * scale, height: size.y, occluder: blocks })
69
70
  : e.collision.addBox({ x: cx, z: cz }, { halfWidth: size.x / 2, halfDepth: size.z / 2, rotation: rot, height: size.y, occluder: blocks }));
70
71
  }
71
- /** What settle last aligned to; update compares it because world.move sends no event @internal */
72
- export const fitKey = (rec, mul = 1) => `${rec.position.x},${rec.position.z},${rec.rot ?? 0},${(rec.scale ?? 1) * mul}`;
72
+ /** Is the model still as settle aligned it? update asks every frame for every built prop, because world.move sends no event: four compares, no text @internal */
73
+ export const fits = (o, rec, mul = 1) => { const f = o.userData.fit, p = rec.position; return f.x === p.x && f.z === p.z && f.rot === (rec.rot ?? 0) && f.scale === (rec.scale ?? 1) * mul; };
73
74
 
74
75
  /** Clone the shared prototype of a model for one record and align it (props and template instances) @internal */
75
76
  export async function buildModel(e, api, rec, model, solid, mul = 1) {
76
- const proto = await protoOf(e, api, model), o = proto.obj.clone(), name = list(model)[0];
77
+ const proto = await protoOf(e, api, model), name = list(model)[0], lod = rec.lod ?? solid.lod;
78
+ // settle below measures proto, never o, so collision stays the full model's; the record keeps only the word `lod`, so a save holds no level
79
+ const o = lod ? await wrapLod(e.assets, name, proto.obj.clone(), { distances: Array.isArray(lod) ? lod : undefined, scale: (rec.scale ?? 1) * mul }) : proto.obj.clone();
77
80
  o.name ||= name; o.userData.name ??= name;
78
81
  o.userData.proto = proto; o.userData.colliders = [];
79
82
  if (rec.batch === false) o.userData.batch = false; // opt out of engine.batching for this record
@@ -10,9 +10,9 @@
10
10
  // - a pack may carry name: 'forest-dlc' for error messages; no other extra key (unknown keys are errors)
11
11
  // Content references assets by name only: a model written as a file path or a function is reported here in dev (the static check is
12
12
  // npm run check -> content-check, packages/tools/content-check/world.mjs).
13
- import { DEV, warnOnce, fmt } from '../../core/validate.js';
14
- import { codedError } from '../../core/errorHints.js';
15
- import { isPlainObject } from '../../core/util.js';
13
+ import { DEV, warnOnce, fmt } from '../../core/base/validate.js';
14
+ import { codedError } from '../../core/base/errorHints.js';
15
+ import { isPlainObject } from '../../core/base/util.js';
16
16
 
17
17
  const STRINGS = {
18
18
  dup: 'content.load: {key}.{id} is defined by both {a} and {b}. Packs loaded together may not share an id: rename one, or drop it from one pack',
@@ -4,8 +4,8 @@
4
4
  // gets its position in the joined array as id, and content check, write-back and the game must agree on it), and the dev line table must keep
5
5
  // naming the right file ("defined in content/props/town.js:14").
6
6
  // content/index.js: const props = contentParts(import.meta.glob('./props/*.js', { eager: true }));
7
- import { DEV } from '../../core/validate.js';
8
- import { codedError } from '../../core/errorHints.js';
7
+ import { DEV } from '../../core/base/validate.js';
8
+ import { codedError } from '../../core/base/errorHints.js';
9
9
 
10
10
  /**
11
11
  * Join the modules of one content folder into one array / object (what a single content/<kind>.js would export).
@@ -0,0 +1,35 @@
1
+ // Places in content: named positions (a pack's places file, the places option, level markers) and the position notation { place?, x?, z?, floor?, y? }.
2
+ // api is engine.content: where and offset read a place through api.place, so a wrapped place is the one they use.
3
+ import { placeY } from '../../core/scene/ground.js';
4
+ import { codedError } from '../../core/base/errorHints.js';
5
+
6
+ /** content.load: add the packs' places, then the places option on top. A text entry in a place file waits for the option */
7
+ export function addPlaces(places, packs, given) {
8
+ const pl = {};
9
+ for (const p of packs) for (const [name, at] of Object.entries(p.places ?? {})) if (at && typeof at === 'object') pl[name] = at;
10
+ Object.assign(pl, given);
11
+ for (const [name, p] of Object.entries(pl)) if (p?.rot !== undefined && !Number.isFinite(p.rot)) throw codedError('content-place', `Place "${name}": rot must be a number of radians about Y, got ${JSON.stringify(p.rot)}`);
12
+ Object.assign(places, pl);
13
+ }
14
+
15
+ /** content.place */
16
+ export function placeOf(e, places, name) {
17
+ const p = places[name] ?? e.level?.marker(name)?.position;
18
+ return p ? { x: p.x, z: p.z, ...(p.y !== undefined && { y: p.y }), ...(p.rot !== undefined && { rot: p.rot }) } : null;
19
+ }
20
+
21
+ /** content.offset */
22
+ export function offsetFrom(api, place, x, z) {
23
+ const base = place ? api.place(place) : null, dx = x - (base?.x ?? 0), dz = z - (base?.z ?? 0), c = Math.cos(base?.rot ?? 0), s = Math.sin(base?.rot ?? 0);
24
+ return { x: dx * c - dz * s, z: dx * s + dz * c };
25
+ }
26
+
27
+ /** content.where */
28
+ export function whereOf(e, api, p) {
29
+ const base = p.place ? api.place(p.place) : null;
30
+ if (p.place && !base) throw codedError('content-place', `Place "${p.place}" not found: give its coordinates in the places of content.load, or add this marker to the level`);
31
+ const ox = p.x ?? 0, oz = p.z ?? 0, c = Math.cos(base?.rot ?? 0), s = Math.sin(base?.rot ?? 0);
32
+ const x = (base?.x ?? 0) + ox * c + oz * s, z = (base?.z ?? 0) - ox * s + oz * c, floor = p.floor ?? base?.y;
33
+ if (floor === undefined && p.y === undefined) return { x, z };
34
+ return { x, y: placeY(e, `content.where(${JSON.stringify(p.place ?? { x: p.x, z: p.z })})`, x, z, floor) + (p.y ?? 0), z };
35
+ }
@@ -1,6 +1,7 @@
1
1
  // Props (each item of content/props.js): data is a plain record in engine.world with kind 'prop'; model and collision are "presentation that exists only when
2
2
  // near".
3
- // record: { id, kind: 'prop', position: {x,y,z}, model, rot?, scale?, collide?, occluder?, offsetY?, static?, batch?, zone? } (plain values only)
3
+ // record: { id, kind: 'prop', position: {x,y,z}, model, rot?, scale?, collide?, occluder?, offsetY?, static?, batch?, source?, zone? } (plain values only)
4
+ // rot = the entry's rot plus its place's. source names the arrangement an entry was copied from: a tag for world.query, nothing at runtime reads it.
4
5
  // Initial world data (initial: true on add): the save records only moves / removals, independent of content.load running before or after loading a save;
5
6
  // positions using level markers carry a zone (data is kept across level changes).
6
7
  // id: the written id if content gives one; otherwise `prop:<model name>:<index in this props array>` (same on every load of the same content, no collisions).
@@ -12,14 +13,14 @@
12
13
  // collision: built / torn down with the model (only things near the player need to block), so props beyond the collision radius take no space in the collision
13
14
  // table.
14
15
  // An entry with template (instead of model) is an instance of a content template: see templates.js.
15
- import { buildModel, settle, fitKey, unbuildModel } from './models.js';
16
+ import { buildModel, settle, fits, unbuildModel } from './models.js';
16
17
  import { placeTemplate } from './templates.js';
17
18
  import { srcOf } from './ids.js';
18
- import { placeY } from '../../core/ground.js';
19
- import { list, PLACEMENT_FIELDS, collideProblem } from './rules.js';
20
- import { DEV, fmt, closest } from '../../core/validate.js';
21
- import { codedError } from '../../core/errorHints.js';
22
-
19
+ import { placeY } from '../../core/scene/ground.js';
20
+ import { PLACEMENT_FIELDS, collideProblem } from './rules.js';
21
+ import { list } from '../../core/base/util.js';
22
+ import { DEV, fmt, closest } from '../../core/base/validate.js';
23
+ import { codedError } from '../../core/base/errorHints.js';
23
24
 
24
25
  /** Stable id of a prop: the written id if given, otherwise "model name + array index" */
25
26
  const propId = (p, i) => p.id ?? `prop:${list(p.model)[0]}:${i}`;
@@ -41,12 +42,14 @@ export function addProps(e, api, props, st, zoneOf, ids) {
41
42
  if (p.id != null) ids.claim(p.id, `props[${i}] (model ${JSON.stringify(p.model)})`);
42
43
  // compute y from the ground now (same as when the model is built): unmoved props equal the content and stay out of the save
43
44
  const def = { id, kind: 'prop', position: { x, y: y ?? placeY(e, `props[${i}] (model ${JSON.stringify(p.model)})`, x, z), z }, model: p.model };
44
- for (const k of ['rot', 'scale', 'collide', 'occluder', 'static', 'batch']) if (p[k] !== undefined) def[k] = p[k];
45
+ for (const k of ['scale', 'collide', 'occluder', 'static', 'batch', 'lod', 'source']) if (p[k] !== undefined) def[k] = p[k];
46
+ const rot = api._facingOf(p);
47
+ if (rot !== undefined) def.rot = rot;
45
48
  if (p.y) def.offsetY = p.y;
46
49
  if (floor !== undefined) def.floor = floor; // kept so a moved prop lands on the same storey
47
50
  if (zone != null) def.zone = zone;
48
51
  const rec = world.add(def, { initial: true });
49
- if (rec && (rec.kind !== 'prop' || JSON.stringify(rec.model) !== JSON.stringify(p.model))) throw codedError('pickup-prop-id', `Prop id "${id}" is already used by other data (${rec.kind}${rec.model ? ' ' + JSON.stringify(rec.model) : ''}): give this item a different id, e.g. { id: '${id}-2', model: ... }`);
52
+ if (rec && (rec.kind !== 'prop' || JSON.stringify(rec.model) !== JSON.stringify(p.model))) throw codedError('world-id', `Prop id "${id}" is already used by other data (${rec.kind}${rec.model ? ' ' + JSON.stringify(rec.model) : ''}): give this item a different id, e.g. { id: '${id}-2', model: ... }`);
50
53
  if (DEV) world.setOrigin(id, { definedAt: at, model: p.model });
51
54
  });
52
55
  }
@@ -73,13 +76,13 @@ function placeGridItem(e, p, i, zone, ids, at) {
73
76
  ids.claim(p.id, `props[${i}] (grid ${p.grid} item ${p.item})`);
74
77
  const { kind, fields } = e.grids.placement(p.grid, p.item, p.cell, p.rotation ?? 0);
75
78
  const rec = e.world.add({ id: p.id, kind, ...fields, ...structuredClone(p.fields ?? {}), ...(zone != null && { zone }) }, { initial: true });
76
- if (rec && rec.kind !== kind) throw codedError('pickup-prop-id', `grid item id "${p.id}" is already used by other data (kind ${rec.kind}): give it a different id`);
79
+ if (rec && rec.kind !== kind) throw codedError('world-id', `grid item id "${p.id}" is already used by other data (kind ${rec.kind}): give it a different id`);
77
80
  if (DEV) e.world.setOrigin(p.id, { definedAt: at });
78
81
  }
79
82
 
80
83
  /** Dev error when the world module is not installed */
81
84
  export function needWorld(e) {
82
- if (!e.world) throw codedError('world-missing', 'content has props or pickups, whose data is stored in world: call engine.use(world()) first (the openWorld() preset already installs it)');
85
+ if (!e.world) throw codedError('module-needs', 'content has props or pickups, whose data is stored in world: call engine.use(world()) first (the openWorld() preset already installs it)');
83
86
  return e.world;
84
87
  }
85
88
 
@@ -87,12 +90,12 @@ export function needWorld(e) {
87
90
  function presentProps(e, api, world, st) {
88
91
  if (st.propsPresenter) return;
89
92
 
90
- st.propsPresenter = world.present('prop', {
93
+ st.propsPresenter = st.track(world.present('prop', {
91
94
  // build by view distance: follows the terrain view distance (fog distance if no terrain), also when changed at runtime
92
95
  radius: () => Math.max(world.radius, e.stream.activeRadius),
93
96
  build: rec => buildModel(e, api, rec, rec.model, rec), // a failed model generation is reported by world (does not block loading), retried when near again
94
97
  // moved / rot or scale changed (world.move sends no event, so compare here): world already put the model at the new position; collision and rays follow
95
- update(rec, o) { if (o.userData.fit !== fitKey(rec)) settle(e, rec, o, rec); },
98
+ update(rec, o) { if (!fits(o, rec)) settle(e, rec, o, rec); },
96
99
  dispose: (rec, o) => unbuildModel(e, o),
97
- });
100
+ }));
98
101
  }
@@ -1,5 +1,5 @@
1
1
  // Content vocabulary: the "conditions" and "effects" that content files (content/*.js) can use. Shared by the loader, the validator packages/tools/content-check.mjs and the map packages/tools/gamemap.mjs.
2
- // Plain data + small functions, no import of three or the engine (the validator reads it directly in node). Real execution is in loader.js.
2
+ // Plain data + small functions, no import of three and nothing from the engine but node-safe core/base/util.js (the validator reads it directly in node). Real execution is in loader.js.
3
3
  //
4
4
  // Conditions (quest step done, dialogue option if, line variant if): several items in one object must all hold; array = every item holds
5
5
  // { flag: 'metFisher' } { notFlag: 'x' } { has: { berry: 3 } } { lacks: { film: 6 } } { counter: { sunsetPhotos: 1 } }
@@ -19,14 +19,16 @@
19
19
  //
20
20
  // Game content kinds: the same content/rules.js may export kinds: { name: { desc, load, check, map } }, so a game keeps its own data
21
21
  // (enemies, recipes, loot tables, waves, shop stock) in content/<name>.js. The loader, content-check and GAMEMAP all read this one table:
22
- // desc one line (map, file list) · load(e, data, content) hands the data to the game when engine.content.load runs (required)
22
+ // desc one line (map, file list) · load(e, data, content) hands the data to the game when engine.content.load runs (optional: a game that imports the file itself needs none)
23
23
  // check(data, ctx) optional validation in npm run check: ctx.err(msg) / ctx.warn(msg); ctx.data is all content (items, npcs…), ctx.known(obj) lists ids
24
24
  // map(data) optional GAMEMAP lines (default: the number of entries and their ids)
25
- // fields optional { key: 'int?' | { type, min, max, values, desc } } (core/params.js format, no default): the keys of each entry; content-check
25
+ // fields optional { key: 'int?' | { type, min, max, values, desc } } (core/base/params.js format, no default): the keys of each entry; content-check
26
26
  // reports unknown keys (did you mean), wrong types, out of range, and missing required keys; engine.content.fields(name) returns it
27
27
  // export default { kinds: { recipes: { desc: 'crafting recipes (id -> { needs: { item: n }, makes })', load: (e, data) => e.crafting.add(data),
28
28
  // check: (data, ctx) => { for (const [id, r] of Object.entries(data)) if (!ctx.data.items?.[r.makes]) ctx.err(`recipe ${id} makes unknown item ${r.makes}`); } } } };
29
29
 
30
+ import { list, isObject } from '../../core/base/util.js';
31
+
30
32
  const counts = o => Object.entries(o || {}).map(([k, n]) => `${k}×${n}`).join('、');
31
33
  const opText = v => Array.isArray(v) ? `${v[0]}${v[1] ? ' ' + Object.entries(v[1]).map(([k, x]) => `${k}=${x}`).join(' ') : ''}` : String(v);
32
34
  const posText = v => typeof v === 'string' ? v : v.place ? `${v.place}${v.x || v.z ? `(${v.x ?? 0},${v.z ?? 0})` : ''}` : `(${v.x},${v.z})`;
@@ -49,7 +51,8 @@ const RULE_STRINGS = {
49
51
  toast: { ref: 'text', desc: 'show a toast', describe: v => `toast "${v}"` },
50
52
  particles: { ref: 'particles', desc: 'play particles', describe: v => `particles ${v.name}×${v.count ?? ''}` },
51
53
  marker: { ref: 'position', desc: 'add an objective marker (hud module)', describe: v => `marker ${posText(v)}${v.label ? `"${v.label}"` : ''}` },
52
- clearMarker: { ref: 'position', desc: 'remove an objective marker', describe: v => `remove marker ${posText(v)}` },
54
+ // raw: the value names the marker (content-check still reads it as a place); a place that is gone, on a level left behind, must not stop the clearing
55
+ clearMarker: { ref: 'position', raw: true, desc: 'remove an objective marker', describe: v => `remove marker ${posText(v)}` },
53
56
  op: { ref: 'op', desc: "run a game op (engine.ops.run); the game's own actions are ops", describe: v => `op ${opText(v)}` },
54
57
  },
55
58
  // content file name -> description (only these files are recognized in content/)
@@ -57,13 +60,13 @@ const RULE_STRINGS = {
57
60
  items: 'items (id -> name, icon, description); also export startItems for starting items',
58
61
  pickups: 'pickups on the ground (list)',
59
62
  containers: 'chests / shelves (container id -> { capacity, items: starting goods }; starting goods are placed only the first time, then saved)',
60
- npcs: 'NPCs (id -> name, schedule, dialogue)',
63
+ npcs: 'NPCs (id -> name, schedule, interact)',
61
64
  dialogues: 'dialogues (id -> speaker, nodes)',
62
65
  quests: 'quests (id -> title, steps, reward; a step can have a target position)',
63
66
  actions: 'own key actions of the game (action name -> default key, label)',
64
- places: 'place names (coordinates computed at runtime in main.js)',
67
+ places: 'place names (name -> { x, z, y?, rot? }; rot turns everything placed there about Y; coordinates may be computed at runtime in main.js)',
65
68
  triggers: 'trigger zones (tag -> position / from level, enter/exit effects)',
66
- level: 'level markers (spawn point, NPCs, trigger zones)',
69
+ level: 'level markers (spawn point, NPCs, trigger zones) of a code-built level: for the tools (content checks, GAMEMAP); load() accepts the file and does not read it',
67
70
  vegetation: 'vegetation (name -> model, growth rule)',
68
71
  props: 'props (list: model, position, facing, collision; or { template, x, z } = an instance of a template; or { id, grid, item, cell } = a grid item), streamed in on demand',
69
72
  templates: 'reusable objects (name -> model, collide, interact, container, sound, animate, state defaults, physics body); shared read-only definitions',
@@ -71,16 +74,16 @@ const RULE_STRINGS = {
71
74
  views: 'named fixed camera views (name -> { position: [x, y, z], target?: [x, y, z], fov? }); engine.views.show(name), ?view=name, npm run shot -- -w game --view name',
72
75
  grids: 'placement grids (name -> { cell, origin, size, zone?, flat? }); layout rules, not saved',
73
76
  renames: "renamed or deleted authored ids (old id -> new id, or null = deleted on purpose): the player's saved changes follow the new id",
74
- rules: 'condition words added by the game ({ conditions }); actions are ops, not effect words',
77
+ rules: 'condition words and data kinds added by the game ({ conditions, kinds }); actions are ops, not effect words',
75
78
  },
76
- // Placement fields: the keys one entry of a content file may have, in the core/params.js spec format. Declared once here, read by the loader
79
+ // Placement fields: the keys one entry of a content file may have, in the core/base/params.js spec format. Declared once here, read by the loader
77
80
  // (unknown keys), content-check (unknown keys with did-you-mean, wrong type, out of range, not in values) and engine.content.fields() (an editor
78
81
  // panel's rows), so the three cannot drift apart. props has three entry shapes: a plain model ('props'), a template instance ('props.template',
79
82
  // plus the template's state fields) and a grid item ('props.grid'). Required-ness of x / z / model is checked by the content rules themselves
80
83
  // (x, z are optional when place is given), so they are marked optional here.
81
84
  fields: (() => {
82
85
  const at = {
83
- place: { type: 'string', optional: true, desc: 'place name (places.js / level marker); x and z are then offsets from it' },
86
+ place: { type: 'string', optional: true, desc: "place name (places.js / level marker); x and z are then offsets from it and turn with the place's rot" },
84
87
  x: { type: 'number', optional: true, desc: 'meters along x (offset from place when place is given)' },
85
88
  z: { type: 'number', optional: true, desc: 'meters along z (offset from place when place is given)' },
86
89
  floor: { type: 'number', optional: true, desc: 'reference height of the storey it stands on (multi-layer ground)' },
@@ -90,18 +93,21 @@ const RULE_STRINGS = {
90
93
  rot: { type: 'number', optional: true, desc: 'facing around the vertical axis, radians' },
91
94
  scale: { type: 'number', optional: true, min: 0, desc: 'uniform scale (1 = model size)' },
92
95
  };
96
+ // a plain tag, so world.query({ where: r => r.source === 'stall' }) finds every copy of one arrangement; nothing else reads it
97
+ const copied = { source: { type: 'string', optional: true, desc: 'name of the arrangement this entry was copied from; queryable, no other effect' } };
93
98
  return {
94
99
  props: {
95
100
  id: { type: 'string', optional: true, desc: 'stable id (needed when entries are later inserted in the middle)' },
96
- model: { type: 'any', desc: "model name, or [name, ...args] for a generated model" }, ...at, ...pose,
101
+ model: { type: 'any', desc: "model name, or [name, ...args] for a generated model" }, ...at, ...pose, ...copied,
97
102
  collide: { type: 'any', optional: true, desc: "collision: 'box', 'circle', { circle: radius, occluder?: false }, or false = none" },
98
103
  occluder: { type: 'bool', optional: true, desc: 'false = a solid prop the follow camera may pass through (walkers are still stopped)' },
99
104
  static: { type: 'bool', optional: true, desc: 'never moves (may be merged into one draw call)' },
100
105
  batch: { type: 'bool', optional: true, desc: 'false = never batch this copy' },
106
+ lod: { type: 'any', optional: true, desc: 'true = lower-detail levels far away (threedog assets optimize --lod), or rising distances in meters like [40, 120]; such a copy is never batched' },
101
107
  },
102
108
  'props.template': {
103
109
  template: { type: 'string', desc: 'template name (content/templates.js)' },
104
- id: { type: 'string', optional: true, desc: 'stable id; instances with state should have one' }, ...at, ...pose,
110
+ id: { type: 'string', optional: true, desc: 'stable id; instances with state should have one' }, ...at, ...pose, ...copied,
105
111
  items: { type: 'object', optional: true, desc: "starting goods of the instance's container { itemId: count }" },
106
112
  },
107
113
  'props.grid': {
@@ -146,12 +152,12 @@ export const EFFECTS = RULE_STRINGS.effects;
146
152
  export const REFS = RULE_STRINGS.refs;
147
153
  /** content file name -> description */
148
154
  export const CONTENT_FILES = RULE_STRINGS.files;
149
- /** content entry shape -> { key: field spec } (core/params.js format): 'props', 'props.template', 'props.grid', 'pickups', 'views'. Read via fields.js */
155
+ /** content entry shape -> { key: field spec } (core/base/params.js format): 'props', 'props.template', 'props.grid', 'pickups', 'views'. Read via fields.js */
150
156
  export const PLACEMENT_FIELDS = RULE_STRINGS.fields;
151
157
  /** Why a prop's or template's `collide` is wrong, or null. One rule for the load and content-check: a mistyped object must not quietly become a box */
152
158
  export function collideProblem(v) {
153
159
  if (v === undefined || v === false || v === 'box' || v === 'circle') return null;
154
- const form = !!v && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).every(k => k === 'circle' || k === 'occluder');
160
+ const form = isObject(v) && Object.keys(v).every(k => k === 'circle' || k === 'occluder');
155
161
  if (form && Number.isFinite(v.circle) && v.circle > 0 && (v.occluder === undefined || typeof v.occluder === 'boolean')) return null;
156
162
  return `must be one of false, "box", "circle" or { circle: radius in meters above 0, occluder?: false }, got ${JSON.stringify(v)}`;
157
163
  }
@@ -168,22 +174,20 @@ export function contentFiles(game = {}) {
168
174
  for (const [name, k] of Object.entries(game?.kinds || {})) out[name] ??= k?.desc || 'game data kind';
169
175
  return out;
170
176
  }
171
- /** Problems with a game's kinds table (name clashes with an engine file, no load): a list of messages */
177
+ /** Problems with a game's kinds table (name clashes with an engine file, a load that is no function): a list of messages */
172
178
  export function kindProblems(game = {}) {
173
179
  return Object.entries(game?.kinds || {}).flatMap(([name, k]) => [
174
180
  ...(CONTENT_FILES[name] || name === 'startItems' ? [`kind "${name}" is an engine content file name: pick another name (engine files: ${Object.keys(CONTENT_FILES).join(', ')})`] : []),
175
- ...(typeof k?.load !== 'function' ? [`kind "${name}" has no load(e, data) function, so its data would never reach the game`] : []),
181
+ ...(k?.load !== undefined && typeof k.load !== 'function' ? [`kind "${name}": load must be a function (e, data) => …, or left out when the game imports the file itself`] : []),
176
182
  ]);
177
183
  }
178
184
  /** Error text for a content name that is neither an engine file nor a registered kind */
179
185
  export const unknownContent = (name, game) => `unknown content "${name}". Known: ${Object.keys(contentFiles(game)).join(', ')}. `
180
- + `For the game's own data, register it in content/rules.js: export default { kinds: { ${name}: { desc: '…', load: (e, data) => { … } } } }`;
181
- /** Error text when a game's content/rules.js still exports effects */
182
- export const NO_GAME_EFFECTS = "content/rules.js: games no longer add effect words. Register the action as an op (engine.ops.define('noun.verb', { can, run }) in main.js) "
186
+ + `For the game's own data, register it in content/rules.js: export default { kinds: { ${name}: { desc: '…', load: (e, data) => { … } } } }, and list \`rules\` in content/index.js too: the loader only knows what it is handed`;
187
+ /** Error text for an effects key in a game's content/rules.js */
188
+ export const NO_GAME_EFFECTS = "content/rules.js: effects is not a key here. Register the action as an op (engine.ops.define('noun.verb', { can, run }) in main.js) "
183
189
  + "and call it from content with { op: ['noun.verb', { args }] }; see recipes/23-ops.md";
184
190
 
185
- /** Wrap a single value into an array (a model written as 'tree' or ['tree', ...args]); the one copy for the content files @param {any} v @returns {any[]} */
186
- export const list = v => (Array.isArray(v) ? v : [v]);
187
191
  const say = (vocab, x) => Object.entries(x).map(([k, v]) => vocab[k]?.describe?.(v) ?? `${k} ${JSON.stringify(v)}`);
188
192
 
189
193
  /** Describe a condition as one human-readable sentence (for the map); vocab defaults to the engine vocabulary */
@@ -5,15 +5,15 @@
5
5
  // canGrow: (rec, e) => rec.watered }
6
6
  // Why the stage lives on the record and not on a separate registry: the record is what world saves, what content-check / content.fields() describe
7
7
  // and what the editor edits, so `stage` is an ordinary state field (default 0, range 0..n-1) and `stageAt` (engine.clock.now when it entered the stage)
8
- // sits beside it. Growth is counted in game seconds (clock.now), so a far record, a loaded save or a time skip all catch up in one pass.
8
+ // sits beside it. Growth is counted in calendar seconds (clock.now), so a far record, a loaded save or a time skip all catch up in one pass.
9
9
  // Node-safe (no three): content-check imports this file directly, so the engine and the check accept the same stages.
10
- import { closest } from '../../core/validate.js';
10
+ import { closest } from '../../core/base/validate.js';
11
+ import { isModelName } from '../../core/base/util.js';
11
12
 
12
13
  const STAGE_KEYS = ['name', 'duration', 'scale', 'model'];
13
- const isModel = m => typeof m === 'string' || (Array.isArray(m) && typeof m[0] === 'string');
14
14
 
15
15
  /**
16
- * Problems of a template's stages list (empty list = fine). Every stage but the last needs a duration (game seconds spent there); the last may omit it
16
+ * Problems of a template's stages list (empty list = fine). Every stage but the last needs a duration (calendar seconds spent there); the last may omit it
17
17
  * (stays there). model is a model name like the template's own model (no functions: stages are data an editor can show and content-check can read).
18
18
  * @param {string} where e.g. "template 'crop'"
19
19
  * @param {any} stages
@@ -37,12 +37,12 @@ export function stagesProblems(where, stages) {
37
37
  else if (names.has(s.name)) out.push(`${at}: name '${s.name}' is used by an earlier stage; stage names must differ`);
38
38
  else names.add(s.name);
39
39
  const last = i === stages.length - 1;
40
- if (s.duration === undefined) { if (!last) out.push(`${at} needs duration (game seconds spent in this stage); only the last stage may leave it out`); }
41
- else if (!Number.isFinite(s.duration) || s.duration <= 0) out.push(`${at}: duration must be a positive number of game seconds, got ${JSON.stringify(s.duration)}`);
40
+ if (s.duration === undefined) { if (!last) out.push(`${at} needs duration (calendar seconds spent in this stage); only the last stage may leave it out`); }
41
+ else if (!Number.isFinite(s.duration) || s.duration <= 0) out.push(`${at}: duration must be a positive number of calendar seconds, got ${JSON.stringify(s.duration)}`);
42
42
  if (s.scale !== undefined && (!Number.isFinite(s.scale) || s.scale <= 0)) {
43
43
  out.push(`${at}: scale must be a positive number (multiplies the instance scale), got ${JSON.stringify(s.scale)}`);
44
44
  }
45
- if (s.model !== undefined && !isModel(s.model)) out.push(`${at}: model must be a model name (like the template's model), got ${JSON.stringify(s.model)}`);
45
+ if (s.model !== undefined && !isModelName(s.model)) out.push(`${at}: model must be a model name (like the template's model), got ${JSON.stringify(s.model)}`);
46
46
  });
47
47
  return out;
48
48
  }
@@ -23,23 +23,23 @@
23
23
  // body: { shape: 'box' | 'ball' | 'hull', mass?, friction?, restitution?, damping?, angularDamping? } makes each copy a rigid body (needs rigid()):
24
24
  // it can be pushed, the model moves itself and its position is copied back to the record, so a pushed crate's place is saved like any other change.
25
25
  // Ids: an instance with state (state / container / interact / body) should have a written id (ids.js); without one dev warns.
26
- import { checkOptions, freezeDef, missingText, fmt, DEV } from '../../core/validate.js';
27
- import { xzOf } from '../../core/math.js';
28
- import { placeY } from '../../core/ground.js';
29
- import { buildModel, settle, fitKey, unbuildModel } from './models.js';
26
+ import { checkOptions, freezeDef, missingText, fmt, DEV } from '../../core/base/validate.js';
27
+ import { xzOf } from '../../core/base/math.js';
28
+ import { placeY } from '../../core/scene/ground.js';
29
+ import { buildModel, settle, fits, unbuildModel } from './models.js';
30
30
  import { srcOf, stateful, templateId } from './ids.js';
31
31
  import { PLACEMENT_FIELDS, collideProblem } from './rules.js';
32
32
  import { fieldsShape } from './fields.js';
33
- import { whyBad, readParams, keysSchema } from '../../core/params.js';
33
+ import { whyBad, readParams, keysSchema } from '../../core/base/params.js';
34
34
  import { stagesProblems, stagedFields, growStages } from './stages.js';
35
- import { codedError } from '../../core/errorHints.js';
35
+ import { codedError } from '../../core/base/errorHints.js';
36
36
 
37
- const DEF_KEYS = ['model', 'collide', 'occluder', 'static', 'interact', 'container', 'sound', 'animate', 'state', 'fields', 'body', 'stages', 'update', 'canGrow'];
37
+ const DEF_KEYS = ['model', 'collide', 'occluder', 'static', 'lod', 'interact', 'container', 'sound', 'animate', 'state', 'fields', 'body', 'stages', 'update', 'canGrow'];
38
38
  const BODY_KEYS = ['shape', 'mass', 'friction', 'restitution', 'damping', 'angularDamping'];
39
39
  // what a placement may set besides the state fields: the placement field table (rules.js), so the loader, content-check and content.fields() agree
40
40
  const PLACE_KEYS = Object.keys(PLACEMENT_FIELDS['props.template']);
41
41
  // content.spawn gets its position as an argument, so only the id and the picture / goods keys of the same table
42
- const SPAWN_KEYS = PLACE_KEYS.filter(k => !['template', 'place', 'x', 'z', 'floor'].includes(k));
42
+ const SPAWN_KEYS = PLACE_KEYS.filter(k => !['template', 'place', 'x', 'z', 'floor', 'source'].includes(k));
43
43
 
44
44
  const STRINGS = {
45
45
  noModel: "template '{name}' needs a model: a model name from an asset pack (engine.assets.manifest({ models: { chest: '/models/chest.glb' | fn } })), e.g. { model: 'chest' }",
@@ -99,7 +99,7 @@ export function defineTemplates(e, api, st, defs) {
99
99
  limitContainers(e, st, name);
100
100
  }
101
101
  // a save brings back runtime instances and their goods, but container limits are definition data: put them back from the template
102
- st.templateLoad ??= e.events.on('world:load', () => { for (const name of st.templates.keys()) limitContainers(e, st, name); });
102
+ st.templateLoad ??= st.track(e.events.on('world:load', () => { for (const name of st.templates.keys()) limitContainers(e, st, name); }));
103
103
  }
104
104
 
105
105
  /** The definition of a template, or a dev error listing the known ones. @internal */
@@ -117,6 +117,9 @@ export function placeTemplate(e, api, st, p, i, zone, ids, origin) {
117
117
  const name = p.template, d = templateOf(st, name), id = templateId(p, i), { x, y, z } = api.where(p), floor = api._floorOf(p);
118
118
  const own = instanceFields(name, d, p, PLACE_KEYS, st.templateFields.get(name));
119
119
  if (floor !== undefined) own.floor = floor; // same as props: a moved instance lands on the same storey
120
+ const rot = api._facingOf(p);
121
+ if (rot !== undefined) own.rot = rot;
122
+ if (p.source !== undefined) own.source = p.source;
120
123
  if (ids && p.id != null) ids.claim(p.id, `props[${i}] (template ${name})`);
121
124
  else if (ids && stateful(d)) ids.unnamed(id, `props[${i}] (template ${name})`);
122
125
  const rec = e.world.add({ id, kind: name, position: { x, y: y ?? placeY(e, `props[${i}] (template ${name})`, x, z), z }, ...own, ...(zone != null && { zone }) }, { initial: true });
@@ -171,7 +174,7 @@ function present(e, api, st, name) {
171
174
  st.templateViews.add(name);
172
175
  const def = () => st.templates.get(name); // a later load may replace the definition: always read the current one
173
176
  const body = !!def().body; // a physics body moves the model itself: the record follows the model (positionFrom 'view'), so a pushed position is saved
174
- e.world.present(name, {
177
+ st.track(e.world.present(name, { // tracked: without content there is no definition to build from, and a new content() must be able to present the kind
175
178
  radius: () => Math.max(e.world.radius, e.stream.activeRadius), // same build distance as props
176
179
  positionFrom: body ? 'view' : 'record',
177
180
  async build(rec) {
@@ -193,12 +196,12 @@ function present(e, api, st, name) {
193
196
  // a stage that names another model: tear this copy down, world builds the new one next frame (the record, and so the save, is untouched)
194
197
  if (d.stages && !sameModel(o.userData, d, rec)) { e.world.rebuild(rec.id); return; }
195
198
  const mul = stageScale(d, rec);
196
- if (!d.body && o.userData.fit !== fitKey(rec, mul)) settle(e, rec, o, d, mul); // a body places itself; a stage scale re-aligns collision too
199
+ if (!d.body && !fits(o, rec, mul)) settle(e, rec, o, d, mul); // a body places itself; a stage scale re-aligns collision too
197
200
  else if (d.body) restBody(e, rec, o);
198
201
  d.animate?.(rec, o, dt);
199
202
  },
200
203
  dispose(rec, o) { o.userData.use?.remove(); o.userData.body?.remove(); unbuildModel(e, o); },
201
- });
204
+ }));
202
205
  }
203
206
 
204
207
  /**
@@ -228,11 +231,6 @@ function restBody(e, rec, o) {
228
231
  if (b.isSleeping()) e.world.rest(rec.id, p, SETTLE);
229
232
  }
230
233
 
231
- /** The model a copy shows: its stage's model, else the nearest earlier stage's, else the template's (so it never depends on what was built before) */
232
- function modelOf(d, rec) {
233
- for (let i = Math.min(rec.stage ?? 0, (d.stages?.length ?? 0) - 1); i >= 0; i--) if (d.stages[i].model) return d.stages[i].model;
234
- return d.model;
235
- }
236
234
  /**
237
235
  * Which definition and which stage supplied the model (the stage index, -1 for the template's own). Two equal keys always mean the same model, so
238
236
  * the per-frame check compares one object and one number instead of serializing the model of every instance every frame.
@@ -241,6 +239,8 @@ function modelSource(d, rec) {
241
239
  for (let i = Math.min(rec.stage ?? 0, (d.stages?.length ?? 0) - 1); i >= 0; i--) if (d.stages[i].model) return { d, at: i };
242
240
  return { d, at: -1 };
243
241
  }
242
+ /** The model a copy shows: its stage's model, else the nearest earlier stage's, else the template's (so it never depends on what was built before) */
243
+ function modelOf(d, rec) { const { at } = modelSource(d, rec); return at < 0 ? d.model : d.stages[at].model; }
244
244
  /** Same model as when built? Same definition + same source stage is a yes without serializing; only a reloaded definition falls back to comparing text */
245
245
  function sameModel(ud, d, rec) {
246
246
  const k = modelSource(d, rec), b = ud.modelFrom;
@@ -254,7 +254,7 @@ const stageScale = (d, rec) => d.stages?.[rec.stage ?? 0]?.scale ?? 1;
254
254
 
255
255
  /**
256
256
  * Gameplay of a template kind on the fixed step (world.simulate, once per name; each step reads the current definition, so a later load replaces it).
257
- * Growth runs near and far (far catches up in game seconds, several stages at once); update runs near only: a far copy only grows.
257
+ * Growth runs near and far (far catches up in calendar seconds, several stages at once); update runs near only: a far copy only grows.
258
258
  */
259
259
  function simulate(e, st, name) {
260
260
  if (st.templateSims.has(name)) return;
@@ -267,10 +267,10 @@ function simulate(e, st, name) {
267
267
  e.world.set(rec.id, next); // through world.set: world:change fires and the save keeps it, like any other gameplay change
268
268
  e.events.emit('template:stage', { id: rec.id, template: name, stage: next.stage, name: d.stages[next.stage].name });
269
269
  };
270
- e.world.simulate(name, {
270
+ st.track(e.world.simulate(name, {
271
271
  near: (rec, dt) => { grow(rec); st.templates.get(name)?.update?.(rec, dt, e); },
272
272
  far: rec => grow(rec),
273
- });
273
+ }));
274
274
  }
275
275
 
276
276
  const label = (e, l, rec) => typeof l === 'function' ? l(rec, e) : l && e.i18n.has(l) ? e.t(l) : l;
@@ -0,0 +1,34 @@
1
+ // Running condition and effect words: content.test and content.run. The vocabulary is rules.js, the built-in meanings are in loader.js.
2
+ import { warnMissing } from '../../core/base/validate.js';
3
+ import { parseClock } from '../../core/time/dayTime.js';
4
+ import { list } from '../../core/base/util.js';
5
+
6
+ /** Convert content notation to runtime values by ref (clock time -> fraction, place -> { x, z }) */
7
+ const norm = (e, api, ref, v) => ref === 'clock' ? parseClock(v, e.calendar?.hoursPerDay ?? 24) : ref === 'position' ? api.where(typeof v === 'string' ? { place: v } : v) : v;
8
+
9
+ /** content.test */
10
+ export function testWords(e, api, conds, c, actor) {
11
+ if (!c) return true;
12
+ const ctx = { actor };
13
+ if (typeof c === 'function') return !!c(e, ctx);
14
+ return list(c).every(x => Object.entries(x).every(([k, v]) => {
15
+ const d = conds.get(k);
16
+ if (!d) { warnMissing('condition', k, [...conds.keys()]); return false; }
17
+ return !!d.test(e, norm(e, api, d.ref, v), v, ctx);
18
+ }));
19
+ }
20
+
21
+ /** content.run */
22
+ export function runWords(e, api, effects, a, actor) {
23
+ if (!a) return;
24
+ const ctx = { actor };
25
+ if (typeof a === 'function') return a(e, ctx);
26
+ // One failing effect must not drop the ones after it (a reward with give + spawn would be half given): run them all, then rethrow the first error
27
+ let first = null, failed = 0;
28
+ for (const x of list(a)) for (const [k, v] of Object.entries(x)) {
29
+ const d = effects.get(k);
30
+ if (!d) { warnMissing('effect', k, [...effects.keys()]); continue; }
31
+ try { d.run(e, d.raw ? v : norm(e, api, d.ref, v), v, ctx); } catch (err) { first ??= err; failed++; }
32
+ }
33
+ if (first) { if (failed > 1) first.message += ` (${failed} effects failed; the others ran)`; throw first; }
34
+ }