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,134 @@
1
+ // Content vocabulary: the "conditions" and "effects" that content files (content/*.js) can use. Shared by the loader, the validator packages/tools/content-check.mjs and the map packages/tools/gamemap.mjs.
2
+ // Plain data + small functions, no import of three or the engine (the validator reads it directly in node). Real execution is in loader.js.
3
+ //
4
+ // Conditions (quest step done, dialogue option if, line variant if): several items in one object must all hold; array = every item holds
5
+ // { flag: 'metFisher' } { notFlag: 'x' } { has: { berry: 3 } } { lacks: { film: 6 } } { counter: { sunsetPhotos: 1 } }
6
+ // { can: ['shop.buy', { shop: 'bakery', item: 'bread' }] } an op would succeed now (engine.ops.can)
7
+ // Effects (dialogue node/option do, quest reward, trigger onEnter/onExit): same, one or several items or an array
8
+ // { setFlag: 'metFisher' } { give: { film: 6 } } { take: { berry: 3 } } { bump: 'sunsetPhotos' } { startQuest: 'first-light' }
9
+ // { toast: 'text' } { particles: { name: 'sparks', at: [x, y, z], count: 40 } }
10
+ // { marker: 'river' } or { marker: { place: 'home', x: 2, z: 0, label: '门口' } } adds an objective marker (hud module); { clearMarker: 'river' } removes it
11
+ // { op: ['shop.buy', { shop: 'bakery', item: 'bread' }] } runs a game op (engine.ops.run). A game's own actions are ops (recipes/23-ops.md), never new effect words,
12
+ // so every action has one registration and one log.
13
+ //
14
+ // Game condition words: in content/rules.js, export default { conditions: { word: { ref, desc, describe, test } } } (conditions only read state),
15
+ // registered automatically when the engine loads, and the validator and map read it too. ref is the value notation (the validator checks by it, the loader converts by it):
16
+ // flag flag name · counter counter name · itemCounts { item: count } · counterCounts { counter: count } · quest quest id · text text
17
+ // particles { name, at, count } · clock 'HH:MM' (test/run receive a 0-1 fraction) · position place name or { place, x, z } (receive { x, z })
18
+ // op ['noun.verb', { args }] · any not checked
19
+ //
20
+ // Game content kinds: the same content/rules.js may export kinds: { name: { desc, load, check, map } }, so a game keeps its own data
21
+ // (enemies, recipes, loot tables, waves, shop stock) in content/<name>.js. The loader, content-check and GAMEMAP all read this one table:
22
+ // desc one line (map, file list) · load(e, data, content) hands the data to the game when engine.content.load runs (required)
23
+ // check(data, ctx) optional validation in npm run check: ctx.err(msg) / ctx.warn(msg); ctx.data is all content (items, npcs…), ctx.known(obj) lists ids
24
+ // map(data) optional GAMEMAP lines (default: the number of entries and their ids)
25
+ // export default { kinds: { recipes: { desc: 'crafting recipes (id -> { needs: { item: n }, makes })', load: (e, data) => e.crafting.add(data),
26
+ // check: (data, ctx) => { for (const [id, r] of Object.entries(data)) if (!ctx.data.items?.[r.makes]) ctx.err(`recipe ${id} makes unknown item ${r.makes}`); } } } };
27
+
28
+ const counts = o => Object.entries(o || {}).map(([k, n]) => `${k}×${n}`).join('、');
29
+ const opText = v => Array.isArray(v) ? `${v[0]}${v[1] ? ' ' + Object.entries(v[1]).map(([k, x]) => `${k}=${x}`).join(' ') : ''}` : String(v);
30
+ const posText = v => typeof v === 'string' ? v : v.place ? `${v.place}${v.x || v.z ? `(${v.x ?? 0},${v.z ?? 0})` : ''}` : `(${v.x},${v.z})`;
31
+
32
+ const RULE_STRINGS = {
33
+ conditions: {
34
+ flag: { ref: 'flag', desc: 'story flag is set', describe: v => `flag ${v}` },
35
+ notFlag: { ref: 'flag', desc: 'story flag is not set', describe: v => `no flag ${v}` },
36
+ has: { ref: 'itemCounts', desc: 'inventory has at least', describe: v => `has ${counts(v)}` },
37
+ lacks: { ref: 'itemCounts', desc: 'inventory has fewer than', describe: v => `fewer than ${counts(v)}` },
38
+ counter: { ref: 'counterCounts', desc: 'counter is at least', describe: v => `counter ${Object.entries(v).map(([a, n]) => `${a}≥${n}`).join(', ')}` },
39
+ can: { ref: 'op', desc: 'an op would succeed now (engine.ops.can)', describe: v => `can ${opText(v)}` },
40
+ },
41
+ effects: {
42
+ setFlag: { ref: 'flag', desc: 'set a story flag', describe: v => `set flag ${v}` },
43
+ give: { ref: 'itemCounts', desc: 'give items', describe: v => `give ${counts(v)}` },
44
+ take: { ref: 'itemCounts', desc: 'take items', describe: v => `take ${counts(v)}` },
45
+ bump: { ref: 'counter', desc: 'counter +1', describe: v => `counter ${v}+1` },
46
+ startQuest: { ref: 'quest', desc: 'start a quest', describe: v => `start quest ${v}` },
47
+ toast: { ref: 'text', desc: 'show a toast', describe: v => `toast "${v}"` },
48
+ particles: { ref: 'particles', desc: 'play particles', describe: v => `particles ${v.name}×${v.count ?? ''}` },
49
+ marker: { ref: 'position', desc: 'add an objective marker (hud module)', describe: v => `marker ${posText(v)}${v.label ? `"${v.label}"` : ''}` },
50
+ clearMarker: { ref: 'position', desc: 'remove an objective marker', describe: v => `remove marker ${posText(v)}` },
51
+ op: { ref: 'op', desc: "run a game op (engine.ops.run); the game's own actions are ops", describe: v => `op ${opText(v)}` },
52
+ },
53
+ // content file name -> description (only these files are recognized in content/)
54
+ files: {
55
+ items: 'items (id -> name, icon, description); also export startItems for starting items',
56
+ pickups: 'pickups on the ground (list)',
57
+ containers: 'chests / shelves (container id -> { capacity, items: starting goods }; starting goods are placed only the first time, then saved)',
58
+ npcs: 'NPCs (id -> name, schedule, dialogue)',
59
+ dialogues: 'dialogues (id -> speaker, nodes)',
60
+ quests: 'quests (id -> title, steps, reward; a step can have a target position)',
61
+ actions: 'own key actions of the game (action name -> default key, label)',
62
+ places: 'place names (coordinates computed at runtime in main.js)',
63
+ triggers: 'trigger zones (tag -> position / from level, enter/exit effects)',
64
+ level: 'level markers (spawn point, NPCs, trigger zones)',
65
+ vegetation: 'vegetation (name -> model, growth rule)',
66
+ props: 'props (list: model, position, facing, collision; or { template, x, z } = an instance of a template; or { id, grid, item, cell } = a grid item), streamed in on demand',
67
+ templates: 'reusable objects (name -> model, collide, interact, container, sound, animate, state defaults, physics body); shared read-only definitions',
68
+ audio: 'sounds by asset name, ambience and music rules as data, footsteps (sounds, ambience, music: { tracks, rules }, footsteps)',
69
+ views: 'named fixed camera views (name -> { position: [x, y, z], target?: [x, y, z], fov? }); engine.views.show(name), ?view=name, npm run shot -- -w game --view name',
70
+ grids: 'placement grids (name -> { cell, origin, size, zone?, flat? }); layout rules, not saved',
71
+ renames: "renamed or deleted authored ids (old id -> new id, or null = deleted on purpose): the player's saved changes follow the new id",
72
+ rules: 'condition words added by the game ({ conditions }); actions are ops, not effect words',
73
+ },
74
+ // ref of conditions / effects -> how to write the value (used to generate API docs)
75
+ refs: {
76
+ flag: "value is a flag name, e.g. 'metFisher'", counter: "value is a counter name, e.g. 'sunsetPhotos'", itemCounts: 'value is { itemId: count }, e.g. { berry: 3 }',
77
+ counterCounts: 'value is { counterName: count }, e.g. { sunsetPhotos: 1 }', quest: 'value is a quest id', text: 'value is text',
78
+ particles: 'value is { name, at: [x, y, z], count }', op: "value is ['noun.verb', { args }], e.g. ['shop.buy', { shop: 'bakery', item: 'bread' }]", position: 'value is a place name, or { place, x, z } / { x, z }', clock: "value is 'HH:MM'", any: 'value is passed to the function as is',
79
+ },
80
+ and: ' and ', then: ', ', fn: '(function)',
81
+ };
82
+ const S = RULE_STRINGS;
83
+
84
+ /** Built-in condition words of the engine */
85
+ export const CONDITIONS = RULE_STRINGS.conditions;
86
+ /** Built-in effect words of the engine */
87
+ export const EFFECTS = RULE_STRINGS.effects;
88
+ /** ref → ref -> how to write the value */
89
+ export const REFS = RULE_STRINGS.refs;
90
+ /** content file name -> description */
91
+ export const CONTENT_FILES = RULE_STRINGS.files;
92
+ /** Clock time notation 'HH:MM' (24-hour) */
93
+ export const CLOCK_RE = /^([01]\d|2[0-3]):[0-5]\d$/;
94
+
95
+ /** Merge the engine vocabulary and the game vocabulary (default export of the game's content/rules.js) -> { conditions, effects }. Games add conditions only */
96
+ export function mergeRules(game = {}) {
97
+ return { conditions: { ...CONDITIONS, ...game.conditions }, effects: EFFECTS };
98
+ }
99
+ /** Every content name a game may use: the engine's files plus the game's kinds (rules.js kinds) -> description; the one list loader, content-check and GAMEMAP share */
100
+ export function contentFiles(game = {}) {
101
+ const out = { ...CONTENT_FILES, startItems: 'starting items (exported from items.js)' };
102
+ for (const [name, k] of Object.entries(game?.kinds || {})) out[name] ??= k?.desc || 'game data kind';
103
+ return out;
104
+ }
105
+ /** Problems with a game's kinds table (name clashes with an engine file, no load): a list of messages */
106
+ export function kindProblems(game = {}) {
107
+ return Object.entries(game?.kinds || {}).flatMap(([name, k]) => [
108
+ ...(CONTENT_FILES[name] || name === 'startItems' ? [`kind "${name}" is an engine content file name: pick another name (engine files: ${Object.keys(CONTENT_FILES).join(', ')})`] : []),
109
+ ...(typeof k?.load !== 'function' ? [`kind "${name}" has no load(e, data) function, so its data would never reach the game`] : []),
110
+ ]);
111
+ }
112
+ /** Error text for a content name that is neither an engine file nor a registered kind */
113
+ export const unknownContent = (name, game) => `unknown content "${name}". Known: ${Object.keys(contentFiles(game)).join(', ')}. `
114
+ + `For the game's own data, register it in content/rules.js: export default { kinds: { ${name}: { desc: '…', load: (e, data) => { … } } } }`;
115
+ /** Error text when a game's content/rules.js still exports effects */
116
+ export const NO_GAME_EFFECTS = "content/rules.js: games no longer add effect words. Register the action as an op (engine.ops.define('noun.verb', { can, run }) in main.js) "
117
+ + "and call it from content with { op: ['noun.verb', { args }] }; see recipes/23-ops.md";
118
+
119
+ /** Wrap a single value into an array (a model written as 'tree' or ['tree', ...args]); the one copy for the content files @param {any} v @returns {any[]} */
120
+ export const list = v => (Array.isArray(v) ? v : [v]);
121
+ const say = (vocab, x) => Object.entries(x).map(([k, v]) => vocab[k]?.describe?.(v) ?? `${k} ${JSON.stringify(v)}`);
122
+
123
+ /** Describe a condition as one human-readable sentence (for the map); vocab defaults to the engine vocabulary */
124
+ export function describeCond(c, vocab = CONDITIONS) {
125
+ if (!c) return '';
126
+ if (typeof c === 'function') return S.fn;
127
+ return list(c).map(x => say(vocab, x).join(S.and)).join(S.and);
128
+ }
129
+ /** Describe an effect as one human-readable sentence (for the map); vocab defaults to the engine vocabulary */
130
+ export function describeEffect(a, vocab = EFFECTS) {
131
+ if (!a) return '';
132
+ if (typeof a === 'function') return S.fn;
133
+ return list(a).map(x => say(vocab, x).join(S.then)).join(S.then);
134
+ }
@@ -0,0 +1,189 @@
1
+ // Content templates (content/templates.js): one reusable object = model + collision + interaction + optional container / sound / animation + state defaults.
2
+ // The template is a shared, frozen definition; every placed copy is a world record whose kind is the template name and whose own fields are its state.
3
+ // content/templates.js:
4
+ // export default { chest: { model: 'chest', collide: 'box', state: { opened: false },
5
+ // interact: { label: rec => rec.opened ? '关上' : '打开', op: 'chest.toggle' }, // op is run with { id } of the instance
6
+ // container: { capacity: 6, items: { berry: 2 } }, sound: { use: 'chest' }, // container id = record id
7
+ // animate: (rec, obj, dt) => { obj.rotation.x = rec.opened ? -0.3 : 0; } } }; // per-frame look from the record
8
+ // content/props.js: { template: 'chest', id: 'chest-home', place: 'home', x: 3, z: 1, opened: true, items: { film: 2 } } // position + overrides
9
+ // code (in an op or fixed step): engine.spawn('chest', { x: 10, z: 4 }, { opened: true }) // runtime copy, saved whole
10
+ // Definition (shared, read-only): model, collide, static, interact, container capacity / starting goods, sound, animate, state defaults.
11
+ // Instance (saved): the record (id, kind, position, rot, scale, y offset, state fields) and the container with the record's id (its goods).
12
+ // A placement may override only rot / scale / y / items and the state fields; a different look or behaviour is a different template.
13
+ // Recipe: docs/recipes/30-templates.md.
14
+ // body: { shape: 'box' | 'ball' | 'hull', mass?, friction?, restitution?, damping?, angularDamping? } makes each copy a rigid body (needs rigid()):
15
+ // it can be pushed, the model moves itself and its position is copied back to the record, so a pushed crate's place is saved like any other change.
16
+ // Ids: an instance with state (state / container / interact / body) should have a written id (ids.js); without one dev warns.
17
+ import { checkOptions, freezeDef, missingText, fmt, DEV } from '../../core/validate.js';
18
+ import { xzOf } from '../../core/math.js';
19
+ import { placeY } from '../../core/ground.js';
20
+ import { buildModel, settle, fitKey, unbuildModel } from './models.js';
21
+ import { srcOf, stateful, templateId } from './ids.js';
22
+
23
+ const DEF_KEYS = ['model', 'collide', 'static', 'interact', 'container', 'sound', 'animate', 'state', 'body'];
24
+ const BODY_KEYS = ['shape', 'mass', 'friction', 'restitution', 'damping', 'angularDamping'];
25
+ const OWN_KEYS = ['rot', 'scale', 'y', 'items']; // what one instance may set besides its state fields
26
+
27
+ const STRINGS = {
28
+ noModel: "template '{name}' needs a model (a style pack model name or an assets name), e.g. { model: 'chest' }",
29
+ noOp: "template '{name}': interact needs op, the op run with { id } of the instance when used, e.g. interact: { label: '打开', op: 'chest.toggle' } "
30
+ + "and in main.js engine.ops.define('chest.toggle', { run: (e, { id }) => e.world.set(id, { opened: !e.world.get(id).opened }) })",
31
+ taken: "template '{name}': world kind '{name}' already has a world.present of its own; rename the template (its name is the kind of its instances)",
32
+ clash: 'template instance id "{id}" is already used by other data (kind {kind}): give it a different id, e.g. { id: "{id}-2", template: "{name}" }',
33
+ defKey: "template '{name}': '{key}' belongs to the definition and cannot be set per instance. Define another template for a different {key}",
34
+ noBox: "template '{name}' has no container, so an instance cannot have items. Add container: { capacity } to the template",
35
+ noInv: "template '{name}' has a container: install inventory() (the openWorld() preset includes it)",
36
+ noRigid: "template '{name}' has a body: install rigid() (real physics; the openWorld() preset includes it)",
37
+ shape: "template '{name}': body.shape must be 'box', 'ball' or 'hull', e.g. body: { shape: 'box', mass: 2 }",
38
+ };
39
+
40
+ /** Register template definitions (frozen) and their presenters; a later load replaces a definition of the same name. @internal */
41
+ export function defineTemplates(e, api, st, defs) {
42
+ for (const [name, d] of Object.entries(defs)) {
43
+ checkOptions(`template '${name}'`, d, DEF_KEYS);
44
+ if (!d?.model) throw new Error(fmt(STRINGS.noModel, { name }));
45
+ if (d.interact) {
46
+ checkOptions(`template '${name}' interact`, d.interact, ['label', 'op', 'radius', 'height', 'action', 'enabled']);
47
+ if (!d.interact.op) throw new Error(fmt(STRINGS.noOp, { name }));
48
+ st.ops.add(d.interact.op); // checked against engine.ops once the game is ready, like { op } in content
49
+ }
50
+ checkOptions(`template '${name}' container`, d.container, ['capacity', 'maxWeight', 'items']);
51
+ checkOptions(`template '${name}' sound`, d.sound, ['use']);
52
+ if (d.container && !e.inventory) throw new Error(fmt(STRINGS.noInv, { name }));
53
+ if (d.body) {
54
+ checkOptions(`template '${name}' body`, d.body, BODY_KEYS);
55
+ if (!['box', 'ball', 'hull'].includes(d.body.shape)) throw new Error(fmt(STRINGS.shape, { name }));
56
+ if (!e.rigid) throw new Error(fmt(STRINGS.noRigid, { name }));
57
+ }
58
+ st.templates.set(name, freezeDef(d));
59
+ if (DEV) st.templateSrc.set(name, srcOf(defs, name));
60
+ present(e, api, st, name);
61
+ limitContainers(e, st, name);
62
+ }
63
+ // a save brings back runtime instances and their goods, but container limits are definition data: put them back from the template
64
+ st.templateLoad ??= e.events.on('world:load', () => { for (const name of st.templates.keys()) limitContainers(e, st, name); });
65
+ }
66
+
67
+ /** The definition of a template, or a dev error listing the known ones. @internal */
68
+ export function templateOf(st, name) {
69
+ const d = st.templates.get(name);
70
+ if (!d) throw new Error(`${missingText('template', name, [...st.templates.keys()])} (define it in content/templates.js)`);
71
+ return d;
72
+ }
73
+
74
+ /**
75
+ * One entry of content/props.js with template: an initial world record (stable id `<template>:<index>` unless given). @internal
76
+ * ids: this load's IdCheck (null for level nodes, whose ids the level makes); origin: where it was authored ({ definedAt } or { level, node }), dev only
77
+ */
78
+ export function placeTemplate(e, api, st, p, i, zone, ids, origin) {
79
+ const name = p.template, d = templateOf(st, name), id = templateId(p, i), { x, y, z } = api.where(p), floor = api._floorOf(p);
80
+ const own = instanceFields(name, d, p, ['template', 'id', 'place', 'x', 'z', 'floor']);
81
+ if (floor !== undefined) own.floor = floor; // same as props: a moved instance lands on the same storey
82
+ if (ids && p.id != null) ids.claim(p.id, `props[${i}] (template ${name})`);
83
+ else if (ids && stateful(d)) ids.unnamed(id, `props[${i}] (template ${name})`);
84
+ const rec = e.world.add({ id, kind: name, position: { x, y: y ?? placeY(e, `props[${i}] (template ${name})`, x, z), z }, ...own, ...(zone != null && { zone }) }, { initial: true });
85
+ if (rec && rec.kind !== name) throw new Error(fmt(STRINGS.clash, { id, kind: rec.kind, name }));
86
+ if (DEV) e.world.setOrigin(id, { ...(typeof origin === 'string' ? { definedAt: origin } : origin), template: name, templateAt: st.templateSrc.get(name) ?? null, model: d.model });
87
+ if (rec) openContainer(e, name, d, id, p.items); // null = removed in the save: no container either
88
+ }
89
+
90
+ /** engine.spawn: a runtime instance (saved whole). at = position ({ x, z } or [x, y, z]; it sits on the ground, fields.y lifts it). @internal */
91
+ export function spawnTemplate(e, st, name, at, fields = {}) {
92
+ const d = templateOf(st, name), [x, z] = xzOf(at);
93
+ const own = instanceFields(name, d, fields, ['id']);
94
+ const rec = e.world.add({ ...(fields.id != null && { id: fields.id }), kind: name, position: { x, y: placeY(e, `engine.spawn('${name}')`, x, z, undefined, 0) + (fields.y ?? 0), z }, ...own });
95
+ if (DEV) e.world.setOrigin(rec.id, { template: name, templateAt: st.templateSrc.get(name) ?? null, model: d.model }); // world.add already noted the op that spawned it
96
+ openContainer(e, name, d, rec.id, fields.items);
97
+ return rec;
98
+ }
99
+
100
+ /** Instance fields of a placement: state defaults (copied, never shared), then the allowed overrides. */
101
+ function instanceFields(name, d, p, also) {
102
+ const state = Object.keys(d.state ?? {});
103
+ for (const key of Object.keys(p)) if (DEF_KEYS.includes(key) && !state.includes(key)) throw new Error(fmt(STRINGS.defKey, { name, key }));
104
+ checkOptions(`template '${name}' instance`, p, [...also, ...OWN_KEYS, ...state]);
105
+ if (p.items && !d.container) throw new Error(fmt(STRINGS.noBox, { name }));
106
+ const own = structuredClone(d.state ?? {});
107
+ for (const k of state) if (p[k] !== undefined) own[k] = structuredClone(p[k]);
108
+ for (const k of ['rot', 'scale']) if (p[k] !== undefined) own[k] = p[k];
109
+ if (p.y) own.offsetY = p.y;
110
+ return own;
111
+ }
112
+
113
+ /** The instance's container (id = record id); starting goods only the first time, a save wins afterwards (see Containers). */
114
+ function openContainer(e, name, d, id, items) {
115
+ if (!d.container) return;
116
+ const { capacity, maxWeight } = d.container;
117
+ e.inventory.container(id, { capacity, maxWeight, items: items ?? d.container.items });
118
+ }
119
+
120
+ function limitContainers(e, st, name) {
121
+ const c = st.templates.get(name).container;
122
+ if (c) for (const r of e.world.query({ kind: name })) e.inventory.container(r.id, { capacity: c.capacity, maxWeight: c.maxWeight });
123
+ }
124
+
125
+ /** How a template's instances look: shared prototype model, collision, interaction; built near, torn down far (once per template name). */
126
+ function present(e, api, st, name) {
127
+ if (st.templateViews.has(name)) return;
128
+ if (e.world.presents(name)) throw new Error(fmt(STRINGS.taken, { name }));
129
+ st.templateViews.add(name);
130
+ const def = () => st.templates.get(name); // a later load may replace the definition: always read the current one
131
+ const body = !!def().body; // a physics body moves the model itself: the record follows the model (positionFrom 'view'), so a pushed position is saved
132
+ e.world.present(name, {
133
+ radius: () => Math.max(e.world.radius, e.stream.activeRadius), // same build distance as props
134
+ positionFrom: body ? 'view' : 'record',
135
+ async build(rec) {
136
+ const d = def(), o = await buildModel(e, api, rec, d.model, d.body ? { ...d, static: false, collide: false } : d), id = rec.id;
137
+ if (d.body) addBody(e, rec, o, d.body);
138
+ if (d.interact && e.interactions) o.userData.use = e.interactions.add(o, {
139
+ id, radius: d.interact.radius ?? 2.5, height: d.interact.height, action: d.interact.action,
140
+ label: () => label(e, def().interact?.label, e.world.get(id)) ?? name,
141
+ enabled: () => { const r = e.world.get(id), en = def().interact?.enabled; return !!r && (!en || !!en(r, e)); },
142
+ onUse: () => use(e, def(), id),
143
+ });
144
+ return o;
145
+ },
146
+ update(rec, o, dt) {
147
+ const d = def();
148
+ if (!d.body && o.userData.fit !== fitKey(rec)) settle(e, rec, o, d); // a body places itself
149
+ else if (d.body) restBody(e, rec, o);
150
+ d.animate?.(rec, o, dt);
151
+ },
152
+ dispose(rec, o) { o.userData.use?.remove(); o.userData.body?.remove(); unbuildModel(e, o); },
153
+ });
154
+ }
155
+
156
+ /**
157
+ * A rigid body for one built copy, never batched (it moves). It rests on the ground at the record's place: the collider is centred on the model's origin,
158
+ * so the copy is lifted by half its height, and that resting place counts as the authored one (world.rest), so an untouched crate stays out of the save.
159
+ * The body starts asleep: it stays exactly there until something hits it; then its moves are copied to the record (positionFrom 'view') and saved.
160
+ */
161
+ function addBody(e, rec, o, b) {
162
+ const { shape, ...opts } = b, s = o.userData.proto.size, scale = rec.scale ?? 1;
163
+ o.userData.batch = false;
164
+ const ground = e.surface(rec.position.x, rec.position.z, rec.floor), y = Math.max(rec.position.y, ground + s.y * scale / 2);
165
+ e.world.rest(rec.id, { x: rec.position.x, y, z: rec.position.z });
166
+ o.position.y = rec.position.y;
167
+ o.updateMatrixWorld(true);
168
+ const add = shape === 'ball' ? 'addBall' : shape === 'hull' && o.isMesh ? 'addHull' : 'addBox'; // a hull needs one mesh; a group gets a box
169
+ o.userData.body = e.rigid[add](o, opts);
170
+ o.userData.body?.body.sleep();
171
+ }
172
+ const SETTLE = 0.05; // meters: a body that only settled (contact with uneven ground) moves less than this; a push moves it more
173
+ /** While an authored body only settles where content put it, that settled pose is its authored rest (it stays out of the save); once pushed, the record keeps the change */
174
+ function restBody(e, rec, o) {
175
+ const ud = o.userData, b = ud.body?.body;
176
+ if (ud.pushed || !b) return;
177
+ ud.restAt ??= { ...rec.position };
178
+ const p = rec.position, r = ud.restAt;
179
+ if (Math.abs(p.x - r.x) > SETTLE || Math.abs(p.y - r.y) > SETTLE || Math.abs(p.z - r.z) > SETTLE) { ud.pushed = true; return; }
180
+ if (b.isSleeping()) e.world.rest(rec.id, p, SETTLE);
181
+ }
182
+
183
+ const label = (e, l, rec) => typeof l === 'function' ? l(rec, e) : l && e.i18n.has(l) ? e.t(l) : l;
184
+
185
+ /** Using an instance runs the template's op with its id (a gameplay action, logged), then plays the use sound if it succeeded. */
186
+ function use(e, d, id) {
187
+ const r = e.ops.run(d.interact.op, { id });
188
+ if (r.ok && d.sound?.use) e.audio.sfx(d.sound.use);
189
+ }
@@ -0,0 +1,174 @@
1
+ // Performance panel + time/weather debugging + stress test. Collapsed by default; F3 shows/hides it (debug({ open: true }) shows it at start). Quality, view distance and density are in the settings menu. Do not install this module in a release.
2
+ import { readParams, keysSchema } from '../../core/params.js';
3
+ import { esc } from '../../ui/UI.js';
4
+ /** @import { ModuleDef } from '../../types/core' */
5
+
6
+ // Note: the debug panel is a dev tool; its UI text is plain English, not in the string table; do not install this module in a release.
7
+ // The panel sits next to the core diagnostics as engine.debug.panel (composition): engine.debug (override / clear / view) is core and works without it.
8
+ // It used to subclass DebugOverrides and replace engine.debug, which needed shared state on the engine and a module-name exception; nothing of that is left.
9
+ /** engine.debug.panel (F3 panel) */
10
+ export class DebugPanel {
11
+ /** @internal */
12
+ constructor(engine, { open = false } = {}) {
13
+ /** @internal */ this.engine = engine;
14
+ /** @internal */ this.bench = null;
15
+ /** Stress test running (player auto-runs fast) @type {boolean} */
16
+ this.benchmarking = false;
17
+ /** Panel root element @type {HTMLElement} */
18
+ this.el = document.createElement('div');
19
+ const el = this.el;
20
+ el.className = 'threedog-debug'; el.hidden = !open; // collapsed by default so it does not cover the game HUD
21
+ el.innerHTML = `<style>
22
+ .threedog-debug{position:fixed;top:calc(12px + env(safe-area-inset-top,0px));left:max(12px,env(safe-area-inset-left,0px));width:min(290px,calc(100% - 24px));max-height:calc(100% - 24px);overflow:auto;
23
+ background:rgba(17,23,20,.82);color:#e9ece0;border:1px solid rgba(226,232,214,.14);border-radius:10px;font:12px/1.5 system-ui,"PingFang SC","Microsoft YaHei",sans-serif;z-index:10;backdrop-filter:blur(8px)}
24
+ .threedog-debug .g{display:grid;grid-template-columns:repeat(3,1fr);gap:6px 10px;padding:10px 12px}
25
+ .threedog-debug .s b{display:block;font:600 15px ui-monospace,Menlo,Consolas,monospace;font-variant-numeric:tabular-nums}
26
+ .threedog-debug .s span{color:#a2ad9b;font-size:11px}
27
+ .threedog-debug details{border-top:1px solid rgba(226,232,214,.14)}
28
+ .threedog-debug summary{cursor:pointer;padding:8px 12px;font-weight:700}
29
+ .threedog-debug .c{padding:0 12px 12px;display:flex;flex-direction:column;gap:8px}
30
+ .threedog-debug .r{display:grid;grid-template-columns:64px 1fr 44px;gap:8px;align-items:center}
31
+ .threedog-debug .r label{color:#a2ad9b}.threedog-debug output{font-family:ui-monospace,Menlo,monospace;text-align:right}
32
+ .threedog-debug input[type=range]{width:100%;accent-color:#f0b450}
33
+ .threedog-debug .k{display:flex;flex-wrap:wrap;gap:4px 12px;color:#a2ad9b}
34
+ .threedog-debug button{font:inherit;font-weight:700;background:#f0b450;color:#1b1408;border:0;border-radius:7px;padding:7px 10px;cursor:pointer}
35
+ .threedog-debug .res{font-family:ui-monospace,Menlo,monospace;white-space:pre-line}
36
+ .threedog-debug [hidden]{display:none!important}
37
+ .threedog-debug>.res{padding:0 12px 8px}
38
+ .threedog-debug .ok{color:#8fd17a}.threedog-debug .mid{color:#f0b450}.threedog-debug .bad{color:#ef7d62}
39
+ </style>
40
+ <div class="g">
41
+ <div class="s"><b data-k="fps">--</b><span>FPS</span></div>
42
+ <div class="s"><b data-k="ms">--</b><span>CPU ms/frame</span></div>
43
+ <div class="s"><b data-k="calls">--</b><span>Draw calls</span></div>
44
+ <div class="s"><b data-k="tris">--</b><span>Triangles</span></div>
45
+ <div class="s"><b data-k="chunks">--</b><span>Visible/loaded</span></div>
46
+ <div class="s"><b data-k="inst">--</b><span>Instances</span></div>
47
+ <div class="s"><b data-k="apply">--</b><span>Upload ms</span></div>
48
+ <div class="s"><b data-k="queue">--</b><span>Queued</span></div>
49
+ <div class="s"><b data-k="clock">--</b><span>Time</span></div>
50
+ </div>
51
+ <div class="res k" data-k="budget" hidden></div>
52
+ <div class="res k" data-k="startup" hidden></div>
53
+ <details ${engine.renderer.getSize(new engine.THREE.Vector2()).x > 600 ? 'open' : ''}><summary>Debug</summary><div class="c">
54
+ <div class="r"><label>Time scale</label><input data-i="ts" type="range" min="0" max="60" step="1"><output data-o="ts"></output></div>
55
+ <div class="r"><label>Time</label><input data-i="tod" type="range" min="0" max="1" step="0.005"><output data-o="tod"></output></div>
56
+ <div class="r"><label>Weather</label><select data-s="weather" style="grid-column:span 2;font:inherit;background:#222;color:#eee;border:1px solid #444;border-radius:6px;padding:3px">
57
+ </select></div>
58
+ <button type="button" data-b="bench">20 s stress test</button>
59
+ <div class="res" data-k="bench"></div>
60
+ </div></details>`;
61
+ this.engine.uiRoot.appendChild(el);
62
+ const q = s => el.querySelector(s);
63
+ /** @internal */ this.out = {}; el.querySelectorAll('[data-k]').forEach(n => this.out[n.dataset.k] = n);
64
+ const e = engine, w = e.terrain;
65
+ // controls for modules that are not installed are hidden
66
+ const hideRow = k => { const i = q(`[data-i="${k}"]`); if (i) i.closest('.r').hidden = true; };
67
+ if (!e.sky) { hideRow('ts'); hideRow('tod'); }
68
+ if (!e.weather) q('[data-s="weather"]').closest('.r').hidden = true;
69
+ const bind = (k, get, set, fmt) => {
70
+ const i = q(`[data-i="${k}"]`), o = q(`[data-o="${k}"]`);
71
+ i.value = get(); o.textContent = fmt(get());
72
+ i.addEventListener('input', () => { o.textContent = fmt(+i.value); if (k !== 'dens') set(+i.value); });
73
+ if (k === 'dens') i.addEventListener('change', () => set(+i.value));
74
+ return i;
75
+ };
76
+ if (e.sky) {
77
+ bind('ts', () => e.clock.timeScale, v => e.clock.timeScale = v, v => v + '×');
78
+ /** @internal */ this.tod = bind('tod', () => e.sky.timeOfDay, v => e.sky.timeOfDay = v, () => e.sky.clock);
79
+ }
80
+ const ws = q('[data-s="weather"]');
81
+ if (e.weather) { // options come from the game's weather table (its own types show up here automatically)
82
+ // weather names come from the weather module's string table (weather.<name>); do not duplicate them here
83
+ ws.innerHTML = Object.keys(e.weather.types).map(k => `<option value="${esc(k)}">${esc(e.weather.label(k))}</option>`).join('') + `<option value="auto">${esc(e.weather.label('auto'))}</option>`;
84
+ ws.value = e.weather.name;
85
+ }
86
+ ws.onchange = () => { if (ws.value === 'auto') e.weather.setAuto(true); else { e.weather.setAuto(false); e.weather.set(ws.value, 8); } };
87
+ q('[data-b="bench"]').onclick = () => this.startBench();
88
+ engine.i18n.add({ 'zh-CN': { 'debug.toggle': '调试面板' }, en: { 'debug.toggle': 'Debug panel' } }); // the settings menu's rebind page shows this name
89
+ engine.input.define('debugPanel', ['F3'], 'debug.toggle');
90
+ }
91
+
92
+ /**
93
+ * Start the stress test (seconds, default 20): the character auto-runs fast, continuously loading new chunks, and a report is shown in the panel at the end
94
+ * @param {number} [seconds]
95
+ * @returns {void}
96
+ */
97
+ startBench(seconds = 20) {
98
+ if (this.bench) return;
99
+ this.bench = { t: 0, dur: seconds, dts: [], built: 0 };
100
+ this.out.bench.textContent = 'Testing: character runs straight at 32 m/s, continuously loading new chunks...';
101
+ this.benchmarking = true; this.engine.input.autopilot = { x: 0, y: 1, speed: 32 }; this.engine.adaptive.paused = true;
102
+ }
103
+
104
+ /** @internal */
105
+ frame(dt, built) {
106
+ if (!this.bench) return;
107
+ const b = this.bench; b.t += dt; b.dts.push(dt); b.built += built;
108
+ if (b.t < b.dur) return;
109
+ this.benchmarking = false; this.bench = null; this.engine.input.autopilot = null; this.engine.adaptive.paused = false;
110
+ const d = b.dts.slice().sort((x, y) => y - x), sum = b.dts.reduce((x, y) => x + y, 0);
111
+ const n1 = Math.max(1, Math.floor(d.length * 0.01)), worst = d.slice(0, n1).reduce((x, y) => x + y, 0) / n1;
112
+ const avg = b.dts.length / sum, low = 1 / worst, L = this.limits();
113
+ const cls = (v, lim) => lim == null ? '' : v >= lim ? 'ok' : v >= lim * 0.6 ? 'mid' : 'bad';
114
+ const w = this.engine.terrain;
115
+ this.out.bench.innerHTML = `${w ? `View distance ${w.viewChunks * w.CHUNK}m · Density ${w.density}×` : ''}\nAvg FPS <b class="${cls(avg, L.fps)}">${avg.toFixed(1)}</b>\n1% low FPS <b class="${cls(low, L.low1)}">${low.toFixed(1)}</b>\nLongest frame ${(d[0] * 1000).toFixed(1)} ms\nChunks built: ${b.built}`;
116
+ }
117
+
118
+ /** Budget limits (empty object if budget is off: numbers are not colored) @internal */
119
+ limits() { const b = this.engine.budget; return b.enabled ? { ...Object.fromEntries([...b.metrics].map(([k, m]) => [k, m.limit])), ...b.limits } : {}; }
120
+
121
+ /** @internal */
122
+ stats(s) {
123
+ const o = this.out, fmt = n => n >= 1e6 ? (n / 1e6).toFixed(2) + 'M' : n >= 1e3 ? (n / 1e3).toFixed(1) + 'k' : String(n), L = this.limits();
124
+ // colors: green = within limit, yellow = slightly off (within 1.5x of an upper limit / above 0.6x of a lower limit), red = worse; no limit = no color
125
+ const atMost = (v, lim) => lim == null ? '' : v <= lim ? 'ok' : v <= lim * 1.5 ? 'mid' : 'bad';
126
+ const atLeast = (v, lim) => lim == null ? '' : v >= lim ? 'ok' : v >= lim * 0.6 ? 'mid' : 'bad';
127
+ o.fps.textContent = s.fps.toFixed(0); o.fps.className = atLeast(s.fps, L.fps);
128
+ o.ms.textContent = s.cpu.toFixed(1); o.ms.className = atMost(s.cpu, L.cpuMs);
129
+ o.calls.textContent = s.calls; o.calls.className = atMost(s.calls, L.drawCalls);
130
+ o.tris.textContent = fmt(s.tris); o.tris.className = atMost(s.tris, L.triangles);
131
+ o.apply.className = atMost(s.apply, L.chunkApplyMs);
132
+ const r = this.engine.budget.report();
133
+ o.budget.hidden = !r;
134
+ if (r) o.budget.innerHTML = r.ok ? '<span class="ok">Budget OK</span>' : r.over.map(x => `<span class="bad">${x.category} ${x.value}/${x.limit}</span>`).join(' ') + (r.over[0].top.length ? '<br>' + r.over[0].top.map(t => `${t.tag} ${t.drawCalls}`).join(' · ') : '');
135
+ const st = this.engine.startup;
136
+ o.startup.hidden = !st;
137
+ if (st) {
138
+ const slow = Object.entries(st.modules).map(([k, v]) => [k, (v.init ?? 0) + (v.ready ?? 0)]).sort((a, b) => b[1] - a[1])[0];
139
+ o.startup.textContent = `Startup ${st.totalMs} ms` + (slow ? ` · slowest ${slow[0]} ${slow[1]} ms` : '');
140
+ }
141
+ o.chunks.textContent = s.visible + '/' + s.loaded;
142
+ o.inst.textContent = fmt(s.instances);
143
+ o.apply.textContent = s.apply.toFixed(1);
144
+ o.queue.textContent = s.queued;
145
+ o.clock.textContent = this.engine.sky?.clock ?? '--';
146
+ if (this.tod && document.activeElement !== this.tod) this.tod.value = this.engine.sky.timeOfDay;
147
+ }
148
+ }
149
+
150
+ const DEBUG_PANEL_PARAMS = keysSchema(['open']);
151
+
152
+ /**
153
+ * F3 debug panel -> engine.debug.panel: performance panel, settings, stress test. Collapsed by default; F3 shows/hides it; open: true shows it at start. Just do not install it in a release
154
+ * @param {{ open?: boolean }} [opts]
155
+ * @returns {ModuleDef<DebugPanel>}
156
+ */
157
+ export function debug(opts = {}) {
158
+ readParams('debugPanel', DEBUG_PANEL_PARAMS, opts);
159
+ let d = null; const prof = { n: 0, t: 0, cpu: 0 };
160
+ return {
161
+ name: 'debugPanel', params: DEBUG_PANEL_PARAMS, options: opts, label: 'Debug panel', optional: ['sky', 'weather', 'terrain'], presentation: true,
162
+ install(e) { d = new DebugPanel(e, opts); e.debug.panel = d; return d; },
163
+ dispose(e) { if (e.debug.panel === d) e.debug.panel = null; d?.el.remove(); },
164
+ frame(dt, e) { if (e.input.pressedRaw('debugPanel')) d.el.hidden = !d.el.hidden; },
165
+ afterRender(dt, e) {
166
+ d.frame(dt, e.terrain?.stats.builtThisFrame || 0);
167
+ prof.n++; prof.t += dt; prof.cpu += e.cpuMs || 0;
168
+ if (prof.t < 0.5) return;
169
+ const s = e.terrain?.stats || {}, info = e.renderer.info.render;
170
+ d.stats({ fps: prof.n / prof.t, cpu: prof.cpu / prof.n, calls: info.calls, tris: info.triangles, visible: s.visible ?? 0, loaded: s.loaded ?? 0, instances: s.instances ?? 0, apply: s.applyMs ?? 0, queued: s.queued ?? 0 });
171
+ prof.n = prof.t = prof.cpu = 0;
172
+ },
173
+ };
174
+ }