threedog 0.7.0 → 1.0.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 +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -12
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -19
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/{core → render}/shadows.js +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Grid.d.ts +1 -0
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +5 -4
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
|
@@ -19,11 +19,13 @@
|
|
|
19
19
|
// The speaker defaults to the script name; set speaker: '另一个人' on a node to switch speakers.
|
|
20
20
|
// Advancing and picking a choice are the ops dialogue.advance and dialogue.choose { index } (recipes/23-ops.md): keys, the cursor, clicks, the dev bridge and
|
|
21
21
|
// tests all run them, so a choice's do (which may change gameplay state) always runs inside a logged op.
|
|
22
|
+
import { keepTable } from '../../core/base/sections.js';
|
|
22
23
|
import { uiFocus } from '../../ui/UI.js';
|
|
23
|
-
import { warnMissing, warnOnce } from '../../core/validate.js';
|
|
24
|
-
import {
|
|
24
|
+
import { warnMissing, warnOnce, fmt } from '../../core/base/validate.js';
|
|
25
|
+
import { reportError } from '../../core/base/errors.js';
|
|
26
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
25
27
|
import { dialogueBox } from './dialogueBox.js';
|
|
26
|
-
import { codedError } from '../../core/errorHints.js';
|
|
28
|
+
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
27
29
|
import { Bubbles, bubblePart } from './dialogueBubbles.js';
|
|
28
30
|
// 'data' is the one slot for game-specific fields: other unknown keys stay typos (a misspelled next would silently end the dialogue)
|
|
29
31
|
const NODE_KEYS = ['text', 'next', 'choices', 'do', 'speaker', 'data'], CHOICE_KEYS = ['text', 'next', 'if', 'do', 'data'];
|
|
@@ -34,17 +36,19 @@ const STR = {
|
|
|
34
36
|
channel: "dialogue: channel '{got}' is not one of 'main' (the conversation the player reads, locks input) | 'bubble' (a line over its speaker while play goes on)",
|
|
35
37
|
bubbleChoices: "[dialogue] '{name}' node '{id}' has choices: choices need the main channel (the player picks them), so on the bubble channel the script ends there",
|
|
36
38
|
};
|
|
37
|
-
const checkChannel = c => { if (!CHANNELS.includes(c)) throw codedError('module-params', STR.channel
|
|
39
|
+
const checkChannel = c => { if (!CHANNELS.includes(c)) throw codedError('module-params', fmt(STR.channel, { got: String(c) })); };
|
|
38
40
|
const SAY_KEYS = ['speaker', 'node', 'channel', 'at', 'seconds', 'queue', 'onCancel'], START_KEYS = ['channel', 'at', 'onCancel'];
|
|
39
|
-
// 0.2 lock: false is now channel: 'bubble'; if not caught, old code would silently take the main channel and lock input (the opposite behavior), so name the new form first, then run the generic unknown-key check
|
|
40
41
|
const readLine = (fn, keys, o) => readParams(`dialogue.${fn}`, keysSchema(keys), o ?? {});
|
|
41
42
|
|
|
42
43
|
export class Dialogue {
|
|
43
|
-
constructor(engine, { charsPerSecond = 40, advanceActions = ['confirm'], holdSeconds = 2 } = {}) {
|
|
44
|
+
constructor(engine, { charsPerSecond = 40, advanceActions = ['confirm'], holdSeconds = 2, bubbleChoice = 'end' } = {}) {
|
|
44
45
|
this.engine = engine;
|
|
46
|
+
// a bubble script reaching a node with choices: 'end' (warn, the script ends there) or 'ask' (the line stays with its choices until dialogue.choose { index, run })
|
|
47
|
+
if (bubbleChoice !== 'end' && bubbleChoice !== 'ask') throw codedError('module-params', `dialogue({ bubbleChoice }): 'end' (default) or 'ask'; got ${JSON.stringify(bubbleChoice)}`);
|
|
48
|
+
this.bubbleChoice = bubbleChoice; /** @internal run id -> { opts, pick(i) } for bubble lines waiting for a choice */ this._asks = new Map(); this._askSeq = 0;
|
|
45
49
|
this.scripts = new Map();
|
|
46
50
|
this.state = { get flags() { return engine.vars.flags; } }; // story flags = engine.vars.flags (autosaved)
|
|
47
|
-
this.
|
|
51
|
+
this.charsPerSecond = charsPerSecond;
|
|
48
52
|
// default: confirm only (a basic key). Other actions advance only when the game names them: advanceActions: ['confirm', 'interact']
|
|
49
53
|
this.advanceActions = advanceActions;
|
|
50
54
|
this.holdSeconds = holdSeconds;
|
|
@@ -91,18 +95,28 @@ export class Dialogue {
|
|
|
91
95
|
_playBubbles(name, nodeId, onEnd, { at = null, seconds, queue } = {}) {
|
|
92
96
|
const nodes = this.scripts.get(name);
|
|
93
97
|
let stopped = false, cur = null;
|
|
98
|
+
let asking = 0;
|
|
99
|
+
const actor = this.engine.ops.actor; // who it opened for, as on the main channel (_by)
|
|
94
100
|
const finish = () => { if (!stopped) { stopped = true; onEnd?.(); } };
|
|
95
101
|
const step = id => {
|
|
96
102
|
const node = id && id !== 'end' && nodes[id];
|
|
97
103
|
if (!node || stopped) { finish(); return; }
|
|
98
|
-
|
|
104
|
+
const opts = node.choices?.length && this.bubbleChoice === 'ask' ? node.choices.filter(c => !c.if || c.if(this.state, this.engine)) : null;
|
|
105
|
+
if (node.choices?.length && !opts) { warnOnce(fmt(STR.bubbleChoices, { name, id })); finish(); return; }
|
|
99
106
|
const text = typeof node.text === 'function' ? node.text(this.state, this.engine) : node.text;
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
if (!this._do(node)) { finish(); return; }
|
|
108
|
+
const speaker = node.speaker || (name.startsWith('__say_') ? '' : name);
|
|
109
|
+
if (opts?.length) { // 'ask': the line stays up with its choices until one is picked (dialogue.choose { index, run })
|
|
110
|
+
const run = asking = ++this._askSeq, label = c => typeof c.text === 'function' ? c.text(this.state, this.engine) : c.text;
|
|
111
|
+
cur = this._bubbles.say(at, text, { speaker, seconds: Infinity, queue, run, choices: opts.map(label) });
|
|
112
|
+
this._asks.set(run, { opts, actor, pick: i => { const c = opts[i]; this._asks.delete(run); asking = 0; cur.remove(); step(this._do(c) ? c.next || 'end' : 'end'); } });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
cur = this._bubbles.say(at, text, { speaker, seconds, queue });
|
|
102
116
|
cur.then(() => step(node.next || 'end'));
|
|
103
117
|
};
|
|
104
118
|
step(nodeId);
|
|
105
|
-
return { remove: () => { stopped || cur?.remove(); finish(); } };
|
|
119
|
+
return { remove: () => { this._asks.delete(asking); stopped || cur?.remove(); finish(); } };
|
|
106
120
|
}
|
|
107
121
|
|
|
108
122
|
/**
|
|
@@ -116,9 +130,9 @@ export class Dialogue {
|
|
|
116
130
|
// wrong name: warn with the fix and still call onEnd (so an NPC waiting on it and the say() Promise don't hang)
|
|
117
131
|
if (!nodes) { warnMissing('dialogue', speaker, [...this.scripts.keys()].filter(k => !k.startsWith('__say_'))); onEnd?.(); return; }
|
|
118
132
|
if (channel === 'bubble') { this._playBubbles(speaker, nodeId, onEnd, { at }); return; }
|
|
119
|
-
|
|
133
|
+
while (this.active) this.end(); // end a running dialogue normally first (runs its onEnd so NPCs don't hang); an onEnd may open the next one, which ends too
|
|
120
134
|
// join the UI focus stack (Esc swallowed unless onCancel; the choice cursor lives on this entry) and lock game input with an opaque context
|
|
121
|
-
this.active = { speaker, nodes, onEnd, focus: uiFocus(this.engine).push('dialogue', { cancel: onCancel }), ctx: this.engine.input.push('dialog', { owner: 'dialogue' }) };
|
|
135
|
+
this.active = { speaker, nodes, onEnd, actor: this.engine.ops.actor, focus: uiFocus(this.engine).push('dialogue', { cancel: onCancel }), ctx: this.engine.input.push('dialog', { owner: 'dialogue' }), duringLoad: this.engine.saves.replacing };
|
|
122
136
|
this.part = this.engine.ui.get('dialogue');
|
|
123
137
|
this.part?.show();
|
|
124
138
|
this.engine.events.emit('dialogue:start', speaker);
|
|
@@ -134,9 +148,9 @@ export class Dialogue {
|
|
|
134
148
|
a?.onEnd?.();
|
|
135
149
|
if (a) this.engine.events.emit('dialogue:end', a.speaker);
|
|
136
150
|
}
|
|
137
|
-
/** @internal session:end: close the dialogue without its onEnd (that callback belongs to the old playthrough: an NPC's busy flag, a say() Promise); drop bubbles */
|
|
151
|
+
/** @internal session:end or a load: close the dialogue without its onEnd (that callback belongs to the old playthrough: an NPC's busy flag, a say() Promise); drop bubbles */
|
|
138
152
|
_cancel() {
|
|
139
|
-
this._bubbles.clear();
|
|
153
|
+
this._bubbles.clear(); this._asks.clear();
|
|
140
154
|
const a = this.active;
|
|
141
155
|
if (!a) return;
|
|
142
156
|
a.onEnd = null;
|
|
@@ -144,19 +158,27 @@ export class Dialogue {
|
|
|
144
158
|
this.end();
|
|
145
159
|
}
|
|
146
160
|
|
|
161
|
+
/** @internal A node's or choice's do. One that throws ends the conversation, as a throwing step ends a cutscene: a line nobody can finish would keep the keys and a say() waiting */
|
|
162
|
+
_do(x) {
|
|
163
|
+
try { x.do?.(this.state, this.engine); return true; } catch (err) { reportError(this.engine, err, 'dialogue do', { soft: true }); return false; }
|
|
164
|
+
}
|
|
165
|
+
|
|
147
166
|
_show(id) {
|
|
148
|
-
const a = this.active
|
|
167
|
+
const a = this.active;
|
|
168
|
+
if (!a) return; // a dialogue:start listener ended it
|
|
169
|
+
const node = id && a.nodes[id];
|
|
149
170
|
if (!node && id && id !== 'end') warnMissing('node', id, Object.keys(a.nodes)); // next points at a node that doesn't exist
|
|
150
171
|
if (!node || id === 'end') { this.end(); return; }
|
|
151
172
|
a.node = node; a.id = id;
|
|
152
173
|
a.focus.setNav(null); // no choices while the new line types
|
|
153
174
|
const text = typeof node.text === 'function' ? node.text(this.state, this.engine) : node.text;
|
|
154
|
-
|
|
175
|
+
if (!this._do(node)) { this.end(); return; } // read the line before running effects, so it doesn't see flags just changed
|
|
155
176
|
if (this.active !== a) return; // do ended the dialogue or started another
|
|
156
177
|
a.who = node.speaker || a.speaker;
|
|
157
178
|
this.full = String(text ?? ''); this.shown = 0; this.typing = true; this._opts = null;
|
|
158
179
|
this.engine.events.emit('dialogue:line', { script: a.speaker, node: id, speaker: a.who, text: this.full, data: node.data ?? {} });
|
|
159
|
-
if (
|
|
180
|
+
if (this.active !== a) return; // a dialogue:line listener ended it (a skip key)
|
|
181
|
+
if (!this.full || !(this.charsPerSecond > 0)) this._finishTyping(); // charsPerSecond 0 = whole line at once
|
|
160
182
|
else this._draw();
|
|
161
183
|
}
|
|
162
184
|
|
|
@@ -170,13 +192,15 @@ export class Dialogue {
|
|
|
170
192
|
// key: the first bound key only ('1', not '1/Numpad1'), so a rebound choice key shows its new name
|
|
171
193
|
this._choices = opts.map((c, i) => ({ text: label(c), key: i < 9 ? e.input.label('choice' + (i + 1)).split('/')[0] || null : null, data: c.data ?? {} }));
|
|
172
194
|
// the choice cursor: the menu keys / d-pad / stick move it, confirm picks (the same op as a click or a number key); the part draws view.selected
|
|
173
|
-
if (this._opts) a.focus.setNav({ count: () => this._choices.length, moved: () => this._draw(), confirm: i => e.ops.run('dialogue.choose', { index: i },
|
|
195
|
+
if (this._opts) a.focus.setNav({ count: () => this._choices.length, moved: () => this._draw(), confirm: i => e.ops.run('dialogue.choose', { index: i }, this._by) });
|
|
174
196
|
this._draw();
|
|
175
197
|
}
|
|
176
198
|
|
|
199
|
+
/** @internal who presses on in this conversation: the actor it was opened for (a seat, an NPC's op), so what its choices give does not land on the local player */
|
|
200
|
+
get _by() { return { source: 'player', actor: this.active?.actor }; }
|
|
177
201
|
/** @internal hand the current line to the UI part: plain data plus advance() / choose(i), which run the ops */
|
|
178
202
|
_draw() {
|
|
179
|
-
const a = this.active, e = this.engine, P =
|
|
203
|
+
const a = this.active, e = this.engine, P = this._by;
|
|
180
204
|
const hint = !this.typing && !this._opts ? e.t('dialogue.continue', { key: e.input.label(this.advanceActions[0]) }) : '';
|
|
181
205
|
this.part?.update({
|
|
182
206
|
script: a.speaker, node: a.id, speaker: a.who, text: this.full.slice(0, Math.floor(this.shown)), full: this.full, typing: this.typing,
|
|
@@ -201,7 +225,7 @@ export class Dialogue {
|
|
|
201
225
|
if (this.typing) this._finishTyping(); // mid-typing: finish the sentence (choices appear) before picking
|
|
202
226
|
if (!this._opts?.[i]) return;
|
|
203
227
|
const c = this._opts[i], a = this.active;
|
|
204
|
-
|
|
228
|
+
if (!this._do(c)) { this.end(); return; }
|
|
205
229
|
if (this.active === a) this._show(c.next || 'end'); // do ended the dialogue or started another: its next belongs to the old one
|
|
206
230
|
}
|
|
207
231
|
|
|
@@ -213,13 +237,13 @@ export class Dialogue {
|
|
|
213
237
|
const ops = this.engine.ops;
|
|
214
238
|
if (this.typing) {
|
|
215
239
|
const was = Math.floor(this.shown);
|
|
216
|
-
this.shown = Math.min(this.full.length, this.shown + dt * this.
|
|
240
|
+
this.shown = Math.min(this.full.length, this.shown + dt * this.charsPerSecond);
|
|
217
241
|
if (this.shown >= this.full.length) this._finishTyping();
|
|
218
242
|
else if (Math.floor(this.shown) !== was) this._draw(); // redraw only when another character shows
|
|
219
243
|
}
|
|
220
244
|
// just opened this frame (the press that opened it does not advance), or the choice cursor already used confirm this frame
|
|
221
245
|
if (a.focus.fresh || a.focus.consumed) return;
|
|
222
|
-
const input = this.engine.input, P =
|
|
246
|
+
const input = this.engine.input, P = this._by;
|
|
223
247
|
if (this.advanceActions.some(x => input.pressedRaw(x))) ops.run('dialogue.advance', {}, P);
|
|
224
248
|
for (let i = 1; i <= 9; i++) if (input.pressedRaw('choice' + i) && this.active && this._visible()[i - 1]) ops.run('dialogue.choose', { index: i - 1 }, P);
|
|
225
249
|
}
|
|
@@ -230,14 +254,44 @@ const STRINGS = {
|
|
|
230
254
|
en: { 'module.dialogue': 'dialogue', 'dialogue.continue': '{key} to continue ▸', 'dialogue.choice': 'Choose option' },
|
|
231
255
|
};
|
|
232
256
|
|
|
233
|
-
const DIALOGUE_PARAMS = keysSchema(['charsPerSecond', 'advanceActions', 'holdSeconds']);
|
|
257
|
+
const DIALOGUE_PARAMS = keysSchema(['charsPerSecond', 'advanceActions', 'holdSeconds', 'bubbleChoice']);
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The dialogues section of content data. A line can be several variants [{ if: condition, text }, ..., { text }]; the first whose condition holds is used.
|
|
261
|
+
* When none holds the line is empty and a warning names it: throwing inside the dialogue's op would leave the conversation stuck on that node.
|
|
262
|
+
*/
|
|
263
|
+
const variants = (content, at, list) => () => {
|
|
264
|
+
const hit = list.find(v => content.test(v.if));
|
|
265
|
+
if (!hit) warnOnce(coded('content-misuse', `content ${at}: no variant's "if" holds and there is no variant without "if", so the line is empty. ` +
|
|
266
|
+
'End the list with a plain { text } as the fallback'), at);
|
|
267
|
+
return hit?.text ?? '';
|
|
268
|
+
};
|
|
269
|
+
const DIALOGUE_CONTENT = {
|
|
270
|
+
desc: 'dialogues (id -> speaker, nodes)',
|
|
271
|
+
undo: (d, { engine: e }) => keepTable(e.dialogue.scripts),
|
|
272
|
+
commit(d, { engine: e, content }) {
|
|
273
|
+
for (const [id, def] of Object.entries(d)) {
|
|
274
|
+
const nodes = {};
|
|
275
|
+
for (const [nid, n] of Object.entries(def.nodes ?? {})) {
|
|
276
|
+
nodes[nid] = {
|
|
277
|
+
...n, speaker: n.speaker ?? def.speaker,
|
|
278
|
+
text: Array.isArray(n.text) ? variants(content, `dialogues.${id}.nodes.${nid}.text`, n.text) : n.text,
|
|
279
|
+
do: n.do && (() => content.run(n.do)),
|
|
280
|
+
choices: n.choices?.map(ch => ({ ...ch, if: ch.if && (() => content.test(ch.if)), do: ch.do && (() => content.run(ch.do)) })),
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
e.dialogue.define(id, nodes);
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
};
|
|
234
287
|
|
|
235
288
|
/** Dialogue module. Installs engine.dialogue; story flags engine.dialogue.state.flags are engine.vars.flags. Declares the UI parts 'dialogue' and 'dialogue.bubble'. */
|
|
236
289
|
export function dialogue(opts = {}) {
|
|
237
290
|
readParams('dialogue', DIALOGUE_PARAMS, opts);
|
|
238
291
|
let d = null;
|
|
239
292
|
return {
|
|
240
|
-
|
|
293
|
+
content: { dialogues: DIALOGUE_CONTENT },
|
|
294
|
+
name: 'dialogue', skipKind: 'none', type: 'rules', provides: ['dialogue'], params: DIALOGUE_PARAMS, options: opts, label: 'Dialogue', stage: 'gameplay', after: ['interactions'],
|
|
241
295
|
install(e, ctx) {
|
|
242
296
|
e.i18n.add(STRINGS);
|
|
243
297
|
d = new Dialogue(e, opts);
|
|
@@ -245,33 +299,38 @@ export function dialogue(opts = {}) {
|
|
|
245
299
|
// (basic menu keys + confirm) and clicks pick choices without them. Context 'dialog', so 1-9 stay free for hotbars outside a conversation
|
|
246
300
|
for (let i = 1; i <= 9; i++) ctx.input.action('choice' + i, { context: 'dialog', label: 'dialogue.choice', optional: true });
|
|
247
301
|
ctx.track(e.events.on('session:end', () => d._cancel())); // an open dialogue belongs to the playthrough that opened it
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
302
|
+
ctx.ui.define('dialogue', dialogueBox);
|
|
303
|
+
ctx.ui.define('dialogue.bubble', bubblePart, { multi: true });
|
|
304
|
+
ctx.ops.define('dialogue.advance', {
|
|
251
305
|
desc: 'Finish typing the line, or go on to the next one',
|
|
252
306
|
net: 'local', // in co-op each player reads their own dialogue box; ops it runs (give, start a quest) still go to the host
|
|
253
307
|
can: () => d.active ? true : 'noDialogue',
|
|
254
308
|
run: () => { d._advance(); },
|
|
255
309
|
offers: () => d.active && !d._opts ? [{}] : [],
|
|
256
310
|
});
|
|
257
|
-
|
|
258
|
-
desc: 'Pick a visible dialogue choice (0-based)', args: { index: 'int' },
|
|
311
|
+
ctx.ops.define('dialogue.choose', {
|
|
312
|
+
desc: 'Pick a visible dialogue choice (0-based); run: the bubble line asking (dialogue.bubbles() run), none = the main conversation', args: { index: 'int', run: 'int?' },
|
|
259
313
|
net: 'local',
|
|
260
|
-
can: (e, { index }) => !d.active ? 'noDialogue' : d._visible()[index] ? true : 'noChoice',
|
|
261
|
-
run: (e, { index }) => { d._choose(index); },
|
|
262
|
-
offers: () => d.active ? d._visible().map((c, index) => ({ index })) : [],
|
|
314
|
+
can: (e, { index, run }) => run != null ? (d._asks.get(run)?.opts[index] ? true : 'noChoice') : !d.active ? 'noDialogue' : d._visible()[index] ? true : 'noChoice',
|
|
315
|
+
run: (e, { index, run }) => { if (run != null) d._asks.get(run)?.pick(index); else d._choose(index); },
|
|
316
|
+
offers: () => [...(d.active ? d._visible().map((c, index) => ({ index })) : []), ...[...d._asks].flatMap(([run, a]) => a.opts.map((c, index) => ({ index, run })))],
|
|
263
317
|
});
|
|
264
318
|
return d;
|
|
265
319
|
},
|
|
266
320
|
frame(dt) { d.frame(dt); },
|
|
321
|
+
// unloaded mid-conversation: the input context and focus entry are the conversation's, not tracked, and a say() Promise gets its end. Not on engine.dispose: waits stay pending there
|
|
322
|
+
dispose(e) { if (!e.disposed) { d._bubbles.clear(); d._asks.clear(); d.end(); } },
|
|
323
|
+
afterLoad() { if (!d.active?.duringLoad) d._cancel(); }, // a line open at a load belongs to the state thrown away; one a load opened stays
|
|
267
324
|
describe(e, ctx) {
|
|
268
325
|
const a = d.active, bubbles = d.bubbles();
|
|
269
326
|
if (!a && !bubbles.length) return;
|
|
270
327
|
const label = c => (typeof c.text === 'function' ? c.text(d.state, e) : c.text);
|
|
271
328
|
if (ctx.out.ui) {
|
|
272
|
-
if (a) ctx.out.ui.dialogue = { speaker: a.who, text: d.full, typing: d.typing, choices: (d._opts || []).map(label), selected: d._opts ? a.focus.index ?? 0 : -1 };
|
|
329
|
+
if (a) ctx.out.ui.dialogue = { speaker: a.who, text: d.full, typing: d.typing, choices: (d._opts || []).map(label), selected: d._opts ? a.focus.index ?? 0 : -1, advance: d.advanceActions.map(x => e.input.label(x)).join(' / ') };
|
|
273
330
|
if (bubbles.length) ctx.out.ui.bubbles = bubbles;
|
|
274
331
|
}
|
|
275
332
|
},
|
|
276
333
|
};
|
|
277
334
|
}
|
|
335
|
+
|
|
336
|
+
export const handRolled = [{ kind: 'dialogue', seen: 'a dialogue box of its own', use: 'engine.dialogue.define(speaker, nodes) and the dialogue part: typing on game time, choices, input lock (recipe 02, recipe 26)', quiet: /\b(engine|e|eng|ctx)\.dialogue\b|\bdialogue\(\s*[{)]/, code: /\b(createElement|innerHTML|className|classList|getElementById|querySelector|\.id)\b/, raw: /(?:createElement|innerHTML|className|classList|getElementById|querySelector|\.id\b)[^,;{}]*(?:dialog(?:ue)?|speech|subtitle|textbox|conversation)|(?:dialog(?:ue)?|speech|subtitle|textbox|conversation)[^,;{}]*(?:createElement|innerHTML|className|classList|getElementById|querySelector|\.id\b)/i }];
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
// Using one is the op interaction.use { id?, action? } (recipes/23-ops.md): the interact key (in fixed), a click on the prompt, the dev bridge and tests all
|
|
5
5
|
// run it,
|
|
6
6
|
// so every use is logged and checked by the same can (exists, enabled, in range, input not locked). Without id it uses the one the actor would pick now.
|
|
7
|
-
// Who interacts is engine.actor (core/actor.js), measured with engine.actorPosition(): the player by default, a vehicle or squad member when the game says so
|
|
7
|
+
// Who interacts is engine.actor (core/ops/actor.js), measured with engine.actorPosition(): the player by default, a vehicle or squad member when the game says so.
|
|
8
|
+
// A seat (engine.input.seat) presses for its own seat.actor; the prompt and the options stay engine.actor's, since one screen shows one prompt;
|
|
8
9
|
// the op's ctx.actor (a net peer, an NPC) is handed to label / enabled / onUse as (object, { actor }).
|
|
9
10
|
// How the one in front of you is chosen is the pick option: 'nearest' | 'facing' | 'aim' | a function (see interactions()). Each action is picked on its own,
|
|
10
11
|
// so one object can carry "Open" and "Lock" as two interactions with different action names (each bound to the game's own key).
|
|
@@ -16,7 +17,7 @@
|
|
|
16
17
|
// once: true hides the object after a use that went through and it stays gone; counter: 'shells' adds 1 to that HUD counter (optional: engine.hud?.). So a
|
|
17
18
|
// mesh the game already built is a pick-and-count thing with no world record or bag; what was used is this module's save part, because a thing that comes
|
|
18
19
|
// back after a load while the count does not would be silently lost progress. Things that go in a bag, respawn or are decided by a net host: pickups.js.
|
|
19
|
-
// Finding candidates goes through one shared xz index (core/cells.js) keyed by each item's actual world position, instead of measuring every interaction
|
|
20
|
+
// Finding candidates goes through one shared xz index (core/stream/cells.js) keyed by each item's actual world position, instead of measuring every interaction
|
|
20
21
|
// each frame. Before a pick pass reads it, items that follow an object are re-filed if they moved: for an object straight under the scene (models, pickups,
|
|
21
22
|
// hand-placed meshes) the check is its local position against the last one seen, so a still crowd costs a few compares; a nested one (a part of a vehicle)
|
|
22
23
|
// is measured. Why the actual position and not the world record's: a game may move a record's model away from its record, and the item must be found where
|
|
@@ -26,11 +27,15 @@ import * as THREE from 'three';
|
|
|
26
27
|
import { worldToScreen } from '../../ui/UI.js';
|
|
27
28
|
import { promptPart } from './interactionPrompt.js';
|
|
28
29
|
|
|
29
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
30
|
-
import { codedError } from '../../core/errorHints.js';
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
30
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
31
|
+
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
32
|
+
import { reportError } from '../../core/base/errors.js';
|
|
33
|
+
import { failure } from '../../core/ops/opsFail.js';
|
|
34
|
+
import { refuseSave } from '../../core/base/saveValues.js';
|
|
35
|
+
import { isPlainObject } from '../../core/base/util.js';
|
|
36
|
+
import { DEV, warnOnce } from '../../core/base/validate.js';
|
|
37
|
+
import { vec3 } from '../../core/base/math.js';
|
|
38
|
+
import { Cells } from '../../core/stream/cells.js';
|
|
34
39
|
|
|
35
40
|
const PICKS = ['nearest', 'facing', 'aim'];
|
|
36
41
|
// 'facing': within 60° either side of where the actor faces (wide enough for a gamepad stick, narrow enough that doors behind you stay dark)
|
|
@@ -49,12 +54,12 @@ const bindLine = action => action === 'interact' ? 'createEngine({ bindings: { .
|
|
|
49
54
|
const SETUP_FIX = "e.g. engine.use(interactions({ ...presets.interactions.nearest })) (import { presets } from 'threedog'), or interactions({ pick: 'nearest' | 'facing' | 'aim' | fn })";
|
|
50
55
|
|
|
51
56
|
export class Interactions {
|
|
52
|
-
constructor(engine, { action, promptHeight, radius, pick } = {},
|
|
57
|
+
constructor(engine, { action, promptHeight, radius, pick } = {}, ctx) {
|
|
53
58
|
// No default pick and no default key: which object counts as "in front of you" and which key uses it are the game's choices (genericity rule:
|
|
54
59
|
// core carries no preset). presets.interactions.* are the picks, presets.bindings.interact the keys (declared here, bound by the game).
|
|
55
60
|
if (pick === undefined) throw codedError('interaction-setup', `interactions(): no pick given; ${SETUP_FIX}`);
|
|
56
61
|
if (typeof pick !== 'function' && !PICKS.includes(pick)) throw codedError('interaction-setup', `interactions({ pick }): '${pick}' is not a pick mode. Use ${PICKS.map(p => `'${p}'`).join(' | ')} or a function (candidates, ctx) => candidate`);
|
|
57
|
-
track(engine.input.action(action, { label: 'input.interact', owner: 'interactions' }));
|
|
62
|
+
ctx.track(engine.input.action(action, { label: 'input.interact', owner: 'interactions' }));
|
|
58
63
|
this.engine = engine;
|
|
59
64
|
this.action = action;
|
|
60
65
|
this.radius = radius;
|
|
@@ -82,8 +87,8 @@ export class Interactions {
|
|
|
82
87
|
this._seq = 0; this._order = 0;
|
|
83
88
|
/** @internal non-zero during one fixed() / update() pass: each item's world position is computed once per pass, not once per action */ this._pass = 0;
|
|
84
89
|
this._passes = 0;
|
|
85
|
-
engine.input.touchButton(action, 'input.interact');
|
|
86
|
-
|
|
90
|
+
ctx.track(engine.input.touchButton(action, 'input.interact'));
|
|
91
|
+
ctx.ui.define('prompt', promptPart);
|
|
87
92
|
/** @internal clicking the prompt: the same op as the interact key */
|
|
88
93
|
this._use = () => { if (this.current) engine.ops.run('interaction.use', { id: this.current.id }, { source: 'player' }); };
|
|
89
94
|
this._shown = false;
|
|
@@ -92,7 +97,8 @@ export class Interactions {
|
|
|
92
97
|
/** @internal dev: an add since the last key check */ this._keysDue = false;
|
|
93
98
|
/** @internal ids of the once items already used; _counted: counter name -> what uses added. The saved state, so both follow a load and a new game */
|
|
94
99
|
this._spent = new Set(); this._counted = new Map();
|
|
95
|
-
|
|
100
|
+
/** @internal ids of the once items whose async onUse has not settled: not spent yet, but not usable twice either */ this._waiting = new Set();
|
|
101
|
+
ctx.saves.register('interactions', { atomic: true, version: 1, save: () => ({ spent: [...this._spent], counted: Object.fromEntries(this._counted) }), load: d => this._load(d) });
|
|
96
102
|
}
|
|
97
103
|
|
|
98
104
|
/**
|
|
@@ -102,9 +108,10 @@ export class Interactions {
|
|
|
102
108
|
* radius defaults to interactions({ radius }) (2.5 m; Infinity = from anywhere, usually with approach). Add two with different actions to give one object
|
|
103
109
|
* two verbs. hold: seconds the key must stay down (progress goes to the prompt; release, leaving reach or disabled interrupts it: interaction:interrupt).
|
|
104
110
|
* approach: true walks the player there first (walkTo, stops 1.2 m away), then uses it. Returns a handle { remove() }.
|
|
105
|
-
* once: true hides the object after a use and it cannot be used again (onUse returning { ok: false } leaves it
|
|
111
|
+
* once: true hides the object after a use and it cannot be used again (onUse returning { ok: false } leaves it, also when an async onUse resolves to it or rejects: the use is judged
|
|
112
|
+
* when it settles, and the item cannot be used again meanwhile); saved, and back on a new game. The save
|
|
106
113
|
* knows it by id, else the object's name; development throws when it has neither. counter: name of a HUD counter that each use
|
|
107
|
-
* adds 1 to (hud.
|
|
114
|
+
* adds 1 to (hud.bump; nothing without hud()); declare it once at setup with hud.counter(name, { label, value: 0, max }), not on session:start.
|
|
108
115
|
* label, enabled and onUse are called with (object, { actor }): actor is the world record id of who asks / uses it (engine.actor for the local user,
|
|
109
116
|
* a net peer's or an NPC's id when they run interaction.use), so per-actor rules never read engine.player.
|
|
110
117
|
* @example engine.interactions.add(door, { label: (o, { actor }) => owns(actor) ? 'Open' : 'Knock', onUse: (o, { actor }) => engine.ops.run('door.open', { id: o.name }, { actor }) });
|
|
@@ -116,6 +123,8 @@ export class Interactions {
|
|
|
116
123
|
* engine.interactions.add(clerk, { label: 'Talk', radius: Infinity, approach: true, onUse: talk }); // from anywhere: walk over, then talk
|
|
117
124
|
* @example // onUse may return a result; interaction.use hands it back as value. Returning { ok: false, code } (failure(code)) fails the op with that code:
|
|
118
125
|
* const r = engine.ops.run('interaction.use'); if (!r.ok) say(r.code) // 'full' for a pickup in a full bag
|
|
126
|
+
* @example // an async onUse: the op is ok once it started, and its value is a Promise of the answer (never a rejection: a throw answers { ok: false, code: 'error' })
|
|
127
|
+
* const r = engine.ops.run('interaction.use', { id: 'shrine' }); const a = await r.value; if (a?.ok === false) say(a.code);
|
|
119
128
|
*/
|
|
120
129
|
add(target, opts = {}) {
|
|
121
130
|
readParams('interactions.add()', keysSchema(['id', 'label', 'radius', 'action', 'onUse', 'enabled', 'height', 'hold', 'approach', 'once', 'counter']), opts);
|
|
@@ -125,16 +134,16 @@ export class Interactions {
|
|
|
125
134
|
if (counter !== undefined && !(typeof counter === 'string' && counter)) throw codedError('interaction-option', `interactions.add(): counter is the name of a HUD counter (counter: 'shells'), got ${JSON.stringify(counter)}`, TypeError);
|
|
126
135
|
// stable id for the interaction.use op: given, else the world record being built (pickup, NPC, entity), else (once: the save knows it by id) the mesh's
|
|
127
136
|
// name, else a running number. The number counts adds over the page's life, so it means another thing after a rebuild: a once item kept under one
|
|
128
|
-
// comes back after a load while its count stays, or hides the wrong thing. So once refuses it
|
|
137
|
+
// comes back after a load while its count stays, or hides the wrong thing. So once refuses it, and the fix is one word
|
|
129
138
|
let id = opts.id ?? this.engine.world?.buildingId ?? (once && target?.name || null);
|
|
130
|
-
if (once &&
|
|
139
|
+
if (once && (id == null || this.get(id))) throw codedError('interaction-option', `interactions.add(): a once item is saved by its id, and this one has ${id == null ? 'none' : `the same id as another ('${id}')`}. Give each a stable one: { id: 'shell-3', once: true }, or set mesh.name`, TypeError);
|
|
131
140
|
id ??= 'interaction' + (++this._seq);
|
|
132
141
|
if (this.get(id)) id += '#' + (++this._seq);
|
|
133
142
|
let object = target;
|
|
134
143
|
if (!target?.isObject3D) { object = new THREE.Object3D(); vec3(target, object.position); }
|
|
135
144
|
// a fixed position never moves: its world position is known now; an object is measured once per pass (_at)
|
|
136
145
|
// a used once item is simply not enabled: pick, the hold, describe and the op's can all ask enabled, so none of them needs a rule of its own
|
|
137
|
-
const enabled = once ? (o, c) => !this._spent.has(id) && allowed(o, c) : allowed;
|
|
146
|
+
const enabled = once ? (o, c) => !this._spent.has(id) && !this._waiting.has(id) && allowed(o, c) : allowed;
|
|
138
147
|
const it = { id, object, label, radius, action, onUse, enabled, height, hold, approach: !!approach, once: !!once, counter, _p: new THREE.Vector3(), _at: target?.isObject3D ? -1 : Infinity,
|
|
139
148
|
_n: this._order++, _en: null, _ix: null, _lx: NaN, _lz: NaN, _par: undefined };
|
|
140
149
|
if (!target?.isObject3D) it._p.copy(object.position);
|
|
@@ -143,11 +152,22 @@ export class Interactions {
|
|
|
143
152
|
this._index(it);
|
|
144
153
|
return { remove: () => { if (it._gone) return; it._gone = true; this._byId.delete(it.id); this._unindex(it); if (this.current === it) this.current = null; } };
|
|
145
154
|
}
|
|
146
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* @internal Every use ends here (key, click, hold, approach, op), and is judged when onUse has settled, sync or async. An async one hands back a Promise of the same answer,
|
|
157
|
+
* which never rejects: the key press that started it has nobody listening. A state replaced while it waited is not the state it was used in, so it spends nothing there
|
|
158
|
+
*/
|
|
147
159
|
_run(it, actor) {
|
|
148
|
-
const r = it.onUse?.(it.object, { actor });
|
|
160
|
+
const e = this.engine, r = it.onUse?.(it.object, { actor });
|
|
161
|
+
if (typeof r?.then !== 'function') return this._judge(it, r);
|
|
162
|
+
const state = e.saves.generation;
|
|
163
|
+
this._waiting.add(it.id);
|
|
164
|
+
return r.then(v => e.saves.generation === state ? e.ops.allow(() => this._judge(it, v)) : v, err => { reportError(e, err, `interaction '${it.id}' onUse`, { soft: true }); return failure('error'); })
|
|
165
|
+
.finally(() => { if (e.saves.generation === state) this._waiting.delete(it.id); });
|
|
166
|
+
}
|
|
167
|
+
/** @internal once and counter count only a use that went through */
|
|
168
|
+
_judge(it, r) {
|
|
149
169
|
if (r?.ok === false) return r;
|
|
150
|
-
if (it.counter && this.engine.hud) { this.engine.hud.
|
|
170
|
+
if (it.counter && this.engine.hud) { this.engine.hud.bump(it.counter); this._counted.set(it.counter, (this._counted.get(it.counter) ?? 0) + 1); }
|
|
151
171
|
// shortcut: once lives on the local peer (interaction.use is net: 'local'); a thing all peers share in a net game is a pickup (the host decides)
|
|
152
172
|
if (it.once) { this._spent.add(it.id); it.object.visible = false; }
|
|
153
173
|
return r;
|
|
@@ -156,12 +176,16 @@ export class Interactions {
|
|
|
156
176
|
* @internal Load or new game. A counter gets the difference, not a value: its base is the game's (hud.counter(name, { value })), this module only knows
|
|
157
177
|
* what uses added. Only things whose state changed are shown or hidden: a once item the game hid itself stays hidden
|
|
158
178
|
*/
|
|
159
|
-
_load(
|
|
179
|
+
_load(d) {
|
|
180
|
+
const { spent, counted } = d ?? {};
|
|
181
|
+
if (!Array.isArray(spent) || !spent.every(id => typeof id === 'string') || !isPlainObject(counted) || !Object.values(counted).every(Number.isFinite))
|
|
182
|
+
refuseSave('interactions', 'the part', 'must be { spent: [id], counted: { id: number } }', d);
|
|
160
183
|
const was = this._spent; this._spent = new Set(spent);
|
|
184
|
+
if (this.engine.saves.replacing) this._waiting.clear(); // a load, not an atomic rollback: what was waiting belongs to the state just left
|
|
161
185
|
for (const it of this._byId.values()) if (it.once && was.has(it.id) !== this._spent.has(it.id)) it.object.visible = !this._spent.has(it.id);
|
|
162
186
|
for (const name of new Set([...this._counted.keys(), ...Object.keys(counted)])) {
|
|
163
187
|
const d = (counted[name] ?? 0) - (this._counted.get(name) ?? 0);
|
|
164
|
-
if (d) this.engine.hud?.
|
|
188
|
+
if (d) this.engine.hud?.bump(name, d);
|
|
165
189
|
}
|
|
166
190
|
this._counted = new Map(Object.entries(counted));
|
|
167
191
|
}
|
|
@@ -219,8 +243,8 @@ export class Interactions {
|
|
|
219
243
|
return C;
|
|
220
244
|
}
|
|
221
245
|
|
|
222
|
-
/** The interaction with this id (
|
|
223
|
-
get(id) { return this._byId.get(id)
|
|
246
|
+
/** The interaction with this id (undefined if none). @param {string} id */
|
|
247
|
+
get(id) { return this._byId.get(id); }
|
|
224
248
|
/** All interactions in the order added (a fresh array each read) */
|
|
225
249
|
get items() { return [...this._byId.values()]; }
|
|
226
250
|
|
|
@@ -235,7 +259,7 @@ export class Interactions {
|
|
|
235
259
|
// 'aim' follows the camera, which only the local user looks through; anyone else aims where they face
|
|
236
260
|
const aim = mode === 'aim' && actor === e.actor;
|
|
237
261
|
// the actor's body, for its facing
|
|
238
|
-
const obj = mode === 'nearest' || aim ? null : actor === 'player' && e.player ? e.player.root : e.world?.view(actor) ?? null;
|
|
262
|
+
const obj = mode === 'nearest' || aim ? null : actor === 'player' && e.player ? e.player.root : e.control.characterOf(actor)?.root ?? e.world?.view(actor) ?? null;
|
|
239
263
|
if (obj) { obj.getWorldDirection(D); D.y = 0; D.normalize(); }
|
|
240
264
|
if (aim) { e.camera.getWorldPosition(O); e.camera.getWorldDirection(D); }
|
|
241
265
|
let best = null, bestS = Infinity;
|
|
@@ -282,31 +306,43 @@ export class Interactions {
|
|
|
282
306
|
const c = fn(list, { engine: this.engine, actor, position: pos, action });
|
|
283
307
|
return c ? this.get(c.id) : null;
|
|
284
308
|
}
|
|
309
|
+
/** @internal The key went down and nothing was used: logged like a refused interaction.use, with the same codes. A record, not a warning: tapping E in a menu is normal play */
|
|
310
|
+
_pressRefused(action, reason, actor = this.engine.actor) { const e = this.engine; e.ops.refused('interaction.use', { action, ...(reason === 'inputLocked' && { by: lockFacts(e).by }) }, { reason, actor, source: 'player' }); }
|
|
285
311
|
/** Fixed step: each action's key fires that action's pick (input snapshot, frame-rate independent; picked on the spot, not from last frame). @internal */
|
|
286
312
|
fixed(dt) {
|
|
287
313
|
const inp = this.engine.input;
|
|
288
|
-
if (!inp.enabled) {
|
|
314
|
+
if (!inp.enabled) {
|
|
315
|
+
if (this._hold) this._interrupt('inputLocked');
|
|
316
|
+
// a press that does nothing still leaves a trace: an open dialogue swallowed every E, and the game's test could only report "have 0"
|
|
317
|
+
for (const a of this._actions.keys()) if (inp.pressedRaw(a)) this._pressRefused(a, 'inputLocked');
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
289
320
|
this._pass = ++this._passes;
|
|
290
321
|
if (this._hold) this._tickHold(dt);
|
|
322
|
+
this._presses(inp, this.engine.actor);
|
|
323
|
+
for (const s of inp.seats) if (s.actor) this._presses(s, s.actor);
|
|
324
|
+
this._pass = 0;
|
|
325
|
+
}
|
|
326
|
+
/** @internal The presses of one input, engine.input or a seat, for the actor it acts for. One hold at a time: a press during someone's hold waits for it to end */
|
|
327
|
+
_presses(input, actor) {
|
|
291
328
|
for (const a of this._actions.keys()) {
|
|
292
|
-
if (!
|
|
293
|
-
const b = this.pick(
|
|
294
|
-
if (!b) continue;
|
|
295
|
-
if (b.hold > 0) { this._hold = { it: b, action: a, t: 0 }; this._holdView(); this.engine.events.emit('interaction:hold', { id: b.id, action: a, seconds: b.hold }); }
|
|
296
|
-
else this.engine.ops.run('interaction.use', { id: b.id }, { source: 'player' });
|
|
329
|
+
if (!input.pressed(a) || this._hold) continue;
|
|
330
|
+
const b = this.pick(actor, a);
|
|
331
|
+
if (!b) { this._pressRefused(a, 'nothingNear', actor); continue; }
|
|
332
|
+
if (b.hold > 0) { this._hold = { it: b, action: a, t: 0, input, actor }; this._holdView(); this.engine.events.emit('interaction:hold', { id: b.id, action: a, seconds: b.hold }); }
|
|
333
|
+
else this.engine.ops.run('interaction.use', { id: b.id }, { source: 'player', actor });
|
|
297
334
|
}
|
|
298
|
-
this._pass = 0;
|
|
299
335
|
}
|
|
300
336
|
/** @internal One fixed step of the hold: released / removed / disabled / out of reach interrupts it, else it counts; complete = the op interaction.use */
|
|
301
337
|
_tickHold(dt) {
|
|
302
|
-
const h = this._hold, it = h.it, e = this.engine, p = e.actorPosition();
|
|
303
|
-
const why = !
|
|
338
|
+
const h = this._hold, it = h.it, e = this.engine, p = e.actorPosition(h.actor);
|
|
339
|
+
const why = !h.input.down(h.action) ? 'released' : it._gone ? 'removed' : !it.enabled(it.object, { actor: h.actor }) ? 'disabled'
|
|
304
340
|
: !p || this._where(it).distanceTo(W.set(p.x, p.y ?? 0, p.z)) >= it.radius ? 'tooFar' : null;
|
|
305
341
|
if (why) return this._interrupt(why);
|
|
306
342
|
h.t += dt; this._holdView();
|
|
307
343
|
if (h.t < it.hold) return;
|
|
308
344
|
this._hold = this.holding = null;
|
|
309
|
-
e.ops.run('interaction.use', { id: it.id }, { source: 'player' });
|
|
345
|
+
e.ops.run('interaction.use', { id: it.id }, { source: 'player', actor: h.actor });
|
|
310
346
|
}
|
|
311
347
|
/** @internal */
|
|
312
348
|
_holdView() { const h = this._hold; this.holding = { id: h.it.id, action: h.action, seconds: h.it.hold, progress: Math.min(1, h.t / h.it.hold) }; }
|
|
@@ -322,14 +358,14 @@ export class Interactions {
|
|
|
322
358
|
try { this._update(); } finally { this._pass = 0; }
|
|
323
359
|
}
|
|
324
360
|
/**
|
|
325
|
-
* @internal Dev: an interaction whose action has no key
|
|
326
|
-
*
|
|
327
|
-
* `await engine.start()` may still bind.
|
|
361
|
+
* @internal Dev: an interaction whose action has no key is reached by no key press, and nothing else would say so. A warning, not a throw: a click-only or touch-only
|
|
362
|
+
* game runs the op from its own code and is right, so this must not stop it (bind the action to [] to say so and the warning ends). Only once running: code right
|
|
363
|
+
* after `await engine.start()` may still bind. describe() keeps the note for every build.
|
|
328
364
|
*/
|
|
329
365
|
_checkKeys() {
|
|
330
366
|
this._keysDue = false;
|
|
331
367
|
for (const a of this._actions.keys()) {
|
|
332
|
-
if (this.engine.input.isUnbound(a))
|
|
368
|
+
if (this.engine.input.isUnbound(a)) warnOnce(coded('interaction-no-key', `interactions: action '${a}' has no key, so no key press reaches what was added to it. Add: ${bindLine(a)}. Reached by a click or your own code? engine.input.bind('${a}', []) says so`), `interaction-no-key:${a}`);
|
|
333
369
|
}
|
|
334
370
|
}
|
|
335
371
|
/** @internal */
|
|
@@ -367,8 +403,8 @@ export class Interactions {
|
|
|
367
403
|
// label / enabled / onUse all get (object, { actor }): who is asking is part of the question (a door that only its owner may open, a shop that greets each
|
|
368
404
|
// net peer by name), so a game never has to read engine.actor or engine.player inside them and they stay right for NPCs and peers
|
|
369
405
|
const labelOf = (it, actor) => typeof it.label === 'function' ? it.label(it.object, { actor }) : it.label;
|
|
370
|
-
// shortcut: approach walks only
|
|
371
|
-
const walkerOf = (e, actor) => actor === 'player'
|
|
406
|
+
// shortcut: approach walks only players (actor 'player' or a seat's); a squad / RTS game whose actor is an NPC gets 'cannotWalk' until NPC actors map to a Character
|
|
407
|
+
const walkerOf = (e, actor) => { const c = actor === 'player' ? e.player : e.input.seats.some(s => s.actor === actor) ? e.control.characterOf(actor) : null; return c?.walkTo ? c : null; };
|
|
372
408
|
|
|
373
409
|
const INTERACTION_PARAMS = {
|
|
374
410
|
action: { type: 'string', default: 'interact', desc: 'input action that uses the interaction' },
|
|
@@ -392,9 +428,9 @@ const INTERACTION_PARAMS = {
|
|
|
392
428
|
export function interactions(opts) {
|
|
393
429
|
const o = readParams('interactions', INTERACTION_PARAMS, opts ?? {});
|
|
394
430
|
let i = null;
|
|
395
|
-
return { name: 'interactions', type: 'rules', provides: ['interactions'], optional: ['hud'], label: 'Interactions', params: INTERACTION_PARAMS, options: o, noSkip: 'input and prompt state only', stage: 'gameplay',
|
|
431
|
+
return { name: 'interactions', skipKind: 'none', type: 'rules', provides: ['interactions'], optional: ['hud'], label: 'Interactions', params: INTERACTION_PARAMS, options: o, noSkip: 'input and prompt state only', stage: 'gameplay',
|
|
396
432
|
// o: the schema defaults are filled in, the class repeats none
|
|
397
|
-
install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.interactions': '交互' }, en: { 'module.interactions': 'interactions' } }); i = new Interactions(e, o, ctx
|
|
433
|
+
install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.interactions': '交互' }, en: { 'module.interactions': 'interactions' } }); i = new Interactions(e, o, ctx); defineUse(e, ctx, i); return i; },
|
|
398
434
|
fixed(dt) { i.fixed(dt); }, frame() { i.update(); },
|
|
399
435
|
// interactions are "weak" info: when an NPC, pickup or entity already reported the same object, only add "interactable: xxx"
|
|
400
436
|
describe(e, ctx) {
|
|
@@ -417,9 +453,9 @@ function lockFacts(e) {
|
|
|
417
453
|
}
|
|
418
454
|
|
|
419
455
|
/** The engine op interaction.use { id?, action? }: what the interact key, the prompt click, the dev bridge and tests all run */
|
|
420
|
-
function defineUse(e, i) {
|
|
456
|
+
function defineUse(e, ctx, i) {
|
|
421
457
|
const find = (id, action, ctx) => id !== undefined ? i.get(id) : i.pick(ctx.actor, action);
|
|
422
|
-
|
|
458
|
+
ctx.ops.define('interaction.use', {
|
|
423
459
|
desc: 'Use an interaction (talk, pick up, open...); without id, the one the actor would pick now (optionally for one action)',
|
|
424
460
|
args: { id: 'string?', action: 'string?' },
|
|
425
461
|
net: 'local', // the prompt and reach are this player's; game ops inside onUse are routed to the host (net: 'peer' ones) or refused
|
|
@@ -427,8 +463,6 @@ function defineUse(e, i) {
|
|
|
427
463
|
const it = find(id, action, ctx);
|
|
428
464
|
if (!it) return id === undefined ? 'nothingNear' : 'unknown';
|
|
429
465
|
if (!it.enabled(it.object, { actor: ctx.actor })) return 'disabled';
|
|
430
|
-
// the local player only: a net peer or an NPC does not go through this page's keys. The bridge and tests are refused too, so `ops` never shows a ✓ no player can do
|
|
431
|
-
if (ctx.actor === e.actor && e.input.isUnbound(it.action)) return { code: 'noKey', facts: { action: it.action, fix: bindLine(it.action) } };
|
|
432
466
|
if (ctx.actor === e.actor && !e.input.enabled) return { code: 'inputLocked', facts: lockFacts(e) };
|
|
433
467
|
if (it.approach && !walkerOf(e, ctx.actor)) return 'cannotWalk';
|
|
434
468
|
const p = e.actorPosition(ctx.actor);
|
|
@@ -438,17 +472,25 @@ function defineUse(e, i) {
|
|
|
438
472
|
const d = it.object.getWorldPosition(V).distanceTo(W.set(p.x, p.y ?? 0, p.z)), r1 = v => Math.round(v * 10) / 10;
|
|
439
473
|
return d >= it.radius ? { code: 'tooFar', facts: { distance: r1(d), radius: it.radius, at: { x: r1(V.x), z: r1(V.z) } } } : true;
|
|
440
474
|
},
|
|
441
|
-
// onUse's return value is the op's value; { ok: false, code } fails the op (pickups: code 'full' when the bag is full).
|
|
475
|
+
// onUse's return value is the op's value; { ok: false, code } fails the op (pickups: code 'full' when the bag is full). An async onUse: the value is a Promise of that answer.
|
|
442
476
|
// approach from afar: the value is { approaching } (a Promise of onUse's result after arrival, or the walk's { status } when it did not arrive)
|
|
443
477
|
run(e, { id, action }, ctx) {
|
|
444
478
|
const it = find(id, action, ctx);
|
|
445
479
|
if (!it.approach) return i._run(it, ctx.actor);
|
|
446
480
|
const ch = walkerOf(e, ctx.actor), q = it.object.getWorldPosition(new THREE.Vector3());
|
|
447
481
|
if (Math.hypot(q.x - ch.position.x, q.z - ch.position.z) <= APPROACH_ARRIVE + 0.3) return i._run(it, ctx.actor);
|
|
482
|
+
// the game holds this character on the walk's layer: 'cannot walk now' is an answer, and from the key press in a fixed step a throw would freeze play
|
|
483
|
+
let walk; try { walk = ch.walkTo(q, { arrive: APPROACH_ARRIVE }); } catch (err) { if (err?.code === 'control-conflict') return { ok: false, code: 'cannotWalk' }; throw err; }
|
|
448
484
|
// used after arrival, so checked again then: removed or disabled while walking = not used
|
|
449
|
-
|
|
485
|
+
// the op ended steps ago: the use is the same op again, now in reach, so it has its actor, source, checks and a line in the history
|
|
486
|
+
const use = () => { const u = e.ops.run('interaction.use', { id: it.id }, { actor: ctx.actor, source: ctx.source }); return u.ok ? u.value : u; };
|
|
487
|
+
// the handle of the task it started: remove() calls the walk off, and the walk's cancelled answer is what approaching settles with
|
|
488
|
+
return { approaching: Object.assign(walk.then(r => r.status === 'arrived' && !it._gone && it.enabled(it.object, { actor: ctx.actor }) ? use() : r), { remove: () => walk.remove() }) };
|
|
450
489
|
},
|
|
451
|
-
|
|
452
|
-
|
|
490
|
+
// no key: the op still runs when code asks (a click-only game), but it is not offered, so `ops` shows no ✓ for what no key reaches; describe() says why
|
|
491
|
+
offers(e, ctx) { const it = find(undefined, undefined, ctx); return it && !(ctx.actor === e.actor && e.input.isUnbound(it.action)) ? [{ id: it.id }] : []; },
|
|
492
|
+
reasons: { unknown: 'No interaction with this id', nothingNear: 'No interaction in range', disabled: 'Its enabled() is false', tooFar: 'Actor is outside its radius', cannotWalk: 'approach walks the player; this actor has no character to walk', inputLocked: 'A title, window, dialogue or cutscene locks input; facts.by names it' },
|
|
453
493
|
});
|
|
454
494
|
}
|
|
495
|
+
|
|
496
|
+
export const handRolled = [{ kind: 'reach', seen: 'a hand-made reach check for interacting', use: 'engine.interactions.add(target, { ... }): prompt, range and the interact action are handled (recipe 20)', quiet: /\b(engine|e|eng|ctx)\.interactions\b/, code: /(?:\bdistanceTo(?:Squared)?\(|\bMath\.hypot\(|\bdist(?:ance)?\w*)[^;]*<=?\s*\d/, near: [{ re: /KeyE|['"]e['"]|interact|press e\b|talk/i, lines: 3, on: 'raw' }] }];
|