threedog 0.2.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (725) hide show
  1. package/CHANGELOG.md +371 -1
  2. package/README.md +21 -12
  3. package/core/Animator.js +15 -12
  4. package/core/Assets.js +92 -26
  5. package/core/Audio.js +45 -38
  6. package/core/Baked.js +30 -15
  7. package/core/Batching.js +102 -15
  8. package/core/Budget.js +40 -19
  9. package/core/Clock.js +40 -80
  10. package/core/DebugOverrides.js +75 -25
  11. package/core/Describe.js +105 -45
  12. package/core/Engine.js +203 -75
  13. package/core/Events.js +4 -1
  14. package/core/I18n.js +25 -13
  15. package/core/Input.js +175 -80
  16. package/core/Inspect.js +8 -5
  17. package/core/InspectMaterials.js +84 -0
  18. package/core/InspectPerf.js +68 -0
  19. package/core/InspectScene.js +13 -2
  20. package/core/Loading.js +2 -1
  21. package/core/MaterialInfo.js +7 -5
  22. package/core/Ops.js +50 -9
  23. package/core/Random.js +9 -2
  24. package/core/Rays.js +12 -7
  25. package/core/SaveStore.js +41 -9
  26. package/core/Saves.js +71 -15
  27. package/core/Stream.js +13 -10
  28. package/core/Threads.js +26 -7
  29. package/core/UrlState.js +69 -13
  30. package/core/Views.js +10 -6
  31. package/core/actor.js +1 -1
  32. package/core/adaptive.js +93 -0
  33. package/core/assetEntry.js +27 -7
  34. package/core/assetHot.js +176 -0
  35. package/core/assetLoad.js +44 -19
  36. package/core/assetManifest.js +53 -11
  37. package/core/assetReport.js +5 -5
  38. package/core/audioRules.js +13 -11
  39. package/core/audioVoice.js +69 -42
  40. package/core/batchGroups.js +9 -1
  41. package/core/canvasBox.js +1 -2
  42. package/core/catalog.js +21 -5
  43. package/core/cells.js +62 -0
  44. package/core/checks.js +10 -8
  45. package/core/chunkStream.js +87 -0
  46. package/core/control.js +149 -0
  47. package/core/copies.js +32 -0
  48. package/core/dayTime.js +12 -6
  49. package/core/debugView.js +85 -18
  50. package/core/describeRender.js +117 -21
  51. package/core/describeText.js +41 -21
  52. package/core/engineCamera.js +32 -0
  53. package/core/errorCodes.js +478 -32
  54. package/core/errorHints.js +41 -142
  55. package/core/errors.js +31 -8
  56. package/core/events.generated.js +13 -7
  57. package/core/gameLights.js +69 -0
  58. package/core/grayMap.js +20 -0
  59. package/core/grid.js +14 -13
  60. package/core/gridLoad.js +2 -1
  61. package/core/ground.js +6 -4
  62. package/core/headlessLoad.js +55 -0
  63. package/core/holds.js +78 -50
  64. package/core/inputContext.js +11 -7
  65. package/core/inputDefaults.js +24 -21
  66. package/core/inputPad.js +1 -1
  67. package/core/inputPointer.js +1 -1
  68. package/core/inputTouch.js +2 -2
  69. package/core/lifecycle.js +46 -12
  70. package/core/lightWatch.js +9 -5
  71. package/core/loop.js +109 -43
  72. package/core/math.js +18 -3
  73. package/core/moduleSlots.js +100 -0
  74. package/core/moduleTypes.js +86 -0
  75. package/core/modules.js +147 -29
  76. package/core/movement.js +2 -2
  77. package/core/namedModel.js +74 -0
  78. package/core/opsCheck.js +3 -3
  79. package/core/opsFail.js +15 -6
  80. package/core/opsGuard.js +4 -4
  81. package/core/opsRun.js +4 -3
  82. package/core/owned.js +171 -0
  83. package/core/page.js +44 -10
  84. package/core/params.js +30 -8
  85. package/core/pictureSlots.js +33 -0
  86. package/core/pictureWriters.js +343 -0
  87. package/core/plugins.js +245 -0
  88. package/core/saveApply.js +99 -17
  89. package/core/saveFiles.js +8 -6
  90. package/core/saveValues.js +46 -0
  91. package/core/saveVersions.js +20 -3
  92. package/core/scatter.js +48 -19
  93. package/core/sceneDelta.js +211 -0
  94. package/core/sceneMethods.js +31 -33
  95. package/core/screenToGround.js +1 -1
  96. package/core/services.js +27 -11
  97. package/core/session.js +28 -25
  98. package/core/shaderCost.js +78 -0
  99. package/core/shadowTypes.js +3 -2
  100. package/core/shadows.js +405 -0
  101. package/core/sharedPoint.js +303 -0
  102. package/core/skip.js +36 -28
  103. package/core/stackFrames.js +45 -0
  104. package/core/stacks.js +166 -0
  105. package/core/startup.js +153 -13
  106. package/core/streamSources.js +0 -11
  107. package/core/targeting.js +1 -1
  108. package/core/textureBytes.js +20 -0
  109. package/core/thingExplain.js +3 -3
  110. package/core/thingOps.js +29 -6
  111. package/core/things.js +22 -12
  112. package/core/threadPure.js +7 -3
  113. package/core/threePatches.js +47 -0
  114. package/core/tier.js +21 -10
  115. package/core/time.js +236 -0
  116. package/core/uiClock.js +25 -0
  117. package/core/util.js +8 -2
  118. package/core/validate.js +66 -87
  119. package/core/view.js +43 -0
  120. package/core/wrap.js +106 -0
  121. package/docs/AI.md +95 -104
  122. package/docs/API.md +35 -31
  123. package/docs/CODEMAP.md +231 -176
  124. package/docs/COMMANDS.md +63 -39
  125. package/docs/CONVENTIONS.md +99 -31
  126. package/docs/MIGRATING-0.3.md +248 -0
  127. package/docs/MIGRATING-0.4.md +320 -0
  128. package/docs/MIGRATING-0.5.md +68 -0
  129. package/docs/MIGRATING-0.6.md +126 -0
  130. package/docs/MIGRATING-0.7.md +39 -0
  131. package/docs/PERF.md +35 -7
  132. package/docs/THREE.md +82 -28
  133. package/docs/api/ambience.md +0 -1
  134. package/docs/api/assets.md +15 -11
  135. package/docs/api/audio.md +10 -14
  136. package/docs/api/budget.md +4 -0
  137. package/docs/api/calendar.md +41 -0
  138. package/docs/api/cameraRig.md +16 -5
  139. package/docs/api/characters.md +41 -24
  140. package/docs/api/clock.md +6 -5
  141. package/docs/api/collision.md +10 -7
  142. package/docs/api/content.md +6 -4
  143. package/docs/api/dialogue.md +9 -9
  144. package/docs/api/engine.md +95 -65
  145. package/docs/api/events.md +20 -14
  146. package/docs/api/grids.md +10 -3
  147. package/docs/api/ground.md +1 -1
  148. package/docs/api/hud.md +5 -2
  149. package/docs/api/i18n.md +1 -1
  150. package/docs/api/input.md +13 -7
  151. package/docs/api/interactions.md +10 -6
  152. package/docs/api/inventory.md +17 -17
  153. package/docs/api/level.md +0 -2
  154. package/docs/api/lightPool.md +3 -1
  155. package/docs/api/music.md +1 -1
  156. package/docs/api/nav.md +3 -0
  157. package/docs/api/occlusion.md +5 -0
  158. package/docs/api/openWorld.md +2 -1
  159. package/docs/api/particles.md +6 -3
  160. package/docs/api/photo.md +0 -2
  161. package/docs/api/pickups.md +21 -0
  162. package/docs/api/post.md +8 -5
  163. package/docs/api/quests.md +2 -3
  164. package/docs/api/rigid.md +16 -14
  165. package/docs/api/saves.md +6 -4
  166. package/docs/api/settings.md +2 -3
  167. package/docs/api/sky.md +18 -49
  168. package/docs/api/stream.md +1 -1
  169. package/docs/api/terrain.md +16 -7
  170. package/docs/api/terrainDraw.md +12 -0
  171. package/docs/api/timeline.md +3 -4
  172. package/docs/api/tools.md +32 -15
  173. package/docs/api/triggers.md +7 -10
  174. package/docs/api/vegetation.md +17 -9
  175. package/docs/api/vegetationDraw.md +10 -0
  176. package/docs/api/water.md +9 -21
  177. package/docs/api/weather.md +10 -15
  178. package/docs/api/weatherDraw.md +10 -0
  179. package/docs/api/world.md +3 -2
  180. package/docs/recipes/01-new-game.md +52 -42
  181. package/docs/recipes/02-npc.md +24 -7
  182. package/docs/recipes/03-items-pickups.md +57 -22
  183. package/docs/recipes/04-quests.md +12 -5
  184. package/docs/recipes/05-props-bake.md +174 -22
  185. package/docs/recipes/06-clock-events.md +100 -52
  186. package/docs/recipes/07-flow-scenes-pause.md +50 -10
  187. package/docs/recipes/08-weather-sky.md +134 -37
  188. package/docs/recipes/09-materials-lights-models.md +185 -0
  189. package/docs/recipes/10-blender-level.md +16 -4
  190. package/docs/recipes/11-vehicles.md +67 -10
  191. package/docs/recipes/13-animation.md +23 -9
  192. package/docs/recipes/14-custom-module.md +63 -29
  193. package/docs/recipes/15-perf.md +31 -10
  194. package/docs/recipes/16-dev-bridge.md +74 -40
  195. package/docs/recipes/18-world.md +26 -14
  196. package/docs/recipes/19-shooting-picking.md +12 -10
  197. package/docs/recipes/20-content-actions-save.md +60 -18
  198. package/docs/recipes/21-camera.md +55 -17
  199. package/docs/recipes/22-shop-gold.md +3 -3
  200. package/docs/recipes/23-ops.md +17 -11
  201. package/docs/recipes/26-ui-parts.md +86 -13
  202. package/docs/recipes/27-net.md +11 -5
  203. package/docs/recipes/28-terrain.md +36 -3
  204. package/docs/recipes/29-grid.md +46 -19
  205. package/docs/recipes/30-templates.md +72 -15
  206. package/docs/recipes/31-audio.md +20 -12
  207. package/docs/recipes/32-action-game.md +51 -4
  208. package/docs/recipes/34-environment-lighting.md +108 -21
  209. package/docs/recipes/35-picture-from-reference.md +147 -0
  210. package/docs/recipes/36-sky-ground-plants.md +158 -0
  211. package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -12
  212. package/docs/recipes/38-environment-hooks.md +67 -0
  213. package/docs/recipes/40-scene.md +114 -32
  214. package/docs/recipes/42-terrain-shape.md +2 -2
  215. package/docs/recipes/43-shader-patches-surfaces.md +206 -0
  216. package/docs/recipes/44-water-weather-hooks.md +191 -0
  217. package/docs/recipes/45-cascaded-shadows.md +130 -23
  218. package/docs/recipes/46-blender-art-route.md +17 -20
  219. package/docs/recipes/47-island-snow-backdrop.md +13 -15
  220. package/docs/recipes/49-game-module-contract.md +30 -17
  221. package/docs/recipes/50-own-renderer.md +4 -4
  222. package/docs/recipes/51-capability-catalog.md +3 -3
  223. package/docs/recipes/52-around-the-picture.md +181 -0
  224. package/docs/recipes/53-ground-up-close.md +12 -12
  225. package/docs/recipes/54-three-idioms.md +88 -0
  226. package/docs/recipes/55-mods-time-wrap.md +124 -0
  227. package/docs/recipes/56-webgpu-tsl.md +303 -0
  228. package/docs/recipes/57-control.md +104 -0
  229. package/docs/recipes/58-input.md +60 -0
  230. package/docs/recipes/59-depth-post-effects.md +83 -0
  231. package/docs/recipes/60-judge-the-picture.md +70 -0
  232. package/docs/recipes/61-deploy.md +27 -0
  233. package/docs/recipes/62-picture-code.md +244 -0
  234. package/docs/recipes/63-third-person-start.md +77 -0
  235. package/docs/recipes/64-particles.md +35 -0
  236. package/examples/action/.threedog/content-index.json +1 -0
  237. package/examples/action/GAMEMAP.md +20 -14
  238. package/examples/action/assets.js +8 -0
  239. package/examples/action/content/actions.js +1 -1
  240. package/examples/action/content/audio.js +5 -5
  241. package/examples/action/main.js +12 -15
  242. package/examples/action/models.js +23 -24
  243. package/examples/action/picture/index.js +13 -0
  244. package/examples/action/picture/lights.js +35 -0
  245. package/examples/action/picture/materials.js +8 -0
  246. package/examples/action/picture/palette.js +33 -0
  247. package/examples/plain-picture/.threedog/content-index.json +1 -0
  248. package/examples/plain-picture/FINDINGS.md +53 -0
  249. package/examples/plain-picture/GAMEMAP.md +90 -0
  250. package/examples/plain-picture/main.js +48 -0
  251. package/examples/plain-picture/picture/index.js +21 -0
  252. package/examples/plain-picture/picture/lights.js +54 -0
  253. package/examples/plain-picture/picture/materials.js +24 -0
  254. package/examples/plain-picture/picture/palette.js +16 -0
  255. package/examples/plain-picture/picture/sky.js +37 -0
  256. package/examples/pullable.json +133 -0
  257. package/examples/rc2d/.threedog/content-index.json +1 -0
  258. package/examples/rc2d/GAMEMAP.md +88 -0
  259. package/examples/rc2d/README.md +57 -0
  260. package/examples/rc2d/main.js +55 -0
  261. package/examples/rc2d/picture/index.js +18 -0
  262. package/examples/rc2d/picture/lights.js +11 -0
  263. package/examples/rc2d/picture/materials.js +18 -0
  264. package/examples/rc2d/picture/palette.js +15 -0
  265. package/examples/rc2d/picture/post.js +11 -0
  266. package/examples/rc2d/rc2d.js +187 -0
  267. package/examples/rc2d/shaders.js +144 -0
  268. package/examples/sheepisland/.threedog/content-index.json +1 -0
  269. package/examples/sheepisland/GAMEMAP.md +22 -17
  270. package/examples/sheepisland/assets.js +5 -0
  271. package/examples/sheepisland/content/templates.js +1 -1
  272. package/examples/sheepisland/content/vegetation.js +3 -1
  273. package/examples/sheepisland/main.js +29 -18
  274. package/examples/sheepisland/{style/models.js → models.js} +13 -24
  275. package/examples/sheepisland/picture/index.js +20 -0
  276. package/examples/sheepisland/picture/lights.js +34 -0
  277. package/examples/sheepisland/picture/materials.js +61 -0
  278. package/examples/sheepisland/picture/palette.js +60 -0
  279. package/examples/sheepisland/picture/sky.js +20 -0
  280. package/examples/sheepisland/views.js +1 -1
  281. package/examples/styletest/.threedog/content-index.json +1 -0
  282. package/examples/styletest/GAMEMAP.md +25 -22
  283. package/examples/styletest/assets.js +6 -0
  284. package/examples/styletest/content/templates.js +1 -1
  285. package/examples/styletest/content/vegetation.js +1 -1
  286. package/examples/styletest/main.js +25 -34
  287. package/examples/styletest/models.js +30 -30
  288. package/examples/styletest/params.js +2 -5
  289. package/examples/styletest/picture/env.js +38 -0
  290. package/examples/styletest/picture/index.js +16 -0
  291. package/examples/styletest/picture/lights.js +9 -0
  292. package/examples/styletest/picture/materials.js +28 -0
  293. package/examples/styletest/picture/palette.js +22 -0
  294. package/examples/techniques/contact-shadows/README.md +91 -0
  295. package/examples/techniques/contact-shadows/contactShadows.js +67 -0
  296. package/examples/techniques/contact-shadows/main.js +55 -0
  297. package/examples/techniques/contact-shadows/picture/index.js +14 -0
  298. package/examples/techniques/contact-shadows/picture/lights.js +34 -0
  299. package/examples/techniques/contact-shadows/picture/materials.js +12 -0
  300. package/examples/techniques/contact-shadows/picture/palette.js +17 -0
  301. package/examples/techniques/day-night-grade/README.md +83 -0
  302. package/examples/techniques/day-night-grade/main.js +41 -0
  303. package/examples/techniques/day-night-grade/picture/index.js +20 -0
  304. package/examples/techniques/day-night-grade/picture/lights.js +45 -0
  305. package/examples/techniques/day-night-grade/picture/materials.js +15 -0
  306. package/examples/techniques/day-night-grade/picture/palette.js +59 -0
  307. package/examples/techniques/day-night-grade/picture/post.js +25 -0
  308. package/examples/techniques/day-night-grade/picture/sky.js +33 -0
  309. package/examples/techniques/interior-light/README.md +106 -0
  310. package/examples/techniques/interior-light/interiorLight.js +47 -0
  311. package/examples/techniques/interior-light/main.js +87 -0
  312. package/examples/techniques/interior-light/picture/index.js +24 -0
  313. package/examples/techniques/interior-light/picture/lights.js +52 -0
  314. package/examples/techniques/interior-light/picture/materials.js +13 -0
  315. package/examples/techniques/interior-light/picture/palette.js +32 -0
  316. package/examples/techniques/interior-light/picture/sky.js +40 -0
  317. package/examples/techniques/modular-building/README.md +126 -0
  318. package/examples/techniques/modular-building/kit.js +426 -0
  319. package/examples/techniques/modular-building/main.js +39 -0
  320. package/examples/techniques/modular-building/picture/index.js +17 -0
  321. package/examples/techniques/modular-building/picture/lights.js +26 -0
  322. package/examples/techniques/modular-building/picture/materials.js +13 -0
  323. package/examples/techniques/modular-building/picture/palette.js +23 -0
  324. package/examples/techniques/night-lights/README.md +95 -0
  325. package/examples/techniques/night-lights/main.js +47 -0
  326. package/examples/techniques/night-lights/nightLights.js +95 -0
  327. package/examples/techniques/night-lights/picture/index.js +18 -0
  328. package/examples/techniques/night-lights/picture/lights.js +44 -0
  329. package/examples/techniques/night-lights/picture/materials.js +15 -0
  330. package/examples/techniques/night-lights/picture/palette.js +34 -0
  331. package/examples/techniques/night-lights/picture/post.js +9 -0
  332. package/examples/techniques/night-lights/picture/sky.js +36 -0
  333. package/examples/techniques/outlines-and-rim/README.md +59 -0
  334. package/examples/techniques/outlines-and-rim/main.js +61 -0
  335. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  336. package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
  337. package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
  338. package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
  339. package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
  340. package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
  341. package/examples/techniques/procedural-animation/README.md +79 -0
  342. package/examples/techniques/procedural-animation/creature.js +44 -0
  343. package/examples/techniques/procedural-animation/main.js +47 -0
  344. package/examples/techniques/procedural-animation/picture/index.js +15 -0
  345. package/examples/techniques/procedural-animation/picture/lights.js +35 -0
  346. package/examples/techniques/procedural-animation/picture/materials.js +10 -0
  347. package/examples/techniques/procedural-animation/picture/palette.js +16 -0
  348. package/examples/techniques/procedural-animation/picture/sky.js +31 -0
  349. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  350. package/examples/techniques/procedural-surface/README.md +69 -0
  351. package/examples/techniques/procedural-surface/main.js +65 -0
  352. package/examples/techniques/procedural-surface/picture/index.js +14 -0
  353. package/examples/techniques/procedural-surface/picture/lights.js +18 -0
  354. package/examples/techniques/procedural-surface/picture/materials.js +34 -0
  355. package/examples/techniques/procedural-surface/picture/palette.js +15 -0
  356. package/examples/techniques/procedural-surface/surface.js +120 -0
  357. package/examples/techniques/stylized-shading/README.md +74 -0
  358. package/examples/techniques/stylized-shading/main.js +62 -0
  359. package/examples/techniques/stylized-shading/picture/index.js +14 -0
  360. package/examples/techniques/stylized-shading/picture/lights.js +23 -0
  361. package/examples/techniques/stylized-shading/picture/materials.js +18 -0
  362. package/examples/techniques/stylized-shading/picture/palette.js +19 -0
  363. package/examples/techniques/stylized-shading/shading.js +131 -0
  364. package/examples/techniques/sun-and-key-light/README.md +133 -0
  365. package/examples/techniques/sun-and-key-light/keyLight.js +71 -0
  366. package/examples/techniques/sun-and-key-light/main.js +51 -0
  367. package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
  368. package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
  369. package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
  370. package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
  371. package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
  372. package/examples/techniques/three-looks/README.md +21 -0
  373. package/examples/techniques/three-looks/main.js +58 -0
  374. package/examples/techniques/three-looks/picture/cartoon.js +23 -0
  375. package/examples/techniques/three-looks/picture/cinematic.js +27 -0
  376. package/examples/techniques/three-looks/picture/comic.js +27 -0
  377. package/examples/techniques/three-looks/picture/index.js +14 -0
  378. package/examples/techniques/three-looks/picture/sun.js +23 -0
  379. package/examples/techniques/wet-road/README.md +102 -0
  380. package/examples/techniques/wet-road/main.js +48 -0
  381. package/examples/techniques/wet-road/picture/index.js +17 -0
  382. package/examples/techniques/wet-road/picture/lights.js +57 -0
  383. package/examples/techniques/wet-road/picture/materials.js +16 -0
  384. package/examples/techniques/wet-road/picture/palette.js +24 -0
  385. package/examples/techniques/wet-road/picture/sky.js +46 -0
  386. package/examples/techniques/wet-road/wetRoad.js +209 -0
  387. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  388. package/examples/webgpu-tsl/GAMEMAP.md +89 -0
  389. package/examples/webgpu-tsl/README.md +45 -0
  390. package/examples/webgpu-tsl/main.js +44 -0
  391. package/examples/webgpu-tsl/picture/index.js +18 -0
  392. package/examples/webgpu-tsl/picture/lights.js +25 -0
  393. package/examples/webgpu-tsl/picture/materials.js +36 -0
  394. package/examples/webgpu-tsl/picture/palette.js +23 -0
  395. package/examples/webgpu-tsl/picture/post.js +16 -0
  396. package/examples/webgpu-tsl/picture/sky.js +30 -0
  397. package/examples/world/.threedog/content-index.json +1 -0
  398. package/examples/world/GAMEMAP.md +31 -21
  399. package/examples/world/art/humanoid.js +38 -0
  400. package/examples/world/art/index.js +11 -0
  401. package/examples/world/art/models.js +57 -0
  402. package/examples/world/art/shapes.js +9 -0
  403. package/examples/world/assets.js +6 -0
  404. package/examples/world/content/audio.js +5 -5
  405. package/examples/world/content/items.js +1 -1
  406. package/examples/world/content/npcs.js +1 -1
  407. package/examples/world/content/props.js +1 -1
  408. package/examples/world/content/rules.js +1 -1
  409. package/examples/world/content/templates.js +1 -1
  410. package/examples/world/content/vegetation.js +1 -1
  411. package/examples/world/main.js +22 -18
  412. package/examples/world/models.js +17 -7
  413. package/examples/world/picture/index.js +20 -0
  414. package/examples/world/picture/lights.js +41 -0
  415. package/examples/world/picture/materials.js +34 -0
  416. package/examples/world/picture/palette.js +74 -0
  417. package/examples/world/picture/post.js +9 -0
  418. package/examples/world/picture/sky.js +39 -0
  419. package/index.d.ts +44 -54
  420. package/index.js +29 -25
  421. package/llms.txt +24 -15
  422. package/modules/ambience/Ambience.js +34 -23
  423. package/modules/calendar/Calendar.js +163 -0
  424. package/modules/calendar/contract.js +21 -0
  425. package/modules/calendar/index.js +82 -0
  426. package/modules/{sky → calendar}/schedule.js +17 -16
  427. package/modules/calendar/seasons.js +55 -0
  428. package/modules/camera/FirstPersonCamera.js +6 -15
  429. package/modules/camera/FixedCamera.js +33 -15
  430. package/modules/camera/FollowCamera.js +90 -16
  431. package/modules/camera/RtsCamera.js +18 -17
  432. package/modules/camera/common.js +73 -20
  433. package/modules/camera/contract.js +17 -0
  434. package/modules/camera/projection.js +11 -24
  435. package/modules/characters/Character.js +188 -48
  436. package/modules/characters/NPC.js +92 -41
  437. package/modules/characters/assetModel.js +8 -16
  438. package/modules/characters/behaviors.js +2 -1
  439. package/modules/characters/contract.js +13 -0
  440. package/modules/characters/footsteps.js +1 -1
  441. package/modules/characters/index.js +112 -49
  442. package/modules/characters/moveHelpers.js +4 -5
  443. package/modules/characters/movers/common.js +102 -19
  444. package/modules/characters/movers/manual.js +23 -0
  445. package/modules/characters/movers/rapier.js +19 -16
  446. package/modules/characters/movers/simple.js +14 -11
  447. package/modules/characters/movers/support.js +186 -0
  448. package/modules/characters/npcAvoid.js +47 -42
  449. package/modules/characters/npcSim.js +17 -9
  450. package/modules/characters/npcView.js +44 -16
  451. package/modules/characters/pathAsync.js +7 -3
  452. package/modules/characters/playerStrings.js +4 -3
  453. package/modules/characters/proceduralRig.js +19 -4
  454. package/modules/characters/useModel.js +2 -2
  455. package/modules/characters/vehicle.contract.js +21 -0
  456. package/modules/characters/walkTo.js +21 -7
  457. package/modules/collision/Collision.js +69 -27
  458. package/modules/collision/grid.js +8 -6
  459. package/modules/content/explain.js +2 -2
  460. package/modules/content/fields.js +102 -0
  461. package/modules/content/ids.js +8 -6
  462. package/modules/content/index.js +104 -27
  463. package/modules/content/loader.js +45 -33
  464. package/modules/content/models.js +58 -42
  465. package/modules/content/packs.js +6 -5
  466. package/modules/content/parts.js +41 -0
  467. package/modules/content/props.js +20 -11
  468. package/modules/content/rules.js +66 -0
  469. package/modules/content/stages.js +80 -0
  470. package/modules/content/templates.js +123 -30
  471. package/modules/debug/DebugPanel.js +24 -17
  472. package/modules/flow/contract.js +16 -0
  473. package/modules/flow/index.js +21 -15
  474. package/modules/gameplay/Container.js +41 -32
  475. package/modules/gameplay/Containers.js +30 -15
  476. package/modules/gameplay/Dialogue.js +113 -55
  477. package/modules/gameplay/Interactions.js +273 -72
  478. package/modules/gameplay/Inventory.js +72 -76
  479. package/modules/gameplay/Quests.js +75 -39
  480. package/modules/gameplay/boxOps.js +3 -3
  481. package/modules/gameplay/dialogue.contract.js +21 -0
  482. package/modules/gameplay/dialogueBox.js +4 -2
  483. package/modules/gameplay/dialogueBubbles.js +116 -0
  484. package/modules/gameplay/interactionPrompt.js +4 -1
  485. package/modules/gameplay/interactions.contract.js +16 -0
  486. package/modules/gameplay/inventory.contract.js +23 -0
  487. package/modules/gameplay/inventoryOps.js +19 -17
  488. package/modules/gameplay/pickups.js +306 -85
  489. package/modules/gameplay/questLog.js +6 -6
  490. package/modules/gameplay/quests.contract.js +17 -0
  491. package/modules/grid/Grid.js +92 -50
  492. package/modules/grid/Layer.js +27 -13
  493. package/modules/grid/index.js +96 -43
  494. package/modules/grid/ops.js +20 -18
  495. package/modules/grid/preview.js +37 -29
  496. package/modules/grid/strings.js +12 -0
  497. package/modules/grid/tiles.js +19 -22
  498. package/modules/hlod/index.js +52 -19
  499. package/modules/hud/index.js +48 -20
  500. package/modules/hud/parts.js +28 -13
  501. package/modules/level/heightfield.js +3 -1
  502. package/modules/level/index.js +49 -23
  503. package/modules/level/nodes.js +4 -3
  504. package/modules/lights/index.js +47 -19
  505. package/modules/music/Music.js +38 -21
  506. package/modules/music/rules.js +1 -1
  507. package/modules/nav/index.js +48 -42
  508. package/modules/net/Client.js +13 -6
  509. package/modules/net/Host.js +19 -5
  510. package/modules/net/Net.js +2 -1
  511. package/modules/net/index.js +13 -8
  512. package/modules/net/sync.js +9 -8
  513. package/modules/net/transports.js +77 -27
  514. package/modules/particles/Particles.js +58 -28
  515. package/modules/particles/contract.js +17 -0
  516. package/modules/particles/effect.js +54 -11
  517. package/modules/photo/Photo.js +56 -38
  518. package/modules/rigid/RigidBodies.js +194 -32
  519. package/modules/rigid/Vehicles.js +18 -15
  520. package/modules/rigid/sync.js +62 -17
  521. package/modules/settings/Settings.js +60 -55
  522. package/modules/settings/apply.js +38 -3
  523. package/modules/settings/sections.js +5 -3
  524. package/modules/settings/strings.js +3 -2
  525. package/modules/settings/view.js +5 -3
  526. package/modules/sky/Sky.js +132 -205
  527. package/modules/sky/clouds.js +37 -23
  528. package/modules/sky/dome.js +100 -0
  529. package/modules/sky/domeLayers.js +30 -15
  530. package/modules/sky/environment.js +45 -99
  531. package/modules/sky/fog.js +9 -139
  532. package/modules/sky/frame.js +60 -56
  533. package/modules/sky/season.js +21 -0
  534. package/modules/sky/shader.js +63 -35
  535. package/modules/sky/skyModule.js +52 -37
  536. package/modules/sky/tint.js +59 -0
  537. package/modules/terrain/ChunkManager.js +194 -110
  538. package/modules/terrain/chunkJob.js +1 -1
  539. package/modules/terrain/chunkQueries.js +6 -4
  540. package/modules/terrain/draw.js +154 -0
  541. package/modules/terrain/index.js +87 -54
  542. package/modules/terrain/terrainDefaults.js +2 -2
  543. package/modules/terrain/terrainEdit.js +18 -20
  544. package/modules/terrain/terrainGen.js +6 -4
  545. package/modules/terrain/terrainIsland.js +5 -4
  546. package/modules/terrain/terrainShape.js +12 -12
  547. package/modules/terrain/terrainShapeMain.js +8 -7
  548. package/modules/terrain/terrainTexture.js +21 -19
  549. package/modules/timeline/Timeline.js +95 -43
  550. package/modules/timeline/Tween.js +18 -10
  551. package/modules/timeline/letterbox.js +2 -2
  552. package/modules/timeline/shots.js +5 -1
  553. package/modules/triggers/index.js +111 -76
  554. package/modules/vegetation/Vegetation.js +229 -112
  555. package/modules/vegetation/densityMap.js +62 -0
  556. package/modules/vegetation/draw.js +191 -0
  557. package/modules/vegetation/groundChunks.js +52 -58
  558. package/modules/vegetation/index.js +32 -11
  559. package/modules/vegetation/modelGeometry.js +3 -2
  560. package/modules/vegetation/nearFade.js +8 -2
  561. package/modules/water/Water.js +157 -72
  562. package/modules/water/surface.js +86 -47
  563. package/modules/weather/Weather.js +96 -103
  564. package/modules/weather/particles.js +37 -14
  565. package/modules/weather/shaders.js +1 -1
  566. package/modules/weather/strings.js +2 -2
  567. package/modules/weather/weatherDraw.js +141 -0
  568. package/modules/world/World.js +26 -9
  569. package/modules/world/explain.js +1 -1
  570. package/modules/world/index.js +18 -4
  571. package/modules/world/persist.js +62 -2
  572. package/modules/world/pos.js +3 -2
  573. package/modules/world/records.js +8 -6
  574. package/modules/world/sim.js +60 -20
  575. package/modules/world/simFar.js +4 -3
  576. package/modules/world/state.js +3 -2
  577. package/modules/world/thingSource.js +1 -1
  578. package/modules/world/views.js +8 -6
  579. package/package.json +8 -3
  580. package/presets.js +43 -29
  581. package/render/PostFX.js +318 -135
  582. package/render/backend.js +486 -0
  583. package/render/cascades.js +195 -0
  584. package/render/cascades.tsl.js +96 -0
  585. package/render/daylight.js +39 -0
  586. package/render/detail.js +122 -41
  587. package/render/effects.js +155 -48
  588. package/render/engineUniforms.js +10 -1
  589. package/render/fuse.js +5 -4
  590. package/render/fx/cel.tsl.js +42 -0
  591. package/render/fx/cloudShadow.tsl.js +16 -0
  592. package/render/fx/detail.tsl.js +66 -0
  593. package/render/fx/index.js +28 -0
  594. package/render/fx/lighting.tsl.js +28 -0
  595. package/render/fx/nodeErrors.tsl.js +68 -0
  596. package/render/fx/noise.tsl.js +12 -0
  597. package/render/fx/objectOrigin.tsl.js +42 -0
  598. package/render/fx/particles.tsl.js +139 -0
  599. package/render/fx/patchNodes.tsl.js +403 -0
  600. package/render/fx/postWebGPU.tsl.js +181 -0
  601. package/render/fx/season.tsl.js +13 -0
  602. package/render/fx/sky.tsl.js +187 -0
  603. package/render/fx/uniforms.tsl.js +67 -0
  604. package/render/fx/water.tsl.js +53 -0
  605. package/render/fx/wind.tsl.js +22 -0
  606. package/render/fxNumbers.js +36 -0
  607. package/render/hotGlsl.js +24 -0
  608. package/render/layers.js +14 -0
  609. package/render/lighting.js +71 -18
  610. package/render/lightmap.js +142 -0
  611. package/render/lights.js +47 -6
  612. package/render/materials.js +55 -152
  613. package/render/modeling.js +73 -0
  614. package/render/neutral.js +23 -0
  615. package/render/occlusion.js +184 -0
  616. package/render/ownFrame.js +76 -0
  617. package/render/patches.js +317 -35
  618. package/render/postWebGL.js +205 -0
  619. package/render/probes.js +288 -0
  620. package/render/shaderErrors.js +154 -0
  621. package/render/slots.js +165 -0
  622. package/render/terms.js +163 -0
  623. package/render/uniformDecl.js +4 -3
  624. package/types/common.d.ts +2 -2
  625. package/types/core.d.ts +757 -346
  626. package/types/gameplay.d.ts +539 -330
  627. package/types/generated/core/Audio.d.ts +26 -42
  628. package/types/generated/core/Batching.d.ts +6 -2
  629. package/types/generated/core/Budget.d.ts +2 -8
  630. package/types/generated/core/DebugOverrides.d.ts +58 -9
  631. package/types/generated/core/I18n.d.ts +2 -2
  632. package/types/generated/core/Input.d.ts +110 -32
  633. package/types/generated/core/Ops.d.ts +31 -0
  634. package/types/generated/core/Random.d.ts +2 -2
  635. package/types/generated/core/Saves.d.ts +10 -2
  636. package/types/generated/core/Stream.d.ts +1 -1
  637. package/types/generated/core/Threads.d.ts +4 -1
  638. package/types/generated/core/Views.d.ts +0 -1
  639. package/types/generated/core/audioVoice.d.ts +17 -9
  640. package/types/generated/core/control.d.ts +55 -0
  641. package/types/generated/core/page.d.ts +9 -2
  642. package/types/generated/core/session.d.ts +2 -1
  643. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  644. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  645. package/types/generated/modules/calendar/index.d.ts +10 -0
  646. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  647. package/types/generated/modules/grid/Grid.d.ts +61 -25
  648. package/types/generated/modules/grid/Layer.d.ts +13 -5
  649. package/types/generated/modules/grid/index.d.ts +56 -20
  650. package/types/generated/modules/music/Music.d.ts +5 -3
  651. package/types/generated/modules/net/index.d.ts +3 -3
  652. package/types/generated/modules/net/transports.d.ts +12 -3
  653. package/types/generated/modules/particles/Particles.d.ts +13 -6
  654. package/types/generated/modules/sky/Sky.d.ts +85 -110
  655. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  656. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  657. package/types/generated/modules/water/Water.d.ts +50 -3
  658. package/types/generated/modules/weather/Weather.d.ts +44 -15
  659. package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
  660. package/types/generated/modules/world/World.d.ts +20 -5
  661. package/types/generated/render/PostFX.d.ts +109 -29
  662. package/types/generated/render/lighting.d.ts +29 -0
  663. package/types/generated/render/materials.d.ts +31 -50
  664. package/types/generated/render/modeling.d.ts +30 -0
  665. package/types/generated/render/occlusion.d.ts +13 -0
  666. package/types/generated/render/patches.d.ts +16 -2
  667. package/types/generated/ui/UI.d.ts +6 -3
  668. package/types/nav.d.ts +6 -0
  669. package/types/physics.d.ts +140 -45
  670. package/types/tsl.d.ts +94 -0
  671. package/types/world.d.ts +489 -122
  672. package/ui/Focus.js +35 -14
  673. package/ui/LoadingScreen.js +3 -3
  674. package/ui/Parts.js +35 -15
  675. package/ui/UI.js +27 -17
  676. package/ui/cursor.js +115 -0
  677. package/ui/defaults.js +15 -11
  678. package/ui/theme.js +36 -27
  679. package/ui/touchPart.js +2 -2
  680. package/core/claims.js +0 -51
  681. package/core/look/coreParts.js +0 -112
  682. package/core/look/layers.js +0 -136
  683. package/core/look/part.js +0 -173
  684. package/core/look/report.js +0 -79
  685. package/core/look/write.js +0 -86
  686. package/core/renamed.js +0 -22
  687. package/core/styleParts.js +0 -98
  688. package/docs/api/entities.md +0 -61
  689. package/docs/api/style.md +0 -134
  690. package/docs/recipes/09-style-pack.md +0 -169
  691. package/docs/recipes/35-style-from-reference.md +0 -84
  692. package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
  693. package/docs/recipes/38-environment-look-hooks.md +0 -88
  694. package/docs/recipes/41-thing-registry.md +0 -93
  695. package/docs/recipes/43-shader-patches-surface-looks.md +0 -135
  696. package/docs/recipes/44-water-weather-look-hooks.md +0 -135
  697. package/docs/recipes/48-make-material.md +0 -70
  698. package/docs/recipes/52-look.md +0 -146
  699. package/examples/action/look.js +0 -5
  700. package/examples/sheepisland/style/index.js +0 -79
  701. package/examples/styletest/look.js +0 -11
  702. package/examples/styletest/overrides.js +0 -33
  703. package/examples/styletest/panel.js +0 -135
  704. package/modules/entities/Entities.js +0 -243
  705. package/modules/entities/build.js +0 -25
  706. package/modules/entities/index.js +0 -4
  707. package/modules/sky/calendar.js +0 -80
  708. package/modules/sky/cascades.js +0 -125
  709. package/modules/sky/layers.js +0 -69
  710. package/modules/sky/look.js +0 -51
  711. package/modules/sky/lookFog.js +0 -80
  712. package/modules/sky/lookShadow.js +0 -50
  713. package/modules/sky/lookSky.js +0 -108
  714. package/modules/sky/shadow.js +0 -74
  715. package/modules/terrain/chunkLevels.js +0 -40
  716. package/modules/terrain/lookGround.js +0 -61
  717. package/modules/terrain/mountTerrain.js +0 -32
  718. package/modules/vegetation/lookWind.js +0 -37
  719. package/modules/water/look.js +0 -80
  720. package/modules/weather/look.js +0 -75
  721. package/modules/world/cells.js +0 -42
  722. package/render/lookSurface.js +0 -161
  723. package/render/postLook.js +0 -86
  724. package/render/surface.js +0 -69
  725. package/types/style.d.ts +0 -643
package/core/modules.js CHANGED
@@ -2,8 +2,9 @@
2
2
  // See CLAUDE.md "writing a module" for the module shape; dispose is called by lifecycle.js in reverse install order.
3
3
  //
4
4
  // Run order (fixed / frame / afterRender / skip hooks): by stage first, then before / after within a stage, then install order.
5
- // Stages (first to last): control timeline, camera -> world terrain, level -> environment weather, sky, water
6
- // -> gameplay interactions, dialogue, trigger zones, entities -> presentation particles, settings, objective markers
5
+ // stage only orders hooks; what a module may own and what happens when it throws come from its type (moduleTypes.js, errors.js).
6
+ // Stages (first to last): control timeline, camera -> ground terrain, level -> environment weather, sky, water
7
+ // -> gameplay interactions, dialogue, trigger zones -> effects particles, settings, objective markers
7
8
  // -> late (the default) characters, physics, navigation... -> audio music
8
9
  // before / after: lists of module names (not-installed names are ignored); they order modules only inside one stage.
9
10
  // One that contradicts the stage order (a 'control' module with after: ['sky']) makes use() throw naming both modules and stages;
@@ -12,22 +13,35 @@
12
13
  // before anything installs; if a module's install() then throws, the modules this call already installed are removed again
13
14
  // (engine.name, module table, hooks; their dispose() runs) and the error is rethrown.
14
15
  // Module state (engine.moduleStates): registered -> initializing -> running | failed; disposed after engine.dispose(). Modules without init() are
15
- // running at once. fixed / frame / afterRender / skip hooks run only for modules that are not initializing or failed,
16
- // so a module installed after start() gets no hook before its init() finished.
17
- // critical: true on a module makes a failed init() stop engine.start() with the reason; without it a failed init is reported (presentation: disabled;
18
- // gameplay: error tiers in errors.js) and start() goes on.
16
+ // running at once. fixed / frame / afterRender / skip hooks run only for running modules, so no module gets a hook before its init() finished
17
+ // (during start() or when installed later).
18
+ // Ownership: install(e, ctx) and init(e, ctx) get ctx = { name, track(handle), mod(point, o), control.take(character, o) }. A handle passed to ctx.track (events.on, onFixed, onFrame,
19
+ // clock timers, audio.measure... anything with remove()) belongs to the module and is removed with it: when the use() batch rolls back,
20
+ // when its init fails, and on engine.dispose() (before the module's own dispose). Listeners a module adds go through it, so an install
21
+ // that fails halfway leaves no ghost listener behind (review 0.4 A; the rollback spec checks every built-in module).
22
+ // ctx.mod(point, o) = ctx.track(engine.mod(point, { ...o, owner: ctx.name })): a module's changes to shared values go with it too.
23
+ // ctx.input.action(name, { context }) / ctx.input.bind(name, keys): the module's input declarations and bindings, gone with it too.
24
+ // Every install is its own instance (engine._modInst: name -> token): a ctx belongs to one install, not to a name. An async init that resumes after
25
+ // its module was unloaded (replaces, a plugin removed) and a same-named one installed must not act on the newcomer: what the stale ctx tracks is
26
+ // removed at once (dev warning naming the module), and its completion or failure changes no state and drops no handle of the newcomer.
27
+ // Exclusive slots: provides: ['inventory'] takes each named slot (a kind 'one' shared point, core/sharedPoint.js) for the module before its install;
28
+ // a second provider is shared-taken. requires may name a slot instead of a module. engine.use(mine(), { replaces: 'inventory' }) unloads the
29
+ // holder first (its handles, slot, drawing parts, dispose), and puts it back if the new install fails.
30
+ // critical: true on a module makes a failed init() stop engine.start() with the reason; without it a failed init is reported (picture / ui: disabled;
31
+ // other types: error tiers in errors.js) and start() goes on.
19
32
  // Dependencies: requires must be installed first (throws if missing). optional is a soft dependency: an array is only recorded (for GAMEMAP and rule R16);
20
33
  // written as { module: 'what is lost without it' }, start() warns once in dev when it is missing: use this form for optional dependencies
21
34
  // that change gameplay results, which must not be skipped silently.
22
- import { requiresText, warnOnce, DEV, fmt } from './validate.js';
35
+ import { warnOnce, DEV, fmt, closest } from './validate.js';
23
36
  import { codedError, coded } from './errorHints.js';
24
37
  import { reportError } from './errors.js';
25
38
  import { catalog, catalogSnap, catalogClaim } from './catalog.js';
26
39
  import { readParams } from './params.js';
27
- import { disposeLooksOf } from './look/part.js';
40
+ import { slotMethods, isUseOpts, checkProvides } from './moduleSlots.js';
41
+ import { checkType, asModule } from './moduleTypes.js';
28
42
 
29
43
  /** Stage -> sort position */
30
- const STAGES = { control: 100, world: 200, environment: 300, gameplay: 400, presentation: 450, late: 500, audio: 510 };
44
+ const STAGES = { control: 100, ground: 200, environment: 300, gameplay: 400, effects: 450, late: 500, audio: 510 };
31
45
  const HOOKS = ['fixed', 'frame', 'afterRender', 'skip'];
32
46
  const STRINGS = {
33
47
  cycle: 'module order forms a cycle: {path} (check before / after on these modules)',
@@ -37,12 +51,21 @@ const STRINGS = {
37
51
  called: 'engine.use received the module function {name} itself; call it: {name}()',
38
52
  twice: 'module {name} is already installed; the second engine.use({name}()) is ignored',
39
53
  readyHook: 'module {name}: the load-complete hook is named isReady(e) (ready is always a boolean property in the engine); ready(e) will not be called',
40
- needs: 'module {name} requires module {dep} to be installed first; put {dep}() before it',
54
+ // both ways out: the engine's part of that name, or the game's own provider (requires names a capability, never a particular module)
55
+ needs: "module {name} requires '{dep}', which no installed module provides. Fix: install the engine's part first, engine.use({dep}(), {name}(...)), "
56
+ + "or your own module with provides: ['{dep}'] (then engine.{dep} is your module's API){typo}",
57
+ typo: " (did you mean '{hint}'? installed: {list})",
41
58
  clash: 'module name {name} clashes with an existing engine property; pick another name',
59
+ slotClash: "module {name} provides '{slot}', but engine.{slot} is already an engine property, so dependents could not reach it there. Fix: pick another slot name",
42
60
  lateInit: 'init of module {name} (installed after start)',
43
61
  conflict: 'module {a} (stage "{sa}") sets {kind}: ["{b}"], but module {b} is in stage "{sb}", which always runs {kind} stage "{sa}" (stage order: {list}); '
44
62
  + 'before / after only order modules inside one stage. Fix: give both modules the same stage, or remove {kind}: ["{b}"] from {a}',
45
63
  };
64
+ const CTX_OWNER = "ctx.mod('{point}', { owner }) in module {name}: ctx.mod names the module as the owner itself; drop owner (use engine.mod for another owner name)";
65
+ const BAD_HANDLE = 'ctx.track(handle) in module {name}: handle must have remove(), like the result of engine.events.on / onFixed / clock.after; got {got}';
66
+ const STALE = 'module {name} registered something after it was unloaded (its async init or a callback resumed after replaces / unload); it was removed at once. '
67
+ + 'The module installed under that name now is not affected';
68
+ const STALE_INIT = 'init of module {name}, which was unloaded before it finished';
46
69
  const hookCache = new WeakMap(); // module definition -> { fixed, frame, afterRender, skip } hook entries (reused when re-sorting)
47
70
 
48
71
  /** Sort modules by stage, before / after and install order (Kahn topological sort; among the ready ones take the earliest stage,
@@ -83,6 +106,7 @@ function checkStages(list) {
83
106
  }
84
107
 
85
108
  export const moduleMethods = {
109
+ ...slotMethods, // provides / replaces (moduleSlots.js)
86
110
  /**
87
111
  * Install one or more modules in order; dependencies must be installed first; hook order is described at the top of this file.
88
112
  * All-or-nothing: the batch is validated first, and if an install() throws, the modules this call installed are removed again.
@@ -91,24 +115,39 @@ export const moduleMethods = {
91
115
  * `await engine.loading.settled()` waits for it; engine.moduleStates shows where each module is.
92
116
  */
93
117
  use(...mods) {
94
- const plan = this._planUse(mods.flat()), done = [];
118
+ const opts = isUseOpts(mods.at(-1)) ? mods.pop() : null;
119
+ const list = mods.flat(Infinity), gone = this._replaced(list, opts?.replaces);
120
+ const plan = this._planUse(list, gone), done = [];
121
+ // replaces: the holder goes first (its tracked handles, its slot, its drawing parts, its dispose), so the newcomer's install sees a free slot
122
+ const removed = [...gone].map(n => this._unuse(n, true));
95
123
  try {
96
124
  for (const m of plan) {
97
- const had = Object.hasOwn(this, m.name), prev = this[m.name], snap = catalogSnap(this), api = m.install?.(this) ?? m;
125
+ const had = Object.hasOwn(this, m.name), prev = this[m.name], snap = catalogSnap(this);
126
+ done.push({ m, had, prev }); // before install(): what it tracked before throwing is removed too
127
+ this._modInst.set(m.name, {}); // this install's identity: install and init ctx check it, so a stale async init cannot act on a later install
128
+ const ctx = this._modCtx(m);
129
+ this._picture?.installing(m);
130
+ for (const slot of m.provides ?? []) ctx.track(this._slot(slot, m.name).take({ owner: m.name })); // shared-taken when another module holds it
131
+ const api = asModule(this, m, () => m.install?.(this, ctx)) ?? m; // asModule: the type checks know who is installing (moduleTypes.js)
98
132
  catalogClaim(this, m.name, snap); // ops / save parts / describe names it registered show under it in engine.catalog()
99
133
  this.modules.set(m.name, m);
100
134
  if (m.name) this[m.name] = api;
101
- done.push({ m, had, prev });
135
+ // engine.<slot> is the provider's API too, so a module that requires 'inventory' reaches the game's own bag at engine.inventory after
136
+ // a replaces: dependents name the capability, never the module that gives it
137
+ for (const slot of m.provides ?? []) if (slot !== m.name) { this[slot] = api; ctx.track(this._aliasSlot(slot, api)); }
102
138
  this._modState.set(m.name, m.init ? (this._started ? 'initializing' : 'registered') : 'running');
103
139
  }
104
140
  } catch (err) {
105
141
  for (const { m, had, prev } of done.reverse()) { // undo in reverse install order, like dispose
106
- this.modules.delete(m.name); this._modState.delete(m.name);
142
+ const installed = this.modules.get(m.name) === m;
143
+ this.modules.delete(m.name); this._modState.delete(m.name); this._modInst.delete(m.name);
107
144
  if (had) this[m.name] = prev; else delete this[m.name]; // put back what was there (an undefined slot stays undefined), never blank it
108
- try { m.dispose?.(this); } catch { /* the install error below is the one to report */ }
145
+ this._dropTracked(m.name);
146
+ if (installed) try { m.dispose?.(this); } catch { /* the install error below is the one to report */ }
109
147
  }
110
- for (const m of plan) disposeLooksOf(this, m.name); // look parts and driven keys of every module in the batch, the one that threw too (review M9)
111
148
  this._sortHooks();
149
+ // a replaced module comes back, so a failed swap leaves the game as it was (it installs fresh: its old handles already went)
150
+ if (removed.length) try { this.use(...removed); } catch (e2) { reportError(this, e2, 'putting back the module a failed replaces removed', { soft: true }); }
112
151
  throw err;
113
152
  }
114
153
  this._sortHooks();
@@ -117,8 +156,11 @@ export const moduleMethods = {
117
156
  },
118
157
  /** @internal validate a batch without touching the engine (so a failure leaves nothing half-installed);
119
158
  * returns the modules to install */
120
- _planUse(list) {
121
- const names = new Set(this.modules.keys()), plan = [];
159
+ _planUse(list, gone = new Set()) {
160
+ const names = new Set([...this.modules.keys()].filter(n => !gone.has(n))), plan = [];
161
+ // requires names a module or a capability: another module's provides (depend on 'inventory', not on whichever module gives it)
162
+ const caps = new Set(names);
163
+ for (const n of names) for (const s of this.modules.get(n).provides ?? []) caps.add(s);
122
164
  for (const m of list) {
123
165
  if (!m) continue;
124
166
  if (typeof m === 'function') throw codedError('module-called', fmt(STRINGS.called, { name: m.name }));
@@ -127,13 +169,20 @@ export const moduleMethods = {
127
169
  if (m.order != null) throw codedError('module-stage', fmt(STRINGS.order, { name: m.name, list: Object.keys(STAGES).join(', ') }));
128
170
  if (m.stage != null && !(m.stage in STAGES))
129
171
  throw codedError('module-stage', fmt(STRINGS.stage, { name: m.name, stage: m.stage, list: Object.keys(STAGES).join(', ') }));
130
- for (const dep of m.requires || []) if (!names.has(dep))
131
- throw codedError('module-requires', requiresText(m.name, dep, [...names]) ?? fmt(STRINGS.needs, { name: m.name, dep }));
172
+ checkType(m);
173
+ for (const dep of m.requires || []) if (!caps.has(dep)) {
174
+ const hint = closest(dep, [...caps]);
175
+ throw codedError('module-requires', fmt(STRINGS.needs, { name: m.name, dep, typo: hint ? fmt(STRINGS.typo, { hint, list: [...caps].join(', ') }) : '' }));
176
+ }
177
+ checkProvides(m);
178
+ for (const slot of m.provides ?? []) if (slot !== m.name && !gone.has(slot) && !names.has(slot) && slot in this && this[slot] !== undefined && !this._slotAlias?.has(slot))
179
+ throw codedError('module-provides', fmt(STRINGS.slotClash, { name: m.name, slot }));
132
180
  if (DEV && m.params && m.options) readParams(m.name, m.params, m.options); // a definition built by hand still gets its options checked
133
- if (m.name in this && this[m.name] !== undefined) throw codedError('module-name', fmt(STRINGS.clash, { name: m.name }));
134
- names.add(m.name); plan.push(m);
181
+ if (!gone.has(m.name) && m.name in this && this[m.name] !== undefined) throw codedError('module-name', fmt(STRINGS.clash, { name: m.name }));
182
+ names.add(m.name); caps.add(m.name); for (const s of m.provides ?? []) caps.add(s);
183
+ plan.push(m);
135
184
  }
136
- if (plan.length) { const all = [...this.modules.values(), ...plan]; checkStages(all); sortModules(all); }
185
+ if (plan.length) { const all = [...[...this.modules.values()].filter(m => !gone.has(m.name)), ...plan]; checkStages(all); sortModules(all); }
137
186
  return plan;
138
187
  },
139
188
  /** @internal init of a module installed after start(): run now, tracked in engine.loading, errors through the error tiers;
@@ -142,9 +191,78 @@ export const moduleMethods = {
142
191
  const L = this.loading, task = L._begin(m.name, 'module');
143
192
  task.phase('build');
144
193
  const snap = catalogSnap(this);
145
- L._track(Promise.resolve().then(() => m.init(this)).then(
146
- () => { catalogClaim(this, m.name, snap); L._done(task); this._setModState(m, 'running'); },
147
- e => { L._fail(task, e); this._setModState(m, 'failed'); reportError(this, e, fmt(STRINGS.lateInit, { name: m.name }), { module: m }); }));
194
+ // the instance and its ctx are taken now, not when the microtask runs: by then a same-named module may be installed in its place
195
+ const inst = this._modInst.get(m.name), ctx = this._modCtx(m, inst), live = () => this._isLive(m.name, inst);
196
+ L._track(Promise.resolve().then(() => asModule(this, m, () => m.init(this, ctx))).then(
197
+ () => { L._done(task); if (live()) { catalogClaim(this, m.name, snap); this._setModState(m, 'running'); } },
198
+ e => {
199
+ L._fail(task, e);
200
+ // unloaded meanwhile: its handles already went with it, and the state / handles under this name belong to the newcomer now
201
+ if (!live()) return reportError(this, e, fmt(STALE_INIT, { name: m.name }), { soft: true });
202
+ this._setModState(m, 'failed'); this._dropTracked(m.name); reportError(this, e, fmt(STRINGS.lateInit, { name: m.name }), { module: m });
203
+ }));
204
+ },
205
+ /** @internal is this install (token from engine._modInst) still the module installed under its name? */
206
+ _isLive(name, inst) { return !this.disposed && inst !== undefined && this._modInst.get(name) === inst; },
207
+ /** @internal the ctx install / init receive: track(handle) ties a handle to the module's life (see the top of this file) */
208
+ _modCtx(m, inst = this._modInst.get(m.name)) {
209
+ const name = m.name;
210
+ const track = h => {
211
+ if (typeof h?.remove !== 'function') throw codedError('module-handle', fmt(BAD_HANDLE, { name, got: String(h) }));
212
+ if (this.disposed) { h.remove(); return h; } // a late registration after dispose: nothing will ever remove it otherwise
213
+ // a registration from an install that is gone (replaced / unloaded while its async init awaited): filing it under the name would hand it
214
+ // to the newcomer, which would then own a listener it never made; remove it now instead
215
+ if (!this._isLive(name, inst)) { if (DEV) warnOnce(coded('module-handle', fmt(STALE, { name }))); h.remove(); return h; }
216
+ let set = this._modTracked.get(name);
217
+ if (!set) this._modTracked.set(name, set = new Set());
218
+ set.add(h);
219
+ if (this._curModule === m) this._picture?.learn(m); // the module's own code called this: its file is the part's (core/pictureWriters.js)
220
+ return h;
221
+ };
222
+ // mod: engine.mod with the module as owner, tracked. Why a ctx verb and not "guess the running module": in an async callback the guess is wrong;
223
+ // and a handle that is not tracked is a weather multiplier still on after the module went
224
+ const mod = (point, o) => {
225
+ if (o?.owner !== undefined) throw codedError('mod-owner', fmt(CTX_OWNER, { point, name }));
226
+ return track(this.mod(point, { ...o, owner: name }));
227
+ };
228
+ // input: declare actions / bind the keys the game handed the module, owned by the module (removed with it); never a key of its own
229
+ const input = {
230
+ action: (n, o) => track(this.input.action(n, { ...o, owner: name })),
231
+ bind: (n, keys) => track(this.input.bind(n, keys, { owner: name })),
232
+ };
233
+ // control: engine.control.take with the module as default owner, tracked, so a module that goes (unload, rollback, replaces) hands back every
234
+ // character it was steering. Unlike mod an owner may be given: one module can hold several characters on its own names (one per cutscene run).
235
+ // A hold that ends by itself leaves the tracked set too, so a module taking control often (a cutscene a minute) does not pile up dead handles.
236
+ // Taking the same character again under the same owner replaces the hold, so the stale handle leaves the tracked set as well.
237
+ const held = new Map(); // `${id} ${owner}` -> the live handle
238
+ const control = {
239
+ take: (who, o = {}) => {
240
+ const h = this.control.take(who, { ...o, owner: o.owner ?? name }), end = h.remove, key = `${h.id} ${h.owner}`;
241
+ const old = held.get(key);
242
+ if (old) this._modTracked.get(name)?.delete(old);
243
+ held.set(key, h);
244
+ h.remove = () => { end(); if (held.get(key) === h) held.delete(key); this._modTracked.get(name)?.delete(h); };
245
+ return track(h);
246
+ },
247
+ has: (who, owner = name) => this.control.has(who, owner),
248
+ };
249
+ // whileCompiling: a one-time warm-up (a WASM library's first call) run while start() waits for the GPU to compile shaders, when the page's
250
+ // thread is idle anyway (startup.js); after start() it runs at once
251
+ // It checks the install like track does: a warm-up queued by an install that was unloaded before start() ran the queue must not run
252
+ // (it would touch state of an install that is gone), and one asked for by an install that is already stale is not queued at all
253
+ const whileCompiling = fn => {
254
+ if (!this._isLive(name, inst)) return;
255
+ const run = () => { if (this._isLive(name, inst)) fn(); };
256
+ if (this.ready) run(); else this._whileCompiling.push(run);
257
+ };
258
+ return { name, track, mod, input, control, whileCompiling };
259
+ },
260
+ /** @internal remove every handle a module tracked; one that throws is reported and the rest still go */
261
+ _dropTracked(name) {
262
+ const set = this._modTracked.get(name);
263
+ if (!set) return;
264
+ this._modTracked.delete(name);
265
+ for (const h of set) { try { h.remove(); } catch (err) { reportError(this, err, `remove() of a handle module ${name} tracked`, { soft: true }); } }
148
266
  },
149
267
  /** @internal move a module to a new state and refresh the hooks (initializing / failed modules run none) */
150
268
  _setModState(m, state) {
@@ -170,14 +288,14 @@ export const moduleMethods = {
170
288
  /** Run order of module hooks (module names, first to last), for debugging "who runs first". */
171
289
  get moduleOrder() { return this._moduleOrder ?? []; },
172
290
 
173
- /** Re-sort the module hooks in the main loop (disabled presentation modules are not put back). */
291
+ /** Re-sort the module hooks in the main loop (disabled picture / ui modules are not put back). */
174
292
  _sortHooks() {
175
293
  const order = sortModules([...this.modules.values()]);
176
294
  this._moduleOrder = order.map(m => m.name);
177
295
  for (const k of HOOKS) this._hooks[k] = [];
178
296
  for (const m of order) {
179
297
  const st = this._modState.get(m.name);
180
- if (this.disabledModules.has(m.name) || st === 'initializing' || st === 'failed') continue;
298
+ if (this.disabledModules.has(m.name) || st !== 'running') continue; // registered (init not run yet), initializing, failed: no hooks
181
299
  let c = hookCache.get(m);
182
300
  if (!c) hookCache.set(m, c = {});
183
301
  for (const k of HOOKS) if (m[k]) this._hooks[k].push(c[k] ??= { fn: m[k].bind(m), name: m.name, mod: m });
@@ -189,7 +307,7 @@ export const moduleMethods = {
189
307
  for (const m of this.modules.values()) {
190
308
  const opt = m.optional;
191
309
  if (!opt || Array.isArray(opt)) continue;
192
- for (const [dep, what] of Object.entries(opt)) if (!this.modules.has(dep))
310
+ for (const [dep, what] of Object.entries(opt)) if (!this.modules.has(dep) && !this._provided(dep))
193
311
  warnOnce(coded('module-requires', fmt(STRINGS.optional, { name: m.name, dep, what })));
194
312
  }
195
313
  },
package/core/movement.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // the A* fallback pathfinding, the level heightfield step height and Character's default radius / step all read engine.movement by default, so no one keeps a private number.
4
4
  // Core only holds this data and depends on no module (hard rule 2); a module's same-named option can still be passed and acts as an override.
5
5
  // createEngine({ movement: { radius: 0.5 } }) -> engine.movement.radius === 0.5 (read-only, never changed at runtime)
6
- import { checkOptions } from './validate.js';
6
+ import { readParams, keysSchema } from './params.js';
7
7
  import { codedError } from './errorHints.js';
8
8
 
9
9
  /** Defaults (meters / degrees): radius is the character radius, height the character height, maxSlope the steepest walkable slope (degrees), stepHeight the step it can climb directly. */
@@ -11,7 +11,7 @@ export const MOVEMENT_DEFAULTS = { radius: 0.4, height: 1.8, maxSlope: 48, stepH
11
11
 
12
12
  /** Build the read-only movement parameters. slopeRatio (rise over run) is maxSlope converted to a ratio, which lightweight collision tests against. */
13
13
  export function createMovement(opts = {}) {
14
- checkOptions('createEngine({ movement })', opts, Object.keys(MOVEMENT_DEFAULTS));
14
+ readParams('createEngine({ movement })', keysSchema(Object.keys(MOVEMENT_DEFAULTS)), opts);
15
15
  const m = { ...MOVEMENT_DEFAULTS, ...opts };
16
16
  for (const k of Object.keys(MOVEMENT_DEFAULTS)) if (!(m[k] > 0)) throw codedError('movement', `movement.${k} must be a positive number; got ${m[k]}`);
17
17
  m.slopeRatio = Math.tan(m.maxSlope * Math.PI / 180);
@@ -0,0 +1,74 @@
1
+ // A model, used by name: the one path for "a model made in code (or a file), reused by name". Content (props, templates, vegetation), pickups and
2
+ // vegetation.define all resolve a model name here, so caching (baked file -> dev cache -> build), the per-name prototype and the shadow rule exist once.
3
+ // It lives in core because several modules need it and none of them owns it (content, inventory, vegetation): no module depends on another for it.
4
+ import * as THREE from 'three';
5
+ import { neutralMaterial } from '../render/neutral.js';
6
+ import { shadowDefaults } from './assetEntry.js';
7
+ import { paramValues } from './assetManifest.js';
8
+
9
+ /** One value or a list, as a list @internal */
10
+ export const list = v => (Array.isArray(v) ? v : [v]);
11
+
12
+ /**
13
+ * A model name (name or [name, params...]) whose asset entry is a generator (an asset pack's procedural model) goes through assets.cached:
14
+ * name = model name, params count into the cache key. Returns a Promise (geometry or Object3D); null for a file model or an unknown name (assets.model takes those)
15
+ */
16
+ export function cachedModel(e, m) {
17
+ const [name, ...args0] = list(m), fn = e.assets.builder(name);
18
+ if (!fn) return null;
19
+ // every model asked for by name is remembered, so a dev hot swap (core/assetHot.js) can build the same name + params list again
20
+ const made = (e.assets._made ||= new Map());
21
+ (made.get(name) ?? made.set(name, new Map()).get(name)).set(JSON.stringify(m), m);
22
+ // a generator with a params schema gets one object: defaults < dev panel values < the call's own object (assetManifest.js paramValues)
23
+ const entry = e.assets.entries.get(name), args = entry?.schema ? [paramValues(entry, args0[0])] : args0;
24
+ // pass the generator function to cached as is (dev cache hashes its source); wrap only when there are several params
25
+ return args.length > 1 ? e.assets.cached(name, function (p) { return fn.apply(this, p); }, args) : e.assets.cached(name, fn, args[0]);
26
+ }
27
+
28
+ /** A model name in model / lod position: 'pine' or ['flower', 0xff0000] (content data and vegetation.define take the same form) @internal */
29
+ export const isModelName = m => typeof m === 'string' || Array.isArray(m) && typeof m[0] === 'string';
30
+ /**
31
+ * A vegetation model by name: { geometry } for a generator that returns geometry or for a file model (its first mesh), { model } for a generator
32
+ * that returns an Object3D (one material per mesh kept). content's vegetation table and vegetation.define(name, { model: 'pine' }) both resolve here,
33
+ * so a name means the same thing in data and in code. @internal
34
+ */
35
+ export async function vegetationModel(e, m) {
36
+ const r = await (cachedModel(e, m) ?? e.assets.geometry(list(m)[0]));
37
+ return r?.isObject3D ? { model: r } : { geometry: r };
38
+ }
39
+
40
+ // One prototype per model name: a generator entry -> assets.cached (baked file / dev cache); a file entry -> assets.model. Content names models only (no paths).
41
+ // The only entry for "reuse a code-made model by name": content props / templates / vegetation and ground pickups all take it from here, so cache, bake and shadow rules exist once.
42
+ const protos = new WeakMap(); // owner (engine.content, or the inventory for pickups) → Map(model key → Promise<{ obj, size, center, fromGeometry }>)
43
+ const protoPalette = new WeakMap(); // prototype promise → the palette it was built from (null for a file model)
44
+ const owners = new WeakMap(); // engine → Set(owner): a hot swap walks every owner's prototypes of a changed name
45
+ /** Every prototype cache of this engine: [{ api, cache }] (cache: model key → Promise of the prototype). For core/assetHot.js @internal */
46
+ export const protoCaches = e => [...(owners.get(e) ?? [])].map(api => ({ api, cache: protos.get(api) }));
47
+ /**
48
+ * The shared prototype of a model name (or [name, ...params]): { obj, size, center, fromGeometry }. fromGeometry: the generator returned a bare
49
+ * geometry, wrapped here in a mesh of neutral gray; a caller with a material of its own (pickups) swaps that one. @internal
50
+ */
51
+ export function protoOf(e, api, model) {
52
+ if (!protos.has(api)) protos.set(api, new Map());
53
+ (owners.get(e) ?? owners.set(e, new Set()).get(e)).add(api);
54
+ const cache = protos.get(api), key = JSON.stringify(model), palette = e.assets.builder(list(model)[0]) ? e.assets._paletteKey : null;
55
+ // a palette written since this prototype was built: the next placement builds again, the same rule assets.cached has by its key
56
+ if (cache.has(key) && protoPalette.get(cache.get(key)) !== palette) cache.delete(key);
57
+ if (!cache.has(key)) {
58
+ const gen = cachedModel(e, model);
59
+ cache.set(key, (gen ? gen.then(r => {
60
+ const p = r.isObject3D ? r : new THREE.Mesh(r, neutralMaterial('prop', { vertexColors: !!r.attributes.color }));
61
+ if (!r.isObject3D) p.userData.fromGeometry = true;
62
+ // the generator's own castShadow / receiveShadow are kept (a decal or flat rug that must not cast); the manifest entry can set them;
63
+ // a generator that set none gets cast + receive. Same rule as assets.model (core/assetEntry.js shadowDefaults)
64
+ return shadowDefaults(p, e.assets.entries.get(list(model)[0])?.opts);
65
+ }) : e.assets.model(list(model)[0])).then(obj => {
66
+ const box = new THREE.Box3().setFromObject(obj); // collision and the "build within what distance" check both use the prototype's bounding box, computed once
67
+ obj.userData.modelKey = key; // copies carry it (clone copies userData): a hot swap whose new model has other parts finds them by it
68
+ return { obj, size: box.getSize(new THREE.Vector3()), center: box.getCenter(new THREE.Vector3()), fromGeometry: !!obj.userData.fromGeometry };
69
+ }));
70
+ protoPalette.set(cache.get(key), palette);
71
+ }
72
+ return cache.get(key);
73
+ }
74
+
package/core/opsCheck.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // Each message says what is wrong and how to write it, because the reader is usually an AI that will fix the call from the text alone.
3
3
  import { closest, fmt } from './validate.js';
4
4
  import { codedError } from './errorHints.js';
5
- import { parseSchema, whyBad, CHECK, OP_TYPES as TYPES } from './params.js'; // one type check for op args and module params
5
+ import { parseSchema, whyBad, checkOf, OP_TYPES as TYPES } from './params.js'; // one type check for op args and module params
6
6
 
7
7
  export const SOURCES = ['player', 'game', 'bridge', 'test', 'replay', 'net'];
8
8
  const NAME = /^[a-z][a-zA-Z0-9]*(\.[a-z][a-zA-Z0-9]*)+$/;
@@ -77,7 +77,7 @@ export function checkArgs(e, d, args) {
77
77
  for (const key in d.shape) {
78
78
  const s = d.shape[key], v = args[key];
79
79
  if (v === undefined) { if (!s.optional) throw devError(fmt(STRINGS.missing, { name, key, shape: shapeText })); continue; }
80
- if (!CHECK[s.type](v)) throw devError(fmt(STRINGS.wrong, { name, key, type: s.type === 'position' ? '[x, y, z]' : s.type, got: JSON.stringify(v), shape: shapeText }));
80
+ if (!checkOf(s.type)(v)) throw devError(fmt(STRINGS.wrong, { name, key, type: s.type === 'position' ? '[x, y, z]' : s.type, got: JSON.stringify(v), shape: shapeText }));
81
81
  const range = whyBad(s, v); // min / max / values of the full schema form
82
82
  if (range) throw devError(fmt(STRINGS.range, { name, key, why: range, shape: shapeText }));
83
83
  if (s.type === 'id' && e._things.sources.length && !e._things.source(v)) throw devError(fmt(STRINGS.noRecord, { name, key, id: v }));
@@ -89,7 +89,7 @@ export function argRange(d, args) {
89
89
  if (!d.shape || !args) return null;
90
90
  for (const key in d.shape) {
91
91
  const s = d.shape[key], v = args[key];
92
- if (v === undefined || !CHECK[s.type](v)) { if (v !== undefined) return { code: 'badArgs', facts: [{ id: d.name, field: key, actual: v, expected: s.type }] }; continue; }
92
+ if (v === undefined || !checkOf(s.type)(v)) { if (v !== undefined) return { code: 'badArgs', facts: [{ id: d.name, field: key, actual: v, expected: s.type }] }; continue; }
93
93
  const why = whyBad(s, v);
94
94
  if (why) return { code: 'badArgs', facts: [{ id: d.name, field: key, actual: v, expected: why }] };
95
95
  }
package/core/opsFail.js CHANGED
@@ -2,17 +2,26 @@
2
2
  // can: () => cond ? true : { code: 'noMoney', facts: { need: 5, have: 2 }, nextActions: [{ op: 'job.work', args: {} }] }
3
3
  // facts: an object ({ need: 5, have: 2 }) or a list [{ id, field, actual, expected? }] (which record / field was wrong, and what it should have been). nextActions are declared by the game here, never guessed by the engine.
4
4
  // run may fail the same way: return or throw { ok: false, code, facts?, nextActions? } (the op then counts as failed; an atomic op is rolled back).
5
- // Every failed result from run / can / undo is normalized to { ok: false, code, facts, nextActions }; `code` is the name to read. The old field `reason`
6
- // is a hidden (non-enumerable) trap: reading it throws renamed-api and names result.code, in every build.
7
- import { renamed } from './errorHints.js';
5
+ // Every failed result from run / can / undo is normalized to { ok: false, code, facts, nextActions }; `code` is the name to read.
8
6
  const NONE = Object.freeze([]), NO_FACTS = Object.freeze({});
9
- const TRAP = { get() { return renamed('reason'); }, enumerable: false, configurable: true };
10
7
 
11
- /** @param {string | { code: string, facts?: object, nextActions?: any[] }} r a code string or a structured failure @returns {{ ok: false, code: string, facts: object, nextActions: any[], reason?: never }} */
8
+ /** @param {string | { code: string, facts?: object, nextActions?: any[] }} r a code string or a structured failure @returns {{ ok: false, code: string, facts: object, nextActions: any[] }} */
12
9
  export function failure(r) {
13
10
  const out = typeof r === 'string' ? { ok: false, code: r, facts: NO_FACTS, nextActions: NONE }
14
11
  : { ok: false, code: r.code, facts: r.facts ?? NO_FACTS, nextActions: r.nextActions ?? NONE };
15
- return Object.defineProperty(out, 'reason', TRAP);
12
+ return out;
13
+ }
14
+ /**
15
+ * Freeze owner held while a save's parts load (saveApply.js). A part's load() may return a Promise (an async terrain, a streamed world): until the
16
+ * last part is applied the game is half old, half new, so fixed steps stop (freeze) and ops refuse with code 'loading' (a click or a net message
17
+ * arriving in that gap would change the old state and be wiped, or act on a mix). Shared here so ops and the loader name the same owner.
18
+ * @internal
19
+ */
20
+ export const PARTS_LOADING = 'threedog:load-parts';
21
+ /** Why ops refuse right now: 'halted' (a gameplay error froze the game), 'loading' (save parts still loading), or null @internal */
22
+ export function opsBlocked(e) {
23
+ const f = e.stacks.get('freeze');
24
+ return f.has('error') ? 'halted' : f.has(PARTS_LOADING) ? 'loading' : null;
16
25
  }
17
26
  /** True when can returned a usable structured failure */
18
27
  export const isStructured = r => r !== null && typeof r === 'object' && typeof r.code === 'string' && r.code.length > 0;
package/core/opsGuard.js CHANGED
@@ -2,6 +2,7 @@
2
2
  // Ops.guard(where) is the public entry; the work is here.
3
3
  import { coded } from './errorHints.js';
4
4
  import { devError, fmt } from './opsCheck.js';
5
+ import { warnOnce } from './validate.js';
5
6
 
6
7
  const STRINGS = {
7
8
  canWrote: "{name}'s can changed state ({where}). can is read-only; change state in run",
@@ -18,9 +19,8 @@ export function guardWrite(ops, where) {
18
19
  if (ops._client ? !e.ready || ops._allowDepth > 0 || where === 'world.move' : !e.ready || e._inFixed || ops._stack.length || ops._allowDepth > 0) return;
19
20
  // first caller outside the engine: skip frames in engine folders, or in the bundle file this guard itself lives in
20
21
  const lines = (new Error().stack || '').split('\n'), file = l => l.match(/\(?([^()\s]+?):\d+:\d+\)?$/)?.[1], own = file(lines[1] || '');
21
- const at = lines.slice(4) // 0 Error, 1 guardWrite, 2 Ops.guard, 3 the module method that called guard, then its callers.find(l => !/\/(core|modules)\//.test(l) && file(l) !== own)?.trim() ?? '';
22
+ // 0 Error, 1 guardWrite, 2 Ops.guard, 3 the module method that called guard, then its callers
23
+ const at = lines.slice(4).find(l => !/\/(core|modules)\//.test(l) && file(l) !== own)?.trim() ?? '';
22
24
  const key = where + '|' + at;
23
- if (ops._warned.has(key)) return;
24
- ops._warned.add(key);
25
- console.warn(coded('ops-guard', fmt(ops._client ? STRINGS.clientGuard : STRINGS.guard, { where, at: at ? ', called ' + at : '' })));
25
+ warnOnce(coded('ops-guard', fmt(ops._client ? STRINGS.clientGuard : STRINGS.guard, { where, at: at ? ', called ' + at : '' })), 'ops-guard\0' + key); // once per call site
26
26
  }
package/core/opsRun.js CHANGED
@@ -3,12 +3,12 @@
3
3
  import { DEV } from './validate.js';
4
4
  import { devError, fmt, argRange } from './opsCheck.js';
5
5
  import { reportError } from './errors.js';
6
- import { failure, isRunFailure } from './opsFail.js';
6
+ import { failure, isRunFailure, opsBlocked } from './opsFail.js';
7
7
  import { snapshot, rollback, markRolledBack } from './opsAtomic.js';
8
8
  import { withDefaults } from './params.js';
9
9
 
10
10
  const MAX_DEPTH = 16;
11
- export const RUN_STRINGS = {
11
+ const RUN_STRINGS = {
12
12
  canRun: "{name}'s can called ops.run('{inner}'). can is read-only; call other ops from run",
13
13
  loop: 'ops call each other in a loop (deeper than ' + MAX_DEPTH + '): {chain}',
14
14
  };
@@ -31,7 +31,8 @@ export function runOp(ops, name, args, opts) {
31
31
  const parent = ops._stack.length ? ops._last : null;
32
32
  const ctx = ops._ctx(name, args, opts, parent);
33
33
  const depth = ops._stack.length, ev = e.events, where = `ops.run('${name}')`;
34
- if (e._freezers.has('error')) { ops._log(name, args, ctx, false, 'halted', depth); return ops._res(failure('halted')); }
34
+ const blocked = opsBlocked(e);
35
+ if (blocked) { ops._log(name, args, ctx, false, blocked, depth); return ops._res(failure(blocked)); }
35
36
  if (DEV && args && typeof args === 'object') Object.freeze(args);
36
37
  const failed = (f, h) => { // a failed run: log it, trace it with its code
37
38
  if (h) { h.ok = false; h.code = f.code; } else ops._log(name, args, ctx, false, f.code, depth);