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
package/ui/Focus.js ADDED
@@ -0,0 +1,51 @@
1
+ // UI focus stack: windows, dialogue, cutscenes and the settings menu are pushed in open order. The back key (action cancel, default Esc) goes to the top entry only;
2
+ // with an empty stack it goes to the "root" (registered by setRoot, usually the settings menu). So Esc has one entry point and never closes a cutscene and opens the menu at once.
3
+ //
4
+ // const f = uiFocus(engine); // one per engine
5
+ // const h = f.push('inventory', { cancel: () => win.toggle(false) }); // no cancel = swallow the back key (Esc does nothing during dialogue)
6
+ // h.fresh pushed this frame: the key press that opened it (E, Space) must not count as its own action
7
+ // h.remove() pop (safe to call repeatedly)
8
+ // f.setRoot(() => settings.open()) // what the back key does on an empty stack; returns a handle { remove() }
9
+ // f.top top name or null; f.list() names from bottom to top
10
+ // Look: none (behavior only).
11
+ const stacks = new WeakMap(); // engine -> UI focus stack
12
+ /** @import { Engine } from '../types/core' */
13
+ /** @import { UIFocus } from '../types/gameplay' */
14
+
15
+ /**
16
+ * UI focus stack: windows, dialogue and cutscenes push in open order; the back key (Esc) goes to the top only; an empty stack hands it to the settings menu
17
+ * @param {Engine} engine
18
+ * @returns {UIFocus}
19
+ */
20
+ export function uiFocus(engine) {
21
+ let f = stacks.get(engine);
22
+ if (f) return f;
23
+ const entries = [];
24
+ let frame = 0, root = null;
25
+ f = {
26
+ get top() { return entries.at(-1)?.id ?? null; },
27
+ list() { return entries.map(x => x.id); },
28
+ /** Push: { cancel }. Returns a handle { id, fresh, remove() } */
29
+ push(id, { cancel = null } = {}) {
30
+ const h = {
31
+ id, cancel, at: frame,
32
+ get fresh() { return h.at === frame; },
33
+ remove() { const i = entries.indexOf(h); if (i >= 0) entries.splice(i, 1); },
34
+ };
35
+ entries.push(h);
36
+ return h;
37
+ },
38
+ /** Who gets the back key when the stack is empty (only one; a later registration replaces the earlier) */
39
+ setRoot(fn) { root = fn; return { remove: () => { if (root === fn) root = null; } }; },
40
+ };
41
+ // Start of each frame (the onFrame callback runs before module frame hooks): bump the frame number so the back key dispatches once
42
+ f.hook = engine.onFrame(() => {
43
+ frame++;
44
+ if (!engine.input.pressedRaw('cancel')) return;
45
+ const top = entries.at(-1);
46
+ if (top) top.cancel?.();
47
+ else root?.();
48
+ });
49
+ stacks.set(engine, f);
50
+ return f;
51
+ }
@@ -0,0 +1,42 @@
1
+ // Default 'loading' UI part: covers the view at start, shows progress, fades out when ready. start() drives it (show -> update... -> hide).
2
+ // Replace it with createEngine({ ui: { loading: (engine) => ({ show, update, hide, dispose }) } }), turn it off with { loading: false }.
3
+ // Look: CSS classes .threedog-loading* (override in style.ui.css), or the inner HTML with style.ui.templates.loading({ title }).
4
+ // text names the item being waited for (engine.loading.text()); when a critical item fails, update gets failed (engine.loading tasks) and the
5
+ // screen stays up with class .threedog-loading-failed, so the player sees why instead of a frozen bar.
6
+ import { injectUICSS, esc } from './UI.js';
7
+ /** @import { Engine, UIPart } from '../types/core' */
8
+
9
+ /**
10
+ * Default loading screen part. show({ title }) · update({ progress 0-1, text, failed? }) · hide() fades out (returns a promise for the fade).
11
+ * @param {Engine} engine
12
+ * @param {{ title?: string }} [opts]
13
+ * @returns {UIPart}
14
+ * @internal
15
+ */
16
+ export function loadingScreen(engine, { title } = {}) {
17
+ injectUICSS();
18
+ let el = null, bar = null, msg = null;
19
+ return {
20
+ show(d = {}) {
21
+ el = document.createElement('div');
22
+ el.className = 'threedog-loading';
23
+ const t = d.title ?? title ?? engine.t('common.loading');
24
+ const tpl = engine.style.ui?.templates?.loading;
25
+ el.innerHTML = tpl ? tpl({ title: t }, { esc }) :
26
+ `<div class="threedog-loading-box"><div class="threedog-loading-title">${esc(t)}</div><div class="threedog-loading-track"><div class="threedog-loading-bar"></div></div><div class="threedog-loading-msg"></div></div>`;
27
+ engine.uiRoot.appendChild(el);
28
+ bar = el.querySelector('.threedog-loading-bar'); msg = el.querySelector('.threedog-loading-msg');
29
+ },
30
+ update({ progress, text, failed }) {
31
+ if (bar) bar.style.width = Math.round(progress * 100) + '%';
32
+ if (msg && text != null) msg.textContent = text;
33
+ el?.classList.toggle('threedog-loading-failed', !!failed?.length);
34
+ },
35
+ hide() { // resolves when the fade has finished and the element is gone (engine.ui.settled waits for it)
36
+ if (!el) return;
37
+ const x = el; el = null; x.style.opacity = '0'; x.style.pointerEvents = 'none';
38
+ return new Promise(res => setTimeout(() => { x.remove(); res(); }, 700)); // wall-clock: CSS fade length
39
+ },
40
+ dispose() { el?.remove(); el = null; },
41
+ };
42
+ }
package/ui/Parts.js ADDED
@@ -0,0 +1,199 @@
1
+ // UI parts (engine.ui): every piece of screen UI the engine or a module draws is a named part with a default implementation.
2
+ // A game swaps any part for its own DOM / canvas code, or turns it off, without touching the engine; the engine keeps the behavior
3
+ // (when to show it, the UI focus stack, Esc, input lock, i18n), the part only draws.
4
+ //
5
+ // createEngine({ ui: { loading: false, title: { title: 'My Game' }, toast: (engine) => ({ show: d => myToast(d.text) }) } })
6
+ // engine.ui.set('hud.counter', (engine) => { // replace a part: a function returning { show, update, hide, dispose } (any may be omitted)
7
+ // const el = document.createElement('div'); engine.uiRoot.appendChild(el);
8
+ // return { update: d => { el.textContent = `${d.label} ${d.value}`; }, dispose: () => el.remove() };
9
+ // });
10
+ // engine.ui.set('hud.marker', false); // turn a part off
11
+ // engine.ui.open('title') / engine.ui.close('title') // full-screen parts (title): pushes the UI focus stack, locks input, emits ui:open / ui:close
12
+ //
13
+ // Value per name: false = off; true = the default; a plain object = the default with these options; a function (engine, options) => part = your own.
14
+ // Names and the data each part receives are listed in `engine.ui.describe()` and in recipes/26-ui-parts.md.
15
+ import { uiFocus } from './Focus.js';
16
+ /** @import { Engine } from '../types/core' */
17
+ /** @import { UIPart, UIPartFactory, UIPartValue, UIPartDef } from '../types/core' */
18
+
19
+ const VERBS = ['show', 'update', 'hide', 'dispose'];
20
+ const noop = () => {};
21
+ const DEV = {
22
+ badValue: "engine.ui.set('{name}', …): pass false (off), true (default), an options object, or a function (engine, options) => ({ show, update, hide, dispose }). Got {got}.",
23
+ badPart: "ui part '{name}': the function must return an object { show, update, hide, dispose } (any may be omitted). Got {got}.",
24
+ badVerb: "ui part '{name}': {verb} must be a function.",
25
+ unknown: "engine.ui.set('{name}'): no UI part has that name. Known parts: {known}. (A module's parts exist only after engine.use(module).)",
26
+ notModal: "engine.ui.open('{name}'): only full-screen parts can be opened ({known}).",
27
+ };
28
+ const fmt = (s, p) => s.replace(/\{(\w+)\}/g, (_, k) => p[k]);
29
+ const kind = v => v === null ? 'null' : Array.isArray(v) ? 'array' : typeof v;
30
+
31
+ /** @internal Fill missing verbs with no-ops so callers never write ?. */
32
+ function normalize(name, p) {
33
+ if (!p || typeof p !== 'object') throw new Error(fmt(DEV.badPart, { name, got: kind(p) }));
34
+ for (const v of VERBS) {
35
+ if (p[v] == null) p[v] = noop;
36
+ else if (typeof p[v] !== 'function') throw new Error(fmt(DEV.badVerb, { name, verb: v }));
37
+ }
38
+ return p;
39
+ }
40
+
41
+ export class UIParts {
42
+ /**
43
+ * @param {Engine} engine
44
+ * @param {Record<string, UIPartValue>} [values] createEngine({ ui })
45
+ * @internal
46
+ */
47
+ constructor(engine, values = {}) {
48
+ this.engine = engine;
49
+ /** @internal name -> { factory, on, multi, modal } */ this.defs = new Map();
50
+ /** @internal name -> value given by the game (wins over the default whatever the install order) */ this.values = new Map();
51
+ /** @internal name -> live singleton */ this.live = new Map();
52
+ /** @internal name -> { focus } while a full-screen part is open */ this.opened = new Map();
53
+ /** @internal hide() promises still fading out (see settled) */ this._fading = new Set();
54
+ for (const [k, v] of Object.entries(values)) this.set(k, v);
55
+ }
56
+
57
+ /**
58
+ * Declare a part and its default implementation (engine and modules call this in install; games use set).
59
+ * @param {string} name
60
+ * @param {UIPartFactory} factory default implementation (engine, options) => part
61
+ * @param {UIPartDef} [def] on: shown unless the game asks (default true); multi: one part per item (markers, counters); modal: full-screen, opened with ui.open
62
+ * @returns {void}
63
+ * @example engine.ui.define('hud.ammo', (e, o) => ({ update: d => {...} }), { multi: true })
64
+ */
65
+ define(name, factory, { on = true, multi = false, modal = null } = {}) {
66
+ this.defs.set(name, { factory, on, multi, modal });
67
+ }
68
+
69
+ /**
70
+ * Replace a part with your own, give the default options, or turn it off. Affects parts created after this call (set before engine.start()).
71
+ * @param {string} name e.g. 'loading' 'toast' 'title' 'hud.marker' 'hud.counter' 'hud.bar'
72
+ * @param {UIPartValue} value false off · true default · { ...options } default with options · (engine, options) => ({ show, update, hide, dispose })
73
+ * @returns {void}
74
+ * @example engine.ui.set('toast', (engine) => ({ show: ({ text, kind }) => { if (kind !== 'quest') myToast(text); } }))
75
+ */
76
+ set(name, value) {
77
+ const t = kind(value);
78
+ if (t !== 'boolean' && t !== 'function' && t !== 'object') throw new Error(fmt(DEV.badValue, { name, got: t }));
79
+ this.values.set(name, value);
80
+ }
81
+
82
+ /** @internal value -> { factory, options } or null when off */
83
+ _resolve(name) {
84
+ const d = this.defs.get(name), v = this.values.has(name) ? this.values.get(name) : d?.on;
85
+ if (!d || v === false || v === undefined) return null;
86
+ if (typeof v === 'function') return { factory: v, options: {} };
87
+ return { factory: d.factory, options: v === true ? {} : v };
88
+ }
89
+ /** @internal */
90
+ _make(name) {
91
+ const r = this._resolve(name);
92
+ if (!r) return null;
93
+ const p = normalize(name, r.factory(this.engine, r.options)), hide = p.hide;
94
+ // a hide() that fades out may return a promise; track it so settled() knows when the screen is really clear
95
+ p.hide = (...a) => {
96
+ const out = hide.apply(p, a);
97
+ if (out?.then) { this._fading.add(out); out.finally(() => this._fading.delete(out)); }
98
+ return out;
99
+ };
100
+ return p;
101
+ }
102
+
103
+ /**
104
+ * Resolves once every part that is hiding has finished fading out (a part's hide() may return a promise for its fade).
105
+ * Screenshots wait for it so the loading screen is not captured half-transparent.
106
+ * @example await engine.ui.settled(); renderer.domElement.toDataURL();
107
+ * @returns {Promise<void>}
108
+ */
109
+ settled() { return Promise.all([...this._fading]).then(() => {}); }
110
+
111
+ /**
112
+ * The live single part (loading, toast, title...), built on first use; null when the part is off.
113
+ * @param {string} name
114
+ * @returns {UIPart | null}
115
+ * @example engine.ui.get('loading')?.update({ progress: 0.5, text: '' })
116
+ */
117
+ get(name) {
118
+ if (this.live.has(name)) return this.live.get(name);
119
+ const p = this._make(name);
120
+ this.live.set(name, p);
121
+ return p;
122
+ }
123
+
124
+ /**
125
+ * A new part for one item of a multi part (a HUD marker, counter, bar); null when the part is off. The caller disposes it.
126
+ * @param {string} name
127
+ * @returns {UIPart | null}
128
+ */
129
+ create(name) { return this._make(name); }
130
+
131
+ /**
132
+ * Open a full-screen part (the title screen): shows it, pushes the UI focus stack (Esc goes to it), locks gameplay input, emits ui:open.
133
+ * @param {string} name
134
+ * @param {object} [data] passed to the part's show()
135
+ * @returns {boolean} false when the part is off
136
+ * @example engine.ui.open('title')
137
+ */
138
+ open(name, data) {
139
+ const d = this.defs.get(name);
140
+ if (!d?.modal) throw new Error(fmt(DEV.notModal, { name, known: [...this.defs].filter(([, x]) => x.modal).map(([n]) => n).join(', ') }));
141
+ const p = this.get(name);
142
+ if (!p) return false;
143
+ if (this.opened.has(name)) return true;
144
+ const e = this.engine, m = d.modal;
145
+ // Each modal part owns its own freeze ('ui-<name>') and its own input context, so closing help releases only help's hold, never a player pause or another part's.
146
+ // m.freeze may be a function (inventory: pauseGame is switchable at runtime)
147
+ // a string names the freeze kind engine.runState reads ('title' = waiting for start), so core never matches part names
148
+ const fr = typeof m.freeze === 'function' ? m.freeze(e) : m.freeze;
149
+ if (fr) e.freeze('ui-' + name, { kind: typeof fr === 'string' ? fr : undefined });
150
+ this.opened.set(name, { focus: uiFocus(e).push('ui-' + name, { cancel: m.cancel ? () => m.cancel(e) : null }), ctx: e.input.push('ui-' + name) }); // own opaque context: gameplay actions stop responding
151
+ p.show({ ...m.data?.(e, this._resolve(name).options), ...data });
152
+ e.events.emit('ui:open', name);
153
+ return true;
154
+ }
155
+
156
+ /**
157
+ * Close a full-screen part opened with open().
158
+ * @param {string} name
159
+ * @returns {void}
160
+ */
161
+ close(name) {
162
+ const f = this.opened.get(name);
163
+ if (!f) return;
164
+ const e = this.engine;
165
+ this.opened.delete(name);
166
+ f.focus.remove(); f.ctx.remove();
167
+ e.unfreeze('ui-' + name);
168
+ this.live.get(name)?.hide();
169
+ e.events.emit('ui:close', name);
170
+ }
171
+
172
+ /**
173
+ * Whether a full-screen part is open
174
+ * @param {string} name
175
+ * @returns {boolean}
176
+ */
177
+ isOpen(name) { return this.opened.has(name); }
178
+
179
+ /**
180
+ * Each part: 'default' | 'custom' | 'off'
181
+ * @returns {Record<string, string>}
182
+ */
183
+ describe() {
184
+ const out = {};
185
+ for (const [n, d] of this.defs) { const v = this.values.has(n) ? this.values.get(n) : d.on; out[n] = v === false ? 'off' : typeof v === 'function' ? 'custom' : 'default'; }
186
+ return out;
187
+ }
188
+
189
+ /** @internal start(): every module is installed, so a name the game set but nobody defined is a typo */
190
+ _check() {
191
+ for (const n of this.values.keys()) if (!this.defs.has(n)) throw new Error(fmt(DEV.unknown, { name: n, known: [...this.defs.keys()].join(', ') }));
192
+ }
193
+ /** @internal engine.dispose() */
194
+ _dispose() {
195
+ for (const n of [...this.opened.keys()]) this.close(n);
196
+ for (const p of this.live.values()) p?.dispose();
197
+ this.live.clear();
198
+ }
199
+ }
package/ui/UI.js ADDED
@@ -0,0 +1,167 @@
1
+ // UI base. The engine provides only structure and behavior (windows open/close, toasts pop up); the look is fully replaceable:
2
+ // 1. Colors, fonts, radii: variables in the style pack's style.ui (bg, fg, accent...), turned into CSS variables --threedog-* on engine.uiRoot
3
+ // 2. Layout details: style.ui.css is placed after every engine and module default, so it overrides the .threedog-* classes
4
+ // 3. Whole window content: style.ui.templates.<window name>(data, helpers) returns HTML and replaces the default layout
5
+ //
6
+ // Every window and component uses classes (no inline styles), so option 2 always takes effect.
7
+ import * as THREE from 'three';
8
+ import { vec3 } from '../core/math.js';
9
+ import { uiFocus } from './Focus.js';
10
+ import { injectUICSS } from './theme.js';
11
+ /** @import { Engine } from '../types/core' */
12
+ /** @import { PositionLike, Object3D } from '../types/common' */
13
+ /** @import { UIWindow, WindowOptions, ScreenPoint } from '../types/gameplay' */
14
+ export { uiFocus, injectUICSS };
15
+
16
+ /** @internal */
17
+ export function esc(s) { return String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c])); }
18
+ /** Icon: def.iconUrl is an image, def.icon is text/emoji */
19
+ /** @internal icon markup of an item / thing definition (image when it has iconUrl, else its icon text) */
20
+ export const iconHTML = def => def?.iconUrl ? `<img src="${esc(def.iconUrl)}" alt="">` : esc(def?.icon ?? '·');
21
+
22
+ /**
23
+ * Show a short message through the 'toast' UI part (default: top of the screen, gone after ms). A game restyles it, filters it by kind
24
+ * or turns it off with createEngine({ ui: { toast: false } }). kind says where it came from: 'info' (default), 'quest', 'item', 'save', 'error'.
25
+ * @param {Engine} engine
26
+ * @param {string} text
27
+ * @param {{ kind?: string, ms?: number }} [opts] ms default 2600
28
+ * @returns {void}
29
+ * @example toast(engine, 'Saved', { kind: 'save' })
30
+ */
31
+ export function toast(engine, text, { kind = 'info', ms = 2600 } = {}) {
32
+ if (!engine?.ui) throw new Error(`toast(engine, text): the engine comes first, e.g. toast(engine, ${JSON.stringify(String(engine ?? ''))}).`);
33
+ engine.ui.get('toast')?.show({ text, kind, ms });
34
+ }
35
+
36
+ /**
37
+ * Default 'toast' UI part: show({ text, kind, ms })
38
+ * @param {Engine} engine
39
+ * @returns {import('../types/core').UIPart}
40
+ * @internal
41
+ */
42
+ export function toastPart(engine) {
43
+ injectUICSS();
44
+ let box = null;
45
+ return {
46
+ show({ text, ms = 2600 }) {
47
+ if (!box) { box = document.createElement('div'); box.className = 'threedog-ui threedog-toasts'; engine.uiRoot.appendChild(box); }
48
+ const t = document.createElement('div'); t.className = 'threedog-toast'; t.textContent = text; box.appendChild(t);
49
+ setTimeout(() => { t.style.opacity = '0'; setTimeout(() => t.remove(), 400); }, ms); // wall-clock: a message stays readable while gameplay is paused
50
+ },
51
+ dispose() { box?.remove(); box = null; },
52
+ };
53
+ }
54
+
55
+ // When the style pack has style.ui.templates[id](data, { esc, t, icon }), it replaces the default content.
56
+ // Opening pushes onto the UI focus stack (uiFocus): Esc goes only to the top window / dialogue / cutscene, see Focus.js.
57
+ /**
58
+ * A toggleable window
59
+ * @param {Engine} engine
60
+ * @param {WindowOptions} opts
61
+ * @returns {UIWindow}
62
+ */
63
+ export function makeWindow(engine, opts) {
64
+ const { id, title, hintAction, render, data = () => ({}), onCancel = null } = opts;
65
+ injectUICSS();
66
+ const w = document.createElement('div'); w.className = `threedog-ui threedog-win threedog-win-${id}`; w.hidden = true; engine.uiRoot.appendChild(w);
67
+ const tools = { esc, t: (k, p) => engine.t(k, p), icon: iconHTML };
68
+ let focus = null, ctx = null; // handles on the UI focus stack and the input context stack while open
69
+ const api = {
70
+ el: w,
71
+ get open() { return !w.hidden; },
72
+ refresh() {
73
+ if (w.hidden) return;
74
+ const tpl = engine.style.ui?.templates?.[id];
75
+ const body = tpl ? tpl(data(), tools) : render(data(), tools);
76
+ const hint = hintAction ? `<span class="threedog-win-hint">${esc(engine.input.label(hintAction))}</span>` : '';
77
+ w.innerHTML = `<div class="threedog-win-head"><span>${esc(title())}</span><span>${hint} <button class="threedog-btn threedog-close" type="button">${esc(engine.t('common.close'))}</button></span></div>${body}`;
78
+ w.querySelector('.threedog-close').onclick = () => api.toggle(false);
79
+ },
80
+ toggle(on = w.hidden) {
81
+ if (on === !w.hidden) return;
82
+ w.hidden = !on;
83
+ if (on) { ctx = engine.input.push('win-' + id); focus = uiFocus(engine).push('win-' + id, { cancel: onCancel || (() => api.toggle(false)) }); }
84
+ else { ctx?.remove(); ctx = null; focus?.remove(); focus = null; }
85
+ api.refresh();
86
+ engine.events.emit(on ? 'ui:open' : 'ui:close', id);
87
+ },
88
+ };
89
+ engine.events.on('i18n:change', () => api.refresh());
90
+ engine.events.on('input:rebind', () => api.refresh());
91
+ return api;
92
+ }
93
+
94
+ // e.g. inventory I, quests J. While closed the action opens it (ignored when input is locked by someone else); while open pressing again closes it (the window locks input itself, hence pressedRaw). The back key is handled by the UI focus stack.
95
+ /**
96
+ * Window toggle key: call once per frame in a frame hook; opens on the action when closed, closes on another press when open
97
+ * @param {Engine} engine
98
+ * @param {{ open: boolean, toggle(on?: boolean): void }} win a makeWindow window or any handle with open / toggle
99
+ * @param {string} action
100
+ * @returns {void}
101
+ */
102
+ export function toggleOnKey(engine, win, action) {
103
+ const inp = engine.input;
104
+ if (win.open ? inp.pressedRaw(action) : inp.pressed(action)) win.toggle(!win.open);
105
+ }
106
+
107
+ // ---------- screen projection, fades ----------
108
+ const _v = new THREE.Vector3(), _s = new THREE.Vector2();
109
+ // behind: behind the camera
110
+ /**
111
+ * World coordinates (position or object) -> pixels from the canvas's top-left corner { x, y, onScreen, behind } (the UI root covers the canvas, so these place UI elements directly)
112
+ * @param {Engine} engine
113
+ * @param {PositionLike} pos
114
+ * @returns {ScreenPoint}
115
+ */
116
+ export function worldToScreen(engine, pos) {
117
+ const obj = /** @type {Object3D} */ (pos); // isObject3D is three's own duck-type flag; the cast only lets the check read it
118
+ (obj.isObject3D ? obj.getWorldPosition(_v) : vec3(pos, _v)).project(engine.camera);
119
+ const behind = _v.z > 1, { x: W, y: H } = engine.renderer.getSize(_s); // pixels inside the canvas box (the UI root covers exactly that box)
120
+ return { x: (_v.x + 1) / 2 * W, y: (1 - _v.y) / 2 * H, behind, onScreen: !behind && Math.abs(_v.x) <= 1 && Math.abs(_v.y) <= 1 };
121
+ }
122
+
123
+ /**
124
+ * Move a screen-anchored element (prompt, marker) to pixel x, y, writing the DOM only when the rounded position changed (called every frame: fewer reflows)
125
+ * @param {HTMLElement} el
126
+ * @param {number} x
127
+ * @param {number} y
128
+ * @returns {void}
129
+ * @internal
130
+ */
131
+ export function placeAt(el, x, y) {
132
+ const left = Math.round(x) + 'px', top = Math.round(y) + 'px';
133
+ if (el.style.left !== left) el.style.left = left;
134
+ if (el.style.top !== top) el.style.top = top;
135
+ }
136
+
137
+ const fades = new WeakMap(); // engine → { el, value, from, to, t, d, done }
138
+ // color --threedog-fade-bg. Follows engine frames (step() advances it too; stops while pause()d). A new fade interrupts the old (the old Promise resolves at once).
139
+ // Scene transitions use engine.flow.transition and cutscenes use the timeline's { fade: seconds, to } step; both go through here.
140
+ /**
141
+ * Fade the whole screen to `to` (0 clear ... 1 fully covered) over `seconds` (default 0.5); the Promise resolves when the fade ends
142
+ * @param {Engine} engine
143
+ * @param {number} to 0 clear ... 1 fully covered
144
+ * @param {number} [seconds] default 0.5
145
+ * @returns {Promise<void>}
146
+ */
147
+ export function fadeScreen(engine, to, seconds = 0.5) {
148
+ injectUICSS();
149
+ let f = fades.get(engine);
150
+ if (!f) {
151
+ const el = document.createElement('div'); el.className = 'threedog-fade'; engine.uiRoot.appendChild(el);
152
+ f = { el, value: 0, from: 0, to: 0, t: 0, d: 0, done: null };
153
+ fades.set(engine, f);
154
+ engine.onFrame(dt => { if (f.done) { f.t += dt; set(f, f.t >= f.d ? 1 : f.t / f.d); } });
155
+ }
156
+ f.done?.();
157
+ Object.assign(f, { from: f.value, to, t: 0, d: seconds, done: null });
158
+ const p = new Promise(res => { f.done = () => { f.done = null; res(); }; });
159
+ if (seconds <= 0) set(f, 1);
160
+ return p;
161
+ }
162
+ function set(f, k) {
163
+ f.value = f.from + (f.to - f.from) * k;
164
+ f.el.style.setProperty('--threedog-fade', f.value);
165
+ f.el.classList.toggle('is-on', f.value > 0.01);
166
+ if (k >= 1) f.done?.();
167
+ }
package/ui/defaults.js ADDED
@@ -0,0 +1,85 @@
1
+ // The core UI parts every engine declares: 'loading' (on), 'toast' (on), 'title' (off until the game asks). Modules declare their own (hud.*).
2
+ // The title screen is a full-screen part: start() opens it after loading when the game turned it on; engine.ui.open('title') shows it again (e.g. "back to title").
3
+ import { injectUICSS, toastPart, esc } from './UI.js';
4
+ import { loadingScreen } from './LoadingScreen.js';
5
+ import { touchPart } from './touchPart.js';
6
+ /** @import { Engine, UIPart, UITitleItem } from '../types/core' */
7
+
8
+ const STRINGS = {
9
+ 'zh-CN': { 'title.start': '开始', 'title.continue': '继续', 'title.settings': '设置' },
10
+ en: { 'title.start': 'Start', 'title.continue': 'Continue', 'title.settings': 'Settings' },
11
+ };
12
+ const CSS = `
13
+ .threedog-title{position:fixed;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:28px;background:var(--threedog-loading-bg);color:var(--threedog-fg);z-index:80;font-family:var(--threedog-font)}
14
+ .threedog-title-name{font-size:32px;font-weight:600;letter-spacing:.08em}
15
+ .threedog-title-items{display:flex;flex-direction:column;gap:10px;min-width:200px}
16
+ .threedog-title-items .threedog-btn{padding:8px 16px;font-size:16px}
17
+ `;
18
+ const DEV = { badItem: "ui title items: each item is 'start' | 'continue' | 'settings' or { label, run(engine) }. Got {got}." };
19
+
20
+ // Built-in title items; when() hides an item that has nothing to do (no save yet, no settings module)
21
+ // Both go through engine.session so nothing of an earlier playthrough (after "back to title") is left over; a save that cannot be read keeps the title up (the engine shows why).
22
+ const BUILTIN = {
23
+ continue: { when: e => e.saves.list().length > 0, run: async e => { if (await e.session.load(e.saves.list()[0].slot)) e.ui.close('title'); } },
24
+ start: { run: async e => { await e.session.newGame(); e.ui.close('title'); } },
25
+ settings: { when: e => !!e.settings, run: e => e.settings.open() },
26
+ };
27
+
28
+ /**
29
+ * Title items -> [{ id, label, run }] (what the title part's show() receives)
30
+ * @param {Engine} e
31
+ * @param {(string | UITitleItem)[]} items
32
+ * @returns {{ id: string, label: string, run: () => any }[]}
33
+ */
34
+ function titleItems(e, items) {
35
+ const out = [];
36
+ for (const it of items) {
37
+ if (typeof it === 'string' && BUILTIN[it]) { const b = BUILTIN[it]; if (!b.when || b.when(e)) out.push({ id: it, label: e.t('title.' + it), run: () => b.run(e) }); }
38
+ else if (it && typeof it.run === 'function') out.push({ id: it.id ?? it.label, label: typeof it.label === 'function' ? it.label(e) : it.label, run: () => it.run(e) });
39
+ else throw new Error(DEV.badItem.replace('{got}', JSON.stringify(it)));
40
+ }
41
+ return out;
42
+ }
43
+
44
+ /**
45
+ * Default title part: the game name and a column of buttons. show({ title, items: [{ id, label, run }] }) · hide()
46
+ * @param {Engine} engine
47
+ * @returns {UIPart}
48
+ */
49
+ function titleScreen(engine) {
50
+ injectUICSS(CSS);
51
+ let el = null;
52
+ return {
53
+ show({ title, items }) {
54
+ el ??= document.createElement('div');
55
+ el.className = 'threedog-ui threedog-title';
56
+ el.innerHTML = `<div class="threedog-title-name">${esc(title)}</div><div class="threedog-title-items">${items.map((it, i) => `<button type="button" class="threedog-btn" data-i="${i}">${esc(it.label)}</button>`).join('')}</div>`;
57
+ el.querySelectorAll('[data-i]').forEach(b => { b.onclick = () => items[+b.dataset.i].run(); });
58
+ engine.uiRoot.appendChild(el);
59
+ el.querySelector('button')?.focus();
60
+ },
61
+ hide() { el?.remove(); },
62
+ dispose() { el?.remove(); el = null; },
63
+ };
64
+ }
65
+
66
+ /**
67
+ * Declare the core UI parts on a new engine
68
+ * @param {Engine} e
69
+ * @returns {void}
70
+ * @internal
71
+ */
72
+ export function defineCoreParts(e) {
73
+ e.i18n.add(STRINGS);
74
+ e.ui.define('loading', loadingScreen);
75
+ e.ui.define('toast', toastPart);
76
+ e.ui.define('title', titleScreen, {
77
+ on: false,
78
+ modal: {
79
+ freeze: 'title', // freezes gameplay; the kind tells engine.runState this is a title screen waiting for start
80
+ // items default to continue / start / settings, each shown only when it applies (a save exists, settings is installed)
81
+ data: (eng, o) => ({ title: o.title ?? '', items: titleItems(eng, o.items ?? ['continue', 'start', 'settings']) }),
82
+ },
83
+ });
84
+ e.ui.define('touch', touchPart); // drawn only when a stick (createEngine({ joystick })) or a touch button is wanted
85
+ }