threedog 0.2.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (593) hide show
  1. package/CHANGELOG.md +290 -0
  2. package/README.md +9 -8
  3. package/core/Animator.js +15 -12
  4. package/core/Assets.js +71 -16
  5. package/core/Audio.js +45 -38
  6. package/core/Baked.js +32 -8
  7. package/core/Batching.js +102 -15
  8. package/core/Budget.js +39 -18
  9. package/core/Clock.js +40 -80
  10. package/core/DebugOverrides.js +45 -10
  11. package/core/Describe.js +104 -43
  12. package/core/Engine.js +183 -59
  13. package/core/Events.js +4 -1
  14. package/core/I18n.js +25 -13
  15. package/core/Input.js +168 -79
  16. package/core/Inspect.js +2 -2
  17. package/core/InspectMaterials.js +85 -0
  18. package/core/InspectPerf.js +61 -0
  19. package/core/InspectScene.js +13 -2
  20. package/core/Loading.js +2 -1
  21. package/core/Ops.js +50 -9
  22. package/core/Random.js +9 -2
  23. package/core/Rays.js +5 -5
  24. package/core/SaveStore.js +41 -9
  25. package/core/Saves.js +71 -15
  26. package/core/Stream.js +14 -10
  27. package/core/Threads.js +26 -7
  28. package/core/UrlState.js +25 -9
  29. package/core/Views.js +9 -6
  30. package/core/actor.js +1 -1
  31. package/core/adaptive.js +93 -0
  32. package/core/assetEntry.js +22 -5
  33. package/core/assetHot.js +176 -0
  34. package/core/assetLoad.js +38 -11
  35. package/core/assetManifest.js +48 -9
  36. package/core/assetReport.js +1 -1
  37. package/core/audioRules.js +13 -11
  38. package/core/audioVoice.js +69 -42
  39. package/core/canvasBox.js +1 -2
  40. package/core/catalog.js +5 -2
  41. package/core/cells.js +62 -0
  42. package/core/checks.js +10 -8
  43. package/core/chunkStream.js +87 -0
  44. package/core/control.js +149 -0
  45. package/core/copies.js +32 -0
  46. package/core/dayTime.js +12 -6
  47. package/core/debugView.js +82 -15
  48. package/core/describeRender.js +37 -17
  49. package/core/describeText.js +41 -21
  50. package/core/engineCamera.js +32 -0
  51. package/core/errorCodes.js +438 -19
  52. package/core/errorHints.js +37 -141
  53. package/core/errors.js +31 -8
  54. package/core/events.generated.js +12 -7
  55. package/core/gameLights.js +62 -0
  56. package/core/grayMap.js +20 -0
  57. package/core/grid.js +14 -13
  58. package/core/gridLoad.js +2 -1
  59. package/core/ground.js +6 -4
  60. package/core/headlessLoad.js +55 -0
  61. package/core/holds.js +78 -50
  62. package/core/inputContext.js +11 -7
  63. package/core/inputDefaults.js +24 -21
  64. package/core/inputPad.js +1 -1
  65. package/core/inputPointer.js +1 -1
  66. package/core/inputTouch.js +2 -2
  67. package/core/lifecycle.js +48 -12
  68. package/core/lightWatch.js +6 -4
  69. package/core/look/coreParts.js +137 -30
  70. package/core/look/part.js +175 -95
  71. package/core/look/points.js +255 -0
  72. package/core/look/report.js +34 -17
  73. package/core/look/shadowPart.js +63 -0
  74. package/core/look/state.js +45 -0
  75. package/core/look/write.js +12 -28
  76. package/core/loop.js +100 -41
  77. package/core/math.js +11 -3
  78. package/core/moduleSlots.js +75 -0
  79. package/core/moduleTypes.js +73 -0
  80. package/core/modules.js +145 -27
  81. package/core/movement.js +2 -2
  82. package/core/namedModel.js +70 -0
  83. package/core/opsCheck.js +3 -3
  84. package/core/opsFail.js +15 -6
  85. package/core/opsGuard.js +4 -4
  86. package/core/opsRun.js +4 -3
  87. package/core/owned.js +168 -0
  88. package/core/page.js +2 -1
  89. package/core/params.js +30 -8
  90. package/core/plugins.js +277 -0
  91. package/core/saveApply.js +99 -17
  92. package/core/saveFiles.js +8 -6
  93. package/core/saveValues.js +46 -0
  94. package/core/saveVersions.js +20 -3
  95. package/core/scatter.js +48 -19
  96. package/core/sceneDelta.js +203 -0
  97. package/core/sceneMethods.js +35 -30
  98. package/core/screenToGround.js +1 -1
  99. package/core/services.js +27 -11
  100. package/core/session.js +28 -25
  101. package/core/shaderCost.js +78 -0
  102. package/core/shadowTypes.js +2 -1
  103. package/core/sharedPoint.js +317 -0
  104. package/core/skip.js +36 -28
  105. package/core/stackFrames.js +34 -0
  106. package/core/stacks.js +166 -0
  107. package/core/startup.js +153 -11
  108. package/core/streamSources.js +0 -11
  109. package/core/styleParts.js +63 -47
  110. package/core/targeting.js +1 -1
  111. package/core/textureBytes.js +20 -0
  112. package/core/thingExplain.js +2 -2
  113. package/core/thingOps.js +29 -6
  114. package/core/things.js +21 -11
  115. package/core/threadPure.js +7 -3
  116. package/core/threePatches.js +47 -0
  117. package/core/tier.js +21 -10
  118. package/core/time.js +236 -0
  119. package/core/uiClock.js +25 -0
  120. package/core/util.js +7 -1
  121. package/core/validate.js +65 -86
  122. package/core/wrap.js +106 -0
  123. package/docs/AI.md +87 -100
  124. package/docs/API.md +32 -28
  125. package/docs/CODEMAP.md +220 -147
  126. package/docs/COMMANDS.md +56 -35
  127. package/docs/CONVENTIONS.md +90 -28
  128. package/docs/MIGRATING-0.3.md +248 -0
  129. package/docs/MIGRATING-0.4.md +228 -0
  130. package/docs/MIGRATING-0.5.md +68 -0
  131. package/docs/PERF.md +35 -7
  132. package/docs/THREE.md +79 -27
  133. package/docs/api/ambience.md +0 -1
  134. package/docs/api/assets.md +11 -9
  135. package/docs/api/audio.md +10 -14
  136. package/docs/api/calendar.md +41 -0
  137. package/docs/api/cameraRig.md +16 -5
  138. package/docs/api/characters.md +38 -23
  139. package/docs/api/clock.md +6 -5
  140. package/docs/api/collision.md +9 -6
  141. package/docs/api/content.md +6 -4
  142. package/docs/api/dialogue.md +9 -9
  143. package/docs/api/engine.md +63 -60
  144. package/docs/api/events.md +19 -14
  145. package/docs/api/grids.md +3 -3
  146. package/docs/api/ground.md +1 -1
  147. package/docs/api/hud.md +2 -2
  148. package/docs/api/i18n.md +1 -1
  149. package/docs/api/input.md +11 -6
  150. package/docs/api/interactions.md +7 -5
  151. package/docs/api/inventory.md +17 -16
  152. package/docs/api/level.md +0 -1
  153. package/docs/api/lightPool.md +3 -1
  154. package/docs/api/music.md +1 -1
  155. package/docs/api/nav.md +3 -0
  156. package/docs/api/openWorld.md +2 -1
  157. package/docs/api/particles.md +2 -2
  158. package/docs/api/photo.md +0 -2
  159. package/docs/api/pickups.md +15 -0
  160. package/docs/api/post.md +5 -4
  161. package/docs/api/quests.md +2 -3
  162. package/docs/api/rigid.md +16 -14
  163. package/docs/api/saves.md +6 -4
  164. package/docs/api/settings.md +2 -3
  165. package/docs/api/sky.md +11 -44
  166. package/docs/api/stream.md +1 -1
  167. package/docs/api/style.md +28 -26
  168. package/docs/api/terrain.md +9 -6
  169. package/docs/api/terrainLook.md +10 -0
  170. package/docs/api/timeline.md +3 -4
  171. package/docs/api/tools.md +29 -13
  172. package/docs/api/triggers.md +5 -10
  173. package/docs/api/vegetation.md +11 -8
  174. package/docs/api/vegetationLook.md +10 -0
  175. package/docs/api/water.md +4 -20
  176. package/docs/api/weather.md +5 -15
  177. package/docs/api/weatherLook.md +10 -0
  178. package/docs/api/world.md +2 -1
  179. package/docs/recipes/01-new-game.md +48 -34
  180. package/docs/recipes/02-npc.md +24 -7
  181. package/docs/recipes/03-items-pickups.md +35 -21
  182. package/docs/recipes/04-quests.md +12 -5
  183. package/docs/recipes/05-props-bake.md +151 -15
  184. package/docs/recipes/06-clock-events.md +100 -52
  185. package/docs/recipes/07-flow-scenes-pause.md +40 -9
  186. package/docs/recipes/08-weather-sky.md +145 -36
  187. package/docs/recipes/{09-style-pack.md → 09-style.md} +101 -52
  188. package/docs/recipes/10-blender-level.md +14 -2
  189. package/docs/recipes/11-vehicles.md +64 -7
  190. package/docs/recipes/13-animation.md +14 -6
  191. package/docs/recipes/14-custom-module.md +61 -29
  192. package/docs/recipes/15-perf.md +30 -9
  193. package/docs/recipes/16-dev-bridge.md +61 -37
  194. package/docs/recipes/18-world.md +16 -6
  195. package/docs/recipes/19-shooting-picking.md +6 -6
  196. package/docs/recipes/20-content-actions-save.md +55 -17
  197. package/docs/recipes/21-camera.md +49 -16
  198. package/docs/recipes/22-shop-gold.md +3 -3
  199. package/docs/recipes/23-ops.md +16 -10
  200. package/docs/recipes/26-ui-parts.md +61 -12
  201. package/docs/recipes/27-net.md +11 -5
  202. package/docs/recipes/28-terrain.md +34 -1
  203. package/docs/recipes/29-grid.md +34 -16
  204. package/docs/recipes/30-templates.md +64 -12
  205. package/docs/recipes/31-audio.md +20 -12
  206. package/docs/recipes/32-action-game.md +35 -2
  207. package/docs/recipes/34-environment-lighting.md +26 -3
  208. package/docs/recipes/35-style-from-reference.md +88 -19
  209. package/docs/recipes/36-sky-ground-plant-looks.md +18 -18
  210. package/docs/recipes/37-terrain-look-hooks.md +3 -2
  211. package/docs/recipes/38-environment-look-hooks.md +37 -26
  212. package/docs/recipes/40-scene.md +16 -13
  213. package/docs/recipes/41-thing-registry.md +11 -7
  214. package/docs/recipes/42-terrain-shape.md +2 -2
  215. package/docs/recipes/43-shader-patches-surface-looks.md +158 -76
  216. package/docs/recipes/44-water-weather-look-hooks.md +26 -17
  217. package/docs/recipes/45-cascaded-shadows.md +16 -7
  218. package/docs/recipes/47-island-snow-backdrop.md +7 -7
  219. package/docs/recipes/48-make-material.md +11 -6
  220. package/docs/recipes/49-game-module-contract.md +30 -17
  221. package/docs/recipes/50-own-renderer.md +2 -2
  222. package/docs/recipes/51-capability-catalog.md +3 -3
  223. package/docs/recipes/52-look.md +197 -61
  224. package/docs/recipes/53-ground-up-close.md +1 -1
  225. package/docs/recipes/54-three-idioms.md +88 -0
  226. package/docs/recipes/55-mods-time-wrap.md +112 -0
  227. package/docs/recipes/56-webgpu-tsl.md +260 -0
  228. package/docs/recipes/57-control.md +65 -0
  229. package/docs/recipes/58-input.md +57 -0
  230. package/docs/recipes/59-depth-post-effects.md +83 -0
  231. package/docs/recipes/60-judge-the-picture.md +55 -0
  232. package/examples/action/.threedog/content-index.json +1 -0
  233. package/examples/action/GAMEMAP.md +17 -13
  234. package/examples/action/assets.js +8 -0
  235. package/examples/action/content/actions.js +1 -1
  236. package/examples/action/content/audio.js +5 -5
  237. package/examples/action/look.js +1 -1
  238. package/examples/action/main.js +10 -14
  239. package/examples/action/models.js +24 -23
  240. package/examples/pullable.json +111 -0
  241. package/examples/rc2d/.threedog/content-index.json +1 -0
  242. package/examples/rc2d/GAMEMAP.md +83 -0
  243. package/examples/rc2d/README.md +52 -0
  244. package/examples/rc2d/main.js +63 -0
  245. package/examples/rc2d/rc2d.js +197 -0
  246. package/examples/rc2d/shaders.js +144 -0
  247. package/examples/sheepisland/.threedog/content-index.json +1 -0
  248. package/examples/sheepisland/GAMEMAP.md +13 -11
  249. package/examples/sheepisland/assets.js +5 -0
  250. package/examples/sheepisland/main.js +17 -12
  251. package/examples/sheepisland/style/index.js +6 -6
  252. package/examples/styletest/.threedog/content-index.json +1 -0
  253. package/examples/styletest/GAMEMAP.md +15 -16
  254. package/examples/styletest/assets.js +6 -0
  255. package/examples/styletest/content/templates.js +1 -1
  256. package/examples/styletest/content/vegetation.js +1 -1
  257. package/examples/styletest/look.js +1 -1
  258. package/examples/styletest/main.js +17 -16
  259. package/examples/styletest/models.js +1 -1
  260. package/examples/styletest/params.js +3 -3
  261. package/examples/techniques/contact-shadows/README.md +92 -0
  262. package/examples/techniques/contact-shadows/contactShadows.js +51 -0
  263. package/examples/techniques/contact-shadows/main.js +53 -0
  264. package/examples/techniques/day-night-grade/README.md +86 -0
  265. package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
  266. package/examples/techniques/day-night-grade/main.js +51 -0
  267. package/examples/techniques/interior-light/README.md +103 -0
  268. package/examples/techniques/interior-light/interiorLight.js +45 -0
  269. package/examples/techniques/interior-light/main.js +124 -0
  270. package/examples/techniques/modular-building/README.md +125 -0
  271. package/examples/techniques/modular-building/kit.js +426 -0
  272. package/examples/techniques/modular-building/main.js +47 -0
  273. package/examples/techniques/night-lights/README.md +94 -0
  274. package/examples/techniques/night-lights/main.js +70 -0
  275. package/examples/techniques/night-lights/nightLights.js +91 -0
  276. package/examples/techniques/outlines-and-rim/README.md +59 -0
  277. package/examples/techniques/outlines-and-rim/main.js +84 -0
  278. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  279. package/examples/techniques/procedural-animation/README.md +77 -0
  280. package/examples/techniques/procedural-animation/creature.js +44 -0
  281. package/examples/techniques/procedural-animation/main.js +45 -0
  282. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  283. package/examples/techniques/procedural-surface/README.md +67 -0
  284. package/examples/techniques/procedural-surface/main.js +103 -0
  285. package/examples/techniques/procedural-surface/surface.js +120 -0
  286. package/examples/techniques/stylized-shading/README.md +75 -0
  287. package/examples/techniques/stylized-shading/main.js +93 -0
  288. package/examples/techniques/stylized-shading/shading.js +131 -0
  289. package/examples/techniques/sun-and-key-light/README.md +135 -0
  290. package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
  291. package/examples/techniques/sun-and-key-light/main.js +95 -0
  292. package/examples/techniques/wet-road/README.md +99 -0
  293. package/examples/techniques/wet-road/main.js +68 -0
  294. package/examples/techniques/wet-road/wetRoad.js +209 -0
  295. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  296. package/examples/webgpu-tsl/GAMEMAP.md +84 -0
  297. package/examples/webgpu-tsl/README.md +42 -0
  298. package/examples/webgpu-tsl/main.js +21 -0
  299. package/examples/webgpu-tsl/tslScene.js +75 -0
  300. package/examples/world/.threedog/content-index.json +1 -0
  301. package/examples/world/GAMEMAP.md +22 -15
  302. package/examples/world/art/humanoid.js +42 -0
  303. package/examples/world/art/index.js +11 -0
  304. package/examples/world/art/models.js +58 -0
  305. package/examples/world/art/shapes.js +9 -0
  306. package/examples/world/assets.js +6 -0
  307. package/examples/world/content/audio.js +5 -5
  308. package/examples/world/content/npcs.js +1 -1
  309. package/examples/world/content/props.js +1 -1
  310. package/examples/world/content/rules.js +1 -1
  311. package/examples/world/content/templates.js +1 -1
  312. package/examples/world/content/vegetation.js +1 -1
  313. package/examples/world/main.js +17 -13
  314. package/examples/world/style/index.js +61 -0
  315. package/examples/world/style/plugins/10-bloom.js +5 -0
  316. package/index.d.ts +44 -45
  317. package/index.js +26 -22
  318. package/llms.txt +11 -4
  319. package/modules/ambience/Ambience.js +34 -23
  320. package/modules/calendar/Calendar.js +163 -0
  321. package/modules/calendar/contract.js +21 -0
  322. package/modules/calendar/index.js +81 -0
  323. package/modules/{sky → calendar}/schedule.js +17 -16
  324. package/modules/calendar/seasons.js +55 -0
  325. package/modules/camera/FirstPersonCamera.js +6 -15
  326. package/modules/camera/FixedCamera.js +33 -15
  327. package/modules/camera/FollowCamera.js +90 -16
  328. package/modules/camera/RtsCamera.js +18 -17
  329. package/modules/camera/common.js +70 -19
  330. package/modules/camera/contract.js +17 -0
  331. package/modules/camera/projection.js +11 -24
  332. package/modules/characters/Character.js +177 -42
  333. package/modules/characters/NPC.js +87 -36
  334. package/modules/characters/assetModel.js +4 -13
  335. package/modules/characters/behaviors.js +2 -1
  336. package/modules/characters/contract.js +13 -0
  337. package/modules/characters/footsteps.js +1 -1
  338. package/modules/characters/index.js +87 -49
  339. package/modules/characters/moveHelpers.js +4 -5
  340. package/modules/characters/movers/common.js +97 -19
  341. package/modules/characters/movers/manual.js +20 -0
  342. package/modules/characters/movers/rapier.js +19 -16
  343. package/modules/characters/movers/simple.js +14 -11
  344. package/modules/characters/movers/support.js +172 -0
  345. package/modules/characters/npcAvoid.js +47 -42
  346. package/modules/characters/npcSim.js +12 -8
  347. package/modules/characters/npcView.js +44 -16
  348. package/modules/characters/pathAsync.js +7 -3
  349. package/modules/characters/playerStrings.js +4 -3
  350. package/modules/characters/proceduralRig.js +2 -1
  351. package/modules/characters/useModel.js +1 -1
  352. package/modules/characters/vehicle.contract.js +21 -0
  353. package/modules/characters/walkTo.js +21 -7
  354. package/modules/collision/Collision.js +65 -25
  355. package/modules/collision/grid.js +8 -6
  356. package/modules/content/explain.js +2 -2
  357. package/modules/content/fields.js +102 -0
  358. package/modules/content/ids.js +8 -6
  359. package/modules/content/index.js +96 -27
  360. package/modules/content/loader.js +45 -33
  361. package/modules/content/models.js +11 -40
  362. package/modules/content/packs.js +6 -5
  363. package/modules/content/parts.js +41 -0
  364. package/modules/content/props.js +16 -9
  365. package/modules/content/rules.js +58 -0
  366. package/modules/content/stages.js +80 -0
  367. package/modules/content/templates.js +121 -30
  368. package/modules/debug/DebugPanel.js +24 -17
  369. package/modules/flow/contract.js +16 -0
  370. package/modules/flow/index.js +21 -15
  371. package/modules/gameplay/Container.js +41 -32
  372. package/modules/gameplay/Containers.js +30 -15
  373. package/modules/gameplay/Dialogue.js +113 -55
  374. package/modules/gameplay/Interactions.js +193 -67
  375. package/modules/gameplay/Inventory.js +69 -73
  376. package/modules/gameplay/Quests.js +75 -39
  377. package/modules/gameplay/boxOps.js +3 -3
  378. package/modules/gameplay/dialogue.contract.js +21 -0
  379. package/modules/gameplay/dialogueBox.js +4 -2
  380. package/modules/gameplay/dialogueBubbles.js +116 -0
  381. package/modules/gameplay/interactionPrompt.js +4 -1
  382. package/modules/gameplay/interactions.contract.js +16 -0
  383. package/modules/gameplay/inventory.contract.js +23 -0
  384. package/modules/gameplay/inventoryOps.js +18 -16
  385. package/modules/gameplay/pickups.js +268 -85
  386. package/modules/gameplay/questLog.js +4 -4
  387. package/modules/gameplay/quests.contract.js +17 -0
  388. package/modules/grid/Grid.js +92 -50
  389. package/modules/grid/Layer.js +14 -13
  390. package/modules/grid/index.js +60 -36
  391. package/modules/grid/ops.js +20 -18
  392. package/modules/grid/preview.js +15 -16
  393. package/modules/grid/strings.js +12 -0
  394. package/modules/grid/tiles.js +6 -5
  395. package/modules/hlod/index.js +51 -19
  396. package/modules/hud/index.js +35 -20
  397. package/modules/hud/parts.js +20 -7
  398. package/modules/level/heightfield.js +3 -1
  399. package/modules/level/index.js +45 -20
  400. package/modules/level/nodes.js +4 -3
  401. package/modules/lights/index.js +42 -18
  402. package/modules/music/Music.js +38 -21
  403. package/modules/music/rules.js +1 -1
  404. package/modules/nav/index.js +48 -42
  405. package/modules/net/Client.js +13 -6
  406. package/modules/net/Host.js +19 -5
  407. package/modules/net/Net.js +2 -1
  408. package/modules/net/index.js +13 -8
  409. package/modules/net/sync.js +9 -8
  410. package/modules/net/transports.js +77 -27
  411. package/modules/particles/Particles.js +23 -14
  412. package/modules/particles/contract.js +17 -0
  413. package/modules/particles/effect.js +39 -11
  414. package/modules/photo/Photo.js +53 -36
  415. package/modules/rigid/RigidBodies.js +194 -32
  416. package/modules/rigid/Vehicles.js +18 -15
  417. package/modules/rigid/sync.js +62 -17
  418. package/modules/settings/Settings.js +57 -52
  419. package/modules/settings/apply.js +38 -3
  420. package/modules/settings/sections.js +5 -3
  421. package/modules/settings/strings.js +3 -2
  422. package/modules/settings/view.js +5 -3
  423. package/modules/sky/Sky.js +88 -176
  424. package/modules/sky/cascades.js +86 -25
  425. package/modules/sky/cascades.tsl.js +82 -0
  426. package/modules/sky/clouds.js +34 -19
  427. package/modules/sky/domeLayers.js +30 -15
  428. package/modules/sky/environment.js +83 -13
  429. package/modules/sky/fog.js +140 -95
  430. package/modules/sky/frame.js +112 -44
  431. package/modules/sky/look.js +22 -19
  432. package/modules/sky/lookFog.js +48 -52
  433. package/modules/sky/lookShadow.js +53 -41
  434. package/modules/sky/lookSky.js +82 -21
  435. package/modules/sky/season.js +21 -0
  436. package/modules/sky/shader.js +41 -19
  437. package/modules/sky/shadow.js +44 -20
  438. package/modules/sky/skyModule.js +45 -33
  439. package/modules/sky/tint.js +61 -0
  440. package/modules/terrain/ChunkManager.js +175 -108
  441. package/modules/terrain/chunkJob.js +1 -1
  442. package/modules/terrain/chunkQueries.js +6 -4
  443. package/modules/terrain/index.js +105 -50
  444. package/modules/terrain/look.js +83 -0
  445. package/modules/terrain/lookGround.js +21 -16
  446. package/modules/terrain/terrainDefaults.js +1 -1
  447. package/modules/terrain/terrainEdit.js +18 -20
  448. package/modules/terrain/terrainGen.js +5 -3
  449. package/modules/terrain/terrainIsland.js +5 -4
  450. package/modules/terrain/terrainShape.js +12 -12
  451. package/modules/terrain/terrainShapeMain.js +8 -7
  452. package/modules/terrain/terrainTexture.js +21 -19
  453. package/modules/timeline/Timeline.js +95 -43
  454. package/modules/timeline/Tween.js +18 -10
  455. package/modules/timeline/letterbox.js +2 -2
  456. package/modules/timeline/shots.js +5 -1
  457. package/modules/triggers/index.js +107 -76
  458. package/modules/vegetation/Vegetation.js +186 -110
  459. package/modules/vegetation/densityMap.js +62 -0
  460. package/modules/vegetation/groundChunks.js +52 -58
  461. package/modules/vegetation/index.js +32 -11
  462. package/modules/vegetation/look.js +119 -0
  463. package/modules/vegetation/lookWind.js +71 -10
  464. package/modules/vegetation/modelGeometry.js +3 -2
  465. package/modules/vegetation/nearFade.js +8 -2
  466. package/modules/water/Water.js +65 -27
  467. package/modules/water/look.js +29 -18
  468. package/modules/water/surface.js +64 -25
  469. package/modules/water/surfaceDefaults.js +3 -0
  470. package/modules/weather/Weather.js +62 -104
  471. package/modules/weather/look.js +1 -2
  472. package/modules/weather/particles.js +24 -9
  473. package/modules/weather/strings.js +2 -2
  474. package/modules/weather/weatherLook.js +135 -0
  475. package/modules/world/World.js +24 -7
  476. package/modules/world/explain.js +1 -1
  477. package/modules/world/index.js +18 -4
  478. package/modules/world/persist.js +62 -2
  479. package/modules/world/pos.js +3 -2
  480. package/modules/world/records.js +8 -6
  481. package/modules/world/sim.js +60 -20
  482. package/modules/world/simFar.js +4 -3
  483. package/modules/world/state.js +3 -2
  484. package/modules/world/thingSource.js +1 -1
  485. package/modules/world/views.js +7 -5
  486. package/package.json +7 -3
  487. package/presets.js +41 -27
  488. package/render/PostFX.js +145 -120
  489. package/render/backend.js +440 -0
  490. package/render/detail.js +120 -39
  491. package/render/effects.js +130 -38
  492. package/render/engineUniforms.js +10 -1
  493. package/render/fuse.js +5 -4
  494. package/render/fx/cloudShadow.tsl.js +16 -0
  495. package/render/fx/detail.tsl.js +66 -0
  496. package/render/fx/index.js +26 -0
  497. package/render/fx/lighting.tsl.js +28 -0
  498. package/render/fx/nodeErrors.tsl.js +68 -0
  499. package/render/fx/noise.tsl.js +12 -0
  500. package/render/fx/objectOrigin.tsl.js +42 -0
  501. package/render/fx/particles.tsl.js +139 -0
  502. package/render/fx/patchNodes.tsl.js +403 -0
  503. package/render/fx/postWebGPU.tsl.js +158 -0
  504. package/render/fx/season.tsl.js +13 -0
  505. package/render/fx/sky.tsl.js +260 -0
  506. package/render/fx/uniforms.tsl.js +67 -0
  507. package/render/fx/water.tsl.js +53 -0
  508. package/render/fx/wind.tsl.js +22 -0
  509. package/render/fxNumbers.js +36 -0
  510. package/render/hotGlsl.js +24 -0
  511. package/render/lighting.js +66 -14
  512. package/render/lights.js +223 -4
  513. package/render/lookGlow.js +139 -0
  514. package/render/lookSurface.js +99 -36
  515. package/render/materials.js +71 -52
  516. package/render/modeling.js +73 -0
  517. package/render/ownFrame.js +76 -0
  518. package/render/patches.js +311 -34
  519. package/render/postLook.js +124 -46
  520. package/render/postWebGL.js +197 -0
  521. package/render/probes.js +231 -0
  522. package/render/shaderErrors.js +154 -0
  523. package/render/slots.js +165 -0
  524. package/render/surface.js +53 -17
  525. package/render/terms.js +211 -0
  526. package/render/uniformDecl.js +3 -2
  527. package/types/common.d.ts +2 -2
  528. package/types/core.d.ts +614 -240
  529. package/types/gameplay.d.ts +482 -312
  530. package/types/generated/core/Audio.d.ts +26 -42
  531. package/types/generated/core/Batching.d.ts +6 -2
  532. package/types/generated/core/Budget.d.ts +2 -8
  533. package/types/generated/core/DebugOverrides.d.ts +44 -3
  534. package/types/generated/core/I18n.d.ts +2 -2
  535. package/types/generated/core/Input.d.ts +102 -31
  536. package/types/generated/core/Ops.d.ts +31 -0
  537. package/types/generated/core/Random.d.ts +2 -2
  538. package/types/generated/core/Saves.d.ts +10 -2
  539. package/types/generated/core/Stream.d.ts +1 -1
  540. package/types/generated/core/Threads.d.ts +4 -1
  541. package/types/generated/core/Views.d.ts +0 -1
  542. package/types/generated/core/audioVoice.d.ts +17 -9
  543. package/types/generated/core/control.d.ts +55 -0
  544. package/types/generated/core/session.d.ts +2 -1
  545. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  546. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  547. package/types/generated/modules/calendar/index.d.ts +10 -0
  548. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  549. package/types/generated/modules/grid/Grid.d.ts +61 -25
  550. package/types/generated/modules/grid/Layer.d.ts +5 -5
  551. package/types/generated/modules/grid/index.d.ts +29 -17
  552. package/types/generated/modules/music/Music.d.ts +5 -3
  553. package/types/generated/modules/net/index.d.ts +3 -3
  554. package/types/generated/modules/net/transports.d.ts +12 -3
  555. package/types/generated/modules/particles/Particles.d.ts +1 -1
  556. package/types/generated/modules/sky/Sky.d.ts +12 -104
  557. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  558. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  559. package/types/generated/modules/weather/Weather.d.ts +17 -18
  560. package/types/generated/modules/weather/weatherLook.d.ts +12 -0
  561. package/types/generated/modules/world/World.d.ts +18 -3
  562. package/types/generated/render/PostFX.d.ts +67 -30
  563. package/types/generated/render/materials.d.ts +26 -20
  564. package/types/generated/render/modeling.d.ts +30 -0
  565. package/types/generated/render/patches.d.ts +16 -2
  566. package/types/generated/ui/UI.d.ts +6 -3
  567. package/types/nav.d.ts +6 -0
  568. package/types/physics.d.ts +137 -44
  569. package/types/style.d.ts +109 -81
  570. package/types/tsl.d.ts +86 -0
  571. package/types/world.d.ts +158 -110
  572. package/ui/Focus.js +25 -14
  573. package/ui/LoadingScreen.js +1 -1
  574. package/ui/Parts.js +27 -11
  575. package/ui/UI.js +20 -10
  576. package/ui/cursor.js +115 -0
  577. package/ui/defaults.js +15 -11
  578. package/ui/theme.js +9 -6
  579. package/ui/touchPart.js +1 -1
  580. package/core/claims.js +0 -51
  581. package/core/look/layers.js +0 -136
  582. package/core/renamed.js +0 -22
  583. package/docs/api/entities.md +0 -61
  584. package/examples/styletest/overrides.js +0 -33
  585. package/examples/styletest/panel.js +0 -135
  586. package/modules/entities/Entities.js +0 -243
  587. package/modules/entities/build.js +0 -25
  588. package/modules/entities/index.js +0 -4
  589. package/modules/sky/calendar.js +0 -80
  590. package/modules/sky/layers.js +0 -69
  591. package/modules/terrain/chunkLevels.js +0 -40
  592. package/modules/terrain/mountTerrain.js +0 -32
  593. package/modules/world/cells.js +0 -42
@@ -5,9 +5,10 @@
5
5
  // Positions are always a single argument (Vector3 / Object3D / [x, y, z] / { x, z }); sizes go in the options object:
6
6
  // const h = engine.collision.addBox(house, { halfWidth: 3, halfDepth: 2, rotation: 0.3 }); h.remove();
7
7
  import { xzOf } from '../../core/math.js';
8
- import { checkOptionsArg } from '../../core/validate.js';
8
+
9
9
  import { readParams, keysSchema } from '../../core/params.js';
10
10
  import { CollisionGrid, gridBlocks } from './grid.js';
11
+ import { codedError } from '../../core/errorHints.js';
11
12
 
12
13
  /** One axis of the slab test: narrows S.t0 / S.t1 to where the ray is inside |o + d t| <= h; false when it misses */
13
14
  function slab(S, o, d, h) {
@@ -17,7 +18,7 @@ function slab(S, o, d, h) {
17
18
  return S.t0 <= S.t1;
18
19
  }
19
20
 
20
- const BOX_KEYS = ['halfWidth', 'halfDepth', 'rotation', 'height', 'y'], CIRCLE_KEYS = ['radius', 'height'], SEG_KEYS = ['thickness', 'height', 'y'], BLOCK_KEYS = ['bounds'];
21
+ const BOX_KEYS = ['halfWidth', 'halfDepth', 'rotation', 'height', 'y', 'occluder'], CIRCLE_KEYS = ['radius', 'height', 'occluder'], SEG_KEYS = ['thickness', 'height', 'y', 'occluder'], BLOCK_KEYS = ['bounds'];
21
22
 
22
23
  export class Collision {
23
24
  /**
@@ -28,8 +29,10 @@ export class Collision {
28
29
  constructor(engine, { maxClimb = engine.movement.slopeRatio, canopyHeight = 5, cameraPad = 0.5, cameraMin = 1.5, walkableWaterMargin = 0.2, cameraOcclusion = 'colliders' } = {}) {
29
30
  this.engine = engine;
30
31
  Object.assign(this, { maxClimb, canopyHeight, cameraPad, cameraMin, walkableWaterMargin, cameraOcclusion });
31
- this.circles = []; // manually added circle colliders {x, z, r, h}
32
- this.boxes = []; // rectangles {x, z, hw, hd, rot, h}
32
+ // Sets, not arrays: they keep insertion order (forEachStatic and every consumer see colliders in the order added) and delete in O(1),
33
+ // where an array filter per remove made unloading n colliders O(n^2)
34
+ /** manually added circle colliders {x, z, r, h} @type {Set<any>} */ this.circles = new Set();
35
+ /** rectangles {x, z, hw, hd, rot, h} @type {Set<any>} */ this.boxes = new Set();
33
36
  this._grid = new CollisionGrid(); // grid index: resolve / camera look only nearby instead of scanning all (circles / boxes change only via addCircle / addBox)
34
37
  this._blocked = []; // addBlocked fields {fn, bounds}; empty = zero cost
35
38
  this.blockedVersion = 0; // +1 on addBlocked / remove: async paths re-sample their cached ground rasters
@@ -41,43 +44,72 @@ export class Collision {
41
44
  }
42
45
  /** Iterate all manually added static colliders (for the physics module): fn('box' | 'circle', data) */
43
46
  forEachStatic(fn) { for (const b of this.boxes) fn('box', b); for (const c of this.circles) fn('circle', c); }
47
+ /**
48
+ * Keep an outside copy of the static colliders (boxes and circles) in step, e.g. physics colliders or navmesh obstacles. add(type, data) builds the
49
+ * copy of one collider and returns it; remove(piece, data) drops one. sync() does the work only when `version` moved since the last sync, then adds
50
+ * what is new (in forEachStatic order) and removes what is gone; returns whether anything was compared. clear() forgets every piece without calling
51
+ * remove (the outside world they lived in was thrown away) so the next sync builds all again.
52
+ * Why one shared mirror: nav and rigid each had their own copy of this diff, and the two copies drifted (one checked readiness, the other a version
53
+ * field of its own); a third consumer would copy it a third time.
54
+ * @param {{ add: (type: 'box' | 'circle', data: any) => any, remove: (piece: any, data: any) => void }} fns
55
+ */
56
+ mirror({ add, remove }) {
57
+ const pieces = new Map(), col = this;
58
+ const seen = new Set();
59
+ let version = -1;
60
+ return {
61
+ sync() {
62
+ if (col.version === version) return false;
63
+ version = col.version; seen.clear();
64
+ col.forEachStatic((type, o) => { seen.add(o); if (!pieces.has(o)) pieces.set(o, add(type, o)); });
65
+ for (const [o, p] of pieces) if (!seen.has(o)) { pieces.delete(o); remove(p, o); }
66
+ seen.clear();
67
+ return true;
68
+ },
69
+ clear() { pieces.clear(); version = -1; },
70
+ get size() { return pieces.size; },
71
+ };
72
+ }
44
73
 
45
- /** Add a circle collider (pillar, statue, campfire): position is the centre, radius (default 0.5), height (default 6). Returns a handle { remove() } */
74
+ /**
75
+ * Add a circle collider (pillar, statue, campfire): position is the centre, radius (default 0.5), height (default 6).
76
+ * occluder: false keeps it from pulling the follow camera in (walkers are still stopped), e.g. forest trunks the camera may pass through. Returns a handle { remove() }
77
+ */
46
78
  addCircle(position, opts = {}) {
47
- checkOptionsArg('collision.addCircle()', opts, CIRCLE_KEYS); if (typeof opts !== 'object') opts = {};
48
- const [x, z] = xzOf(position), c = { x, z, r: opts.radius ?? 0.5, h: opts.height ?? 6 };
49
- this.circles.push(c); this._grid.add(c, false); this.version++;
50
- return { remove: () => { if (!this.circles.includes(c)) return; this.circles = this.circles.filter(o => o !== c); this._grid.remove(c); this.version++; } };
79
+ readParams('collision.addCircle()', keysSchema(CIRCLE_KEYS), opts); if (typeof opts !== 'object') opts = {};
80
+ const [x, z] = xzOf(position), c = { x, z, r: opts.radius ?? 0.5, h: opts.height ?? 6, occ: opts.occluder !== false };
81
+ this.circles.add(c); this._grid.add(c, false); this.version++;
82
+ return { remove: () => { if (!this.circles.delete(c)) return; this._grid.remove(c); this.version++; } };
51
83
  }
52
84
  /**
53
85
  * Add a rectangle collider (house, fence): position is the centre; halfWidth / halfDepth (default 1), rotation about the Y axis (radians),
54
- * height (default 6), y is the box bottom height (omit to sit on the ground; set it for walls on platforms in levels). Returns a handle { remove() }
86
+ * height (default 6), y is the box bottom height (omit to sit on the ground; set it for walls on platforms in levels); occluder: false as in addCircle. Returns a handle { remove() }
55
87
  */
56
88
  addBox(position, opts = {}) {
57
- checkOptionsArg('collision.addBox()', opts, BOX_KEYS); if (typeof opts !== 'object') opts = {};
89
+ readParams('collision.addBox()', keysSchema(BOX_KEYS), opts); if (typeof opts !== 'object') opts = {};
58
90
  const [x, z] = xzOf(position), hw = opts.halfWidth ?? 1, hd = opts.halfDepth ?? 1, rot = opts.rotation ?? 0;
59
- const b = { x, z, hw, hd, rot, h: opts.height ?? 6, y: opts.y, c: Math.cos(rot), s: Math.sin(rot), r: Math.hypot(hw, hd) };
60
- this.boxes.push(b); this._grid.add(b, true); this.version++;
61
- return { remove: () => { if (!this.boxes.includes(b)) return; this.boxes = this.boxes.filter(o => o !== b); this._grid.remove(b); this.version++; } };
91
+ const b = { x, z, hw, hd, rot, h: opts.height ?? 6, y: opts.y, c: Math.cos(rot), s: Math.sin(rot), r: Math.hypot(hw, hd), occ: opts.occluder !== false };
92
+ this.boxes.add(b); this._grid.add(b, true); this.version++;
93
+ return { remove: () => { if (!this.boxes.delete(b)) return; this._grid.remove(b); this.version++; } };
62
94
  }
63
95
  /**
64
- * Add a thin wall along the line a -> b (fence, wall; positions like addBox). thickness (default 0.3), height (default 6), y as in addBox.
96
+ * Add a thin wall along the line a -> b (fence, wall; positions like addBox). thickness (default 0.3), height (default 6), y and occluder as in addBox.
65
97
  * It is a rotated box in the same grid, so a gap between two segments is a gate. Returns a handle { remove() }
66
98
  */
67
99
  addSegment(a, b, opts = {}) {
68
- checkOptionsArg('collision.addSegment()', opts, SEG_KEYS); if (typeof opts !== 'object') opts = {};
100
+ readParams('collision.addSegment()', keysSchema(SEG_KEYS), opts); if (typeof opts !== 'object') opts = {};
69
101
  const [ax, az] = xzOf(a), [bx, bz] = xzOf(b);
70
102
  // box-local +x is (cos r, -sin r) in world, so r = -atan2(dz, dx)
71
- return this.addBox([(ax + bx) / 2, 0, (az + bz) / 2], { halfWidth: Math.hypot(bx - ax, bz - az) / 2, halfDepth: (opts.thickness ?? 0.3) / 2, rotation: -Math.atan2(bz - az, bx - ax), height: opts.height, y: opts.y });
103
+ return this.addBox([(ax + bx) / 2, 0, (az + bz) / 2], { halfWidth: Math.hypot(bx - ax, bz - az) / 2, halfDepth: (opts.thickness ?? 0.3) / 2, rotation: -Math.atan2(bz - az, bx - ax), height: opts.height, y: opts.y, occluder: opts.occluder });
72
104
  }
73
105
  /**
74
106
  * Mark ground as impassable where fn(x, z) is true (river, lava, cliff edge). Walkers are stopped at its edge (sliding along it) and walkable() says no.
75
- * fn must be pure and deterministic (no clock, no random). bounds { minX, maxX, minZ, maxZ } skips fn outside it. A bridge: have fn return false over it,
107
+ * fn must be pure and deterministic (no clock, no random). bounds { minX, maxX, minZ, maxZ } (world metres, the field's x / z extent) skips fn outside it. A bridge: have fn return false over it,
76
108
  * or keep the water field exact and let fn test `!onBridge(x, z)`. findPathAsync samples fn into its ground raster (1 m cells), so give bounds to keep that cheap. Returns a handle { remove() }
77
109
  */
78
110
  addBlocked(fn, opts = {}) {
79
- checkOptionsArg('collision.addBlocked()', opts, BLOCK_KEYS); if (typeof opts !== 'object') opts = {};
80
- if (typeof fn !== 'function') throw new Error('collision.addBlocked(fn): fn(x, z) => boolean is required');
111
+ readParams('collision.addBlocked()', keysSchema(BLOCK_KEYS), opts); if (typeof opts !== 'object') opts = {};
112
+ if (typeof fn !== 'function') throw codedError('collision-misuse', 'collision.addBlocked(fn): fn(x, z) => boolean is required');
81
113
  const f = { fn, bounds: opts.bounds ?? null }; this._blocked.push(f); this.version++; this.blockedVersion++;
82
114
  return { remove: () => { if (!this._blocked.includes(f)) return; this._blocked = this._blocked.filter(o => o !== f); this.version++; this.blockedVersion++; } };
83
115
  }
@@ -91,11 +123,11 @@ export class Collision {
91
123
  }
92
124
  return false;
93
125
  }
94
- /** Add collision from a three.js object's bounding box (common for house models), pad grows it outward (m). Returns a handle { remove() } */
95
- addObject(obj, { pad = 0 } = {}) {
126
+ /** Add collision from a three.js object's bounding box (common for house models), pad grows it outward (m), occluder as in addBox. Returns a handle { remove() } */
127
+ addObject(obj, { pad = 0, occluder = true } = {}) {
96
128
  obj.updateMatrixWorld(true);
97
129
  const THREE = this.engine.THREE, box = new THREE.Box3().setFromObject(obj), c = box.getCenter(new THREE.Vector3()), s = box.getSize(new THREE.Vector3());
98
- return this.addBox(c, { halfWidth: s.x / 2 + pad, halfDepth: s.z / 2 + pad, height: s.y });
130
+ return this.addBox(c, { halfWidth: s.x / 2 + pad, halfDepth: s.z / 2 + pad, height: s.y, occluder });
99
131
  }
100
132
 
101
133
  // The per-frame walkers below pass state through fields instead of building callbacks: resolve() and cameraDistance() run every step / frame.
@@ -156,7 +188,7 @@ export class Collision {
156
188
  }
157
189
  /** @internal */
158
190
  _lineClear(a, b, opts) {
159
- checkOptionsArg('collision.lineClear()', opts, ['radius', 'who']); if (typeof opts !== 'object') opts = {};
191
+ readParams('collision.lineClear()', keysSchema(['radius', 'who']), opts); if (typeof opts !== 'object') opts = {};
160
192
  const rad = opts.radius ?? 0;
161
193
  const A = this._vec(a), B = this._vec(b), dx = B.x - A.x, dz = B.z - A.z, dy = B.y - A.y;
162
194
  const S = this._lineS;
@@ -257,6 +289,7 @@ export class Collision {
257
289
  const list = this._grid.query(from.x + sx / 2, from.z + sz / 2, len / 2 + 1);
258
290
  for (let i = 0; i < list.length; i++) {
259
291
  const it = list[i];
292
+ if (!it.occ) continue; // occluder: false (addCircle / addBox)
260
293
  if (it._b) this._camBox(it); else this._camCircle(it.x, it.z, it.r);
261
294
  }
262
295
  best = S.best;
@@ -270,5 +303,12 @@ const COLLISION_PARAMS = keysSchema(['maxClimb', 'canopyHeight', 'cameraPad', 'c
270
303
  /** Collision module: lightweight character walking collision, covers the whole map. Once installed: engine.collision */
271
304
  export function collision(opts = {}) {
272
305
  readParams('collision', COLLISION_PARAMS, opts);
273
- return { name: 'collision', params: COLLISION_PARAMS, options: opts, label: 'Collision', install(e) { return new Collision(e, opts); } };
306
+ let c = null;
307
+ return { name: 'collision', type: 'world', provides: ['collision'], params: COLLISION_PARAMS, options: opts, label: 'Collision', install(e) { e.i18n.add({ 'zh-CN': { 'module.collision': '碰撞' }, en: { 'module.collision': 'collision' } }); return (c = new Collision(e, opts)); },
308
+ // counts of what blocks walking, and whether the player's own spot is walkable: answers "why can the player not go there" without stepping
309
+ describe(e) {
310
+ const p = e.player?.position;
311
+ return { circles: c.circles.size, boxes: c.boxes.size, fields: c._blocked.length, cameraOcclusion: c.cameraOcclusion,
312
+ ...(p ? { atPlayer: { walkable: c.groundWalkable(p.x, p.z), blocked: c.blockedAt(p.x, p.z) } } : {}) };
313
+ } };
274
314
  }
@@ -1,5 +1,6 @@
1
1
  // Grid index of colliders: register each by bounding circle in the cells it covers; queries look at a few nearby cells instead of scanning all colliders.
2
2
  // Results are ordered circles first, then boxes, each in insertion order, exactly the callback order of a linear scan (resolve edits the position in turn, so a different order changes the result).
3
+ // Worker-safe (no imports): the path worker (characters/pathJob.js) rebuilds the same grid from the colliders it mirrors.
3
4
  const CELL = 8, MAX_CELLS = 64, KEY = 1048576; // colliders too large (covering > 64 cells) skip the grid and are scanned linearly, so registration cost does not blow up
4
5
  const byOrder = (a, b) => a._b - b._b || a._o - b._o;
5
6
 
@@ -15,30 +16,31 @@ function take(out, it, x, z, range, st) {
15
16
  }
16
17
 
17
18
  export class CollisionGrid {
18
- constructor() { this.cells = new Map(); this.big = []; this.seq = 0; this.stamp = 0; this.out = []; }
19
+ constructor() { this.cells = new Map(); this.big = new Set(); this.seq = 0; this.stamp = 0; this.out = []; }
19
20
  /** Register; item needs x, z, r. isBox puts it after circles in the callback order */
20
21
  add(item, isBox) {
21
22
  item._o = this.seq++; item._b = isBox ? 1 : 0;
22
23
  const [x0, x1, z0, z1] = cellRange(item);
23
- if ((x1 - x0 + 1) * (z1 - z0 + 1) > MAX_CELLS) { this.big.push(item); return; }
24
+ if ((x1 - x0 + 1) * (z1 - z0 + 1) > MAX_CELLS) { this.big.add(item); return; }
24
25
  for (let i = x0; i <= x1; i++) for (let j = z0; j <= z1; j++) {
25
26
  const k = i * KEY + j; let c = this.cells.get(k); if (!c) this.cells.set(k, c = []); c.push(item);
26
27
  }
27
28
  }
28
29
  remove(item) {
29
- const bi = this.big.indexOf(item); if (bi >= 0) { this.big.splice(bi, 1); return; }
30
+ if (this.big.delete(item)) return;
30
31
  const [x0, x1, z0, z1] = cellRange(item);
31
32
  for (let i = x0; i <= x1; i++) for (let j = z0; j <= z1; j++) {
32
33
  const k = i * KEY + j, c = this.cells.get(k); if (!c) continue;
33
- c.splice(c.indexOf(item), 1); if (!c.length) this.cells.delete(k);
34
+ // swap-remove: order inside a cell does not matter (query sorts by insertion order), and splice shifted the rest of a crowded cell every time
35
+ const at = c.indexOf(item); if (at < 0) continue;
36
+ c[at] = c[c.length - 1]; c.pop(); if (!c.length) this.cells.delete(k);
34
37
  }
35
38
  }
36
39
  /** Colliders intersecting the circle at (x, z) with radius range (exactly filtered, sorted). The returned array is reused by the next query, do not keep it */
37
40
  query(x, z, range) {
38
41
  const out = this.out; out.length = 0;
39
42
  const st = ++this.stamp;
40
- const big = this.big;
41
- for (let i = 0; i < big.length; i++) take(out, big[i], x, z, range, st);
43
+ for (const it of this.big) take(out, it, x, z, range, st);
42
44
  const x0 = Math.floor((x - range) / CELL), x1 = Math.floor((x + range) / CELL), z0 = Math.floor((z - range) / CELL), z1 = Math.floor((z + range) / CELL);
43
45
  for (let i = x0; i <= x1; i++) for (let j = z0; j <= z1; j++) {
44
46
  const c = this.cells.get(i * KEY + j);
@@ -1,9 +1,9 @@
1
1
  // Content's contribution to thing.explain(): rules read from the thing's template (collide, static, interact), which win over the world record's own.
2
- const safe = f => { try { return f(); } catch { return null; } };
2
+ import { orNull } from '../../core/util.js';
3
3
 
4
4
  /** @internal */
5
5
  export function contentExplain(e, t, out) {
6
- const def = t.template ? safe(() => e.content.template(t.template)) : null;
6
+ const def = t.template ? orNull(() => e.content.template(t.template)) : null;
7
7
  if (!def) return;
8
8
  Object.assign(out.rules, {
9
9
  blocksMovement: def.collide ?? false, pickable: def.static !== false,
@@ -0,0 +1,102 @@
1
+ // Field descriptions of content entries: one table per entry shape, in the core/params.js spec format (no second format).
2
+ // Three sources, one result (engine.content.fields(), content-check, the template loader all go through here):
3
+ // 1. placement fields of the engine's files (rules.js PLACEMENT_FIELDS: props, props.template, props.grid, pickups, views)
4
+ // 2. a template's state fields: the default is the value in state (the one place it is written), the type is inferred from it; the template's
5
+ // optional `fields` adds range / values / desc: crop: { state: { stage: 0 }, fields: { stage: { type: 'int', min: 0, max: 4 } } }
6
+ // 3. a game kind's `fields` (rules.js kinds.<name>.fields): the keys of each entry of content/<name>.js
7
+ // Why `default` is refused inside fields: a default written twice (state and fields) drifts; the value in state / the data is the only one.
8
+ // Node-safe (no three): packages/tools/content-check imports this file directly.
9
+ import { PLACEMENT_FIELDS } from './rules.js';
10
+ import { parseSpec, whyBad } from '../../core/params.js';
11
+ import { closest, fmt } from '../../core/validate.js';
12
+
13
+ const STRINGS = {
14
+ noDefault: "{where}: fields.{key} has a default; defaults live only in {home} (one place), fields hold only type, min, max, values, desc",
15
+ notState: "{where}: fields.{key} names no state field{hint}; fields describe the keys of state ({list})",
16
+ stateBad: '{where}: state.{key} = {got} does not fit fields.{key}: {why}',
17
+ unknown: "{where}: unknown field '{key}'{hint}. Fields: {list}",
18
+ bad: '{where}: {key} {why}',
19
+ required: '{where}: {key} is required',
20
+ reserved: "{where}: state.{key} is a world record field of every instance (id, kind, position): rename the state field",
21
+ };
22
+ // state is spread onto the instance record after id / kind / position, so a state field with one of these names silently overwrote it
23
+ const RECORD_KEYS = ['id', 'kind', 'position'];
24
+ const hintOf = (k, list) => { const c = closest(k, list); return c ? ` (did you mean '${c}'?)` : ''; };
25
+
26
+ /** The spec type a value has, so a state default needs no written type ('number' for any number: an int default may still take 2.5) */
27
+ function typeOf(v) {
28
+ if (typeof v === 'boolean') return 'bool';
29
+ if (typeof v === 'number') return 'number';
30
+ if (typeof v === 'string') return 'string';
31
+ if (Array.isArray(v)) return 'array';
32
+ if (v && typeof v === 'object') return 'object';
33
+ return 'any';
34
+ }
35
+
36
+ /** Parse a whole table, collecting problems instead of throwing (content-check wants every message, the engine throws the first) */
37
+ function parseAll(where, specs, problems) {
38
+ const out = {};
39
+ for (const [key, spec] of Object.entries(specs)) {
40
+ try { out[key] = parseSpec(where, key, spec, msg => new Error(msg)); } catch (err) { problems.push(err.message); }
41
+ }
42
+ return out;
43
+ }
44
+
45
+ const placementCache = new Map();
46
+ /** Parsed placement fields of an engine entry shape ('props', 'props.template', 'props.grid', 'pickups', 'views'), or null */
47
+ export function placementShape(shape) {
48
+ if (!PLACEMENT_FIELDS[shape]) return null;
49
+ if (!placementCache.has(shape)) placementCache.set(shape, parseAll(`content ${shape}`, PLACEMENT_FIELDS[shape], []));
50
+ return placementCache.get(shape);
51
+ }
52
+
53
+ /**
54
+ * A content `fields` table (template or game kind) -> { shape, problems }. With state (a template): every key must be a state key, the type is
55
+ * inferred from the state value when not written, the state value must fit; state keys without an entry get { type: inferred }.
56
+ * @param {string} where e.g. "template 'crop'" or "kind 'recipes'"
57
+ * @param {Record<string, any> | undefined} fields
58
+ * @param {Record<string, any> | null} [state]
59
+ */
60
+ export function fieldsShape(where, fields, state = null) {
61
+ const problems = [], specs = {}, home = state ? 'state' : 'the data itself (or the code that reads it)';
62
+ const stateKeys = state ? Object.keys(state) : null;
63
+ if (fields !== undefined && (!fields || typeof fields !== 'object' || Array.isArray(fields))) return { shape: {}, problems: [`${where}: fields must be an object { key: 'int?' | { type, min, max, values, desc } }`] };
64
+ for (const [key, spec] of Object.entries(fields || {})) {
65
+ if (stateKeys && !stateKeys.includes(key)) { problems.push(fmt(STRINGS.notState, { where, key, hint: hintOf(key, stateKeys), list: stateKeys.join(', ') || 'none' })); continue; }
66
+ if (spec && typeof spec === 'object' && 'default' in spec) { problems.push(fmt(STRINGS.noDefault, { where, key, home })); continue; }
67
+ // a template may leave the type out ({ min: 0, max: 4 }): it is the state value's type
68
+ specs[key] = state && spec && typeof spec === 'object' && !('type' in spec) ? { type: typeOf(state[key]), ...spec } : spec;
69
+ }
70
+ for (const key of stateKeys || []) if (RECORD_KEYS.includes(key)) problems.push(fmt(STRINGS.reserved, { where, key }));
71
+ for (const key of stateKeys || []) specs[key] ??= { type: typeOf(state[key]), optional: true };
72
+ const shape = parseAll(where, specs, problems);
73
+ for (const key of stateKeys || []) {
74
+ if (!shape[key]) continue;
75
+ shape[key].optional = true; // a placement may leave any state field out: the state value fills it
76
+ const why = whyBad(shape[key], state[key]);
77
+ if (why) problems.push(fmt(STRINGS.stateBad, { where, key, got: JSON.stringify(state[key]), why }));
78
+ }
79
+ return { shape, problems };
80
+ }
81
+
82
+ /**
83
+ * Problems of one entry against a parsed shape: unknown keys (with the closest name), values of the wrong type, out of range or not in values,
84
+ * and (required: true) missing non-optional keys. Returns messages; an empty list = fine.
85
+ * @param {string} where e.g. 'prop #3'
86
+ * @param {Record<string, any>} entry
87
+ * @param {Record<string, any>} shape
88
+ * @param {{ required?: boolean, also?: Record<string, any> }} [opts] also: more parsed fields allowed on this entry (a template's state fields)
89
+ */
90
+ export function entryProblems(where, entry, shape, { required = false, also = null } = {}) {
91
+ const all = also ? { ...shape, ...also } : shape, keys = Object.keys(all), out = [];
92
+ if (!entry || typeof entry !== 'object') return out;
93
+ for (const [key, v] of Object.entries(entry)) {
94
+ const s = all[key];
95
+ if (!s) { out.push(fmt(STRINGS.unknown, { where, key, hint: hintOf(key, keys), list: keys.join(', ') })); continue; }
96
+ if (v === undefined) continue;
97
+ const why = whyBad(s, v);
98
+ if (why) out.push(fmt(STRINGS.bad, { where, key, why }));
99
+ }
100
+ if (required) for (const key of keys) if (!all[key].optional && entry[key] === undefined) out.push(fmt(STRINGS.required, { where, key }));
101
+ return out;
102
+ }
@@ -8,6 +8,7 @@
8
8
  // Two entries with the same id in one load are an error with the fix. Source lines ("defined in content/props.js:14") come from the dev-only
9
9
  // line tables of packages/tools/vite/vite-threedog-content-src.js (srcOf); a release build has none.
10
10
  import { DEV, warnOnce, fmt } from '../../core/validate.js';
11
+ import { codedError } from '../../core/errorHints.js';
11
12
 
12
13
  const STRINGS = {
13
14
  badId: 'content: id "{id}" ({what}) may not contain "#" or "/": "#" is for records made during play and "/" for level-model nodes. Write it with - _ . or :, e.g. "{fix}"',
@@ -32,8 +33,9 @@ const tableOf = v => (DEV && v && typeof v === 'object' && globalThis.__threedog
32
33
  * @internal
33
34
  */
34
35
  export function srcOf(container, key) {
35
- const t = tableOf(container);
36
- return t ? `${t.file}:${t.at[key] ?? t.line}` : null;
36
+ const t = tableOf(container), a = t?.at[key];
37
+ if (typeof a === 'string') return a; // a kind joined from several files (parts.js): each entry names its own file
38
+ return t ? `${t.file}:${a ?? t.line}` : null;
37
39
  }
38
40
 
39
41
  /** Per content.load: catches duplicate ids across props, pickups, NPCs, containers and grid items, and collects stateful entries without an id @internal */
@@ -41,9 +43,9 @@ export class IdCheck {
41
43
  constructor() { this.seen = new Map(); this.missing = []; }
42
44
  /** An authored id: format check, and an error if this load already used it @param {string} id @param {string} what e.g. "props[3] (template chest)" */
43
45
  claim(id, what) {
44
- if (typeof id === 'string' && /[#/]/.test(id)) throw new Error(fmt(STRINGS.badId, { id, what, fix: id.replace(/[#/]/g, '-') }));
46
+ if (typeof id === 'string' && /[#/]/.test(id)) throw codedError('content-id', fmt(STRINGS.badId, { id, what, fix: id.replace(/[#/]/g, '-') }));
45
47
  const a = this.seen.get(id);
46
- if (a) throw new Error(fmt(STRINGS.dup, { id, a, b: what }));
48
+ if (a) throw codedError('content-id', fmt(STRINGS.dup, { id, a, b: what }));
47
49
  this.seen.set(id, what);
48
50
  }
49
51
  /** A stateful entry relies on its index id */
@@ -65,8 +67,8 @@ export class IdCheck {
65
67
  */
66
68
  export function applyRenames(e, map) {
67
69
  for (const [a, b] of Object.entries(map || {})) {
68
- if (b !== null && typeof b !== 'string') throw new Error(fmt(RENAME_STRINGS.shape, { id: a, got: JSON.stringify(b) }));
69
- if (typeof b === 'string' && b.includes('#')) throw new Error(fmt(RENAME_STRINGS.badTarget, { a, b }));
70
+ if (b !== null && typeof b !== 'string') throw codedError('content-id', fmt(RENAME_STRINGS.shape, { id: a, got: JSON.stringify(b) }));
71
+ if (typeof b === 'string' && b.includes('#')) throw codedError('content-id', fmt(RENAME_STRINGS.badTarget, { a, b }));
70
72
  }
71
73
  const stuck = e.world?.renameIds(map) ?? [];
72
74
  e.inventory?.renameIds(map);
@@ -1,16 +1,16 @@
1
- // Content loader: hands the plain data in the game's content/*.js to the engine (items, pickups, vegetation, NPCs, dialogues, quests, key actions, trigger
2
- // zones, props).
1
+ // Content loader: game data files into the engine.
2
+ // It hands the plain data in content/*.js to the modules (items, pickups, vegetation, NPCs, dialogues, quests, key actions, trigger zones, props).
3
3
  // engine.use(content());
4
4
  // engine.assets.manifest(yourAssets); // models content names (an asset pack; content never holds paths or code)
5
5
  // engine.content.load(data, { places: { home: { x, z } } }); // or several packs at once: load([base, dlc, level]) (packs.js)
6
6
  // Condition/effect vocabulary is in rules.js. Games add condition words (content/rules.js, or content.condition(name, { test }) in code);
7
7
  // a game's own actions are ops, called from content with { op: ['noun.verb', args] } and tested with { can: [...] }.
8
8
  // Op names used in content are checked when the game becomes ready (did you mean...).
9
- // Templates (content/templates.js): reusable objects placed from props.js ({ template, x, z }) or engine.spawn; see templates.js.
9
+ // Templates (content/templates.js): reusable objects placed from props.js ({ template, x, z }) or engine.content.spawn; see templates.js.
10
10
  // Props (content/props.js) and pickups (pickups.js) are stored in engine.world (requires world(); openWorld() includes it; see props.js for the stable id
11
11
  // rule),
12
12
  // models and collision are built only near the focus; move / remove with engine.world.move / remove, saved with the save. Procedural models of vegetation and
13
- // props go through engine.assets.cached (name = model name):
13
+ // props go through core/namedModel.js protoOf (name = model name; the same path pickups and vegetation use):
14
14
  // baked files from npm run bake are read from file, otherwise cached automatically in dev. Models arrive asynchronously: the loading screen of start() waits
15
15
  // for them (isReady) before the game counts as ready.
16
16
  // Repeated load: a quest's startOn and a trigger's enter/exit effects do not attach listeners twice (the later load overrides the same name).
@@ -28,6 +28,10 @@ import { templateOf, spawnTemplate, placeTemplate } from './templates.js';
28
28
  import { packsOf } from './packs.js';
29
29
  import { placeY } from '../../core/ground.js';
30
30
  import { IdCheck } from './ids.js';
31
+ import { PLACEMENT_FIELDS } from './rules.js';
32
+ import { placementShape, fieldsShape } from './fields.js';
33
+ import { schemaInfo } from '../../core/params.js';
34
+ import { codedError } from '../../core/errorHints.js';
31
35
 
32
36
  export function content() {
33
37
  let e = null, places = {};
@@ -35,21 +39,35 @@ export function content() {
35
39
  const pending = new Set();
36
40
  const st = {
37
41
  triggers: {}, subs: null, startOn: new Map(), ops: new Set(), kinds: {},
42
+ marks: new Map(), // marker id -> [position, label]: what the marker effect shows (the content save part)
38
43
  templates: new Map(), templateViews: new Set(), // template name -> frozen definition; names whose presenter is registered
44
+ templateSims: new Set(), // names whose world.simulate (stages / update) is registered
39
45
  templateSrc: new Map(), // dev: template name -> 'content/templates.js:12'
46
+ templateFields: new Map(), // template name -> parsed state fields (fields.js), for placement checks and content.fields()
40
47
  levelPlace: name => !!name && !(name in places) && !!e.level?.marker(name),
41
48
  wait: p => { pending.add(p); p.catch(err => reportError(e, err, 'content model', { soft: true })).finally(() => pending.delete(p)); },
42
49
  };
43
50
  const conds = new Map(Object.entries(CONDITIONS).map(([k, d]) => [k, { ...d, test: BUILTIN_TESTS[k] }]));
44
51
  const effects = new Map(Object.entries(EFFECTS).map(([k, d]) => [k, { ...d, run: BUILTIN_RUNS[k] }]));
45
52
  // convert content notation to runtime values by ref (clock time -> fraction, place -> { x, z })
46
- const norm = (ref, v) => ref === 'clock' ? parseClock(v, e.sky?.hoursPerDay ?? 24) : ref === 'position' ? api.where(typeof v === 'string' ? { place: v } : v) : v;
53
+ const norm = (ref, v) => ref === 'clock' ? parseClock(v, e.calendar?.hoursPerDay ?? 24) : ref === 'position' ? api.where(typeof v === 'string' ? { place: v } : v) : v;
47
54
 
48
55
  const api = {
49
56
  /** All vegetation models are ready and the models of nearby world data such as props are built (world.ready) */
50
57
  get ready() { return pending.size === 0 && (!e.world || e.world.ready); },
51
58
  /** marker markers added by the marker effect: id -> hud marker */
52
59
  markers: new Map(),
60
+ /**
61
+ * @internal the marker / clearMarker effects: set (v = position) or clear (v = null) marker id. What is shown is playthrough state, kept in
62
+ * the 'content' save part, so a load shows the save's markers and a new game none of the old ones (review 0.4 modules-a B5)
63
+ */
64
+ _mark(id, v, label) {
65
+ api.markers.get(id)?.remove(); api.markers.delete(id); st.marks.delete(id);
66
+ if (!v) return;
67
+ st.marks.set(id, [v, label ?? null]);
68
+ const m = e.hud?.marker(v, { label });
69
+ if (m) api.markers.set(id, m);
70
+ },
53
71
  /**
54
72
  * Load content data: one pack (the object of content/index.js) or a list of packs loaded together in order, where an id defined by two packs is an error
55
73
  * (packs.js).
@@ -68,24 +86,37 @@ export function content() {
68
86
  },
69
87
  /** Register a condition word: condition('timeAfter', { ref: 'clock', desc, test: (e, value) => ... }) */
70
88
  condition(name, def) { conds.set(name, def); return api; },
71
- /** Whether a condition holds (object = all listed items hold, array = every item holds, function = called directly) */
72
- test(c) {
89
+ /**
90
+ * Whether a condition holds (object = all listed items hold, array = every item holds, function = called directly as fn(e, { actor })).
91
+ * actor: whose bag { has } / { lacks } look in (default: the running op's actor, else engine.actor), so a net peer's dialogue checks the peer's bag.
92
+ * @example engine.content.test({ has: { berry: 3 } }, { actor: 'peer-2' })
93
+ * @param {any} c
94
+ * @param {{ actor?: string }} [opts]
95
+ */
96
+ test(c, { actor = e.ops.actor } = {}) {
73
97
  if (!c) return true;
74
- if (typeof c === 'function') return !!c(e);
98
+ const ctx = { actor };
99
+ if (typeof c === 'function') return !!c(e, ctx);
75
100
  return list(c).every(x => Object.entries(x).every(([k, v]) => {
76
101
  const d = conds.get(k);
77
102
  if (!d) { warnMissing('condition', k, [...conds.keys()]); return false; }
78
- return !!d.test(e, norm(d.ref, v), v);
103
+ return !!d.test(e, norm(d.ref, v), v, ctx);
79
104
  }));
80
105
  },
81
- /** Run an effect (object, array or function) */
82
- run(a) {
106
+ /**
107
+ * Run an effect (object, array or function fn(e, { actor })). actor: whose bag { give } / { take } change (default: the running op's actor, else
108
+ * engine.actor), so a reward lands in the bag of whoever earned it.
109
+ * @param {any} a
110
+ * @param {{ actor?: string }} [opts]
111
+ */
112
+ run(a, { actor = e.ops.actor } = {}) {
83
113
  if (!a) return;
84
- if (typeof a === 'function') return a(e);
114
+ const ctx = { actor };
115
+ if (typeof a === 'function') return a(e, ctx);
85
116
  for (const x of list(a)) for (const [k, v] of Object.entries(x)) {
86
117
  const d = effects.get(k);
87
118
  if (!d) { warnMissing('effect', k, [...effects.keys()]); continue; }
88
- d.run(e, norm(d.ref, v), v);
119
+ d.run(e, norm(d.ref, v), v, ctx);
89
120
  }
90
121
  },
91
122
  /**
@@ -95,11 +126,52 @@ export function content() {
95
126
  * @returns {Readonly<Record<string, any>>}
96
127
  */
97
128
  template(name) { return templateOf(st, name); },
129
+ /**
130
+ * Place a new instance of a content template at runtime (a gameplay change: call it inside an op or a fixed step); saved whole.
131
+ * Returns the world record (kind = template name; without fields.id the id is numbered `<template>#<n>`, e.g. 'chest#3').
132
+ * at is a ground position ({ x, z }, [x, y, z] or an object); fields may set id, rot, scale, y (height above ground), items (container start goods)
133
+ * and the template's state fields (stage too, for a template with stages).
134
+ * @example engine.ops.define('chest.build', { run: (e, { x, z }) => e.content.spawn('chest', { x, z }, { items: { stick: 3 } }).id });
135
+ * @param {string} name
136
+ * @param {any} at
137
+ * @param {{ id?: string, rot?: number, scale?: number, y?: number, items?: Record<string, number>, [state: string]: any }} [fields]
138
+ * @returns {import('../world/World.js').WorldRecord}
139
+ */
140
+ spawn(name, at, fields) { return spawnTemplate(e, st, name, at, fields); },
98
141
  /**
99
142
  * @internal A level-model node with the custom property template: an authored instance with id `<level>/<node>` (level module).
100
143
  * entry is a props-style entry ({ template, id, x, z, floor, rot, scale, state fields }); origin = { level, node }
101
144
  */
102
145
  placeNode(entry, zone, origin) { placeTemplate(e, api, st, entry, 0, zone, null, origin); },
146
+ /**
147
+ * The fields one content entry may have, in the core/params.js format ({ key: { type, optional?, default?, min?, max?, values?, desc? } }):
148
+ * what an editor panel lists and what content-check validates against (one table, rules.js PLACEMENT_FIELDS + the template / kind `fields`).
149
+ * name: a template name (its placement fields plus its state fields; default = the value in state), an engine entry shape
150
+ * ('props', 'props.template', 'props.grid', 'pickups', 'views'), a game kind with fields (content/rules.js kinds), or a world record id
151
+ * (answers for the shape that record came from).
152
+ * @example engine.content.fields('crop').stage // { type: 'int', optional: true, default: 0, min: 0, max: 4 }
153
+ * @example engine.content.fields('props').rot // { type: 'number', optional: true, desc: 'facing around the vertical axis, radians' }
154
+ * @param {string} name
155
+ * @returns {Record<string, { type: string, optional?: boolean, default?: any, min?: number, max?: number, values?: any[], desc?: string }>}
156
+ */
157
+ fields(name) {
158
+ if (st.templates.has(name)) {
159
+ const state = st.templates.get(name).state ?? {}, own = schemaInfo(st.templateFields.get(name));
160
+ for (const k in own) own[k].default = structuredClone(state[k]); // the default is the state value: written once, in state
161
+ return { ...schemaInfo(placementShape('props.template')), ...own };
162
+ }
163
+ if (PLACEMENT_FIELDS[name]) return schemaInfo(placementShape(name));
164
+ const kind = st.kinds[name];
165
+ if (kind?.fields) {
166
+ const { shape, problems } = fieldsShape(`kind '${name}'`, kind.fields);
167
+ if (problems.length) throw codedError('content-misuse', problems.join('; '));
168
+ return schemaInfo(shape);
169
+ }
170
+ const rec = e.world?.get(name);
171
+ if (rec) return api.fields(rec.kind === 'prop' ? 'props' : rec.kind === 'pickup' ? 'pickups' : rec.kind);
172
+ const known = [...st.templates.keys(), ...Object.keys(PLACEMENT_FIELDS), ...Object.keys(st.kinds).filter(k => st.kinds[k]?.fields)];
173
+ throw codedError('unknown-name', `content.fields: ${missingText('field table', name, known)} (a template name, ${Object.keys(PLACEMENT_FIELDS).join(' / ')}, a game kind with fields, or a world record id)`);
174
+ },
103
175
  /** @internal dev: where a template is defined ('content/templates.js:12'), null if unknown */
104
176
  templateSource(name) { return st.templateSrc.get(name) ?? null; },
105
177
  /** Place name -> position { x, z } plus y when the place has a height (level markers, places given with y); null if not found */
@@ -116,7 +188,7 @@ export function content() {
116
188
  */
117
189
  where(p) {
118
190
  const base = p.place ? api.place(p.place) : null;
119
- if (p.place && !base) throw new Error(`Place "${p.place}" not found: give its coordinates in the places of content.load, or add this marker to the level`);
191
+ 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`);
120
192
  const x = (base?.x ?? 0) + (p.x ?? 0), z = (base?.z ?? 0) + (p.z ?? 0), floor = p.floor ?? base?.y;
121
193
  if (floor === undefined && p.y === undefined) return { x, z };
122
194
  return { x, y: placeY(e, `content.where(${JSON.stringify(p.place ?? { x: p.x, z: p.z })})`, x, z, floor) + (p.y ?? 0), z };
@@ -125,24 +197,21 @@ export function content() {
125
197
  _floorOf(p) { return p.floor ?? (p.place ? api.place(p.place)?.y : undefined); },
126
198
  };
127
199
  return {
128
- name: 'content', label: 'Content',
129
- optional: ['level', 'sky', 'inventory', 'quests', 'particles', 'hud', 'vegetation', 'dialogue', 'triggers', 'collision', 'world', 'interactions', 'grids', 'rigid'],
130
- install(engine) {
200
+ name: 'content', type: 'rules', label: 'Content',
201
+ optional: ['level', 'calendar', 'inventory', 'pickups', 'quests', 'particles', 'hud', 'vegetation', 'dialogue', 'triggers', 'collision', 'world', 'interactions', 'grids', 'rigid'],
202
+ install(engine, ctx) { engine.i18n.add({ 'zh-CN': { 'module.content': '内容' }, en: { 'module.content': 'content' } });
131
203
  e = engine;
204
+ st.track = ctx.track; // loader.js subscribes on the first content.load: those listeners belong to the module too
132
205
  engine.explainWith(contentExplain);
133
- /**
134
- * Place a new instance of a content template at runtime (a gameplay change: call it inside an op or a fixed step); saved whole.
135
- * Returns the world record (kind = template name). at is a ground position ({ x, z }, [x, y, z] or an object);
136
- * fields may set id, rot, scale, y (height above ground), items (container start goods) and the template's state fields.
137
- * Installed by content(), so it exists once the content module is used.
138
- * @example engine.ops.define('chest.build', { run: (e, { x, z }) => e.spawn('chest', { x, z }, { items: { stick: 3 } }).id });
139
- */
140
- e.spawn = (name, at, fields) => spawnTemplate(e, st, name, at, fields);
206
+ e.saves.register('content', {
207
+ save: () => ({ marks: [...st.marks].map(([id, [v, label]]) => [id, v, label]) }),
208
+ load: d => { for (const id of [...st.marks.keys()]) api._mark(id, null); for (const [id, v, label] of d?.marks || []) api._mark(id, v, label ?? undefined); },
209
+ });
141
210
  // content may name ops that main.js defines after load: check once everything is set up, and again for loads after that
142
211
  const check = () => {
143
- for (const name of st.ops) if (!e.ops.defs.has(name)) throw new Error(`content: ${missingText('op', name, [...e.ops.defs.keys()])} (used in { op } / { can })`);
212
+ for (const name of st.ops) if (!e.ops.defs.has(name)) throw codedError('unknown-name', `content: ${missingText('op', name, [...e.ops.defs.keys()])} (used in { op } / { can })`);
144
213
  };
145
- e.events.on('engine:ready', check);
214
+ ctx.track(e.events.on('engine:ready', check));
146
215
  st.checkOps = () => { if (e.ready) check(); };
147
216
  return api;
148
217
  },