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
|
@@ -0,0 +1,1822 @@
|
|
|
1
|
+
// Gameplay modules: timeline, level, triggers, entities, world changes, particles, settings, music, characters/NPCs, interactions, dialogue, inventory,
|
|
2
|
+
// quests, photo mode, ambience, debug.
|
|
3
|
+
import type { Object3D, Vector3, Vector2, Quaternion, Texture, ColorLike, Vec3Like, Ease, Handle, Range, XZ, Loose, PositionLike } from './common';
|
|
4
|
+
import type { Engine } from './core';
|
|
5
|
+
import type { Input } from './generated/core/Input';
|
|
6
|
+
import type { Animator, AnimatorOptions, Vehicle } from './physics';
|
|
7
|
+
import type { WorldRecord } from './generated/modules/world/World';
|
|
8
|
+
|
|
9
|
+
// ======================================================================
|
|
10
|
+
// Timeline timeline()
|
|
11
|
+
// ======================================================================
|
|
12
|
+
|
|
13
|
+
/** Promise of a tween: await it to wait for the end; finish() jumps to the end now, cancel() stops at the current position */
|
|
14
|
+
export interface TweenPromise extends Promise<boolean> {
|
|
15
|
+
finish(): void;
|
|
16
|
+
cancel(): void;
|
|
17
|
+
task: any;
|
|
18
|
+
}
|
|
19
|
+
/** Tween target: 'dotted.path' -> target value. E.g. { 'position.y': 3, 'material.color': 0xffffff, scale: [2, 2, 2] }; a value can also be () => value */
|
|
20
|
+
export type TweenTo = Record<string, number | string | number[] | object | (() => any)>;
|
|
21
|
+
|
|
22
|
+
/** One end point of a camera move */
|
|
23
|
+
export interface CameraPose {
|
|
24
|
+
/** Camera position */
|
|
25
|
+
position?: Vec3Like;
|
|
26
|
+
/** The point to look at, or a moving object */
|
|
27
|
+
lookAt?: Vec3Like | Object3D;
|
|
28
|
+
/** Field of view (degrees) */
|
|
29
|
+
fov?: number;
|
|
30
|
+
}
|
|
31
|
+
/** Timeline steps (run in order) */
|
|
32
|
+
export type TimelineStep =
|
|
33
|
+
| TimelineStep[]
|
|
34
|
+
| ((engine: Engine, run: any) => any)
|
|
35
|
+
| { parallel: TimelineStep[] }
|
|
36
|
+
| { sequence: TimelineStep[] }
|
|
37
|
+
/** Wait some seconds */
|
|
38
|
+
| { wait: number }
|
|
39
|
+
/** Wait for an event; timeout is the maximum seconds to wait */
|
|
40
|
+
| { waitFor: string; timeout?: number }
|
|
41
|
+
/** Run a piece of code (may be async) */
|
|
42
|
+
| { do: (engine: Engine, run: any) => any }
|
|
43
|
+
/** Tween: target is the object, to the target values, duration in seconds */
|
|
44
|
+
| { tween: { target: any; to: TweenTo; duration?: number; ease?: Ease } }
|
|
45
|
+
/** Camera: from/to end points, duration in seconds, fov target field of view; or { release: true } to hand the camera back */
|
|
46
|
+
| { camera: { from?: CameraPose; to?: CameraPose; duration?: number; ease?: Ease; fov?: number; release?: false } | { release: true } }
|
|
47
|
+
/**
|
|
48
|
+
* Move an object (or character, or camera) along a path: points are the path points, duration in seconds, lookAhead how far ahead to look (0–1),
|
|
49
|
+
* ground snaps to the ground (a number = height above ground)
|
|
50
|
+
*/
|
|
51
|
+
| { path: { object: any; points: Vec3Like[]; duration?: number; ease?: Ease; lookAhead?: number; ground?: boolean | number; closed?: boolean; curve?: 'catmullrom' | 'centripetal' | 'chordal'; tension?: number; upright?: boolean } }
|
|
52
|
+
/** Full-screen fade: fade is the seconds, to is the target cover (0 transparent ... 1 full black, default 1) */
|
|
53
|
+
| { fade: number; to?: number }
|
|
54
|
+
/** Say a line of dialogue (needs the dialogue module) and wait for the dialogue to end */
|
|
55
|
+
| { say: { speaker?: string; text?: string; nodes?: DialogueScript; node?: string } }
|
|
56
|
+
| null | undefined | false;
|
|
57
|
+
|
|
58
|
+
export interface TimelinePlayOptions {
|
|
59
|
+
/** Can be skipped, default true */
|
|
60
|
+
skippable?: boolean;
|
|
61
|
+
/** Letterbox bars, default false */
|
|
62
|
+
letterbox?: boolean;
|
|
63
|
+
/** Lock player input while playing, default true */
|
|
64
|
+
lockInput?: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Timeline (engine.timeline) is generated from the JSDoc in modules/timeline/Timeline.js (npm run map); only the type is re-exported here
|
|
68
|
+
import type { Timeline } from './generated/modules/timeline/Timeline';
|
|
69
|
+
export type { Timeline };
|
|
70
|
+
export interface TimelineOptions {
|
|
71
|
+
/**
|
|
72
|
+
* Keys that skip a cutscene, default ['Escape', 'Backspace'] (Esc is the back key, which the UI focus stack hands to the topmost cutscene; cutscenes
|
|
73
|
+
* do not advance while frozen)
|
|
74
|
+
*/
|
|
75
|
+
skipKeys?: string[];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ======================================================================
|
|
79
|
+
// Level level()
|
|
80
|
+
// ======================================================================
|
|
81
|
+
|
|
82
|
+
export interface LevelOptions {
|
|
83
|
+
/** glTF path (or asset name); pick one of this and scene */
|
|
84
|
+
url?: string | null;
|
|
85
|
+
/** THREE.Object3D built in code; pick one of this and url */
|
|
86
|
+
scene?: Object3D | null;
|
|
87
|
+
/** Decide yourself which meshes are walkable */
|
|
88
|
+
walkable?: ((mesh: Object3D) => boolean) | null;
|
|
89
|
+
/** 'named' only col_ meshes block the player | 'auto' every tall mesh that is not walkable blocks | false */
|
|
90
|
+
colliders?: 'named' | 'auto' | false;
|
|
91
|
+
/** Heightfield cell size (meters), default 0.5 */
|
|
92
|
+
cellSize?: number;
|
|
93
|
+
/** Ground height outside the level (meters), default 0 */
|
|
94
|
+
outside?: number;
|
|
95
|
+
/** Water surface height (meters), default no water */
|
|
96
|
+
waterLevel?: number;
|
|
97
|
+
/** Expand the collision box outward by this much (meters) */
|
|
98
|
+
colliderPad?: number;
|
|
99
|
+
/** Minimum height of the collision box (meters) */
|
|
100
|
+
colliderHeight?: number;
|
|
101
|
+
/** Treat it as a step edge when the height difference between adjacent grid points exceeds this (meters), default 0.6 */
|
|
102
|
+
sharpEdge?: number;
|
|
103
|
+
/** Hide the marker placeholder meshes, default true */
|
|
104
|
+
hideMarkers?: boolean;
|
|
105
|
+
/** Add the scene to engine.scene, default true */
|
|
106
|
+
addToScene?: boolean;
|
|
107
|
+
}
|
|
108
|
+
/** Markers in the level (spawn, npc_*, trigger_*, marker_*), in world coordinates */
|
|
109
|
+
export interface LevelMarker { name: string; position: Vector3; quaternion: Quaternion; scale: Vector3; userData: Record<string, any>; object: Object3D }
|
|
110
|
+
export interface LevelLoadedEvent { root: Object3D; markers: Record<string, LevelMarker>; spawn: Vector3 }
|
|
111
|
+
|
|
112
|
+
/** engine.level */
|
|
113
|
+
export interface Level {
|
|
114
|
+
/** Scene root node */
|
|
115
|
+
root: Object3D | null;
|
|
116
|
+
/** Same as root (the name consistent with player.object and ent.object) */
|
|
117
|
+
readonly object: Object3D | null;
|
|
118
|
+
/** All markers: name -> marker */
|
|
119
|
+
markers: Record<string, LevelMarker>;
|
|
120
|
+
/** Spawn point position */
|
|
121
|
+
spawn: Vector3;
|
|
122
|
+
/** Heightfield (for debugging) */
|
|
123
|
+
heightfield: any;
|
|
124
|
+
/** Milliseconds spent building the heightfield */
|
|
125
|
+
buildMs?: number;
|
|
126
|
+
/** Whether loading is finished */
|
|
127
|
+
readonly ready: boolean;
|
|
128
|
+
/** Get a marker, null if none */
|
|
129
|
+
marker(name: string): LevelMarker | null;
|
|
130
|
+
/** Get all markers whose names start with prefix, e.g. markersWith('npc_') */
|
|
131
|
+
markersWith(prefix: string): LevelMarker[];
|
|
132
|
+
/** Unload the level (the scene is fully deleted with engine.remove; collision, ray registrations and things registered with track are removed together) */
|
|
133
|
+
unload(): void;
|
|
134
|
+
/**
|
|
135
|
+
* Change level: unload the current one, load the new one (glTF path/asset name, or a THREE object), and emit level:loaded when done. When a load
|
|
136
|
+
* changes level, the save system waits for it
|
|
137
|
+
*/
|
|
138
|
+
load(urlOrScene: string | Object3D): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Register things that belong to the current level and need not be kept (the { remove() } handles of triggers...); they are deleted automatically on
|
|
141
|
+
* level change / unload; returns the same handle. world data that keeps state (NPCs, pickups, props) needs no registration: with a zone, a level
|
|
142
|
+
* change only tears down the model
|
|
143
|
+
*/
|
|
144
|
+
track<T extends { remove(): void }>(handle: T): T;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ======================================================================
|
|
148
|
+
// Trigger zones triggers()
|
|
149
|
+
// ======================================================================
|
|
150
|
+
|
|
151
|
+
/** Trigger zone parameters */
|
|
152
|
+
export interface TriggerOptions {
|
|
153
|
+
/** Shape: 'cylinder' upright cylinder (default) | 'sphere' | 'box' cuboid */
|
|
154
|
+
shape?: 'cylinder' | 'sphere' | 'box';
|
|
155
|
+
/** Center { x, y, z } / [x, y, z] / Vector3 / object (meters); for box and cylinder y is the bottom height; without y the ground height is used */
|
|
156
|
+
position?: PositionLike;
|
|
157
|
+
/** Sphere/cylinder radius (meters), default 1.5 */
|
|
158
|
+
radius?: number;
|
|
159
|
+
/** Box size [width, height, depth] (meters), default [2, 2, 2] */
|
|
160
|
+
size?: number[];
|
|
161
|
+
/** Cylinder height (meters), default 3 */
|
|
162
|
+
height?: number;
|
|
163
|
+
/** Box rotation around the Y axis (radians) */
|
|
164
|
+
rotation?: number;
|
|
165
|
+
/** Called on entering; who is the position that entered */
|
|
166
|
+
onEnter?: ((t: Trigger, who: Vector3) => void) | null;
|
|
167
|
+
/** Called on leaving */
|
|
168
|
+
onExit?: ((t: Trigger, who: Vector3 | null) => void) | null;
|
|
169
|
+
/** Called every fixed step while inside (dt in seconds) */
|
|
170
|
+
onStay?: ((dt: number, t: Trigger, who: Vector3) => void) | null;
|
|
171
|
+
/** Fire on the first enter only (exit follows at once); the zone stays with used = true, and a new playthrough (engine.session) re-arms it */
|
|
172
|
+
once?: boolean;
|
|
173
|
+
/** false pauses detection */
|
|
174
|
+
enabled?: boolean;
|
|
175
|
+
/** Name (carried in events) */
|
|
176
|
+
tag?: string;
|
|
177
|
+
/** Who can trigger it: the player by default; or a position, an object (its position is used), or a function returning an array of positions */
|
|
178
|
+
who?: Vector3 | Object3D | { x: number; y: number; z: number } | (() => Array<{ x: number; y: number; z: number }>) | null;
|
|
179
|
+
/** Seconds after leaving during which entering does not fire again, default 0 */
|
|
180
|
+
cooldown?: number;
|
|
181
|
+
/** Custom data */
|
|
182
|
+
userData?: Record<string, any>;
|
|
183
|
+
}
|
|
184
|
+
/** A trigger zone (the return value of add()) */
|
|
185
|
+
export interface Trigger {
|
|
186
|
+
shape: 'cylinder' | 'sphere' | 'box';
|
|
187
|
+
/** Position (meters) */
|
|
188
|
+
x: number; y: number; z: number;
|
|
189
|
+
radius: number; height: number; rotation: number;
|
|
190
|
+
tag: string;
|
|
191
|
+
/** Whether the player is inside now */
|
|
192
|
+
inside: boolean;
|
|
193
|
+
/** Can be changed at any time: false pauses detection */
|
|
194
|
+
enabled: boolean;
|
|
195
|
+
once: boolean;
|
|
196
|
+
/** A once zone that already fired this playthrough */
|
|
197
|
+
used: boolean;
|
|
198
|
+
cooldown: number;
|
|
199
|
+
userData: Record<string, any>;
|
|
200
|
+
onEnter: TriggerOptions['onEnter'];
|
|
201
|
+
onExit: TriggerOptions['onExit'];
|
|
202
|
+
onStay: TriggerOptions['onStay'];
|
|
203
|
+
/** Delete this trigger zone */
|
|
204
|
+
remove(): void;
|
|
205
|
+
/** Whether a point is inside */
|
|
206
|
+
contains(p: { x: number; y: number; z: number }): boolean;
|
|
207
|
+
}
|
|
208
|
+
export interface TriggerEvent { tag: string; trigger: Trigger; who: Vector3 | null }
|
|
209
|
+
export interface TriggersOptions {
|
|
210
|
+
/** Show the wireframes from the start */
|
|
211
|
+
debug?: boolean;
|
|
212
|
+
/** Action name that toggles the wireframes, default 'triggersDebug' */
|
|
213
|
+
action?: string;
|
|
214
|
+
/** Key that toggles the wireframes: default ['F4'] in dev builds, none in release builds */
|
|
215
|
+
keys?: string[];
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** engine.triggers */
|
|
219
|
+
export interface Triggers {
|
|
220
|
+
/** All trigger zones (a new array) */
|
|
221
|
+
list(): Trigger[];
|
|
222
|
+
/** Whether wireframes are shown */
|
|
223
|
+
debug: boolean;
|
|
224
|
+
action: string;
|
|
225
|
+
/** Add a trigger zone */
|
|
226
|
+
add(opts?: TriggerOptions): Trigger;
|
|
227
|
+
/** Delete all (delete a single one with trigger.remove()) */
|
|
228
|
+
clear(): void;
|
|
229
|
+
/** Find by tag */
|
|
230
|
+
byTag(tag: string): Trigger[];
|
|
231
|
+
/** Every trigger_xxx marker in the level becomes a trigger zone with tag xxx; opts is shared by all of them */
|
|
232
|
+
fromMarkers(opts?: TriggerOptions): Trigger[];
|
|
233
|
+
/** Show / hide the wireframes */
|
|
234
|
+
setDebug(on: boolean): void;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// ======================================================================
|
|
238
|
+
// Entities entities()
|
|
239
|
+
// ======================================================================
|
|
240
|
+
|
|
241
|
+
/** Growth stage */
|
|
242
|
+
export interface EntityStage {
|
|
243
|
+
/** Stage name, e.g. 'seed' */
|
|
244
|
+
name: string;
|
|
245
|
+
/** How many game seconds to stay in this stage (leave out on the last one = stay here forever) */
|
|
246
|
+
duration?: number;
|
|
247
|
+
/** Model size multiplier */
|
|
248
|
+
scale?: number;
|
|
249
|
+
/** Swap the model */
|
|
250
|
+
model?: (engine: Engine, ent: Entity) => Object3D;
|
|
251
|
+
}
|
|
252
|
+
/** Entity interaction settings (needs the interactions module) */
|
|
253
|
+
export interface EntityInteract {
|
|
254
|
+
/** Prompt text: an i18n key, plain text, or a function ent => text */
|
|
255
|
+
label?: string | ((ent: Entity, engine: Engine) => string);
|
|
256
|
+
/** Interaction action name, default 'interact' */
|
|
257
|
+
action?: string;
|
|
258
|
+
/** How close you must be to interact (meters), default 2.5 */
|
|
259
|
+
radius?: number;
|
|
260
|
+
/** How high the prompt floats (meters) */
|
|
261
|
+
height?: number;
|
|
262
|
+
/** Whether it can be interacted with */
|
|
263
|
+
enabled?: (ent: Entity, engine: Engine) => boolean;
|
|
264
|
+
/** When the interact key is pressed */
|
|
265
|
+
onUse?: (ent: Entity, engine: Engine) => void;
|
|
266
|
+
}
|
|
267
|
+
/** Entity type definition: engine.entities.define('sapling', {...}) */
|
|
268
|
+
export interface EntityDef<S = Record<string, any>> {
|
|
269
|
+
/** Create the model (required), returns a THREE.Object3D */
|
|
270
|
+
create: (engine: Engine, ent: Entity<S>) => Object3D;
|
|
271
|
+
/** Default state (merged with the state given at spawn) */
|
|
272
|
+
state?: S;
|
|
273
|
+
/** Growth stages */
|
|
274
|
+
stages?: EntityStage[];
|
|
275
|
+
/** Growth stops when this returns false */
|
|
276
|
+
canGrow?: (ent: Entity<S>, engine: Engine) => boolean;
|
|
277
|
+
/** Called every fixed step (dt in seconds); runs only near the player, far away only growth is caught up */
|
|
278
|
+
update?: (dt: number, ent: Entity<S>, engine: Engine) => void;
|
|
279
|
+
/** Interaction */
|
|
280
|
+
interact?: EntityInteract;
|
|
281
|
+
/** Circular collision radius (meters, needs the collision module; follows the model, exists only near the player) */
|
|
282
|
+
collider?: number;
|
|
283
|
+
/** Collision height (meters), default 3 */
|
|
284
|
+
colliderHeight?: number;
|
|
285
|
+
/** Cleanup when the model is torn down (called both when walking away and on deletion; don't clear data while the data still exists) */
|
|
286
|
+
dispose?: (ent: Entity<S>, engine: Engine) => void;
|
|
287
|
+
/** false = not saved (temporary things, cleared on load), default true */
|
|
288
|
+
save?: boolean;
|
|
289
|
+
}
|
|
290
|
+
/** Parameters of spawn() */
|
|
291
|
+
export interface EntitySpawnData {
|
|
292
|
+
/** Specify the id (generated automatically if omitted) */
|
|
293
|
+
id?: string;
|
|
294
|
+
/** Position: Vector3 / object / [x, y, z] / { x, z } ({ x, z } without y snaps to the ground), default origin */
|
|
295
|
+
position?: PositionLike;
|
|
296
|
+
/** Heading (radians) */
|
|
297
|
+
rotation?: number;
|
|
298
|
+
/** Initial state (merged onto the default state) */
|
|
299
|
+
state?: Record<string, any>;
|
|
300
|
+
/** Extra data (ent.data, saved) */
|
|
301
|
+
extra?: Record<string, any>;
|
|
302
|
+
}
|
|
303
|
+
/** An entity: x / y / z / rotation / state / data read engine.world data directly (kind is 'entity:<type>'); object / visual exist only near the player */
|
|
304
|
+
export interface Entity<S = Record<string, any>> {
|
|
305
|
+
id: string;
|
|
306
|
+
type: string;
|
|
307
|
+
def: EntityDef<S>;
|
|
308
|
+
/** Position (meters) */
|
|
309
|
+
readonly x: number; readonly z: number; readonly y: number;
|
|
310
|
+
readonly rotation: number;
|
|
311
|
+
/** State (stage is the current stage index, stageAt the time it was entered); change values with ent.set() so that events fire */
|
|
312
|
+
state: S & { stage?: number; stageAt?: number };
|
|
313
|
+
/** Root node (heading and interactions hang on it); null when there is no model far away, built the frame after spawn */
|
|
314
|
+
readonly object: Object3D | null;
|
|
315
|
+
/** Model (a child of the root node) */
|
|
316
|
+
readonly visual: Object3D | null;
|
|
317
|
+
/** Extra data */
|
|
318
|
+
readonly data: Record<string, any>;
|
|
319
|
+
/** Change one state value (emits the entity:state event) */
|
|
320
|
+
set(key: string, value: any): void;
|
|
321
|
+
/** Delete this entity */
|
|
322
|
+
remove(): boolean;
|
|
323
|
+
/** Current stage name */
|
|
324
|
+
readonly stageName: string | null;
|
|
325
|
+
}
|
|
326
|
+
export interface EntityStateEvent { ent: Entity; key: string; value: any; prev: any }
|
|
327
|
+
export interface EntityStageEvent { ent: Entity; stage: number; name: string }
|
|
328
|
+
|
|
329
|
+
/** engine.entities */
|
|
330
|
+
export interface Entities {
|
|
331
|
+
/** Type definitions */
|
|
332
|
+
types: Map<string, EntityDef>;
|
|
333
|
+
/** Game seconds (= engine.clock.now) */
|
|
334
|
+
readonly now: number;
|
|
335
|
+
/** Define an entity type */
|
|
336
|
+
define<S = Record<string, any>>(type: string, def: EntityDef<S>): this;
|
|
337
|
+
/** Spawn an entity (returns null if the type is not defined) */
|
|
338
|
+
spawn(type: string, data?: EntitySpawnData): Entity | null;
|
|
339
|
+
get(id: string): Entity | null;
|
|
340
|
+
byType(type: string): Entity[];
|
|
341
|
+
list(): Entity[];
|
|
342
|
+
/** The entity nearest to position within radius meters (default 3) (type restricts to one type) */
|
|
343
|
+
nearest(position: PositionLike, opts?: { radius?: number; type?: string | null }): Entity | null;
|
|
344
|
+
remove(id: string): boolean;
|
|
345
|
+
/** Delete all entities */
|
|
346
|
+
clear(): void;
|
|
347
|
+
/** Jump straight to a growth stage */
|
|
348
|
+
setStage(ent: Entity, i: number): void;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ======================================================================
|
|
352
|
+
// Particles particles()
|
|
353
|
+
// ======================================================================
|
|
354
|
+
|
|
355
|
+
/** Particle effect parameters (style.particles[name] of the style pack uses the same format too). All optional */
|
|
356
|
+
export interface ParticleOptions {
|
|
357
|
+
/** Maximum alive at once, default 120 (halved on low-end devices) */
|
|
358
|
+
max?: number;
|
|
359
|
+
/** Seconds each particle lives [min, max] */
|
|
360
|
+
lifetime?: Range;
|
|
361
|
+
/** Default particles per second for attach */
|
|
362
|
+
rate?: number;
|
|
363
|
+
/** Initial speed (m/s) [min, max] */
|
|
364
|
+
speed?: Range;
|
|
365
|
+
/** Emission direction [x, y, z] */
|
|
366
|
+
direction?: number[];
|
|
367
|
+
/** Maximum angle away from the direction (radians, π = all directions) */
|
|
368
|
+
spread?: number;
|
|
369
|
+
/** Radius of random spread around the spawn point (meters), or a box [x, y, z] */
|
|
370
|
+
area?: number | number[];
|
|
371
|
+
/** Vertical acceleration (m/s², negative falls) */
|
|
372
|
+
gravity?: number;
|
|
373
|
+
/** Air drag (fraction of speed lost per second) */
|
|
374
|
+
drag?: number;
|
|
375
|
+
/** How much wind affects it */
|
|
376
|
+
wind?: number;
|
|
377
|
+
/** Wind direction [x, y, z] */
|
|
378
|
+
windDir?: number[];
|
|
379
|
+
/** Size at birth / at death (meters) */
|
|
380
|
+
size?: Range;
|
|
381
|
+
/** Color at birth / at death (one color, or [birth, death]; an array, not a tuple, so a plain JS literal [0xffffff, 0xdddddd] type-checks) */
|
|
382
|
+
color?: ColorLike | ColorLike[];
|
|
383
|
+
/** Opacity at birth / at death, 0–1 */
|
|
384
|
+
opacity?: Range;
|
|
385
|
+
/** Texture (asset name, path or THREE.Texture); a soft round dot if omitted */
|
|
386
|
+
texture?: string | Texture | null;
|
|
387
|
+
/** 'normal' | 'additive' (glowing blend, for sparks) */
|
|
388
|
+
blending?: Loose<'normal' | 'additive'>;
|
|
389
|
+
/** Texture rotation speed (radians/second) */
|
|
390
|
+
spin?: number;
|
|
391
|
+
/** With attach, whether particles stay in the world (true) or the emission direction rotates with the object (false) */
|
|
392
|
+
worldSpace?: boolean;
|
|
393
|
+
/** Affected by fog, default true */
|
|
394
|
+
fog?: boolean;
|
|
395
|
+
/** Largest on-screen size of one particle in pixels (smoke drifting past the camera stays bounded), default 512 */
|
|
396
|
+
maxPixels?: number;
|
|
397
|
+
}
|
|
398
|
+
/** Continuous emitter returned by attach() (a handle) */
|
|
399
|
+
export interface ParticleEmitter extends Handle {
|
|
400
|
+
/** Particles per second (can be changed at any time) */
|
|
401
|
+
rate: number;
|
|
402
|
+
/** false pauses */
|
|
403
|
+
active: boolean;
|
|
404
|
+
/** Stop and remove (also removed automatically when the object leaves the scene) */
|
|
405
|
+
remove(): void;
|
|
406
|
+
[key: string]: any;
|
|
407
|
+
}
|
|
408
|
+
/** A particle effect */
|
|
409
|
+
export interface ParticleEffect { name: string; o: ParticleOptions; max: number; alive: number; points: Object3D; [key: string]: any }
|
|
410
|
+
|
|
411
|
+
// Particles (engine.particles) is generated from the JSDoc in modules/particles/Particles.js (npm run map); only the type is re-exported here
|
|
412
|
+
import type { Particles } from './generated/modules/particles/Particles';
|
|
413
|
+
export type { Particles };
|
|
414
|
+
|
|
415
|
+
// ======================================================================
|
|
416
|
+
// Settings menu settings()
|
|
417
|
+
// ======================================================================
|
|
418
|
+
|
|
419
|
+
/** Contents of a graphics quality preset */
|
|
420
|
+
export interface QualityPreset { pixelRatio?: number; shadows?: boolean; antialias?: boolean; bloom?: boolean; ao?: boolean; viewChunks?: number; density?: number; [key: string]: any }
|
|
421
|
+
/**
|
|
422
|
+
* The tools a settings tab's render(tools, e, s) receives: escaping, translation and the control helpers (each returns HTML)
|
|
423
|
+
* @example render: (tools, e, s) => tools.row(tools.t('my.subtitles'), tools.toggle('subtitles', s.get('subtitles')))
|
|
424
|
+
*/
|
|
425
|
+
export interface SettingsTools {
|
|
426
|
+
/** Escape text for HTML */
|
|
427
|
+
esc: (s: any) => string;
|
|
428
|
+
/** Translate a string key */
|
|
429
|
+
t: (key: string, params?: Record<string, any>) => string;
|
|
430
|
+
/** One row: text on the left, control on the right */
|
|
431
|
+
row(label: string, ctl: string): string;
|
|
432
|
+
/** Toggle button for a setting */
|
|
433
|
+
toggle(key: string, on: boolean): string;
|
|
434
|
+
/** Slider for a setting */
|
|
435
|
+
range(key: string, v: number, min: number, max: number, step: number): string;
|
|
436
|
+
/** A group of mutually exclusive buttons: options = [[value, text], ...]; a disabled value is display-only */
|
|
437
|
+
segmented(key: string, cur: any, options: [any, string][], disabled?: any[]): string;
|
|
438
|
+
}
|
|
439
|
+
/** One settings tab */
|
|
440
|
+
export interface SettingsSection {
|
|
441
|
+
/** Title: text or engine => text */
|
|
442
|
+
title: string | ((e: Engine) => string);
|
|
443
|
+
/** Generate the content HTML */
|
|
444
|
+
render: (tools: SettingsTools, e: Engine, s: Settings) => string;
|
|
445
|
+
/** Called after every redraw, to bind events to custom controls */
|
|
446
|
+
bind?: (el: HTMLElement, e: Engine, s: Settings) => void;
|
|
447
|
+
/** When this returns false the tab is not shown */
|
|
448
|
+
when?: (e: Engine) => boolean;
|
|
449
|
+
/** Sort order, smaller first, default 100 */
|
|
450
|
+
order?: number;
|
|
451
|
+
}
|
|
452
|
+
export interface SettingsOptions {
|
|
453
|
+
/** Action name that opens the menu, default 'menu' */
|
|
454
|
+
action?: string;
|
|
455
|
+
/** Key that opens the menu, default ['Escape'] */
|
|
456
|
+
keys?: string[];
|
|
457
|
+
/** Browser storage key */
|
|
458
|
+
storageKey?: string;
|
|
459
|
+
/** Override the graphics presets: { low: {...}, medium: {...}, high: {...} } */
|
|
460
|
+
presets?: Record<string, QualityPreset>;
|
|
461
|
+
/**
|
|
462
|
+
* Tabs: true (default) graphics, audio, controls, language, saves; false none; or a list by name, which may include the optional
|
|
463
|
+
* 'game' (resume, load a save, back to title) and 'camera' (mouse sensitivity, invert Y, field of view; saved as camera.sensitivity / camera.invertY
|
|
464
|
+
* / camera.fov)
|
|
465
|
+
* @example settings({ sections: ['game', 'graphics', 'audio', 'controls', 'camera'] })
|
|
466
|
+
*/
|
|
467
|
+
sections?: boolean | string[];
|
|
468
|
+
/**
|
|
469
|
+
* Pause gameplay while the menu is open (with flow installed it switches to flow's 'paused' and returns to the previous state on close; without flow
|
|
470
|
+
* it uses engine.freeze); the picture keeps running, default false
|
|
471
|
+
*/
|
|
472
|
+
freezeWorld?: boolean;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/** engine.settings */
|
|
476
|
+
export interface Settings {
|
|
477
|
+
action: string;
|
|
478
|
+
/** All current setting values */
|
|
479
|
+
values: Record<string, any>;
|
|
480
|
+
/** Graphics presets */
|
|
481
|
+
presets: Record<string, QualityPreset>;
|
|
482
|
+
/** Tabs */
|
|
483
|
+
sections: Map<string, any>;
|
|
484
|
+
/** Whether the menu is open */
|
|
485
|
+
readonly isOpen: boolean;
|
|
486
|
+
/** Read a setting, e.g. get('vol.music') */
|
|
487
|
+
get(key: string): any;
|
|
488
|
+
/** Change a setting (takes effect immediately + saved) */
|
|
489
|
+
set(key: string, value: any, opts?: { save?: boolean }): void;
|
|
490
|
+
/** Graphics preset: 'low' | 'medium' | 'high' */
|
|
491
|
+
preset(name: 'low' | 'medium' | 'high' | (string & {})): void;
|
|
492
|
+
/** Game-defined setting: default value + apply function (saved automatically) */
|
|
493
|
+
define<T = any>(key: string, def: T, apply?: (value: T, e: Engine) => void): this;
|
|
494
|
+
/** Add a tab of your own, or a built-in / optional one by name: addSection('camera') */
|
|
495
|
+
addSection(id: string, section?: SettingsSection): this;
|
|
496
|
+
removeSection(id: string): void;
|
|
497
|
+
open(): void;
|
|
498
|
+
close(): void;
|
|
499
|
+
toggle(on?: boolean): void;
|
|
500
|
+
/** Restore all keys to defaults */
|
|
501
|
+
resetBindings(): void;
|
|
502
|
+
/** Change the first key of an action to code */
|
|
503
|
+
rebind(action: string, code: string): void;
|
|
504
|
+
/** Key list (for the UI) */
|
|
505
|
+
actionList(): any[];
|
|
506
|
+
/** Save to the browser */
|
|
507
|
+
save(): void;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// ======================================================================
|
|
511
|
+
// Music music()
|
|
512
|
+
// ======================================================================
|
|
513
|
+
|
|
514
|
+
/** Track: a path, or { url, volume 0-1, loop, stems }. Stems are extra layers started in sync; each fades in as music.intensity rises through its `at` range */
|
|
515
|
+
export type MusicTrack = string | { url?: string; volume?: number; loop?: boolean; stems?: MusicStem[] };
|
|
516
|
+
/** A layer of a track: silent below at[0], full at at[1] and above (intensity 0-1) */
|
|
517
|
+
export interface MusicStem { url: string; at?: number[]; volume?: number }
|
|
518
|
+
/** Auto-selection condition: an object of condition keys ({ state: 'combat', time: 'night', zone: 'cave' }) or (e, music) => boolean */
|
|
519
|
+
export type MusicCondition = import('./core').AudioCondition;
|
|
520
|
+
/** Auto-selection rule: when the condition holds play track (null = silence), higher priority wins; no `when` = always (a fallback) */
|
|
521
|
+
export interface MusicRule { track: string | null; when?: MusicCondition; priority?: number }
|
|
522
|
+
export interface MusicChangeEvent { from: string | null; to: string | null }
|
|
523
|
+
export interface MusicOptions {
|
|
524
|
+
/** Tracks: name -> path or { url, volume, loop, stems } */
|
|
525
|
+
tracks?: Record<string, MusicTrack>;
|
|
526
|
+
/** Auto track rules (same as engine.music.rules(list)) */
|
|
527
|
+
rules?: MusicRule[];
|
|
528
|
+
/** Default crossfade seconds, default 2 */
|
|
529
|
+
fade?: number;
|
|
530
|
+
/** Duck the music bus during dialogue to this (0-1, e.g. 0.35); default false = no duck (the game opts in) */
|
|
531
|
+
duckDialogue?: number | false;
|
|
532
|
+
/** Fade seconds for the ducking */
|
|
533
|
+
duckFade?: number;
|
|
534
|
+
/** Rule debounce seconds, default 2 */
|
|
535
|
+
hold?: number;
|
|
536
|
+
/** Rule check interval (seconds), default 1 */
|
|
537
|
+
interval?: number;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// Music (engine.music) is generated from the JSDoc in modules/music/Music.js (npm run map); only the type is re-exported here
|
|
541
|
+
import type { Music } from './generated/modules/music/Music';
|
|
542
|
+
export type { Music };
|
|
543
|
+
|
|
544
|
+
// ======================================================================
|
|
545
|
+
// Characters characters() -> engine.characters, engine.npcs
|
|
546
|
+
// ======================================================================
|
|
547
|
+
|
|
548
|
+
/** Skeleton of a style pack's custom character: root is the root node, body/head optional, limbs are the swinging limbs */
|
|
549
|
+
export interface CharacterRig {
|
|
550
|
+
root: Object3D;
|
|
551
|
+
body?: Object3D;
|
|
552
|
+
head?: Object3D;
|
|
553
|
+
/** Named joints, exposed on the character as properties (lowpoly humanoid: armL armR legL legR) */
|
|
554
|
+
joints?: Record<string, Object3D>;
|
|
555
|
+
limbs?: { joint: Object3D; offset: number; amp: number; kind: 'arm' | 'leg'; side?: number }[];
|
|
556
|
+
}
|
|
557
|
+
/** Character parameters (shared by the player and NPCs) */
|
|
558
|
+
export interface CharacterOptions {
|
|
559
|
+
/** Colors (default from the style pack's style.character.colors) */
|
|
560
|
+
colors?: { body?: ColorLike; skin?: ColorLike; legs?: ColorLike; hair?: ColorLike };
|
|
561
|
+
/** Walking speed (m/s), default 4.5 */
|
|
562
|
+
speed?: number;
|
|
563
|
+
/** Running speed (m/s), default 7 */
|
|
564
|
+
runSpeed?: number;
|
|
565
|
+
/** Collision radius (meters), default 0.4 */
|
|
566
|
+
radius?: number;
|
|
567
|
+
/** Whether it can swim, default true */
|
|
568
|
+
canSwim?: boolean;
|
|
569
|
+
/** Water depth (meters) at which swimming starts, default 1 */
|
|
570
|
+
swimDepth?: number;
|
|
571
|
+
/** Swimming speed multiplier, default 0.45 */
|
|
572
|
+
swimSpeed?: number;
|
|
573
|
+
/** How fast it turns, default 10 */
|
|
574
|
+
turnSpeed?: number;
|
|
575
|
+
/** How fast it starts / stops, default 12 */
|
|
576
|
+
acceleration?: number;
|
|
577
|
+
/** Gravity (m/s², negative), default -24 */
|
|
578
|
+
gravity?: number;
|
|
579
|
+
/** Jump speed (m/s), default 8 */
|
|
580
|
+
jumpSpeed?: number;
|
|
581
|
+
/** Step height it can climb directly (meters), default 0.45 */
|
|
582
|
+
stepHeight?: number;
|
|
583
|
+
/** Air control, 0–1 */
|
|
584
|
+
airControl?: number;
|
|
585
|
+
/** How long after walking off an edge a jump is still allowed (seconds) */
|
|
586
|
+
coyoteTime?: number;
|
|
587
|
+
/** Whether it can jump, default true */
|
|
588
|
+
canJump?: boolean;
|
|
589
|
+
/**
|
|
590
|
+
* glTF model: what engine.assets.model() returned, or the name of a registered model asset (default style.character.model).
|
|
591
|
+
* A name builds the character at once with the placeholder body and swaps in a copy of the asset when it loads (see Character.ready / whenReady,
|
|
592
|
+
* event 'character:model')
|
|
593
|
+
* @example engine.characters.createPlayer({ model: 'hero' }) // after engine.assets.manifest({ models: { hero: '/models/hero.glb' } })
|
|
594
|
+
*/
|
|
595
|
+
model?: Object3D | string | null;
|
|
596
|
+
/** Action name mapping { idle, walk, run, swim, jump, fall } (shorthand for animation) */
|
|
597
|
+
clips?: { idle?: string; walk?: string; run?: string; swim?: string; jump?: string; fall?: string; drive?: string } | null;
|
|
598
|
+
/** Skeletal animation state machine config (states, blend trees, one-shot actions), see AnimatorOptions */
|
|
599
|
+
animation?: AnimatorOptions | null;
|
|
600
|
+
/** Movement method: 'simple' built into the engine (default) | 'rapier' Rapier character controller (needs the rigid module) */
|
|
601
|
+
mover?: 'simple' | 'rapier';
|
|
602
|
+
/**
|
|
603
|
+
* Which way it turns each move: 'move' (default, toward its velocity) | 'camera' (along cameraRig.forward()) | 'target' (toward faceTarget) | 'manual'
|
|
604
|
+
* (only face() turns it)
|
|
605
|
+
*/
|
|
606
|
+
faceMode?: FaceMode;
|
|
607
|
+
/** What faceMode 'target' faces (lock-on) */
|
|
608
|
+
faceTarget?: PositionLike | null;
|
|
609
|
+
}
|
|
610
|
+
/** Character facing mode, see CharacterOptions.faceMode */
|
|
611
|
+
export type FaceMode = 'move' | 'camera' | 'target' | 'manual';
|
|
612
|
+
/** What a player control function returns: world direction (length 0–1), run, speed override (m/s); null = stand still */
|
|
613
|
+
export type MoveRequest = { x: number; z: number; run?: boolean; speed?: number } | null | undefined;
|
|
614
|
+
/**
|
|
615
|
+
* Who moves the player each fixed step: 'camera' movement keys relative to the camera | 'none' the game calls player.move() itself | function returns
|
|
616
|
+
* the move request
|
|
617
|
+
*/
|
|
618
|
+
export type PlayerControl = 'camera' | 'none' | ((player: Character, input: Input, dt: number) => MoveRequest);
|
|
619
|
+
/** Parameters of createPlayer() */
|
|
620
|
+
export interface PlayerOptions extends CharacterOptions {
|
|
621
|
+
/** Spawn point (meters, { x, z } / Vector3 / object); flat ground is found automatically if omitted */
|
|
622
|
+
spawn?: PositionLike;
|
|
623
|
+
/** Keys of the 'jump' action; none bound when omitted (player.jump() still works). presets.player.* use ['Space', 'PadA'] */
|
|
624
|
+
jumpKeys?: string[];
|
|
625
|
+
/** Keys of the 'run' action read by control 'camera' / moveInput(); none bound when omitted. presets.player.* use Shift / gamepad LB */
|
|
626
|
+
runKeys?: string[];
|
|
627
|
+
/**
|
|
628
|
+
* Required, no default: 'camera' (keys relative to the camera) | 'none' (call player.move() yourself in onFixed) | (player, input, dt) => ({ x, z,
|
|
629
|
+
* run?, speed? }). Also the runtime property player.control. presets.player.* fill it
|
|
630
|
+
*/
|
|
631
|
+
control: PlayerControl;
|
|
632
|
+
/** true: the camera module follows the player (and back after a vehicle, and on a new session). Omitted with a camera installed warns in dev */
|
|
633
|
+
cameraFollow?: boolean;
|
|
634
|
+
}
|
|
635
|
+
/** Character state */
|
|
636
|
+
export type CharacterState = 'idle' | 'walk' | 'run' | 'swim' | 'jump' | 'fall' | 'drive';
|
|
637
|
+
|
|
638
|
+
/** Character (player and NPCs) */
|
|
639
|
+
export declare class Character {
|
|
640
|
+
constructor(engine: Engine, opts?: CharacterOptions);
|
|
641
|
+
engine: Engine;
|
|
642
|
+
/** Root node (this is what gets added to the scene) */
|
|
643
|
+
root: Object3D;
|
|
644
|
+
/** Same as root: add children, change visible and scale on it */
|
|
645
|
+
readonly object: Object3D;
|
|
646
|
+
/** Position (= root.position) */
|
|
647
|
+
readonly position: Vector3;
|
|
648
|
+
/** Horizontal velocity (x, y map to world x, z) */
|
|
649
|
+
velocity: Vector2;
|
|
650
|
+
/**
|
|
651
|
+
* Heading (radians): 0 faces +Z, forward = (sin facing, cos facing); increasing turns toward +X (rotation about the Y axis, consistent with
|
|
652
|
+
* root.rotation.y)
|
|
653
|
+
*/
|
|
654
|
+
facing: number;
|
|
655
|
+
/** Vertical velocity (m/s) */
|
|
656
|
+
vy: number;
|
|
657
|
+
/** Whether standing on the ground */
|
|
658
|
+
grounded: boolean;
|
|
659
|
+
/** Whether swimming */
|
|
660
|
+
swimming: boolean;
|
|
661
|
+
/** Current action state */
|
|
662
|
+
state: CharacterState;
|
|
663
|
+
/** Current movement speed (m/s) */
|
|
664
|
+
moveAmount: number;
|
|
665
|
+
/** Facing mode, change at any time; see CharacterOptions.faceMode */
|
|
666
|
+
faceMode: FaceMode;
|
|
667
|
+
/** What faceMode 'target' faces */
|
|
668
|
+
faceTarget: PositionLike | null;
|
|
669
|
+
/** Player only: who moves it each fixed step (see PlayerOptions.control) */
|
|
670
|
+
control?: PlayerControl;
|
|
671
|
+
/** Player only: whether the camera module follows it (see PlayerOptions.cameraFollow) */
|
|
672
|
+
cameraFollow?: boolean;
|
|
673
|
+
/** Move at a fixed velocity (m/s) for seconds, ignoring move()'s direction and without turning (knockback, dodge roll); gravity and collision still apply */
|
|
674
|
+
push(vx: number, vz: number, seconds: number): void;
|
|
675
|
+
speed: number; runSpeed: number; radius: number; canSwim: boolean; swimDepth: number; swimSpeedFactor: number;
|
|
676
|
+
turnSpeed: number; acceleration: number; gravity: number; jumpSpeed: number; stepHeight: number; airControl: number; coyoteTime: number; canJump: boolean;
|
|
677
|
+
/** Called when a foot lands (the argument is the ground type underfoot) */
|
|
678
|
+
onStep: ((groundType: string) => void) | null;
|
|
679
|
+
/** Called on landing (the argument is the landing speed) */
|
|
680
|
+
onLand: ((impact: number) => void) | null;
|
|
681
|
+
/** Movement method; name is 'simple' | 'rapier', controller is the native Rapier character controller (when rapier) */
|
|
682
|
+
mover: { name: 'simple' | 'rapier'; controller?: any; body?: any; collider?: any; move(dirX: number, dirZ: number, run: boolean, dt: number, speedOverride?: number): void; dispose?(): void };
|
|
683
|
+
/** Skeletal animation state machine (when there is a glTF model; null while a model named by asset is still loading) */
|
|
684
|
+
anim: Animator | null;
|
|
685
|
+
/** false while a model named by asset is loading (the placeholder body shows); true otherwise, also after a failed load (placeholder kept) */
|
|
686
|
+
ready: boolean;
|
|
687
|
+
/**
|
|
688
|
+
* Settles (never rejects) when a model named by asset is swapped in or has failed; already settled otherwise
|
|
689
|
+
* @example const npc = new Character(engine, { model: 'villager' }).addTo(); // import { Character } from 'threedog' await npc.whenReady;
|
|
690
|
+
* npc.playAction('Wave');
|
|
691
|
+
*/
|
|
692
|
+
readonly whenReady: Promise<void>;
|
|
693
|
+
/** The vehicle being driven (null when not driving) */
|
|
694
|
+
vehicle: Vehicle | null;
|
|
695
|
+
/** Board a vehicle (the vehicle returned by rigid.addVehicle) */
|
|
696
|
+
enter(vehicle: Vehicle): void;
|
|
697
|
+
/** Exit the vehicle */
|
|
698
|
+
exit(): void;
|
|
699
|
+
/** Play a one-shot action (e.g. 'wave'); skipped if the model has no such clip */
|
|
700
|
+
playAction(name: string): void;
|
|
701
|
+
/**
|
|
702
|
+
* Run fn(character, dt) every frame right after the animation pose is applied (model clips or procedural rig): attach things to bones or adjust bones. h.remove() stops it. Presentation only.
|
|
703
|
+
* @example const h = player.onPose(() => sword.position.copy(hand.getWorldPosition(v)));
|
|
704
|
+
*/
|
|
705
|
+
onPose(fn: (character: Character, dt: number) => void): { remove(): void };
|
|
706
|
+
/**
|
|
707
|
+
* Fully delete this character: exits the vehicle first, releases animation and movement, removes it from the scene and releases geometry and materials
|
|
708
|
+
* (used by npcs.remove / removePlayer)
|
|
709
|
+
*/
|
|
710
|
+
dispose(): void;
|
|
711
|
+
/** Request a jump */
|
|
712
|
+
jump(): void;
|
|
713
|
+
/** Add to the scene */
|
|
714
|
+
addTo(scene?: any): this;
|
|
715
|
+
/** Put it on the ground at position (Vector3 / object / [x, y, z] / { x, z }) */
|
|
716
|
+
placeAt(position: PositionLike): this;
|
|
717
|
+
/**
|
|
718
|
+
* After moving root yourself (a cutscene path, a scripted pose): write position and motion back to its world record (the player's), so a save right
|
|
719
|
+
* after has it
|
|
720
|
+
*/
|
|
721
|
+
syncRecord(): this;
|
|
722
|
+
/**
|
|
723
|
+
* Walk to a point along characters.findPath on fixed steps; never rejects. One walk per character: a new walkTo, dispose() or a save load ends the old
|
|
724
|
+
* one with 'cancelled'. Transient: not saved, not fast-forwarded by engine.skip
|
|
725
|
+
*/
|
|
726
|
+
walkTo(target: Vector3 | { x: number; z: number } | [number, number, number], opts?: { speed?: number; arrive?: number; turnRate?: number; stuckSeconds?: number; maxRepaths?: number; run?: boolean }): Promise<{ status: 'arrived' | 'noPath' | 'stuck' | 'cancelled' }> & { remove(): void };
|
|
727
|
+
/** Move in a direction (called once per fixed step): dirX/dirZ is the world direction (length 0–1), run to run, dt in seconds */
|
|
728
|
+
move(dirX: number, dirZ: number, run: boolean, dt: number, speedOverride?: number): void;
|
|
729
|
+
/** Ground type underfoot ('water' while swimming) */
|
|
730
|
+
groundType(): string;
|
|
731
|
+
/** Turn at once to a position, or to an angle in radians (0 = +Z) */
|
|
732
|
+
face(target: PositionLike | number): void;
|
|
733
|
+
/**
|
|
734
|
+
* Copy the motion state into a plain object (velocity, vertical velocity, heading, movement amount, grounded, swimming) to store in world data; after
|
|
735
|
+
* the model is rebuilt or a save is loaded, loadMotion continues from it with identical results
|
|
736
|
+
*/
|
|
737
|
+
saveMotion(out?: CharacterMotion): CharacterMotion;
|
|
738
|
+
/** Restore the motion state from the plain object of saveMotion */
|
|
739
|
+
loadMotion(m: CharacterMotion | null | undefined): this;
|
|
740
|
+
}
|
|
741
|
+
/** Result of Character.saveMotion (plain values, can be saved) */
|
|
742
|
+
/** facing is the same as Character.facing: 0 = +Z, forward (sin f, cos f) */
|
|
743
|
+
export interface CharacterMotion { vx?: number; vz?: number; vy?: number; facing?: number; amount?: number; grounded?: boolean; swimming?: boolean; coyote?: number }
|
|
744
|
+
|
|
745
|
+
/** One schedule stop (the npcs.add form): at is when to set off, position the destination */
|
|
746
|
+
export interface ScheduleStop {
|
|
747
|
+
/** When to set off: clock time 'HH:MM' (e.g. '18:30'), or a time of day 0–1 (0.25 = 6 am) */
|
|
748
|
+
at: number | string;
|
|
749
|
+
/** Destination (Vector3 / object / [x, y, z] / { x, z }) */
|
|
750
|
+
position: PositionLike;
|
|
751
|
+
}
|
|
752
|
+
/** One schedule stop (as stored in npc.schedule after install): at has been converted to 0–1, x/z is the destination (meters) */
|
|
753
|
+
export interface ScheduleEntry { at: number; x: number; z: number }
|
|
754
|
+
/** Parameters of engine.npcs.add({...}) */
|
|
755
|
+
export interface NPCOptions extends CharacterOptions {
|
|
756
|
+
/**
|
|
757
|
+
* Stable id (used by saves, quest targets { npc } and npcs.get); falls back to name if omitted (two NPCs with the same name and no id throw an error).
|
|
758
|
+
* Calling add again with the same id updates the definition and keeps position and state
|
|
759
|
+
*/
|
|
760
|
+
id?: string;
|
|
761
|
+
/**
|
|
762
|
+
* NPC authored in content (everything added by content): the initial record of world; saves only record changes such as position and state, the
|
|
763
|
+
* schedule follows the content; deleted ones do not reappear after loading
|
|
764
|
+
*/
|
|
765
|
+
initial?: boolean;
|
|
766
|
+
/** Name */
|
|
767
|
+
name?: string;
|
|
768
|
+
/**
|
|
769
|
+
* Which zone it belongs to (a level name, see world.zone): when not in this zone only the model is torn down and the data stays; null (default) means
|
|
770
|
+
* it is present everywhere
|
|
771
|
+
*/
|
|
772
|
+
zone?: string | null;
|
|
773
|
+
/** Schedule (needs the sky module; without it the first entry is always used) */
|
|
774
|
+
schedule?: ScheduleStop[];
|
|
775
|
+
/** Behavior name: 'schedule' (default, follows the schedule), 'wander' (roams around home) or a name registered with npcs.behavior() */
|
|
776
|
+
behavior?: string;
|
|
777
|
+
/**
|
|
778
|
+
* Behavior parameters and memory (plain values, saved). wander: { radius in meters (8), pause [min, max] seconds ([2, 6]), home { x, z } (defaults to
|
|
779
|
+
* the position when wandering started) }
|
|
780
|
+
*/
|
|
781
|
+
mind?: Record<string, any>;
|
|
782
|
+
/** Dialogue script name (needs the dialogue and interactions modules), triggered by pressing the interact key when close */
|
|
783
|
+
talk?: string | null;
|
|
784
|
+
/** Prompt text (text is stored in the data; a function stays in memory only) */
|
|
785
|
+
talkLabel?: string | (() => string);
|
|
786
|
+
/** Dialogue distance (meters), default 3.2 */
|
|
787
|
+
talkRadius?: number;
|
|
788
|
+
/** Pathfinding grid size (meters), default 2 */
|
|
789
|
+
pathStep?: number;
|
|
790
|
+
/** Seconds before re-pathfinding after getting stuck, default 2 */
|
|
791
|
+
repath?: number;
|
|
792
|
+
/**
|
|
793
|
+
* Arrival distance (meters), default 1.2: within 1.2 m of the schedule stop / target counts as arrived and stops, it does not step exactly on the
|
|
794
|
+
* point (call placeAt yourself for an exact spot)
|
|
795
|
+
*/
|
|
796
|
+
arriveDistance?: number;
|
|
797
|
+
/** Initial position (Vector3 / object / [x, y, z] / { x, z }); the current schedule stop is used if omitted */
|
|
798
|
+
position?: PositionLike;
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* NPC handle (returned by npcs.add): the truth of an NPC is one record of kind 'npc' in engine.world; the model (Character) exists only when nearby.
|
|
802
|
+
* The handle finds the record and the current model by id, so it keeps working after the model is torn down or a load replaces the data.
|
|
803
|
+
*/
|
|
804
|
+
export declare class NPC {
|
|
805
|
+
/** Stable id */
|
|
806
|
+
readonly id: string;
|
|
807
|
+
/** The record in world (a plain object; undefined after deletion). Change fields with engine.world.set(npc.id, {...}) */
|
|
808
|
+
readonly data: WorldRecord | undefined;
|
|
809
|
+
readonly name: string | undefined;
|
|
810
|
+
/** Schedule (at converted to 0–1, sorted by time) */
|
|
811
|
+
readonly schedule: ScheduleEntry[];
|
|
812
|
+
/** Current behavior name */
|
|
813
|
+
readonly behavior: string;
|
|
814
|
+
/** Dialogue id */
|
|
815
|
+
readonly talk: string | null;
|
|
816
|
+
/** Animation state ('idle' / 'walk'...) */
|
|
817
|
+
readonly state: string;
|
|
818
|
+
/** In dialogue (stopped, not walking) */
|
|
819
|
+
readonly busy: boolean;
|
|
820
|
+
/** The current character model: exists only when nearby; null when far away, in another level, or not yet built */
|
|
821
|
+
readonly character: Character | null;
|
|
822
|
+
/** Root object of the current model (= character.root), null when there is no model */
|
|
823
|
+
readonly root: Object3D | null;
|
|
824
|
+
/** Same as root */
|
|
825
|
+
readonly object: Object3D | null;
|
|
826
|
+
/** Position: the model's position when there is a model (use it read-only, move with placeAt), a copy of the record's position when there is none */
|
|
827
|
+
readonly position: Vector3;
|
|
828
|
+
/**
|
|
829
|
+
* Change behavior (stored in the data, restored by saves). mind is the new behavior's parameters / memory (plain values), cleared if omitted. E.g.
|
|
830
|
+
* npc.setBehavior('wander', { radius: 12 })
|
|
831
|
+
*/
|
|
832
|
+
setBehavior(name: string, mind?: Record<string, any>): this;
|
|
833
|
+
/** The stop it should be heading to now */
|
|
834
|
+
currentStop(): ScheduleEntry | null;
|
|
835
|
+
/** Teleport to the ground at a position (handed to the mover when there is a model, otherwise the data is changed) and re-pathfind */
|
|
836
|
+
placeAt(position: PositionLike): this;
|
|
837
|
+
/** Face a position (when there is a model) */
|
|
838
|
+
face(position: PositionLike): this;
|
|
839
|
+
/** Delete this NPC (data and model together) */
|
|
840
|
+
remove(): boolean;
|
|
841
|
+
}
|
|
842
|
+
/** engine.npcs (NPC data lives in engine.world, kind 'npc'; needs the world module) */
|
|
843
|
+
export interface NPCManager {
|
|
844
|
+
/** All NPCs (including far ones and ones in other levels) */
|
|
845
|
+
list(): NPC[];
|
|
846
|
+
/** Add an NPC, returns a handle */
|
|
847
|
+
add(opts: NPCOptions): NPC;
|
|
848
|
+
/**
|
|
849
|
+
* Delete an NPC (pass a handle, id or name): the data is deleted, and the model and dialogue interaction are torn down together. Returns false if not
|
|
850
|
+
* found
|
|
851
|
+
*/
|
|
852
|
+
remove(npc: NPC | string): boolean;
|
|
853
|
+
/**
|
|
854
|
+
* Register an NPC behavior: near(rec, dt, npc) once per fixed step when nearby, far(rec, dt) simulated from the data when far (dt is accumulated
|
|
855
|
+
* seconds); selected through behavior in the data
|
|
856
|
+
*/
|
|
857
|
+
behavior(name: string, impl: { near?: (rec: WorldRecord, dt: number, npc: NPC) => void; far?: (rec: WorldRecord, dt: number) => void }): this;
|
|
858
|
+
/**
|
|
859
|
+
* Nearby NPCs avoid each other (on by default): pushed apart to no less than the sum of their radii, the player counts as an obstacle (NPCs yield to
|
|
860
|
+
* the player), then constrained back to walkable places by engine.collision; deterministic and cheap, with identical results after loading.
|
|
861
|
+
* With nav({ crowd: true }) crowd takes over. Far NPCs (no model) do not avoid one by one. on / radius / strength are the current values.
|
|
862
|
+
* @example engine.npcs.avoid.set({ radius: 0.6, strength: 2 }); // set(false) turns it off
|
|
863
|
+
*/
|
|
864
|
+
readonly avoid: {
|
|
865
|
+
on: boolean;
|
|
866
|
+
/** Avoidance radius of each NPC (meters), null = engine.movement.radius */
|
|
867
|
+
radius: number | null;
|
|
868
|
+
/** Maximum push-apart speed (m/s), default 3 */
|
|
869
|
+
strength: number;
|
|
870
|
+
set(opts: boolean | { on?: boolean; radius?: number | null; strength?: number }): NPCManager['avoid'];
|
|
871
|
+
/**
|
|
872
|
+
* For custom behaviors: call once after character.move and before writing back to the data, to push this NPC away from neighbors and the player
|
|
873
|
+
* (built-in behaviors already call it)
|
|
874
|
+
*/
|
|
875
|
+
push(rec: WorldRecord, character: Character, dt: number): void;
|
|
876
|
+
};
|
|
877
|
+
/** Find by id or name (id first) */
|
|
878
|
+
get(idOrName: string): NPC | undefined;
|
|
879
|
+
/** The current character model of an NPC, null if none */
|
|
880
|
+
character(id: string): Character | null;
|
|
881
|
+
}
|
|
882
|
+
/** engine.characters */
|
|
883
|
+
export interface CharactersApi {
|
|
884
|
+
/**
|
|
885
|
+
* Find a spawn point: searches outward from position (default origin) for walkable (not steep, no obstacle), non-water ground, without assuming
|
|
886
|
+
* terrain height; e.g. findSpawn(v, { minH: 3, maxH: 20 }). Returns a Vector3 (y is the ground height)
|
|
887
|
+
*/
|
|
888
|
+
findSpawn(position?: PositionLike, opts?: FindSpawnOptions): Vector3;
|
|
889
|
+
/**
|
|
890
|
+
* Create the player and set engine.player; control is required (no default feel), e.g. createPlayer({ ...presets.player.thirdPerson, spawn }). An
|
|
891
|
+
* existing player is deleted first
|
|
892
|
+
*/
|
|
893
|
+
createPlayer(opts: PlayerOptions): Character;
|
|
894
|
+
/**
|
|
895
|
+
* The 'camera' player control as a value: keys / stick relative to the camera, the 'run' action if bound, input.autopilot. Reused object; call it
|
|
896
|
+
* inside your own control function to wrap it
|
|
897
|
+
*/
|
|
898
|
+
moveInput(): { x: number; z: number; run: boolean; speed?: number };
|
|
899
|
+
/**
|
|
900
|
+
* Delete the current player (exits the vehicle first, stops responding to keys, fully deletes the model). The player save (key player) carries the
|
|
901
|
+
* position and the vehicle; loading an on-foot save exits the vehicle first
|
|
902
|
+
*/
|
|
903
|
+
removePlayer(): void;
|
|
904
|
+
/**
|
|
905
|
+
* Pathfinding (the single entry point): uses the navmesh when nav is installed and ready, otherwise the A* fallback. Returns a path [{ x, z }...], or
|
|
906
|
+
* null if unreachable
|
|
907
|
+
*/
|
|
908
|
+
findPath(from: PositionLike, to: PositionLike, opts?: FindPathOptions & { detailed?: false }): XZ[] | null;
|
|
909
|
+
/**
|
|
910
|
+
* Pass detailed: true: returns { status, path }, distinguishing 'ok' found | 'noPath' unreachable | 'notReady' nav is installed but the mesh is not
|
|
911
|
+
* built yet (path is the A* fallback result and may be inaccurate)
|
|
912
|
+
*/
|
|
913
|
+
findPath(from: PositionLike, to: PositionLike, opts: FindPathOptions & { detailed: true }): PathResult;
|
|
914
|
+
/**
|
|
915
|
+
* findPath for many callers (NPC crowds, AI squads): solved in engine.threads workers; done(path, status) runs on a fixed step a few steps later (same
|
|
916
|
+
* paths with threads on or off). Recipe 12 section 4
|
|
917
|
+
*/
|
|
918
|
+
findPathAsync(
|
|
919
|
+
from: PositionLike, to: PositionLike, done: (path: XZ[] | null, status: 'ok' | 'noPath' | 'notReady') => void,
|
|
920
|
+
opts?: { radius?: number; step?: number; maxNodes?: number }
|
|
921
|
+
): { remove(): void };
|
|
922
|
+
/** How many findPathAsync requests leave per fixed step (default 32); the rest wait for the next steps */
|
|
923
|
+
pathsPerStep: number;
|
|
924
|
+
}
|
|
925
|
+
/** Return value of findPath(..., { detailed: true }) */
|
|
926
|
+
export interface PathResult { status: 'ok' | 'noPath' | 'notReady'; path: XZ[] | null }
|
|
927
|
+
/**
|
|
928
|
+
* Parameters of findSpawn(): minH/maxH height range (meters, default unlimited), maxSlope maximum slope (default 0.3), waterMargin minimum meters above
|
|
929
|
+
* the water (default 0.5)
|
|
930
|
+
*/
|
|
931
|
+
export interface FindSpawnOptions { minH?: number; maxH?: number; maxSlope?: number; waterMargin?: number }
|
|
932
|
+
export interface CharactersOptions {
|
|
933
|
+
/** Whether to enable NPCs (engine.npcs), default true */
|
|
934
|
+
npcs?: boolean;
|
|
935
|
+
/** Brake key when driving (action brake, registered when rigid is installed), none by default (no brake while driving; one warning names the fix);
|
|
936
|
+
* presets.keys.brake has ['KeyB'] (so it doesn't fight with Space for jump) */
|
|
937
|
+
brakeKeys?: string[];
|
|
938
|
+
/** Gamepad button for braking, none by default; presets.keys.brake has ['PadLT'] */
|
|
939
|
+
brakePad?: string[];
|
|
940
|
+
}
|
|
941
|
+
/** Pathfinding options: step is the grid size (meters, A*), maxNodes the maximum cells searched (A*), radius the character radius (meters) */
|
|
942
|
+
/** radius defaults to engine.movement.radius; for detailed see findPath */
|
|
943
|
+
export interface FindPathOptions { step?: number; maxNodes?: number; radius?: number; detailed?: boolean }
|
|
944
|
+
|
|
945
|
+
// ======================================================================
|
|
946
|
+
// Interactions interactions()
|
|
947
|
+
// ======================================================================
|
|
948
|
+
|
|
949
|
+
export interface InteractionOptions {
|
|
950
|
+
/** Stable id for the op interaction.use { id } (default: the world record id it was built for, else a running number) */
|
|
951
|
+
id?: string;
|
|
952
|
+
/** Prompt text, or a function returning text */
|
|
953
|
+
label?: string | (() => string);
|
|
954
|
+
/** How close the actor must be (meters), default interactions({ radius }) = 2.5 */
|
|
955
|
+
radius?: number;
|
|
956
|
+
/** Key action name, default 'interact' (E key). Give one object a second verb by adding another interaction with another action */
|
|
957
|
+
action?: string;
|
|
958
|
+
/** Called when pressed */
|
|
959
|
+
onUse?: (object: Object3D) => void;
|
|
960
|
+
/**
|
|
961
|
+
* When this returns false the whole prompt disappears (to show a state such as "growing", don't use enabled: have the label function return different
|
|
962
|
+
* text by state and decide in onUse whether it can be used)
|
|
963
|
+
*/
|
|
964
|
+
enabled?: () => boolean;
|
|
965
|
+
/** How high the prompt floats above the object (meters) */
|
|
966
|
+
height?: number;
|
|
967
|
+
}
|
|
968
|
+
/** engine.interactions */
|
|
969
|
+
export interface Interactions {
|
|
970
|
+
action: string;
|
|
971
|
+
/** How high the prompt floats (meters) */
|
|
972
|
+
promptHeight: number;
|
|
973
|
+
/** All interactions */
|
|
974
|
+
items: any[];
|
|
975
|
+
/** Default reach of add() in meters (2.5) */
|
|
976
|
+
radius: number;
|
|
977
|
+
/** How the one in front of the actor is chosen; can be changed at runtime */
|
|
978
|
+
pickMode: InteractionPick;
|
|
979
|
+
/** The interaction the prompt shows right now (null if none) */
|
|
980
|
+
current: any;
|
|
981
|
+
/** One best interaction per key action this frame, for a prompt that lists several keys */
|
|
982
|
+
options: { action: string; id: string; label: string }[];
|
|
983
|
+
/**
|
|
984
|
+
* Add an interaction: passing an object makes it follow the object, passing a position (Vector3 / [x, y, z] / { x, y, z }) makes a fixed point.
|
|
985
|
+
* Returns a handle { remove() }
|
|
986
|
+
*/
|
|
987
|
+
add(target: Object3D | PositionLike, opts?: InteractionOptions): Handle;
|
|
988
|
+
/** The interaction with this id, or null. Using one is the op: engine.ops.run('interaction.use', { id }) (no id = the one the actor would pick) */
|
|
989
|
+
get(id: string): any;
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* What the 'prompt' UI part receives in update(view) every frame while an interaction is in reach (hide() when none). Call use() on click: it runs the
|
|
993
|
+
* op interaction.use.
|
|
994
|
+
* @example engine.ui.set('prompt', (engine) => ({ update: (v) => myLabel.set(v.x, v.y, v.label, v.key), hide: () => myLabel.hide() }))
|
|
995
|
+
*/
|
|
996
|
+
export interface PromptView {
|
|
997
|
+
/** Interaction id */
|
|
998
|
+
id: string;
|
|
999
|
+
/** Action that uses it ('interact') and its key label ('E') */
|
|
1000
|
+
action: string;
|
|
1001
|
+
key: string;
|
|
1002
|
+
/** The interaction's label, and the default text 'E · label' */
|
|
1003
|
+
label: string;
|
|
1004
|
+
text: string;
|
|
1005
|
+
/** Screen pixels above the target */
|
|
1006
|
+
x: number;
|
|
1007
|
+
y: number;
|
|
1008
|
+
onScreen: boolean;
|
|
1009
|
+
/** Use it (the op interaction.use) */
|
|
1010
|
+
use(): void;
|
|
1011
|
+
/** One best interaction per action this frame, for a prompt that lists several keys ("E · 浇水 F · 收获") */
|
|
1012
|
+
options: { action: string; id: string; label: string }[];
|
|
1013
|
+
}
|
|
1014
|
+
/** A candidate handed to a pick function: an enabled interaction within its radius of the actor */
|
|
1015
|
+
export interface InteractionCandidate { id: string; object: Object3D; action: string; label: string | (() => string); distance: number }
|
|
1016
|
+
/**
|
|
1017
|
+
* 'nearest' | 'facing' (within 60° of where the actor faces) | 'aim' (closest to the screen-center ray) | a function choosing one candidate (nearest
|
|
1018
|
+
* first) or null
|
|
1019
|
+
*/
|
|
1020
|
+
export type InteractionPick = 'nearest' | 'facing' | 'aim'
|
|
1021
|
+
| ((candidates: InteractionCandidate[], ctx: { engine: Engine; actor: string; position: Vector3; action?: string }) => InteractionCandidate | null | undefined);
|
|
1022
|
+
export interface InteractionsOptions {
|
|
1023
|
+
/** Default action name, default 'interact' */
|
|
1024
|
+
action?: string;
|
|
1025
|
+
/** How high the prompt floats (meters) */
|
|
1026
|
+
promptHeight?: number;
|
|
1027
|
+
/** Default reach of add() in meters, default 2.5 */
|
|
1028
|
+
radius?: number;
|
|
1029
|
+
/**
|
|
1030
|
+
* Required, no default: how the interaction in front of the actor is chosen. presets.interactions.* fill it. @example interactions({ pick: 'aim',
|
|
1031
|
+
* keys: ['KeyE'], radius: 2 }) // first person
|
|
1032
|
+
*/
|
|
1033
|
+
pick: InteractionPick;
|
|
1034
|
+
/** Keys of the action; required unless the game bound the action already (createEngine({ bindings: { interact: [...] } }) or input.define) */
|
|
1035
|
+
keys?: string[];
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
// ======================================================================
|
|
1039
|
+
// Dialogue dialogue()
|
|
1040
|
+
// ======================================================================
|
|
1041
|
+
|
|
1042
|
+
/** Story state: flags are story flags (this is engine.vars.flags, autosaved) */
|
|
1043
|
+
export interface DialogueState { flags: Record<string, any>; [key: string]: any }
|
|
1044
|
+
/** Dialogue choice */
|
|
1045
|
+
export interface DialogueChoice {
|
|
1046
|
+
/** Choice text */
|
|
1047
|
+
text: string | ((state: DialogueState, engine: Engine) => string);
|
|
1048
|
+
/** Which node to go to after choosing (omit = end) */
|
|
1049
|
+
next?: string;
|
|
1050
|
+
/** Condition: when it returns false this choice is not shown */
|
|
1051
|
+
if?: (state: DialogueState, engine: Engine) => boolean;
|
|
1052
|
+
/** Run after choosing */
|
|
1053
|
+
do?: (state: DialogueState, engine: Engine) => void;
|
|
1054
|
+
/** The game's own fields (icon, tone...): handed to the UI part as choices[i].data. Other unknown keys are reported as typos */
|
|
1055
|
+
data?: Record<string, any>;
|
|
1056
|
+
}
|
|
1057
|
+
/** Dialogue node */
|
|
1058
|
+
export interface DialogueNode {
|
|
1059
|
+
/** Line of dialogue, or a function returning one */
|
|
1060
|
+
text: string | ((state: DialogueState, engine: Engine) => string);
|
|
1061
|
+
/** Change the speaker (the script name by default) */
|
|
1062
|
+
speaker?: string;
|
|
1063
|
+
/** Next node (omit = end; 'end' also means end) */
|
|
1064
|
+
next?: string;
|
|
1065
|
+
/** Choices (next has no effect when there are choices) */
|
|
1066
|
+
choices?: DialogueChoice[];
|
|
1067
|
+
/** Run when this line is shown (change story flags, give items...) */
|
|
1068
|
+
do?: (state: DialogueState, engine: Engine) => void;
|
|
1069
|
+
/**
|
|
1070
|
+
* The game's own fields (portrait, mood, voice clip, camera shot...): handed to the 'dialogue' UI part and the 'dialogue:line' event.
|
|
1071
|
+
* Other unknown keys are reported as typos, so a misspelled next does not silently end the dialogue.
|
|
1072
|
+
* @example { text: 'Hm.', data: { portrait: 'fisher', mood: 'tired', voice: 'fisher_03.mp3' } }
|
|
1073
|
+
*/
|
|
1074
|
+
data?: Record<string, any>;
|
|
1075
|
+
}
|
|
1076
|
+
/** Dialogue script: node name -> node, starting from 'start' */
|
|
1077
|
+
export type DialogueScript = Record<string, DialogueNode>;
|
|
1078
|
+
/** Promise returned by say() (id is a temporary dialogue name) */
|
|
1079
|
+
export interface SayPromise extends Promise<void> { id: string }
|
|
1080
|
+
|
|
1081
|
+
/** engine.dialogue */
|
|
1082
|
+
export interface Dialogue {
|
|
1083
|
+
/** Story state: state.flags is engine.vars.flags (autosaved) */
|
|
1084
|
+
readonly state: DialogueState;
|
|
1085
|
+
/** All scripts */
|
|
1086
|
+
scripts: Map<string, DialogueScript>;
|
|
1087
|
+
/** The dialogue in progress (null when none) */
|
|
1088
|
+
active: { speaker: string; nodes: DialogueScript; node?: DialogueNode; onEnd: (() => void) | null; lock: boolean } | null;
|
|
1089
|
+
/** The script currently speaking */
|
|
1090
|
+
readonly speaking: string | null;
|
|
1091
|
+
/** Typing speed (characters/second) */
|
|
1092
|
+
cps: number;
|
|
1093
|
+
/** Define a dialogue (the name is usually the speaker) */
|
|
1094
|
+
define(speaker: string, nodes: DialogueScript): void;
|
|
1095
|
+
/**
|
|
1096
|
+
* Start a dialogue: from node nodeId (default 'start'), onEnd is called when it ends.
|
|
1097
|
+
* lock (default true) locks game input and takes Esc; lock: false lets the player keep playing (lines move on by themselves) and never cuts into a
|
|
1098
|
+
* locking dialogue.
|
|
1099
|
+
* onCancel: what the back key (Esc) does while this locking dialogue is on top of the UI focus stack (default: nothing).
|
|
1100
|
+
* Ending the playthrough (engine.session newGame / load / quit) closes the dialogue without calling onEnd.
|
|
1101
|
+
* @example engine.dialogue.start('guard', 'start', null, { lock: false })
|
|
1102
|
+
*/
|
|
1103
|
+
start(speaker: string, nodeId?: string, onEnd?: (() => void) | null, opts?: { lock?: boolean; onCancel?: (() => void) | null }): void;
|
|
1104
|
+
/**
|
|
1105
|
+
* Say a one-off line (no need to define first); the Promise resolves when it is done. lock: false = said while the player keeps playing (barks, radio
|
|
1106
|
+
* chatter).
|
|
1107
|
+
* When the playthrough ends (engine.session) the line is dropped and the Promise never resolves, so code awaiting it does not run in the next playthrough.
|
|
1108
|
+
* @example await engine.dialogue.say('Reloading!', { speaker: 'Mira', lock: false })
|
|
1109
|
+
*/
|
|
1110
|
+
say(text: string | DialogueScript, opts?: { speaker?: string; node?: string; lock?: boolean; onCancel?: (() => void) | null }): SayPromise;
|
|
1111
|
+
/** End the current dialogue */
|
|
1112
|
+
end(): void;
|
|
1113
|
+
// Advancing and choosing are ops: engine.ops.run('dialogue.advance') / engine.ops.run('dialogue.choose', { index })
|
|
1114
|
+
// (0-based; while typing it completes the line first)
|
|
1115
|
+
}
|
|
1116
|
+
export interface DialogueOptions {
|
|
1117
|
+
/** Typing speed (characters/second, game time: advanced by engine.step), default 40 */
|
|
1118
|
+
charsPerSecond?: number;
|
|
1119
|
+
/** Actions that advance the dialogue, default ['confirm', 'interact'] (interact only when the game bound it) */
|
|
1120
|
+
advanceActions?: string[];
|
|
1121
|
+
/** Number keys 1-9 pick choices (read only while a locking dialogue runs; rebind them as actions choice1...choice9), false = click / op only. Default true */
|
|
1122
|
+
choiceKeys?: boolean;
|
|
1123
|
+
/** A non-locking line (lock: false) moves on this many seconds after it is fully typed, default 2 */
|
|
1124
|
+
holdSeconds?: number;
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* What the 'dialogue' UI part receives in update(view) (show() comes first, hide() when the dialogue ends). Call advance() / choose(i) from your UI:
|
|
1128
|
+
* they run the ops dialogue.advance / dialogue.choose, so keys, clicks and tests stay one path.
|
|
1129
|
+
* @example
|
|
1130
|
+
* engine.ui.set('dialogue', (engine) => {
|
|
1131
|
+
* const el = document.createElement('div'); engine.uiRoot.appendChild(el); el.hidden = true;
|
|
1132
|
+
* el.onclick = () => view?.advance();
|
|
1133
|
+
* let view = null;
|
|
1134
|
+
* return {
|
|
1135
|
+
* show: () => { el.hidden = false; },
|
|
1136
|
+
* update: (v) => { view = v; el.textContent = `${v.speaker}: ${v.text}`; }, // v.data.portrait, v.choices[i].text ...
|
|
1137
|
+
* hide: () => { el.hidden = true; },
|
|
1138
|
+
* dispose: () => el.remove(),
|
|
1139
|
+
* };
|
|
1140
|
+
* });
|
|
1141
|
+
*/
|
|
1142
|
+
export interface DialogueView {
|
|
1143
|
+
/** Script name (dialogue.define name) */
|
|
1144
|
+
script: string;
|
|
1145
|
+
/** Node id */
|
|
1146
|
+
node: string;
|
|
1147
|
+
/** Who speaks this line */
|
|
1148
|
+
speaker: string;
|
|
1149
|
+
/** The part typed so far (the whole line once typing ends) */
|
|
1150
|
+
text: string;
|
|
1151
|
+
/** The whole line */
|
|
1152
|
+
full: string;
|
|
1153
|
+
/** Still typing (charsPerSecond) */
|
|
1154
|
+
typing: boolean;
|
|
1155
|
+
/** Visible choices once typing ends (empty while typing or without choices); key is the key label ('1') or null */
|
|
1156
|
+
choices: { text: string; key: string | null; data: Record<string, any> }[];
|
|
1157
|
+
/** "E to continue" text when the line waits for the player, else '' */
|
|
1158
|
+
hint: string;
|
|
1159
|
+
/** The node's data (the game's own fields), {} when none */
|
|
1160
|
+
data: Record<string, any>;
|
|
1161
|
+
/** false for a line said while the player keeps playing */
|
|
1162
|
+
lock: boolean;
|
|
1163
|
+
/** Run the op dialogue.advance (finish typing / next line) */
|
|
1164
|
+
advance(): any;
|
|
1165
|
+
/** Run the op dialogue.choose { index } (0-based among choices) */
|
|
1166
|
+
choose(index: number): any;
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
// ======================================================================
|
|
1170
|
+
// Inventory inventory()
|
|
1171
|
+
// ======================================================================
|
|
1172
|
+
|
|
1173
|
+
/** Item definition */
|
|
1174
|
+
export interface ItemDef {
|
|
1175
|
+
/** Display name */
|
|
1176
|
+
name?: string;
|
|
1177
|
+
/** Icon (text or emoji) */
|
|
1178
|
+
icon?: string;
|
|
1179
|
+
/** Icon image path */
|
|
1180
|
+
iconUrl?: string;
|
|
1181
|
+
/** Description */
|
|
1182
|
+
desc?: string;
|
|
1183
|
+
/** Pieces per slot, default 99 (an entry of 150 uses 2 slots); 1 = every piece with data is its own entry */
|
|
1184
|
+
stack?: number;
|
|
1185
|
+
/** Weight of one piece, counted against a container's maxWeight (default 0) */
|
|
1186
|
+
weight?: number;
|
|
1187
|
+
/** Makes the item usable with the inventory.use op */
|
|
1188
|
+
use?: (e: any, info: ItemUseEvent) => void;
|
|
1189
|
+
/** Whether it can be used now: true or a reason string (checked by the op's can) */
|
|
1190
|
+
canUse?: (e: any, info: ItemUseEvent) => true | string;
|
|
1191
|
+
/** inventory.use removes one piece before calling use */
|
|
1192
|
+
consume?: boolean;
|
|
1193
|
+
/** Color of the pickup on the ground */
|
|
1194
|
+
color?: ColorLike;
|
|
1195
|
+
[key: string]: any;
|
|
1196
|
+
}
|
|
1197
|
+
/** id = item id, key = entry key ('arrow', or 'sword#3' for a piece with data), count = change, total = how many of the item now */
|
|
1198
|
+
export interface ItemEvent { id: string; key: string; count: number; total: number }
|
|
1199
|
+
/** inventory.use: who used which entry (data = that piece's data) */
|
|
1200
|
+
export interface ItemUseEvent { actor: string; item: string; key: string; data?: Record<string, any> }
|
|
1201
|
+
/** One entry of a container: plain items share one entry per kind (key = item id); items with data have their own key ('sword#3') */
|
|
1202
|
+
export interface ItemEntry { key: string; id: string; count: number; data?: Readonly<Record<string, any>>; def: ItemDef }
|
|
1203
|
+
/** Change in a non-player container (the player inventory emits item:add / item:remove): container is the container id */
|
|
1204
|
+
export interface ContainerEvent extends ItemEvent { container: string }
|
|
1205
|
+
export interface PickupEvent { id: string; x: number; z: number }
|
|
1206
|
+
/**
|
|
1207
|
+
* Handle returned by spawnPickup(): id is the item, worldId is the id of this record in engine.world, object is the current model (null when far away);
|
|
1208
|
+
* remove() deletes the pickup (data and model; a model passed in through opts.mesh is only taken off)
|
|
1209
|
+
*/
|
|
1210
|
+
export interface PickupHandle extends Handle { id: string; worldId: string; readonly object: Object3D | null }
|
|
1211
|
+
/** Parameters of spawnPickup() */
|
|
1212
|
+
export interface PickupOptions {
|
|
1213
|
+
/**
|
|
1214
|
+
* Stable id of this record in world (saves recognize it by this); numbered automatically pickup#1... if omitted, and an existing record with the same
|
|
1215
|
+
* id is reused
|
|
1216
|
+
*/
|
|
1217
|
+
id?: string;
|
|
1218
|
+
/** How many you get when picking up, default 1 */
|
|
1219
|
+
count?: number;
|
|
1220
|
+
/** The piece's own data (a dropped sword keeps its durability) */
|
|
1221
|
+
data?: Record<string, any>;
|
|
1222
|
+
/** Reach in meters, default inventory pickupRadius (2) */
|
|
1223
|
+
radius?: number;
|
|
1224
|
+
/** Taken by walking into it (no key press, no prompt) */
|
|
1225
|
+
auto?: boolean;
|
|
1226
|
+
/** Custom model (the style pack's style.pickup is used if omitted) */
|
|
1227
|
+
mesh?: Object3D | null;
|
|
1228
|
+
/** Game seconds until it reappears, 0 = never reappears */
|
|
1229
|
+
respawnSeconds?: number;
|
|
1230
|
+
/** Bob up and down and rotate, default true */
|
|
1231
|
+
bob?: boolean;
|
|
1232
|
+
/**
|
|
1233
|
+
* Pickup authored in content (needs an id): the initial record of world; saves record only being picked up / waiting to respawn, with identical
|
|
1234
|
+
* results whether the load comes before or after this spawn
|
|
1235
|
+
*/
|
|
1236
|
+
initial?: boolean;
|
|
1237
|
+
/** Which zone it belongs to (a level name, see world.zone): the data stays across level changes (a picked-up one stays picked up) */
|
|
1238
|
+
zone?: string | null;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
/**
|
|
1242
|
+
* Container (inventory, chest, corpse, shelf): inventory.container(id, opts) gets or creates one; the player inventory is the one with id 'player'.
|
|
1243
|
+
* Every x is an item id or an entry key
|
|
1244
|
+
*/
|
|
1245
|
+
export interface Container {
|
|
1246
|
+
readonly id: string;
|
|
1247
|
+
/** Slot limit, default Infinity */
|
|
1248
|
+
capacity: number;
|
|
1249
|
+
/** Weight limit (item weight × count), default Infinity */
|
|
1250
|
+
maxWeight: number;
|
|
1251
|
+
/** How many of an item, or of one entry key */
|
|
1252
|
+
count(x: string): number;
|
|
1253
|
+
/** Whether there are at least n (default 1) */
|
|
1254
|
+
has(x: string, n?: number): boolean;
|
|
1255
|
+
/** One entry by key, or null */
|
|
1256
|
+
get(key: string): ItemEntry | null;
|
|
1257
|
+
/** Slots used */
|
|
1258
|
+
readonly slotsUsed: number;
|
|
1259
|
+
/** Total weight */
|
|
1260
|
+
readonly weight: number;
|
|
1261
|
+
/** Every entry (for custom UI) */
|
|
1262
|
+
list(): ItemEntry[];
|
|
1263
|
+
/** How many more fit (Infinity = no limit), for an item without data, with this data, or like an existing entry key */
|
|
1264
|
+
room(x: string, data?: Record<string, any>): number;
|
|
1265
|
+
/** Add n (default 1), optionally with data; returns the entry key, false if none fit; silent suppresses the toast (only the player inventory shows one) */
|
|
1266
|
+
add(id: string, n?: number, opts?: { data?: Record<string, any>; silent?: boolean }): string | false;
|
|
1267
|
+
/** Remove n (default 1) of an item or entry key, returns false if there are not enough */
|
|
1268
|
+
remove(x: string, n?: number): boolean;
|
|
1269
|
+
/**
|
|
1270
|
+
* Atomic trade: take A (id or entry key) and give B in one all-or-nothing step; reason 'notEnough' | 'full'. Ops: inventory.trade, engine.ops.undo
|
|
1271
|
+
* reverses it
|
|
1272
|
+
*/
|
|
1273
|
+
trade(
|
|
1274
|
+
take: string, give: string, opts?: { takeN?: number; giveN?: number; data?: Record<string, any>; silent?: boolean }
|
|
1275
|
+
): { ok: boolean; reason?: string; took?: { id: string; count: number; data?: any }[]; gave?: string; giveId?: string; giveN?: number };
|
|
1276
|
+
/** Replace an entry's data (null = none) for n pieces (default all); returns the key now holding them */
|
|
1277
|
+
setData(key: string, data: Record<string, any> | null, n?: number): string;
|
|
1278
|
+
/** Listen for changes of this container, returns a handle */
|
|
1279
|
+
on(type: 'add' | 'remove', fn: (e: ItemEvent) => void): Handle;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
/** engine.inventory */
|
|
1283
|
+
export interface Inventory {
|
|
1284
|
+
/** true: gameplay freezes while the inventory window is open (set from inventory({ pauseGame }) or at runtime) */
|
|
1285
|
+
pauseGame: boolean;
|
|
1286
|
+
/** Item definitions */
|
|
1287
|
+
defs: Map<string, ItemDef>;
|
|
1288
|
+
/** Slot limit of the player inventory */
|
|
1289
|
+
capacity: number;
|
|
1290
|
+
/** Player inventory (= container('player')) */
|
|
1291
|
+
readonly bag: Container;
|
|
1292
|
+
defaultStack: number;
|
|
1293
|
+
/** Reach of pickups that do not set their own (meters) */
|
|
1294
|
+
pickupRadius: number;
|
|
1295
|
+
action: string;
|
|
1296
|
+
/** Define an item (chainable) */
|
|
1297
|
+
define(id: string, def: ItemDef): this;
|
|
1298
|
+
/** Get an item definition */
|
|
1299
|
+
item(id: string): ItemDef;
|
|
1300
|
+
/** How many of an item, or of one entry key */
|
|
1301
|
+
count(x: string): number;
|
|
1302
|
+
/** Whether there are at least n (default 1) */
|
|
1303
|
+
has(x: string, n?: number): boolean;
|
|
1304
|
+
/** Slots used */
|
|
1305
|
+
readonly slotsUsed: number;
|
|
1306
|
+
/** Player inventory entries (for custom UI) */
|
|
1307
|
+
list(): ItemEntry[];
|
|
1308
|
+
/** One player inventory entry by key, or null */
|
|
1309
|
+
get(key: string): ItemEntry | null;
|
|
1310
|
+
/** Add n to the player inventory (default 1), opts { data, silent }; returns the entry key, false if it does not fit */
|
|
1311
|
+
add(id: string, n?: number, opts?: { data?: Record<string, any>; silent?: boolean }): string | false;
|
|
1312
|
+
/** Remove n (default 1) of an item or entry key, returns false if there are not enough */
|
|
1313
|
+
remove(x: string, n?: number): boolean;
|
|
1314
|
+
/**
|
|
1315
|
+
* Atomic trade: take A (id or entry key) and give B in one all-or-nothing step; reason 'notEnough' | 'full'. Ops: inventory.trade, engine.ops.undo
|
|
1316
|
+
* reverses it
|
|
1317
|
+
*/
|
|
1318
|
+
trade(
|
|
1319
|
+
take: string, give: string, opts?: { takeN?: number; giveN?: number; data?: Record<string, any>; silent?: boolean }
|
|
1320
|
+
): { ok: boolean; reason?: string; took?: { id: string; count: number; data?: any }[]; gave?: string; giveId?: string; giveN?: number };
|
|
1321
|
+
/** Replace a player inventory entry's data for n pieces (default all); returns the key now holding them */
|
|
1322
|
+
setData(key: string, data: Record<string, any> | null, n?: number): string;
|
|
1323
|
+
/**
|
|
1324
|
+
* Get or create a container (chest, corpse, shelf...); the id can be the id of a world record, and the contents are saved. A second call returns the
|
|
1325
|
+
* same one; deleting the world record does not delete the container automatically
|
|
1326
|
+
*/
|
|
1327
|
+
container(id: string, opts?: { capacity?: number; maxWeight?: number; items?: Record<string, number> }): Container;
|
|
1328
|
+
/**
|
|
1329
|
+
* Move n (default 1) of an item or one entry key between containers (pieces keep data and key); moves fewer if the target cannot hold them all,
|
|
1330
|
+
* returns how many were actually moved
|
|
1331
|
+
*/
|
|
1332
|
+
transfer(from: Container | string, to: Container | string, item: string, n?: number): number;
|
|
1333
|
+
/** Delete a container together with its contents ('player' cannot be deleted), returns whether one was deleted */
|
|
1334
|
+
removeContainer(id: string): boolean;
|
|
1335
|
+
/**
|
|
1336
|
+
* Place a pickup on the ground at position; its y, if any, is the reference height on multi-layer ground (needs the interactions module unless auto):
|
|
1337
|
+
* spawnPickup('berry', v, { count: 2 }). Returns a handle, remove() deletes it
|
|
1338
|
+
*/
|
|
1339
|
+
spawnPickup(id: string, position: PositionLike, opts?: PickupOptions): PickupHandle;
|
|
1340
|
+
/** The data of the nearest pickup of an item still on the ground to from (default the player) (a world record of kind 'pickup'), null if none */
|
|
1341
|
+
nearestPickup(id: string, from?: PositionLike): WorldRecord | null;
|
|
1342
|
+
}
|
|
1343
|
+
export interface InventoryOptions {
|
|
1344
|
+
/** Action name that opens the inventory, default 'inventory' */
|
|
1345
|
+
action?: string;
|
|
1346
|
+
/** Keys that open the bag: required unless createEngine({ bindings }) binds the action ([] = no key); presets.keys.inventory has ['KeyI'] */
|
|
1347
|
+
keys?: string[];
|
|
1348
|
+
/** Gamepad button, none by default; presets.keys.inventory has ['PadY'] */
|
|
1349
|
+
pad?: string[];
|
|
1350
|
+
/** true: gameplay freezes (engine.freeze) while the inventory window is open, default false. Also settable at runtime: engine.inventory.pauseGame */
|
|
1351
|
+
pauseGame?: boolean;
|
|
1352
|
+
/** Pickups float and spin only within this distance (meters) of the focus, default 60 */
|
|
1353
|
+
bobDistance?: number;
|
|
1354
|
+
/** Slot limit of the player inventory, default Infinity (no limit) */
|
|
1355
|
+
capacity?: number;
|
|
1356
|
+
/** Weight limit of the player inventory, default Infinity */
|
|
1357
|
+
maxWeight?: number;
|
|
1358
|
+
/** Reach of pickups that do not set their own radius (meters), default 2 */
|
|
1359
|
+
pickupRadius?: number;
|
|
1360
|
+
/** Default stack limit, default 99 */
|
|
1361
|
+
defaultStack?: number;
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
// ======================================================================
|
|
1365
|
+
// Quests quests()
|
|
1366
|
+
// ======================================================================
|
|
1367
|
+
|
|
1368
|
+
/**
|
|
1369
|
+
* One quest step: text is the displayed text, done the completion condition (checked every half second), target the objective (a marker is shown when
|
|
1370
|
+
* hud is installed)
|
|
1371
|
+
*/
|
|
1372
|
+
export interface QuestStep {
|
|
1373
|
+
/** Stable id: saves store progress by it, so steps can be inserted or reordered later (default: the step's position) */
|
|
1374
|
+
id?: string;
|
|
1375
|
+
text: string;
|
|
1376
|
+
done: (e: Engine) => boolean;
|
|
1377
|
+
/**
|
|
1378
|
+
* Objective: a place name (content.place), object, character, { x, z }, { nearest: itemId } or a function returning an objective; with the hud module
|
|
1379
|
+
* the current step shows a marker automatically
|
|
1380
|
+
*/
|
|
1381
|
+
target?: HudTarget;
|
|
1382
|
+
}
|
|
1383
|
+
/** One goal of a parallel step; optional goals do not hold the step back */
|
|
1384
|
+
export interface QuestPart { /** Stable id within the step (default: its position) */ id?: string; text: string; done: (e: Engine) => boolean; target?: HudTarget; optional?: boolean }
|
|
1385
|
+
/** Parallel goals: done when every non-optional part is done, in any order; text defaults to the required parts joined */
|
|
1386
|
+
export interface QuestParallelStep { /** Stable id (default: the step's position) */ id?: string; text?: string; all: QuestPart[] }
|
|
1387
|
+
/** Quest definition */
|
|
1388
|
+
export interface QuestDef {
|
|
1389
|
+
/** Title */
|
|
1390
|
+
title: string;
|
|
1391
|
+
/** Description */
|
|
1392
|
+
desc?: string;
|
|
1393
|
+
/** Steps (completed in order); a step may be parallel goals { all: [...] } */
|
|
1394
|
+
steps: (QuestStep | QuestParallelStep)[];
|
|
1395
|
+
/** Called on completion (give rewards) */
|
|
1396
|
+
reward?: (e: Engine) => void;
|
|
1397
|
+
/** Checked while active; true fails the quest (quest:fail; start(id) can begin it again). @example fail: e => e.vars.flag('caravanLost') */
|
|
1398
|
+
fail?: (e: Engine) => boolean;
|
|
1399
|
+
/** Called when the quest fails */
|
|
1400
|
+
onFail?: (e: Engine) => void;
|
|
1401
|
+
}
|
|
1402
|
+
/** engine.quests */
|
|
1403
|
+
export interface Quests {
|
|
1404
|
+
defs: Map<string, QuestDef>;
|
|
1405
|
+
/** Quests in progress / completed / failed: id -> { step (current step), done, failed?, parts? } */
|
|
1406
|
+
state: Record<string, { step: number; done: boolean; failed?: boolean; parts?: boolean[] }>;
|
|
1407
|
+
/** The quest log (UI part 'questLog'): open, toggle(on?), refresh() */
|
|
1408
|
+
win: { readonly open: boolean; toggle(on?: boolean): void; refresh(): void };
|
|
1409
|
+
/** Define a quest (chainable) */
|
|
1410
|
+
define(id: string, def: QuestDef): this;
|
|
1411
|
+
/** Start a quest */
|
|
1412
|
+
start(id: string): void;
|
|
1413
|
+
isDone(id: string): boolean;
|
|
1414
|
+
/** Started, not done and not failed */
|
|
1415
|
+
isActive(id: string): boolean;
|
|
1416
|
+
/** Its fail condition held (start(id) begins it again) */
|
|
1417
|
+
isFailed(id: string): boolean;
|
|
1418
|
+
/** Check completion conditions once immediately */
|
|
1419
|
+
check(): void;
|
|
1420
|
+
/** Quest list (for custom UI) */
|
|
1421
|
+
list(): { id: string; title: string; desc?: string; done: boolean; failed: boolean;
|
|
1422
|
+
steps: { text: string; target?: HudTarget; done: boolean; current: boolean; parts?: { text: string; target?: HudTarget; optional: boolean; done: boolean }[] }[] }[];
|
|
1423
|
+
}
|
|
1424
|
+
/**
|
|
1425
|
+
* What the 'questLog' UI part receives in show(view) / update(view) (hide() when it closes). The engine opens it on the quest key, pushes the UI focus stack
|
|
1426
|
+
* (Esc calls close), locks gameplay input and calls update again when quests change while it is open.
|
|
1427
|
+
* @example
|
|
1428
|
+
* engine.ui.set('questLog', (engine) => {
|
|
1429
|
+
* const el = document.createElement('div'); engine.uiRoot.appendChild(el); el.hidden = true;
|
|
1430
|
+
* const draw = (v) => { el.hidden = false; el.innerHTML = v.quests.map(q => `<p>${q.title}: ${q.steps.find(s => s.current)?.text ??
|
|
1431
|
+
* 'done'}</p>`).join(''); el.onclick = v.close; };
|
|
1432
|
+
* return { show: draw, update: draw, hide: () => { el.hidden = true; }, dispose: () => el.remove() };
|
|
1433
|
+
* });
|
|
1434
|
+
*/
|
|
1435
|
+
export interface QuestLogView {
|
|
1436
|
+
/** Window title (localized) */
|
|
1437
|
+
title: string;
|
|
1438
|
+
/** Label of the key that toggles the log, e.g. 'J' */
|
|
1439
|
+
key: string;
|
|
1440
|
+
/** Same as engine.quests.list(): unfinished first */
|
|
1441
|
+
quests: ReturnType<Quests['list']>;
|
|
1442
|
+
/** Close the log (same as Esc or the quest key) */
|
|
1443
|
+
close(): void;
|
|
1444
|
+
}
|
|
1445
|
+
export interface QuestsOptions {
|
|
1446
|
+
/** Action name that opens the quest log, default 'quests' */
|
|
1447
|
+
action?: string;
|
|
1448
|
+
/** Keys that open the quest log: required unless createEngine({ bindings }) binds the action ([] = no key); presets.keys.quests has ['KeyJ'] */
|
|
1449
|
+
keys?: string[];
|
|
1450
|
+
/** Gamepad button, none by default; presets.keys.quests has ['PadSelect'] */
|
|
1451
|
+
pad?: string[];
|
|
1452
|
+
/** Check interval (game seconds, checked in the fixed step; not checked while frozen / paused), default 0.5 */
|
|
1453
|
+
checkInterval?: number;
|
|
1454
|
+
/**
|
|
1455
|
+
* Messages on quest start / step / done: true a toast with kind 'quest' (default) · false none · a function to show them your way.
|
|
1456
|
+
* @example quests({ notify: false }) quests({ notify: ({ type, text }) => type === 'done' && myBanner(text) })
|
|
1457
|
+
*/
|
|
1458
|
+
notify?: boolean | ((msg: { type: 'start' | 'step' | 'done'; id: string; text: string }) => void);
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
// ======================================================================
|
|
1462
|
+
// Photo mode photo()
|
|
1463
|
+
// ======================================================================
|
|
1464
|
+
|
|
1465
|
+
/** A photo: url is the image data, time the clock time it was taken (e.g. "18:00"), position where it was taken */
|
|
1466
|
+
export interface PhotoShot {
|
|
1467
|
+
/**
|
|
1468
|
+
* Id of the photo in storage (available right after taking it; photos are stored separately as Blobs in IndexedDB and the album is read back on the
|
|
1469
|
+
* next start, url is a blob: address)
|
|
1470
|
+
*/
|
|
1471
|
+
id?: string;
|
|
1472
|
+
url: string; time: string; position: XZ | null;
|
|
1473
|
+
/** What was in the middle of the frame: name is the name, kind the kind (npc, entity, vegetation...), distance in meters */
|
|
1474
|
+
subject?: { name: string; kind: string; distance: number } | null;
|
|
1475
|
+
}
|
|
1476
|
+
export interface PhotoTakeOptions {
|
|
1477
|
+
/** Resolution multiplier, default 1.6 */
|
|
1478
|
+
scale?: number;
|
|
1479
|
+
/** Shadow resolution (pixels), default 4096 */
|
|
1480
|
+
shadowMapSize?: number;
|
|
1481
|
+
/** Turn bloom on when taking a photo */
|
|
1482
|
+
bloom?: boolean;
|
|
1483
|
+
/** Image quality 0–1 */
|
|
1484
|
+
quality?: number;
|
|
1485
|
+
/** Image format, e.g. 'image/jpeg' */
|
|
1486
|
+
format?: string;
|
|
1487
|
+
}
|
|
1488
|
+
export interface PhotoOptions extends PhotoTakeOptions {
|
|
1489
|
+
/** Photo key: required unless createEngine({ bindings }) binds 'photo' ([] = no key); presets.keys.photo has ['KeyP'] */
|
|
1490
|
+
keys?: string[];
|
|
1491
|
+
/** Gamepad button for taking a photo, none by default; presets.keys.photo has ['PadRB'] */
|
|
1492
|
+
pad?: string[];
|
|
1493
|
+
/** How many photos the album keeps at most, default 50 */
|
|
1494
|
+
maxAlbum?: number;
|
|
1495
|
+
}
|
|
1496
|
+
/** engine.photo */
|
|
1497
|
+
export interface Photo {
|
|
1498
|
+
/** Album (newest first) */
|
|
1499
|
+
album: PhotoShot[];
|
|
1500
|
+
/** The op photo.take's can: return true, or false / a reason string to refuse (e.g. () => engine.inventory.has('film') || 'noFilm') */
|
|
1501
|
+
canTake: () => boolean | string;
|
|
1502
|
+
scale: number; shadowMapSize: number; bloom: boolean; quality: number; format: string; maxAlbum: number;
|
|
1503
|
+
/** Capture a photo now without checks. Gameplay takes photos through the op: engine.ops.run('photo.take') (checks canTake, logged) */
|
|
1504
|
+
take(opts?: PhotoTakeOptions): PhotoShot;
|
|
1505
|
+
/** What is in the middle of the frame (NPC, entity, named object, vegetation), null if nothing; this is the subject of take() */
|
|
1506
|
+
subject(): { name: string; kind: string; distance: number } | null;
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
// ======================================================================
|
|
1510
|
+
// Ambience ambience(), debug debug()
|
|
1511
|
+
// ======================================================================
|
|
1512
|
+
|
|
1513
|
+
// Ambience (engine.ambience) is generated from the JSDoc in modules/ambience/Ambience.js (npm run map); only the type is re-exported here
|
|
1514
|
+
import type { Ambience } from './generated/modules/ambience/Ambience';
|
|
1515
|
+
export type { Ambience };
|
|
1516
|
+
/** ambience() options: rules (the rule table; added after createEngine({ audio: { ambience } })), interval seconds between rule checks (0.25) */
|
|
1517
|
+
export interface AmbienceOptions { rules?: import('./core').AmbienceRule[]; interval?: number }
|
|
1518
|
+
// DebugPanel (engine.debug) is generated from the JSDoc in modules/debug/DebugPanel.js (npm run map); only the type is re-exported here
|
|
1519
|
+
import type { DebugPanel } from './generated/modules/debug/DebugPanel';
|
|
1520
|
+
export type { DebugPanel };
|
|
1521
|
+
|
|
1522
|
+
// ======================================================================
|
|
1523
|
+
// UI
|
|
1524
|
+
// ======================================================================
|
|
1525
|
+
|
|
1526
|
+
/** Window returned by makeWindow() */
|
|
1527
|
+
export interface UIWindow {
|
|
1528
|
+
el: HTMLElement;
|
|
1529
|
+
/** Whether it is open */
|
|
1530
|
+
readonly open: boolean;
|
|
1531
|
+
/** Redraw the content */
|
|
1532
|
+
refresh(): void;
|
|
1533
|
+
/** Open / close (toggle if no argument is passed) */
|
|
1534
|
+
toggle(on?: boolean): void;
|
|
1535
|
+
}
|
|
1536
|
+
/** Parameters of makeWindow() */
|
|
1537
|
+
export interface WindowOptions {
|
|
1538
|
+
/** Window name (also the style pack's template name) */
|
|
1539
|
+
id: string;
|
|
1540
|
+
/** Title */
|
|
1541
|
+
title: () => string;
|
|
1542
|
+
/** Action name that toggles it (shows the key hint) */
|
|
1543
|
+
hintAction?: string;
|
|
1544
|
+
/** Default content: (data, tools) => HTML */
|
|
1545
|
+
render: (data: any, tools: { esc: (s: any) => string; t: (key: string, params?: Record<string, any>) => string; icon: (def: any) => string }) => string;
|
|
1546
|
+
/** Template data */
|
|
1547
|
+
data?: () => any;
|
|
1548
|
+
/** What to do on the back key (Esc), default closes the window (an open window is on the UI focus stack, and Esc goes only to the topmost) */
|
|
1549
|
+
onCancel?: () => void;
|
|
1550
|
+
}
|
|
1551
|
+
/** An entry of the UI focus stack (returned by uiFocus(engine).push) */
|
|
1552
|
+
export interface FocusHandle extends Handle {
|
|
1553
|
+
id: string;
|
|
1554
|
+
/** Called on the back key; null = swallow the back key */
|
|
1555
|
+
cancel: (() => void) | null;
|
|
1556
|
+
/** Just pushed this frame (the key press that opened it must not count as its own action) */
|
|
1557
|
+
readonly fresh: boolean;
|
|
1558
|
+
}
|
|
1559
|
+
/**
|
|
1560
|
+
* UI focus stack: windows, dialogue, cutscenes and the settings menu are pushed in the order they open, and the back key (action cancel) goes only to
|
|
1561
|
+
* the top; when the stack is empty it goes to the one registered by setRoot (the settings menu)
|
|
1562
|
+
*/
|
|
1563
|
+
export interface UIFocus {
|
|
1564
|
+
/** Name of the top, null for an empty stack */
|
|
1565
|
+
readonly top: string | null;
|
|
1566
|
+
/** Names from bottom to top */
|
|
1567
|
+
list(): string[];
|
|
1568
|
+
/** Push; without cancel = swallow the back key */
|
|
1569
|
+
push(id: string, opts?: { cancel?: (() => void) | null }): FocusHandle;
|
|
1570
|
+
/** What to do on the back key when the stack is empty (only one, a later registration replaces it) */
|
|
1571
|
+
setRoot(fn: () => void): Handle;
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
|
|
1575
|
+
// ======================================================================
|
|
1576
|
+
// Game clock engine.clock, story variables engine.vars (core)
|
|
1577
|
+
// ======================================================================
|
|
1578
|
+
|
|
1579
|
+
/**
|
|
1580
|
+
* engine.clock: game seconds and "after how long / every how long". Clock-time / season timers are on engine.sky (at / between / daily / onSeason). All
|
|
1581
|
+
* timers return a handle { remove() }
|
|
1582
|
+
*/
|
|
1583
|
+
export interface Clock {
|
|
1584
|
+
/**
|
|
1585
|
+
* Game seconds = fixed-step seconds x clock.timeScale (the time scale is 1 without sky), does not advance while paused / frozen, saved with the game;
|
|
1586
|
+
* one sky day = sky.dayLength game seconds
|
|
1587
|
+
*/
|
|
1588
|
+
now: number;
|
|
1589
|
+
/**
|
|
1590
|
+
* Game-time speed: game seconds per fixed-step second (default 1; the sky's time of day follows it). `engine.clock.timeScale = 60` makes a minute pass
|
|
1591
|
+
* per second
|
|
1592
|
+
*/
|
|
1593
|
+
timeScale: number;
|
|
1594
|
+
/** Call fn after seconds game seconds; if an event name is passed, the event is emitted when due (with data, can be saved) */
|
|
1595
|
+
after(seconds: number, fnOrEvent: (() => void) | string, data?: any): Handle;
|
|
1596
|
+
/** Call once every seconds game seconds */
|
|
1597
|
+
every(seconds: number, fn: () => void): Handle;
|
|
1598
|
+
}
|
|
1599
|
+
/** engine.vars: story flags and counters (autosaved) */
|
|
1600
|
+
export interface Vars {
|
|
1601
|
+
/** All flags */
|
|
1602
|
+
flags: Record<string, any>;
|
|
1603
|
+
/** All counters */
|
|
1604
|
+
counters: Record<string, number>;
|
|
1605
|
+
/** Read a flag */
|
|
1606
|
+
flag(key: string): any;
|
|
1607
|
+
/** Set a flag (default true) */
|
|
1608
|
+
setFlag(key: string, value?: any): void;
|
|
1609
|
+
/** Read a counter (0 if none) */
|
|
1610
|
+
counter(key: string): number;
|
|
1611
|
+
/** Counter +n (default 1), returns the new value */
|
|
1612
|
+
bump(key: string, n?: number): number;
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
// ======================================================================
|
|
1616
|
+
// Content content()
|
|
1617
|
+
// ======================================================================
|
|
1618
|
+
|
|
1619
|
+
/** How a vocabulary value is written (the validator checks by it, the loader converts by it): clock receives a 0–1 ratio, position receives { x, z } */
|
|
1620
|
+
export type ContentRef = 'flag' | 'counter' | 'itemCounts' | 'counterCounts' | 'quest' | 'text' | 'particles' | 'clock' | 'position' | 'any' | (string & {});
|
|
1621
|
+
/** Custom condition: test(e, value) says whether it holds; ref/desc/describe are for the validator and the game map */
|
|
1622
|
+
export interface ContentConditionDef {
|
|
1623
|
+
/** How the value is written, e.g. 'clock' */
|
|
1624
|
+
ref?: ContentRef;
|
|
1625
|
+
/** One-line description */
|
|
1626
|
+
desc?: string;
|
|
1627
|
+
/** Whether it holds: value is the value converted by ref, raw is the form written in the content */
|
|
1628
|
+
test(e: Engine, value: any, raw?: any): boolean;
|
|
1629
|
+
/** Write the value as human-readable text (for the game map) */
|
|
1630
|
+
describe?(value: any): string;
|
|
1631
|
+
}
|
|
1632
|
+
/** Parameters of content.load(): places is place name -> position. Models are asset names (engine.assets.manifest / an asset pack), not an option */
|
|
1633
|
+
export interface ContentLoadOptions { places?: Record<string, PositionLike> }
|
|
1634
|
+
/** A content pack: the object of content/index.js, or a folder / npm package exporting the same tables. Data only: it names assets, never paths or code */
|
|
1635
|
+
export type ContentPack = Record<string, any> & { name?: string; audio?: import('./core').ContentAudio };
|
|
1636
|
+
/**
|
|
1637
|
+
* Prop (each item of content/props.js): model name (an asset name from engine.assets.manifest / an asset pack, never a path; write an array to pass
|
|
1638
|
+
* parameters), position, heading (radians), collision
|
|
1639
|
+
*/
|
|
1640
|
+
export interface PropDef {
|
|
1641
|
+
/**
|
|
1642
|
+
* Stable id (saves recognize it by this); if omitted it is `prop:<model name>:<index in the props array>`. Inserting in the middle of the array shifts
|
|
1643
|
+
* the later indices, so write an id for content that will change
|
|
1644
|
+
*/
|
|
1645
|
+
id?: string;
|
|
1646
|
+
model: string | any[];
|
|
1647
|
+
place?: string; x?: number; z?: number;
|
|
1648
|
+
/** Height above the ground (meters) */
|
|
1649
|
+
y?: number;
|
|
1650
|
+
/** Rotation about the Y axis (radians) */
|
|
1651
|
+
rot?: number;
|
|
1652
|
+
scale?: number;
|
|
1653
|
+
/** Collision: 'box' cuboid, 'circle' cylinder, false none (default) */
|
|
1654
|
+
collide?: 'box' | 'circle' | false;
|
|
1655
|
+
/** Register for ray acceleration (engine.raycast can hit it), default true */
|
|
1656
|
+
static?: boolean;
|
|
1657
|
+
/** false: never drawn through engine.batching (default: repeated props batch automatically) */
|
|
1658
|
+
batch?: boolean;
|
|
1659
|
+
}
|
|
1660
|
+
/** engine.content: loads the plain data of the game's content/*.js into the engine */
|
|
1661
|
+
export interface Content {
|
|
1662
|
+
/** All vegetation models are fetched and the models of world data such as nearby props are built (world.ready) */
|
|
1663
|
+
readonly ready: boolean;
|
|
1664
|
+
/** Markers added by the marker effect: id -> marker */
|
|
1665
|
+
markers: Map<string, HudMarker | undefined>;
|
|
1666
|
+
/**
|
|
1667
|
+
* Load content (items, pickups, vegetation, NPCs, dialogue, quests, keys, trigger zones, props, the game vocabulary rules): one pack, or a list of packs
|
|
1668
|
+
* loaded together in order; an id defined by two packs of one call is an error naming both (a later separate load overrides by name instead)
|
|
1669
|
+
* @example engine.content.load([baseContent, forestDlc], { places: { home } })
|
|
1670
|
+
*/
|
|
1671
|
+
load(data: ContentPack | ContentPack[], opts?: ContentLoadOptions): this;
|
|
1672
|
+
/** Register a custom condition, e.g. condition('timeAfter', { ref: 'clock', test: (e, t) => e.sky.timeOfDay >= t }) */
|
|
1673
|
+
condition(name: string, def: ContentConditionDef): this;
|
|
1674
|
+
/** Whether a condition holds (object, array or function) */
|
|
1675
|
+
test(cond: any): boolean;
|
|
1676
|
+
/** Run an effect (object, array or function) */
|
|
1677
|
+
run(effect: any): any;
|
|
1678
|
+
/** Place name -> position (load's places first, then level markers), null if none */
|
|
1679
|
+
place(name: string): XZ | null;
|
|
1680
|
+
/** Position form in content { place?, x?, z? } -> world coordinates */
|
|
1681
|
+
where(p: { place?: string; x?: number; z?: number }): XZ;
|
|
1682
|
+
/**
|
|
1683
|
+
* The shared, frozen definition of a content template (content/templates.js); instance state lives on the world record. e.g.
|
|
1684
|
+
* template('chest').container.capacity
|
|
1685
|
+
*/
|
|
1686
|
+
template(name: string): Readonly<ContentTemplate>;
|
|
1687
|
+
}
|
|
1688
|
+
/** A content template: shared definition of a reusable object (recipes/30-templates.md) */
|
|
1689
|
+
export interface ContentTemplate {
|
|
1690
|
+
/** Model name (style pack generator or assets name); every instance clones one shared prototype */
|
|
1691
|
+
model: string | any[];
|
|
1692
|
+
/** Collision box or circle from the model's bounds; omitted = does not block */
|
|
1693
|
+
collide?: 'box' | 'circle';
|
|
1694
|
+
/** false = not registered for rays */
|
|
1695
|
+
static?: boolean;
|
|
1696
|
+
/** Interaction: using an instance runs op with { id } */
|
|
1697
|
+
interact?: { op: string; label?: string | ((rec: WorldRecord, e: Engine) => string); radius?: number; height?: number; action?: string; enabled?: (rec: WorldRecord, e: Engine) => boolean };
|
|
1698
|
+
/** Each instance gets a container with its record id; items = starting goods (placed once) */
|
|
1699
|
+
container?: { capacity?: number; maxWeight?: number; items?: Record<string, number> };
|
|
1700
|
+
/** sfx played after a successful use */
|
|
1701
|
+
sound?: { use?: string };
|
|
1702
|
+
/** Per-frame look from the record (lid angle, glow); runs only while the model exists */
|
|
1703
|
+
animate?: (rec: WorldRecord, obj: Object3D, dt: number) => void;
|
|
1704
|
+
/** Instance state fields and their defaults, copied onto each record (saved) */
|
|
1705
|
+
state?: Record<string, any>;
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
// ======================================================================
|
|
1709
|
+
// Game flow flow()
|
|
1710
|
+
// ======================================================================
|
|
1711
|
+
|
|
1712
|
+
/** Parameters of flow() */
|
|
1713
|
+
export interface FlowOptions {
|
|
1714
|
+
/** Starting state, default 'playing'; other states are entered on engine:ready (so you can define after use()) */
|
|
1715
|
+
start?: string;
|
|
1716
|
+
}
|
|
1717
|
+
/** A flow state (title, playing, paused, game over...) */
|
|
1718
|
+
export interface FlowStateDef {
|
|
1719
|
+
/** Called on entering */
|
|
1720
|
+
enter?: (e: Engine, from: string) => void;
|
|
1721
|
+
/** Called on leaving */
|
|
1722
|
+
exit?: (e: Engine, to: string) => void;
|
|
1723
|
+
/** Freeze gameplay (engine.freeze, the picture keeps running), default false */
|
|
1724
|
+
freeze?: boolean;
|
|
1725
|
+
/** Lock game input, default false */
|
|
1726
|
+
lockInput?: boolean;
|
|
1727
|
+
/** Music played on entering (track name, null for silence) */
|
|
1728
|
+
music?: string | null;
|
|
1729
|
+
}
|
|
1730
|
+
/** Parameters of flow.transition() */
|
|
1731
|
+
export interface FlowTransitionOptions {
|
|
1732
|
+
/** Fade-to-black / fade-in seconds, default 0.5 */
|
|
1733
|
+
fade?: number;
|
|
1734
|
+
/** Lock input during the switch, default true */
|
|
1735
|
+
lockInput?: boolean;
|
|
1736
|
+
/** Music: 'fade' fades out (default) | 'keep' leaves it alone */
|
|
1737
|
+
music?: 'fade' | 'keep';
|
|
1738
|
+
/** Save to slot 'auto' before the switch: 'auto' | false (default: a game with its own save points keeps its slots) */
|
|
1739
|
+
autosave?: 'auto' | false;
|
|
1740
|
+
}
|
|
1741
|
+
/** engine.flow: game state and scene transitions */
|
|
1742
|
+
export interface Flow {
|
|
1743
|
+
/** Current state name */
|
|
1744
|
+
state: string;
|
|
1745
|
+
/** A scene transition is in progress */
|
|
1746
|
+
readonly transitioning: boolean;
|
|
1747
|
+
/** Define a state (built-in 'playing', 'paused') */
|
|
1748
|
+
define(name: string, def: FlowStateDef): this;
|
|
1749
|
+
/** Switch state */
|
|
1750
|
+
go(name: string): void;
|
|
1751
|
+
/**
|
|
1752
|
+
* Scene transition: lock input -> fade to black -> fade out music -> autosave -> fn() -> wait for modules to be ready -> fade in -> unlock; multiple
|
|
1753
|
+
* calls queue up
|
|
1754
|
+
*/
|
|
1755
|
+
transition(fn: () => any, opts?: FlowTransitionOptions): Promise<void>;
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
// ======================================================================
|
|
1759
|
+
// Objective markers hud()
|
|
1760
|
+
// ======================================================================
|
|
1761
|
+
|
|
1762
|
+
/** Parameters of hud() */
|
|
1763
|
+
export interface HudOptions {
|
|
1764
|
+
/** Show a marker automatically when the current quest step has a target, default true */
|
|
1765
|
+
questMarkers?: boolean;
|
|
1766
|
+
}
|
|
1767
|
+
/** Objective marker parameters */
|
|
1768
|
+
export interface HudMarkerOptions {
|
|
1769
|
+
/** Text */
|
|
1770
|
+
label?: string | (() => string);
|
|
1771
|
+
/** Icon (text or image URL) */
|
|
1772
|
+
icon?: string;
|
|
1773
|
+
/** When the target is off screen: 'arrow' an arrow at the screen edge (default) | 'hide' not shown */
|
|
1774
|
+
offscreen?: 'arrow' | 'hide';
|
|
1775
|
+
/** Show the distance, default true */
|
|
1776
|
+
distance?: boolean;
|
|
1777
|
+
/** How high the marker floats above the target (meters) */
|
|
1778
|
+
height?: number;
|
|
1779
|
+
}
|
|
1780
|
+
/**
|
|
1781
|
+
* Marker target: an object, a character (with root), { x, z } (snapped to the ground), { x, y, z }, a place name;
|
|
1782
|
+
* { nearest: itemId } the nearest not-yet-picked-up pickup of that kind to the player (hidden when all are picked up); a function: called every frame
|
|
1783
|
+
* to get the target, hidden when it returns null
|
|
1784
|
+
*/
|
|
1785
|
+
export type HudTarget = Object3D | { root: Object3D } | PositionLike | string | { nearest: string } | (() => Object3D | { root: Object3D } | PositionLike | string | null);
|
|
1786
|
+
/** Marker returned by hud.marker() */
|
|
1787
|
+
export interface HudMarker {
|
|
1788
|
+
target: HudTarget;
|
|
1789
|
+
/** Distance in meters from the player (from the focus when there is no player) */
|
|
1790
|
+
dist: number | null;
|
|
1791
|
+
/** Shown this frame (false when the target is missing, off screen with offscreen 'hide', or before the first frame) */
|
|
1792
|
+
visible: boolean;
|
|
1793
|
+
/** The UI part drawing it (null when hud.marker is turned off); the default part has .el */
|
|
1794
|
+
part: import('./core').UIPart | null;
|
|
1795
|
+
/** On screen (otherwise an edge arrow is shown or it is hidden) */
|
|
1796
|
+
onScreen: boolean;
|
|
1797
|
+
/** Change parameters */
|
|
1798
|
+
set(opts: HudMarkerOptions): void;
|
|
1799
|
+
/** Change the target (the marker itself is not rebuilt) */
|
|
1800
|
+
setTarget(target: HudTarget): void;
|
|
1801
|
+
/** Delete */
|
|
1802
|
+
remove(): void;
|
|
1803
|
+
}
|
|
1804
|
+
/** engine.hud: objective markers, counters, progress bars */
|
|
1805
|
+
export interface Hud {
|
|
1806
|
+
/** All markers */
|
|
1807
|
+
markers: HudMarker[];
|
|
1808
|
+
/** Add an objective marker: target is an object, position or place name */
|
|
1809
|
+
marker(target: HudTarget, opts?: HudMarkerOptions): HudMarker;
|
|
1810
|
+
/** Counter (calling again with the same id = update; calling every frame is fine), e.g. counter('fish', { label: '鱼', value: 2, max: 5 }) */
|
|
1811
|
+
counter(id: string, opts: { label?: string; icon?: string; value?: number; max?: number }): void;
|
|
1812
|
+
/** Progress bar (calling again with the same id = update; calling every frame is fine, the DOM is untouched when the value is unchanged),
|
|
1813
|
+
* value/max 0–max */
|
|
1814
|
+
bar(id: string, opts: { value: number; max?: number; label?: string }): void;
|
|
1815
|
+
/** Delete a counter or progress bar */
|
|
1816
|
+
remove(id: string): void;
|
|
1817
|
+
}
|
|
1818
|
+
/**
|
|
1819
|
+
* Result of worldToScreen(): x/y are pixels from the canvas's top-left corner (the UI root covers the canvas), onScreen is inside the view, behind is
|
|
1820
|
+
* behind the camera
|
|
1821
|
+
*/
|
|
1822
|
+
export interface ScreenPoint { x: number; y: number; onScreen: boolean; behind: boolean }
|