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.
- package/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +39 -2
- package/core/Animator.js +268 -0
- package/core/Assets.js +256 -0
- package/core/Audio.js +267 -0
- package/core/Baked.js +72 -0
- package/core/Batching.js +247 -0
- package/core/Budget.js +221 -0
- package/core/Clock.js +94 -0
- package/core/Commits.js +77 -0
- package/core/DebugOverrides.js +143 -0
- package/core/Describe.js +145 -0
- package/core/Engine.js +184 -0
- package/core/Events.js +153 -0
- package/core/I18n.js +94 -0
- package/core/Input.js +245 -0
- package/core/Inspect.js +77 -0
- package/core/InspectScene.js +191 -0
- package/core/Jobs.js +146 -0
- package/core/Loading.js +149 -0
- package/core/MaterialInfo.js +32 -0
- package/core/Ops.js +256 -0
- package/core/Random.js +52 -0
- package/core/Rays.js +160 -0
- package/core/SaveStore.js +85 -0
- package/core/Saves.js +254 -0
- package/core/Stream.js +279 -0
- package/core/Threads.js +158 -0
- package/core/UrlState.js +94 -0
- package/core/Vars.js +35 -0
- package/core/Views.js +49 -0
- package/core/actor.js +23 -0
- package/core/assetEntry.js +89 -0
- package/core/assetLoad.js +190 -0
- package/core/assetManifest.js +35 -0
- package/core/assetReport.js +83 -0
- package/core/audioRules.js +121 -0
- package/core/audioVoice.js +225 -0
- package/core/batchGroups.js +116 -0
- package/core/canvasBox.js +63 -0
- package/core/catalog.js +169 -0
- package/core/checks.js +67 -0
- package/core/claims.js +51 -0
- package/core/dayTime.js +15 -0
- package/core/debugView.js +76 -0
- package/core/describeRender.js +45 -0
- package/core/describeText.js +143 -0
- package/core/easing.js +34 -0
- package/core/errorCodes.js +205 -0
- package/core/errorHints.js +208 -0
- package/core/errors.js +40 -0
- package/core/events.generated.js +84 -0
- package/core/ground.js +102 -0
- package/core/holds.js +106 -0
- package/core/inputContext.js +69 -0
- package/core/inputDefaults.js +22 -0
- package/core/inputPad.js +35 -0
- package/core/inputPointer.js +48 -0
- package/core/inputTouch.js +48 -0
- package/core/lifecycle.js +69 -0
- package/core/lightWatch.js +56 -0
- package/core/look/coreParts.js +112 -0
- package/core/look/layers.js +136 -0
- package/core/look/part.js +173 -0
- package/core/look/report.js +79 -0
- package/core/look/write.js +86 -0
- package/core/loop.js +200 -0
- package/core/math.js +33 -0
- package/core/modules.js +196 -0
- package/core/movement.js +19 -0
- package/core/mulberry32.js +14 -0
- package/core/opsAtomic.js +31 -0
- package/core/opsCheck.js +97 -0
- package/core/opsFail.js +20 -0
- package/core/opsGuard.js +26 -0
- package/core/opsHistory.js +27 -0
- package/core/opsRun.js +77 -0
- package/core/page.js +78 -0
- package/core/params.js +132 -0
- package/core/pureWorker.js +5 -0
- package/core/renamed.js +21 -0
- package/core/saveApply.js +128 -0
- package/core/saveFiles.js +139 -0
- package/core/saveIds.js +53 -0
- package/core/saveVersions.js +97 -0
- package/core/scatter.js +92 -0
- package/core/sceneMethods.js +100 -0
- package/core/screenToGround.js +39 -0
- package/core/services.js +73 -0
- package/core/session.js +171 -0
- package/core/shadowTypes.js +15 -0
- package/core/skip.js +104 -0
- package/core/startup.js +135 -0
- package/core/streamCells.js +24 -0
- package/core/streamSources.js +73 -0
- package/core/styleParts.js +96 -0
- package/core/targeting.js +64 -0
- package/core/thingExplain.js +68 -0
- package/core/thingOps.js +168 -0
- package/core/things.js +212 -0
- package/core/threadPure.js +120 -0
- package/core/threadServe.js +25 -0
- package/core/tier.js +11 -0
- package/core/util.js +11 -0
- package/core/validate.js +204 -0
- package/docs/AI.md +123 -0
- package/docs/API.md +83 -0
- package/docs/CODEMAP.md +347 -0
- package/docs/COMMANDS.md +108 -0
- package/docs/CONVENTIONS.md +145 -0
- package/docs/PERF.md +217 -0
- package/docs/THREE.md +86 -0
- package/docs/api/ambience.md +15 -0
- package/docs/api/assets.md +62 -0
- package/docs/api/audio.md +53 -0
- package/docs/api/budget.md +40 -0
- package/docs/api/cameraRig.md +120 -0
- package/docs/api/characters.md +144 -0
- package/docs/api/clock.md +7 -0
- package/docs/api/collision.md +39 -0
- package/docs/api/content.md +64 -0
- package/docs/api/dialogue.md +39 -0
- package/docs/api/engine.md +199 -0
- package/docs/api/entities.md +61 -0
- package/docs/api/events.md +95 -0
- package/docs/api/flow.md +27 -0
- package/docs/api/grids.md +11 -0
- package/docs/api/ground.md +16 -0
- package/docs/api/hlod.md +34 -0
- package/docs/api/hud.md +31 -0
- package/docs/api/i18n.md +10 -0
- package/docs/api/input.md +24 -0
- package/docs/api/interactions.md +31 -0
- package/docs/api/inventory.md +66 -0
- package/docs/api/jobs.md +10 -0
- package/docs/api/level.md +41 -0
- package/docs/api/lightPool.md +56 -0
- package/docs/api/music.md +34 -0
- package/docs/api/nav.md +26 -0
- package/docs/api/net.md +14 -0
- package/docs/api/openWorld.md +24 -0
- package/docs/api/particles.md +41 -0
- package/docs/api/photo.md +15 -0
- package/docs/api/post.md +10 -0
- package/docs/api/quests.md +36 -0
- package/docs/api/rays.md +26 -0
- package/docs/api/rigid.md +84 -0
- package/docs/api/saves.md +32 -0
- package/docs/api/settings.md +36 -0
- package/docs/api/sky.md +58 -0
- package/docs/api/stream.md +31 -0
- package/docs/api/style.md +134 -0
- package/docs/api/terrain.md +34 -0
- package/docs/api/timeline.md +39 -0
- package/docs/api/tools.md +57 -0
- package/docs/api/triggers.md +56 -0
- package/docs/api/vars.md +9 -0
- package/docs/api/vegetation.md +52 -0
- package/docs/api/water.md +48 -0
- package/docs/api/weather.md +29 -0
- package/docs/api/world.md +30 -0
- package/docs/recipes/01-new-game.md +148 -0
- package/docs/recipes/02-npc.md +167 -0
- package/docs/recipes/03-items-pickups.md +158 -0
- package/docs/recipes/04-quests.md +83 -0
- package/docs/recipes/05-props-bake.md +159 -0
- package/docs/recipes/06-clock-events.md +117 -0
- package/docs/recipes/07-flow-scenes-pause.md +132 -0
- package/docs/recipes/08-weather-sky.md +74 -0
- package/docs/recipes/09-style-pack.md +234 -0
- package/docs/recipes/10-blender-level.md +67 -0
- package/docs/recipes/11-vehicles.md +55 -0
- package/docs/recipes/12-navmesh.md +79 -0
- package/docs/recipes/13-animation.md +149 -0
- package/docs/recipes/14-custom-module.md +91 -0
- package/docs/recipes/15-perf.md +78 -0
- package/docs/recipes/16-dev-bridge.md +180 -0
- package/docs/recipes/18-world.md +185 -0
- package/docs/recipes/19-shooting-picking.md +76 -0
- package/docs/recipes/20-content-actions-save.md +176 -0
- package/docs/recipes/21-camera.md +153 -0
- package/docs/recipes/22-shop-gold.md +107 -0
- package/docs/recipes/23-ops.md +175 -0
- package/docs/recipes/26-ui-parts.md +138 -0
- package/docs/recipes/27-net.md +96 -0
- package/docs/recipes/28-terrain.md +80 -0
- package/docs/recipes/29-grid.md +87 -0
- package/docs/recipes/30-templates.md +131 -0
- package/docs/recipes/31-audio.md +126 -0
- package/docs/recipes/32-action-game.md +33 -0
- package/docs/recipes/33-stream-sources.md +37 -0
- package/docs/recipes/34-environment-lighting.md +36 -0
- package/docs/recipes/35-style-from-reference.md +89 -0
- package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
- package/docs/recipes/37-terrain-look-hooks.md +97 -0
- package/docs/recipes/38-environment-look-hooks.md +83 -0
- package/docs/recipes/40-scene.md +108 -0
- package/docs/recipes/41-thing-registry.md +93 -0
- package/docs/recipes/42-terrain-shape.md +64 -0
- package/docs/recipes/43-shader-patches-surface-looks.md +120 -0
- package/docs/recipes/44-water-weather-look-hooks.md +135 -0
- package/docs/recipes/45-cascaded-shadows.md +51 -0
- package/docs/recipes/46-blender-art-route.md +114 -0
- package/docs/recipes/47-island-snow-backdrop.md +44 -0
- package/docs/recipes/48-make-material.md +70 -0
- package/docs/recipes/49-game-module-contract.md +71 -0
- package/docs/recipes/50-own-renderer.md +12 -0
- package/docs/recipes/51-capability-catalog.md +63 -0
- package/docs/recipes/52-look.md +108 -0
- package/examples/action/DESIGN.md +3 -0
- package/examples/action/GAMEMAP.md +127 -0
- package/examples/action/content/actions.js +8 -0
- package/examples/action/content/audio.js +9 -0
- package/examples/action/content/index.js +10 -0
- package/examples/action/content/items.js +4 -0
- package/examples/action/content/places.js +4 -0
- package/examples/action/content/props.js +11 -0
- package/examples/action/content/templates.js +10 -0
- package/examples/action/content/views.js +6 -0
- package/examples/action/look.js +5 -0
- package/examples/action/main.js +137 -0
- package/examples/action/models.js +25 -0
- package/examples/sheepisland/GAMEMAP.md +107 -0
- package/examples/sheepisland/content/index.js +6 -0
- package/examples/sheepisland/content/props.js +19 -0
- package/examples/sheepisland/content/templates.js +5 -0
- package/examples/sheepisland/content/vegetation.js +8 -0
- package/examples/sheepisland/main.js +71 -0
- package/examples/sheepisland/params.js +25 -0
- package/examples/sheepisland/style/index.js +79 -0
- package/examples/sheepisland/style/models.js +59 -0
- package/examples/sheepisland/views.js +9 -0
- package/examples/styletest/GAMEMAP.md +135 -0
- package/examples/styletest/content/index.js +9 -0
- package/examples/styletest/content/items.js +8 -0
- package/examples/styletest/content/npcs.js +8 -0
- package/examples/styletest/content/places.js +5 -0
- package/examples/styletest/content/props.js +16 -0
- package/examples/styletest/content/templates.js +9 -0
- package/examples/styletest/content/vegetation.js +31 -0
- package/examples/styletest/look.js +11 -0
- package/examples/styletest/main.js +95 -0
- package/examples/styletest/models.js +87 -0
- package/examples/styletest/overrides.js +33 -0
- package/examples/styletest/panel.js +135 -0
- package/examples/styletest/params.js +32 -0
- package/examples/styletest/views.js +31 -0
- package/examples/world/DESIGN.md +5 -0
- package/examples/world/GAMEMAP.md +171 -0
- package/examples/world/content/actions.js +8 -0
- package/examples/world/content/audio.js +25 -0
- package/examples/world/content/bodies.js +12 -0
- package/examples/world/content/containers.js +4 -0
- package/examples/world/content/dialogues.js +33 -0
- package/examples/world/content/index.js +17 -0
- package/examples/world/content/items.js +10 -0
- package/examples/world/content/npcs.js +14 -0
- package/examples/world/content/pickups.js +11 -0
- package/examples/world/content/places.js +6 -0
- package/examples/world/content/props.js +12 -0
- package/examples/world/content/quests.js +15 -0
- package/examples/world/content/rules.js +23 -0
- package/examples/world/content/templates.js +5 -0
- package/examples/world/content/vegetation.js +32 -0
- package/examples/world/main.js +168 -0
- package/examples/world/models.js +28 -0
- package/index.d.ts +306 -0
- package/index.js +122 -0
- package/llms.txt +61 -0
- package/modules/ambience/Ambience.js +186 -0
- package/modules/camera/FirstPersonCamera.js +131 -0
- package/modules/camera/FixedCamera.js +162 -0
- package/modules/camera/FollowCamera.js +91 -0
- package/modules/camera/RtsCamera.js +132 -0
- package/modules/camera/common.js +182 -0
- package/modules/camera/index.js +11 -0
- package/modules/camera/projection.js +34 -0
- package/modules/characters/Character.js +235 -0
- package/modules/characters/NPC.js +242 -0
- package/modules/characters/assetModel.js +42 -0
- package/modules/characters/astar.js +66 -0
- package/modules/characters/behaviors.js +72 -0
- package/modules/characters/footsteps.js +13 -0
- package/modules/characters/index.js +215 -0
- package/modules/characters/moveHelpers.js +29 -0
- package/modules/characters/movers/common.js +62 -0
- package/modules/characters/movers/rapier.js +74 -0
- package/modules/characters/movers/simple.js +43 -0
- package/modules/characters/npcAvoid.js +129 -0
- package/modules/characters/npcSim.js +150 -0
- package/modules/characters/npcView.js +42 -0
- package/modules/characters/pathAsync.js +113 -0
- package/modules/characters/pathJob.js +62 -0
- package/modules/characters/pathWorker.js +7 -0
- package/modules/characters/playerStrings.js +12 -0
- package/modules/characters/proceduralRig.js +58 -0
- package/modules/characters/useModel.js +22 -0
- package/modules/characters/walkTo.js +58 -0
- package/modules/collision/Collision.js +274 -0
- package/modules/collision/grid.js +63 -0
- package/modules/content/explain.js +13 -0
- package/modules/content/ids.js +95 -0
- package/modules/content/index.js +154 -0
- package/modules/content/loader.js +190 -0
- package/modules/content/models.js +69 -0
- package/modules/content/packs.js +69 -0
- package/modules/content/props.js +89 -0
- package/modules/content/rules.js +134 -0
- package/modules/content/templates.js +189 -0
- package/modules/debug/DebugPanel.js +174 -0
- package/modules/entities/Entities.js +243 -0
- package/modules/entities/build.js +25 -0
- package/modules/entities/index.js +4 -0
- package/modules/flow/index.js +101 -0
- package/modules/gameplay/Container.js +227 -0
- package/modules/gameplay/Containers.js +89 -0
- package/modules/gameplay/Dialogue.js +219 -0
- package/modules/gameplay/Interactions.js +253 -0
- package/modules/gameplay/Inventory.js +224 -0
- package/modules/gameplay/Quests.js +205 -0
- package/modules/gameplay/boxOps.js +60 -0
- package/modules/gameplay/dialogueBox.js +48 -0
- package/modules/gameplay/interactionPrompt.js +28 -0
- package/modules/gameplay/inventoryOps.js +137 -0
- package/modules/gameplay/pickups.js +115 -0
- package/modules/gameplay/questLog.js +54 -0
- package/modules/gameplay/questSave.js +71 -0
- package/modules/grid/Grid.js +184 -0
- package/modules/grid/Layer.js +142 -0
- package/modules/grid/index.js +236 -0
- package/modules/grid/ops.js +73 -0
- package/modules/grid/preview.js +85 -0
- package/modules/grid/tiles.js +79 -0
- package/modules/hlod/index.js +167 -0
- package/modules/hud/index.js +167 -0
- package/modules/hud/parts.js +80 -0
- package/modules/level/geometry.js +46 -0
- package/modules/level/heightfield.js +160 -0
- package/modules/level/index.js +233 -0
- package/modules/level/nodes.js +84 -0
- package/modules/lights/index.js +227 -0
- package/modules/music/Music.js +294 -0
- package/modules/music/index.js +2 -0
- package/modules/music/rules.js +28 -0
- package/modules/nav/index.js +156 -0
- package/modules/nav/navPath.js +17 -0
- package/modules/net/Client.js +137 -0
- package/modules/net/Host.js +117 -0
- package/modules/net/Net.js +49 -0
- package/modules/net/index.js +77 -0
- package/modules/net/sync.js +114 -0
- package/modules/net/transports.js +118 -0
- package/modules/particles/Particles.js +179 -0
- package/modules/particles/effect.js +112 -0
- package/modules/particles/shaders.js +28 -0
- package/modules/photo/Photo.js +146 -0
- package/modules/rigid/RigidBodies.js +265 -0
- package/modules/rigid/Vehicles.js +97 -0
- package/modules/rigid/sync.js +158 -0
- package/modules/settings/Settings.js +297 -0
- package/modules/settings/apply.js +21 -0
- package/modules/settings/index.js +3 -0
- package/modules/settings/sections.js +156 -0
- package/modules/settings/strings.js +53 -0
- package/modules/settings/view.js +65 -0
- package/modules/sky/Sky.js +259 -0
- package/modules/sky/calendar.js +80 -0
- package/modules/sky/cascades.js +125 -0
- package/modules/sky/clouds.js +79 -0
- package/modules/sky/domeLayers.js +33 -0
- package/modules/sky/environment.js +141 -0
- package/modules/sky/fog.js +139 -0
- package/modules/sky/frame.js +77 -0
- package/modules/sky/layers.js +69 -0
- package/modules/sky/look.js +51 -0
- package/modules/sky/lookFog.js +80 -0
- package/modules/sky/lookShadow.js +50 -0
- package/modules/sky/lookSky.js +108 -0
- package/modules/sky/schedule.js +80 -0
- package/modules/sky/shader.js +96 -0
- package/modules/sky/shadow.js +74 -0
- package/modules/sky/skyModule.js +60 -0
- package/modules/terrain/ChunkManager.js +260 -0
- package/modules/terrain/chunkJob.js +19 -0
- package/modules/terrain/chunkLevels.js +40 -0
- package/modules/terrain/chunkQueries.js +42 -0
- package/modules/terrain/chunkWorker.js +5 -0
- package/modules/terrain/index.js +118 -0
- package/modules/terrain/lookGround.js +61 -0
- package/modules/terrain/mountTerrain.js +32 -0
- package/modules/terrain/terrainColorMap.js +41 -0
- package/modules/terrain/terrainDefaults.js +39 -0
- package/modules/terrain/terrainEdit.js +139 -0
- package/modules/terrain/terrainGen.js +155 -0
- package/modules/terrain/terrainIsland.js +131 -0
- package/modules/terrain/terrainMesh.js +92 -0
- package/modules/terrain/terrainShape.js +108 -0
- package/modules/terrain/terrainShapeMain.js +41 -0
- package/modules/terrain/terrainTexture.js +44 -0
- package/modules/timeline/Timeline.js +253 -0
- package/modules/timeline/Tween.js +114 -0
- package/modules/timeline/letterbox.js +24 -0
- package/modules/timeline/shots.js +90 -0
- package/modules/triggers/index.js +268 -0
- package/modules/vegetation/Vegetation.js +256 -0
- package/modules/vegetation/groundChunks.js +177 -0
- package/modules/vegetation/index.js +43 -0
- package/modules/vegetation/lookWind.js +37 -0
- package/modules/vegetation/modelGeometry.js +21 -0
- package/modules/water/Water.js +160 -0
- package/modules/water/look.js +80 -0
- package/modules/water/surface.js +88 -0
- package/modules/weather/Weather.js +242 -0
- package/modules/weather/look.js +75 -0
- package/modules/weather/particles.js +92 -0
- package/modules/weather/shaders.js +49 -0
- package/modules/weather/strings.js +15 -0
- package/modules/world/World.js +231 -0
- package/modules/world/cells.js +42 -0
- package/modules/world/explain.js +11 -0
- package/modules/world/index.js +71 -0
- package/modules/world/persist.js +107 -0
- package/modules/world/pos.js +20 -0
- package/modules/world/records.js +89 -0
- package/modules/world/sim.js +175 -0
- package/modules/world/simFar.js +82 -0
- package/modules/world/state.js +115 -0
- package/modules/world/thingSource.js +44 -0
- package/modules/world/views.js +182 -0
- package/package.json +66 -4
- package/presets.js +96 -0
- package/render/PostFX.js +240 -0
- package/render/detail.js +105 -0
- package/render/effects.js +144 -0
- package/render/engineUniforms.js +23 -0
- package/render/fuse.js +84 -0
- package/render/lighting.js +100 -0
- package/render/lights.js +18 -0
- package/render/lookSurface.js +161 -0
- package/render/materials.js +220 -0
- package/render/patches.js +252 -0
- package/render/postLook.js +86 -0
- package/render/surface.js +69 -0
- package/render/uniformDecl.js +29 -0
- package/types/common.d.ts +34 -0
- package/types/core.d.ts +1965 -0
- package/types/gameplay.d.ts +1822 -0
- package/types/generated/core/Audio.d.ts +200 -0
- package/types/generated/core/Batching.d.ts +47 -0
- package/types/generated/core/Budget.d.ts +90 -0
- package/types/generated/core/Commits.d.ts +31 -0
- package/types/generated/core/DebugOverrides.d.ts +52 -0
- package/types/generated/core/Events.d.ts +89 -0
- package/types/generated/core/I18n.d.ts +30 -0
- package/types/generated/core/Input.d.ts +118 -0
- package/types/generated/core/Jobs.d.ts +41 -0
- package/types/generated/core/Ops.d.ts +203 -0
- package/types/generated/core/Random.d.ts +49 -0
- package/types/generated/core/Rays.d.ts +49 -0
- package/types/generated/core/Saves.d.ts +162 -0
- package/types/generated/core/Stream.d.ts +93 -0
- package/types/generated/core/Threads.d.ts +82 -0
- package/types/generated/core/Views.d.ts +33 -0
- package/types/generated/core/audioVoice.d.ts +47 -0
- package/types/generated/core/page.d.ts +18 -0
- package/types/generated/core/session.d.ts +48 -0
- package/types/generated/modules/ambience/Ambience.d.ts +48 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
- package/types/generated/modules/flow/index.d.ts +10 -0
- package/types/generated/modules/grid/Grid.d.ts +151 -0
- package/types/generated/modules/grid/Layer.d.ts +65 -0
- package/types/generated/modules/grid/index.d.ts +86 -0
- package/types/generated/modules/hlod/index.d.ts +11 -0
- package/types/generated/modules/hud/index.d.ts +10 -0
- package/types/generated/modules/lights/index.d.ts +13 -0
- package/types/generated/modules/music/Music.d.ts +111 -0
- package/types/generated/modules/net/Net.d.ts +34 -0
- package/types/generated/modules/net/index.d.ts +53 -0
- package/types/generated/modules/net/transports.d.ts +58 -0
- package/types/generated/modules/particles/Particles.d.ts +69 -0
- package/types/generated/modules/sky/Sky.d.ts +145 -0
- package/types/generated/modules/sky/skyModule.d.ts +10 -0
- package/types/generated/modules/timeline/Timeline.d.ts +51 -0
- package/types/generated/modules/water/Water.d.ts +29 -0
- package/types/generated/modules/weather/Weather.d.ts +62 -0
- package/types/generated/modules/world/World.d.ts +242 -0
- package/types/generated/modules/world/index.d.ts +15 -0
- package/types/generated/render/PostFX.d.ts +125 -0
- package/types/generated/render/materials.d.ts +100 -0
- package/types/generated/render/patches.d.ts +41 -0
- package/types/generated/ui/Focus.d.ts +11 -0
- package/types/generated/ui/LoadingScreen.d.ts +2 -0
- package/types/generated/ui/UI.d.ts +57 -0
- package/types/nav.d.ts +52 -0
- package/types/physics.d.ts +592 -0
- package/types/style.d.ts +638 -0
- package/types/worker.d.ts +11 -0
- package/types/world.d.ts +772 -0
- package/ui/Focus.js +51 -0
- package/ui/LoadingScreen.js +42 -0
- package/ui/Parts.js +199 -0
- package/ui/UI.js +167 -0
- package/ui/defaults.js +85 -0
- package/ui/theme.js +124 -0
- 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 => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[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
|
+
}
|