threedog 0.0.0-stage → 0.2.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 (506) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +39 -2
  4. package/core/Animator.js +268 -0
  5. package/core/Assets.js +256 -0
  6. package/core/Audio.js +267 -0
  7. package/core/Baked.js +72 -0
  8. package/core/Batching.js +247 -0
  9. package/core/Budget.js +221 -0
  10. package/core/Clock.js +94 -0
  11. package/core/Commits.js +77 -0
  12. package/core/DebugOverrides.js +143 -0
  13. package/core/Describe.js +145 -0
  14. package/core/Engine.js +184 -0
  15. package/core/Events.js +153 -0
  16. package/core/I18n.js +94 -0
  17. package/core/Input.js +245 -0
  18. package/core/Inspect.js +77 -0
  19. package/core/InspectScene.js +191 -0
  20. package/core/Jobs.js +146 -0
  21. package/core/Loading.js +149 -0
  22. package/core/MaterialInfo.js +32 -0
  23. package/core/Ops.js +256 -0
  24. package/core/Random.js +52 -0
  25. package/core/Rays.js +160 -0
  26. package/core/SaveStore.js +85 -0
  27. package/core/Saves.js +254 -0
  28. package/core/Stream.js +279 -0
  29. package/core/Threads.js +158 -0
  30. package/core/UrlState.js +94 -0
  31. package/core/Vars.js +35 -0
  32. package/core/Views.js +49 -0
  33. package/core/actor.js +23 -0
  34. package/core/assetEntry.js +89 -0
  35. package/core/assetLoad.js +190 -0
  36. package/core/assetManifest.js +35 -0
  37. package/core/assetReport.js +83 -0
  38. package/core/audioRules.js +121 -0
  39. package/core/audioVoice.js +225 -0
  40. package/core/batchGroups.js +116 -0
  41. package/core/canvasBox.js +63 -0
  42. package/core/catalog.js +169 -0
  43. package/core/checks.js +67 -0
  44. package/core/claims.js +51 -0
  45. package/core/dayTime.js +15 -0
  46. package/core/debugView.js +76 -0
  47. package/core/describeRender.js +45 -0
  48. package/core/describeText.js +143 -0
  49. package/core/easing.js +34 -0
  50. package/core/errorCodes.js +205 -0
  51. package/core/errorHints.js +208 -0
  52. package/core/errors.js +40 -0
  53. package/core/events.generated.js +84 -0
  54. package/core/ground.js +102 -0
  55. package/core/holds.js +106 -0
  56. package/core/inputContext.js +69 -0
  57. package/core/inputDefaults.js +22 -0
  58. package/core/inputPad.js +35 -0
  59. package/core/inputPointer.js +48 -0
  60. package/core/inputTouch.js +48 -0
  61. package/core/lifecycle.js +69 -0
  62. package/core/lightWatch.js +56 -0
  63. package/core/look/coreParts.js +112 -0
  64. package/core/look/layers.js +136 -0
  65. package/core/look/part.js +173 -0
  66. package/core/look/report.js +79 -0
  67. package/core/look/write.js +86 -0
  68. package/core/loop.js +200 -0
  69. package/core/math.js +33 -0
  70. package/core/modules.js +196 -0
  71. package/core/movement.js +19 -0
  72. package/core/mulberry32.js +14 -0
  73. package/core/opsAtomic.js +31 -0
  74. package/core/opsCheck.js +97 -0
  75. package/core/opsFail.js +20 -0
  76. package/core/opsGuard.js +26 -0
  77. package/core/opsHistory.js +27 -0
  78. package/core/opsRun.js +77 -0
  79. package/core/page.js +78 -0
  80. package/core/params.js +132 -0
  81. package/core/pureWorker.js +5 -0
  82. package/core/renamed.js +21 -0
  83. package/core/saveApply.js +128 -0
  84. package/core/saveFiles.js +139 -0
  85. package/core/saveIds.js +53 -0
  86. package/core/saveVersions.js +97 -0
  87. package/core/scatter.js +92 -0
  88. package/core/sceneMethods.js +100 -0
  89. package/core/screenToGround.js +39 -0
  90. package/core/services.js +73 -0
  91. package/core/session.js +171 -0
  92. package/core/shadowTypes.js +15 -0
  93. package/core/skip.js +104 -0
  94. package/core/startup.js +135 -0
  95. package/core/streamCells.js +24 -0
  96. package/core/streamSources.js +73 -0
  97. package/core/styleParts.js +96 -0
  98. package/core/targeting.js +64 -0
  99. package/core/thingExplain.js +68 -0
  100. package/core/thingOps.js +168 -0
  101. package/core/things.js +212 -0
  102. package/core/threadPure.js +120 -0
  103. package/core/threadServe.js +25 -0
  104. package/core/tier.js +11 -0
  105. package/core/util.js +11 -0
  106. package/core/validate.js +204 -0
  107. package/docs/AI.md +123 -0
  108. package/docs/API.md +83 -0
  109. package/docs/CODEMAP.md +347 -0
  110. package/docs/COMMANDS.md +108 -0
  111. package/docs/CONVENTIONS.md +145 -0
  112. package/docs/PERF.md +217 -0
  113. package/docs/THREE.md +86 -0
  114. package/docs/api/ambience.md +15 -0
  115. package/docs/api/assets.md +62 -0
  116. package/docs/api/audio.md +53 -0
  117. package/docs/api/budget.md +40 -0
  118. package/docs/api/cameraRig.md +120 -0
  119. package/docs/api/characters.md +144 -0
  120. package/docs/api/clock.md +7 -0
  121. package/docs/api/collision.md +39 -0
  122. package/docs/api/content.md +64 -0
  123. package/docs/api/dialogue.md +39 -0
  124. package/docs/api/engine.md +199 -0
  125. package/docs/api/entities.md +61 -0
  126. package/docs/api/events.md +95 -0
  127. package/docs/api/flow.md +27 -0
  128. package/docs/api/grids.md +11 -0
  129. package/docs/api/ground.md +16 -0
  130. package/docs/api/hlod.md +34 -0
  131. package/docs/api/hud.md +31 -0
  132. package/docs/api/i18n.md +10 -0
  133. package/docs/api/input.md +24 -0
  134. package/docs/api/interactions.md +31 -0
  135. package/docs/api/inventory.md +66 -0
  136. package/docs/api/jobs.md +10 -0
  137. package/docs/api/level.md +41 -0
  138. package/docs/api/lightPool.md +56 -0
  139. package/docs/api/music.md +34 -0
  140. package/docs/api/nav.md +26 -0
  141. package/docs/api/net.md +14 -0
  142. package/docs/api/openWorld.md +24 -0
  143. package/docs/api/particles.md +41 -0
  144. package/docs/api/photo.md +15 -0
  145. package/docs/api/post.md +10 -0
  146. package/docs/api/quests.md +36 -0
  147. package/docs/api/rays.md +26 -0
  148. package/docs/api/rigid.md +84 -0
  149. package/docs/api/saves.md +32 -0
  150. package/docs/api/settings.md +36 -0
  151. package/docs/api/sky.md +58 -0
  152. package/docs/api/stream.md +31 -0
  153. package/docs/api/style.md +134 -0
  154. package/docs/api/terrain.md +34 -0
  155. package/docs/api/timeline.md +39 -0
  156. package/docs/api/tools.md +57 -0
  157. package/docs/api/triggers.md +56 -0
  158. package/docs/api/vars.md +9 -0
  159. package/docs/api/vegetation.md +52 -0
  160. package/docs/api/water.md +48 -0
  161. package/docs/api/weather.md +29 -0
  162. package/docs/api/world.md +30 -0
  163. package/docs/recipes/01-new-game.md +148 -0
  164. package/docs/recipes/02-npc.md +167 -0
  165. package/docs/recipes/03-items-pickups.md +158 -0
  166. package/docs/recipes/04-quests.md +83 -0
  167. package/docs/recipes/05-props-bake.md +159 -0
  168. package/docs/recipes/06-clock-events.md +117 -0
  169. package/docs/recipes/07-flow-scenes-pause.md +132 -0
  170. package/docs/recipes/08-weather-sky.md +74 -0
  171. package/docs/recipes/09-style-pack.md +234 -0
  172. package/docs/recipes/10-blender-level.md +67 -0
  173. package/docs/recipes/11-vehicles.md +55 -0
  174. package/docs/recipes/12-navmesh.md +79 -0
  175. package/docs/recipes/13-animation.md +149 -0
  176. package/docs/recipes/14-custom-module.md +91 -0
  177. package/docs/recipes/15-perf.md +78 -0
  178. package/docs/recipes/16-dev-bridge.md +180 -0
  179. package/docs/recipes/18-world.md +185 -0
  180. package/docs/recipes/19-shooting-picking.md +76 -0
  181. package/docs/recipes/20-content-actions-save.md +176 -0
  182. package/docs/recipes/21-camera.md +153 -0
  183. package/docs/recipes/22-shop-gold.md +107 -0
  184. package/docs/recipes/23-ops.md +175 -0
  185. package/docs/recipes/26-ui-parts.md +138 -0
  186. package/docs/recipes/27-net.md +96 -0
  187. package/docs/recipes/28-terrain.md +80 -0
  188. package/docs/recipes/29-grid.md +87 -0
  189. package/docs/recipes/30-templates.md +131 -0
  190. package/docs/recipes/31-audio.md +126 -0
  191. package/docs/recipes/32-action-game.md +33 -0
  192. package/docs/recipes/33-stream-sources.md +37 -0
  193. package/docs/recipes/34-environment-lighting.md +36 -0
  194. package/docs/recipes/35-style-from-reference.md +89 -0
  195. package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
  196. package/docs/recipes/37-terrain-look-hooks.md +97 -0
  197. package/docs/recipes/38-environment-look-hooks.md +83 -0
  198. package/docs/recipes/40-scene.md +108 -0
  199. package/docs/recipes/41-thing-registry.md +93 -0
  200. package/docs/recipes/42-terrain-shape.md +64 -0
  201. package/docs/recipes/43-shader-patches-surface-looks.md +120 -0
  202. package/docs/recipes/44-water-weather-look-hooks.md +135 -0
  203. package/docs/recipes/45-cascaded-shadows.md +51 -0
  204. package/docs/recipes/46-blender-art-route.md +114 -0
  205. package/docs/recipes/47-island-snow-backdrop.md +44 -0
  206. package/docs/recipes/48-make-material.md +70 -0
  207. package/docs/recipes/49-game-module-contract.md +71 -0
  208. package/docs/recipes/50-own-renderer.md +12 -0
  209. package/docs/recipes/51-capability-catalog.md +63 -0
  210. package/docs/recipes/52-look.md +108 -0
  211. package/examples/action/DESIGN.md +3 -0
  212. package/examples/action/GAMEMAP.md +127 -0
  213. package/examples/action/content/actions.js +8 -0
  214. package/examples/action/content/audio.js +9 -0
  215. package/examples/action/content/index.js +10 -0
  216. package/examples/action/content/items.js +4 -0
  217. package/examples/action/content/places.js +4 -0
  218. package/examples/action/content/props.js +11 -0
  219. package/examples/action/content/templates.js +10 -0
  220. package/examples/action/content/views.js +6 -0
  221. package/examples/action/look.js +5 -0
  222. package/examples/action/main.js +137 -0
  223. package/examples/action/models.js +25 -0
  224. package/examples/sheepisland/GAMEMAP.md +107 -0
  225. package/examples/sheepisland/content/index.js +6 -0
  226. package/examples/sheepisland/content/props.js +19 -0
  227. package/examples/sheepisland/content/templates.js +5 -0
  228. package/examples/sheepisland/content/vegetation.js +8 -0
  229. package/examples/sheepisland/main.js +71 -0
  230. package/examples/sheepisland/params.js +25 -0
  231. package/examples/sheepisland/style/index.js +79 -0
  232. package/examples/sheepisland/style/models.js +59 -0
  233. package/examples/sheepisland/views.js +9 -0
  234. package/examples/styletest/GAMEMAP.md +135 -0
  235. package/examples/styletest/content/index.js +9 -0
  236. package/examples/styletest/content/items.js +8 -0
  237. package/examples/styletest/content/npcs.js +8 -0
  238. package/examples/styletest/content/places.js +5 -0
  239. package/examples/styletest/content/props.js +16 -0
  240. package/examples/styletest/content/templates.js +9 -0
  241. package/examples/styletest/content/vegetation.js +31 -0
  242. package/examples/styletest/look.js +11 -0
  243. package/examples/styletest/main.js +95 -0
  244. package/examples/styletest/models.js +87 -0
  245. package/examples/styletest/overrides.js +33 -0
  246. package/examples/styletest/panel.js +135 -0
  247. package/examples/styletest/params.js +32 -0
  248. package/examples/styletest/views.js +31 -0
  249. package/examples/world/DESIGN.md +5 -0
  250. package/examples/world/GAMEMAP.md +171 -0
  251. package/examples/world/content/actions.js +8 -0
  252. package/examples/world/content/audio.js +25 -0
  253. package/examples/world/content/bodies.js +12 -0
  254. package/examples/world/content/containers.js +4 -0
  255. package/examples/world/content/dialogues.js +33 -0
  256. package/examples/world/content/index.js +17 -0
  257. package/examples/world/content/items.js +10 -0
  258. package/examples/world/content/npcs.js +14 -0
  259. package/examples/world/content/pickups.js +11 -0
  260. package/examples/world/content/places.js +6 -0
  261. package/examples/world/content/props.js +12 -0
  262. package/examples/world/content/quests.js +15 -0
  263. package/examples/world/content/rules.js +23 -0
  264. package/examples/world/content/templates.js +5 -0
  265. package/examples/world/content/vegetation.js +32 -0
  266. package/examples/world/main.js +168 -0
  267. package/examples/world/models.js +28 -0
  268. package/index.d.ts +306 -0
  269. package/index.js +122 -0
  270. package/llms.txt +61 -0
  271. package/modules/ambience/Ambience.js +186 -0
  272. package/modules/camera/FirstPersonCamera.js +131 -0
  273. package/modules/camera/FixedCamera.js +162 -0
  274. package/modules/camera/FollowCamera.js +91 -0
  275. package/modules/camera/RtsCamera.js +132 -0
  276. package/modules/camera/common.js +182 -0
  277. package/modules/camera/index.js +11 -0
  278. package/modules/camera/projection.js +34 -0
  279. package/modules/characters/Character.js +235 -0
  280. package/modules/characters/NPC.js +242 -0
  281. package/modules/characters/assetModel.js +42 -0
  282. package/modules/characters/astar.js +66 -0
  283. package/modules/characters/behaviors.js +72 -0
  284. package/modules/characters/footsteps.js +13 -0
  285. package/modules/characters/index.js +215 -0
  286. package/modules/characters/moveHelpers.js +29 -0
  287. package/modules/characters/movers/common.js +62 -0
  288. package/modules/characters/movers/rapier.js +74 -0
  289. package/modules/characters/movers/simple.js +43 -0
  290. package/modules/characters/npcAvoid.js +129 -0
  291. package/modules/characters/npcSim.js +150 -0
  292. package/modules/characters/npcView.js +42 -0
  293. package/modules/characters/pathAsync.js +113 -0
  294. package/modules/characters/pathJob.js +62 -0
  295. package/modules/characters/pathWorker.js +7 -0
  296. package/modules/characters/playerStrings.js +12 -0
  297. package/modules/characters/proceduralRig.js +58 -0
  298. package/modules/characters/useModel.js +22 -0
  299. package/modules/characters/walkTo.js +58 -0
  300. package/modules/collision/Collision.js +274 -0
  301. package/modules/collision/grid.js +63 -0
  302. package/modules/content/explain.js +13 -0
  303. package/modules/content/ids.js +95 -0
  304. package/modules/content/index.js +154 -0
  305. package/modules/content/loader.js +190 -0
  306. package/modules/content/models.js +69 -0
  307. package/modules/content/packs.js +69 -0
  308. package/modules/content/props.js +89 -0
  309. package/modules/content/rules.js +134 -0
  310. package/modules/content/templates.js +189 -0
  311. package/modules/debug/DebugPanel.js +174 -0
  312. package/modules/entities/Entities.js +243 -0
  313. package/modules/entities/build.js +25 -0
  314. package/modules/entities/index.js +4 -0
  315. package/modules/flow/index.js +101 -0
  316. package/modules/gameplay/Container.js +227 -0
  317. package/modules/gameplay/Containers.js +89 -0
  318. package/modules/gameplay/Dialogue.js +219 -0
  319. package/modules/gameplay/Interactions.js +253 -0
  320. package/modules/gameplay/Inventory.js +224 -0
  321. package/modules/gameplay/Quests.js +205 -0
  322. package/modules/gameplay/boxOps.js +60 -0
  323. package/modules/gameplay/dialogueBox.js +48 -0
  324. package/modules/gameplay/interactionPrompt.js +28 -0
  325. package/modules/gameplay/inventoryOps.js +137 -0
  326. package/modules/gameplay/pickups.js +115 -0
  327. package/modules/gameplay/questLog.js +54 -0
  328. package/modules/gameplay/questSave.js +71 -0
  329. package/modules/grid/Grid.js +184 -0
  330. package/modules/grid/Layer.js +142 -0
  331. package/modules/grid/index.js +236 -0
  332. package/modules/grid/ops.js +73 -0
  333. package/modules/grid/preview.js +85 -0
  334. package/modules/grid/tiles.js +79 -0
  335. package/modules/hlod/index.js +167 -0
  336. package/modules/hud/index.js +167 -0
  337. package/modules/hud/parts.js +80 -0
  338. package/modules/level/geometry.js +46 -0
  339. package/modules/level/heightfield.js +160 -0
  340. package/modules/level/index.js +233 -0
  341. package/modules/level/nodes.js +84 -0
  342. package/modules/lights/index.js +227 -0
  343. package/modules/music/Music.js +294 -0
  344. package/modules/music/index.js +2 -0
  345. package/modules/music/rules.js +28 -0
  346. package/modules/nav/index.js +156 -0
  347. package/modules/nav/navPath.js +17 -0
  348. package/modules/net/Client.js +137 -0
  349. package/modules/net/Host.js +117 -0
  350. package/modules/net/Net.js +49 -0
  351. package/modules/net/index.js +77 -0
  352. package/modules/net/sync.js +114 -0
  353. package/modules/net/transports.js +118 -0
  354. package/modules/particles/Particles.js +179 -0
  355. package/modules/particles/effect.js +112 -0
  356. package/modules/particles/shaders.js +28 -0
  357. package/modules/photo/Photo.js +146 -0
  358. package/modules/rigid/RigidBodies.js +265 -0
  359. package/modules/rigid/Vehicles.js +97 -0
  360. package/modules/rigid/sync.js +158 -0
  361. package/modules/settings/Settings.js +297 -0
  362. package/modules/settings/apply.js +21 -0
  363. package/modules/settings/index.js +3 -0
  364. package/modules/settings/sections.js +156 -0
  365. package/modules/settings/strings.js +53 -0
  366. package/modules/settings/view.js +65 -0
  367. package/modules/sky/Sky.js +259 -0
  368. package/modules/sky/calendar.js +80 -0
  369. package/modules/sky/cascades.js +125 -0
  370. package/modules/sky/clouds.js +79 -0
  371. package/modules/sky/domeLayers.js +33 -0
  372. package/modules/sky/environment.js +141 -0
  373. package/modules/sky/fog.js +139 -0
  374. package/modules/sky/frame.js +77 -0
  375. package/modules/sky/layers.js +69 -0
  376. package/modules/sky/look.js +51 -0
  377. package/modules/sky/lookFog.js +80 -0
  378. package/modules/sky/lookShadow.js +50 -0
  379. package/modules/sky/lookSky.js +108 -0
  380. package/modules/sky/schedule.js +80 -0
  381. package/modules/sky/shader.js +96 -0
  382. package/modules/sky/shadow.js +74 -0
  383. package/modules/sky/skyModule.js +60 -0
  384. package/modules/terrain/ChunkManager.js +260 -0
  385. package/modules/terrain/chunkJob.js +19 -0
  386. package/modules/terrain/chunkLevels.js +40 -0
  387. package/modules/terrain/chunkQueries.js +42 -0
  388. package/modules/terrain/chunkWorker.js +5 -0
  389. package/modules/terrain/index.js +118 -0
  390. package/modules/terrain/lookGround.js +61 -0
  391. package/modules/terrain/mountTerrain.js +32 -0
  392. package/modules/terrain/terrainColorMap.js +41 -0
  393. package/modules/terrain/terrainDefaults.js +39 -0
  394. package/modules/terrain/terrainEdit.js +139 -0
  395. package/modules/terrain/terrainGen.js +155 -0
  396. package/modules/terrain/terrainIsland.js +131 -0
  397. package/modules/terrain/terrainMesh.js +92 -0
  398. package/modules/terrain/terrainShape.js +108 -0
  399. package/modules/terrain/terrainShapeMain.js +41 -0
  400. package/modules/terrain/terrainTexture.js +44 -0
  401. package/modules/timeline/Timeline.js +253 -0
  402. package/modules/timeline/Tween.js +114 -0
  403. package/modules/timeline/letterbox.js +24 -0
  404. package/modules/timeline/shots.js +90 -0
  405. package/modules/triggers/index.js +268 -0
  406. package/modules/vegetation/Vegetation.js +256 -0
  407. package/modules/vegetation/groundChunks.js +177 -0
  408. package/modules/vegetation/index.js +43 -0
  409. package/modules/vegetation/lookWind.js +37 -0
  410. package/modules/vegetation/modelGeometry.js +21 -0
  411. package/modules/water/Water.js +160 -0
  412. package/modules/water/look.js +80 -0
  413. package/modules/water/surface.js +88 -0
  414. package/modules/weather/Weather.js +242 -0
  415. package/modules/weather/look.js +75 -0
  416. package/modules/weather/particles.js +92 -0
  417. package/modules/weather/shaders.js +49 -0
  418. package/modules/weather/strings.js +15 -0
  419. package/modules/world/World.js +231 -0
  420. package/modules/world/cells.js +42 -0
  421. package/modules/world/explain.js +11 -0
  422. package/modules/world/index.js +71 -0
  423. package/modules/world/persist.js +107 -0
  424. package/modules/world/pos.js +20 -0
  425. package/modules/world/records.js +89 -0
  426. package/modules/world/sim.js +175 -0
  427. package/modules/world/simFar.js +82 -0
  428. package/modules/world/state.js +115 -0
  429. package/modules/world/thingSource.js +44 -0
  430. package/modules/world/views.js +182 -0
  431. package/package.json +66 -4
  432. package/presets.js +96 -0
  433. package/render/PostFX.js +240 -0
  434. package/render/detail.js +105 -0
  435. package/render/effects.js +144 -0
  436. package/render/engineUniforms.js +23 -0
  437. package/render/fuse.js +84 -0
  438. package/render/lighting.js +100 -0
  439. package/render/lights.js +18 -0
  440. package/render/lookSurface.js +161 -0
  441. package/render/materials.js +220 -0
  442. package/render/patches.js +252 -0
  443. package/render/postLook.js +86 -0
  444. package/render/surface.js +69 -0
  445. package/render/uniformDecl.js +29 -0
  446. package/types/common.d.ts +34 -0
  447. package/types/core.d.ts +1965 -0
  448. package/types/gameplay.d.ts +1822 -0
  449. package/types/generated/core/Audio.d.ts +200 -0
  450. package/types/generated/core/Batching.d.ts +47 -0
  451. package/types/generated/core/Budget.d.ts +90 -0
  452. package/types/generated/core/Commits.d.ts +31 -0
  453. package/types/generated/core/DebugOverrides.d.ts +52 -0
  454. package/types/generated/core/Events.d.ts +89 -0
  455. package/types/generated/core/I18n.d.ts +30 -0
  456. package/types/generated/core/Input.d.ts +118 -0
  457. package/types/generated/core/Jobs.d.ts +41 -0
  458. package/types/generated/core/Ops.d.ts +203 -0
  459. package/types/generated/core/Random.d.ts +49 -0
  460. package/types/generated/core/Rays.d.ts +49 -0
  461. package/types/generated/core/Saves.d.ts +162 -0
  462. package/types/generated/core/Stream.d.ts +93 -0
  463. package/types/generated/core/Threads.d.ts +82 -0
  464. package/types/generated/core/Views.d.ts +33 -0
  465. package/types/generated/core/audioVoice.d.ts +47 -0
  466. package/types/generated/core/page.d.ts +18 -0
  467. package/types/generated/core/session.d.ts +48 -0
  468. package/types/generated/modules/ambience/Ambience.d.ts +48 -0
  469. package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
  470. package/types/generated/modules/flow/index.d.ts +10 -0
  471. package/types/generated/modules/grid/Grid.d.ts +151 -0
  472. package/types/generated/modules/grid/Layer.d.ts +65 -0
  473. package/types/generated/modules/grid/index.d.ts +86 -0
  474. package/types/generated/modules/hlod/index.d.ts +11 -0
  475. package/types/generated/modules/hud/index.d.ts +10 -0
  476. package/types/generated/modules/lights/index.d.ts +13 -0
  477. package/types/generated/modules/music/Music.d.ts +111 -0
  478. package/types/generated/modules/net/Net.d.ts +34 -0
  479. package/types/generated/modules/net/index.d.ts +53 -0
  480. package/types/generated/modules/net/transports.d.ts +58 -0
  481. package/types/generated/modules/particles/Particles.d.ts +69 -0
  482. package/types/generated/modules/sky/Sky.d.ts +145 -0
  483. package/types/generated/modules/sky/skyModule.d.ts +10 -0
  484. package/types/generated/modules/timeline/Timeline.d.ts +51 -0
  485. package/types/generated/modules/water/Water.d.ts +29 -0
  486. package/types/generated/modules/weather/Weather.d.ts +62 -0
  487. package/types/generated/modules/world/World.d.ts +242 -0
  488. package/types/generated/modules/world/index.d.ts +15 -0
  489. package/types/generated/render/PostFX.d.ts +125 -0
  490. package/types/generated/render/materials.d.ts +100 -0
  491. package/types/generated/render/patches.d.ts +41 -0
  492. package/types/generated/ui/Focus.d.ts +11 -0
  493. package/types/generated/ui/LoadingScreen.d.ts +2 -0
  494. package/types/generated/ui/UI.d.ts +57 -0
  495. package/types/nav.d.ts +52 -0
  496. package/types/physics.d.ts +592 -0
  497. package/types/style.d.ts +638 -0
  498. package/types/worker.d.ts +11 -0
  499. package/types/world.d.ts +772 -0
  500. package/ui/Focus.js +51 -0
  501. package/ui/LoadingScreen.js +42 -0
  502. package/ui/Parts.js +199 -0
  503. package/ui/UI.js +167 -0
  504. package/ui/defaults.js +85 -0
  505. package/ui/theme.js +124 -0
  506. package/ui/touchPart.js +49 -0
@@ -0,0 +1,208 @@
1
+ // Error hints: a table of "message pattern -> likely cause + which doc to read", so an AI that sees an error knows the next step
2
+ // without searching. Appended to engine.error (errors.js), warnOnce (validate.js), .threedog/errors.log (vite-error-relay) and
3
+ // the dev bridge `errors` command, all through hintText() / withHint().
4
+ //
5
+ // hintFor('world data must be plain values (...)') // { id: 'world-plain', cause: '...', docs: ['recipes/18-world.md', ...] }
6
+ // withHint(message) // message + "\n Code: world-plain\n Possible cause: ...\n Read: recipes/18-world.md, api/world.md"
7
+ // throw codedError('clock-interval', 'clock.every(0): ...') // err.code, err.fix, err.docs; the message ends with [clock-interval]
8
+ //
9
+ // Codes: an error the engine raises by name carries a stable code (a key of ERROR_CODES, or an ERROR_HINTS id) as err.code and as a "[code]"
10
+ // tag at the end of its message, so logs, engine.error and the dev bridge `errors` command show it; a message matched only by pattern gets the hint's id.
11
+ //
12
+ // Doc paths are relative to the package docs (recipes/..., api/..., CONVENTIONS.md), same as the shipped docs.
13
+ // Plain data (it imports only errorCodes.js, also plain data), so node tools can load it too. To add a class: append an entry (first match wins, so put specific ones first).
14
+ import { ERROR_CODES } from './errorCodes.js';
15
+ import { RENAMED } from './renamed.js';
16
+ export { RENAMED };
17
+
18
+
19
+ /** @typedef {{ id: string, match: RegExp, cause: string, docs: string[] }} ErrorHint */
20
+
21
+ /** @type {ErrorHint[]} */
22
+ export const ERROR_HINTS = [
23
+ // ---- module install / dependencies ----
24
+ { id: 'module-requires', match: /module \S+ requires module "?\S+"?/i,
25
+ cause: 'A module needs another module that is not installed yet, or is installed after it. Add the missing module, or ' +
26
+ 'put it earlier in engine.use(...) (a typo is suggested in the message).',
27
+ docs: ['recipes/14-custom-module.md', 'api/engine.md'] },
28
+ { id: 'module-cycle', match: /module order forms a cycle/,
29
+ cause: 'before / after constraints of two or more modules point at each other. Remove one of them or give a module a different stage.',
30
+ docs: ['recipes/14-custom-module.md'] },
31
+ { id: 'module-stage', match: /has stage ".*", which is not a stage|sets order, which is not supported/,
32
+ cause: 'Modules sort by stage (+ before / after), not by number. Use one of the listed stage names.',
33
+ docs: ['recipes/14-custom-module.md'] },
34
+ { id: 'module-name', match: /clashes with an existing engine property/,
35
+ cause: 'The module name becomes engine.<name>; it must not be an existing engine property or another module name.',
36
+ docs: ['recipes/14-custom-module.md'] },
37
+ { id: 'module-called', match: /received the module function \S+ itself/,
38
+ cause: 'engine.use() takes the module object: write engine.use(sky()), not engine.use(sky).',
39
+ docs: ['recipes/01-new-game.md', 'api/engine.md'] },
40
+ { id: 'describe-name', match: /describe\.add\(.*\): this name is already taken/,
41
+ cause: 'describe.add names share one namespace with the standard fields and module names. Pick a unique name.',
42
+ docs: ['recipes/16-dev-bridge.md', 'api/engine.md'] },
43
+
44
+ // ---- world data ----
45
+ { id: 'world-missing', match: /world\(\) (installed )?first|world\(\) module|use\(world\(\)\)|world\(\) (is|must)/,
46
+ cause: 'The feature stores its data in engine.world, but the world() module is not installed or comes after it. ' +
47
+ 'engine.use(world(), ...) first; the openWorld() preset already includes it.',
48
+ docs: ['recipes/18-world.md', 'api/world.md'] },
49
+ { id: 'world-plain', match: /world data must be plain values/,
50
+ cause: 'A record holds a three.js object, function or class instance. World data must be JSON-like (it is saved and ' +
51
+ 'may go to a worker). Keep the model in world.present(), the logic in world.simulate().',
52
+ docs: ['recipes/18-world.md', 'api/world.md'] },
53
+ { id: 'frozen-definition', match: /Cannot (assign to read only property|add property .*not extensible|delete property)/,
54
+ cause: 'Definitions (content templates, items, entity types) are shared by every instance and frozen. Keep per-instance ' +
55
+ 'state on the world record (engine.world.set(id, { opened: true })) or in its container; define another template for a different kind of thing.',
56
+ docs: ['recipes/30-templates.md', 'recipes/18-world.md'] },
57
+ { id: 'pickup-prop-id', match: /[Pp]ickup id .* already used|Prop id ".*" is already used|Pickup data lives in world/,
58
+ cause: 'A pickup / prop id collides with other data, or world() is not ordered before inventory(). Use distinct ids; ' +
59
+ 'stable ids are what saves match on.',
60
+ docs: ['recipes/03-items-pickups.md', 'api/inventory.md'] },
61
+ { id: 'world-id', match: /\bid ["'][^"']+["'] (already exists|is already used)|an NPC named ".*" already exists/,
62
+ cause: 'Two records share one id. Omit id to auto-number, give each its own id, or use world.set(id, patch) to update an existing record.',
63
+ docs: ['recipes/18-world.md', 'api/world.md'] },
64
+ { id: 'world-record', match: /world\.\w+\(\): no record with id/,
65
+ cause: 'The id was never added, was removed, or is misspelled. world.query({ kind }) lists what exists.',
66
+ docs: ['recipes/18-world.md', 'api/world.md'] },
67
+ { id: 'world-add', match: /world\.add\(\) needs a kind|needs a stable id|patch must not contain id/,
68
+ cause: 'world.add({ kind, position, ... }) needs a kind; initial records need a stable id; id and kind of an existing ' +
69
+ 'record cannot be changed by set().',
70
+ docs: ['recipes/18-world.md', 'api/world.md'] },
71
+ { id: 'world-present', match: /world\.present\(|build of world\.present/,
72
+ cause: 'present(kind, { build }) must return a three.js object (or use show: rec => false to hide). Errors inside build also land here.',
73
+ docs: ['recipes/18-world.md', 'api/world.md'] },
74
+ { id: 'bad-position', match: /position is not a valid number|array position must be \[x, y, z\]/,
75
+ cause: 'A position was NaN or the wrong shape: a Vector3 used like an array (v[0]), a missing field, or a division by ' +
76
+ 'zero upstream. Use [x, y, z], { x, z } or the Vector3 itself.',
77
+ docs: ['CONVENTIONS.md', 'api/world.md'] },
78
+
79
+ // ---- content / items / npcs ----
80
+ { id: 'content-place', match: /Place ".*" not found|content has props or pickups/,
81
+ cause: 'content.load references a place that has no coordinates, or needs world() for props / pickups. Give the place ' +
82
+ 'in content.load({ places }) or add the marker to the level.',
83
+ docs: ['recipes/20-content-actions-save.md', 'api/content.md'] },
84
+ { id: 'container', match: /inventory\.(container|transfer)|container\.on events|cannot be removed/,
85
+ cause: 'Container id / capacity / count was invalid, or a container used in transfer was never created. Create it ' +
86
+ 'first with inventory.container(id, { capacity }).',
87
+ docs: ['recipes/03-items-pickups.md', 'api/inventory.md'] },
88
+ { id: 'npc-behavior', match: /no NPC behavior named/,
89
+ cause: 'The schedule / behavior name is unknown. Register it with engine.npcs.behavior(name, { near, far }) before ' +
90
+ 'npcs.add, or use a listed built-in.',
91
+ docs: ['recipes/02-npc.md', 'api/characters.md'] },
92
+
93
+ // ---- API misuse caught by validate ----
94
+ { id: 'unknown-option', match: /unknown option "/,
95
+ cause: 'An options key is misspelled or does not exist for this call (ignored, so the feature silently does nothing). ' +
96
+ 'Use the suggested key or one of the listed options.',
97
+ docs: ['api/engine.md', 'CONVENTIONS.md'] },
98
+ { id: 'unknown-name', match: /does not exist, (did you mean|\(available)|does not exist \(available/,
99
+ cause: 'A name (action, item, asset, weather, text key, ...) was never registered or has a typo. The message lists the registered names.',
100
+ docs: ['CONVENTIONS.md', 'api/engine.md'] },
101
+ { id: 'options-object', match: /the second argument must be an options object/,
102
+ cause: 'The old positional form was used. In this engine a position is one argument and the rest goes in an options object.',
103
+ docs: ['CONVENTIONS.md'] },
104
+ { id: 'event-typo', match: /was never emitted or listened to/,
105
+ cause: 'The event name is probably a typo of an engine event (the engine emits no event you did not subscribe to under this name).',
106
+ docs: ['api/events.md'] },
107
+ { id: 'owned-prop', match: /is recomputed every frame/,
108
+ cause: 'A module rewrites this property every frame, so a direct assignment is lost. Use the module API named in the message (e.g. sky.modify).',
109
+ docs: ['recipes/08-weather-sky.md', 'api/sky.md'] },
110
+ { id: 'camera-kind', match: /has no camera kind/,
111
+ cause: 'setCamera() got an unknown camera kind. Use one of the listed kinds; for a camera of your own, take it with engine.takeCamera(owner) and place engine.camera yourself (recipes/21-camera.md).',
112
+ docs: ['recipes/21-camera.md', 'api/cameraRig.md'] },
113
+ { id: 'movement', match: /movement\.\w+ must be a positive number/,
114
+ cause: 'A movement parameter was zero, negative or not a number (a typo in a name gives undefined).',
115
+ docs: ['api/characters.md', 'api/engine.md'] },
116
+ { id: 'commit-fallback', match: /commits\.request\(\) needs a fallback/,
117
+ cause: 'Async results apply at fixed steps; the fallback is the deterministic main-thread computation used when the result is late.',
118
+ docs: ['api/jobs.md'] },
119
+
120
+ // ---- resources / platform ----
121
+ { id: 'asset-critical', match: /Startup blocked: \d+ critical item/,
122
+ cause: 'An asset marked critical: true in the manifest (or an engine.loading.track step) failed, so start() stopped instead of starting ' +
123
+ 'a broken game. The line names the file, HTTP status and manifest. Fix the path or the file; if the game can run without it, drop critical ' +
124
+ 'so it falls back. engine.loading.list({ phase: "failed" }) or threedog loading shows every failure.',
125
+ docs: ['recipes/05-props-bake.md', 'api/assets.md'] },
126
+ { id: 'asset-missing-ref', match: /Asset loaded with missing references/,
127
+ cause: 'The model file loaded, but a file it references (texture image or .bin) is missing, usually after moving the .gltf without its ' +
128
+ 'folder or a case mismatch in the referenced name. Export as .glb (everything in one file) or copy the referenced files next to it.',
129
+ docs: ['recipes/05-props-bake.md', 'api/assets.md'] },
130
+ { id: 'asset-load', match: /Asset failed to load|Audio file failed to load|Failed to load <(img|script|link|audio)/,
131
+ cause: 'The file was not found (404) or is not valid. Check the path (files under public/ are served from /), the ' +
132
+ 'extension, and the case of the name. A registered file that is not critical now shows its fallback; engine.loading.get(name) has the details.',
133
+ docs: ['api/assets.md', 'recipes/05-props-bake.md'] },
134
+ { id: 'audio-unsupported', match: /Audio is not supported/,
135
+ cause: 'No AudioContext in this browser / test environment. Guard calls with typeof AudioContext, or skip audio in headless tests.',
136
+ docs: ['api/audio.md'] },
137
+ { id: 'indexeddb', match: /indexedDB is unavailable/,
138
+ cause: 'Saves use IndexedDB, which is blocked in private windows and some embedded browsers. Test in a normal window, ' +
139
+ 'or export / import the save as a file.',
140
+ docs: ['api/saves.md', 'recipes/20-content-actions-save.md'] },
141
+
142
+ // ---- runtime failures reported by the error tiers (errors.js) ----
143
+ { id: 'gameplay-frozen', match: /threw and gameplay is frozen/,
144
+ cause: 'In dev / tests a gameplay error freezes the game on purpose, so half-applied state is not mistaken for normal. ' +
145
+ 'Read the error printed with it (engine.error has where + message), fix it, reload.',
146
+ docs: ['recipes/16-dev-bridge.md', 'recipes/14-custom-module.md'] },
147
+ { id: 'module-disabled', match: /presentation module \S+ threw and was disabled/,
148
+ cause: 'A presentation-only module (particles, ambience, music...) threw and was switched off; the game keeps running ' +
149
+ 'without it. The error printed with it is the real cause.',
150
+ docs: ['recipes/14-custom-module.md'] },
151
+ { id: 'not-installed', match: /Cannot read properties of (undefined|null) \(reading '[\w$]+'\)|engine\.[\w$]+(\.[\w$]+)* is undefined/,
152
+ cause: 'Usually engine.<module> was used but the module is not installed (engine.use(...)), or it ran before ' +
153
+ 'engine.start() finished. Check the stack for the line, and that the module is in engine.use().',
154
+ docs: ['recipes/01-new-game.md', 'api/engine.md'] },
155
+ { id: 'not-function', match: /[\w$.]+ is not a function/,
156
+ cause: 'The method name is wrong, or the module is not installed (the property is then undefined). Check spelling against api/<module>.md.',
157
+ docs: ['api/engine.md', 'CODEMAP.md'] },
158
+ ];
159
+
160
+
161
+ const TAG = /\[([a-z]+(?:-[a-z0-9]+)+)\]/;
162
+
163
+ /** The hint for a message: its "[code]" tag first (ERROR_CODES or a hint id), else the first pattern that matches; null if none. @param {unknown} message */
164
+ export function hintFor(message) {
165
+ const s = String(message ?? ''), tag = TAG.exec(s)?.[1], c = tag && ERROR_CODES[tag];
166
+ return (c ? { id: tag, cause: c.fix, docs: c.docs } : tag && ERROR_HINTS.find(h => h.id === tag)) || ERROR_HINTS.find(h => h.match.test(s)) || null;
167
+ }
168
+
169
+ /**
170
+ * Machine-readable view of any error: its code, the fix and the pages to read (err.code first, else the hint for its message; nulls when unknown).
171
+ * @param {any} err
172
+ * @returns {{ code: string | null, fix: string | null, docs: string[] }}
173
+ */
174
+ export function errorInfo(err) {
175
+ const h = hintFor(err?.code ? `[${err.code}]` : err?.message ?? err);
176
+ return { code: err?.code ?? h?.id ?? null, fix: err?.fix ?? h?.cause ?? null, docs: err?.docs ?? h?.docs ?? [] };
177
+ }
178
+
179
+ /**
180
+ * An Error with a stable code: err.code, err.fix (what to do), err.docs (pages to read); the message ends with "[code]".
181
+ * @param {string} code a key of ERROR_CODES or an ERROR_HINTS id
182
+ * @param {string} message English: what is wrong and how to fix it
183
+ * @param {ErrorConstructor} [Type] Error by default (TypeError for a wrong argument type)
184
+ * @returns {Error & { code: string, fix: string | null, docs: string[] }}
185
+ * @example throw codedError('clock-interval', 'clock.every(0): seconds must be > 0');
186
+ */
187
+ export function codedError(code, message, Type = Error) {
188
+ const err = /** @type {any} */ (new Type(coded(code, message)));
189
+ return Object.assign(err, errorInfo({ code }));
190
+ }
191
+
192
+ /** The stub every removed old name becomes: throws `<old> was renamed: <new call>` [renamed-api]. @param {keyof RENAMED} key @param {string} [oldOverride] @returns {never} */
193
+ export function renamed(key, oldOverride) { throw codedError('renamed-api', `${oldOverride ?? RENAMED[key].old} was renamed: ${RENAMED[key].now}`); }
194
+
195
+ /** A message tagged with its code, for warnings: warnOnce(coded('save-refused', text)). @param {string} code @param {string} message */
196
+ export function coded(code, message) { return `${message} [${code}]`; }
197
+
198
+ /** Indented lines "Code" (when the message has no [code] tag) + "Possible cause" + "Read"; '' if no hint matches. @param {unknown} message */
199
+ export function hintText(message) {
200
+ const h = hintFor(message);
201
+ if (!h) return '';
202
+ return (TAG.test(String(message)) ? '' : `\n Code: ${h.id}`) + `\n Possible cause: ${h.cause}\n Read: ${h.docs.join(', ')}`;
203
+ }
204
+
205
+ /** message + its hint (unchanged if none matches or it already has one). @example withHint('world data must be plain values (...)') @param {string} message */
206
+ export function withHint(message) {
207
+ return /\n\s*Possible cause:/.test(message) ? message : message + hintText(message);
208
+ }
package/core/errors.js ADDED
@@ -0,0 +1,40 @@
1
+ // Error tiers: what to do when a module hook, onFixed / onFrame / clock callback or event listener throws (the main loop and the event bus both come here).
2
+ // Presentation modules (declared presentation: true: particles, ambience, music, objective marker, far scenery...): disable the module (its hooks are no longer called),
3
+ // log once to the console, emit module:disabled; the game carries on -- a missing effect does not affect gameplay.
4
+ // Gameplay (all other modules, the game's own callbacks and event listeners): in dev and tests (DEV) fail hard -- freeze gameplay (freeze('error')),
5
+ // engine.error records where and why, emits engine:error, and describe() / describeText() show it on the first line;
6
+ // so a half-deducted inventory or half-updated quest does not keep running, and a test does not mistake it for normal. A release build reports once and keeps running (so the player is not stuck for the whole session).
7
+ // soft (core steps such as rendering and stream.update): report once per site and continue.
8
+ // engine.error is machine-readable: { where, message, code, fix, docs } (code / fix / docs come from the error itself or from the hint table, errorHints.js).
9
+ import { DEV } from './validate.js';
10
+ import { errorInfo, hintText } from './errorHints.js';
11
+
12
+ const STRINGS = { once: '[engine] {key} threw (later errors at the same place are not reported again)', disabled: '[engine] presentation module {name} threw and was disabled (the game continues)', halted: '[engine] {key} threw and gameplay is frozen (in dev / tests a gameplay error fails hard; see engine.error for details)', listener: 'listener of event {name}' };
13
+
14
+ /** Handle an error. key: where it happened (for display); module: the module definition that threw (none means a game callback / event listener, counted as gameplay); soft: report only once */
15
+ export function reportError(engine, err, key, { module = null, soft = false } = {}) {
16
+ if (module?.presentation) return disableModule(engine, module, err);
17
+ if (!soft && DEV && !engine.error) {
18
+ const message = String(err?.message ?? err);
19
+ engine.error = { where: key, message, ...errorInfo(err) }; // code + fix + docs: what to do and which page to read
20
+ engine.freeze('error');
21
+ console.error(STRINGS.halted.replace('{key}', key) + hintText(err?.code ? `[${err.code}]` : message), err);
22
+ engine.events.emit('engine:error', engine.error);
23
+ return;
24
+ }
25
+ if (engine._hookErrors.has(key)) return;
26
+ engine._hookErrors.add(key);
27
+ console.error(STRINGS.once.replace('{key}', key), err);
28
+ }
29
+
30
+ /** An event listener threw (called by the event bus): counted as gameplay */
31
+ export function reportListenerError(engine, name, err) { reportError(engine, err, STRINGS.listener.replace('{name}', name)); }
32
+
33
+ /** Disable a presentation module: remove its fixed / frame / afterRender hooks */
34
+ function disableModule(engine, m, err) {
35
+ if (engine.disabledModules.has(m.name)) return;
36
+ engine.disabledModules.add(m.name);
37
+ for (const k in engine._hooks) engine._hooks[k] = engine._hooks[k].filter(h => h.name !== m.name);
38
+ console.error(STRINGS.disabled.replace('{name}', m.name), err);
39
+ engine.events.emit('module:disabled', { name: m.name, message: String(err?.message ?? err) });
40
+ }
@@ -0,0 +1,84 @@
1
+ // Generated, do not edit by hand: npm run map generates it from EventMap in packages/engine/types/core.d.ts (the single source of event names).
2
+ // Event names emitted by the engine and modules, used by Events.js for dev-time spell checking.
3
+ export const ENGINE_EVENTS = [
4
+ 'engine:ready',
5
+ 'audio:ready',
6
+ 'i18n:change',
7
+ 'input:rebind',
8
+ 'input:context',
9
+ 'save:written',
10
+ 'save:imported',
11
+ 'save:loaded',
12
+ 'ui:open',
13
+ 'ui:close',
14
+ 'settings:shadows',
15
+ 'settings:change',
16
+ 'water:add',
17
+ 'water:remove',
18
+ 'day:start',
19
+ 'season:change',
20
+ 'time:skip',
21
+ 'weather:lightning',
22
+ 'weather:change',
23
+ 'camera:shot',
24
+ 'camera:change',
25
+ 'character:jump',
26
+ 'character:model',
27
+ 'character:land',
28
+ 'dialogue:start',
29
+ 'dialogue:line',
30
+ 'dialogue:end',
31
+ 'item:add',
32
+ 'item:remove',
33
+ 'container:add',
34
+ 'container:remove',
35
+ 'item:pickup',
36
+ 'item:use',
37
+ 'quest:start',
38
+ 'quest:step',
39
+ 'quest:done',
40
+ 'quest:part',
41
+ 'quest:fail',
42
+ 'photo:taken',
43
+ 'photo:denied',
44
+ 'trigger:enter',
45
+ 'trigger:exit',
46
+ 'level:loaded',
47
+ 'timeline:start',
48
+ 'timeline:end',
49
+ 'entity:spawn',
50
+ 'entity:remove',
51
+ 'entity:state',
52
+ 'entity:stage',
53
+ 'ground:change',
54
+ 'terrain:void',
55
+ 'vegetation:remove',
56
+ 'vegetation:restore',
57
+ 'music:change',
58
+ 'music:stinger',
59
+ 'state:applied',
60
+ 'anim:end',
61
+ 'world:add',
62
+ 'world:change',
63
+ 'world:remove',
64
+ 'world:load',
65
+ 'net:join',
66
+ 'net:leave',
67
+ 'net:open',
68
+ 'net:close',
69
+ 'net:sync',
70
+ 'net:result',
71
+ 'engine:error',
72
+ 'module:disabled',
73
+ 'vehicle:enter',
74
+ 'vehicle:exit',
75
+ 'flow:change',
76
+ 'flow:transition',
77
+ 'session:end',
78
+ 'session:start',
79
+ 'page:blur',
80
+ 'page:focus',
81
+ 'page:pointerlock',
82
+ 'page:contextlost',
83
+ 'page:contextrestored',
84
+ ];
package/core/ground.js ADDED
@@ -0,0 +1,102 @@
1
+ // Ground API (part of Engine, mixed into Engine.prototype): whoever provides ground height is the "terrain" -- a procedural terrain module, a hand-made level, or a flat plane.
2
+ // The queries below take (x, z), or a Vector3 / Object3D directly: engine.surface(mesh.position)
3
+ import { xzOf } from './math.js';
4
+ import { checkOptions, DEV } from './validate.js';
5
+
6
+ // Default ground: an infinite flat plane at y = 0. A terrain or level module replaces it
7
+ export const flatGround = {
8
+ height: () => 0, slope: () => 0, type: () => 'default', waterLevel: -Infinity,
9
+ // is there ground at (x, z): false only off the outline of terrain({ shape }), where height is -Infinity
10
+ has: () => true,
11
+ // height below which something has fallen out of the world (terrain:void); only an outline sets a finite one
12
+ voidY: () => -Infinity,
13
+ };
14
+ const NO_GROUND = '{who}: there is no ground at ({x}, {z}) (outside terrain({ shape })){left}; check engine.ground.has(x, z) first';
15
+ const noGround = (who, x, z, left = '') => NO_GROUND.replace('{who}', who).replace('{x}', x.toFixed(1)).replace('{z}', z.toFixed(1)).replace('{left}', left);
16
+
17
+ /**
18
+ * Ground height for a place-it-here entry (spawn, props, pickups, npcs, placeAt). Beyond terrain({ shape }) surface() is -Infinity, and that must never
19
+ * reach a position (a save turns it into null / NaN and the object vanishes): dev throws with the fix, release keeps `fallback`. @internal
20
+ */
21
+ export function placeY(e, who, x, z, refY, fallback = 0) {
22
+ const y = e.surface(x, z, refY);
23
+ if (y !== -Infinity) return y;
24
+ if (DEV) throw new Error(noGround(who, x, z));
25
+ return fallback;
26
+ }
27
+ /** Ground height for a visual-only reader (hud anchor, grid tiles, camera start, shot path): off the island use `fallback`, never throw. @internal */
28
+ export function surfaceOr(e, x, z, refY, fallback = 0) {
29
+ const y = e.surface(x, z, refY);
30
+ return y === -Infinity ? fallback : y;
31
+ }
32
+ const WATER_KEYS = ['position', 'radius', 'halfWidth', 'halfDepth', 'level'];
33
+
34
+ // engine.ground.forEachCollider = the provider's own followed by every added source; absent when there is none
35
+ function joinColliders(e) {
36
+ const own = e._groundOwn ?? null, extra = e._groundExtra ?? [];
37
+ const all = own ? [own, ...extra] : extra.slice();
38
+ const g = { ...e.ground };
39
+ if (all.length) g.forEachCollider = (x, z, range, fn) => { for (let i = 0; i < all.length; i++) all[i](x, z, range, fn); };
40
+ else delete g.forEachCollider;
41
+ e.ground = g;
42
+ }
43
+
44
+ export const groundMethods = {
45
+ setGround(g) { this._groundOwn = g.forEachCollider ?? null; this.ground = { ...flatGround, ...g }; joinColliders(this); },
46
+ /**
47
+ * @internal module plumbing: add a source of static circle colliders (x, z, r) to engine.ground.forEachCollider, which collision and path
48
+ * planning read. It survives a later setGround (a level installed after the module), so a module streaming its own colliders
49
+ * (plants scattered over a level model) need not care who provides the ground. Returns { remove() }
50
+ * @param {(x: number, z: number, range: number, fn: (x: number, z: number, r: number) => void) => void} forEach
51
+ */
52
+ addGroundColliders(forEach) {
53
+ const list = (this._groundExtra ||= []);
54
+ list.push(forEach); joinColliders(this);
55
+ return { remove: () => { const i = list.indexOf(forEach); if (i >= 0) { list.splice(i, 1); joinColliders(this); } } };
56
+ },
57
+ /** Ground height. For multi-layer ground (bridges, caves) pass a reference height refY: it picks the highest layer not above refY plus one step; without it, the highest layer. When passing an object, the second argument is refY */
58
+ surface(x, z, refY) {
59
+ if (typeof x === 'object') { refY = z; [x, z] = xzOf(x); }
60
+ return this.ground.height(x, z, refY);
61
+ },
62
+ /** Slope */
63
+ slope(x, z) { if (typeof x === 'object') [x, z] = xzOf(x); return this.ground.slope(x, z); },
64
+ /** Ground type (grass, sand...), used by footsteps and particles */
65
+ groundType(x, z) { if (typeof x === 'object') [x, z] = xzOf(x); return this.ground.type(x, z); },
66
+ /** Put an object on the ground beneath it (y = ground height + offset); returns the object. With multi-layer ground the object's current y is the reference height: things under a bridge stay on the ground, things on it land on the deck */
67
+ snapToGround(obj, offset = 0) {
68
+ const p = obj.position, y = this.surface(p.x, p.z, p.y);
69
+ if (y === -Infinity) { // never write an infinite y: the object would vanish and poison bounds and physics
70
+ if (DEV) throw new Error(noGround('engine.snapToGround()', p.x, p.z, ', so the object was left where it is'));
71
+ return obj;
72
+ }
73
+ p.y = y + offset; return obj;
74
+ },
75
+ /** Water surface height at a point: water bodies (lake, pond, river segment) first, else the global water level; -Infinity if there is no water */
76
+ waterAt(x, z) {
77
+ if (typeof x === 'object') [x, z] = xzOf(x);
78
+ let lv = this.ground.waterLevel;
79
+ const bodies = this.waterBodies;
80
+ for (let i = 0; i < bodies.length; i++) { // indexed: runs per sample, no iterator
81
+ const b = bodies[i];
82
+ const inside = b.radius != null ? (x - b.x) ** 2 + (z - b.z) ** 2 < b.radius * b.radius
83
+ : Math.abs(x - b.x) < b.hw && Math.abs(z - b.z) < b.hd;
84
+ if (inside && b.level > lv) lv = b.level;
85
+ }
86
+ return lv;
87
+ },
88
+ /** Add a water body: a circle { position, radius, level } or a rectangle { position, halfWidth, halfDepth, level } (meters). Returns a handle { body, remove() }. The water module draws it */
89
+ addWaterBody(opts) {
90
+ checkOptions('engine.addWaterBody()', opts, WATER_KEYS);
91
+ const [x, z] = xzOf(opts.position);
92
+ const b = opts.radius != null ? { x, z, radius: opts.radius, level: opts.level }
93
+ : { x, z, hw: opts.halfWidth ?? 1, hd: opts.halfDepth ?? 1, level: opts.level };
94
+ this.waterBodies.push(b); this.events.emit('water:add', b);
95
+ const remove = () => {
96
+ if (!this.waterBodies.includes(b)) return;
97
+ this.waterBodies = this.waterBodies.filter(x => x !== b);
98
+ this.events.emit('water:remove', b);
99
+ };
100
+ return { body: b, remove };
101
+ },
102
+ };
package/core/holds.js ADDED
@@ -0,0 +1,106 @@
1
+ // Who holds the engine still: pause / resume, freeze / unfreeze, runState, and the camera takeover (takeCamera / cameraOverride).
2
+ // Split out of loop.js (which keeps the loop itself) so each owner-based hold uses the same claims() rules (core/claims.js) in one file.
3
+ import { warnOnce } from './validate.js';
4
+ import { coded, renamed } from './errorHints.js';
5
+ import { ownerArgs } from './claims.js';
6
+
7
+ // pause / freeze return a claim handle, but they used to return the engine for chaining (engine.pause('x').step(1)); the handle forwards those
8
+ // calls so old code keeps working. release (optional) replaces the bare claim removal when releasing has side effects (resume restarts the loop).
9
+ const CHAIN = ['pause', 'resume', 'freeze', 'unfreeze', 'step'];
10
+ function chained(e, h, release) {
11
+ const out = { owner: h.owner, remove: release ? () => { if (e._pausers.has(h.owner)) release(); } : h.remove };
12
+ for (const k of CHAIN) out[k] = (...a) => e[k](...a);
13
+ return out;
14
+ }
15
+
16
+ export const holdMethods = {
17
+ /**
18
+ * Pause the real-time loop (the picture stops and the game stops advancing). owner names who paused (default 'game'; pause({ owner }) works too): the loop
19
+ * stays paused until every owner has resumed, and resume(owner) by someone who did not pause does not undo another owner's pause.
20
+ * kind tells engine.runState what the pause means: 'test' (a test or the dev bridge holds it: 'test-paused'); any other pause reads as 'paused'.
21
+ * Returns a handle: remove() resumes this owner (same as resume(owner)); pause / resume / freeze / unfreeze / step on it still chain to the engine.
22
+ * @param {string | { owner?: string, kind?: 'test' }} [owner] @param {{ kind?: 'test' }} [opts]
23
+ * @returns {{ owner: string, remove(): void, [k: string]: any }}
24
+ * @example const p = engine.pause('perf-test'); ... p.remove(); // or engine.resume('perf-test')
25
+ */
26
+ pause(owner, opts) {
27
+ const a = ownerArgs(owner, opts);
28
+ const h = this._pausers.take(a.owner, { kind: a.opts.kind ?? null });
29
+ this.paused = true;
30
+ return chained(this, h, () => this.resume(a.owner));
31
+ },
32
+ /**
33
+ * Resume the real-time loop (in headless mode this starts live running). With owners: removes this owner's pause and resumes only when none remain;
34
+ * a resume by a non-owner while others hold a pause is ignored with a dev warning (a pause that silently stays stops even rendering, so it warns;
35
+ * an unfreeze by a non-owner is the same no-op but quiet, because UI parts release their freeze on every close whether or not they froze).
36
+ * @param {string | { owner?: string }} [owner]
37
+ */
38
+ resume(owner) {
39
+ const { owner: o } = ownerArgs(owner);
40
+ if (this._pausers.size && !this._pausers.has(o)) { warnOnce(coded('pause-owner', `engine.resume('${o}'): paused by ${this._pausers.names().map(n => `'${n}'`).join(', ')}, not by '${o}'. Pass the same owner to pause() and resume(), or the pause stays`)); return this; }
41
+ this._pausers.release(o);
42
+ if (!this._pausers.size && !this.disposed) { this.paused = false; this._loop(); }
43
+ return this;
44
+ },
45
+ // Gameplay freeze (menus, flow 'paused'): no fixed steps (movement, timers, game clock and engine.elapsed all stop) while frame hooks
46
+ // and rendering go on, so the picture and UI stay alive.
47
+ // Gameplay logic (quest checks, cutscene waits) belongs in fixed, or check engine.frozen first in frame (see the top of this file).
48
+ // Unlike pause(), which stops rendering too and is for tests and step(). owner is the freezer's name; play resumes only when all
49
+ // have unfrozen. step() obeys freezes as well. Same claim rules as pause (core/claims.js).
50
+ /**
51
+ * Freeze gameplay for owner (default 'game'; freeze({ owner, kind }) works too). kind 'title' marks a title screen waiting for start (runState 'title-frozen').
52
+ * Returns a handle whose remove() unfreezes this owner; chains to the engine like before.
53
+ * @param {string | { owner?: string, kind?: 'title' }} [owner] @param {{ kind?: 'title' }} [opts]
54
+ * @returns {{ owner: string, remove(): void, [k: string]: any }}
55
+ */
56
+ freeze(owner, opts) {
57
+ const a = ownerArgs(owner, opts);
58
+ return chained(this, this._freezers.take(a.owner, { kind: a.opts.kind ?? null }));
59
+ },
60
+ /** Release owner's freeze (only that owner's) @param {string | { owner?: string }} [owner] */
61
+ unfreeze(owner) { this._freezers.release(ownerArgs(owner).owner); return this; },
62
+ /** True while someone has frozen gameplay */
63
+ get frozen() { return this._freezers.size > 0; },
64
+ /**
65
+ * The one answer to "why is the page (not) advancing"; the dev bridge and the MCP tools copy it as-is.
66
+ * state: 'loading' | 'title-frozen' (a freeze of kind 'title' is up, waiting for start) | 'test-paused' (only pauses of kind 'test': the bridge or a test)
67
+ * | 'paused' (paused or frozen by owners, listed in `by`) | 'running';
68
+ * by: every pause and freeze owner, so closing one part's pause can be told from a player's;
69
+ * blockedBy: what keeps the player's input from driving the game: each opaque input context ('win-settings', 'ui-title', 'dialogue', 'cutscene'...),
70
+ * 'error' (a gameplay error froze the game) and 'loading' (the loading screen blocks).
71
+ * @returns {{ state: 'loading' | 'title-frozen' | 'test-paused' | 'paused' | 'running', by: string[], blockedBy: string[] }}
72
+ */
73
+ get runState() {
74
+ const P = this._pausers, F = this._freezers, by = [...P.names(), ...F.names()];
75
+ const lv = this.loading?.view();
76
+ const onlyTest = by.length > 0 && !F.size && !P.some(d => d.kind !== 'test');
77
+ const state = !this.ready || !lv?.done ? 'loading' : F.some(d => d.kind === 'title') ? 'title-frozen'
78
+ : !by.length && !this.paused ? 'running' : !by.length || onlyTest ? 'test-paused' : 'paused';
79
+ const blockedBy = (this.input?.contexts ?? []).filter((n, i) => !this.input._stack[i].pass);
80
+ if (F.has('error')) blockedBy.push('error');
81
+ if (lv?.blocked) blockedBy.push('loading');
82
+ return { state, by, blockedBy };
83
+ },
84
+
85
+ // ---------- camera takeover ----------
86
+ // While anyone holds the camera, no camera module moves it (camera/common.js reads cameraOverride). Before this was a bare field: a named view
87
+ // overwrote a running cutscene's takeover and release() then handed the camera to nobody. Now each holder has a claim; the latest holder is in charge,
88
+ // and releasing it hands the camera back to the previous holder (or to the rig when none is left).
89
+ /**
90
+ * Take the camera over: camera modules leave engine.camera alone until every holder has released it. The latest holder is in charge; its focus
91
+ * (optional) is where the world loads around. Returns { remove() } (only this owner's claim). engine.cameraOverride shows the holder in charge.
92
+ * @param {string | { owner: string, focus?: import('three').Vector3 }} owner @param {{ focus?: import('three').Vector3, [k: string]: any }} [opts] extra fields stay readable on cameraOverride
93
+ * @returns {{ owner: string, remove(): void }}
94
+ * @example const cam = engine.takeCamera('photo-mode', { focus: engine.player.position }); ... cam.remove();
95
+ */
96
+ takeCamera(owner, opts) {
97
+ const a = ownerArgs(owner, opts, undefined);
98
+ return this._cameraClaims.take(a.owner, { ...a.opts, owner: a.owner });
99
+ },
100
+ /**
101
+ * The camera holder in charge ({ owner, focus? }), or null. Read-only: assigning throws renamed-api and names engine.takeCamera(owner).
102
+ * @type {{ owner: string, focus?: import('three').Vector3, [k: string]: any } | null}
103
+ */
104
+ get cameraOverride() { return this._cameraClaims?.top()?.data ?? null; },
105
+ set cameraOverride(_v) { renamed('cameraOverride'); },
106
+ };
@@ -0,0 +1,69 @@
1
+ // Input contexts (like Unity's Action Maps): a stack of named groups of actions. The top context shadows lower ones that bind the same key;
2
+ // an opaque context (the default) blocks everything below it, a `pass` context lets unrelated actions through. Menus, dialogue, cutscenes and
3
+ // full-screen UI push an opaque context instead of "locking input", so there is one mechanism, not two.
4
+ // Changes take effect at the start of the next fixed step (before the input snapshot), so a key pressed in step N never acts in both the old and the new context.
5
+
6
+ const BASE_CONTEXT = 'gameplay';
7
+
8
+ /** @internal */
9
+ export function initContexts(input) {
10
+ input._stack = [{ name: BASE_CONTEXT, pass: true }];
11
+ input._pendingCtx = [];
12
+ input._readable = null; // action -> readable? Rebuilt lazily after a switch / define / rebind
13
+ input._muted = new Set(); // keys cleared by a switch: ignored until physically released (keyboard auto-repeat must not revive them)
14
+ }
15
+
16
+ /** @internal */
17
+ export function pushContext(input, name, { pass = false } = {}) {
18
+ const entry = { name, pass };
19
+ let gone = false;
20
+ input._pendingCtx.push({ add: entry });
21
+ return {
22
+ name,
23
+ /** Pop this context (safe to call twice) */
24
+ remove() { if (!gone) { gone = true; input._pendingCtx.push({ del: entry }); } },
25
+ };
26
+ }
27
+
28
+ /** Which actions can currently be read: walk the stack from the top down to the action's own context @internal */
29
+ export function readableMap(input) {
30
+ if (input._readable) return input._readable;
31
+ const keysOf = new Map();
32
+ for (const [, a] of input.actions) { const c = a.context || BASE_CONTEXT; let s = keysOf.get(c); if (!s) keysOf.set(c, s = new Set()); for (const k of a.keys) s.add(k); }
33
+ const m = new Map(), stack = input._stack;
34
+ for (const [name, a] of input.actions) {
35
+ const ctx = a.context || BASE_CONTEXT;
36
+ let ok = false;
37
+ for (let i = stack.length - 1; i >= 0; i--) {
38
+ const c = stack[i];
39
+ if (c.name === ctx) { ok = true; break; }
40
+ if (!c.pass) break;
41
+ const shadow = keysOf.get(c.name);
42
+ if (shadow && a.keys.some(k => shadow.has(k))) break;
43
+ }
44
+ m.set(name, ok);
45
+ }
46
+ return input._readable = m;
47
+ }
48
+
49
+ /** Apply queued push/remove at the start of a fixed step; held keys of newly blocked actions are cleared (a key stays dead until released) @internal */
50
+ export function applyContexts(input) {
51
+ const q = input._pendingCtx;
52
+ if (!q.length) return;
53
+ const before = readableMap(input);
54
+ for (const op of q) {
55
+ if (op.add) input._stack.push(op.add);
56
+ else { const i = input._stack.indexOf(op.del); if (i > 0) input._stack.splice(i, 1); }
57
+ }
58
+ q.length = 0;
59
+ input._readable = null;
60
+ const after = readableMap(input);
61
+ for (const [name, was] of before) {
62
+ if (!was || after.get(name)) continue;
63
+ for (const k of input.actions.get(name)?.keys ?? []) {
64
+ if (!input.keys.has(k)) continue; // even if another action on this key becomes readable: it needs a fresh press (F that boards must not also exit)
65
+ input.keys.delete(k); input._accP.delete(k); input._accR.delete(k); input._muted.add(k);
66
+ }
67
+ }
68
+ input.engine.events.emit('input:context', { stack: input._stack.map(c => c.name) });
69
+ }
@@ -0,0 +1,22 @@
1
+ // Input defaults and strings (split out of Input.js): neutral actions, bound-action labels, gamepad menu keys, the redefine warning.
2
+ // Only neutral input lives here: the direction axis (input.axis, the touch stick) and menu confirm / cancel. Nothing in it does anything until a game or module
3
+ // reads it.
4
+ // Gameplay keys (run, interact, jump...) are not core defaults: the game binds them (createEngine({ bindings }), input.define, a module's keys option or a
5
+ // preset such as
6
+ // presets.player.thirdPerson / presets.interactions.nearest), so no game inherits another game's Shift-to-run or E-to-use.
7
+ export const DEFAULT_ACTIONS = {
8
+ moveForward: [['KeyW', 'ArrowUp'], 'input.moveForward'],
9
+ moveBack: [['KeyS', 'ArrowDown'], 'input.moveBack'],
10
+ moveLeft: [['KeyA', 'ArrowLeft'], 'input.moveLeft'],
11
+ moveRight: [['KeyD', 'ArrowRight'], 'input.moveRight'],
12
+ confirm: [['Space', 'Enter'], 'input.confirm'],
13
+ cancel: [['Escape'], 'input.cancel'],
14
+ };
15
+ // display names for actions a game creates through createEngine({ bindings }) before the module that reads them defines its label
16
+ export const BOUND_LABELS = { run: 'input.run', interact: 'input.interact', jump: 'input.jump' };
17
+ // Default gamepad keys for the neutral menu actions only (confirm / cancel / menu): added when the action is registered (override in createEngine({ padBindings
18
+ // })).
19
+ // Gameplay actions (jump, run, interact, inventory...) get pad keys the same way as keyboard keys: from the game or a preset (presets.player.*, presets.keys.*)
20
+ export const PAD_DEFAULTS = { confirm: 'PadA', cancel: 'PadB', menu: 'PadStart' };
21
+ const STRINGS = { redefine: 'Input action "{action}" defined twice: it already had keys {from}, now {to}; the later definition overrides. Ignore this if the change is intended; to change only the label, pass the same keys' };
22
+ export const fmtRedefine = (action, from, to) => STRINGS.redefine.replace('{action}', action).replace('{from}', from.join(', ')).replace('{to}', to.join(', '));