threedog 0.5.0 → 0.8.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 +276 -1
- package/README.md +18 -13
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +116 -61
- package/core/{Baked.js → assets/Baked.js} +16 -25
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- package/core/{assetLoad.js → assets/assetLoad.js} +66 -29
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +23 -12
- package/core/{assetReport.js → assets/assetReport.js} +9 -15
- package/core/{namedModel.js → assets/namedModel.js} +24 -16
- package/core/{Audio.js → audio/Audio.js} +27 -24
- 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} +10 -10
- package/core/{Random.js → base/Random.js} +5 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +154 -139
- package/core/{errorHints.js → base/errorHints.js} +9 -10
- package/core/{errors.js → base/errors.js} +9 -9
- package/core/{events.generated.js → base/events.generated.js} +2 -0
- package/core/{math.js → base/math.js} +22 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +29 -8
- package/core/{Engine.js → engine/Engine.js} +112 -105
- package/core/{Loading.js → engine/Loading.js} +4 -2
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
- package/core/{lifecycle.js → engine/lifecycle.js} +16 -16
- package/core/{loop.js → engine/loop.js} +80 -52
- package/core/{moduleSlots.js → engine/moduleSlots.js} +35 -10
- package/core/{moduleTypes.js → engine/moduleTypes.js} +30 -18
- package/core/{modules.js → engine/modules.js} +20 -17
- package/core/engine/page.js +125 -0
- package/core/{plugins.js → engine/plugins.js} +68 -103
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +35 -35
- package/core/{Input.js → input/Input.js} +41 -27
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/{inputPad.js → input/inputPad.js} +1 -1
- package/core/{inputPointer.js → input/inputPointer.js} +8 -2
- package/core/{inputTouch.js → input/inputTouch.js} +1 -1
- package/core/{Budget.js → inspect/Budget.js} +23 -22
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +60 -31
- package/core/{Describe.js → inspect/Describe.js} +33 -30
- package/core/{Inspect.js → inspect/Inspect.js} +14 -9
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +8 -10
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +29 -16
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +9 -6
- package/core/inspect/UrlState.js +182 -0
- package/core/{catalog.js → inspect/catalog.js} +18 -5
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +8 -8
- package/core/inspect/describeRender.js +148 -0
- package/core/{describeText.js → inspect/describeText.js} +17 -12
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +11 -9
- package/core/inspect/pictureWriters.js +342 -0
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/{Ops.js → ops/Ops.js} +16 -11
- package/core/{control.js → ops/control.js} +13 -12
- package/core/ops/holds.js +139 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
- package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +7 -4
- package/core/{owned.js → ops/owned.js} +37 -37
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -27
- package/core/{stackFrames.js → ops/stackFrames.js} +17 -6
- package/core/{stacks.js → ops/stacks.js} +18 -20
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
- package/core/{Saves.js → saves/Saves.js} +58 -36
- package/core/{saveApply.js → saves/saveApply.js} +13 -9
- package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
- package/core/{saveValues.js → saves/saveValues.js} +20 -3
- package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
- package/core/{session.js → saves/session.js} +31 -17
- package/core/{Rays.js → scene/Rays.js} +27 -24
- package/core/{Views.js → scene/Views.js} +15 -6
- package/core/{adaptive.js → scene/adaptive.js} +15 -8
- package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
- package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
- package/core/{gameLights.js → scene/gameLights.js} +24 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +4 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/{ground.js → scene/ground.js} +9 -9
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/scene/pictureSlots.js +33 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +14 -6
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -20
- package/core/scene/stepPoses.js +55 -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} +4 -3
- package/core/{things.js → scene/things.js} +19 -6
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +1 -1
- package/core/scene/view.js +44 -0
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +62 -33
- package/core/{batchGroups.js → stream/batchGroups.js} +18 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +41 -1
- package/core/{scatter.js → stream/scatter.js} +2 -2
- package/core/{streamSources.js → stream/streamSources.js} +12 -7
- package/core/{Commits.js → threads/Commits.js} +6 -5
- package/core/{Jobs.js → threads/Jobs.js} +12 -10
- package/core/{Threads.js → threads/Threads.js} +16 -16
- 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} +17 -10
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +18 -17
- package/core/{time.js → time/time.js} +18 -12
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +70 -63
- package/docs/API.md +30 -29
- package/docs/CODEMAP.md +98 -223
- package/docs/COMMANDS.md +80 -69
- package/docs/CONVENTIONS.md +87 -41
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +100 -49
- package/docs/api/assets.md +17 -16
- package/docs/api/audio.md +8 -7
- package/docs/api/budget.md +8 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +29 -29
- package/docs/api/characters.md +26 -19
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +14 -11
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +82 -53
- package/docs/api/events.md +5 -3
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +9 -2
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +4 -1
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +10 -9
- package/docs/api/interactions.md +6 -4
- package/docs/api/inventory.md +10 -11
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -8
- package/docs/api/lightPool.md +2 -7
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/occlusion.md +5 -0
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +8 -5
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +7 -1
- package/docs/api/post.md +24 -5
- package/docs/api/quests.md +3 -3
- package/docs/api/rays.md +5 -7
- package/docs/api/rigid.md +27 -18
- package/docs/api/saves.md +8 -7
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +17 -14
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +17 -12
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +30 -26
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +11 -5
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +11 -6
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +38 -57
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +47 -42
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +72 -66
- package/docs/recipes/06-clock-events.md +30 -21
- package/docs/recipes/07-flow-scenes-pause.md +21 -17
- package/docs/recipes/08-weather-sky.md +117 -75
- package/docs/recipes/09-materials-lights-models.md +171 -0
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +33 -25
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +50 -22
- package/docs/recipes/14-custom-module.md +20 -17
- package/docs/recipes/15-perf.md +52 -29
- package/docs/recipes/16-dev-bridge.md +47 -57
- package/docs/recipes/18-world.md +45 -30
- package/docs/recipes/19-shooting-picking.md +11 -7
- package/docs/recipes/20-content-actions-save.md +36 -37
- package/docs/recipes/21-camera.md +41 -8
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +11 -11
- package/docs/recipes/26-ui-parts.md +56 -22
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +126 -30
- package/docs/recipes/29-grid.md +16 -7
- package/docs/recipes/30-templates.md +62 -21
- package/docs/recipes/31-audio.md +9 -9
- package/docs/recipes/32-action-game.md +32 -9
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +164 -52
- package/docs/recipes/35-picture-from-reference.md +140 -0
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +105 -30
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +74 -106
- package/docs/recipes/44-water-weather-hooks.md +196 -0
- package/docs/recipes/45-cascaded-shadows.md +145 -25
- package/docs/recipes/46-blender-art-route.md +21 -25
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +137 -0
- package/docs/recipes/53-ground-up-close.md +65 -28
- package/docs/recipes/55-mods-time-wrap.md +25 -17
- package/docs/recipes/56-webgpu-tsl.md +73 -28
- package/docs/recipes/57-control.md +47 -1
- package/docs/recipes/58-input.md +3 -0
- package/docs/recipes/59-depth-post-effects.md +5 -5
- package/docs/recipes/60-judge-the-picture.md +47 -27
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +276 -0
- package/docs/recipes/63-third-person-start.md +90 -0
- package/docs/recipes/64-particles.md +35 -0
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +9 -7
- package/examples/action/main.js +5 -4
- package/examples/action/models.js +12 -14
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +18 -14
- package/examples/{sheepisland → perf-island}/assets.js +2 -2
- package/examples/{sheepisland → perf-island}/content/templates.js +1 -1
- package/examples/{sheepisland → perf-island}/content/vegetation.js +3 -1
- package/examples/{sheepisland → perf-island}/main.js +22 -16
- package/examples/{sheepisland/style → perf-island}/models.js +13 -24
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/perf-island/picture/index.js +20 -0
- package/examples/perf-island/picture/lights.js +34 -0
- package/examples/perf-island/picture/materials.js +61 -0
- package/examples/perf-island/picture/palette.js +60 -0
- package/examples/perf-island/picture/sky.js +20 -0
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/GAMEMAP.md +91 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +31 -9
- package/examples/rc2d/GAMEMAP.md +10 -4
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +26 -36
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +18 -28
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -10
- package/examples/styletest/main.js +20 -30
- package/examples/styletest/models.js +29 -29
- package/examples/styletest/params.js +1 -4
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +22 -23
- package/examples/techniques/contact-shadows/contactShadows.js +32 -16
- package/examples/techniques/contact-shadows/main.js +20 -18
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +13 -16
- package/examples/techniques/day-night-grade/main.js +15 -25
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +16 -13
- package/examples/techniques/interior-light/interiorLight.js +19 -17
- package/examples/techniques/interior-light/main.js +31 -68
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +8 -6
- package/examples/techniques/modular-building/kit.js +2 -2
- package/examples/techniques/modular-building/main.js +9 -17
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +15 -14
- package/examples/techniques/night-lights/main.js +20 -43
- package/examples/techniques/night-lights/nightLights.js +25 -21
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +2 -2
- package/examples/techniques/outlines-and-rim/main.js +15 -38
- package/examples/techniques/outlines-and-rim/outlines.js +3 -3
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +6 -4
- package/examples/techniques/procedural-animation/main.js +9 -7
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
- package/examples/techniques/procedural-surface/README.md +2 -0
- package/examples/techniques/procedural-surface/main.js +17 -55
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/stylized-shading/README.md +13 -14
- package/examples/techniques/stylized-shading/main.js +11 -42
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +2 -2
- package/examples/techniques/sun-and-key-light/README.md +20 -22
- package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
- package/examples/techniques/sun-and-key-light/main.js +19 -63
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +7 -4
- package/examples/techniques/wet-road/main.js +18 -38
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/webgpu-tsl/GAMEMAP.md +10 -4
- package/examples/webgpu-tsl/README.md +13 -10
- package/examples/webgpu-tsl/main.js +30 -7
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +16 -12
- package/examples/world/art/humanoid.js +9 -13
- package/examples/world/art/index.js +2 -2
- package/examples/world/art/models.js +3 -4
- package/examples/world/art/shapes.js +2 -2
- package/examples/world/assets.js +2 -2
- package/examples/world/content/audio.js +1 -1
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +10 -10
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +14 -22
- package/index.js +36 -36
- package/llms.txt +19 -21
- package/modules/ambience/Ambience.js +12 -9
- package/modules/calendar/Calendar.js +20 -20
- package/modules/calendar/index.js +14 -13
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +2 -2
- package/modules/camera/FixedCamera.js +14 -15
- package/modules/camera/FollowCamera.js +4 -4
- package/modules/camera/RtsCamera.js +11 -11
- package/modules/camera/common.js +51 -25
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +47 -39
- package/modules/characters/NPC.js +30 -22
- package/modules/characters/assetModel.js +18 -13
- package/modules/characters/astar.js +7 -5
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +172 -193
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +22 -15
- package/modules/characters/movers/manual.js +4 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +32 -18
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +28 -18
- package/modules/characters/npcView.js +6 -5
- package/modules/characters/pathAsync.js +12 -10
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +108 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +19 -5
- package/modules/characters/useModel.js +5 -5
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +30 -22
- package/modules/collision/contract.js +15 -0
- package/modules/content/explain.js +1 -2
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +2 -2
- package/modules/content/index.js +68 -98
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +66 -18
- package/modules/content/packs.js +3 -3
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +35 -0
- package/modules/content/props.js +19 -14
- package/modules/content/rules.js +34 -22
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +24 -22
- package/modules/content/words.js +34 -0
- package/modules/debug/DebugPanel.js +10 -43
- package/modules/flow/contract.js +1 -1
- package/modules/flow/index.js +11 -7
- package/modules/gameplay/Container.js +12 -11
- package/modules/gameplay/Containers.js +14 -5
- package/modules/gameplay/Dialogue.js +13 -11
- package/modules/gameplay/Interactions.js +115 -27
- package/modules/gameplay/Inventory.js +11 -12
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +4 -5
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -3
- package/modules/gameplay/pickups.js +81 -44
- package/modules/gameplay/questLog.js +2 -2
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +16 -3
- package/modules/grid/index.js +47 -19
- package/modules/grid/preview.js +29 -20
- package/modules/grid/tiles.js +19 -23
- package/modules/hlod/index.js +38 -55
- package/modules/hud/index.js +27 -8
- package/modules/hud/parts.js +13 -11
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +48 -152
- package/modules/level/load.js +79 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +6 -7
- package/modules/lights/index.js +34 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +31 -27
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +14 -0
- package/modules/nav/index.js +11 -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 +5 -4
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +49 -25
- package/modules/particles/effect.js +27 -10
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +26 -27
- package/modules/rigid/RigidBodies.js +66 -43
- package/modules/rigid/Vehicles.js +2 -3
- package/modules/rigid/ragdoll.js +287 -0
- package/modules/rigid/ragdollBones.js +159 -0
- package/modules/rigid/sync.js +6 -6
- package/modules/settings/Settings.js +114 -45
- package/modules/settings/apply.js +10 -10
- package/modules/settings/sections.js +16 -14
- package/modules/settings/strings.js +1 -1
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +125 -103
- package/modules/sky/clouds.js +22 -23
- package/modules/sky/dome.js +113 -0
- package/modules/sky/domeLayers.js +13 -13
- package/modules/sky/environment.js +47 -171
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +42 -97
- package/modules/sky/season.js +9 -3
- package/modules/sky/shader.js +49 -44
- package/modules/sky/skyModule.js +25 -35
- package/modules/sky/tint.js +9 -11
- package/modules/swarm/Swarm.js +346 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +97 -62
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +157 -0
- package/modules/terrain/index.js +60 -88
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +4 -3
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +19 -14
- 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 +27 -19
- package/modules/timeline/Tween.js +6 -6
- package/modules/timeline/shots.js +5 -7
- package/modules/triggers/index.js +19 -15
- package/modules/vegetation/Vegetation.js +87 -39
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +196 -0
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +18 -16
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +140 -93
- package/modules/water/surface.js +56 -56
- package/modules/weather/Weather.js +84 -38
- package/modules/weather/particles.js +18 -10
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +145 -0
- package/modules/world/World.js +10 -10
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -12
- package/modules/world/persist.js +73 -25
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +28 -8
- package/modules/world/sim.js +4 -4
- package/modules/world/state.js +12 -5
- package/modules/world/thingSource.js +4 -2
- package/modules/world/views.js +12 -10
- package/package.json +44 -8
- package/presets.js +3 -5
- package/render/PostFX.js +233 -63
- package/render/backend.js +72 -32
- package/render/cascades.js +200 -0
- package/render/cascades.tsl.js +93 -0
- package/render/daylight.js +56 -0
- package/render/detail.js +13 -12
- package/render/effects.js +60 -42
- package/render/fuse.js +3 -3
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +10 -13
- 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/patchNodes.tsl.js +6 -16
- package/render/fx/postWebGPU.tsl.js +55 -28
- package/render/fx/sky.tsl.js +34 -109
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/water.tsl.js +1 -1
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +14 -0
- package/render/lighting.js +11 -8
- package/render/lightmap.js +142 -0
- package/render/lights.js +26 -204
- package/render/lit.js +24 -0
- package/render/materials.js +47 -162
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/neutral.js +23 -0
- package/render/occlusion.js +200 -0
- package/render/ownFrame.js +5 -5
- package/render/patches.js +46 -41
- package/render/postWebGL.js +19 -9
- package/render/probes.js +182 -128
- 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/render/shadows.js +451 -0
- package/render/slots.js +11 -11
- package/render/terms.js +63 -113
- package/render/uniformDecl.js +2 -2
- package/types/core.d.ts +489 -405
- package/types/gameplay.d.ts +225 -114
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +23 -8
- 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} +7 -15
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/engine/page.d.ts +24 -0
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +21 -10
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +16 -8
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
- 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/Layer.d.ts +9 -1
- package/types/generated/modules/grid/index.d.ts +32 -8
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +14 -7
- package/types/generated/modules/sky/Sky.d.ts +101 -23
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +2 -1
- package/types/generated/modules/water/Water.d.ts +51 -3
- package/types/generated/modules/weather/Weather.d.ts +44 -10
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +7 -5
- package/types/generated/render/PostFX.d.ts +69 -20
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +20 -44
- package/types/generated/render/occlusion.d.ts +22 -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 +11 -11
- package/types/physics.d.ts +104 -73
- package/types/tsl.d.ts +45 -4
- package/types/world.d.ts +372 -86
- package/ui/Focus.js +21 -10
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +12 -7
- package/ui/UI.js +17 -17
- package/ui/cursor.js +1 -1
- package/ui/defaults.js +3 -2
- package/ui/theme.js +36 -28
- package/ui/touchPart.js +1 -1
- package/core/UrlState.js +0 -110
- package/core/assetEntry.js +0 -106
- package/core/describeRender.js +0 -71
- package/core/holds.js +0 -134
- package/core/look/coreParts.js +0 -219
- package/core/look/part.js +0 -253
- package/core/look/points.js +0 -255
- package/core/look/report.js +0 -96
- package/core/look/shadowPart.js +0 -63
- package/core/look/state.js +0 -45
- package/core/look/write.js +0 -70
- package/core/page.js +0 -79
- package/core/shadowTypes.js +0 -16
- package/core/styleParts.js +0 -114
- package/core/util.js +0 -17
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -228
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/PERF.md +0 -245
- package/docs/api/style.md +0 -136
- package/docs/api/terrainLook.md +0 -10
- package/docs/api/vegetationLook.md +0 -10
- package/docs/api/weatherLook.md +0 -10
- package/docs/recipes/09-style.md +0 -218
- package/docs/recipes/35-style-from-reference.md +0 -153
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/37-terrain-look-hooks.md +0 -119
- package/docs/recipes/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/47-island-snow-backdrop.md +0 -45
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
- package/examples/webgpu-tsl/tslScene.js +0 -75
- package/examples/world/style/index.js +0 -61
- package/examples/world/style/plugins/10-bloom.js +0 -5
- package/modules/sky/cascades.js +0 -186
- package/modules/sky/cascades.tsl.js +0 -82
- package/modules/sky/look.js +0 -54
- package/modules/sky/lookFog.js +0 -76
- package/modules/sky/lookShadow.js +0 -62
- package/modules/sky/lookSky.js +0 -169
- package/modules/sky/shadow.js +0 -98
- package/modules/terrain/look.js +0 -83
- package/modules/terrain/lookGround.js +0 -66
- package/modules/vegetation/look.js +0 -119
- package/modules/vegetation/lookWind.js +0 -98
- package/modules/water/look.js +0 -91
- package/modules/water/surfaceDefaults.js +0 -3
- package/modules/weather/look.js +0 -74
- package/modules/weather/weatherLook.js +0 -135
- package/render/lookGlow.js +0 -139
- package/render/lookSurface.js +0 -224
- package/render/postLook.js +0 -164
- package/render/surface.js +0 -105
- package/types/generated/core/page.d.ts +0 -18
- package/types/generated/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
- /package/core/{Vars.js → base/Vars.js} +0 -0
- /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/{opsFail.js → ops/opsFail.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
|
@@ -23,23 +23,23 @@
|
|
|
23
23
|
// body: { shape: 'box' | 'ball' | 'hull', mass?, friction?, restitution?, damping?, angularDamping? } makes each copy a rigid body (needs rigid()):
|
|
24
24
|
// it can be pushed, the model moves itself and its position is copied back to the record, so a pushed crate's place is saved like any other change.
|
|
25
25
|
// Ids: an instance with state (state / container / interact / body) should have a written id (ids.js); without one dev warns.
|
|
26
|
-
import { checkOptions, freezeDef, missingText, fmt, DEV } from '../../core/validate.js';
|
|
27
|
-
import { xzOf } from '../../core/math.js';
|
|
28
|
-
import { placeY } from '../../core/ground.js';
|
|
29
|
-
import { buildModel, settle,
|
|
26
|
+
import { checkOptions, freezeDef, missingText, fmt, DEV } from '../../core/base/validate.js';
|
|
27
|
+
import { xzOf } from '../../core/base/math.js';
|
|
28
|
+
import { placeY } from '../../core/scene/ground.js';
|
|
29
|
+
import { buildModel, settle, fits, unbuildModel } from './models.js';
|
|
30
30
|
import { srcOf, stateful, templateId } from './ids.js';
|
|
31
|
-
import { PLACEMENT_FIELDS } from './rules.js';
|
|
31
|
+
import { PLACEMENT_FIELDS, collideProblem } from './rules.js';
|
|
32
32
|
import { fieldsShape } from './fields.js';
|
|
33
|
-
import { whyBad, readParams, keysSchema } from '../../core/params.js';
|
|
33
|
+
import { whyBad, readParams, keysSchema } from '../../core/base/params.js';
|
|
34
34
|
import { stagesProblems, stagedFields, growStages } from './stages.js';
|
|
35
|
-
import { codedError } from '../../core/errorHints.js';
|
|
35
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
36
36
|
|
|
37
|
-
const DEF_KEYS = ['model', 'collide', 'static', 'interact', 'container', 'sound', 'animate', 'state', 'fields', 'body', 'stages', 'update', 'canGrow'];
|
|
37
|
+
const DEF_KEYS = ['model', 'collide', 'occluder', 'static', 'lod', 'interact', 'container', 'sound', 'animate', 'state', 'fields', 'body', 'stages', 'update', 'canGrow'];
|
|
38
38
|
const BODY_KEYS = ['shape', 'mass', 'friction', 'restitution', 'damping', 'angularDamping'];
|
|
39
39
|
// what a placement may set besides the state fields: the placement field table (rules.js), so the loader, content-check and content.fields() agree
|
|
40
40
|
const PLACE_KEYS = Object.keys(PLACEMENT_FIELDS['props.template']);
|
|
41
|
-
// content.spawn gets its position as an argument, so only the id and the
|
|
42
|
-
const SPAWN_KEYS = PLACE_KEYS.filter(k => !['template', 'place', 'x', 'z', 'floor'].includes(k));
|
|
41
|
+
// content.spawn gets its position as an argument, so only the id and the picture / goods keys of the same table
|
|
42
|
+
const SPAWN_KEYS = PLACE_KEYS.filter(k => !['template', 'place', 'x', 'z', 'floor', 'source'].includes(k));
|
|
43
43
|
|
|
44
44
|
const STRINGS = {
|
|
45
45
|
noModel: "template '{name}' needs a model: a model name from an asset pack (engine.assets.manifest({ models: { chest: '/models/chest.glb' | fn } })), e.g. { model: 'chest' }",
|
|
@@ -63,6 +63,8 @@ export function defineTemplates(e, api, st, defs) {
|
|
|
63
63
|
for (const [name, d] of Object.entries(defs)) {
|
|
64
64
|
readParams(`template '${name}'`, keysSchema(DEF_KEYS), d);
|
|
65
65
|
if (!d?.model) throw codedError('content-template', fmt(STRINGS.noModel, { name }));
|
|
66
|
+
const collide = collideProblem(d.collide);
|
|
67
|
+
if (collide) throw codedError('content-template', `template '${name}': collide ${collide}`);
|
|
66
68
|
if (d.interact) {
|
|
67
69
|
readParams(`template '${name}' interact`, keysSchema(['label', 'op', 'radius', 'height', 'action', 'enabled']), d.interact);
|
|
68
70
|
// why a throw and not the usual unknown-key warning: a callback here would be a second, unlogged way to change saved state
|
|
@@ -97,7 +99,7 @@ export function defineTemplates(e, api, st, defs) {
|
|
|
97
99
|
limitContainers(e, st, name);
|
|
98
100
|
}
|
|
99
101
|
// a save brings back runtime instances and their goods, but container limits are definition data: put them back from the template
|
|
100
|
-
st.templateLoad ??= e.events.on('world:load', () => { for (const name of st.templates.keys()) limitContainers(e, st, name); });
|
|
102
|
+
st.templateLoad ??= st.track(e.events.on('world:load', () => { for (const name of st.templates.keys()) limitContainers(e, st, name); }));
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
/** The definition of a template, or a dev error listing the known ones. @internal */
|
|
@@ -115,6 +117,9 @@ export function placeTemplate(e, api, st, p, i, zone, ids, origin) {
|
|
|
115
117
|
const name = p.template, d = templateOf(st, name), id = templateId(p, i), { x, y, z } = api.where(p), floor = api._floorOf(p);
|
|
116
118
|
const own = instanceFields(name, d, p, PLACE_KEYS, st.templateFields.get(name));
|
|
117
119
|
if (floor !== undefined) own.floor = floor; // same as props: a moved instance lands on the same storey
|
|
120
|
+
const rot = api._facingOf(p);
|
|
121
|
+
if (rot !== undefined) own.rot = rot;
|
|
122
|
+
if (p.source !== undefined) own.source = p.source;
|
|
118
123
|
if (ids && p.id != null) ids.claim(p.id, `props[${i}] (template ${name})`);
|
|
119
124
|
else if (ids && stateful(d)) ids.unnamed(id, `props[${i}] (template ${name})`);
|
|
120
125
|
const rec = e.world.add({ id, kind: name, position: { x, y: y ?? placeY(e, `props[${i}] (template ${name})`, x, z), z }, ...own, ...(zone != null && { zone }) }, { initial: true });
|
|
@@ -169,7 +174,7 @@ function present(e, api, st, name) {
|
|
|
169
174
|
st.templateViews.add(name);
|
|
170
175
|
const def = () => st.templates.get(name); // a later load may replace the definition: always read the current one
|
|
171
176
|
const body = !!def().body; // a physics body moves the model itself: the record follows the model (positionFrom 'view'), so a pushed position is saved
|
|
172
|
-
e.world.present(name, {
|
|
177
|
+
st.track(e.world.present(name, { // tracked: without content there is no definition to build from, and a new content() must be able to present the kind
|
|
173
178
|
radius: () => Math.max(e.world.radius, e.stream.activeRadius), // same build distance as props
|
|
174
179
|
positionFrom: body ? 'view' : 'record',
|
|
175
180
|
async build(rec) {
|
|
@@ -191,12 +196,12 @@ function present(e, api, st, name) {
|
|
|
191
196
|
// a stage that names another model: tear this copy down, world builds the new one next frame (the record, and so the save, is untouched)
|
|
192
197
|
if (d.stages && !sameModel(o.userData, d, rec)) { e.world.rebuild(rec.id); return; }
|
|
193
198
|
const mul = stageScale(d, rec);
|
|
194
|
-
if (!d.body && o
|
|
199
|
+
if (!d.body && !fits(o, rec, mul)) settle(e, rec, o, d, mul); // a body places itself; a stage scale re-aligns collision too
|
|
195
200
|
else if (d.body) restBody(e, rec, o);
|
|
196
201
|
d.animate?.(rec, o, dt);
|
|
197
202
|
},
|
|
198
203
|
dispose(rec, o) { o.userData.use?.remove(); o.userData.body?.remove(); unbuildModel(e, o); },
|
|
199
|
-
});
|
|
204
|
+
}));
|
|
200
205
|
}
|
|
201
206
|
|
|
202
207
|
/**
|
|
@@ -226,11 +231,6 @@ function restBody(e, rec, o) {
|
|
|
226
231
|
if (b.isSleeping()) e.world.rest(rec.id, p, SETTLE);
|
|
227
232
|
}
|
|
228
233
|
|
|
229
|
-
/** The model a copy shows: its stage's model, else the nearest earlier stage's, else the template's (so it never depends on what was built before) */
|
|
230
|
-
function modelOf(d, rec) {
|
|
231
|
-
for (let i = Math.min(rec.stage ?? 0, (d.stages?.length ?? 0) - 1); i >= 0; i--) if (d.stages[i].model) return d.stages[i].model;
|
|
232
|
-
return d.model;
|
|
233
|
-
}
|
|
234
234
|
/**
|
|
235
235
|
* Which definition and which stage supplied the model (the stage index, -1 for the template's own). Two equal keys always mean the same model, so
|
|
236
236
|
* the per-frame check compares one object and one number instead of serializing the model of every instance every frame.
|
|
@@ -239,6 +239,8 @@ function modelSource(d, rec) {
|
|
|
239
239
|
for (let i = Math.min(rec.stage ?? 0, (d.stages?.length ?? 0) - 1); i >= 0; i--) if (d.stages[i].model) return { d, at: i };
|
|
240
240
|
return { d, at: -1 };
|
|
241
241
|
}
|
|
242
|
+
/** The model a copy shows: its stage's model, else the nearest earlier stage's, else the template's (so it never depends on what was built before) */
|
|
243
|
+
function modelOf(d, rec) { const { at } = modelSource(d, rec); return at < 0 ? d.model : d.stages[at].model; }
|
|
242
244
|
/** Same model as when built? Same definition + same source stage is a yes without serializing; only a reloaded definition falls back to comparing text */
|
|
243
245
|
function sameModel(ud, d, rec) {
|
|
244
246
|
const k = modelSource(d, rec), b = ud.modelFrom;
|
|
@@ -252,7 +254,7 @@ const stageScale = (d, rec) => d.stages?.[rec.stage ?? 0]?.scale ?? 1;
|
|
|
252
254
|
|
|
253
255
|
/**
|
|
254
256
|
* Gameplay of a template kind on the fixed step (world.simulate, once per name; each step reads the current definition, so a later load replaces it).
|
|
255
|
-
* Growth runs near and far (far catches up in
|
|
257
|
+
* Growth runs near and far (far catches up in calendar seconds, several stages at once); update runs near only: a far copy only grows.
|
|
256
258
|
*/
|
|
257
259
|
function simulate(e, st, name) {
|
|
258
260
|
if (st.templateSims.has(name)) return;
|
|
@@ -265,10 +267,10 @@ function simulate(e, st, name) {
|
|
|
265
267
|
e.world.set(rec.id, next); // through world.set: world:change fires and the save keeps it, like any other gameplay change
|
|
266
268
|
e.events.emit('template:stage', { id: rec.id, template: name, stage: next.stage, name: d.stages[next.stage].name });
|
|
267
269
|
};
|
|
268
|
-
e.world.simulate(name, {
|
|
270
|
+
st.track(e.world.simulate(name, {
|
|
269
271
|
near: (rec, dt) => { grow(rec); st.templates.get(name)?.update?.(rec, dt, e); },
|
|
270
272
|
far: rec => grow(rec),
|
|
271
|
-
});
|
|
273
|
+
}));
|
|
272
274
|
}
|
|
273
275
|
|
|
274
276
|
const label = (e, l, rec) => typeof l === 'function' ? l(rec, e) : l && e.i18n.has(l) ? e.t(l) : l;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Running condition and effect words: content.test and content.run. The vocabulary is rules.js, the built-in meanings are in loader.js.
|
|
2
|
+
import { warnMissing } from '../../core/base/validate.js';
|
|
3
|
+
import { parseClock } from '../../core/time/dayTime.js';
|
|
4
|
+
import { list } from '../../core/base/util.js';
|
|
5
|
+
|
|
6
|
+
/** Convert content notation to runtime values by ref (clock time -> fraction, place -> { x, z }) */
|
|
7
|
+
const norm = (e, api, ref, v) => ref === 'clock' ? parseClock(v, e.calendar?.hoursPerDay ?? 24) : ref === 'position' ? api.where(typeof v === 'string' ? { place: v } : v) : v;
|
|
8
|
+
|
|
9
|
+
/** content.test */
|
|
10
|
+
export function testWords(e, api, conds, c, actor) {
|
|
11
|
+
if (!c) return true;
|
|
12
|
+
const ctx = { actor };
|
|
13
|
+
if (typeof c === 'function') return !!c(e, ctx);
|
|
14
|
+
return list(c).every(x => Object.entries(x).every(([k, v]) => {
|
|
15
|
+
const d = conds.get(k);
|
|
16
|
+
if (!d) { warnMissing('condition', k, [...conds.keys()]); return false; }
|
|
17
|
+
return !!d.test(e, norm(e, api, d.ref, v), v, ctx);
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** content.run */
|
|
22
|
+
export function runWords(e, api, effects, a, actor) {
|
|
23
|
+
if (!a) return;
|
|
24
|
+
const ctx = { actor };
|
|
25
|
+
if (typeof a === 'function') return a(e, ctx);
|
|
26
|
+
// One failing effect must not drop the ones after it (a reward with give + spawn would be half given): run them all, then rethrow the first error
|
|
27
|
+
let first = null, failed = 0;
|
|
28
|
+
for (const x of list(a)) for (const [k, v] of Object.entries(x)) {
|
|
29
|
+
const d = effects.get(k);
|
|
30
|
+
if (!d) { warnMissing('effect', k, [...effects.keys()]); continue; }
|
|
31
|
+
try { d.run(e, d.raw ? v : norm(e, api, d.ref, v), v, ctx); } catch (err) { first ??= err; failed++; }
|
|
32
|
+
}
|
|
33
|
+
if (first) { if (failed > 1) first.message += ` (${failed} effects failed; the others ran)`; throw first; }
|
|
34
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// Performance panel + time/weather debugging
|
|
2
|
-
import {
|
|
1
|
+
// Performance panel + time/weather debugging. Collapsed by default; the action 'debugPanel' shows/hides it (presets.bindings.debug binds F3; debug({ open: true }) shows it at start). Quality, view distance and density are in the settings menu. Do not install this module in a release.
|
|
2
|
+
import { Vector2 } from 'three';
|
|
3
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
3
4
|
import { esc } from '../../ui/UI.js';
|
|
4
5
|
import { stats } from '../../render/backend.js';
|
|
5
6
|
/** @import { ModuleDef } from '../../types/core' */
|
|
@@ -11,9 +12,6 @@ export class DebugPanel {
|
|
|
11
12
|
/** @internal */
|
|
12
13
|
constructor(engine, { open = false } = {}) {
|
|
13
14
|
/** @internal */ this.engine = engine;
|
|
14
|
-
/** @internal */ this.bench = null;
|
|
15
|
-
/** Stress test running (player auto-runs fast) @type {boolean} */
|
|
16
|
-
this.benchmarking = false;
|
|
17
15
|
/** Panel root element @type {HTMLElement} */
|
|
18
16
|
this.el = document.createElement('div');
|
|
19
17
|
const el = this.el;
|
|
@@ -50,18 +48,16 @@ export class DebugPanel {
|
|
|
50
48
|
</div>
|
|
51
49
|
<div class="res k" data-k="budget" hidden></div>
|
|
52
50
|
<div class="res k" data-k="startup" hidden></div>
|
|
53
|
-
<details ${engine.renderer.getSize(new
|
|
51
|
+
<details ${engine.renderer.getSize(new Vector2()).x > 600 ? 'open' : ''}><summary>Debug</summary><div class="c">
|
|
54
52
|
<div class="r"><label>Time scale</label><input data-i="ts" type="range" min="0" max="60" step="1"><output data-o="ts"></output></div>
|
|
55
53
|
<div class="r"><label>Time</label><input data-i="tod" type="range" min="0" max="1" step="0.005"><output data-o="tod"></output></div>
|
|
56
54
|
<div class="r"><label>Weather</label><select data-s="weather" style="grid-column:span 2;font:inherit;background:#222;color:#eee;border:1px solid #444;border-radius:6px;padding:3px">
|
|
57
55
|
</select></div>
|
|
58
|
-
<button type="button" data-b="bench">20 s stress test</button>
|
|
59
|
-
<div class="res" data-k="bench"></div>
|
|
60
56
|
</div></details>`;
|
|
61
57
|
this.engine.uiRoot.appendChild(el);
|
|
62
58
|
const q = s => el.querySelector(s);
|
|
63
59
|
/** @internal */ this.out = {}; el.querySelectorAll('[data-k]').forEach(n => this.out[n.dataset.k] = n);
|
|
64
|
-
const e = engine
|
|
60
|
+
const e = engine;
|
|
65
61
|
// controls for modules that are not installed are hidden
|
|
66
62
|
const hideRow = k => { const i = q(`[data-i="${k}"]`); if (i) i.closest('.r').hidden = true; };
|
|
67
63
|
// time rows follow the calendar, not the sky: an indoor game without a sky still scrubs its clock
|
|
@@ -70,8 +66,7 @@ export class DebugPanel {
|
|
|
70
66
|
const bind = (k, get, set, fmt) => {
|
|
71
67
|
const i = q(`[data-i="${k}"]`), o = q(`[data-o="${k}"]`);
|
|
72
68
|
i.value = get(); o.textContent = fmt(get());
|
|
73
|
-
i.addEventListener('input', () => { o.textContent = fmt(+i.value);
|
|
74
|
-
if (k === 'dens') i.addEventListener('change', () => set(+i.value));
|
|
69
|
+
i.addEventListener('input', () => { o.textContent = fmt(+i.value); set(+i.value); });
|
|
75
70
|
return i;
|
|
76
71
|
};
|
|
77
72
|
if (e.calendar) {
|
|
@@ -85,36 +80,9 @@ export class DebugPanel {
|
|
|
85
80
|
ws.value = e.weather.name;
|
|
86
81
|
}
|
|
87
82
|
ws.onchange = () => { if (ws.value === 'auto') e.weather.setAuto(true); else { e.weather.setAuto(false); e.weather.set(ws.value, { seconds: 8 }); } };
|
|
88
|
-
q('[data-b="bench"]').onclick = () => this.startBench();
|
|
89
83
|
engine.i18n.add({ 'zh-CN': { 'debug.toggle': '调试面板' }, en: { 'debug.toggle': 'Debug panel' } }); // the settings menu's rebind page shows this name
|
|
90
84
|
}
|
|
91
85
|
|
|
92
|
-
/**
|
|
93
|
-
* Start the stress test (seconds, default 20): the character auto-runs fast, continuously loading new chunks, and a report is shown in the panel at the end
|
|
94
|
-
* @param {number} [seconds]
|
|
95
|
-
* @returns {void}
|
|
96
|
-
*/
|
|
97
|
-
startBench(seconds = 20) {
|
|
98
|
-
if (this.bench) return;
|
|
99
|
-
this.bench = { t: 0, dur: seconds, dts: [], built: 0 };
|
|
100
|
-
this.out.bench.textContent = 'Testing: character runs straight at 32 m/s, continuously loading new chunks...';
|
|
101
|
-
this.benchmarking = true; this.engine.input.autopilot = { x: 0, y: 1, speed: 32 }; this.engine.adaptive.paused = true;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** @internal */
|
|
105
|
-
frame(dt, built) {
|
|
106
|
-
if (!this.bench) return;
|
|
107
|
-
const b = this.bench; b.t += dt; b.dts.push(dt); b.built += built;
|
|
108
|
-
if (b.t < b.dur) return;
|
|
109
|
-
this.benchmarking = false; this.bench = null; this.engine.input.autopilot = null; this.engine.adaptive.paused = false;
|
|
110
|
-
const d = b.dts.slice().sort((x, y) => y - x), sum = b.dts.reduce((x, y) => x + y, 0);
|
|
111
|
-
const n1 = Math.max(1, Math.floor(d.length * 0.01)), worst = d.slice(0, n1).reduce((x, y) => x + y, 0) / n1;
|
|
112
|
-
const avg = b.dts.length / sum, low = 1 / worst, L = this.limits();
|
|
113
|
-
const cls = (v, lim) => lim == null ? '' : v >= lim ? 'ok' : v >= lim * 0.6 ? 'mid' : 'bad';
|
|
114
|
-
const w = this.engine.terrain;
|
|
115
|
-
this.out.bench.innerHTML = `${w ? `View distance ${w.viewChunks * w.CHUNK}m · Density ${w.density}×` : ''}\nAvg FPS <b class="${cls(avg, L.fps)}">${avg.toFixed(1)}</b>\n1% low FPS <b class="${cls(low, L.low1)}">${low.toFixed(1)}</b>\nLongest frame ${(d[0] * 1000).toFixed(1)} ms\nChunks built: ${b.built}`;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
86
|
/** Budget limits (empty object if budget is off: numbers are not colored) @internal */
|
|
119
87
|
limits() { const b = this.engine.budget; return b.enabled ? { ...Object.fromEntries([...b.metrics].map(([k, m]) => [k, m.limit])), ...b.limits } : {}; }
|
|
120
88
|
|
|
@@ -150,7 +118,7 @@ export class DebugPanel {
|
|
|
150
118
|
const DEBUG_PANEL_PARAMS = keysSchema(['open']);
|
|
151
119
|
|
|
152
120
|
/**
|
|
153
|
-
* Debug panel -> engine.debug.panel: performance panel,
|
|
121
|
+
* Debug panel -> engine.debug.panel: performance panel, time and weather debugging. Collapsed by default; the action 'debugPanel' shows/hides it (presets.bindings.debug: F3); open: true shows it at start. Just do not install it in a release
|
|
154
122
|
* @param {{ open?: boolean }} [opts]
|
|
155
123
|
* @returns {ModuleDef<DebugPanel>}
|
|
156
124
|
*/
|
|
@@ -167,11 +135,10 @@ export function debug(opts = {}) {
|
|
|
167
135
|
},
|
|
168
136
|
dispose(e) { if (e.debug.panel === d) e.debug.panel = null; d?.el.remove(); },
|
|
169
137
|
frame(dt, e) { if (e.input.pressedRaw('debugPanel')) d.el.hidden = !d.el.hidden; },
|
|
170
|
-
// open matters to a screenshot (the panel covers a corner)
|
|
171
|
-
describe() { return { open: !d.el.hidden
|
|
138
|
+
// open matters to a screenshot (the panel covers a corner)
|
|
139
|
+
describe() { return { open: !d.el.hidden }; },
|
|
172
140
|
afterRender(dt, e) {
|
|
173
|
-
|
|
174
|
-
prof.n++; prof.t += dt; prof.cpu += e.cpuMs || 0;
|
|
141
|
+
prof.n++; prof.t += dt; prof.cpu += e._cpuMs || 0;
|
|
175
142
|
if (prof.t < 0.5) return;
|
|
176
143
|
const s = e.terrain?.stats || {}, info = stats(e.renderer);
|
|
177
144
|
d.stats({ fps: prof.n / prof.t, cpu: prof.cpu / prof.n, calls: info.drawCalls, tris: info.triangles, visible: s.visible ?? 0, loaded: s.loaded ?? 0, instances: s.instances ?? 0, apply: s.applyMs ?? 0, queued: s.queued ?? 0 });
|
package/modules/flow/contract.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// What any game-flow module must provide (fields: see gameplay/inventory.contract.js; shared check: @threedog/tools/contract).
|
|
2
|
-
// A state that stops the game holds engine.freeze('flow') (not engine.
|
|
2
|
+
// A state that stops the game holds engine.freeze('flow') (not engine.haltLoop), so describe().holds and the settings menu see who holds it.
|
|
3
3
|
export default {
|
|
4
4
|
name: 'flow',
|
|
5
5
|
api: ['define', 'go', 'transition'],
|
package/modules/flow/index.js
CHANGED
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
// engine.flow.go('paused'); engine.flow.state // 'paused'
|
|
6
6
|
// await engine.flow.transition(async () => engine.level.load('/models/town2.glb')); // lock input, fade out, load level, wait for ready, fade in
|
|
7
7
|
// Pause has one entry point: flow's 'paused' (internally engine.freeze('flow'); rendering continues); settings({ freezeWorld: true }) switches to it when the menu opens.
|
|
8
|
-
//
|
|
8
|
+
// engine.haltLoop() is another thing: it stops rendering too, for tests only. While frozen: fixed step, module fixed hooks, game clock, quest checks, timeline wait/tween all stop.
|
|
9
9
|
// engine.session.newGame / load / quit move flow too: back to the start state when a playthrough ends, then 'playing' when the next starts.
|
|
10
10
|
// Esc is not handled here: back goes through the UI focus stack (ui/Focus.js), and opens the settings menu when the stack is empty. Events: flow:change { from, to }, flow:transition { phase: 'start' | 'end' }.
|
|
11
|
-
import { warnMissing } from '../../core/validate.js';
|
|
12
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
11
|
+
import { warnMissing } from '../../core/base/validate.js';
|
|
12
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
13
13
|
import { fadeScreen } from '../../ui/UI.js';
|
|
14
|
+
import { unsettled } from '../../core/engine/headlessLoad.js';
|
|
14
15
|
/** @import { ModuleDef } from '../../types/core' */
|
|
15
16
|
/** @import { Flow, FlowOptions } from '../../types/gameplay' */
|
|
16
17
|
|
|
@@ -32,9 +33,9 @@ export function flow(opts = {}) {
|
|
|
32
33
|
if (def.freeze) { if (on) frozen ??= e.freeze('flow'); else { frozen?.remove(); frozen = null; } }
|
|
33
34
|
if (def.lockInput) { if (on) held ??= e.input.push('flow'); else { held?.remove(); held = null; } }
|
|
34
35
|
};
|
|
35
|
-
// wait until
|
|
36
|
-
const
|
|
37
|
-
const waitReady = () =>
|
|
36
|
+
// wait until the modules and the required nearby builds are ready (checked per engine frame, so step() advances it too)
|
|
37
|
+
const settled = () => !unsettled(e).length;
|
|
38
|
+
const waitReady = () => settled() ? Promise.resolve() : new Promise(res => { const h = e.onFrame(() => { if (settled()) { h.remove(); res(); } }); });
|
|
38
39
|
|
|
39
40
|
const api = {
|
|
40
41
|
/** Current state name */
|
|
@@ -87,7 +88,7 @@ export function flow(opts = {}) {
|
|
|
87
88
|
},
|
|
88
89
|
};
|
|
89
90
|
return {
|
|
90
|
-
name: 'flow', type: 'rules', params: FLOW_PARAMS, options: opts, label: 'Game flow', optional: ['music'],
|
|
91
|
+
name: 'flow', type: 'rules', provides: ['flow'], params: FLOW_PARAMS, options: opts, label: 'Game flow', optional: ['music'],
|
|
91
92
|
install(engine, ctx) { engine.i18n.add({ 'zh-CN': { 'module.flow': '游戏流程' }, en: { 'module.flow': 'game flow' } });
|
|
92
93
|
e = engine;
|
|
93
94
|
// initial state (title screen etc.): entered once the world is ready, so the game can define it after use()
|
|
@@ -100,7 +101,10 @@ export function flow(opts = {}) {
|
|
|
100
101
|
ctx.track(e.events.on('session:failed', () => { if (before) api.go(before); }));
|
|
101
102
|
return api;
|
|
102
103
|
},
|
|
104
|
+
// unloaded (unuse, replaces) in a state that stops the game: nothing else would ever end its freeze or input lock
|
|
105
|
+
dispose() { frozen?.remove(); held?.remove(); frozen = held = null; },
|
|
103
106
|
// ?play / applyState({ play }): leave the start state (a title) the way its Start button does; session:start then goes to 'playing'
|
|
107
|
+
stateKeys: ['play'],
|
|
104
108
|
applyState(e, { play }) { if (play != null && opts.start && opts.start !== 'playing' && api.state === opts.start) return e.session.newGame(); },
|
|
105
109
|
describe() { return { state: api.state, transitioning: api.transitioning }; },
|
|
106
110
|
};
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
// stackable ones with equal data share an entry, a stack-1 item is one entry per piece. Keys are unique across containers and kept when moved.
|
|
7
7
|
// Every method that takes an item also takes a key: count('sword') counts all swords, count('sword#3') only that one.
|
|
8
8
|
// Limits are optional: capacity (slots; an entry uses ceil(count / stack) slots) and maxWeight (sum of item weight × count). Locks and prices stay game rules.
|
|
9
|
-
import { fmt, DEV } from '../../core/validate.js';
|
|
10
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
11
|
-
import { failure } from '../../core/opsFail.js';
|
|
9
|
+
import { fmt, DEV } from '../../core/base/validate.js';
|
|
10
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
11
|
+
import { failure } from '../../core/ops/opsFail.js';
|
|
12
12
|
import { sig, freeze, canTrade, acceptsFrom, putIn, loadEntries } from './boxOps.js';
|
|
13
|
-
import { codedError } from '../../core/errorHints.js';
|
|
13
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
14
14
|
|
|
15
15
|
// Developer messages (warned once in DEV): add doesn't throw when full, which an AI would hardly notice
|
|
16
16
|
const STRINGS = {
|
|
@@ -41,8 +41,8 @@ export class Container {
|
|
|
41
41
|
count(x) { let n = 0; for (const e of this._entries) if (e.key === x || e.id === x) n += e.count; return n; }
|
|
42
42
|
/** At least n (default 1) of an item or key? @param {string} x @param {number} [n] @returns {boolean} */
|
|
43
43
|
has(x, n = 1) { return this.count(x) >= n; }
|
|
44
|
-
/** One entry by key: { key, id, count, data, def }, or
|
|
45
|
-
get(key) { const e = this._find(key); return e ? this._view(e) :
|
|
44
|
+
/** One entry by key: { key, id, count, data, def }, or undefined. @param {string} key */
|
|
45
|
+
get(key) { const e = this._find(key); return e ? this._view(e) : undefined; }
|
|
46
46
|
/** Every entry: [{ key, id, count, data, def }] (data is undefined for plain items; for custom UI). */
|
|
47
47
|
list() { return this._entries.map(e => this._view(e)); }
|
|
48
48
|
/** Slots used (an entry of 150 arrows with stack 99 uses 2). */
|
|
@@ -66,21 +66,22 @@ export class Container {
|
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* Add n (default 1) of an item, optionally with data for these pieces. Partial fit places what fits.
|
|
69
|
-
* Returns
|
|
70
|
-
* engine.actor, the local user's bag, toasts).
|
|
69
|
+
* Returns { ok: true, key, added }: key is the entry they went into ('arrow', or 'sword#3' for an item with data), added how many fit. None fit: { ok: false, code: 'full', facts: { id, n } }.
|
|
70
|
+
* silent suppresses the toast (only the container of engine.actor, the local user's bag, toasts).
|
|
71
71
|
* @example engine.inventory.container('chest-1').add('bandage', 2)
|
|
72
|
-
* @example const
|
|
72
|
+
* @example const r = engine.inventory.add('sword', 1, { data: { durability: 80, level: 3 } }); if (r.ok) equip(r.key); // r.key: 'sword#7'
|
|
73
73
|
* @param {string} id
|
|
74
74
|
* @param {number} [n]
|
|
75
75
|
* @param {{ data?: Record<string, any>, silent?: boolean }} [opts]
|
|
76
|
-
* @returns {string
|
|
76
|
+
* @returns {{ ok: boolean, key?: string, added?: number, code?: string, facts?: object, nextActions?: any[] }}
|
|
77
77
|
*/
|
|
78
78
|
add(id, n = 1, opts = {}) {
|
|
79
79
|
DEV && this.inv.engine.ops.guard(this._local ? 'inventory.add' : 'container.add');
|
|
80
80
|
readParams(`add('${id}')`, keysSchema(['data', 'silent']), opts);
|
|
81
81
|
if (isKey(id)) throw codedError('container', fmt(STRINGS.keyToAdd, { key: id }));
|
|
82
82
|
this.inv._known(id);
|
|
83
|
-
|
|
83
|
+
const before = this.count(id), key = this._put(id, n, copyData('add', id, opts?.data), null, !!opts?.silent);
|
|
84
|
+
return key === false ? failure({ code: 'full', facts: { id, n } }) : { ok: true, key, added: this.count(id) - before };
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Container table: implementation of inventory.container() / transfer() and the containers save part.
|
|
2
|
-
import { DEV } from '../../core/validate.js';
|
|
3
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
2
|
+
import { DEV, warnOnce } from '../../core/base/validate.js';
|
|
3
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
4
4
|
import { Container } from './Container.js';
|
|
5
|
-
import { codedError } from '../../core/errorHints.js';
|
|
5
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
6
6
|
|
|
7
7
|
/** Container table: implementation of inventory.container() / transfer(); bag is the home bag 'player' (saved as its own part, never removed). @internal */
|
|
8
8
|
export class Containers {
|
|
@@ -32,7 +32,8 @@ export class Containers {
|
|
|
32
32
|
this.map.set(id, c = new Container(this.inv, id, opts));
|
|
33
33
|
// place goods only on first creation; seeding is setup, so the ops guard lets it through
|
|
34
34
|
if (opts?.items) { c._start = { ...opts.items }; this._seed(c); }
|
|
35
|
-
} else { // container created first by a load, game code sets the limits afterwards; if it already exists, goods are not placed again
|
|
35
|
+
} else { // container created first by a load, game code sets the limits afterwards; if it already exists, goods are not placed again, but a later load of an older save needs them
|
|
36
|
+
if (opts?.items) c._start ??= { ...opts.items };
|
|
36
37
|
if (opts?.capacity != null) c.capacity = opts.capacity;
|
|
37
38
|
if (opts?.maxWeight != null) c.maxWeight = opts.maxWeight;
|
|
38
39
|
}
|
|
@@ -77,7 +78,15 @@ export class Containers {
|
|
|
77
78
|
/** @internal place a container's starting goods (content setup: the ops guard lets it through) */
|
|
78
79
|
_seed(c) {
|
|
79
80
|
c._entries = [];
|
|
80
|
-
this.inv.engine.ops.allow(() => {
|
|
81
|
+
this.inv.engine.ops.allow(() => {
|
|
82
|
+
for (const [item, n] of Object.entries(c._start)) {
|
|
83
|
+
const before = c.count(item);
|
|
84
|
+
c.add(item, n, { silent: true });
|
|
85
|
+
// a start list longer than the room is allowed (a game may start a shelf overfull on purpose), but the goods that did not fit are gone: say so once
|
|
86
|
+
const lost = n - (c.count(item) - before);
|
|
87
|
+
if (lost > 0) warnOnce(`inventory.container('${c.id}'): ${lost} of ${n} '${item}' in its starting items did not fit (capacity ${c.capacity}, maxWeight ${c.maxWeight}) and were not placed. Raise capacity or shorten items if they should all be there`);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
81
90
|
c.seeded = true;
|
|
82
91
|
}
|
|
83
92
|
/** Save: non-player containers that have contents or ever had starting contents placed (an emptied one is still recorded, or a load would treat it as new and place them again) */
|
|
@@ -20,10 +20,10 @@
|
|
|
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
22
|
import { uiFocus } from '../../ui/UI.js';
|
|
23
|
-
import { warnMissing, warnOnce } from '../../core/validate.js';
|
|
24
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
23
|
+
import { warnMissing, warnOnce, fmt } from '../../core/base/validate.js';
|
|
24
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
25
25
|
import { dialogueBox } from './dialogueBox.js';
|
|
26
|
-
import { codedError } from '../../core/errorHints.js';
|
|
26
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
27
27
|
import { Bubbles, bubblePart } from './dialogueBubbles.js';
|
|
28
28
|
// 'data' is the one slot for game-specific fields: other unknown keys stay typos (a misspelled next would silently end the dialogue)
|
|
29
29
|
const NODE_KEYS = ['text', 'next', 'choices', 'do', 'speaker', 'data'], CHOICE_KEYS = ['text', 'next', 'if', 'do', 'data'];
|
|
@@ -34,9 +34,8 @@ const STR = {
|
|
|
34
34
|
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
35
|
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
36
|
};
|
|
37
|
-
const checkChannel = c => { if (!CHANNELS.includes(c)) throw codedError('module-params', STR.channel
|
|
37
|
+
const checkChannel = c => { if (!CHANNELS.includes(c)) throw codedError('module-params', fmt(STR.channel, { got: String(c) })); };
|
|
38
38
|
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
39
|
const readLine = (fn, keys, o) => readParams(`dialogue.${fn}`, keysSchema(keys), o ?? {});
|
|
41
40
|
|
|
42
41
|
export class Dialogue {
|
|
@@ -44,7 +43,7 @@ export class Dialogue {
|
|
|
44
43
|
this.engine = engine;
|
|
45
44
|
this.scripts = new Map();
|
|
46
45
|
this.state = { get flags() { return engine.vars.flags; } }; // story flags = engine.vars.flags (autosaved)
|
|
47
|
-
this.
|
|
46
|
+
this.charsPerSecond = charsPerSecond;
|
|
48
47
|
// default: confirm only (a basic key). Other actions advance only when the game names them: advanceActions: ['confirm', 'interact']
|
|
49
48
|
this.advanceActions = advanceActions;
|
|
50
49
|
this.holdSeconds = holdSeconds;
|
|
@@ -95,7 +94,7 @@ export class Dialogue {
|
|
|
95
94
|
const step = id => {
|
|
96
95
|
const node = id && id !== 'end' && nodes[id];
|
|
97
96
|
if (!node || stopped) { finish(); return; }
|
|
98
|
-
if (node.choices?.length) { warnOnce(STR.bubbleChoices
|
|
97
|
+
if (node.choices?.length) { warnOnce(fmt(STR.bubbleChoices, { name, id })); finish(); return; }
|
|
99
98
|
const text = typeof node.text === 'function' ? node.text(this.state, this.engine) : node.text;
|
|
100
99
|
node.do?.(this.state, this.engine);
|
|
101
100
|
cur = this._bubbles.say(at, text, { speaker: node.speaker || (name.startsWith('__say_') ? '' : name), seconds, queue });
|
|
@@ -145,7 +144,9 @@ export class Dialogue {
|
|
|
145
144
|
}
|
|
146
145
|
|
|
147
146
|
_show(id) {
|
|
148
|
-
const a = this.active
|
|
147
|
+
const a = this.active;
|
|
148
|
+
if (!a) return; // a dialogue:start listener ended it
|
|
149
|
+
const node = id && a.nodes[id];
|
|
149
150
|
if (!node && id && id !== 'end') warnMissing('node', id, Object.keys(a.nodes)); // next points at a node that doesn't exist
|
|
150
151
|
if (!node || id === 'end') { this.end(); return; }
|
|
151
152
|
a.node = node; a.id = id;
|
|
@@ -156,7 +157,8 @@ export class Dialogue {
|
|
|
156
157
|
a.who = node.speaker || a.speaker;
|
|
157
158
|
this.full = String(text ?? ''); this.shown = 0; this.typing = true; this._opts = null;
|
|
158
159
|
this.engine.events.emit('dialogue:line', { script: a.speaker, node: id, speaker: a.who, text: this.full, data: node.data ?? {} });
|
|
159
|
-
if (
|
|
160
|
+
if (this.active !== a) return; // a dialogue:line listener ended it (a skip key)
|
|
161
|
+
if (!this.full || !(this.charsPerSecond > 0)) this._finishTyping(); // charsPerSecond 0 = whole line at once
|
|
160
162
|
else this._draw();
|
|
161
163
|
}
|
|
162
164
|
|
|
@@ -213,7 +215,7 @@ export class Dialogue {
|
|
|
213
215
|
const ops = this.engine.ops;
|
|
214
216
|
if (this.typing) {
|
|
215
217
|
const was = Math.floor(this.shown);
|
|
216
|
-
this.shown = Math.min(this.full.length, this.shown + dt * this.
|
|
218
|
+
this.shown = Math.min(this.full.length, this.shown + dt * this.charsPerSecond);
|
|
217
219
|
if (this.shown >= this.full.length) this._finishTyping();
|
|
218
220
|
else if (Math.floor(this.shown) !== was) this._draw(); // redraw only when another character shows
|
|
219
221
|
}
|
|
@@ -269,7 +271,7 @@ export function dialogue(opts = {}) {
|
|
|
269
271
|
if (!a && !bubbles.length) return;
|
|
270
272
|
const label = c => (typeof c.text === 'function' ? c.text(d.state, e) : c.text);
|
|
271
273
|
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 };
|
|
274
|
+
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
275
|
if (bubbles.length) ctx.out.ui.bubbles = bubbles;
|
|
274
276
|
}
|
|
275
277
|
},
|