threedog 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +39 -2
- package/core/Animator.js +268 -0
- package/core/Assets.js +256 -0
- package/core/Audio.js +267 -0
- package/core/Baked.js +72 -0
- package/core/Batching.js +247 -0
- package/core/Budget.js +221 -0
- package/core/Clock.js +94 -0
- package/core/Commits.js +77 -0
- package/core/DebugOverrides.js +143 -0
- package/core/Describe.js +145 -0
- package/core/Engine.js +184 -0
- package/core/Events.js +153 -0
- package/core/I18n.js +94 -0
- package/core/Input.js +245 -0
- package/core/Inspect.js +77 -0
- package/core/InspectScene.js +191 -0
- package/core/Jobs.js +146 -0
- package/core/Loading.js +149 -0
- package/core/MaterialInfo.js +32 -0
- package/core/Ops.js +256 -0
- package/core/Random.js +52 -0
- package/core/Rays.js +160 -0
- package/core/SaveStore.js +85 -0
- package/core/Saves.js +254 -0
- package/core/Stream.js +279 -0
- package/core/Threads.js +158 -0
- package/core/UrlState.js +94 -0
- package/core/Vars.js +35 -0
- package/core/Views.js +49 -0
- package/core/actor.js +23 -0
- package/core/assetEntry.js +89 -0
- package/core/assetLoad.js +190 -0
- package/core/assetManifest.js +35 -0
- package/core/assetReport.js +83 -0
- package/core/audioRules.js +121 -0
- package/core/audioVoice.js +225 -0
- package/core/batchGroups.js +116 -0
- package/core/canvasBox.js +63 -0
- package/core/catalog.js +169 -0
- package/core/checks.js +67 -0
- package/core/claims.js +51 -0
- package/core/dayTime.js +15 -0
- package/core/debugView.js +76 -0
- package/core/describeRender.js +45 -0
- package/core/describeText.js +143 -0
- package/core/easing.js +34 -0
- package/core/errorCodes.js +205 -0
- package/core/errorHints.js +208 -0
- package/core/errors.js +40 -0
- package/core/events.generated.js +84 -0
- package/core/ground.js +102 -0
- package/core/holds.js +106 -0
- package/core/inputContext.js +69 -0
- package/core/inputDefaults.js +22 -0
- package/core/inputPad.js +35 -0
- package/core/inputPointer.js +48 -0
- package/core/inputTouch.js +48 -0
- package/core/lifecycle.js +69 -0
- package/core/lightWatch.js +56 -0
- package/core/look/coreParts.js +112 -0
- package/core/look/layers.js +136 -0
- package/core/look/part.js +173 -0
- package/core/look/report.js +79 -0
- package/core/look/write.js +86 -0
- package/core/loop.js +200 -0
- package/core/math.js +33 -0
- package/core/modules.js +196 -0
- package/core/movement.js +19 -0
- package/core/mulberry32.js +14 -0
- package/core/opsAtomic.js +31 -0
- package/core/opsCheck.js +97 -0
- package/core/opsFail.js +20 -0
- package/core/opsGuard.js +26 -0
- package/core/opsHistory.js +27 -0
- package/core/opsRun.js +77 -0
- package/core/page.js +78 -0
- package/core/params.js +132 -0
- package/core/pureWorker.js +5 -0
- package/core/renamed.js +21 -0
- package/core/saveApply.js +128 -0
- package/core/saveFiles.js +139 -0
- package/core/saveIds.js +53 -0
- package/core/saveVersions.js +97 -0
- package/core/scatter.js +92 -0
- package/core/sceneMethods.js +100 -0
- package/core/screenToGround.js +39 -0
- package/core/services.js +73 -0
- package/core/session.js +171 -0
- package/core/shadowTypes.js +15 -0
- package/core/skip.js +104 -0
- package/core/startup.js +135 -0
- package/core/streamCells.js +24 -0
- package/core/streamSources.js +73 -0
- package/core/styleParts.js +96 -0
- package/core/targeting.js +64 -0
- package/core/thingExplain.js +68 -0
- package/core/thingOps.js +168 -0
- package/core/things.js +212 -0
- package/core/threadPure.js +120 -0
- package/core/threadServe.js +25 -0
- package/core/tier.js +11 -0
- package/core/util.js +11 -0
- package/core/validate.js +204 -0
- package/docs/AI.md +123 -0
- package/docs/API.md +83 -0
- package/docs/CODEMAP.md +347 -0
- package/docs/COMMANDS.md +108 -0
- package/docs/CONVENTIONS.md +145 -0
- package/docs/PERF.md +217 -0
- package/docs/THREE.md +86 -0
- package/docs/api/ambience.md +15 -0
- package/docs/api/assets.md +62 -0
- package/docs/api/audio.md +53 -0
- package/docs/api/budget.md +40 -0
- package/docs/api/cameraRig.md +120 -0
- package/docs/api/characters.md +144 -0
- package/docs/api/clock.md +7 -0
- package/docs/api/collision.md +39 -0
- package/docs/api/content.md +64 -0
- package/docs/api/dialogue.md +39 -0
- package/docs/api/engine.md +199 -0
- package/docs/api/entities.md +61 -0
- package/docs/api/events.md +95 -0
- package/docs/api/flow.md +27 -0
- package/docs/api/grids.md +11 -0
- package/docs/api/ground.md +16 -0
- package/docs/api/hlod.md +34 -0
- package/docs/api/hud.md +31 -0
- package/docs/api/i18n.md +10 -0
- package/docs/api/input.md +24 -0
- package/docs/api/interactions.md +31 -0
- package/docs/api/inventory.md +66 -0
- package/docs/api/jobs.md +10 -0
- package/docs/api/level.md +41 -0
- package/docs/api/lightPool.md +56 -0
- package/docs/api/music.md +34 -0
- package/docs/api/nav.md +26 -0
- package/docs/api/net.md +14 -0
- package/docs/api/openWorld.md +24 -0
- package/docs/api/particles.md +41 -0
- package/docs/api/photo.md +15 -0
- package/docs/api/post.md +10 -0
- package/docs/api/quests.md +36 -0
- package/docs/api/rays.md +26 -0
- package/docs/api/rigid.md +84 -0
- package/docs/api/saves.md +32 -0
- package/docs/api/settings.md +36 -0
- package/docs/api/sky.md +58 -0
- package/docs/api/stream.md +31 -0
- package/docs/api/style.md +134 -0
- package/docs/api/terrain.md +34 -0
- package/docs/api/timeline.md +39 -0
- package/docs/api/tools.md +57 -0
- package/docs/api/triggers.md +56 -0
- package/docs/api/vars.md +9 -0
- package/docs/api/vegetation.md +52 -0
- package/docs/api/water.md +48 -0
- package/docs/api/weather.md +29 -0
- package/docs/api/world.md +30 -0
- package/docs/recipes/01-new-game.md +148 -0
- package/docs/recipes/02-npc.md +167 -0
- package/docs/recipes/03-items-pickups.md +158 -0
- package/docs/recipes/04-quests.md +83 -0
- package/docs/recipes/05-props-bake.md +159 -0
- package/docs/recipes/06-clock-events.md +117 -0
- package/docs/recipes/07-flow-scenes-pause.md +132 -0
- package/docs/recipes/08-weather-sky.md +74 -0
- package/docs/recipes/09-style-pack.md +234 -0
- package/docs/recipes/10-blender-level.md +67 -0
- package/docs/recipes/11-vehicles.md +55 -0
- package/docs/recipes/12-navmesh.md +79 -0
- package/docs/recipes/13-animation.md +149 -0
- package/docs/recipes/14-custom-module.md +91 -0
- package/docs/recipes/15-perf.md +78 -0
- package/docs/recipes/16-dev-bridge.md +180 -0
- package/docs/recipes/18-world.md +185 -0
- package/docs/recipes/19-shooting-picking.md +76 -0
- package/docs/recipes/20-content-actions-save.md +176 -0
- package/docs/recipes/21-camera.md +153 -0
- package/docs/recipes/22-shop-gold.md +107 -0
- package/docs/recipes/23-ops.md +175 -0
- package/docs/recipes/26-ui-parts.md +138 -0
- package/docs/recipes/27-net.md +96 -0
- package/docs/recipes/28-terrain.md +80 -0
- package/docs/recipes/29-grid.md +87 -0
- package/docs/recipes/30-templates.md +131 -0
- package/docs/recipes/31-audio.md +126 -0
- package/docs/recipes/32-action-game.md +33 -0
- package/docs/recipes/33-stream-sources.md +37 -0
- package/docs/recipes/34-environment-lighting.md +36 -0
- package/docs/recipes/35-style-from-reference.md +89 -0
- package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
- package/docs/recipes/37-terrain-look-hooks.md +97 -0
- package/docs/recipes/38-environment-look-hooks.md +83 -0
- package/docs/recipes/40-scene.md +108 -0
- package/docs/recipes/41-thing-registry.md +93 -0
- package/docs/recipes/42-terrain-shape.md +64 -0
- package/docs/recipes/43-shader-patches-surface-looks.md +120 -0
- package/docs/recipes/44-water-weather-look-hooks.md +135 -0
- package/docs/recipes/45-cascaded-shadows.md +51 -0
- package/docs/recipes/46-blender-art-route.md +114 -0
- package/docs/recipes/47-island-snow-backdrop.md +44 -0
- package/docs/recipes/48-make-material.md +70 -0
- package/docs/recipes/49-game-module-contract.md +71 -0
- package/docs/recipes/50-own-renderer.md +12 -0
- package/docs/recipes/51-capability-catalog.md +63 -0
- package/docs/recipes/52-look.md +108 -0
- package/examples/action/DESIGN.md +3 -0
- package/examples/action/GAMEMAP.md +127 -0
- package/examples/action/content/actions.js +8 -0
- package/examples/action/content/audio.js +9 -0
- package/examples/action/content/index.js +10 -0
- package/examples/action/content/items.js +4 -0
- package/examples/action/content/places.js +4 -0
- package/examples/action/content/props.js +11 -0
- package/examples/action/content/templates.js +10 -0
- package/examples/action/content/views.js +6 -0
- package/examples/action/look.js +5 -0
- package/examples/action/main.js +137 -0
- package/examples/action/models.js +25 -0
- package/examples/sheepisland/GAMEMAP.md +107 -0
- package/examples/sheepisland/content/index.js +6 -0
- package/examples/sheepisland/content/props.js +19 -0
- package/examples/sheepisland/content/templates.js +5 -0
- package/examples/sheepisland/content/vegetation.js +8 -0
- package/examples/sheepisland/main.js +71 -0
- package/examples/sheepisland/params.js +25 -0
- package/examples/sheepisland/style/index.js +79 -0
- package/examples/sheepisland/style/models.js +59 -0
- package/examples/sheepisland/views.js +9 -0
- package/examples/styletest/GAMEMAP.md +135 -0
- package/examples/styletest/content/index.js +9 -0
- package/examples/styletest/content/items.js +8 -0
- package/examples/styletest/content/npcs.js +8 -0
- package/examples/styletest/content/places.js +5 -0
- package/examples/styletest/content/props.js +16 -0
- package/examples/styletest/content/templates.js +9 -0
- package/examples/styletest/content/vegetation.js +31 -0
- package/examples/styletest/look.js +11 -0
- package/examples/styletest/main.js +95 -0
- package/examples/styletest/models.js +87 -0
- package/examples/styletest/overrides.js +33 -0
- package/examples/styletest/panel.js +135 -0
- package/examples/styletest/params.js +32 -0
- package/examples/styletest/views.js +31 -0
- package/examples/world/DESIGN.md +5 -0
- package/examples/world/GAMEMAP.md +171 -0
- package/examples/world/content/actions.js +8 -0
- package/examples/world/content/audio.js +25 -0
- package/examples/world/content/bodies.js +12 -0
- package/examples/world/content/containers.js +4 -0
- package/examples/world/content/dialogues.js +33 -0
- package/examples/world/content/index.js +17 -0
- package/examples/world/content/items.js +10 -0
- package/examples/world/content/npcs.js +14 -0
- package/examples/world/content/pickups.js +11 -0
- package/examples/world/content/places.js +6 -0
- package/examples/world/content/props.js +12 -0
- package/examples/world/content/quests.js +15 -0
- package/examples/world/content/rules.js +23 -0
- package/examples/world/content/templates.js +5 -0
- package/examples/world/content/vegetation.js +32 -0
- package/examples/world/main.js +168 -0
- package/examples/world/models.js +28 -0
- package/index.d.ts +306 -0
- package/index.js +122 -0
- package/llms.txt +61 -0
- package/modules/ambience/Ambience.js +186 -0
- package/modules/camera/FirstPersonCamera.js +131 -0
- package/modules/camera/FixedCamera.js +162 -0
- package/modules/camera/FollowCamera.js +91 -0
- package/modules/camera/RtsCamera.js +132 -0
- package/modules/camera/common.js +182 -0
- package/modules/camera/index.js +11 -0
- package/modules/camera/projection.js +34 -0
- package/modules/characters/Character.js +235 -0
- package/modules/characters/NPC.js +242 -0
- package/modules/characters/assetModel.js +42 -0
- package/modules/characters/astar.js +66 -0
- package/modules/characters/behaviors.js +72 -0
- package/modules/characters/footsteps.js +13 -0
- package/modules/characters/index.js +215 -0
- package/modules/characters/moveHelpers.js +29 -0
- package/modules/characters/movers/common.js +62 -0
- package/modules/characters/movers/rapier.js +74 -0
- package/modules/characters/movers/simple.js +43 -0
- package/modules/characters/npcAvoid.js +129 -0
- package/modules/characters/npcSim.js +150 -0
- package/modules/characters/npcView.js +42 -0
- package/modules/characters/pathAsync.js +113 -0
- package/modules/characters/pathJob.js +62 -0
- package/modules/characters/pathWorker.js +7 -0
- package/modules/characters/playerStrings.js +12 -0
- package/modules/characters/proceduralRig.js +58 -0
- package/modules/characters/useModel.js +22 -0
- package/modules/characters/walkTo.js +58 -0
- package/modules/collision/Collision.js +274 -0
- package/modules/collision/grid.js +63 -0
- package/modules/content/explain.js +13 -0
- package/modules/content/ids.js +95 -0
- package/modules/content/index.js +154 -0
- package/modules/content/loader.js +190 -0
- package/modules/content/models.js +69 -0
- package/modules/content/packs.js +69 -0
- package/modules/content/props.js +89 -0
- package/modules/content/rules.js +134 -0
- package/modules/content/templates.js +189 -0
- package/modules/debug/DebugPanel.js +174 -0
- package/modules/entities/Entities.js +243 -0
- package/modules/entities/build.js +25 -0
- package/modules/entities/index.js +4 -0
- package/modules/flow/index.js +101 -0
- package/modules/gameplay/Container.js +227 -0
- package/modules/gameplay/Containers.js +89 -0
- package/modules/gameplay/Dialogue.js +219 -0
- package/modules/gameplay/Interactions.js +253 -0
- package/modules/gameplay/Inventory.js +224 -0
- package/modules/gameplay/Quests.js +205 -0
- package/modules/gameplay/boxOps.js +60 -0
- package/modules/gameplay/dialogueBox.js +48 -0
- package/modules/gameplay/interactionPrompt.js +28 -0
- package/modules/gameplay/inventoryOps.js +137 -0
- package/modules/gameplay/pickups.js +115 -0
- package/modules/gameplay/questLog.js +54 -0
- package/modules/gameplay/questSave.js +71 -0
- package/modules/grid/Grid.js +184 -0
- package/modules/grid/Layer.js +142 -0
- package/modules/grid/index.js +236 -0
- package/modules/grid/ops.js +73 -0
- package/modules/grid/preview.js +85 -0
- package/modules/grid/tiles.js +79 -0
- package/modules/hlod/index.js +167 -0
- package/modules/hud/index.js +167 -0
- package/modules/hud/parts.js +80 -0
- package/modules/level/geometry.js +46 -0
- package/modules/level/heightfield.js +160 -0
- package/modules/level/index.js +233 -0
- package/modules/level/nodes.js +84 -0
- package/modules/lights/index.js +227 -0
- package/modules/music/Music.js +294 -0
- package/modules/music/index.js +2 -0
- package/modules/music/rules.js +28 -0
- package/modules/nav/index.js +156 -0
- package/modules/nav/navPath.js +17 -0
- package/modules/net/Client.js +137 -0
- package/modules/net/Host.js +117 -0
- package/modules/net/Net.js +49 -0
- package/modules/net/index.js +77 -0
- package/modules/net/sync.js +114 -0
- package/modules/net/transports.js +118 -0
- package/modules/particles/Particles.js +179 -0
- package/modules/particles/effect.js +112 -0
- package/modules/particles/shaders.js +28 -0
- package/modules/photo/Photo.js +146 -0
- package/modules/rigid/RigidBodies.js +265 -0
- package/modules/rigid/Vehicles.js +97 -0
- package/modules/rigid/sync.js +158 -0
- package/modules/settings/Settings.js +297 -0
- package/modules/settings/apply.js +21 -0
- package/modules/settings/index.js +3 -0
- package/modules/settings/sections.js +156 -0
- package/modules/settings/strings.js +53 -0
- package/modules/settings/view.js +65 -0
- package/modules/sky/Sky.js +259 -0
- package/modules/sky/calendar.js +80 -0
- package/modules/sky/cascades.js +125 -0
- package/modules/sky/clouds.js +79 -0
- package/modules/sky/domeLayers.js +33 -0
- package/modules/sky/environment.js +141 -0
- package/modules/sky/fog.js +139 -0
- package/modules/sky/frame.js +77 -0
- package/modules/sky/layers.js +69 -0
- package/modules/sky/look.js +51 -0
- package/modules/sky/lookFog.js +80 -0
- package/modules/sky/lookShadow.js +50 -0
- package/modules/sky/lookSky.js +108 -0
- package/modules/sky/schedule.js +80 -0
- package/modules/sky/shader.js +96 -0
- package/modules/sky/shadow.js +74 -0
- package/modules/sky/skyModule.js +60 -0
- package/modules/terrain/ChunkManager.js +260 -0
- package/modules/terrain/chunkJob.js +19 -0
- package/modules/terrain/chunkLevels.js +40 -0
- package/modules/terrain/chunkQueries.js +42 -0
- package/modules/terrain/chunkWorker.js +5 -0
- package/modules/terrain/index.js +118 -0
- package/modules/terrain/lookGround.js +61 -0
- package/modules/terrain/mountTerrain.js +32 -0
- package/modules/terrain/terrainColorMap.js +41 -0
- package/modules/terrain/terrainDefaults.js +39 -0
- package/modules/terrain/terrainEdit.js +139 -0
- package/modules/terrain/terrainGen.js +155 -0
- package/modules/terrain/terrainIsland.js +131 -0
- package/modules/terrain/terrainMesh.js +92 -0
- package/modules/terrain/terrainShape.js +108 -0
- package/modules/terrain/terrainShapeMain.js +41 -0
- package/modules/terrain/terrainTexture.js +44 -0
- package/modules/timeline/Timeline.js +253 -0
- package/modules/timeline/Tween.js +114 -0
- package/modules/timeline/letterbox.js +24 -0
- package/modules/timeline/shots.js +90 -0
- package/modules/triggers/index.js +268 -0
- package/modules/vegetation/Vegetation.js +256 -0
- package/modules/vegetation/groundChunks.js +177 -0
- package/modules/vegetation/index.js +43 -0
- package/modules/vegetation/lookWind.js +37 -0
- package/modules/vegetation/modelGeometry.js +21 -0
- package/modules/water/Water.js +160 -0
- package/modules/water/look.js +80 -0
- package/modules/water/surface.js +88 -0
- package/modules/weather/Weather.js +242 -0
- package/modules/weather/look.js +75 -0
- package/modules/weather/particles.js +92 -0
- package/modules/weather/shaders.js +49 -0
- package/modules/weather/strings.js +15 -0
- package/modules/world/World.js +231 -0
- package/modules/world/cells.js +42 -0
- package/modules/world/explain.js +11 -0
- package/modules/world/index.js +71 -0
- package/modules/world/persist.js +107 -0
- package/modules/world/pos.js +20 -0
- package/modules/world/records.js +89 -0
- package/modules/world/sim.js +175 -0
- package/modules/world/simFar.js +82 -0
- package/modules/world/state.js +115 -0
- package/modules/world/thingSource.js +44 -0
- package/modules/world/views.js +182 -0
- package/package.json +66 -4
- package/presets.js +96 -0
- package/render/PostFX.js +240 -0
- package/render/detail.js +105 -0
- package/render/effects.js +144 -0
- package/render/engineUniforms.js +23 -0
- package/render/fuse.js +84 -0
- package/render/lighting.js +100 -0
- package/render/lights.js +18 -0
- package/render/lookSurface.js +161 -0
- package/render/materials.js +220 -0
- package/render/patches.js +252 -0
- package/render/postLook.js +86 -0
- package/render/surface.js +69 -0
- package/render/uniformDecl.js +29 -0
- package/types/common.d.ts +34 -0
- package/types/core.d.ts +1965 -0
- package/types/gameplay.d.ts +1822 -0
- package/types/generated/core/Audio.d.ts +200 -0
- package/types/generated/core/Batching.d.ts +47 -0
- package/types/generated/core/Budget.d.ts +90 -0
- package/types/generated/core/Commits.d.ts +31 -0
- package/types/generated/core/DebugOverrides.d.ts +52 -0
- package/types/generated/core/Events.d.ts +89 -0
- package/types/generated/core/I18n.d.ts +30 -0
- package/types/generated/core/Input.d.ts +118 -0
- package/types/generated/core/Jobs.d.ts +41 -0
- package/types/generated/core/Ops.d.ts +203 -0
- package/types/generated/core/Random.d.ts +49 -0
- package/types/generated/core/Rays.d.ts +49 -0
- package/types/generated/core/Saves.d.ts +162 -0
- package/types/generated/core/Stream.d.ts +93 -0
- package/types/generated/core/Threads.d.ts +82 -0
- package/types/generated/core/Views.d.ts +33 -0
- package/types/generated/core/audioVoice.d.ts +47 -0
- package/types/generated/core/page.d.ts +18 -0
- package/types/generated/core/session.d.ts +48 -0
- package/types/generated/modules/ambience/Ambience.d.ts +48 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
- package/types/generated/modules/flow/index.d.ts +10 -0
- package/types/generated/modules/grid/Grid.d.ts +151 -0
- package/types/generated/modules/grid/Layer.d.ts +65 -0
- package/types/generated/modules/grid/index.d.ts +86 -0
- package/types/generated/modules/hlod/index.d.ts +11 -0
- package/types/generated/modules/hud/index.d.ts +10 -0
- package/types/generated/modules/lights/index.d.ts +13 -0
- package/types/generated/modules/music/Music.d.ts +111 -0
- package/types/generated/modules/net/Net.d.ts +34 -0
- package/types/generated/modules/net/index.d.ts +53 -0
- package/types/generated/modules/net/transports.d.ts +58 -0
- package/types/generated/modules/particles/Particles.d.ts +69 -0
- package/types/generated/modules/sky/Sky.d.ts +145 -0
- package/types/generated/modules/sky/skyModule.d.ts +10 -0
- package/types/generated/modules/timeline/Timeline.d.ts +51 -0
- package/types/generated/modules/water/Water.d.ts +29 -0
- package/types/generated/modules/weather/Weather.d.ts +62 -0
- package/types/generated/modules/world/World.d.ts +242 -0
- package/types/generated/modules/world/index.d.ts +15 -0
- package/types/generated/render/PostFX.d.ts +125 -0
- package/types/generated/render/materials.d.ts +100 -0
- package/types/generated/render/patches.d.ts +41 -0
- package/types/generated/ui/Focus.d.ts +11 -0
- package/types/generated/ui/LoadingScreen.d.ts +2 -0
- package/types/generated/ui/UI.d.ts +57 -0
- package/types/nav.d.ts +52 -0
- package/types/physics.d.ts +592 -0
- package/types/style.d.ts +638 -0
- package/types/worker.d.ts +11 -0
- package/types/world.d.ts +772 -0
- package/ui/Focus.js +51 -0
- package/ui/LoadingScreen.js +42 -0
- package/ui/Parts.js +199 -0
- package/ui/UI.js +167 -0
- package/ui/defaults.js +85 -0
- package/ui/theme.js +124 -0
- package/ui/touchPart.js +49 -0
package/types/core.d.ts
ADDED
|
@@ -0,0 +1,1965 @@
|
|
|
1
|
+
// Engine core: the Engine class, events, input, i18n, saves, assets, audio, the ground interface, module definitions.
|
|
2
|
+
import type { Object3D, Vector3, Vector2, Color, Texture, BufferGeometry, Handle, PositionLike, Vec3Like, ColorLike, Material } from './common';
|
|
3
|
+
import type { Style, StyleInput } from './style';
|
|
4
|
+
import type {
|
|
5
|
+
Terrain, Vegetation, Sky, Weather, Water, WaterBody, WaterBodyOptions, VegetationRemoveEvent, Hlod, LightPool, Budget, BudgetLimits, BudgetReport,
|
|
6
|
+
} from './world';
|
|
7
|
+
import type { World } from './generated/modules/world/World';
|
|
8
|
+
import type { Net } from './generated/modules/net/Net';
|
|
9
|
+
import type { PostEffect } from './generated/render/PostFX';
|
|
10
|
+
import type { Grids } from './generated/modules/grid/index';
|
|
11
|
+
import type { Collision, RigidBodies, CameraRig, CameraKind, CameraShotEvent, Animator, AnimatorOptions, Vehicle } from './physics';
|
|
12
|
+
import type { Nav } from './nav';
|
|
13
|
+
import type { Stream } from './generated/core/Stream';
|
|
14
|
+
import type { Batching } from './generated/core/Batching';
|
|
15
|
+
import type { Rays } from './generated/core/Rays';
|
|
16
|
+
import type { I18n } from './generated/core/I18n';
|
|
17
|
+
import type { Audio } from './generated/core/Audio';
|
|
18
|
+
import type { Input } from './generated/core/Input';
|
|
19
|
+
import type { Saves } from './generated/core/Saves';
|
|
20
|
+
import type { Session } from './generated/core/session';
|
|
21
|
+
import type { Page } from './generated/core/page';
|
|
22
|
+
import type { Events } from './generated/core/Events';
|
|
23
|
+
import type { Commits } from './generated/core/Commits';
|
|
24
|
+
import type { Threads } from './generated/core/Threads';
|
|
25
|
+
import type { Ops } from './generated/core/Ops';
|
|
26
|
+
import type { Views } from './generated/core/Views';
|
|
27
|
+
import type { DebugOverrides } from './generated/core/DebugOverrides';
|
|
28
|
+
import type { Jobs } from './generated/core/Jobs';
|
|
29
|
+
import type { Random } from './generated/core/Random';
|
|
30
|
+
import type { PostFX } from './generated/render/PostFX';
|
|
31
|
+
import type {
|
|
32
|
+
Timeline, Level, LevelLoadedEvent, Triggers, TriggerEvent, Entities, Entity, EntityStateEvent, EntityStageEvent,
|
|
33
|
+
Particles, Settings, Music, MusicChangeEvent, CharactersApi, NPCManager, Character,
|
|
34
|
+
Interactions, Dialogue, Inventory, ItemEvent, ItemUseEvent, ContainerEvent, PickupEvent, Quests, Photo, PhotoShot, Ambience, DebugPanel,
|
|
35
|
+
Clock, Vars, Content, Flow, Hud,
|
|
36
|
+
} from './gameplay';
|
|
37
|
+
|
|
38
|
+
// ======================================================================
|
|
39
|
+
// Events
|
|
40
|
+
// ======================================================================
|
|
41
|
+
|
|
42
|
+
declare global {
|
|
43
|
+
/**
|
|
44
|
+
* Your game's own events, declared in the game's folder without touching the engine: games/<game>/events.d.ts
|
|
45
|
+
* @example
|
|
46
|
+
* // games/my-game/events.d.ts
|
|
47
|
+
* interface GameEvents { 'fighter:hit': [{ attacker: string; victim: string; damage: number }] }
|
|
48
|
+
*/
|
|
49
|
+
interface GameEvents {}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Events the engine and modules emit, and the arguments callbacks receive (written as an array: what each argument is).
|
|
53
|
+
* A game adds its own to the global GameEvents interface (games/<game>/events.d.ts); undeclared names still work, their arguments just aren't checked.
|
|
54
|
+
*/
|
|
55
|
+
export interface EventMap extends GameEvents {
|
|
56
|
+
/** Loading finished; the world is playable */
|
|
57
|
+
'engine:ready': [];
|
|
58
|
+
/** Audio can play (after the player's first click / key press) */
|
|
59
|
+
'audio:ready': [];
|
|
60
|
+
/** UI language changed; the argument is the new language */
|
|
61
|
+
'i18n:change': [locale: string];
|
|
62
|
+
/** Key bindings changed; action null means everything was reset to defaults */
|
|
63
|
+
'input:rebind': [{ action: string | null; keys: string[] | null }];
|
|
64
|
+
'input:context': [{ stack: string[] }];
|
|
65
|
+
/** Save written to disk; the argument is the slot name (not emitted when the write fails, a toast is shown instead) */
|
|
66
|
+
'save:written': [slot: string];
|
|
67
|
+
/**
|
|
68
|
+
* Restore from a save file (saves.importFile) finished; the argument is the slot name. Attachments in the file (such as photos) are written to storage
|
|
69
|
+
* too
|
|
70
|
+
*/
|
|
71
|
+
'save:imported': [slot: string];
|
|
72
|
+
/** A save was loaded onto the running playthrough (saves.load / session.load); the argument is the slot name */
|
|
73
|
+
'save:loaded': [slot: string];
|
|
74
|
+
/** A window was opened (the argument is the window id, e.g. 'inventory') */
|
|
75
|
+
'ui:open': [id: string];
|
|
76
|
+
/** A window was closed */
|
|
77
|
+
'ui:close': [id: string];
|
|
78
|
+
/** Shadows were toggled */
|
|
79
|
+
'settings:shadows': [on: boolean];
|
|
80
|
+
/** A value in the settings menu changed (the argument is all setting values) */
|
|
81
|
+
'settings:change': [values: Record<string, any>];
|
|
82
|
+
/** A water body was added */
|
|
83
|
+
'water:add': [body: WaterBody];
|
|
84
|
+
/** A water body was removed */
|
|
85
|
+
'water:remove': [body: WaterBody];
|
|
86
|
+
/** A new day (the argument is the day number, starting at 1; needs the sky module) */
|
|
87
|
+
'day:start': [day: number];
|
|
88
|
+
/** Season changed (the argument is the season name, e.g. 'autumn') */
|
|
89
|
+
'season:change': [season: string];
|
|
90
|
+
/** engine.skip jumped game time forward (seconds = game seconds skipped); timers and world catch-up already ran */
|
|
91
|
+
'time:skip': [{ seconds: number }];
|
|
92
|
+
/** Lightning strike (weather module) */
|
|
93
|
+
'weather:lightning': [];
|
|
94
|
+
/** engine.weather.set switched to another weather name (once, when the blend starts; setting the same name again does not fire) */
|
|
95
|
+
'weather:change': [change: { from: string; to: string }];
|
|
96
|
+
/** The fixed-shot camera switched shots */
|
|
97
|
+
'camera:shot': [CameraShotEvent];
|
|
98
|
+
/** engine.setCamera switched the camera kind; settings that belong to the camera (sensitivity, invert Y, field of view) are re-applied on it */
|
|
99
|
+
'camera:change': [{ kind: string; previous: string }];
|
|
100
|
+
/** A character jumped */
|
|
101
|
+
'character:jump': [{ character: Character }];
|
|
102
|
+
/** A character's model named by asset finished loading and replaced the placeholder body (same root; anim is now set) */
|
|
103
|
+
'character:model': [{ character: Character; model: Object3D }];
|
|
104
|
+
/** A character landed; impact is the landing speed (m/s), the larger the harder the fall */
|
|
105
|
+
'character:land': [{ character: Character; impact: number }];
|
|
106
|
+
/** Dialogue started; the argument is the dialogue script name */
|
|
107
|
+
'dialogue:start': [speaker: string];
|
|
108
|
+
/**
|
|
109
|
+
* A dialogue line started (after its do ran): data is the node's own fields (portrait, voice...), {} when none. Use it for voice, portraits, camera
|
|
110
|
+
* shots without replacing the UI part
|
|
111
|
+
*/
|
|
112
|
+
'dialogue:line': [{ script: string; node: string; speaker: string; text: string; data: Record<string, any> }];
|
|
113
|
+
/** Dialogue ended; the argument is the dialogue script name */
|
|
114
|
+
'dialogue:end': [speaker: string];
|
|
115
|
+
/** An item was added to the inventory */
|
|
116
|
+
'item:add': [ItemEvent];
|
|
117
|
+
/** An item was removed from the inventory */
|
|
118
|
+
'item:remove': [ItemEvent];
|
|
119
|
+
/** An item was added to a non-player container (chest, corpse...); container is the container id */
|
|
120
|
+
'container:add': [ContainerEvent];
|
|
121
|
+
/** An item was removed from a non-player container */
|
|
122
|
+
'container:remove': [ContainerEvent];
|
|
123
|
+
/** An item on the ground was picked up */
|
|
124
|
+
'item:pickup': [PickupEvent];
|
|
125
|
+
/** An item was used through the inventory.use op (after use ran) */
|
|
126
|
+
'item:use': [ItemUseEvent];
|
|
127
|
+
/** A quest started */
|
|
128
|
+
'quest:start': [{ id: string }];
|
|
129
|
+
/** A quest moved to the next step; step is the new step index (starting at 0) */
|
|
130
|
+
'quest:step': [{ id: string; step: number }];
|
|
131
|
+
/** A quest completed */
|
|
132
|
+
'quest:done': [{ id: string }];
|
|
133
|
+
/** A part of a parallel quest step was met; step and part are indexes (starting at 0) */
|
|
134
|
+
'quest:part': [{ id: string; step: number; part: number }];
|
|
135
|
+
/** A quest failed (its fail condition held); quests.start(id) may begin it again */
|
|
136
|
+
'quest:fail': [{ id: string }];
|
|
137
|
+
/** A photo was taken */
|
|
138
|
+
'photo:taken': [PhotoShot];
|
|
139
|
+
/** The photo key was pressed but the op photo.take was refused (reason from photo.canTake(), 'denied' when it returned false) */
|
|
140
|
+
'photo:denied': [{ reason: string }];
|
|
141
|
+
/** Entered a trigger zone */
|
|
142
|
+
'trigger:enter': [TriggerEvent];
|
|
143
|
+
/** Left a trigger zone */
|
|
144
|
+
'trigger:exit': [TriggerEvent];
|
|
145
|
+
/** Level finished loading */
|
|
146
|
+
'level:loaded': [LevelLoadedEvent];
|
|
147
|
+
/** A cutscene started */
|
|
148
|
+
'timeline:start': [{ id: number }];
|
|
149
|
+
/** A cutscene ended; skipped tells whether it was skipped */
|
|
150
|
+
'timeline:end': [{ id: number; skipped: boolean }];
|
|
151
|
+
/** An entity was spawned */
|
|
152
|
+
'entity:spawn': [Entity];
|
|
153
|
+
/** An entity was removed */
|
|
154
|
+
'entity:remove': [Entity];
|
|
155
|
+
/** A state value of an entity changed */
|
|
156
|
+
'entity:state': [EntityStateEvent];
|
|
157
|
+
/** An entity entered a new growth stage */
|
|
158
|
+
'entity:stage': [EntityStageEvent];
|
|
159
|
+
/** The ground's shape or type changed in this world-space box (engine.terrain.edit): cached ground samples (path rasters) inside it are stale */
|
|
160
|
+
'ground:change': [{ x0: number; z0: number; x1: number; z1: number }];
|
|
161
|
+
/** terrain({ shape }): the player or a moving rigid body dropped below engine.terrain.voidY (once per fall). The engine does not respawn: the game decides */
|
|
162
|
+
'terrain:void': [{ who: any; position: { x: number; y: number; z: number } }];
|
|
163
|
+
/** A vegetation instance was chopped / removed */
|
|
164
|
+
'vegetation:remove': [VegetationRemoveEvent];
|
|
165
|
+
/** A vegetation instance was restored */
|
|
166
|
+
'vegetation:restore': [VegetationRemoveEvent];
|
|
167
|
+
/** Background music changed track (null means silence) */
|
|
168
|
+
'music:change': [MusicChangeEvent];
|
|
169
|
+
/** A stinger was played */
|
|
170
|
+
'music:stinger': [{ name: string }];
|
|
171
|
+
/** Scenario parameters were applied (URL parameters or engine.applyState) */
|
|
172
|
+
'state:applied': [StateParams];
|
|
173
|
+
/** A one-shot action of the animation state machine finished */
|
|
174
|
+
'anim:end': [{ root: Object3D; state: string }];
|
|
175
|
+
/** A record was added to world */
|
|
176
|
+
'world:add': [{ id: string; kind: string }];
|
|
177
|
+
/** world.set changed fields (keys lists which) */
|
|
178
|
+
'world:change': [{ id: string; kind: string; keys: string[] }];
|
|
179
|
+
/** A record was removed from world */
|
|
180
|
+
'world:remove': [{ id: string; kind: string }];
|
|
181
|
+
/** world finished loading a save (the data is now the save's; caches holding a rec object should refresh on this, count is the record count after loading) */
|
|
182
|
+
'world:load': [{ count: number }];
|
|
183
|
+
/** Host (net): a peer connected; actor is its world record / container id */
|
|
184
|
+
'net:join': [{ peer: number; actor: string }];
|
|
185
|
+
/** Host (net): a peer disconnected (its bag stays; a reconnect with its key gets the same actor) */
|
|
186
|
+
'net:leave': [{ peer: number; actor: string }];
|
|
187
|
+
/** Client (net): connected to the host (the first snapshot follows) */
|
|
188
|
+
'net:open': [{}];
|
|
189
|
+
/** Client (net): connection lost */
|
|
190
|
+
'net:close': [{}];
|
|
191
|
+
/** Client (net): host state applied (full: a whole snapshot, else a diff); redraw UI from state here */
|
|
192
|
+
'net:sync': [{ tick: number; full: boolean }];
|
|
193
|
+
/** Client (net): the host's answer to an op request (seq from ops.run's return value; tick is the host's), sent after the state it caused */
|
|
194
|
+
'net:result': [{ seq: number; name: string; ok: boolean; code: string | null; value?: any; tick: number }];
|
|
195
|
+
/** A gameplay error in development / testing; gameplay is frozen (error severity levels, see engine.error) */
|
|
196
|
+
'engine:error': [EngineError];
|
|
197
|
+
/** A presentation module errored and was disabled (the game continues) */
|
|
198
|
+
'module:disabled': [{ name: string; message: string }];
|
|
199
|
+
/** A character boarded a vehicle */
|
|
200
|
+
'vehicle:enter': [{ character: Character; vehicle: Vehicle }];
|
|
201
|
+
/** A character exited a vehicle */
|
|
202
|
+
'vehicle:exit': [{ character: Character; vehicle: Vehicle }];
|
|
203
|
+
/** Game flow state changed */
|
|
204
|
+
'flow:change': [{ from: string; to: string }];
|
|
205
|
+
/** Scene transition: phase 'start' begins fading to black, 'end' finishes fading back in */
|
|
206
|
+
'flow:transition': [{ phase: 'start' | 'end' }];
|
|
207
|
+
/** A playthrough ends (engine.session.newGame / load / quit), before the reset */
|
|
208
|
+
'session:end': [];
|
|
209
|
+
/** A playthrough started from a clean slate: kind 'new' (newGame) or 'load' (session.load, with the slot) */
|
|
210
|
+
'session:start': [{ kind: 'new' | 'load'; slot?: string }];
|
|
211
|
+
/** The page went away: the window lost focus or the tab was hidden (engine.page) */
|
|
212
|
+
'page:blur': [{ focused: boolean; visible: boolean }];
|
|
213
|
+
/** The page came back: focused and visible again */
|
|
214
|
+
'page:focus': [{ focused: boolean; visible: boolean }];
|
|
215
|
+
/** The mouse lock on the canvas started or ended (Esc, alt-tab); cameras with pointerLock lock again on the next click */
|
|
216
|
+
'page:pointerlock': [{ locked: boolean }];
|
|
217
|
+
/** The WebGL context was lost: gameplay waits and the player sees a message */
|
|
218
|
+
'page:contextlost': [];
|
|
219
|
+
/** The WebGL context is back: gameplay resumes */
|
|
220
|
+
'page:contextrestored': [];
|
|
221
|
+
}
|
|
222
|
+
/** Arguments a callback of the given event receives: known events follow EventMap, other names are not checked */
|
|
223
|
+
export type EventArgs<K extends string> = K extends keyof EventMap ? EventMap[K] : any[];
|
|
224
|
+
/** Event name: known events get autocompletion, any string is also allowed */
|
|
225
|
+
export type EventName = keyof EventMap | (string & {});
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
// ======================================================================
|
|
229
|
+
// Input
|
|
230
|
+
// ======================================================================
|
|
231
|
+
|
|
232
|
+
/** Mouse / touch pointer. ndcX/ndcY are screen coordinates in -1..1 */
|
|
233
|
+
/** Per-engine shader uniforms (engine.uniforms): { value } objects shared by every material of that engine */
|
|
234
|
+
export interface EngineUniforms {
|
|
235
|
+
/** Fixed seconds (= engine.elapsed) */
|
|
236
|
+
uTime: { value: number };
|
|
237
|
+
/** Wind strength multiplier (weather) */
|
|
238
|
+
uWind: { value: number };
|
|
239
|
+
/** Sway frequency multiplier (style.wind.frequency) */
|
|
240
|
+
uWindFreq: { value: number };
|
|
241
|
+
/** Cloud cover 0-1 (weather) */
|
|
242
|
+
uCloud: { value: number };
|
|
243
|
+
/** Darkest cloud shadow 0-1 (style.clouds.shadow; 0 = none) */
|
|
244
|
+
uCloudShadow: { value: number };
|
|
245
|
+
/** Cloud size: smaller = bigger clouds (style.clouds.scale) */
|
|
246
|
+
uCloudScale: { value: number };
|
|
247
|
+
/** Cloud drift per second (style.clouds.speed) */
|
|
248
|
+
uCloudSpeed: { value: Vector2 };
|
|
249
|
+
/** Season tint of foliage (sky calendar) */
|
|
250
|
+
uFoliageTint: { value: Color };
|
|
251
|
+
/** Season tint of the ground (sky calendar) */
|
|
252
|
+
uGroundTint: { value: Color };
|
|
253
|
+
uFoliageMix: { value: number };
|
|
254
|
+
uGroundMix: { value: number };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface Pointer {
|
|
258
|
+
/** Pixels from the canvas's top-left corner (not the window's): the same space as worldToScreen and the UI root */
|
|
259
|
+
x: number; y: number;
|
|
260
|
+
/** -1..1 across the canvas box (engine.pick / screenToGround take these) */
|
|
261
|
+
ndcX: number; ndcY: number;
|
|
262
|
+
/** Held down */
|
|
263
|
+
down: boolean;
|
|
264
|
+
/**
|
|
265
|
+
* Clicked once this frame (not a drag). Only for in-frame uses such as UI and clicking the ground; bind fire / attack to the action 'Mouse0' and read
|
|
266
|
+
* pressed in onFixed
|
|
267
|
+
*/
|
|
268
|
+
clicked: boolean;
|
|
269
|
+
/** Mouse button pressed: 0 left, 1 middle, 2 right */
|
|
270
|
+
button: number;
|
|
271
|
+
}
|
|
272
|
+
/** Autopilot: movement direction replacing player input (x right-positive, y forward-positive) and speed (m/s) */
|
|
273
|
+
export interface Autopilot { x: number; y: number; speed?: number }
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
// ======================================================================
|
|
277
|
+
// i18n
|
|
278
|
+
// ======================================================================
|
|
279
|
+
|
|
280
|
+
/** String table: { 'zh-CN': { key: text }, en: {...} }. {name} in the text is replaced by arguments, {key:action} shows the key name */
|
|
281
|
+
export type StringTables = Record<string, Record<string, string>>;
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
// ======================================================================
|
|
285
|
+
// Saves
|
|
286
|
+
// ======================================================================
|
|
287
|
+
|
|
288
|
+
/** Save provider: save() returns JSON-able data, load(data) reads it back (may return a Promise, e.g. for changing level;
|
|
289
|
+
* later parts wait for it to finish before loading).
|
|
290
|
+
* first: true providers load first (parts such as the level, where the rest only makes sense after it is loaded) */
|
|
291
|
+
export interface SaveProvider {
|
|
292
|
+
save: () => any;
|
|
293
|
+
load: (data: any) => void | Promise<void>;
|
|
294
|
+
/** Load before the other parts (such as the level) */
|
|
295
|
+
first?: boolean;
|
|
296
|
+
/** Join atomic ops: copied before an atomic op runs, put back if it fails (plain data; afterLoad does not run on rollback) */
|
|
297
|
+
atomic?: boolean;
|
|
298
|
+
/** This part's format version, default 1: raise it by 1 when what save() returns changes shape. A save with a newer version is refused */
|
|
299
|
+
version?: number;
|
|
300
|
+
/** Upgrade steps: old version -> data => data in the next version's shape, e.g. { 1: d => ({ ...d, beds: [] }) }.
|
|
301
|
+
* The second argument is the whole save as read ({ parts, versions }, read only), for a step that depends on another part */
|
|
302
|
+
migrate?: Record<number, (data: any, save: { parts: Record<string, any>, versions: Record<string, number> }) => any>;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
// ======================================================================
|
|
307
|
+
// Assets
|
|
308
|
+
// ======================================================================
|
|
309
|
+
|
|
310
|
+
/** Function that generates a model in code: returns a three object or geometry (may be async) */
|
|
311
|
+
export type ModelBuilder = (params?: any) => Object3D | BufferGeometry | Promise<Object3D | BufferGeometry>;
|
|
312
|
+
/**
|
|
313
|
+
* One asset manifest entry: a path; or { url, preload?, ... }; models can also be a generator function, or { build, params?, preload? } (generated on
|
|
314
|
+
* demand, cached automatically, reads the baked file if there is one)
|
|
315
|
+
*/
|
|
316
|
+
export type AssetEntry = string | ModelBuilder | {
|
|
317
|
+
/** File path (a file under public/ is written as '/models/x.glb') */
|
|
318
|
+
url?: string;
|
|
319
|
+
/** Model: generator function (instead of url) */
|
|
320
|
+
build?: ModelBuilder;
|
|
321
|
+
/** Model: parameters passed to build */
|
|
322
|
+
params?: any;
|
|
323
|
+
/** Bake manifest (bake.js) only: 'file' = the baked file is the source of truth (edited in Blender), npm run bake no longer overwrites it */
|
|
324
|
+
source?: 'file';
|
|
325
|
+
/** Preload at startup */
|
|
326
|
+
preload?: boolean;
|
|
327
|
+
/** start() stops with the reason if this fails (default false: a failed file falls back and the game continues) */
|
|
328
|
+
critical?: boolean;
|
|
329
|
+
/** Name of another entry of the same type to use if this one fails (default: a gray placeholder model / gray texture / silence) */
|
|
330
|
+
fallback?: string;
|
|
331
|
+
/** Texture: whether it is a color texture (write false for normal and roughness maps) */
|
|
332
|
+
color?: boolean;
|
|
333
|
+
/** Texture: pixel-art style (no smoothing) */
|
|
334
|
+
pixelated?: boolean;
|
|
335
|
+
/** Texture: repeat count [horizontal, vertical] */
|
|
336
|
+
repeat?: number[];
|
|
337
|
+
/**
|
|
338
|
+
* Model: game action names -> this file's clip names, as data (assets.animate and characters start from it), e.g.
|
|
339
|
+
* { states: { idle: { clip: 'Idle_Sword' }, attack: { clip: 'Sword_Slash', loop: false, timing: 0.6 } } }
|
|
340
|
+
*/
|
|
341
|
+
animation?: AnimatorOptions;
|
|
342
|
+
};
|
|
343
|
+
/**
|
|
344
|
+
* An asset manifest, also the shape of an asset pack (a folder or npm package exporting one): names -> files or generators; content and code use the
|
|
345
|
+
* names only
|
|
346
|
+
*/
|
|
347
|
+
export interface AssetManifest {
|
|
348
|
+
/** Label shown as the source manifest in engine.loading (default 'manifest#1', '#2'...) */
|
|
349
|
+
name?: string;
|
|
350
|
+
/**
|
|
351
|
+
* Folder that this manifest's relative paths resolve against: '/packs/forest/', a CDN URL, or new URL('./files/', import.meta.url) in an npm pack.
|
|
352
|
+
* '/x' and full URLs stay as written
|
|
353
|
+
*/
|
|
354
|
+
base?: string | URL;
|
|
355
|
+
/** Models (.glb / .gltf, Draco/Meshopt compression also works): name -> path or generator function */
|
|
356
|
+
models?: Record<string, AssetEntry>;
|
|
357
|
+
/** Textures: name -> path */
|
|
358
|
+
textures?: Record<string, AssetEntry>;
|
|
359
|
+
/** Sounds: name -> path */
|
|
360
|
+
sounds?: Record<string, AssetEntry>;
|
|
361
|
+
/** Fonts: name -> file, or { url, family, weight, style, ... } (family defaults to the name). style.ui.fonts lists the names the UI uses */
|
|
362
|
+
fonts?: Record<string, string | FontAssetEntry>;
|
|
363
|
+
}
|
|
364
|
+
/** One font of an asset pack: the file plus the FontFace descriptors (family defaults to the asset name) */
|
|
365
|
+
export interface FontAssetEntry {
|
|
366
|
+
url: string;
|
|
367
|
+
/** CSS font-family it registers (default: the asset name); several entries may share one family with different weight / style */
|
|
368
|
+
family?: string;
|
|
369
|
+
weight?: number | string; style?: string; stretch?: string; unicodeRange?: string; display?: string; featureSettings?: string; variationSettings?: string;
|
|
370
|
+
/** start() stops if it fails (otherwise text falls back to the next family of style.ui.font) */
|
|
371
|
+
critical?: boolean;
|
|
372
|
+
/** Load at start() even if style.ui.fonts does not name it */
|
|
373
|
+
preload?: boolean;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export interface Assets {
|
|
377
|
+
/**
|
|
378
|
+
* Register an asset manifest or asset pack (can be called several times; a later entry with the same name replaces the earlier one). Its name labels
|
|
379
|
+
* it in engine.loading, base resolves its relative paths
|
|
380
|
+
*/
|
|
381
|
+
manifest(m: AssetManifest): this;
|
|
382
|
+
/** The generator function registered under a model name, null for a file model or an unknown name (content builds [name, ...params] models with it) */
|
|
383
|
+
builder(name: string): ((...args: any[]) => any) | null;
|
|
384
|
+
/**
|
|
385
|
+
* Preload (onProgress(0–1, current name)). Code-generated models and fonts are only loaded up front if marked preload. failed includes entries now
|
|
386
|
+
* showing their fallback
|
|
387
|
+
*/
|
|
388
|
+
preload(onProgress?: (p: number, name: string) => void, opts?: { onlyMarked?: boolean }): Promise<{ loaded: number; failed: string[]; ok: boolean }>;
|
|
389
|
+
/**
|
|
390
|
+
* A font from an asset pack by name: downloaded once, added to document.fonts; null when the file failed and it is not critical. style.ui.fonts calls
|
|
391
|
+
* it at start()
|
|
392
|
+
*/
|
|
393
|
+
font(name: string): Promise<FontFace | null>;
|
|
394
|
+
/**
|
|
395
|
+
* Get a model copy (name or path; geometry and materials are shared with other copies). static: true registers it in engine.rays (builds ray
|
|
396
|
+
* acceleration)
|
|
397
|
+
*/
|
|
398
|
+
model(nameOrUrl: string, opts?: { castShadow?: boolean; receiveShadow?: boolean; static?: boolean }): Promise<Object3D>;
|
|
399
|
+
/**
|
|
400
|
+
* A model copy right now if it has already loaded, else null (never starts a load, never waits): lets code that rebuilds often skip the frame an await costs
|
|
401
|
+
* @example const m = engine.assets.modelNow('villager') ?? await engine.assets.model('villager');
|
|
402
|
+
*/
|
|
403
|
+
modelNow(nameOrUrl: string, opts?: { castShadow?: boolean; receiveShadow?: boolean; static?: boolean }): Object3D | null;
|
|
404
|
+
/** Get the geometry of the first mesh in a model */
|
|
405
|
+
geometry(nameOrUrl: string): Promise<BufferGeometry>;
|
|
406
|
+
/** Get a texture (.ktx2 compressed textures also work) */
|
|
407
|
+
texture(nameOrUrl: string, opts?: { color?: boolean; pixelated?: boolean; repeat?: number[] }): Promise<Texture>;
|
|
408
|
+
/**
|
|
409
|
+
* Release a resource and return GPU memory. Not released while copies of the model are still in the scene; it is released when the last copy is
|
|
410
|
+
* removed with engine.remove
|
|
411
|
+
*/
|
|
412
|
+
release(name: string): void;
|
|
413
|
+
/**
|
|
414
|
+
* Release every model that has no copy in use (called automatically after level changes). Models whose shared geometry was taken by geometry() /
|
|
415
|
+
* cached() are not released automatically. Returns the released names
|
|
416
|
+
*/
|
|
417
|
+
trim(): string[];
|
|
418
|
+
/** How many copies of this model are in use now (taken with model() and not yet removed with engine.remove) */
|
|
419
|
+
users(name: string): number;
|
|
420
|
+
/**
|
|
421
|
+
* Called when an object is fully removed (engine.remove already calls it, normally you don't need to): decrements the use count of the model copies
|
|
422
|
+
* under it
|
|
423
|
+
*/
|
|
424
|
+
forget(obj: Object3D): void;
|
|
425
|
+
/**
|
|
426
|
+
* Code-generated model: generated only once per name + params, returns a copy (for geometry, the same one).
|
|
427
|
+
* Order: files baked by npm run bake (public/models/baked/) -> automatic dev cache (.threedog/cache, invalidated automatically when the generator or
|
|
428
|
+
* a file it imports changes) -> compute now.
|
|
429
|
+
* When the generator is newer than the baked file during development, it computes now and prints a one-time hint "run npm run bake once it is final"
|
|
430
|
+
*/
|
|
431
|
+
cached<T = any>(name: string, build: (params?: any) => T | Promise<T>, params?: any): Promise<T>;
|
|
432
|
+
/** Generations faster than this many milliseconds are not written to the automatic cache (reading the file would be slower), default 20 */
|
|
433
|
+
cacheMinMs: number;
|
|
434
|
+
/** Geometry and materials shared by model copies (engine.remove does not release them, use release) */
|
|
435
|
+
shared: WeakSet<object>;
|
|
436
|
+
/** Current GPU memory usage (number of geometries and textures) */
|
|
437
|
+
readonly memory: { geometries: number; textures: number };
|
|
438
|
+
/**
|
|
439
|
+
* Create an animation state machine for a skinned model (without config it is simple play-by-name).
|
|
440
|
+
* A copy of a manifest model whose entry has `animation` starts from that mapping; config wins per state
|
|
441
|
+
*/
|
|
442
|
+
animate(root: Object3D, config?: AnimatorOptions): Animator;
|
|
443
|
+
/** The manifest entry's animation mapping for a model copy, or null (not a manifest copy, or no mapping) */
|
|
444
|
+
mapping(root: Object3D): AnimatorOptions | null;
|
|
445
|
+
/** three.js GLTFLoader (Meshopt installed; Draco and KTX2 are installed the first time they are needed) */
|
|
446
|
+
gltf: any;
|
|
447
|
+
/**
|
|
448
|
+
* three.js DRACOLoader (created only the first time Draco compression is met, null before; the decoder defaults to the one bundled with three, vite
|
|
449
|
+
* packs it automatically)
|
|
450
|
+
*/
|
|
451
|
+
draco: any;
|
|
452
|
+
/** three.js KTX2Loader (created only the first time a KTX2 texture is met, null before) */
|
|
453
|
+
ktx2: any;
|
|
454
|
+
/** Import report of a loaded model (by name, or a copy from model()): materials, textures with colorSpace, clips, colliders, templates, and issues for what the file has but the scene lost */
|
|
455
|
+
report(nameOrRoot: string | Object3D): AssetReport;
|
|
456
|
+
/** assets.report as text for the console / describe */
|
|
457
|
+
reportText(nameOrRoot: string | Object3D): string;
|
|
458
|
+
}
|
|
459
|
+
/** engine.assets.report(): see recipes/46-blender-art-route.md */
|
|
460
|
+
export interface AssetReport {
|
|
461
|
+
name: string | null; url: string | null; fromFile: boolean;
|
|
462
|
+
counts: Record<string, number>;
|
|
463
|
+
materials: { name: string; type: string; maps: Record<string, any>; flatShading: boolean; vertexColors: boolean; madeByStyle: boolean }[];
|
|
464
|
+
textures: any[]; clips: { name: string; seconds: number }[]; colliders: any[]; templates: any[];
|
|
465
|
+
issues: { severity: 'warn' | 'info'; code: string; msg: string }[];
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/** Phase of a loading task */
|
|
469
|
+
export type LoadingPhase = 'queued' | 'download' | 'decode' | 'upload' | 'build' | 'done' | 'failed';
|
|
470
|
+
/** One loading task (engine.loading.get / list) */
|
|
471
|
+
export interface LoadingTask {
|
|
472
|
+
name: string;
|
|
473
|
+
kind: 'model' | 'texture' | 'sound' | 'module' | 'stream' | 'step';
|
|
474
|
+
phase: LoadingPhase;
|
|
475
|
+
/** 0-1 within the phase (download reports bytes) */
|
|
476
|
+
progress: number;
|
|
477
|
+
/** A failure stops start() */
|
|
478
|
+
critical: boolean;
|
|
479
|
+
/** url: the file that failed (may be a .bin / texture the model references); status: HTTP status when known */
|
|
480
|
+
error?: { message: string; url: string | null; status?: number };
|
|
481
|
+
/** Files the model references but could not load (it loaded without them) */
|
|
482
|
+
missing?: string[];
|
|
483
|
+
/** What is used instead: 'gray placeholder', 'silence' or the fallback entry's name */
|
|
484
|
+
fallback?: string;
|
|
485
|
+
/** Where it came from: manifest name, path, file version (ETag / Last-Modified), size, animation clip names */
|
|
486
|
+
source: { manifest: string | null; url: string | null; version: string | null; bytes: number | null; animations: string[] | null };
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* describe().loading: done = nothing pending; ok = nothing failed (all finished is not all succeeded); blocked = a critical item failed before start()
|
|
490
|
+
* finished
|
|
491
|
+
*/
|
|
492
|
+
export interface LoadingView {
|
|
493
|
+
done: boolean; ok: boolean; blocked: boolean;
|
|
494
|
+
/** One English line naming the current item, e.g. 'decoding model "hero" (/models/hero.glb, manifest "main")'; null when done */
|
|
495
|
+
waiting: string | null;
|
|
496
|
+
pending: { name: string; kind: string; phase: LoadingPhase; progress: number; critical: boolean }[];
|
|
497
|
+
failed: LoadingTask[];
|
|
498
|
+
warnings: { name: string; missing: string[]; source: LoadingTask['source'] }[];
|
|
499
|
+
counts: { total: number; done: number; failed: number; pending: number };
|
|
500
|
+
}
|
|
501
|
+
export interface Loading {
|
|
502
|
+
/** Summary (what describe().loading shows) */
|
|
503
|
+
view(): LoadingView;
|
|
504
|
+
/** Player-facing text for the loading screen, null when nothing is pending */
|
|
505
|
+
text(): string | null;
|
|
506
|
+
/** One task with its source, or null */
|
|
507
|
+
get(name: string, kind?: string): LoadingTask | null;
|
|
508
|
+
/** Every task so far */
|
|
509
|
+
list(filter?: { kind?: string; phase?: LoadingPhase }): LoadingTask[];
|
|
510
|
+
/** Run the game's own loading step as a task (critical by default: a failure before start() finishes stops start()) */
|
|
511
|
+
track<T>(name: string, fn: () => Promise<T>, opts?: { critical?: boolean }): Promise<T>;
|
|
512
|
+
/**
|
|
513
|
+
* Resolves when every module installed after start() has finished its init() (also when one failed: see engine.moduleStates).
|
|
514
|
+
* @example engine.use(shop()); await engine.loading.settled(); engine.moduleStates.shop // 'running'
|
|
515
|
+
*/
|
|
516
|
+
settled(): Promise<void>;
|
|
517
|
+
/** How long start() waits for modules whose isReady(e) stays false before it rejects naming them, in ms (default 120000) */
|
|
518
|
+
timeoutMs: number;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// ======================================================================
|
|
522
|
+
// Audio
|
|
523
|
+
// ======================================================================
|
|
524
|
+
|
|
525
|
+
/** Built-in bus names; a game adds its own with createEngine({ audio: { levels: { voice: 1 } } }) or audio.addBus */
|
|
526
|
+
export type AudioBus = 'master' | 'music' | 'sfx' | 'ambience' | 'ui' | (string & {});
|
|
527
|
+
/** A playing sound (returned by audio.sfx / audio.play): stop(fade), fade(to, seconds), setPosition(at) */
|
|
528
|
+
import type { SoundHandle } from './generated/core/audioVoice';
|
|
529
|
+
export type { SoundHandle };
|
|
530
|
+
/** One sounds entry in full form. src: a file or variants (random, no immediate repeat); synth: a registered synth name (default: the entry's own name) */
|
|
531
|
+
export interface SoundDef {
|
|
532
|
+
src?: string | string[];
|
|
533
|
+
synth?: string;
|
|
534
|
+
/** Passed to the synth (merged over its registered defaults) */
|
|
535
|
+
params?: Record<string, any>;
|
|
536
|
+
/** Bus it plays on (default 'sfx', or the synth's registered bus) */
|
|
537
|
+
bus?: AudioBus;
|
|
538
|
+
volume?: number;
|
|
539
|
+
/** Playback rate multiplier (1 = as recorded); synths get it as params.pitch */
|
|
540
|
+
pitch?: number;
|
|
541
|
+
/** Random spread per play, as a fraction: { pitch: 0.08 } = +-8% */
|
|
542
|
+
jitter?: { volume?: number; pitch?: number };
|
|
543
|
+
/** Seconds before the same sound can start again (calls inside it return null) */
|
|
544
|
+
cooldown?: number;
|
|
545
|
+
/** Most voices of this sound at once; the oldest stops for a new one (default unlimited) */
|
|
546
|
+
voices?: number;
|
|
547
|
+
loop?: boolean;
|
|
548
|
+
/** 3D falloff for sfx(name, { at }): ref meters at full volume (2), max meters (60), rolloff (1) */
|
|
549
|
+
distance?: { ref?: number; max?: number; rolloff?: number };
|
|
550
|
+
}
|
|
551
|
+
/** A sounds entry: a file, variants, 'synth' (the synth registered under the same name) or the full form */
|
|
552
|
+
export type SoundSource = string | string[] | SoundDef;
|
|
553
|
+
/** A measure comparison in a rule's `when`: every given key must hold ({ daylight: { gt: 0.15 } }, { rain: { lt: 0.2 } }) */
|
|
554
|
+
export interface AudioCompare { gt?: number; gte?: number; lt?: number; lte?: number }
|
|
555
|
+
/**
|
|
556
|
+
* A rule's condition: an object whose keys all hold, or a function. Keys are condition keys (state, time, weather, zone, engine.audio.condition)
|
|
557
|
+
* or measures compared with AudioCompare (daylight, rain, snow, wind, nearWater, altitude, engine.audio.measure). Content packs: object only
|
|
558
|
+
*/
|
|
559
|
+
export type AudioCondition = Record<string, any | AudioCompare> | ((e: Engine, ...extra: any[]) => boolean);
|
|
560
|
+
/** Volume as data: base plus measure * factor for each add entry, clamped to [min, max] ({ base: 0.05, add: { wind: 0.08 }, max: 0.5 }) */
|
|
561
|
+
export interface AudioVolumeData { base?: number; add?: Record<string, number>; min?: number; max?: number }
|
|
562
|
+
/** A rule volume: a number 0-1, data (AudioVolumeData, the only form in content packs), or a function of the moment */
|
|
563
|
+
export type AudioVolume = number | AudioVolumeData | ((e: Engine, ...extra: any[]) => number);
|
|
564
|
+
/** One ambience rule: while `when` holds, `sound` plays at `volume`. With `every` it is a one-shot repeated at random gaps, else a loop */
|
|
565
|
+
export interface AmbienceRule {
|
|
566
|
+
sound: string;
|
|
567
|
+
when?: AudioCondition;
|
|
568
|
+
/** 0-1, data { base, add: { measure: factor }, min, max }, or a function of the moment (e, ambience) => 0-1 (code only) */
|
|
569
|
+
volume?: number | AudioVolumeData | ((e: Engine, ambience: import('./gameplay').Ambience) => number);
|
|
570
|
+
/** Fade seconds when the rule turns on / off (1) */
|
|
571
|
+
fade?: number;
|
|
572
|
+
/** One-shot: [shortest, longest] seconds between plays */
|
|
573
|
+
every?: number[];
|
|
574
|
+
/** Bus (default 'ambience') */
|
|
575
|
+
bus?: AudioBus;
|
|
576
|
+
}
|
|
577
|
+
/** Synthesized sound: connect to `out` and return the length in seconds, or { stop(time) } for a loop (params.loop is true then) */
|
|
578
|
+
export type SynthFn = (audio: Audio, params: Record<string, any>, out: any) => number | void | { stop(time: number): void };
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* The audio table of a content pack (content.load({ audio })): data only. sounds name asset pack sounds ('synth' for a built-in);
|
|
582
|
+
* ambience and music.rules use condition keys and measures, never functions. Merged with createEngine({ audio }); a name in both is an error
|
|
583
|
+
*/
|
|
584
|
+
export interface ContentAudio {
|
|
585
|
+
sounds?: Record<string, SoundSource>;
|
|
586
|
+
ambience?: AmbienceRule[];
|
|
587
|
+
music?: { tracks?: Record<string, import('./gameplay').MusicTrack>; rules?: import('./gameplay').MusicRule[] };
|
|
588
|
+
footsteps?: Record<string, string>;
|
|
589
|
+
}
|
|
590
|
+
/** The game's sound config: createEngine({ audio }), read back as engine.audio.config (merged with content packs' ContentAudio). Not part of a style pack */
|
|
591
|
+
export interface AudioConfig {
|
|
592
|
+
/** Sound name -> file / variants / 'synth' / SoundDef */
|
|
593
|
+
sounds?: Record<string, SoundSource>;
|
|
594
|
+
/** ambience() rule table */
|
|
595
|
+
ambience?: AmbienceRule[];
|
|
596
|
+
/** music() defaults: tracks, rules, fade seconds, duckDialogue (how low the music bus ducks during dialogue; default false = no duck) */
|
|
597
|
+
music?: {
|
|
598
|
+
tracks?: Record<string, import('./gameplay').MusicTrack>; rules?: import('./gameplay').MusicRule[];
|
|
599
|
+
fade?: number; duckDialogue?: number | false; duckFade?: number; hold?: number; interval?: number;
|
|
600
|
+
};
|
|
601
|
+
/** Ground type (terrain groundType or level material name) -> sound name; 'water' while swimming; default for unmapped types (else 'footstep') */
|
|
602
|
+
footsteps?: Record<string, string>;
|
|
603
|
+
/** Volume per bus 0-1, default { master: 0.8, music: 0.5, sfx: 0.8, ambience: 0.7, ui: 0.8 }; an extra key adds a bus */
|
|
604
|
+
levels?: Record<string, number>;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
// ======================================================================
|
|
609
|
+
// Post-processing (type generated from render/PostFX.js, see types/generated/), UI parts
|
|
610
|
+
// ======================================================================
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* One UI part: the engine calls these, the part only draws. Every method is optional (missing ones do nothing).
|
|
614
|
+
* What each part receives:
|
|
615
|
+
* loading show({ title }) · update({ progress 0-1, text, failed? }) · hide() (failed: the critical tasks that stopped start())
|
|
616
|
+
* toast show({ text, kind: 'info'|'quest'|'item'|'save'|'error'|string, ms })
|
|
617
|
+
* title show({ title, items: [{ id, label, run() }] }) · hide() (full screen: engine.ui.open / close)
|
|
618
|
+
* hud.marker show() · update({ x, y, onScreen, arrow, angle, label, icon, distance }) · hide() · dispose() (one per marker)
|
|
619
|
+
* hud.counter update({ id, label, icon, value, max }) · dispose() (one per counter)
|
|
620
|
+
* hud.bar update({ id, label, value, max }) · dispose() (one per bar)
|
|
621
|
+
* touch show(view) · update(view) TouchView: on-screen stick and action buttons (touch devices / joystick: true)
|
|
622
|
+
* dialogue show() · update(view) · hide() DialogueView (dialogue module)
|
|
623
|
+
* prompt update(view) every frame · hide() PromptView (interactions module)
|
|
624
|
+
* questLog show(view) · update(view) · hide() QuestLogView (quests module; full screen: opened by the quest key)
|
|
625
|
+
*/
|
|
626
|
+
export interface UIPart {
|
|
627
|
+
show?(data?: any): void;
|
|
628
|
+
update?(data?: any): void;
|
|
629
|
+
/** May return a promise that resolves when a fade-out has finished (engine.ui.settled() waits for it) */
|
|
630
|
+
hide?(): void | Promise<void>;
|
|
631
|
+
dispose?(): void;
|
|
632
|
+
[key: string]: any;
|
|
633
|
+
}
|
|
634
|
+
/** Your own part: called once per single part (loading, toast, title) or once per item (hud.*); options are what the game passed as an object */
|
|
635
|
+
export type UIPartFactory = (engine: Engine, options: Record<string, any>) => UIPart;
|
|
636
|
+
/** false off · true the default · an options object for the default · your own factory */
|
|
637
|
+
export type UIPartValue = boolean | Record<string, any> | UIPartFactory;
|
|
638
|
+
/** Declaring a part (engine and modules): on = shown unless turned off; multi = one part per item; modal = full screen, opened with ui.open */
|
|
639
|
+
export interface UIPartDef {
|
|
640
|
+
on?: boolean;
|
|
641
|
+
multi?: boolean;
|
|
642
|
+
modal?: { freeze?: boolean | ((engine: Engine) => boolean); cancel?: (engine: Engine) => void; data?: (engine: Engine, options: Record<string, any>) => object } | null;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* What the 'touch' UI part receives in show(view) and update(view) (buttons added later, language changed). Call move / press / release from your controls:
|
|
646
|
+
* they feed the same input path as keys, so engine.input.axis and pressed('jump') work unchanged.
|
|
647
|
+
* @example
|
|
648
|
+
* engine.ui.set('touch', (engine) => ({
|
|
649
|
+
* show: (v) => { myPad.onDrag = (x, y) => v.move(x, y); for (const b of v.buttons) myButton(b.label, () => v.press(b.action), () => v.release(b.action)); },
|
|
650
|
+
* }));
|
|
651
|
+
*/
|
|
652
|
+
export interface TouchView {
|
|
653
|
+
/** Draw a stick (createEngine({ joystick }): 'auto' on touch devices, true always) */
|
|
654
|
+
stick: boolean;
|
|
655
|
+
/** One button per action the modules asked for (touch devices only) */
|
|
656
|
+
buttons: { action: string; label: string }[];
|
|
657
|
+
/** Stick position: x right, y forward, length <= 1; move(0, 0) on release */
|
|
658
|
+
move(x: number, y: number): void;
|
|
659
|
+
/** Button pressed / released */
|
|
660
|
+
press(action: string): void;
|
|
661
|
+
release(action: string): void;
|
|
662
|
+
}
|
|
663
|
+
/** A title screen button: built-ins 'start' | 'continue' | 'settings', or your own */
|
|
664
|
+
export interface UITitleItem {
|
|
665
|
+
id?: string;
|
|
666
|
+
label: string | ((engine: Engine) => string);
|
|
667
|
+
run(engine: Engine): any;
|
|
668
|
+
}
|
|
669
|
+
/** engine.ui: every piece of screen UI is a named part a game can replace or turn off (see recipes/26-ui-parts.md) */
|
|
670
|
+
export interface UIParts {
|
|
671
|
+
/** Declare a part and its default (engine and modules; games use set) */
|
|
672
|
+
define(name: string, factory: UIPartFactory, def?: UIPartDef): void;
|
|
673
|
+
/**
|
|
674
|
+
* Replace a part, give the default options, or turn it off (before engine.start(); the loading part only via createEngine({ ui }))
|
|
675
|
+
* @example engine.ui.set('hud.marker', false)
|
|
676
|
+
* @example engine.ui.set('toast', (engine) => ({ show: ({ text, kind }) => { if (kind !== 'quest') myToast(text); } }))
|
|
677
|
+
*/
|
|
678
|
+
set(name: string, value: UIPartValue): void;
|
|
679
|
+
/** The live single part (null when off) */
|
|
680
|
+
get(name: string): UIPart | null;
|
|
681
|
+
/** A new part for one item of a multi part (null when off) */
|
|
682
|
+
create(name: string): UIPart | null;
|
|
683
|
+
/** Open a full-screen part (title): shows it, takes Esc, locks input, freezes gameplay, emits ui:open; false when off */
|
|
684
|
+
open(name: string, data?: object): boolean;
|
|
685
|
+
/** Close a full-screen part, emits ui:close */
|
|
686
|
+
close(name: string): void;
|
|
687
|
+
isOpen(name: string): boolean;
|
|
688
|
+
/** name -> 'default' | 'custom' | 'off' */
|
|
689
|
+
describe(): Record<string, string>;
|
|
690
|
+
/**
|
|
691
|
+
* Resolves once every hiding part has finished fading out (hide() returned a promise); screenshots wait for it
|
|
692
|
+
* @example await engine.ui.settled();
|
|
693
|
+
*/
|
|
694
|
+
settled(): Promise<void>;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
// ======================================================================
|
|
698
|
+
// Ground interface
|
|
699
|
+
// ======================================================================
|
|
700
|
+
|
|
701
|
+
/** Ground: whoever provides the ground height is the "terrain" (terrain module, level module, or the default flat y=0) */
|
|
702
|
+
export interface Ground {
|
|
703
|
+
/**
|
|
704
|
+
* Ground height (meters) at (x, z). For multi-layer ground (bridges, caves) pass refY: takes the highest layer not above refY + one step (0.45 m);
|
|
705
|
+
* without it the highest layer is used. Single-layer ground ignores refY
|
|
706
|
+
*/
|
|
707
|
+
height(x: number, z: number, refY?: number): number;
|
|
708
|
+
/** Slope at (x, z) (height difference / horizontal distance) */
|
|
709
|
+
slope(x: number, z: number): number;
|
|
710
|
+
/** Ground type at (x, z) (landform name, e.g. 'meadow') */
|
|
711
|
+
type(x: number, z: number): string;
|
|
712
|
+
/** Global water level (meters); -Infinity when there is no water */
|
|
713
|
+
waterLevel: number;
|
|
714
|
+
/**
|
|
715
|
+
* Is there ground at (x, z). Always true except off the outline of terrain({ shape }), where height is -Infinity and slope 0.
|
|
716
|
+
* @example if (engine.ground.has(x, z)) engine.snapToGround(chest);
|
|
717
|
+
*/
|
|
718
|
+
has(x: number, z: number): boolean;
|
|
719
|
+
/** Height below which something has fallen out of the world (terrain:void): engine.terrain.voidY with terrain({ shape }), else -Infinity */
|
|
720
|
+
voidY(): number;
|
|
721
|
+
/** Optional: iterate the circular colliders (tree trunks etc.) within range meters of (x, z) */
|
|
722
|
+
forEachCollider?(x: number, z: number, range: number, fn: (cx: number, cz: number, r: number) => void): void;
|
|
723
|
+
/** Optional: chunk edge length (meters) */
|
|
724
|
+
chunkSize?: number;
|
|
725
|
+
/** Optional: how far (meters) the ground is shown around a stream source now; stream entries build within it by default (else fogFar) */
|
|
726
|
+
viewRange?(): number;
|
|
727
|
+
/** Optional: collision data of a chunk (used by the physics module) */
|
|
728
|
+
chunkCollision?(cx: number, cz: number): any;
|
|
729
|
+
/** Optional: static triangle mesh (the level module provides it for physics) */
|
|
730
|
+
staticTrimeshes?(): { positions: Float32Array; indices: Uint32Array }[];
|
|
731
|
+
/** Optional: version number of the static mesh; rebuild when it changes */
|
|
732
|
+
staticVersion?(): number;
|
|
733
|
+
/** Optional: triangle mesh for building the navmesh (walkable surfaces + obstacle volumes), used by the nav module */
|
|
734
|
+
navGeometry?(): { positions: Float32Array; indices: Uint32Array };
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// ======================================================================
|
|
738
|
+
// Module definition
|
|
739
|
+
// ======================================================================
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* A module (the argument of engine.use). The name is the property name on the engine once installed.
|
|
743
|
+
* Per-frame hook order follows stage, then before / after within a stage, then install order.
|
|
744
|
+
*/
|
|
745
|
+
export interface ModuleDef<Api = any> {
|
|
746
|
+
/** Module name; after install, access the object returned by install through engine[name] */
|
|
747
|
+
name: string;
|
|
748
|
+
/** Display name (used by the loading screen) */
|
|
749
|
+
label?: string;
|
|
750
|
+
/** Names of other modules this depends on; they must be installed first (an error is thrown if not) */
|
|
751
|
+
requires?: string[];
|
|
752
|
+
/**
|
|
753
|
+
* Optional dependencies (modules the code uses as e.xxx?. or guards with if (e.xxx); rule R16 requires listing them all).
|
|
754
|
+
* An array only registers them; written as { moduleName: 'what is lost when missing' }, start() prints a one-time development hint when one is
|
|
755
|
+
* missing; use this form when it changes gameplay results
|
|
756
|
+
*/
|
|
757
|
+
optional?: string[] | Record<string, string>;
|
|
758
|
+
/**
|
|
759
|
+
* Hook stages (first -> last): 'control' timeline, camera -> 'world' terrain, level -> 'environment' weather, sky, water -> 'gameplay' interactions,
|
|
760
|
+
* dialogue, triggers, entities
|
|
761
|
+
* -> 'presentation' particles, settings, objective markers -> 'late' (default) -> 'audio' music. Within a stage use before / after, then install order
|
|
762
|
+
*/
|
|
763
|
+
stage?: 'control' | 'world' | 'environment' | 'gameplay' | 'presentation' | 'late' | 'audio';
|
|
764
|
+
/** Hooks run before these modules, inside one stage (ignored if not installed;
|
|
765
|
+
* use() throws on a cycle, or when the other module's stage already runs earlier) */
|
|
766
|
+
before?: string[];
|
|
767
|
+
/** Hooks run after these modules, inside one stage (ignored if not installed;
|
|
768
|
+
* use() throws on a cycle, or when the other module's stage already runs later) */
|
|
769
|
+
after?: string[];
|
|
770
|
+
/**
|
|
771
|
+
* Presentation modules (particles, sound effects, HLOD; gameplay is unaffected without them): when a hook errors only this module is disabled and the
|
|
772
|
+
* game continues.
|
|
773
|
+
* Without it the module counts as gameplay: during development / testing an error freezes gameplay and is recorded in engine.error (error severity levels)
|
|
774
|
+
*/
|
|
775
|
+
presentation?: boolean;
|
|
776
|
+
/**
|
|
777
|
+
* The game cannot run without this module (default false): when its init() fails, engine.start() rejects with the module name and reason instead of
|
|
778
|
+
* starting a broken game. Without it a failed init is reported by severity (presentation: disabled and the game carries on; gameplay: error tiers) and
|
|
779
|
+
* start() goes on. Only start() reads it; a critical module installed after start() is reported like any other
|
|
780
|
+
* @example engine.use({ name: 'saveSlots', critical: true, async init(e) { await loadSlots(); } })
|
|
781
|
+
*/
|
|
782
|
+
critical?: boolean;
|
|
783
|
+
/** Install: create and return the object the game uses (engine.name) */
|
|
784
|
+
install?(e: Engine): Api;
|
|
785
|
+
/** Called at startup (download things, wait for assets); may be async */
|
|
786
|
+
init?(e: Engine): void | Promise<void>;
|
|
787
|
+
/** The loading screen waits until this returns true before disappearing (the hook is called isReady; in the engine ready is always a boolean property) */
|
|
788
|
+
isReady?(e: Engine): boolean;
|
|
789
|
+
/** After a save loaded: rebuild what the loaded state needs nearby; gameplay waits frozen until the returned Promise resolves */
|
|
790
|
+
afterLoad?(e: Engine): void | Promise<void>;
|
|
791
|
+
/** Fixed step (60 times per second); dt is in seconds */
|
|
792
|
+
fixed?(dt: number, e: Engine): void;
|
|
793
|
+
/** Once per frame; dt is in seconds */
|
|
794
|
+
frame?(dt: number, e: Engine): void;
|
|
795
|
+
/** After rendering */
|
|
796
|
+
afterRender?(dt: number, e: Engine): void;
|
|
797
|
+
/**
|
|
798
|
+
* engine.skip moved time without stepping: advance your own time by dt fixed seconds (game seconds = dt x clock.timeScale), no per-step work.
|
|
799
|
+
* Called once per skip segment (segments end at timers and sky clock marks); done is true on the last one: do expensive catch-up only then.
|
|
800
|
+
* Only for modules that keep time themselves (sky, world); modules that compare against clock.now need nothing
|
|
801
|
+
*/
|
|
802
|
+
skip?(dt: number, e: Engine, done: boolean): void;
|
|
803
|
+
/**
|
|
804
|
+
* Optional: add state to engine.describe(). The (JSON-able) return value goes into the result keyed by the module name; nothing is added if it
|
|
805
|
+
* returns nothing.
|
|
806
|
+
* It may also fill in the standard fields of ctx.out, or use ctx.near() to report "nearby things"
|
|
807
|
+
*/
|
|
808
|
+
describe?(e: Engine, ctx: DescribeContext): any;
|
|
809
|
+
/** Optional: leak-hunting counts for engine.counts(), put there under the module name (a number or an object of numbers that should not keep growing) */
|
|
810
|
+
counts?(e: Engine): number | Record<string, number>;
|
|
811
|
+
/** Optional: answer engine.explain({ key: value }) for your own keys, e.g. explain: { quest: (e, id) => ({ ok: false, text: 'waits on step 2: ...' }) } */
|
|
812
|
+
explain?: Record<string, (e: Engine, value: any, query: Record<string, any>) => { ok: boolean; text: string; [k: string]: any }>;
|
|
813
|
+
/** Optional: handle the keys of engine.applyState that this module owns (e.g. sky handles time) */
|
|
814
|
+
applyState?(e: Engine, params: StateParams): void | Promise<void>;
|
|
815
|
+
/**
|
|
816
|
+
* Optional: called on engine.dispose() (in reverse install order). Only clean up what the core cannot: Workers, the physics world, real-time timers,
|
|
817
|
+
* Audio nodes you connected yourself.
|
|
818
|
+
* Events, onFixed / onFrame, clock timers, jobs, stream, ray registrations and GPU memory in the scene are reclaimed by the core; DOM listeners
|
|
819
|
+
* attached to engine.signal and UI attached to engine.uiRoot are cleaned up automatically too
|
|
820
|
+
*/
|
|
821
|
+
dispose?(e: Engine): void;
|
|
822
|
+
}
|
|
823
|
+
/** What engine.use() accepts: a module, an array of modules (what openWorld() returns); false/null are ignored */
|
|
824
|
+
export type ModuleInput = ModuleDef | ModuleInput[] | false | null | undefined;
|
|
825
|
+
|
|
826
|
+
// ======================================================================
|
|
827
|
+
// Engine
|
|
828
|
+
// ======================================================================
|
|
829
|
+
|
|
830
|
+
export interface EngineOptions {
|
|
831
|
+
/** Canvas element (required unless renderer is given), e.g. document.getElementById('view') */
|
|
832
|
+
canvas?: HTMLCanvasElement | HTMLElement;
|
|
833
|
+
/** A ready three.js renderer (WebGLRenderer or compatible) to use instead of creating one; canvas then defaults to renderer.domElement. The engine configures
|
|
834
|
+
* (pixel ratio, size, tone mapping, shadows) only a renderer it created itself. WebGL is the fully supported path; WebGPU-style renderers may not run shader patches or post effects (recipe 48) */
|
|
835
|
+
renderer?: any;
|
|
836
|
+
/** Style pack (looks only: materials, sky, lighting, post, UI look), e.g. import lowpoly from '@threedog/style-lowpoly', or a list of parts
|
|
837
|
+
* deep-merged left to right: [lowpoly, { sky: { sunSize: 600 } }]. Without one: neutral gray placeholders */
|
|
838
|
+
style?: StyleInput;
|
|
839
|
+
/** Real-time shadows, default true */
|
|
840
|
+
shadows?: boolean;
|
|
841
|
+
/** Shadow filter: 'basic' (hard edge) | 'pcf' | 'vsm' (softest, costliest), default 'pcf'. Change later with engine.look.shadow.set({ type }) */
|
|
842
|
+
shadowType?: 'basic' | 'pcf' | 'vsm';
|
|
843
|
+
/** MSAA anti-aliasing (kept with post effects on), default style.antialias, else on for desktop and off for low-tier devices */
|
|
844
|
+
antialias?: boolean;
|
|
845
|
+
/** Turn style post effects on or off by name at startup, e.g. { bloom: false }; default: each effect's own setting (costly ones off on low-tier devices) */
|
|
846
|
+
post?: Record<string, boolean>;
|
|
847
|
+
/** Render resolution, default min(device pixel ratio, 1.5) */
|
|
848
|
+
pixelRatio?: number;
|
|
849
|
+
/** Automatically lower resolution when the frame rate is too low, default true */
|
|
850
|
+
adaptiveResolution?: boolean;
|
|
851
|
+
/** Target frame rate for automatic resolution lowering, default 55 */
|
|
852
|
+
targetFps?: number;
|
|
853
|
+
/**
|
|
854
|
+
* UI parts: replace or turn off any piece of screen UI (loading, toast, title, hud.marker, hud.counter, hud.bar). Default title screen is off.
|
|
855
|
+
* @example createEngine({ canvas, ui: { loading: { title: 'My Game' }, title: { title: 'My Game' }, toast: false } })
|
|
856
|
+
*/
|
|
857
|
+
ui?: Record<string, UIPartValue>;
|
|
858
|
+
/** Volume of each channel, 0–1 */
|
|
859
|
+
audio?: AudioConfig;
|
|
860
|
+
/** Camera field of view (degrees), default 55 */
|
|
861
|
+
fov?: number;
|
|
862
|
+
/** Camera near clipping plane (meters), default 0.3 */
|
|
863
|
+
near?: number;
|
|
864
|
+
/** Default fog distance (meters), default 600 */
|
|
865
|
+
fogFar?: number;
|
|
866
|
+
/** UI language: 'auto' (default) follows the browser (a language starting with zh gives 'zh-CN', anything else 'en'); or force 'zh-CN' | 'en' | your own */
|
|
867
|
+
locale?: string;
|
|
868
|
+
/** Override / add UI strings: { 'zh-CN': { key: text } } */
|
|
869
|
+
strings?: StringTables;
|
|
870
|
+
/**
|
|
871
|
+
* Keys per action: changes the neutral defaults (move / confirm / cancel) and binds gameplay actions, e.g. { interact: ['KeyE'], run: ['ShiftLeft'] };
|
|
872
|
+
* a module's define() keeps these keys
|
|
873
|
+
*/
|
|
874
|
+
bindings?: Record<string, string[]>;
|
|
875
|
+
/** Default gamepad buttons: { jump: 'PadA' } */
|
|
876
|
+
padBindings?: Record<string, string>;
|
|
877
|
+
/** Save name prefix; must differ when several games share one site, default 'game' */
|
|
878
|
+
saveKey?: string;
|
|
879
|
+
/** On-screen joystick: 'auto' (only on touch devices) | true | false */
|
|
880
|
+
joystick?: 'auto' | boolean;
|
|
881
|
+
/**
|
|
882
|
+
* Headless mode: no real-time loop and no per-frame rendering, advances only on step() (for tests and screenshots). Adding ?threedog-headless to the
|
|
883
|
+
* URL also turns it on
|
|
884
|
+
*/
|
|
885
|
+
headless?: boolean;
|
|
886
|
+
/**
|
|
887
|
+
* Check parameter names at runtime and warn on misspelled names (the console prints "did you mean xxx"), default true; a release build can write false
|
|
888
|
+
* to turn it off
|
|
889
|
+
*/
|
|
890
|
+
validate?: boolean;
|
|
891
|
+
/**
|
|
892
|
+
* Directory of Draco/KTX2 decoders (a URL containing draco/ and basis/), for when they live on a CDN. Normally not needed: the decoders bundled with
|
|
893
|
+
* three are packed by vite automatically
|
|
894
|
+
*/
|
|
895
|
+
decoders?: string;
|
|
896
|
+
/** Performance budget limits, e.g. { drawCalls: 250, fps: 55 }; only the given categories are checked; off by default */
|
|
897
|
+
budget?: BudgetLimits;
|
|
898
|
+
/** Set up a scenario from URL parameters (?time=18:30&weather=rain&pos=40,-20), default on only in development */
|
|
899
|
+
urlState?: boolean;
|
|
900
|
+
/** Seed for engine.random; default 1 in headless mode (reproducible), the current time for live runs (different every game) */
|
|
901
|
+
seed?: number;
|
|
902
|
+
/**
|
|
903
|
+
* Shared "can walk there" parameters (meters / degrees): collision, the Rapier capsule, navigation and level steps all read them by default. Default {
|
|
904
|
+
* radius: 0.4, height: 1.8, maxSlope: 48, stepHeight: 0.45 }
|
|
905
|
+
*/
|
|
906
|
+
movement?: Partial<MovementProfile>;
|
|
907
|
+
/**
|
|
908
|
+
* Worker pool size for engine.threads: 'auto' (default: cores - 1, at most 4), a worker count, or false (all on the main thread, same results, no
|
|
909
|
+
* workers created) @experimental
|
|
910
|
+
*/
|
|
911
|
+
threads?: 'auto' | number | false;
|
|
912
|
+
/** Gameplay waits while the window is in the background or the tab is hidden; default true (engine.page) */
|
|
913
|
+
pauseOnBlur?: boolean;
|
|
914
|
+
/** false: no default lights in the scene at all (engine.lights.sun / hemi still exist, detached, so sky and describe never see undefined); the game adds its own. Default true */
|
|
915
|
+
lights?: boolean;
|
|
916
|
+
/** Automatic instancing of repeated static models (engine.batching): false turns it off; default { minCount: 8, cell: engine.stream.cellSize } */
|
|
917
|
+
batching?: false | BatchingOptions;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* engine.movement (read-only): character radius / height / max slope (degrees) / step height; slopeRatio is maxSlope converted to height difference /
|
|
922
|
+
* horizontal distance
|
|
923
|
+
*/
|
|
924
|
+
export interface MovementProfile { radius: number; height: number; maxSlope: number; stepHeight: number; readonly slopeRatio: number }
|
|
925
|
+
|
|
926
|
+
// ======================================================================
|
|
927
|
+
// Rays engine.raycast / pick / rays
|
|
928
|
+
// ======================================================================
|
|
929
|
+
|
|
930
|
+
/** Parameters of engine.raycast() */
|
|
931
|
+
export interface RaycastOptions {
|
|
932
|
+
/** Maximum distance (meters), default unlimited */
|
|
933
|
+
far?: number;
|
|
934
|
+
/**
|
|
935
|
+
* What to hit: 'static' registered static objects (default) | 'all' plus what modules merge in (with rigid installed this includes rigid bodies, hits
|
|
936
|
+
* carry entry and kind: 'rigid') | an array of objects
|
|
937
|
+
*/
|
|
938
|
+
targets?: 'static' | 'all' | Object3D[];
|
|
939
|
+
/** Hits for which this returns false are skipped */
|
|
940
|
+
filter?: (hit: RayHit) => boolean;
|
|
941
|
+
/** Hit only meshes that block the camera (level buildings, hidden col_ collision meshes); used by collision's cameraOcclusion */
|
|
942
|
+
occluders?: boolean;
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* Ray hit: point is the hit point, distance in meters, normal the surface direction, object the mesh hit; entry/kind come from the module that merged
|
|
946
|
+
* the hit in (e.g. a rigid body)
|
|
947
|
+
*/
|
|
948
|
+
export interface RayHit {
|
|
949
|
+
point: Vector3;
|
|
950
|
+
distance: number;
|
|
951
|
+
normal: Vector3 | null;
|
|
952
|
+
object: Object3D | null;
|
|
953
|
+
face: any;
|
|
954
|
+
entry?: any;
|
|
955
|
+
kind?: string;
|
|
956
|
+
/**
|
|
957
|
+
* Point -> thing, computed when read: the world record the hit belongs to (a batched instance resolves to its original), where it was authored and
|
|
958
|
+
* what to edit.
|
|
959
|
+
* @example const t = engine.pick(0, 0)?.thing; // { id: 'chest-home', kind: 'chest', template: 'chest', definedAt: 'content/props.js:14', ... }
|
|
960
|
+
*/
|
|
961
|
+
readonly thing?: HitThing;
|
|
962
|
+
}
|
|
963
|
+
/** One reason an object is not (or may not be) drawn: level 'hidden' stops it being seen, 'maybe' may explain an odd look (engine.inspect.scene) */
|
|
964
|
+
export interface SceneReason { code: string; level: 'hidden' | 'maybe'; text: string; fix?: string }
|
|
965
|
+
/** engine.inspect.scene() result */
|
|
966
|
+
export interface SceneInspect {
|
|
967
|
+
camera: { position: { x: number; y: number; z: number }; near: number; far: number } | null;
|
|
968
|
+
counts: { total: number; drawn: number; notDrawn: number; byType: Record<string, number> };
|
|
969
|
+
items: { name: string | null; type: 'Mesh' | 'Points' | 'Line' | 'Sprite'; path: string; id: number; position: { x: number; y: number; z: number }; radius: number | null;
|
|
970
|
+
material: { type: string; purpose: string | null } | null; visible: boolean; drawn: boolean; reasons?: SceneReason[] }[];
|
|
971
|
+
/** objects left out by limit */
|
|
972
|
+
truncated: number;
|
|
973
|
+
text: string;
|
|
974
|
+
}
|
|
975
|
+
/** engine.thing(id): a HitThing with the registry fields always present */
|
|
976
|
+
export interface Thing extends HitThing {
|
|
977
|
+
id: string; owner: string; at: string | null; phase: 'setup' | 'play'; saved: 'record' | 'code' | 'session' | 'engine'; keeps: string[]; loses: string[];
|
|
978
|
+
/** the live object (the record's current model, null when not built) */
|
|
979
|
+
readonly object: Object3D | null;
|
|
980
|
+
/** everything about this id in one JSON-able object: definition file:line, template, model, materials, state, collision rules, related ops, save status, how to change it. Not engine.explain(): that answers "why can this op / quest not run" (recipes/41 section 6) */
|
|
981
|
+
explain(): ThingExplanation;
|
|
982
|
+
}
|
|
983
|
+
/** What thing.explain() returns (`threedog thing <id>` prints the same JSON); modules add keys to rules / state through their explainers */
|
|
984
|
+
export interface ThingExplanation {
|
|
985
|
+
id: string; kind: string; owner: string;
|
|
986
|
+
/** at: 'content/props.js:14' (null in release builds and for code without a file) */
|
|
987
|
+
definition: { at: string | null; template: string | null; templateAt: string | null; level?: string; node?: string; spawned?: boolean; [k: string]: any };
|
|
988
|
+
model: string | null;
|
|
989
|
+
materials: ({ role: string | null; name: string | null; from: string | null; keys: string[]; type: string; color: string | null; mesh: string | null } | { more: number })[];
|
|
990
|
+
state: { position?: number[]; visible?: boolean; scale?: number[]; [k: string]: any };
|
|
991
|
+
rules: { height?: number; blocksMovement?: any; pickable?: boolean; interact?: any; [k: string]: any };
|
|
992
|
+
ops: { op: string; desc: string | null; args: any }[];
|
|
993
|
+
saved: { tier: 'record' | 'code' | 'session' | 'engine'; keeps: string[]; loses: string[]; overridden?: boolean; removed?: boolean };
|
|
994
|
+
change: { runtime: string; permanent: string; diagnostic: string };
|
|
995
|
+
overrides?: any[];
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* What a ray hit is (RayHit.thing, engine.inspect(id).thing; engine.thing gives the same plus owner / saved): the world record it belongs to, else the
|
|
999
|
+
* engine.add object. id is null for an object neither knows (engine.scene.add: only mesh and material are known then)
|
|
1000
|
+
*/
|
|
1001
|
+
export interface HitThing {
|
|
1002
|
+
id: string | null;
|
|
1003
|
+
kind: string | null;
|
|
1004
|
+
/** template name when the record is a content template instance */
|
|
1005
|
+
template: string | null;
|
|
1006
|
+
/** 'content/props.js:14' in dev and test builds (null in release, or when not from a content file) */
|
|
1007
|
+
definedAt: string | null;
|
|
1008
|
+
/** where the template itself is defined ('content/templates.js:3') */
|
|
1009
|
+
templateAt?: string | null;
|
|
1010
|
+
/** a level-model node record: level file name and node name */
|
|
1011
|
+
level?: string;
|
|
1012
|
+
node?: string;
|
|
1013
|
+
/** a record made during play: the op that made it and the tick */
|
|
1014
|
+
spawned?: { op: string | null; tick: number };
|
|
1015
|
+
model: any;
|
|
1016
|
+
mesh?: string | null;
|
|
1017
|
+
material?: string | null;
|
|
1018
|
+
position?: { x: number; y: number; z: number };
|
|
1019
|
+
/** the record's own fields (state you can change with world.set or an op) */
|
|
1020
|
+
fields: Record<string, any>;
|
|
1021
|
+
/** one sentence: where to change it for good */
|
|
1022
|
+
edit: string | null;
|
|
1023
|
+
/** who manages it: 'game' (engine.add), 'world' (a record), 'level' / 'stream' / 'engine:<module>' (engine internals) */
|
|
1024
|
+
owner?: string;
|
|
1025
|
+
/** dev: 'main.js:50' where engine.add was called (a record: where it was authored); null in release */
|
|
1026
|
+
at?: string | null;
|
|
1027
|
+
/** 'setup' (before engine.ready or in session:start) or 'play' (with op / tick) */
|
|
1028
|
+
phase?: 'setup' | 'play';
|
|
1029
|
+
op?: string | null;
|
|
1030
|
+
tick?: number;
|
|
1031
|
+
/** how much a save keeps (recipe 41): record = world save; code = thing.set / thing.remove overrides; session = nothing; engine = its module's business */
|
|
1032
|
+
saved?: 'record' | 'code' | 'session' | 'engine';
|
|
1033
|
+
/** what a save keeps / loses, in words */
|
|
1034
|
+
keeps?: string[];
|
|
1035
|
+
loses?: string[];
|
|
1036
|
+
/** removed with thing.remove (held for undo) */
|
|
1037
|
+
removed?: boolean;
|
|
1038
|
+
}
|
|
1039
|
+
/** A module merging in hits: (origin, direction, max distance) => hit or null */
|
|
1040
|
+
export type RayProvider = (origin: Vector3, dir: Vector3, far: number) => RayHit | null;
|
|
1041
|
+
|
|
1042
|
+
/** createEngine({ batching }) options */
|
|
1043
|
+
export interface BatchingOptions {
|
|
1044
|
+
/** Same geometry + material at least this many times in one cell becomes one InstancedMesh (default 8) */
|
|
1045
|
+
minCount?: number;
|
|
1046
|
+
/** Cell edge in meters that batches are split by (frustum culling, unloading); default engine.stream.cellSize */
|
|
1047
|
+
cell?: number;
|
|
1048
|
+
}
|
|
1049
|
+
/** engine.batching.stats */
|
|
1050
|
+
export interface BatchingStats {
|
|
1051
|
+
/** InstancedMesh batches drawn */
|
|
1052
|
+
batches: number;
|
|
1053
|
+
/** Meshes drawn through them */
|
|
1054
|
+
instances: number;
|
|
1055
|
+
/** Draw calls saved per pass (instances - batches) */
|
|
1056
|
+
saved: number;
|
|
1057
|
+
}
|
|
1058
|
+
/** One entry of engine.batching.batches */
|
|
1059
|
+
export interface BatchInfo {
|
|
1060
|
+
/** The batch (a real THREE.InstancedMesh) */
|
|
1061
|
+
mesh: any;
|
|
1062
|
+
/** Cell key 'cx,cz' */
|
|
1063
|
+
cell: string;
|
|
1064
|
+
/** Instances in use */
|
|
1065
|
+
count: number;
|
|
1066
|
+
/** items[i] is the placed object drawn by instance i */
|
|
1067
|
+
items: Object3D[];
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
// ======================================================================
|
|
1071
|
+
// Frame-spread jobs engine.jobs, stream-in engine.stream, startup timing
|
|
1072
|
+
// ======================================================================
|
|
1073
|
+
|
|
1074
|
+
/** Parameters of engine.stream.add(): position is the location, radius the size (meters), build generates (may be async), dispose unloads */
|
|
1075
|
+
export interface StreamEntryOptions {
|
|
1076
|
+
/** Position (Vector3 / object / [x, y, z] / { x, z }; only the horizontal coordinates count) */
|
|
1077
|
+
position: PositionLike;
|
|
1078
|
+
/** Object size (meters); larger ones are built earlier */
|
|
1079
|
+
radius?: number;
|
|
1080
|
+
/** Generate the object (called when entering range, run spread over frames through engine.jobs) */
|
|
1081
|
+
build: () => Object3D | Promise<Object3D>;
|
|
1082
|
+
/** Unload (called when leaving range), default engine.remove (full removal); write your own when the object is reused (e.g. engine.detach) */
|
|
1083
|
+
dispose?: (obj: Object3D) => void;
|
|
1084
|
+
/** Do not unload even when out of range */
|
|
1085
|
+
keep?: boolean;
|
|
1086
|
+
/** Build order: larger first (nearer first within the same priority), default 0 */
|
|
1087
|
+
priority?: number;
|
|
1088
|
+
}
|
|
1089
|
+
/** Options of engine.stream.source() */
|
|
1090
|
+
export interface StreamSourceOptions {
|
|
1091
|
+
/** Reach in meters: caps every loader's range around this source (default: each loader's own range) */
|
|
1092
|
+
radius?: number;
|
|
1093
|
+
/** 'full' (default): models, stream entries, terrain, colliders; 'simple': terrain and hlod proxies only (a far view) */
|
|
1094
|
+
detail?: 'full' | 'simple';
|
|
1095
|
+
/** Build colliders around it (default true for 'full'); false for a camera that only needs a picture */
|
|
1096
|
+
physics?: boolean;
|
|
1097
|
+
/** Removed automatically when this Promise settles, or when this function returns true (checked every frame) */
|
|
1098
|
+
until?: Promise<unknown> | (() => boolean);
|
|
1099
|
+
/** Label for describe and errors */
|
|
1100
|
+
name?: string;
|
|
1101
|
+
}
|
|
1102
|
+
/** A stream source returned by engine.stream.source() (also engine.stream.player / engine.stream.camera) */
|
|
1103
|
+
export interface StreamSource {
|
|
1104
|
+
name: string;
|
|
1105
|
+
radius: number | null;
|
|
1106
|
+
detail: 'full' | 'simple';
|
|
1107
|
+
physics: boolean;
|
|
1108
|
+
/** Current horizontal position */
|
|
1109
|
+
readonly x: number;
|
|
1110
|
+
readonly z: number;
|
|
1111
|
+
/** Everything this source asks for is loaded (checked at the end of each frame) */
|
|
1112
|
+
readonly ready: boolean;
|
|
1113
|
+
/** Resolves when ready becomes true */
|
|
1114
|
+
readonly whenReady: Promise<void>;
|
|
1115
|
+
/** Move the source (a live Object3D / Vector3, a function returning a position, or a fixed position) */
|
|
1116
|
+
at(position: PositionLike | (() => PositionLike)): this;
|
|
1117
|
+
/** A loader's range for this source: the loader's own range, capped by the source radius */
|
|
1118
|
+
reach(range: number): number;
|
|
1119
|
+
/** Stop loading for this source */
|
|
1120
|
+
remove(): void;
|
|
1121
|
+
}
|
|
1122
|
+
/** Handle returned by stream.add(): object is the generated object (null while not generated) */
|
|
1123
|
+
export interface StreamHandle { def: StreamEntryOptions; object: Object3D | null; built: boolean; remove(): void }
|
|
1124
|
+
/**
|
|
1125
|
+
* Startup timing (milliseconds): totalMs page open to playable, startMs start() to playable, preloadMs preloading, streamMs the nearby builds required
|
|
1126
|
+
* by stream registrations finished, compileMs shader compilation before the first frame,
|
|
1127
|
+
* modules is the init / ready time of each module. With a budget on and startupMs (open to playable) / moduleMs (a single module) given, the slowest
|
|
1128
|
+
* module is reported in the console when exceeded
|
|
1129
|
+
*/
|
|
1130
|
+
export interface StartupReport {
|
|
1131
|
+
totalMs: number; startMs: number; preloadMs: number; streamMs: number | null; compileMs: number; modules: Record<string, { init?: number; ready?: number }>;
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
// ======================================================================
|
|
1135
|
+
// Setting up a scenario engine.applyState
|
|
1136
|
+
// ======================================================================
|
|
1137
|
+
|
|
1138
|
+
/** Scenario parameters (can also go in the URL: ?time=18:30&weather=rain&pos=40,-20&cutscene=skip&state=name) */
|
|
1139
|
+
export interface StateParams {
|
|
1140
|
+
/** A group of parameters named with defineState */
|
|
1141
|
+
state?: string;
|
|
1142
|
+
/** Time of day: 'HH:MM' or 0–1 */
|
|
1143
|
+
time?: string | number;
|
|
1144
|
+
/** Season name from sky({ seasons }): jumps sky.day to that season's first day (time of day kept) */
|
|
1145
|
+
season?: string;
|
|
1146
|
+
/** Weather name */
|
|
1147
|
+
weather?: string;
|
|
1148
|
+
/** Player position: 'x,z' or a position (sets the focus when there is no player) */
|
|
1149
|
+
pos?: string | PositionLike;
|
|
1150
|
+
/** Which save slot to load */
|
|
1151
|
+
save?: string;
|
|
1152
|
+
/** How many seconds to advance (fixed-step seconds, not multiplied by clock.timeScale) */
|
|
1153
|
+
wait?: number;
|
|
1154
|
+
/** Opening cutscene: 'skip' skips it | 'keep' plays it as usual */
|
|
1155
|
+
cutscene?: 'skip' | 'keep';
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
/** A claim on something only its owner releases (pause, freeze, takeCamera, views) */
|
|
1159
|
+
export interface OwnerHandle { owner: string; remove(): void }
|
|
1160
|
+
/** What pause / freeze return: the claim handle, plus the old chaining calls forwarded to the engine */
|
|
1161
|
+
export interface ChainedHandle extends OwnerHandle {
|
|
1162
|
+
pause(owner?: string | { owner?: string; kind?: 'test' }, opts?: { kind?: 'test' }): ChainedHandle;
|
|
1163
|
+
resume(owner?: string | { owner?: string }): Engine;
|
|
1164
|
+
freeze(owner?: string | { owner?: string; kind?: 'title' }, opts?: { kind?: 'title' }): ChainedHandle;
|
|
1165
|
+
unfreeze(owner?: string | { owner?: string }): Engine;
|
|
1166
|
+
step(seconds: number, opts?: { render?: boolean; frameEvery?: number; describe?: boolean }): GameState | null;
|
|
1167
|
+
}
|
|
1168
|
+
/** engine.runState: state in one word, by = every pause / freeze owner, blockedBy = opaque input contexts plus 'error' / 'loading' */
|
|
1169
|
+
export interface RunState { state: 'loading' | 'title-frozen' | 'test-paused' | 'paused' | 'running'; by: string[]; blockedBy: string[] }
|
|
1170
|
+
/** Camera takeover: when non-null no camera module moves the camera (for cutscenes); see engine.takeCamera */
|
|
1171
|
+
export interface CameraOverride {
|
|
1172
|
+
/** Who took over (any name) */
|
|
1173
|
+
owner: string;
|
|
1174
|
+
/** Optional: where the world loads around */
|
|
1175
|
+
focus?: Vector3;
|
|
1176
|
+
[key: string]: any;
|
|
1177
|
+
}
|
|
1178
|
+
/** State of automatic resolution */
|
|
1179
|
+
export interface AdaptiveState { paused: boolean; on: boolean; target: number; min: number; max: number; [key: string]: any }
|
|
1180
|
+
|
|
1181
|
+
// ======================================================================
|
|
1182
|
+
// Look parts engine.look.<part> (recipes/52-look.md)
|
|
1183
|
+
// ======================================================================
|
|
1184
|
+
|
|
1185
|
+
/** Returned by set / patch / replace: remove() takes that owner's layer back off */
|
|
1186
|
+
export interface LookHandle { remove(): void }
|
|
1187
|
+
/** engine.look.post: a LookPart with add() for one custom pass */
|
|
1188
|
+
export interface LookPost extends LookPart {
|
|
1189
|
+
/** Add ONE custom post pass (name, create | fuse, slot, order, params) without replacing the chain; remove() takes it out again. Slot, order and depth-order errors throw and add nothing. Change its params with set({ '<name>.<param>': v }) */
|
|
1190
|
+
add(effect: PostEffect, opts?: LookOptions): LookHandle;
|
|
1191
|
+
}
|
|
1192
|
+
/** owner: who writes the layer (non-empty name, default 'game'); roles: only materials.patch, the material roles that get the patch */
|
|
1193
|
+
export interface LookOptions { owner?: string; roles?: string[] }
|
|
1194
|
+
/** patch(name, spec): a spec instead of plain GLSL. post: fuse snippet (glsl, slot, order, uniforms, values); sky 'layer:<name>': glsl, blend, order, uniforms */
|
|
1195
|
+
export interface LookPatchSpec {
|
|
1196
|
+
glsl?: string | Record<string, any>;
|
|
1197
|
+
/** post: 'hdr' | 'ldr' */
|
|
1198
|
+
slot?: string;
|
|
1199
|
+
/** post and sky layers: draw order, smaller first */
|
|
1200
|
+
order?: number;
|
|
1201
|
+
uniforms?: Record<string, any>;
|
|
1202
|
+
/** post: live values of the generated effect */
|
|
1203
|
+
values?: Record<string, any>;
|
|
1204
|
+
/** sky layer: 'mix' | 'add' */
|
|
1205
|
+
blend?: string;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
/**
|
|
1209
|
+
* One look part. Layers, upper wins: engine default < style < game (per owner, last write wins) < engine.debug.override.
|
|
1210
|
+
* A part offers only the verbs that make sense for it; the others throw naming the verb to use.
|
|
1211
|
+
*/
|
|
1212
|
+
export interface LookPart<P = Record<string, any>> {
|
|
1213
|
+
/** 'look.<part>': the id engine.catalog() and debug.override use */
|
|
1214
|
+
readonly id: string;
|
|
1215
|
+
/** Shallow-merge into the owner's layer, only the keys given; null drops a key so the layer below shows again. Keys that recompile shaders warn once in dev */
|
|
1216
|
+
set(params: { [K in keyof P]?: P[K] | null } & Record<string, any>, opts?: LookOptions): LookHandle;
|
|
1217
|
+
/** Swap one named GLSL hook the part registered (names: engine.catalog('look.<part>').hooks); the same name again overrides; patch(name, null) restores the default */
|
|
1218
|
+
patch(name: string, glsl: string | LookPatchSpec | null, opts?: LookOptions): LookHandle;
|
|
1219
|
+
/** Take the whole part over (Material, texture, object, effect list ...: see the catalog); replace(null) gives it back. materials.replace takes the role first */
|
|
1220
|
+
replace(impl: any, opts?: LookOptions): LookHandle;
|
|
1221
|
+
replace(role: string, impl: any, opts?: LookOptions): LookHandle;
|
|
1222
|
+
/** Drop every game and debug layer of that owner (the style value shows again); returns how many layers were removed, like engine.debug.clear */
|
|
1223
|
+
clear(owner: string): number;
|
|
1224
|
+
/** The resolved value of a key (what is in use now) */
|
|
1225
|
+
value(key: string): any;
|
|
1226
|
+
/** The value from the highest game / debug layer for the key (undefined when only style or default gives it) */
|
|
1227
|
+
top(key: string): any;
|
|
1228
|
+
/** The three.js object(s) behind the part (renderer, lights, scene.fog ...); changing it directly works but describe tags it 'three'.
|
|
1229
|
+
* look.materials: a function, object('wool') = the last Material made for that role, object() = all of them */
|
|
1230
|
+
readonly object: any;
|
|
1231
|
+
/** Each verb's call shape, e.g. { set: 'set(params, { owner })', replace: 'replace(role, ...)' } (also in engine.catalog('look.<part>')) */
|
|
1232
|
+
readonly signatures: Record<string, string>;
|
|
1233
|
+
// ---- for authors of a part made with defineLookPart (recipes/52-look.md) ----
|
|
1234
|
+
/** Write raw keys (params, 'hook:<name>', '@replace') for an owner, no normalize; null drops a key */
|
|
1235
|
+
write(owner: string, values: Record<string, any>, opts?: { layer?: 'game' | 'debug' }): LookHandle;
|
|
1236
|
+
/** What one owner holds for a key, or undefined */
|
|
1237
|
+
ownerValue(owner: string, key: string, opts?: { layer?: 'game' | 'debug' }): any;
|
|
1238
|
+
/** Add declared keys to a started part (same fields as defineLookPart params) */
|
|
1239
|
+
extend(params: Record<string, any>): void;
|
|
1240
|
+
/** Remove every key starting with prefix, with every layer's value for them */
|
|
1241
|
+
retract(prefix: string): void;
|
|
1242
|
+
/** Is key a declared param */
|
|
1243
|
+
has(key: string): boolean;
|
|
1244
|
+
/** [key, value] pairs in effect whose key starts with prefix */
|
|
1245
|
+
resolved(prefix?: string): Array<[string, any]>;
|
|
1246
|
+
/** Replace the style layer */
|
|
1247
|
+
restyle(values: Record<string, any>): void;
|
|
1248
|
+
/** Declare keys a style-driven system writes every frame (by = the driver's module name); drive(keys, null) hands them back */
|
|
1249
|
+
drive(keys: string[], by: string | null): void;
|
|
1250
|
+
/** Unregister the part (its module went away) */
|
|
1251
|
+
dispose(): void;
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
export interface LookTone { mapping: string; exposure: number | Array<[number, number]> | ((t: number) => number) }
|
|
1255
|
+
export interface LookLightSide { color?: ColorLike; intensity?: number }
|
|
1256
|
+
export interface LookLights { sun: LookLightSide | 'manual' | false; hemi: LookLightSide | 'manual' | false }
|
|
1257
|
+
/** The map itself is the replace slot: look.env.replace('sky' | Texture | null) */
|
|
1258
|
+
export interface LookEnv { intensity: number; rotation: number; interval: number }
|
|
1259
|
+
export interface LookFog { kind: string; color: ColorLike | 'horizon'; density: number; near: number; far: number; height: number; falloff: number; enabled: boolean }
|
|
1260
|
+
export interface LookSky { clouds: Record<string, any>; backdrop: ColorLike | null }
|
|
1261
|
+
export interface LookShadow {
|
|
1262
|
+
type: 'basic' | 'pcf' | 'vsm'; radius: number; blurSamples: number; bias: number; normalBias: number; mapSize: number; updateEvery: number;
|
|
1263
|
+
snap: number | 'texel'; ahead: number; cascades: number; maxFar: number; fade: boolean; lightMargin: number; enabled: boolean;
|
|
1264
|
+
split: 'practical' | 'uniform' | 'logarithmic' | ((count: number, near: number, far: number, out: number[]) => void);
|
|
1265
|
+
}
|
|
1266
|
+
export interface LookCloudShadow { shadow: number; scale: number; speed: [number, number] }
|
|
1267
|
+
export interface LookWind { frequency: number; amplitude: number }
|
|
1268
|
+
export interface LookGround {
|
|
1269
|
+
colors: Record<string, ColorLike>; biomeColors: Record<string, string | string[]>; steep: Array<{ maxNormalY: number; colors: any }>;
|
|
1270
|
+
variation: any; detail: any; shading: string;
|
|
1271
|
+
}
|
|
1272
|
+
export interface LookSurface { lighting: Record<string, any>; detail: Record<string, any>; ramp: number[]; soften: number }
|
|
1273
|
+
export interface LookWater {
|
|
1274
|
+
color: ColorLike; opacity: number; depthColor: { shallow?: ColorLike; deep?: ColorLike }; foam: Record<string, any>;
|
|
1275
|
+
waveHeight: number; waveScale: number; waveSpeed: number; fresnel: number;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
/** engine.look: the parts by name. A part exists only when the module that provides it is installed (fog / sky / shadow / env: sky(); ground: terrain(); wind: vegetation(); water; weather) */
|
|
1279
|
+
export interface Look {
|
|
1280
|
+
tone: LookPart<LookTone>;
|
|
1281
|
+
lights: LookPart<LookLights>;
|
|
1282
|
+
cloudShadow: LookPart<LookCloudShadow>;
|
|
1283
|
+
/** Old name of cloudShadow (recipes/52-look.md, Old names) */
|
|
1284
|
+
clouds: LookPart<LookCloudShadow>;
|
|
1285
|
+
env: LookPart<LookEnv>;
|
|
1286
|
+
fog: LookPart<LookFog>;
|
|
1287
|
+
sky: LookPart<LookSky>;
|
|
1288
|
+
shadow: LookPart<LookShadow>;
|
|
1289
|
+
/** Roles are the keys: set({ wool: { roughness: 0.4 } }), patch(name, spec, { roles }), replace('wool', Material | fn) */
|
|
1290
|
+
materials: LookPart<Record<string, Record<string, any>>>;
|
|
1291
|
+
surface: LookPart<LookSurface>;
|
|
1292
|
+
ground: LookPart<LookGround>;
|
|
1293
|
+
wind: LookPart<LookWind>;
|
|
1294
|
+
water: LookPart<LookWater>;
|
|
1295
|
+
/** Keys 'rain.speed', 'snow.size', 'lightning.brightness', overcastColor ...; patch('rain.fragment', wholeShaderText) */
|
|
1296
|
+
weather: LookPart;
|
|
1297
|
+
/** Per effect: set({ bloom: { strength: 0.6 }, vignette: false }); patch(name, { glsl, slot, order, uniforms, values }); add(effect, { owner }); replace([effects]) */
|
|
1298
|
+
post: LookPost;
|
|
1299
|
+
/** Parts made with defineLookPart */
|
|
1300
|
+
[custom: string]: LookPart;
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* The engine. Created by createEngine({ canvas, style }); engine.use(module...) installs modules, engine.start() starts it.
|
|
1305
|
+
* Installed modules hang on the engine (engine.terrain, engine.sky...); modules not installed are undefined, check with engine.xxx?.method().
|
|
1306
|
+
*/
|
|
1307
|
+
export declare class Engine {
|
|
1308
|
+
constructor(opts: EngineOptions);
|
|
1309
|
+
|
|
1310
|
+
// ---------- Core objects ----------
|
|
1311
|
+
/** three.js (a game can also import { THREE } from 'threedog' directly) */
|
|
1312
|
+
THREE: typeof import('three');
|
|
1313
|
+
/** Style pack */
|
|
1314
|
+
style: Style;
|
|
1315
|
+
/** three.js renderer */
|
|
1316
|
+
renderer: import('three').WebGLRenderer;
|
|
1317
|
+
/** Device tier: 'low' (phones, integrated graphics) | 'high' */
|
|
1318
|
+
tier: 'low' | 'high';
|
|
1319
|
+
/** three.js scene */
|
|
1320
|
+
scene: import('three').Scene;
|
|
1321
|
+
/**
|
|
1322
|
+
* Default lights (neutral without sky; the sky module drives these same two). Hide or retune them for your own lighting: `engine.lights.sun.visible =
|
|
1323
|
+
* false`
|
|
1324
|
+
*/
|
|
1325
|
+
lights: { sun: import('three').DirectionalLight; hemi: import('three').HemisphereLight };
|
|
1326
|
+
/** three.js perspective camera */
|
|
1327
|
+
camera: import('three').PerspectiveCamera;
|
|
1328
|
+
/**
|
|
1329
|
+
* Camera focus, updated every frame by the camera module: terrain, models etc. load around it. The center of gameplay simulation is world.anchor (the
|
|
1330
|
+
* player by default), which does not follow the camera
|
|
1331
|
+
*/
|
|
1332
|
+
focus: Vector3;
|
|
1333
|
+
/** Whether shadows are on */
|
|
1334
|
+
shadows: boolean;
|
|
1335
|
+
/** Shadow filter in use; change it with look.shadow.set({ type }) */
|
|
1336
|
+
shadowType: 'basic' | 'pcf' | 'vsm';
|
|
1337
|
+
/** Current ground */
|
|
1338
|
+
ground: Ground;
|
|
1339
|
+
/**
|
|
1340
|
+
* Shared parameters for whether a character can walk somewhere (set by createEngine({ movement }), read-only); same-named options of individual
|
|
1341
|
+
* modules are only overrides
|
|
1342
|
+
*/
|
|
1343
|
+
readonly movement: Readonly<MovementProfile>;
|
|
1344
|
+
/**
|
|
1345
|
+
* The player (exists only after characters.createPlayer()). Its position belongs to the character's mover: other systems request movement (placeAt /
|
|
1346
|
+
* move / vehicle enter), don't modify position directly
|
|
1347
|
+
*/
|
|
1348
|
+
player: Character | null;
|
|
1349
|
+
/**
|
|
1350
|
+
* World record id of the one the local user controls (default 'player'): interactions, trigger zones, marker distances, the world simulation center
|
|
1351
|
+
* and ops (ctx.actor) use it. Set it to hand control to a vehicle or squad member
|
|
1352
|
+
*/
|
|
1353
|
+
actor: string;
|
|
1354
|
+
/**
|
|
1355
|
+
* Where an actor is now (default engine.actor): the player's position for 'player' (engine.focus without a player), else its model or world record
|
|
1356
|
+
* position; null when unknown. @example engine.actor = 'boat_1'; engine.actorPosition()
|
|
1357
|
+
*/
|
|
1358
|
+
actorPosition(id?: string): { x: number; y: number; z: number } | null;
|
|
1359
|
+
/** True once start() completes and the loading screen is gone (every "is it ready" in the engine is such a boolean property) */
|
|
1360
|
+
ready: boolean;
|
|
1361
|
+
/** True after dispose() */
|
|
1362
|
+
readonly disposed: boolean;
|
|
1363
|
+
/** Execution order of module hooks (module names, first -> last), for debugging "who runs before whom" */
|
|
1364
|
+
readonly moduleOrder: string[];
|
|
1365
|
+
/**
|
|
1366
|
+
* Where each module is: 'registered' (init not started), 'initializing', 'running', 'failed' (init threw: its hooks never run) or 'disposed'.
|
|
1367
|
+
* A module installed after start() runs no fixed / frame hook until it is 'running'; `await engine.loading.settled()` waits for that
|
|
1368
|
+
*/
|
|
1369
|
+
readonly moduleStates: Record<string, 'registered' | 'initializing' | 'running' | 'failed' | 'disposed'>;
|
|
1370
|
+
/**
|
|
1371
|
+
* What this game can do, read from the existing registrations (modules, ops, save parts, describe, params schemas).
|
|
1372
|
+
* No argument: short list; a module id / op name: that entry expanded (null if unknown); { find }: the short list filtered. recipes/51-capability-catalog.md
|
|
1373
|
+
* @example engine.catalog('shop').ops[0].failures // ['soldOut', 'noMoney']
|
|
1374
|
+
*/
|
|
1375
|
+
catalog(id?: string | { find?: string }): any;
|
|
1376
|
+
/**
|
|
1377
|
+
* Gameplay error in development / testing (module hooks, onFixed / onFrame / clock callbacks, event listeners): { where (location of the error),
|
|
1378
|
+
* message }, gameplay is frozen; null when there is no error. A release build does not freeze, it reports once in the console
|
|
1379
|
+
*/
|
|
1380
|
+
readonly error: EngineError | null;
|
|
1381
|
+
/** Names of presentation modules disabled after an error (modules with presentation: true) */
|
|
1382
|
+
readonly disabledModules: Set<string>;
|
|
1383
|
+
/**
|
|
1384
|
+
* The engine's cancel signal (AbortSignal): for DOM listeners write addEventListener(type, fn, { signal: engine.signal }), removed automatically on
|
|
1385
|
+
* dispose()
|
|
1386
|
+
*/
|
|
1387
|
+
readonly signal: AbortSignal;
|
|
1388
|
+
/** UI root node: UI elements of the engine and modules hang under it (don't attach to document.body directly), the whole tree is removed on dispose() */
|
|
1389
|
+
readonly uiRoot: HTMLDivElement;
|
|
1390
|
+
/** Base fog distance (meters) */
|
|
1391
|
+
fogFar: number;
|
|
1392
|
+
/** Installed modules: name -> module definition */
|
|
1393
|
+
modules: Map<string, ModuleDef>;
|
|
1394
|
+
/** Standalone water bodies (lakes, ponds) */
|
|
1395
|
+
waterBodies: WaterBody[];
|
|
1396
|
+
/** Event bus */
|
|
1397
|
+
events: Events;
|
|
1398
|
+
/** i18n */
|
|
1399
|
+
i18n: I18n;
|
|
1400
|
+
/** Saves */
|
|
1401
|
+
saves: Saves;
|
|
1402
|
+
/** New game / continue / back to title, each from a clean slate (engine.session.newGame(), load(slot), quit()) */
|
|
1403
|
+
session: Session;
|
|
1404
|
+
/** Window focus, tab visibility, mouse lock, WebGL context: the one place that listens to them */
|
|
1405
|
+
page: Page;
|
|
1406
|
+
/** Input */
|
|
1407
|
+
input: Input;
|
|
1408
|
+
/** Audio */
|
|
1409
|
+
audio: Audio;
|
|
1410
|
+
/** Assets */
|
|
1411
|
+
assets: Assets;
|
|
1412
|
+
/** Observable loading: every asset load, module init / isReady and track() step as a task (phase, error, source manifest) */
|
|
1413
|
+
readonly loading: Loading;
|
|
1414
|
+
/** Post-processing: named effects in slots (add / get / enable / list) */
|
|
1415
|
+
post: PostFX;
|
|
1416
|
+
/** Every look in one place: engine.look.<part>.set / patch / replace (recipes/52-look.md) */
|
|
1417
|
+
look: Look;
|
|
1418
|
+
/** UI parts: every piece of screen UI is replaceable or off (see recipes/26-ui-parts.md) */
|
|
1419
|
+
ui: UIParts;
|
|
1420
|
+
/** Automatic resolution state */
|
|
1421
|
+
adaptive: AdaptiveState;
|
|
1422
|
+
/**
|
|
1423
|
+
* Main-thread CPU milliseconds of the last real-time frame: input, fixed steps, frame hooks, render submission and afterRender hooks
|
|
1424
|
+
* (not GPU time, not the wait for the next frame). Only the real-time loop updates it; step() does not.
|
|
1425
|
+
*/
|
|
1426
|
+
cpuMs: number;
|
|
1427
|
+
/** cpuMs split by phase (last frame): fixed = input + fixed steps, frame = frame hooks incl. stream / jobs, render = draw submission, afterRender = its hooks */
|
|
1428
|
+
cpuPhases: { fixed: number; frame: number; render: number; afterRender: number };
|
|
1429
|
+
/** The camera holder in charge (latest engine.takeCamera claim), null when nobody holds it. Assigning { owner } / null is the old alias of takeCamera */
|
|
1430
|
+
cameraOverride: CameraOverride | null;
|
|
1431
|
+
/** Take the camera over (camera modules leave it alone) until remove(); the latest holder is in charge, releasing hands it back to the previous one */
|
|
1432
|
+
takeCamera(owner: string | ({ owner: string } & Partial<CameraOverride>), opts?: Partial<CameraOverride>): OwnerHandle;
|
|
1433
|
+
/** Why the page is (not) advancing; the dev bridge and MCP tools copy it as-is */
|
|
1434
|
+
readonly runState: RunState;
|
|
1435
|
+
/** Draco/KTX2 decoder directory */
|
|
1436
|
+
decoders: string;
|
|
1437
|
+
/** Game clock: game seconds now, after / every (clock-time / season timers are on engine.sky) */
|
|
1438
|
+
clock: Clock;
|
|
1439
|
+
/** Story flags and counters (autosaved) */
|
|
1440
|
+
vars: Vars;
|
|
1441
|
+
/** Performance budget (off by default) */
|
|
1442
|
+
budget: Budget;
|
|
1443
|
+
/** Ray registry (what engine.raycast hits) */
|
|
1444
|
+
rays: Rays;
|
|
1445
|
+
/** Frame-spread job scheduler */
|
|
1446
|
+
jobs: Jobs;
|
|
1447
|
+
/** Background results that affect gameplay take effect on a fixed tick (chunk collision, spread jobs with apply...), see Commits */
|
|
1448
|
+
commits: Commits;
|
|
1449
|
+
/**
|
|
1450
|
+
* Worker pool (createEngine({ threads })): lane() for your own worker script, pure() for self-contained functions, array() for shared typed arrays.
|
|
1451
|
+
* Results that affect gameplay go through commits @experimental
|
|
1452
|
+
*/
|
|
1453
|
+
threads: Threads;
|
|
1454
|
+
/** One entry point for actions players and NPCs decide to do: define / run / can / list / recent, see Ops and recipes/23-ops.md */
|
|
1455
|
+
ops: Ops;
|
|
1456
|
+
/** Named fixed camera views for repeatable screenshots: define / show / release (recipes/46-blender-art-route.md) */
|
|
1457
|
+
views: Views;
|
|
1458
|
+
/** Fixed-step count (the gameplay timeline: does not advance while frozen; commits due times, event history and the operation log use it) */
|
|
1459
|
+
readonly tick: number;
|
|
1460
|
+
/** Seeded random numbers (use for gameplay randomness: reproducible and saved with the game) */
|
|
1461
|
+
random: Random;
|
|
1462
|
+
/**
|
|
1463
|
+
* Spatial stream-in and the stream sources (where the world is loaded: terrain, colliders, models, stream entries; built-in player and camera sources,
|
|
1464
|
+
* add one for a teleport destination)
|
|
1465
|
+
*/
|
|
1466
|
+
stream: Stream;
|
|
1467
|
+
/** Automatic batching: the same static model placed many times in a cell is drawn as one InstancedMesh (createEngine({ batching })) */
|
|
1468
|
+
batching: Batching;
|
|
1469
|
+
/** Startup timing report (null until start() completes) */
|
|
1470
|
+
startup: StartupReport | null;
|
|
1471
|
+
/**
|
|
1472
|
+
* Run seconds: unaffected by the sky time scale, does not advance while frozen or paused; for presentation animation (swaying, floating).
|
|
1473
|
+
* The other two "times": game seconds engine.clock.now (= fixed-step seconds x clock.timeScale, saved); sky time of day engine.sky.timeOfDay (0–1,
|
|
1474
|
+
* one day = dayLength game seconds)
|
|
1475
|
+
*/
|
|
1476
|
+
readonly elapsed: number;
|
|
1477
|
+
/**
|
|
1478
|
+
* This engine's shader uniforms, read by the built-in effects (wind, clouds, season, water, sky, rain). Share these objects in your
|
|
1479
|
+
* own ShaderMaterial or patch instead of making your own uTime. Weather and sky write them; uTime follows engine.elapsed.
|
|
1480
|
+
* @example
|
|
1481
|
+
* new THREE.ShaderMaterial({ uniforms: { uTime: engine.uniforms.uTime }, vertexShader, fragmentShader });
|
|
1482
|
+
*/
|
|
1483
|
+
readonly uniforms: EngineUniforms;
|
|
1484
|
+
/** Global water level (meters); -Infinity when there is no water */
|
|
1485
|
+
readonly waterLevel: number;
|
|
1486
|
+
|
|
1487
|
+
// ---------- Modules (undefined when not installed) ----------
|
|
1488
|
+
/** Procedural terrain (terrain() module) */
|
|
1489
|
+
terrain?: Terrain;
|
|
1490
|
+
/** Vegetation (vegetation() module; grows on terrain or on any ground provider) */
|
|
1491
|
+
vegetation?: Vegetation;
|
|
1492
|
+
/** Sky, day/night, calendar (sky() module) */
|
|
1493
|
+
sky?: Sky;
|
|
1494
|
+
/** Weather (weather() module, needs sky) */
|
|
1495
|
+
weather?: Weather;
|
|
1496
|
+
/** Water surface (water() module) */
|
|
1497
|
+
water?: Water;
|
|
1498
|
+
/** World data (world() module): things that must be saved, survive level changes and keep changing while far away; the model is built only when nearby */
|
|
1499
|
+
world?: World;
|
|
1500
|
+
/** Co-op multiplayer (net() module): host authority, clients mirror the state and request ops; see recipes/27-net.md @experimental */
|
|
1501
|
+
net?: Net;
|
|
1502
|
+
/** Placement grids: world <-> cell, occupancy derived from world records, per-cell layers, placement preview (grids() module) @experimental */
|
|
1503
|
+
grids?: Grids;
|
|
1504
|
+
/** Lightweight collision (collision() module): no clipping while walking, the camera is not blocked */
|
|
1505
|
+
collision?: Collision;
|
|
1506
|
+
/** Real physics, Rapier (rigid() module, needs collision) */
|
|
1507
|
+
rigid?: RigidBodies;
|
|
1508
|
+
/** Current camera (one of followCamera / firstPersonCamera / fixedCamera / rtsCamera) */
|
|
1509
|
+
cameraRig?: CameraRig;
|
|
1510
|
+
/**
|
|
1511
|
+
* Switch the camera at runtime (only exists with a camera module installed): the target and horizontal heading carry over; the first-person camera
|
|
1512
|
+
* hides the character body automatically (the shadow stays) and locks / releases the mouse; the camera switched out is kept, with its parameters, for
|
|
1513
|
+
* switching back.
|
|
1514
|
+
* Passing opts rebuilds this kind of camera with the new parameters. A wrong kind throws and lists the available options.
|
|
1515
|
+
* @example engine.onFrame(() => { if (engine.input.pressedRaw('toggleView')) engine.setCamera(engine.cameraRig.kind === 'follow' ? 'firstPerson' :
|
|
1516
|
+
* 'follow'); });
|
|
1517
|
+
*/
|
|
1518
|
+
setCamera?(kind: CameraKind, opts?: object): CameraRig;
|
|
1519
|
+
/** Cutscenes, tweens (timeline() module) */
|
|
1520
|
+
timeline?: Timeline;
|
|
1521
|
+
/** Hand-built level (level() module) */
|
|
1522
|
+
level?: Level;
|
|
1523
|
+
/** Trigger zones (triggers() module) */
|
|
1524
|
+
triggers?: Triggers;
|
|
1525
|
+
/**
|
|
1526
|
+
* Entities: single stateful, saved objects such as saplings, campfires and chests; the data is a record of engine.world, the model is built only when
|
|
1527
|
+
* nearby (entities() module)
|
|
1528
|
+
*/
|
|
1529
|
+
entities?: Entities;
|
|
1530
|
+
/** Particles (particles() module) */
|
|
1531
|
+
particles?: Particles;
|
|
1532
|
+
/** Settings menu (settings() module) */
|
|
1533
|
+
settings?: Settings;
|
|
1534
|
+
/** Background music (music() module) */
|
|
1535
|
+
music?: Music;
|
|
1536
|
+
/** Characters: createPlayer() (characters() module) */
|
|
1537
|
+
characters?: CharactersApi;
|
|
1538
|
+
/** NPC management (characters() module, npcs on by default) */
|
|
1539
|
+
npcs?: NPCManager;
|
|
1540
|
+
/** Interaction prompts (interactions() module) */
|
|
1541
|
+
interactions?: Interactions;
|
|
1542
|
+
/** Dialogue (dialogue() module) */
|
|
1543
|
+
dialogue?: Dialogue;
|
|
1544
|
+
/** Inventory (inventory() module) */
|
|
1545
|
+
inventory?: Inventory;
|
|
1546
|
+
/** Quests (quests() module) */
|
|
1547
|
+
quests?: Quests;
|
|
1548
|
+
/** Photo mode (photo() module) */
|
|
1549
|
+
photo?: Photo;
|
|
1550
|
+
/** Ambience (ambience() module) */
|
|
1551
|
+
ambience?: Ambience;
|
|
1552
|
+
/** Diagnostic overrides and view modes with an owner (override / clear / view: core, always there); panel is the F3 panel, null without the debug() module */
|
|
1553
|
+
debug: DebugOverrides & { panel: DebugPanel | null };
|
|
1554
|
+
/** Navmesh (nav() module) */
|
|
1555
|
+
nav?: Nav;
|
|
1556
|
+
/** HLOD, merged distant geometry (hlod() module) @experimental */
|
|
1557
|
+
hlod?: Hlod;
|
|
1558
|
+
/** Light pool: many light sources, a fixed number of real lights (lightPool() module) */
|
|
1559
|
+
lightPool?: LightPool;
|
|
1560
|
+
/** Content loading (content() module) */
|
|
1561
|
+
content?: Content;
|
|
1562
|
+
/** Game flow and scene transitions (flow() module) */
|
|
1563
|
+
flow?: Flow;
|
|
1564
|
+
/** Objective markers, counters, progress bars (hud() module) */
|
|
1565
|
+
hud?: Hud;
|
|
1566
|
+
|
|
1567
|
+
// ---------- Module system ----------
|
|
1568
|
+
/** Install one or more modules (in order; dependencies must be installed first) */
|
|
1569
|
+
use(...mods: ModuleInput[]): this;
|
|
1570
|
+
/** Whether a module is installed */
|
|
1571
|
+
has(name: string): boolean;
|
|
1572
|
+
|
|
1573
|
+
/** Material by role from this engine's style pack: engine.makeMaterial('prop', { color: 0x8a5a36 }) */
|
|
1574
|
+
makeMaterial(purpose?: string, params?: { color?: ColorLike, [prop: string]: any }): Material;
|
|
1575
|
+
|
|
1576
|
+
// ---------- Ground ----------
|
|
1577
|
+
/** Set the ground (called by the terrain and level modules); missing parts fall back to flat ground */
|
|
1578
|
+
setGround(g: Partial<Ground>): void;
|
|
1579
|
+
/**
|
|
1580
|
+
* Ground height (meters) at (x, z); a position or object also works: engine.surface(mesh.position).
|
|
1581
|
+
* For multi-layer ground (bridges, caves, interiors) pass a reference height refY: returns the highest layer not above refY + one step (0.45 m), so
|
|
1582
|
+
* standing under a bridge gives the ground and standing on it gives the deck;
|
|
1583
|
+
* without it the highest layer is used (as before). Procedural terrain and flat ground have one layer and ignore refY.
|
|
1584
|
+
* Off the outline of terrain({ shape }) it is -Infinity (no ground there; engine.ground.has(x, z) says so as a boolean)
|
|
1585
|
+
*/
|
|
1586
|
+
surface(x: number, z: number, refY?: number): number;
|
|
1587
|
+
surface(at: PositionLike, refY?: number): number;
|
|
1588
|
+
/** Slope at (x, z); a position or object also works */
|
|
1589
|
+
slope(x: number, z: number): number;
|
|
1590
|
+
slope(at: PositionLike): number;
|
|
1591
|
+
/** Ground type at (x, z) (for footsteps, particles); a position or object also works. 'void' off the outline of terrain({ shape }) */
|
|
1592
|
+
groundType(x: number, z: number): string;
|
|
1593
|
+
groundType(at: PositionLike): string;
|
|
1594
|
+
/**
|
|
1595
|
+
* Water surface height at (x, z): standalone water bodies first, otherwise the global water level; -Infinity when there is no water. A position or
|
|
1596
|
+
* object also works
|
|
1597
|
+
*/
|
|
1598
|
+
waterAt(x: number, z: number): number;
|
|
1599
|
+
waterAt(at: PositionLike): number;
|
|
1600
|
+
/**
|
|
1601
|
+
* Put an object on the ground under it (y = ground height + offset) and return the object. With multi-layer ground the object's current y is the
|
|
1602
|
+
* reference height
|
|
1603
|
+
*/
|
|
1604
|
+
snapToGround<T = Object3D>(obj: T, offset?: number): T;
|
|
1605
|
+
/** Add a water body (give radius for a circle, halfWidth / halfDepth for a rectangle) and return a handle { body, remove() }. The water module draws it */
|
|
1606
|
+
addWaterBody(opts: WaterBodyOptions): Handle & { body: WaterBody };
|
|
1607
|
+
|
|
1608
|
+
// ---------- Common ----------
|
|
1609
|
+
/** Get UI text (i18n) */
|
|
1610
|
+
t(key: string, params?: Record<string, any>): string;
|
|
1611
|
+
/**
|
|
1612
|
+
* Add objects to the scene and register them (engine.thing), returns the first one. The last argument may be { id?, save? }: id makes thing.set /
|
|
1613
|
+
* thing.remove changes saved (unique, no '#', one object per call); without it a unique obj.name is used, else a session id obj#n. save: true asks dev
|
|
1614
|
+
* to warn when it cannot be saved. engine.scene.add adds without registering.
|
|
1615
|
+
* @example engine.add(windmill, { id: 'windmill' });
|
|
1616
|
+
*/
|
|
1617
|
+
add<T = Object3D>(obj: T, ...more: (Object3D | { id?: string; save?: boolean })[]): T;
|
|
1618
|
+
/**
|
|
1619
|
+
* What a thing is and what a save keeps: a world record id, an engine.add id or name, or any Object3D (its registered ancestor). object is the live
|
|
1620
|
+
* Object3D (not enumerable). Throws with the closest id when nothing matches. Change it with ops.run('thing.set' | 'thing.remove', { id, ... }).
|
|
1621
|
+
* @example engine.thing('windmill').saved // 'code'
|
|
1622
|
+
*/
|
|
1623
|
+
thing(idOrObj: string | Object3D): Thing;
|
|
1624
|
+
/**
|
|
1625
|
+
* Fully delete an object (use it when you no longer want the object): removes it from its parent, unregisters rays, and releases the geometry and
|
|
1626
|
+
* materials of it and its children (textures and geometry / materials shared by assets are not released)
|
|
1627
|
+
*/
|
|
1628
|
+
remove(...objs: Object3D[]): void;
|
|
1629
|
+
/** Only take it off its parent without releasing GPU memory (use when you will add it back later). Use remove for objects you no longer need */
|
|
1630
|
+
detach(...objs: Object3D[]): void;
|
|
1631
|
+
/**
|
|
1632
|
+
* Fixed-step logic (60 times per second, dt in fixed seconds): movement, physics, cooldowns, and gameplay keys (read pressed() here: a per-step
|
|
1633
|
+
* snapshot, independent of frame rate). Returns a handle { remove() }
|
|
1634
|
+
*/
|
|
1635
|
+
onFixed(fn: (dt: number) => void): Handle;
|
|
1636
|
+
/**
|
|
1637
|
+
* Once per frame (dt in frame seconds): animation, camera, UI and UI keys (menus read this frame's latest input). Gameplay keys belong in onFixed.
|
|
1638
|
+
* Returns a handle { remove() }
|
|
1639
|
+
*/
|
|
1640
|
+
onFrame(fn: (dt: number) => void): Handle;
|
|
1641
|
+
|
|
1642
|
+
// ---------- Settings ----------
|
|
1643
|
+
/** Render resolution */
|
|
1644
|
+
setPixelRatio(p: number): void;
|
|
1645
|
+
/** Shadow toggle */
|
|
1646
|
+
setShadows(on: boolean): void;
|
|
1647
|
+
/** Fog distance (meters), also adjusts the camera far plane */
|
|
1648
|
+
setFogFar(d: number): void;
|
|
1649
|
+
/** Exposure per frame from style.exposure / look.tone keyframes or function, null for a plain number; the sky module calls it with engine.sky @readonly */
|
|
1650
|
+
exposureDriver: ((sky: any) => number) | null;
|
|
1651
|
+
|
|
1652
|
+
// ---------- Rays, scenarios ----------
|
|
1653
|
+
/** Ray: shoot from origin along dir, returns the nearest hit or null (by default only registered static objects are hit) */
|
|
1654
|
+
raycast(origin: Vec3Like, dir: Vec3Like, opts?: RaycastOptions): RayHit | null;
|
|
1655
|
+
/** Shoot a ray through the camera from screen coordinates (-1..1, e.g. input.pointer.ndcX/ndcY) */
|
|
1656
|
+
pick(ndcX: number, ndcY: number, opts?: RaycastOptions): RayHit | null;
|
|
1657
|
+
/**
|
|
1658
|
+
* New runtime instance of a content template (inside an op or fixed step), saved whole; returns the world record (kind = template name). Needs content().
|
|
1659
|
+
* e.g. engine.spawn('chest', { x: 10, z: 4 }, { opened: true })
|
|
1660
|
+
*/
|
|
1661
|
+
spawn(name: string, at: any, fields?: { id?: string; rot?: number; scale?: number; y?: number; items?: Record<string, number>; [stateField: string]: any }): import('./generated/modules/world/World').WorldRecord;
|
|
1662
|
+
/** Set up a scenario: time of day, weather, player position, load a save, advance time, skip cutscenes; emits state:applied when done */
|
|
1663
|
+
applyState(params: StateParams): Promise<void>;
|
|
1664
|
+
/** Name a group of scenario parameters, then use applyState({ state: name }) or URL ?state=name */
|
|
1665
|
+
defineState(name: string, params: StateParams): this;
|
|
1666
|
+
/**
|
|
1667
|
+
* Scenario is ready: start() completed, and the URL parameters / the latest applyState have all been applied. Tests and screenshots wait for it:
|
|
1668
|
+
* page.waitForFunction(() => window.engine?.stateApplied)
|
|
1669
|
+
*/
|
|
1670
|
+
readonly stateApplied: boolean;
|
|
1671
|
+
|
|
1672
|
+
// ---------- Start, pause, state ----------
|
|
1673
|
+
/** Start: initialize modules, preload assets, wait for the world to be ready */
|
|
1674
|
+
start(): Promise<this>;
|
|
1675
|
+
/** Whether in headless mode (createEngine({ headless: true })) */
|
|
1676
|
+
headless: boolean;
|
|
1677
|
+
/** Whether paused (headless mode is paused by default, only step() advances) */
|
|
1678
|
+
paused: boolean;
|
|
1679
|
+
/** Smoothed frame rate */
|
|
1680
|
+
fps: number;
|
|
1681
|
+
/** Ids of the open windows */
|
|
1682
|
+
openWindows: Set<string>;
|
|
1683
|
+
/**
|
|
1684
|
+
* Pause the real-time loop: the picture stops and even rendering stops, only step() advances (for tests and screenshots). Use freeze() for a game menu
|
|
1685
|
+
* pause
|
|
1686
|
+
*/
|
|
1687
|
+
pause(owner?: string | { owner?: string; kind?: 'test' }, opts?: { kind?: 'test' }): ChainedHandle;
|
|
1688
|
+
/** Resume the real-time loop (only this owner's pause) */
|
|
1689
|
+
resume(owner?: string | { owner?: string }): this;
|
|
1690
|
+
/** Run fn at the start of the next fixed step (via commits); a Promise of fn's value */
|
|
1691
|
+
nextFixed<T>(fn: () => T): Promise<T>;
|
|
1692
|
+
/**
|
|
1693
|
+
* Gameplay pause (menu, flow's paused): fixed steps are skipped entirely (onFixed, module fixed, the game clock and engine.elapsed all stop), frame
|
|
1694
|
+
* hooks and rendering continue and the UI works.
|
|
1695
|
+
* So gameplay logic (movement, timing, quest checks, cutscene waits) belongs in fixed, or check engine.frozen first in frame. owner is the freezer's
|
|
1696
|
+
* name, default 'game'
|
|
1697
|
+
*/
|
|
1698
|
+
freeze(owner?: string | { owner?: string; kind?: 'title' }, opts?: { kind?: 'title' }): ChainedHandle;
|
|
1699
|
+
/** Release the freeze of owner (gameplay resumes only when all freezers are released) */
|
|
1700
|
+
unfreeze(owner?: string | { owner?: string }): this;
|
|
1701
|
+
/** Is anyone freezing gameplay? */
|
|
1702
|
+
readonly frozen: boolean;
|
|
1703
|
+
/**
|
|
1704
|
+
* Advance seconds of fixed-step time synchronously; seconds must be a finite number >= 0: 0 advances nothing (no step, no render),
|
|
1705
|
+
* negative or non-finite throws (code step-seconds), any positive value runs at least one fixed step (60Hz; when timeScale is not 1,
|
|
1706
|
+
* game seconds clock.now and sky time of day run faster or slower than it;
|
|
1707
|
+
* frame hooks run once every frameEvery fixed steps, default 2; describe: false returns null instead of building describe()).
|
|
1708
|
+
* jobs ignore real time and finish every frame; results of stream's synchronous build are attached to the scene before returning. When render is true
|
|
1709
|
+
* (default) one frame is rendered at the end. Returns the describe() result after advancing
|
|
1710
|
+
*/
|
|
1711
|
+
step(seconds: number, opts?: { render?: boolean; frameEvery?: number; describe?: boolean }): GameState | null;
|
|
1712
|
+
/**
|
|
1713
|
+
* Skip game time forward (sleep until morning, wait an hour) without stepping every fixed step.
|
|
1714
|
+
* clock.after / every, sky.at / daily / between, day:start and season:change fire in time order as if stepped (each crossing once);
|
|
1715
|
+
* world records with far catch up the span in one far(rec, dt). onFixed, module fixed hooks, physics and near simulation do not run;
|
|
1716
|
+
* engine.elapsed does not move. Input is locked and gameplay frozen during the skip; emits time:skip.
|
|
1717
|
+
* fade 0 (default): the time has moved when skip returns. fade > 0: fade out, jump, save, fade in; the Promise resolves after the fade in (it needs frames).
|
|
1718
|
+
* session.newGame / load / quit cancel a running skip: it resolves null.
|
|
1719
|
+
* @example await engine.skip({ to: '06:00' })
|
|
1720
|
+
* @example await engine.skip({ to: '06:00', fade: 0.6, save: 'auto' })
|
|
1721
|
+
* @example engine.skip({ seconds: 600 })
|
|
1722
|
+
*/
|
|
1723
|
+
skip(opts: SkipOptions): Promise<{ seconds: number; clock: string | null; day: number | null } | null>;
|
|
1724
|
+
/**
|
|
1725
|
+
* Consistency check: engine.skip({ seconds }) vs stepping the same span in fixed steps; compares the saved state. Leaves the world at the stepped state (use a scratch playthrough or a test).
|
|
1726
|
+
* @param ignore state paths (or prefixes) not to compare
|
|
1727
|
+
* @returns a = after skip, b = after stepping
|
|
1728
|
+
* @example const r = await engine.checkSkip(600); if (!r.ok) console.log(r.diffs);
|
|
1729
|
+
*/
|
|
1730
|
+
checkSkip(seconds: number, opts?: { ignore?: string[] }): Promise<{ ok: boolean; diffs: { path: string; a: any; b: any }[] }>;
|
|
1731
|
+
/**
|
|
1732
|
+
* Consistency check: save -> load gives the same saved state back (nothing is written to the browser).
|
|
1733
|
+
* @example const r = await engine.checkSave(); if (!r.ok) console.log(r.diffs);
|
|
1734
|
+
*/
|
|
1735
|
+
checkSave(opts?: { ignore?: string[] }): Promise<{ ok: boolean; diffs: { path: string; a: any; b: any }[] }>;
|
|
1736
|
+
/**
|
|
1737
|
+
* Call engine.describe(opts?: { radius?: number }) to get the current game state (a plain object, JSON.stringify-able); radius is how far counts as
|
|
1738
|
+
* "nearby" (meters, default 30).
|
|
1739
|
+
* engine.describe.add(name, fn) registers the game's own state in one line: the return value of fn(engine, ctx) goes into describe().<name>, and the
|
|
1740
|
+
* returned handle's remove() cancels it.
|
|
1741
|
+
* Small games use add; big games write the system as a module and use the module's describe hook. Example: engine.describe.add('range', () => ({
|
|
1742
|
+
* score, targets: targets.length }))
|
|
1743
|
+
*/
|
|
1744
|
+
describe: {
|
|
1745
|
+
(opts?: { radius?: number; center?: { x: number; z: number } }): GameState;
|
|
1746
|
+
add(name: string, fn: (e: Engine, ctx: DescribeContext) => any): { remove(): void };
|
|
1747
|
+
};
|
|
1748
|
+
/**
|
|
1749
|
+
* The same information as English text, summary first: at most 30 lines (standard lines, the 5 nearest things, one line per module with its key
|
|
1750
|
+
* counts), ending with how to expand.
|
|
1751
|
+
* { path: 'world.byKind' } returns one part of describe() as JSON; { full: true } returns everything (all nearby things, every module's full data).
|
|
1752
|
+
* @example engine.describeText() engine.describeText({ path: 'quests' }) engine.describeText({ full: true })
|
|
1753
|
+
*/
|
|
1754
|
+
describeText(opts?: { radius?: number; full?: boolean; path?: string }): string;
|
|
1755
|
+
/**
|
|
1756
|
+
* What is around an actor or a spot, and what that actor can do now (each op offer checked with can, possible first, at most 8; failed ones carry
|
|
1757
|
+
* reason and the op's reasons note).
|
|
1758
|
+
* at: a world record id (that actor), [x, z] / { x, z } (a spot, ops as the player), or nothing (the player). radius default 10 m.
|
|
1759
|
+
* @example engine.inspect(); // { actor: 'player', at: { x, z }, near: [...], ops: [{ op: 'shop.buy', args, ok: false, reason: 'noMoney',
|
|
1760
|
+
* why: 'Not enough gold' }] }
|
|
1761
|
+
* @example engine.inspect('enemy_3'); // why is this enemy not attacking: its ops and their reasons
|
|
1762
|
+
* @example engine.inspect('chest-home').thing.definedAt // 'content/props.js:14': edit that line to change the level for good
|
|
1763
|
+
* thing (when at is a record id): the record as a thing to change, with where it was authored (see HitThing).
|
|
1764
|
+
*/
|
|
1765
|
+
inspect: {
|
|
1766
|
+
(at?: string | { x: number; z: number } | number[], opts?: { radius?: number }): {
|
|
1767
|
+
actor: string; at: { x: number; z: number }; near: any[]; thing?: HitThing;
|
|
1768
|
+
ops: { op: string; args: any; ok: boolean; reason?: string; why?: string | null }[];
|
|
1769
|
+
};
|
|
1770
|
+
/**
|
|
1771
|
+
* The mesh exists but is not drawn: use this first. Lists every Mesh / Points / Line / Sprite in the scene (name, type, world position, bounding radius,
|
|
1772
|
+
* material type and purpose, visible, drawn) and, for each one that is not drawn, every reason found, most likely first: own or ancestor visible = false,
|
|
1773
|
+
* layers not matching the camera, material flags (visible, opacity 0, colorWrite / depthWrite off), scale 0 or NaN, NaN position or vertices, empty geometry
|
|
1774
|
+
* or draw range, behind the camera, beyond camera.far, outside the frustum, bounding radius 0 or NaN, swallowed by fog. Computed on call only.
|
|
1775
|
+
* hidden: only the objects not drawn. limit: how many to list (default 40; counts cover everything). text is the same thing as lines to read.
|
|
1776
|
+
* @example engine.inspect.scene({ hidden: true }).items[0].reasons // [{ code: 'hidden-ancestor', level: 'hidden', text, fix }]
|
|
1777
|
+
* @example engine.inspect.scene().text
|
|
1778
|
+
*/
|
|
1779
|
+
scene(opts?: { hidden?: boolean; limit?: number }): SceneInspect;
|
|
1780
|
+
};
|
|
1781
|
+
/**
|
|
1782
|
+
* Why something is the way it is. { op, args?, actor? }: text says whether it can run now, and if not the reason and the op's note on fixing it
|
|
1783
|
+
* (reason first);
|
|
1784
|
+
* detail has the last attempt and the events around it; recent / events are the raw last 5 attempts and event names within a step of the last one.
|
|
1785
|
+
* Other keys are answered by modules (definition field explain: { key(e, value, query) { return { ok, text } } }); the quests module answers { quest: id }.
|
|
1786
|
+
* @example engine.explain({ op: 'shop.buy', args: { shop: 'bakery', item: 'bread' } }).text // 'shop.buy {...} cannot run now: noMoney (Not enough gold)'
|
|
1787
|
+
* @example engine.explain({ quest: 'first-light' }).text // which step it waits on
|
|
1788
|
+
* An op whose args.id names a world record also says where that record was authored (text ends with "defined in content/props.js:14: edit it there…";
|
|
1789
|
+
* thing has the rest).
|
|
1790
|
+
*/
|
|
1791
|
+
explain(q: { op: string; args?: any; actor?: string } | Record<string, any>): {
|
|
1792
|
+
ok: boolean; reason?: string | null; text: string; detail?: string; recent?: any[]; events?: string[]; thing?: HitThing;
|
|
1793
|
+
};
|
|
1794
|
+
/**
|
|
1795
|
+
* Module hook timing: pass true to turn on, false to turn off (returns the engine); with no argument returns { moduleName: average milliseconds per
|
|
1796
|
+
* rendered frame } and resets, or null when not on
|
|
1797
|
+
*/
|
|
1798
|
+
profile(on: boolean): this;
|
|
1799
|
+
profile(): Record<string, number> | null;
|
|
1800
|
+
/**
|
|
1801
|
+
* Destroy the engine: stop the main loop, call each module's dispose(e) in reverse install order, then reclaim listeners, timers, audio, UI and GPU
|
|
1802
|
+
* memory (scene, assets cache, post-processing, renderer).
|
|
1803
|
+
* After that no callbacks fire and step() returns null. Safe to call repeatedly. Don't use it for level changes; use level.track(handle)
|
|
1804
|
+
*/
|
|
1805
|
+
dispose(): void;
|
|
1806
|
+
/**
|
|
1807
|
+
* Counts for leak hunting: they should not keep growing after repeatedly entering / leaving levels or opening / closing windows. geometries / textures
|
|
1808
|
+
* come from three.js renderer.info.memory (counted only after rendering)
|
|
1809
|
+
*/
|
|
1810
|
+
counts(): EngineCounts;
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
/** Result of engine.counts() */
|
|
1814
|
+
/** engine.error and the engine:error event: where and why, plus a stable code, the fix and the pages to read (from the error or the hint table) */
|
|
1815
|
+
export interface EngineError {
|
|
1816
|
+
/** Where it happened, e.g. "fixed hook of module quests" or "load() of save part 'inventory'" */
|
|
1817
|
+
where: string;
|
|
1818
|
+
/** The error message (English) */
|
|
1819
|
+
message: string;
|
|
1820
|
+
/** Stable code (e.g. 'save-load-threw', 'world-plain'); null for an unknown error */
|
|
1821
|
+
code: string | null;
|
|
1822
|
+
/** What to do about it; null when unknown */
|
|
1823
|
+
fix: string | null;
|
|
1824
|
+
/** Doc pages to read, relative to the package docs */
|
|
1825
|
+
docs: string[];
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
export interface EngineCounts {
|
|
1829
|
+
/** Number of event listeners */
|
|
1830
|
+
listeners: number;
|
|
1831
|
+
/** Number of onFixed callbacks */
|
|
1832
|
+
fixed: number;
|
|
1833
|
+
/** Number of onFrame callbacks */
|
|
1834
|
+
frame: number;
|
|
1835
|
+
/** Number of clock timers (after / every); sky clock-time timers are in sky.timers */
|
|
1836
|
+
timers: number;
|
|
1837
|
+
/** Number of static meshes registered for rays */
|
|
1838
|
+
statics: number;
|
|
1839
|
+
/** Number of stream registrations */
|
|
1840
|
+
streamEntries: number;
|
|
1841
|
+
/** Unfinished tasks in the jobs queue */
|
|
1842
|
+
jobs: number;
|
|
1843
|
+
/** Requests in commits that have not yet taken effect */
|
|
1844
|
+
commits: number;
|
|
1845
|
+
/** Geometries in GPU memory (three.js renderer.info.memory) */
|
|
1846
|
+
geometries: number;
|
|
1847
|
+
/** Textures in GPU memory (three.js renderer.info.memory) */
|
|
1848
|
+
textures: number;
|
|
1849
|
+
/** Only with world() installed: records is the record count, views the number of records with a built model */
|
|
1850
|
+
world?: { records: number; views: number };
|
|
1851
|
+
/** Only with rigid() installed: number of rigid bodies */
|
|
1852
|
+
rigid?: number;
|
|
1853
|
+
/** Only with particles() installed: alive is the number of live particles, emitters the number of attached emitters */
|
|
1854
|
+
particles?: { alive: number; emitters: number };
|
|
1855
|
+
/** Only with sky() installed: timers is the number of at / between / daily / onSeason timers */
|
|
1856
|
+
sky?: { timers: number };
|
|
1857
|
+
/** Any other module's counts(e) hook result, under the module name */
|
|
1858
|
+
[module: string]: any;
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
// ======================================================================
|
|
1862
|
+
// Game state description engine.describe()
|
|
1863
|
+
// ======================================================================
|
|
1864
|
+
|
|
1865
|
+
/** A nearby thing: dist is the distance (meters), dir the compass heading (north = -Z), rel relative to the camera heading */
|
|
1866
|
+
export interface NearbyThing {
|
|
1867
|
+
name?: string;
|
|
1868
|
+
/** 'npc' | 'pickup' | 'interactable' | 'trigger' | 'entity' ... */
|
|
1869
|
+
kind?: string;
|
|
1870
|
+
dist: number;
|
|
1871
|
+
dir: 'N' | 'NE' | 'E' | 'SE' | 'S' | 'SW' | 'W' | 'NW';
|
|
1872
|
+
rel: 'front' | 'front-right' | 'right' | 'back-right' | 'back' | 'back-left' | 'left' | 'front-left';
|
|
1873
|
+
x: number; z: number;
|
|
1874
|
+
/** Prompt text when interactable */
|
|
1875
|
+
use?: string;
|
|
1876
|
+
[key: string]: any;
|
|
1877
|
+
}
|
|
1878
|
+
/** Result of engine.describe(). The standard fields are below; the return values of each module's describe hook are added separately, keyed by module name */
|
|
1879
|
+
export interface GameState {
|
|
1880
|
+
ready: boolean;
|
|
1881
|
+
/** Gameplay error in development / testing (gameplay is frozen), null when there is none */
|
|
1882
|
+
error: EngineError | null;
|
|
1883
|
+
/** Presentation modules disabled after an error */
|
|
1884
|
+
disabledModules: string[];
|
|
1885
|
+
/** Modules that are initializing or failed ({ name: state }); absent when every module with an init is running (engine.moduleStates has all) */
|
|
1886
|
+
moduleStates?: Record<string, string>;
|
|
1887
|
+
/** What loading is waiting for, what failed, whether it blocks the start (engine.loading.view()) */
|
|
1888
|
+
loading: LoadingView;
|
|
1889
|
+
/** elapsed is the run seconds (= engine.elapsed); with the sky module there are also clock, day, season, isDay, timeOfDay */
|
|
1890
|
+
time: {
|
|
1891
|
+
elapsed: number; paused: boolean; frozen: boolean; headless: boolean; clock?: string; day?: number; season?: string; isDay?: boolean;
|
|
1892
|
+
[key: string]: any;
|
|
1893
|
+
};
|
|
1894
|
+
/** Player (null when there is no player), position in meters */
|
|
1895
|
+
/** ground is the ground type, groundName its display name (i18n key ground.<type>, null if none) */
|
|
1896
|
+
player: {
|
|
1897
|
+
x: number; y: number; z: number; ground: string; groundName: string | null; inWater: boolean; state: string | null;
|
|
1898
|
+
running: boolean; jumping: boolean; [key: string]: any;
|
|
1899
|
+
} | null;
|
|
1900
|
+
/** Camera: type 'follow' | 'first' | 'fixed' | 'rts', override is the takeover owner's name */
|
|
1901
|
+
camera: { type: string | null; x: number; y: number; z: number; focus: { x: number; z: number }; override: string | null; [key: string]: any };
|
|
1902
|
+
/** How far counts as nearby (meters) */
|
|
1903
|
+
nearbyRadius: number;
|
|
1904
|
+
/** Nearby things, sorted by distance (at most 15) */
|
|
1905
|
+
nearby: NearbyThing[];
|
|
1906
|
+
/** UI: open windows, whether input is locked, the dialogue in progress */
|
|
1907
|
+
/** windows: open windows and full-screen UI parts (e.g. 'title'); parts: each UI part 'default' | 'custom' | 'off' */
|
|
1908
|
+
ui: {
|
|
1909
|
+
windows: string[]; inputLocked: boolean; parts: Record<string, string>; [key: string]: any;
|
|
1910
|
+
dialogue: { speaker: string; text: string; choices: string[]; [key: string]: any } | null;
|
|
1911
|
+
};
|
|
1912
|
+
/** Cutscenes: count is how many are playing, skippable whether they can be skipped */
|
|
1913
|
+
cutscene: { count: number; skippable: boolean; [key: string]: any } | null;
|
|
1914
|
+
/** Installed module names */
|
|
1915
|
+
modules: string[];
|
|
1916
|
+
/**
|
|
1917
|
+
* engine.add / world things by save tier (counts only) and what will not survive a load: unsaved ('obj#3 (main.js:88, made during play by op x)'),
|
|
1918
|
+
* conflicts (two systems managing one object), orphans (saved ids no object has); atCapped when dev stopped taking stacks
|
|
1919
|
+
*/
|
|
1920
|
+
scene: { game: number; code: number; session: number; world: number; engine: number; unsaved: string[]; conflicts: string[]; orphans: string[]; atCapped?: boolean };
|
|
1921
|
+
/** Performance (fps/cpuMs are null while paused) */
|
|
1922
|
+
perf: {
|
|
1923
|
+
fps: number | null; cpuMs: number | null; drawCalls: number; triangles: number; pixelRatio: number;
|
|
1924
|
+
chunks?: { loaded: number; visible: number; queued: number }; budget?: BudgetReport | null; startup?: StartupReport | null;
|
|
1925
|
+
/** cpuMs by phase (null while paused), see Engine.cpuPhases */
|
|
1926
|
+
cpu?: { fixed: number; frame: number; render: number; afterRender: number } | null;
|
|
1927
|
+
/** Cost of applying background results by stage: transit, build, collider, upload, stream (see engine.budget.cost; upload and transit are approximations) */
|
|
1928
|
+
apply?: Record<string, { n: number; totalMs: number; maxMs: number; frameMs: number; bytes: number }>;
|
|
1929
|
+
/** Stream registry: registered, built, queued */
|
|
1930
|
+
stream?: { entries: number; built: number; queued: number };
|
|
1931
|
+
/** Automatic batching: batches, instances, draw calls saved per pass */
|
|
1932
|
+
batching?: BatchingStats;
|
|
1933
|
+
/** Number of unfinished frame-spread jobs */
|
|
1934
|
+
jobs?: number; [key: string]: any };
|
|
1935
|
+
/**
|
|
1936
|
+
* Weather module additions: name (label is the display name), rain, snow, fog intensity 0–1, progress is the transition progress 0–1, rainVisible /
|
|
1937
|
+
* snowVisible whether raindrops / snowflakes are drawn right now (object names weather-rain / weather-snow)
|
|
1938
|
+
*/
|
|
1939
|
+
weather?: any;
|
|
1940
|
+
/** Content added by other modules */
|
|
1941
|
+
[module: string]: any;
|
|
1942
|
+
}
|
|
1943
|
+
/** ctx received by a module's describe(e, ctx) hook */
|
|
1944
|
+
export interface DescribeContext {
|
|
1945
|
+
/** The result being generated; you can fill in the standard fields (e.g. ctx.out.time.clock = '18:30') */
|
|
1946
|
+
out: GameState;
|
|
1947
|
+
/** How far counts as nearby (meters) */
|
|
1948
|
+
radius: number;
|
|
1949
|
+
/** Center of the search (the player or the focus) */
|
|
1950
|
+
center: Vector3;
|
|
1951
|
+
/** Report a nearby thing: at is an object or {x, z}; reporting the same at several times merges them, weak = true only fills empty fields */
|
|
1952
|
+
near(at: Object3D | { x: number; z: number }, info: { name?: string; kind?: string; [key: string]: any }, weak?: boolean): void;
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
/** engine.skip options: pass to or seconds */
|
|
1956
|
+
export interface SkipOptions {
|
|
1957
|
+
/** Until the sky clock next reads this time ('HH:MM' or 0-1; needs sky). The current time itself means a full day */
|
|
1958
|
+
to?: string | number;
|
|
1959
|
+
/** Game seconds to skip (> 0) */
|
|
1960
|
+
seconds?: number;
|
|
1961
|
+
/** Fade out / in seconds (default 0: no fade, the jump happens before skip returns) */
|
|
1962
|
+
fade?: number;
|
|
1963
|
+
/** Save slot written after the jump, before the fade in (true = 'auto') */
|
|
1964
|
+
save?: string | boolean;
|
|
1965
|
+
}
|