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
@@ -4,17 +4,18 @@
4
4
  // a world coordinate.
5
5
  // Optional floor (reference height on multi-layer ground) and y (meters above that ground): see content.where.
6
6
  import { toast } from '../../ui/UI.js';
7
- import { parseClock } from '../../core/dayTime.js';
8
- import { vegetationModel } from '../../core/namedModel.js';
9
- import { addProps, needWorld } from './props.js';
10
- import { defineTemplates } from './templates.js';
11
7
  import { srcOf, applyRenames, pickupId } from './ids.js';
12
- import { DEV, warnOnce } from '../../core/validate.js';
13
- import { readParams, keysSchema } from '../../core/params.js';
14
- import { NO_GAME_EFFECTS, contentFiles, kindProblems, unknownContent, list } from './rules.js';
15
- import { codedError, coded } from '../../core/errorHints.js';
16
- import { reportError } from '../../core/errors.js';
17
-
8
+ import { DEV, warnOnce } from '../../core/base/validate.js';
9
+ import { NO_GAME_EFFECTS, contentFiles, kindProblems, unknownContent } from './rules.js';
10
+ import { sectionHomes } from '../../core/inspect/metadata.generated.js';
11
+ import { sectionsOf, runSections, keepTable } from '../../core/base/sections.js';
12
+ import { whenTurnFree, whileRestoring, liveTurn } from '../../core/saves/stateReplace.js';
13
+ import { codedError, coded } from '../../core/base/errorHints.js';
14
+ import { failure } from '../../core/ops/opsFail.js';
15
+
16
+ // data order, not ownership: a place or template must exist before what stands on it. A section not listed runs after these. Rules, actions, audio, views and renames run before all of them (loadSteps)
17
+ const ORDER = ['level', 'vegetation', 'items', 'startItems', 'containers', 'pickups', 'npcs', 'dialogues', 'quests', 'triggers', 'grids', 'templates', 'props'];
18
+ const isEmpty = d => d == null || (typeof d === 'object' && Object.keys(d).length === 0);
18
19
  const each = (o, fn) => Object.entries(o || {}).forEach(([k, v]) => fn(k, v));
19
20
  const all = (o, fn) => Object.entries(o || {}).every(([k, n]) => fn(k, n));
20
21
 
@@ -25,9 +26,9 @@ const all = (o, fn) => Object.entries(o || {}).every(([k, n]) => fn(k, n));
25
26
  const inv = (e, word, ctx) => e.inventory?.of(ctx?.actor ?? e.ops.actor) ?? (() => { throw codedError('content-misuse', `content word { ${word} } needs the inventory module: add inventory() to engine.use(...), `
26
27
  + 'or track the thing with a flag / counter ({ setFlag } / { bump }) or a game condition word instead'); })();
27
28
 
28
- /** Execution part of the engine's built-in words (descriptions are in rules.js) */
29
+ /** Execution part of the engine's built-in words (descriptions are in rules.js). A run answers by returning a failure ({ ok: false, code, facts }); runWords hands it up */
29
30
  export const BUILTIN_TESTS = {
30
- can: (e, v) => e.ops.can(v[0], v[1] ?? {}).ok,
31
+ can: (e, v, raw, ctx) => e.ops.can(v[0], v[1] ?? {}, { actor: ctx?.actor }).ok,
31
32
  flag: (e, v) => !!e.vars.flag(v),
32
33
  notFlag: (e, v) => !e.vars.flag(v),
33
34
  has: (e, v, raw, ctx) => all(v, (id, n) => inv(e, 'has', ctx).has(id, n)),
@@ -35,11 +36,19 @@ export const BUILTIN_TESTS = {
35
36
  counter: (e, v) => all(v, (k, n) => e.vars.counter(k) >= n),
36
37
  };
37
38
  export const BUILTIN_RUNS = {
38
- op: (e, v) => { e.ops.run(v[0], v[1] ?? {}); }, setFlag: (e, v) => e.vars.setFlag(v),
39
- give: (e, v, raw, ctx) => each(v, (id, n) => inv(e, 'give', ctx).add(id, n)),
40
- take: (e, v, raw, ctx) => each(v, (id, n) => inv(e, 'take', ctx).remove(id, n)),
39
+ op: (e, v, raw, ctx) => e.ops.run(v[0], v[1] ?? {}, { actor: ctx?.actor }),
40
+ setFlag: (e, v) => e.vars.setFlag(v),
41
+ // add keeps what fits and calls that ok, so the rest is this word's to report; facts.left is exactly what { give } could still pay later
42
+ give(e, v, raw, ctx) {
43
+ const left = {};
44
+ each(v, (id, n) => { const r = inv(e, 'give', ctx).add(id, n), got = r.ok ? r.added : 0; if (got < n) left[id] = n - got; });
45
+ return Object.keys(left).length ? failure({ code: 'full', facts: { left } }) : undefined;
46
+ },
47
+ take(e, v, raw, ctx) {
48
+ const short = Object.entries(v).filter(([id, n]) => !inv(e, 'take', ctx).remove(id, n)).map(([id]) => id);
49
+ return short.length ? failure({ code: 'notEnough', facts: { short } }) : undefined;
50
+ },
41
51
  bump: (e, v) => e.vars.bump(v),
42
- startQuest: (e, v) => e.quests.start(v),
43
52
  toast: (e, v) => toast(e, v),
44
53
  particles: (e, v) => e.particles.emit(v.name, v.at, { count: v.count }),
45
54
  marker: (e, v, raw) => e.content._mark(markerId(raw), v, raw.label), // the same marker again replaces the old one
@@ -48,150 +57,118 @@ export const BUILTIN_RUNS = {
48
57
  const markerId = raw => raw.id ?? (typeof raw === 'string' ? raw : raw.place ?? `${raw.x},${raw.z}`);
49
58
 
50
59
  /**
51
- * Load one content pack. c is the merged object of content/index.js (or one pack of a list); api is engine.content; ids is the IdCheck shared by every pack of
52
- * this load call (ids.js); st is the content module's load state (shared across repeated load calls):
53
- * { triggers: merged trigger table, subs: listener handles, startOn: quest id -> listener handle, pending: set of model Promises being generated,
54
- * levelPlace(name) }
55
- * Order: vocabulary -> key actions -> vegetation -> items -> containers -> pickups -> NPCs -> dialogues -> quests -> trigger zones -> templates -> props.
56
- * Pickups, props and NPCs are initial world data: the save records only changes and removals, independent of load order (rules at the top of world/World.js).
60
+ * Load content packs as one transaction (core/base/sections.js): every pack is checked and prepared before any commits, and whatever fails after that takes every commit
61
+ * back, so a refused load changed nothing. packs are the merged objects of content/index.js; api is engine.content; ids is the IdCheck of this load call (ids.js); st is
62
+ * the content module's load state (shared across repeated load calls): { kinds, ops, sectionIds, refs, levelPlace(name), wait(promise) }; places are this load's new places;
63
+ * turn says it belongs to the state replacement running now (stateReplace.js). checkOps refuses op names nothing defines; a replay passes none, its pack was checked when it came.
64
+ * Returns the Promise of the transaction, or nothing when it ended on this tick.
65
+ * Order per pack: vocabulary -> key actions, audio, views (core services) -> renames -> the modules' sections in ORDER -> any other section -> game kinds. Packs commit in
66
+ * load order, so a later pack stands on an earlier one; with a level file to wait for the whole load commits after it, on the new level's markers. A load waits for the one
67
+ * before it (st.queue) and goes down with it: a level that failed leaves nothing to stand on. A load with its turn does neither: the load before it may be waiting for that very
68
+ * replacement to end, and what a load() brings in is part of the state it builds, not of the line outside. content's isReady waits for all of it.
69
+ * What a section's data means belongs to the module that owns it: replacing the quests module replaces the quests format.
70
+ * Pickups, props and NPCs are initial world data: the save records only changes and removals, independent of load order (rules at the top of world/persist.js).
57
71
  * Positions that use level markers (not in places) belong to the current level: pickup, prop and NPC data carry a zone (= current level name,
58
72
  * engine.world.zone),
59
73
  * a level change only tears down models and they are rebuilt on return, with taken / moved / removed state intact; trigger zones are not data and are removed
60
74
  * on level change (level.track).
61
75
  */
62
- export function loadContent(e, api, c, st, ids) {
76
+ export function loadContent(e, api, packs, st, ids, places = {}, turn, checkOps) {
63
77
  const { where } = api;
64
78
  const origin = (id, list, key) => { if (DEV) e.world?.setOrigin(id, { definedAt: srcOf(list, key) }); };
65
79
  const onLevel = (...ps) => ps.some(p => p && typeof p === 'object' ? st.levelPlace(p.place) : st.levelPlace(p));
66
80
  const bind = (h, ...ps) => { if (h && onLevel(...ps)) e.level?.track(h); return h; };
67
81
  const zoneOf = (...ps) => onLevel(...ps) ? e.world?.zone ?? null : null;
82
+ const sections = sectionsOf(e), kinds = { ...st.kinds };
83
+ const list = [{ s: {
84
+ undo: () => keepLoad(e, st),
85
+ // the first commit of the load, so a refusal leaves the rest uncommitted: a game kind's load has no undo. Not in validate: a load waiting for a file may meet an op defined meanwhile
86
+ commit() { Object.assign(st.places, places); for (const p of packs) collectOps(p, st.ops); checkOps?.(); },
87
+ } }];
88
+ for (const pack of packs) list.push(...loadSteps(e, api, pack, st), ...packSections(e, pack, st, sections, kinds));
89
+ // track: these listeners run content words, so they go with the content module
90
+ const inTurn = liveTurn(e, turn), after = inTurn ? null : st.queue, c = { engine: e, content: api, where, bind, zone: zoneOf, ids, origin, pickupId, track: st.track, after };
91
+ // a commit writes state, so it lands between replacements, never inside one: a pack that waited on a file through a load commits on the state that load left
92
+ const commits = fn => { const r = e.ops.allow(fn); if (r) whileRestoring(e, r); return r; }; // only a failure whose undo has to wait gives a result
93
+ const run = runSections(list, c, { after, around: fn => whenTurnFree(e, () => commits(fn), turn) });
94
+ if (!run || inTurn) return run;
95
+ const tail = st.queue = run.finally(() => { if (st.queue === tail) st.queue = null; });
96
+ return tail;
97
+ }
68
98
 
69
- each(c.rules?.conditions, (name, d) => api.condition(name, d));
70
- if (c.rules?.effects) throw codedError('content-misuse', NO_GAME_EFFECTS);
71
- // game kinds stay registered across loads, so a later content.load({ recipes }) without rules still finds them
72
- const bad = kindProblems(c.rules);
73
- if (bad.length) throw codedError('content-misuse', 'content/rules.js: ' + bad.join('; '));
74
- Object.assign(st.kinds, c.rules?.kinds);
75
- const known = contentFiles({ kinds: st.kinds });
76
- for (const k of Object.keys(c)) if (k !== 'name' && !known[k]) throw codedError('unknown-option', 'content.load: ' + unknownContent(k, { kinds: st.kinds }));
77
- collectOps(c, st.ops);
78
-
79
- if (c.renames) applyRenames(e, c.renames); // first: saved state under an old id must reach the new id before anything is placed under it
99
+ /** The undo of a whole load: the world, which several sections write, and the tables content itself fills */
100
+ function keepLoad(e, st) {
101
+ const world = e.world?.undoPoint();
102
+ const tables = [st.conds, st.ops, st.templates, st.templateFields, st.templateSrc].map(keepTable);
103
+ const { templateViews, templateSims } = st, was = { kinds: { ...st.kinds }, places: { ...st.places }, sectionIds: structuredClone(st.sectionIds), refs: st.refs.length };
104
+ const views = new Set(templateViews.keys()), sims = new Set(templateSims.keys());
105
+ return () => {
106
+ world?.();
107
+ for (const fn of tables) fn();
108
+ st.kinds = was.kinds; st.places = was.places; st.sectionIds = was.sectionIds; st.refs.length = was.refs;
109
+ for (const [map, had] of [[templateViews, views], [templateSims, sims]]) for (const [name, h] of map) if (!had.has(name)) { h.remove(); map.delete(name); }
110
+ };
111
+ }
80
112
 
113
+ /** What a pack registers with the core services and the vocabulary its sections read, as steps of the transaction */
114
+ function loadSteps(e, api, c, st) {
115
+ const steps = [];
116
+ // game kinds stay registered across loads, so a later content.load({ recipes }) without rules still finds them
117
+ if (c.rules) steps.push({ commit() { each(c.rules.conditions, (name, d) => api.condition(name, d)); Object.assign(st.kinds, c.rules.kinds); } });
81
118
  // a pack's actions are the game's own (owner 'game'): loading the pack again replaces them, it is not a second binder
82
- each(c.actions, (name, a) => e.input.action(name, { label: a.label, keys: a.keys, ...(a.context ? { context: a.context } : {}) }));
83
-
84
- // audio: sounds / footsteps by name into engine.audio.config, rules to ambience() / music() (core/audioRules.js). A pack loaded again
119
+ if (c.actions) steps.push({ undo: () => e.input.keepActions(Object.keys(c.actions)), commit: () => each(c.actions, (name, a) => e.input.action(name, { label: a.label, keys: a.keys, ...(a.context ? { context: a.context } : {}) })) });
120
+ // audio: sounds / footsteps by name into engine.audio.config, rules to ambience() / music() (core/audio/audioRules.js). A pack loaded again
85
121
  // replaces its own rules (hot reload): a named pack by its name, an unnamed one by the data object itself, so loading the same object
86
122
  // twice never stacks its rules (a fresh key per load did); two different unnamed objects both keep theirs
87
- if (c.audio) e.audio.contentPack(c.name ? 'pack:' + c.name : c, c.name ? `pack "${c.name}"` : 'pack (no name)', c.audio);
88
-
89
- // views: named fixed camera views (core/Views.js); defining a name again replaces it, so a hot reload just works
90
- each(c.views, (name, v) => e.views.define(name, v));
91
-
92
- // vegetation: model names resolve through vegetationModel (models.js, the same resolver vegetation.define uses for a name); register all
93
- // kinds at the same moment once all models are ready
94
- // (each registration rebuilds terrain chunks; registering one by one would rebuild several times at start). content's isReady waits for them
95
- const veg = [];
96
- each(c.vegetation, (name, { model: m, lod, ...rest }) => {
97
- veg.push(Promise.all([vegetationModel(e, m), lod && vegetationModel(e, lod)])
98
- .then(([main, low]) => [name, { ...rest, ...main, ...(low && { lodGeometry: low.model ?? low.geometry }) }])
99
- .catch(err => { reportError(e, err, `content vegetation ${name}: model generation`, { soft: true }); return null; })); // one failure does not affect the others
100
- });
101
- if (veg.length) st.wait(Promise.all(veg).then(list => { for (const v of list) if (v) e.vegetation.define(v[0], v[1]); }));
102
-
103
- each(c.items, (id, d) => e.inventory.define(id, d));
104
- each(c.startItems, (id, n) => e.inventory.add(id, n, { silent: true }));
105
- // containers: starting goods are placed only the first time (if the save already has the container, the save wins; no refill after it was emptied and
106
- // reloaded)
107
- each(c.containers, (id, d) => { ids.claim(id, `containers.${id}`); e.inventory.container(id, { capacity: d.capacity, items: d.items }); });
108
- // pickups: data goes into world (kind 'pickup'). id: the written id if given, else `pickup:<item>:<index in the pickups array>` (stable for the same content;
109
- // when inserting in the middle, give existing entries an id)
110
- if (c.pickups?.length && !e.pickups) throw codedError('module-needs', 'content pickups lie on the ground as pickups: add pickups() to engine.use(...) after world() (and inventory() for item pickups)');
111
- c.pickups?.forEach((p, i) => {
112
- const id = pickupId(p, i);
113
- if (p.id != null) ids.claim(id, `pickups[${i}] (${p.item})`); else ids.unnamed(id, `pickups[${i}] (${p.item})`); // taken / respawning is state
114
- e.pickups.spawn(where(p), { give: p.item, id, count: p.count, data: p.data, radius: p.radius, auto: p.auto, respawnSeconds: p.respawn, initial: true, zone: zoneOf(p) });
115
- origin(id, c.pickups, i);
116
- });
117
-
118
- const hpd = e.calendar?.hoursPerDay ?? 24;
119
- each(c.npcs, (id, n) => { // the key in content is the NPC's stable id (used by saves and quest targets)
120
- const plan = n.schedule ?? [];
121
- ids.claim(id, `npcs.${id}`);
122
- // every documented npcs.add option can be written in content (arriveDistance, interact, speed...); the same option table checks the spelling.
123
- // The content form owns start / schedule (clock strings, places) and the id (the key), so those are translated below and not passed as written
124
- readParams(`content npcs.${id}`, keysSchema([...e.npcs.optionKeys.filter(k => !['id', 'position', 'zone', 'initial'].includes(k)), 'start']), n);
125
- const { start: _s, schedule: _p, ...rest } = n;
126
- e.npcs.add({ ...rest, id, schedule: plan.map(s => ({ at: parseClock(s.at, hpd), position: where(s) })), position: where(n.start || plan[0]), zone: zoneOf(n.start, ...plan), initial: true });
127
- origin(id, c.npcs, id);
128
- });
123
+ const key = c.name ? 'pack:' + c.name : c;
124
+ if (c.audio) steps.push({ undo: () => e.audio.keepPack(key), commit: () => e.audio.contentPack(key, c.name ? `pack "${c.name}"` : 'pack (no name)', c.audio) });
125
+ // views: named fixed camera views (core/scene/Views.js); defining a name again replaces it, so a hot reload just works
126
+ if (c.views) steps.push({ undo: () => keepTable(e.views.map), commit: () => each(c.views, (name, v) => e.views.define(name, v)) });
127
+ // saved state under an old id must reach the new id before anything is placed under it. The world goes back with keepLoad
128
+ let goods = null;
129
+ if (c.renames) steps.push({ undo: () => () => goods?.(), commit() { goods = applyRenames(e, c.renames); } });
130
+ return steps.map(s => ({ s }));
131
+ }
129
132
 
130
- // dialogue: a line can be several variants [{ if: condition, text }, ..., { text }]; the first whose condition holds is used.
131
- // When none holds (no unconditional last variant) the line is empty and a warning names it: throwing inside the dialogue's op would leave
132
- // the conversation stuck on that node.
133
- const variants = (where, list) => () => {
134
- const hit = list.find(v => api.test(v.if));
135
- if (!hit) warnOnce(coded('content-misuse', `content ${where}: no variant's "if" holds and there is no variant without "if", so the line is empty. ` +
136
- 'End the list with a plain { text } as the fallback'), where);
137
- return hit?.text ?? '';
133
+ /** The sections of one pack, in ORDER. Every check that needs no commit runs here, before anything of the load commits. Game kinds are sections too, after the modules' */
134
+ function packSections(e, pack, st, modules, kinds) {
135
+ if (pack.rules?.effects) throw codedError('content-misuse', NO_GAME_EFFECTS);
136
+ const bad = kindProblems(pack.rules);
137
+ if (bad.length) throw codedError('content-misuse', 'content/rules.js: ' + bad.join('; '));
138
+ Object.assign(kinds, pack.rules?.kinds);
139
+ const known = { ...contentFiles({ kinds }), ...Object.fromEntries(modules) };
140
+ for (const k of Object.keys(pack)) if (k !== 'name' && !known[k]) throw codedError('unknown-option', 'content.load: ' + unknownContent(k, { kinds }));
141
+ const sections = new Map(modules);
142
+ for (const [name, k] of Object.entries(kinds)) {
143
+ if (sections.has(name)) throw codedError('content-misuse', `content kind "${name}" is also a section of module ${sections.get(name).owner}: keep one`);
144
+ sections.set(name, { owner: 'game', commit: (data, c) => k.load?.(e, data, c.content) });
145
+ }
146
+ const rank = n => { const i = ORDER.indexOf(n); return i < 0 ? ORDER.length : i; };
147
+ for (const name of Object.keys(pack)) {
148
+ const home = sectionHomes[name];
149
+ if (home && !sections.has(name) && !isEmpty(pack[name])) throw codedError('module-needs', `content ${name}: no installed module reads this section. Add ${home} to engine.use(...), or a module with content: { ${name}: { commit } }`);
150
+ }
151
+ const done = (name, s) => r => {
152
+ if (typeof r?.then === 'function') st.wait(r);
153
+ st.gaveWay.get(pack)?.delete(name);
154
+ note(st, name, s, pack[name]);
138
155
  };
139
- each(c.dialogues, (id, d) => {
140
- const nodes = {};
141
- each(d.nodes, (nid, n) => {
142
- nodes[nid] = {
143
- ...n, speaker: n.speaker ?? d.speaker,
144
- text: Array.isArray(n.text) ? variants(`dialogues.${id}.nodes.${nid}.text`, n.text) : n.text,
145
- do: n.do && (() => api.run(n.do)),
146
- choices: n.choices?.map(ch => ({ ...ch, if: ch.if && (() => api.test(ch.if)), do: ch.do && (() => api.run(ch.do)) })),
147
- };
148
- });
149
- e.dialogue.define(id, nodes);
150
- });
156
+ const gaveWay = name => () => { if (!st.gaveWay.has(pack)) st.gaveWay.set(pack, new Set()); st.gaveWay.get(pack).add(name); };
157
+ return [...sections].filter(([name]) => pack[name] != null).sort(([a], [b]) => rank(a) - rank(b)).map(([name, s]) => ({ s, data: pack[name], done: done(name, s), gaveWay: gaveWay(name) }));
158
+ }
151
159
 
152
- // quests: a step target can be a place, { place, x, z }, { x, z }, { npc: 'id' } (follows the NPC) or { nearest: itemId } (the nearest pickup)
153
- // { npc } reads the position by id each frame: follow the model if there is one, else (far away, other level) use the data position
154
- const target = t => t == null ? undefined : t.npc ? () => e.npcs?.get(t.npc)?.position : t.nearest ? t : where(typeof t === 'string' ? { place: t } : t);
155
- // a step may be parallel goals { text?, all: [{ text, done, target, optional }] }; fail / onFail are a condition and an effect like done / reward
156
- const goal = s => ({ ...(s.id != null && { id: s.id }), text: s.text, done: () => api.test(s.done), target: target(s.target), ...(s.optional && { optional: true }) }); // id: stable for saves
157
- each(c.quests, (id, q) => {
158
- e.quests.define(id, {
159
- title: q.title, desc: q.desc,
160
- steps: q.steps.map(s => s.all ? { ...(s.id != null && { id: s.id }), text: s.text, all: s.all.map(goal) } : goal(s)),
161
- reward: q.reward && (() => api.run(q.reward)),
162
- ...(q.fail && { fail: () => api.test(q.fail) }), ...(q.onFail && { onFail: () => api.run(q.onFail) }),
163
- });
164
- st.startOn.get(id)?.remove(); // loading the same quest again: replace the old listener instead of attaching twice
165
- if (q.startOn) st.startOn.set(id, e.events.on(q.startOn, () => e.quests.start(id)));
166
- });
160
+ /** What the reference check (checkRefs) needs from a section just loaded */
161
+ function note(st, name, s, data) {
162
+ const ids = st.sectionIds[name] ??= new Set();
163
+ for (const k of Array.isArray(data) ? data.map(x => x?.id) : Object.keys(data)) if (k != null) ids.add(k);
164
+ st.refs.push(...s.references?.(data) ?? []);
165
+ }
167
166
 
168
- // trigger zones: fromLevel = the level's trigger_<tag> marker; otherwise placed by position. Enter/exit effects look up the merged table, and the listener is
169
- // attached only once
170
- if (c.triggers) {
171
- Object.assign(st.triggers, c.triggers);
172
- if (Object.values(c.triggers).some(t => t.fromLevel)) e.triggers.fromMarkers();
173
- each(c.triggers, (tag, t) => {
174
- if (!t.fromLevel) bind(e.triggers.add({ ...t, tag, position: where(t.position), onEnter: null, onExit: null }), t.position);
175
- });
176
- st.subs ??= [
177
- // the effects act for whoever crossed the zone (a { give } lands in that actor's bag); a zone emptied by removal has no id: engine.actor
178
- st.track(e.events.on('trigger:enter', ({ tag, id }) => api.run(st.triggers[tag]?.onEnter, { actor: id ?? e.actor }))),
179
- st.track(e.events.on('trigger:exit', ({ tag, id }) => api.run(st.triggers[tag]?.onExit, { actor: id ?? e.actor }))),
180
- ];
167
+ /** Ids a section names in a section that was loaded and does not have them. Only when that section was loaded: a game may define its items in code */
168
+ export function checkRefs(st) {
169
+ for (const { section, id, at } of st.refs.splice(0)) {
170
+ if (st.sectionIds[section] && !st.sectionIds[section].has(id)) warnOnce(coded('content-misuse', `content ${at}: ${section} has no "${id}"`), `${at}:${id}`);
181
171
  }
182
-
183
- // grids (layout rules, not saved) before props: a props entry with grid places an item on one; a repeated load keeps the grid that exists
184
- each(c.grids, (name, g) => {
185
- if (!e.grids) throw codedError('content-misuse', `content grids: install grids() to use grid "${name}"`);
186
- if (!e.grids.get(name)) e.grids.add(name, g);
187
- });
188
- // templates before props: a props entry with template places an instance of it
189
- if (c.templates) { needWorld(e); defineTemplates(e, api, st, c.templates); }
190
- // props: data goes into world (kind 'prop'); models and collision are built nearby and torn down when far by present in props.js
191
- if (c.props?.length) addProps(e, api, c.props, st, zoneOf, ids);
192
-
193
- // game kinds last: their data may name the items, NPCs and places loaded above
194
- each(st.kinds, (name, k) => { if (c[name] !== undefined) k.load(e, c[name], api); });
195
172
  }
196
173
 
197
174
  /** Op names that content data refers to ({ op: [...] } / { can: [...] } anywhere), checked against engine.ops once the game is ready */
@@ -0,0 +1,25 @@
1
+ // What the marker / clearMarker effects show: playthrough state, kept in the 'content' save part, so a load shows the save's markers and a new game none of the old
2
+ // ones. st.marks holds id -> [position, label]; api.markers holds the hud markers on screen now.
3
+ import { refuseSave } from '../../core/base/saveValues.js';
4
+
5
+ /** content._mark: set (v = position) or clear (v = null) marker id */
6
+ export function setMark(e, api, st, id, v, label) {
7
+ api.markers.get(id)?.remove(); api.markers.delete(id); st.marks.delete(id);
8
+ if (!v) return;
9
+ st.marks.set(id, [v, label ?? null]);
10
+ const m = e.hud?.marker(v, { label });
11
+ if (m) api.markers.set(id, m);
12
+ }
13
+
14
+ /** The 'content' save part */
15
+ export function marksPart(api, st) {
16
+ return {
17
+ save: () => ({ marks: [...st.marks].map(([id, [v, label]]) => [id, v, label]) }),
18
+ load: d => {
19
+ const marks = d?.marks ?? [];
20
+ if (!Array.isArray(marks) || !marks.every(m => Array.isArray(m) && typeof m[0] === 'string')) refuseSave('content', 'marks', 'must be a list of [id, value, label]', marks);
21
+ for (const id of [...st.marks.keys()]) api._mark(id, null);
22
+ for (const [id, v, label] of marks) api._mark(id, v, label ?? undefined);
23
+ },
24
+ };
25
+ }
@@ -1,8 +1,12 @@
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 * as THREE from 'three';
4
+ import { codedError } from '../../core/base/errorHints.js';
5
+ import { protoOf } from '../../core/assets/namedModel.js';
6
+ import { wrapLod } from '../../core/assets/assetLod.js';
4
7
  import { Vector3 } from 'three';
5
- import { list } from './rules.js';
8
+ import { clone as skeletonClone } from 'three/addons/utils/SkeletonUtils.js';
9
+ import { list } from '../../core/base/util.js';
6
10
 
7
11
  const BASE_BAND = 0.2; // the share of the model's height above the ground that counts as its base
8
12
 
@@ -51,35 +55,68 @@ export function baseOf(proto) {
51
55
  * mul: a template stage's scale, multiplied onto the record's own scale (the record keeps only its authored scale). @internal
52
56
  */
53
57
  export function settle(e, rec, o, solid, mul = 1) {
54
- const { x, z } = rec.position, rot = rec.rot ?? 0, scale = (rec.scale ?? 1) * mul, ud = o.userData;
55
- ud.fit = fitKey(rec, mul);
56
- rec.position.y = e.surface(x, z, rec.floor) + (rec.offsetY ?? 0);
57
- o.position.y = rec.position.y; o.rotation.y = rot; o.scale.setScalar(scale);
58
+ const { x, z } = rec.position, rot = rotOf(rec), sv = scaleOf(rec, mul), ud = o.userData;
59
+ ud.fit = fitOf(rec, mul); ud.shape = shapeOf(rec, mul); ud.holder = holderOf(e, rec);
60
+ const tilted = isTilted(rec);
61
+ if (tilted && solid.collide && !e.collider3d) throw tiltError(rec);
62
+ // ground: false keeps the written height (a floating or hung model); a body's height is the solver's (templates.js addBody). The height comes from the ground, not from play,
63
+ // so it stays out of the save (world.rest), and a ground ray's rounding (1e-16 off a turned level) is no new height: a load would write a change for it
64
+ const y = e.surface(x, z, rec.floor) + (rec.offsetY ?? 0);
65
+ if (rec.ground !== false && !solid.body && Math.abs(rec.position.y - y) > 1e-6 && !e.world.rest(rec.id, { x, y, z })) rec.position.y = y;
66
+ o.position.y = rec.position.y; o.rotation.set(rot[0], rot[1], rot[2]); o.scale.set(sv[0], sv[1], sv[2]);
58
67
  ud.unstatic?.remove(); ud.unstatic = null;
59
68
  for (const h of ud.colliders.splice(0)) h.remove();
60
69
  // a solid prop blocks the camera with its whole mesh, not only its footprint collider: crowns and eaves stand outside the footprint, and no game code should have to say so
61
70
  const blocks = !!solid.collide && solid.collide.occluder !== false && solid.occluder !== false;
62
71
  if (solid.static !== false && e.rays) { o.updateMatrixWorld(true); ud.unstatic = e.rays.addStatic(o, { occluder: blocks }); }
63
- if (!solid.collide || !e.collision) return;
72
+ if (!solid.collide) return;
64
73
  const { collide } = solid, set = typeof collide === 'object' ? collide : null, base = set || collide === 'circle' ? baseOf(ud.proto) : null;
65
- const size = ud.proto.size.clone().multiplyScalar(scale), c = base ?? ud.proto.center, ox = c.x * scale, oz = c.z * scale;
66
- const cx = x + ox * Math.cos(rot) + oz * Math.sin(rot), cz = z - ox * Math.sin(rot) + oz * Math.cos(rot);
74
+ const size = ud.proto.size.clone().multiply(new THREE.Vector3(...sv));
75
+ if (tilted) { // a turned-over solid is not a footprint on the ground: the three-axis provider holds it (o.quaternion carries the same turn the model has)
76
+ const mid = ud.proto.center.clone().multiply(new THREE.Vector3(...sv)).applyQuaternion(o.quaternion).add(o.position);
77
+ ud.colliders.push(e.collider3d.addSolid(base
78
+ ? { position: [mid.x, mid.y, mid.z], radius: (set?.circle ?? base.width / 2) * Math.max(sv[0], sv[2]) }
79
+ : { position: [mid.x, mid.y, mid.z], size: [size.x, size.y, size.z], rotation: rot }));
80
+ return;
81
+ }
82
+ if (!e.collision) return;
83
+ const c = base ?? ud.proto.center, ox = c.x * sv[0], oz = c.z * sv[2];
84
+ const cx = x + ox * Math.cos(rot[1]) + oz * Math.sin(rot[1]), cz = z - ox * Math.sin(rot[1]) + oz * Math.cos(rot[1]);
67
85
  ud.colliders.push(base
68
- ? e.collision.addCircle({ x: cx, z: cz }, { radius: (set?.circle ?? base.width / 2) * scale, height: size.y, occluder: blocks })
69
- : e.collision.addBox({ x: cx, z: cz }, { halfWidth: size.x / 2, halfDepth: size.z / 2, rotation: rot, height: size.y, occluder: blocks }));
86
+ ? e.collision.addCircle({ x: cx, z: cz }, { radius: (set?.circle ?? base.width / 2) * Math.max(sv[0], sv[2]), height: size.y, occluder: blocks })
87
+ : e.collision.addBox({ x: cx, z: cz }, { halfWidth: size.x / 2, halfDepth: size.z / 2, rotation: rot[1], height: size.y, occluder: blocks }));
70
88
  }
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}`;
89
+ /** Is the model still as settle aligned it, with its collider in the holder installed now (a new one starts empty; with none there is nothing to do yet)? update asks every frame for every built prop, because world.move sends no event @internal */
90
+ /** rot / scale of a record as [x, y, z]: a number is the facing about Y and a uniform scale, as it always was; an array sets each axis (the model's Euler order XYZ) */
91
+ export const rotOf = rec => Array.isArray(rec.rot) ? rec.rot : [0, rec.rot ?? 0, 0];
92
+ export const scaleOf = (rec, mul = 1) => (Array.isArray(rec.scale) ? rec.scale : [rec.scale ?? 1, rec.scale ?? 1, rec.scale ?? 1]).map(v => v * mul);
93
+ const fitOf = (rec, mul) => JSON.stringify([rec.position.x, rec.position.z, rec.ground === false ? rec.position.y : null, rotOf(rec), scaleOf(rec, mul)]);
94
+ export const fits = (e, o, rec, mul = 1) => { const h = holderOf(e, rec); return (!h || o.userData.holder === h) && o.userData.fit === fitOf(rec, mul); };
95
+ const shapeOf = (rec, mul) => JSON.stringify([rotOf(rec), scaleOf(rec, mul)]);
96
+ /** The turn and size it was built with still hold (a body moves itself, so its place says nothing) @internal */
97
+ export const fitsShape = (o, rec, mul = 1) => o.userData.shape === shapeOf(rec, mul);
98
+ /** A tilted solid needs the three-axis provider (collider3d); the same error at load (props.js) and at build, so a mistake shows once, early @internal */
99
+ export const tiltError = rec => codedError('content-misuse', `prop ${JSON.stringify(rec.id ?? rec.model)}: collide on a model turned about x or z (rot ${JSON.stringify(rec.rot)}) needs a collider3d provider: install rigid() (or your own collider3d), or set collide: false`);
100
+ export const isTilted = rec => { const r = rotOf(rec); return !!(r[0] || r[2]); };
101
+ const holderOf = (e, rec) => isTilted(rec) ? e.collider3d : e.collision;
73
102
 
74
- /** Clone the shared prototype of a model for one record and align it (props and template instances) @internal */
103
+ /** Clone the shared prototype of a model for one record and align it (props and template instances). skeletonClone: a skinned part of a plain clone keeps the prototype's bones and draws where they stand @internal */
75
104
  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];
105
+ const proto = await protoOf(e, api, model), name = list(model)[0], lod = rec.lod ?? solid.lod;
106
+ // 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
107
+ const o = lod ? await wrapLod(e.assets, name, skeletonClone(proto.obj), { distances: Array.isArray(lod) ? lod : undefined, scale: Math.max(...scaleOf(rec, mul)) }) : skeletonClone(proto.obj);
77
108
  o.name ||= name; o.userData.name ??= name;
78
109
  o.userData.proto = proto; o.userData.colliders = [];
110
+ o.userData.refit = r => { if (!solid.body && !fits(e, o, r, mul)) settle(e, r, o, solid, mul); }; // a body places itself; a stale solid or mul is put right by the presenter's next update
111
+ // a file model only: a generator's prototype is pinned for good (Assets.cached), so nothing could free it. The built prop counts in describe().assets until it is torn down
112
+ if (!e.assets.builder(name)) o.userData.lease = await e.assets.lease(name);
79
113
  if (rec.batch === false) o.userData.batch = false; // opt out of engine.batching for this record
80
114
  o.position.set(rec.position.x, 0, rec.position.z); // world puts the model on the record after build; height and collision are aligned here
81
115
  settle(e, rec, o, solid, mul);
82
116
  return o;
83
117
  }
118
+ /** ctx.feeds: every built solid goes into the holder installed now, so the line after use() reads it. The presenters' update asks the same every frame, for what moved @internal */
119
+ export const refit = e => { for (const rec of e.world?.query({}) ?? []) e.world.view(rec.id)?.userData.refit?.(rec); };
120
+
84
121
  /** Tear down only: geometry and material belong to the shared prototype, the next build clones it again @internal */
85
- export function unbuildModel(e, o) { o.userData.unstatic?.remove(); for (const h of o.userData.colliders) h.remove(); e.detach(o); }
122
+ export function unbuildModel(e, o) { o.userData.lease?.remove(); o.userData.unstatic?.remove(); for (const h of o.userData.colliders) h.remove(); o.removeFromParent(); }
@@ -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',
@@ -47,7 +47,8 @@ export function packsOf(data) {
47
47
  packs.forEach((p, i) => {
48
48
  if (!isPlainObject(p)) throw codedError('content-pack', fmt(STRINGS.notPack, { at: i + 1, got: Array.isArray(p) ? 'an array' : typeof p }));
49
49
  for (const [key, v] of Object.entries(p)) {
50
- if (key === 'rules') { claim('rules.conditions', v?.conditions, i); claim('rules.kinds', v?.kinds, i); }
50
+ if (key === 'level' && (typeof v === 'string' || v?.isObject3D)) claim('level', { level: 1 }, i); // a load has one transaction: the second level would drop the first with all that stands on it
51
+ else if (key === 'rules') { claim('rules.conditions', v?.conditions, i); claim('rules.kinds', v?.kinds, i); }
51
52
  // audio: named tables are ids (a sound in two packs is an error), rule lists concatenate
52
53
  else if (key === 'audio') { claim('audio.sounds', v?.sounds, i); claim('audio.footsteps', v?.footsteps, i); claim('audio.music.tracks', v?.music?.tracks, i); }
53
54
  else if (key !== 'name' && !NOT_KEYED.has(key) && isPlainObject(v)) claim(key, v, i);
@@ -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,36 @@
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
+ import { placeProblem } from './rules.js';
6
+
7
+ /** content.load: the packs' places, then the places option on top, checked. A text entry in a place file waits for the option */
8
+ export function placesOf(packs, given) {
9
+ const pl = {};
10
+ for (const p of packs) for (const [name, at] of Object.entries(p.places ?? {})) if (at && typeof at === 'object') pl[name] = at;
11
+ Object.assign(pl, given);
12
+ for (const [name, p] of Object.entries(pl)) { const bad = placeProblem(p); if (bad) throw codedError('content-place', `Place "${name}": ${bad}`); }
13
+ return pl;
14
+ }
15
+
16
+ /** content.place */
17
+ export function placeOf(e, places, name) {
18
+ const p = places[name] ?? e.level?.marker(name)?.position;
19
+ return p ? { x: p.x, z: p.z, ...(p.y !== undefined && { y: p.y }), ...(p.rot !== undefined && { rot: p.rot }) } : null;
20
+ }
21
+
22
+ /** content.offset */
23
+ export function offsetFrom(api, place, x, z) {
24
+ 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);
25
+ return { x: dx * c - dz * s, z: dx * s + dz * c };
26
+ }
27
+
28
+ /** content.where */
29
+ export function whereOf(e, api, p) {
30
+ const base = p.place ? api.place(p.place) : null;
31
+ 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`);
32
+ const ox = p.x ?? 0, oz = p.z ?? 0, c = Math.cos(base?.rot ?? 0), s = Math.sin(base?.rot ?? 0);
33
+ const x = (base?.x ?? 0) + ox * c + oz * s, z = (base?.z ?? 0) - ox * s + oz * c, floor = p.floor ?? base?.y;
34
+ if (floor === undefined && p.y === undefined) return { x, z };
35
+ return { x, y: placeY(e, `content.where(${JSON.stringify(p.place ?? { x: p.x, z: p.z })})`, x, z, floor) + (p.y ?? 0), z };
36
+ }