threedog 0.5.0 → 0.7.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 +81 -1
- package/README.md +21 -13
- package/core/Assets.js +23 -12
- package/core/Audio.js +1 -1
- package/core/Baked.js +14 -23
- package/core/Budget.js +2 -2
- package/core/DebugOverrides.js +33 -18
- package/core/Describe.js +10 -11
- package/core/Engine.js +50 -46
- package/core/I18n.js +2 -2
- package/core/Input.js +11 -5
- package/core/Inspect.js +6 -3
- package/core/InspectMaterials.js +2 -3
- package/core/InspectPerf.js +11 -4
- package/core/MaterialInfo.js +7 -5
- package/core/Rays.js +7 -2
- package/core/Stream.js +2 -3
- package/core/UrlState.js +49 -9
- package/core/Views.js +1 -0
- package/core/adaptive.js +2 -2
- package/core/assetEntry.js +5 -2
- package/core/assetLoad.js +13 -15
- package/core/assetManifest.js +6 -3
- package/core/assetReport.js +4 -4
- package/core/batchGroups.js +9 -1
- package/core/catalog.js +16 -3
- package/core/chunkStream.js +1 -1
- package/core/copies.js +1 -1
- package/core/debugView.js +4 -4
- package/core/describeRender.js +104 -28
- package/core/describeText.js +6 -6
- package/core/errorCodes.js +72 -45
- package/core/errorHints.js +4 -1
- package/core/errors.js +4 -4
- package/core/events.generated.js +1 -0
- package/core/gameLights.js +9 -2
- package/core/lifecycle.js +2 -4
- package/core/lightWatch.js +5 -3
- package/core/loop.js +18 -11
- package/core/math.js +7 -0
- package/core/moduleSlots.js +32 -7
- package/core/moduleTypes.js +20 -7
- package/core/modules.js +7 -7
- package/core/namedModel.js +8 -4
- package/core/owned.js +33 -30
- package/core/page.js +43 -10
- package/core/pictureSlots.js +33 -0
- package/core/pictureWriters.js +343 -0
- package/core/plugins.js +64 -96
- package/core/sceneDelta.js +12 -4
- package/core/sceneMethods.js +2 -9
- package/core/services.js +1 -1
- package/core/shadowTypes.js +1 -1
- package/core/shadows.js +405 -0
- package/core/sharedPoint.js +5 -19
- package/core/stackFrames.js +16 -5
- package/core/stacks.js +6 -6
- package/core/startup.js +9 -11
- package/core/thingExplain.js +1 -1
- package/core/things.js +1 -1
- package/core/tier.js +1 -1
- package/core/util.js +1 -1
- package/core/validate.js +1 -1
- package/core/view.js +43 -0
- package/docs/AI.md +62 -58
- package/docs/API.md +15 -15
- package/docs/CODEMAP.md +36 -54
- package/docs/COMMANDS.md +28 -25
- package/docs/CONVENTIONS.md +36 -30
- package/docs/MIGRATING-0.4.md +93 -1
- package/docs/MIGRATING-0.6.md +126 -0
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/THREE.md +24 -22
- package/docs/api/assets.md +5 -3
- package/docs/api/audio.md +2 -2
- package/docs/api/budget.md +4 -0
- package/docs/api/characters.md +3 -1
- package/docs/api/collision.md +2 -2
- package/docs/api/engine.md +47 -20
- package/docs/api/events.md +2 -1
- package/docs/api/grids.md +8 -1
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +3 -0
- package/docs/api/input.md +3 -2
- package/docs/api/interactions.md +3 -1
- package/docs/api/inventory.md +1 -2
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +1 -1
- package/docs/api/occlusion.md +5 -0
- package/docs/api/particles.md +6 -3
- package/docs/api/pickups.md +6 -0
- package/docs/api/post.md +5 -3
- package/docs/api/sky.md +12 -10
- package/docs/api/terrain.md +12 -6
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/tools.md +8 -7
- package/docs/api/triggers.md +2 -0
- package/docs/api/vegetation.md +7 -2
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +6 -2
- package/docs/api/weather.md +5 -0
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +1 -1
- package/docs/recipes/01-new-game.md +19 -23
- package/docs/recipes/03-items-pickups.md +25 -4
- package/docs/recipes/05-props-bake.md +53 -37
- package/docs/recipes/06-clock-events.md +3 -3
- package/docs/recipes/07-flow-scenes-pause.md +12 -3
- package/docs/recipes/08-weather-sky.md +45 -57
- package/docs/recipes/09-materials-lights-models.md +185 -0
- package/docs/recipes/10-blender-level.md +2 -2
- package/docs/recipes/11-vehicles.md +3 -3
- package/docs/recipes/13-animation.md +13 -7
- package/docs/recipes/14-custom-module.md +7 -5
- package/docs/recipes/15-perf.md +3 -3
- package/docs/recipes/16-dev-bridge.md +22 -12
- package/docs/recipes/18-world.md +10 -8
- package/docs/recipes/19-shooting-picking.md +7 -5
- package/docs/recipes/20-content-actions-save.md +6 -2
- package/docs/recipes/21-camera.md +8 -3
- package/docs/recipes/23-ops.md +1 -1
- package/docs/recipes/26-ui-parts.md +35 -11
- package/docs/recipes/28-terrain.md +12 -12
- package/docs/recipes/29-grid.md +14 -5
- package/docs/recipes/30-templates.md +8 -3
- package/docs/recipes/31-audio.md +4 -4
- package/docs/recipes/32-action-game.md +18 -4
- package/docs/recipes/34-environment-lighting.md +102 -38
- package/docs/recipes/35-picture-from-reference.md +147 -0
- package/docs/recipes/36-sky-ground-plants.md +158 -0
- package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -13
- package/docs/recipes/38-environment-hooks.md +67 -0
- package/docs/recipes/40-scene.md +106 -27
- package/docs/recipes/42-terrain-shape.md +1 -1
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +66 -77
- package/docs/recipes/44-water-weather-hooks.md +191 -0
- package/docs/recipes/45-cascaded-shadows.md +121 -23
- package/docs/recipes/46-blender-art-route.md +17 -20
- package/docs/recipes/47-island-snow-backdrop.md +10 -12
- package/docs/recipes/49-game-module-contract.md +1 -1
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +181 -0
- package/docs/recipes/53-ground-up-close.md +12 -12
- package/docs/recipes/54-three-idioms.md +18 -18
- package/docs/recipes/55-mods-time-wrap.md +17 -5
- package/docs/recipes/56-webgpu-tsl.md +66 -23
- package/docs/recipes/57-control.md +39 -0
- 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 +39 -24
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +244 -0
- package/docs/recipes/63-third-person-start.md +77 -0
- package/docs/recipes/64-particles.md +35 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +7 -5
- 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/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/FINDINGS.md +53 -0
- package/examples/plain-picture/GAMEMAP.md +90 -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 +8 -3
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +25 -33
- 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/sheepisland/.threedog/content-index.json +1 -1
- package/examples/sheepisland/GAMEMAP.md +13 -10
- package/examples/sheepisland/assets.js +2 -2
- package/examples/sheepisland/content/templates.js +1 -1
- package/examples/sheepisland/content/vegetation.js +3 -1
- package/examples/sheepisland/main.js +15 -9
- package/examples/sheepisland/{style/models.js → models.js} +13 -24
- package/examples/sheepisland/picture/index.js +20 -0
- package/examples/sheepisland/picture/lights.js +34 -0
- package/examples/sheepisland/picture/materials.js +61 -0
- package/examples/sheepisland/picture/palette.js +60 -0
- package/examples/sheepisland/picture/sky.js +20 -0
- package/examples/sheepisland/views.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -11
- 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 +30 -67
- 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 +4 -3
- 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 +5 -3
- 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 +9 -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 +15 -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 +7 -16
- package/index.js +7 -7
- package/llms.txt +15 -13
- package/modules/ambience/Ambience.js +1 -1
- package/modules/calendar/Calendar.js +1 -1
- package/modules/calendar/index.js +1 -0
- package/modules/camera/FirstPersonCamera.js +1 -1
- package/modules/camera/FixedCamera.js +2 -2
- package/modules/camera/RtsCamera.js +1 -1
- package/modules/camera/common.js +7 -5
- package/modules/characters/Character.js +15 -10
- package/modules/characters/NPC.js +5 -5
- package/modules/characters/assetModel.js +5 -4
- package/modules/characters/index.js +28 -3
- package/modules/characters/movers/common.js +6 -1
- package/modules/characters/movers/manual.js +3 -0
- package/modules/characters/movers/support.js +25 -11
- package/modules/characters/npcSim.js +5 -1
- package/modules/characters/proceduralRig.js +18 -4
- package/modules/characters/useModel.js +2 -2
- package/modules/collision/Collision.js +4 -2
- package/modules/content/index.js +8 -0
- package/modules/content/models.js +56 -11
- package/modules/content/props.js +5 -3
- package/modules/content/rules.js +12 -4
- package/modules/content/templates.js +5 -3
- package/modules/gameplay/Interactions.js +91 -16
- package/modules/gameplay/Inventory.js +3 -3
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +1 -1
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -2
- package/modules/gameplay/pickups.js +62 -24
- package/modules/gameplay/questLog.js +2 -2
- package/modules/grid/Layer.js +13 -0
- package/modules/grid/index.js +40 -11
- package/modules/grid/preview.js +24 -15
- package/modules/grid/tiles.js +15 -19
- package/modules/hlod/index.js +3 -2
- package/modules/hud/index.js +13 -0
- package/modules/hud/parts.js +9 -7
- package/modules/level/index.js +5 -4
- package/modules/lights/index.js +12 -8
- package/modules/music/Music.js +1 -1
- package/modules/particles/Particles.js +41 -20
- package/modules/particles/effect.js +21 -6
- package/modules/photo/Photo.js +11 -10
- package/modules/settings/Settings.js +7 -7
- package/modules/settings/apply.js +5 -5
- package/modules/settings/sections.js +2 -2
- package/modules/settings/strings.js +1 -1
- package/modules/sky/Sky.js +104 -89
- package/modules/sky/clouds.js +16 -17
- package/modules/sky/dome.js +100 -0
- package/modules/sky/domeLayers.js +5 -5
- package/modules/sky/environment.js +45 -169
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +26 -90
- package/modules/sky/season.js +3 -3
- package/modules/sky/shader.js +35 -29
- package/modules/sky/skyModule.js +25 -22
- package/modules/sky/tint.js +9 -11
- package/modules/terrain/ChunkManager.js +29 -12
- package/modules/terrain/draw.js +154 -0
- package/modules/terrain/index.js +44 -66
- package/modules/terrain/terrainDefaults.js +2 -2
- package/modules/terrain/terrainEdit.js +1 -1
- package/modules/terrain/terrainGen.js +2 -2
- package/modules/triggers/index.js +10 -6
- package/modules/vegetation/Vegetation.js +58 -17
- package/modules/vegetation/draw.js +191 -0
- package/modules/vegetation/groundChunks.js +1 -1
- package/modules/vegetation/index.js +10 -10
- package/modules/water/Water.js +135 -88
- package/modules/water/surface.js +53 -53
- package/modules/weather/Weather.js +52 -17
- package/modules/weather/particles.js +13 -5
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +141 -0
- package/modules/world/World.js +2 -2
- package/modules/world/views.js +1 -1
- package/package.json +3 -2
- package/presets.js +2 -2
- package/render/PostFX.js +199 -41
- package/render/backend.js +52 -6
- package/render/cascades.js +195 -0
- package/render/cascades.tsl.js +96 -0
- package/render/daylight.js +39 -0
- package/render/detail.js +5 -5
- package/render/effects.js +41 -26
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/index.js +7 -5
- package/render/fx/patchNodes.tsl.js +1 -1
- package/render/fx/postWebGPU.tsl.js +30 -7
- package/render/fx/sky.tsl.js +19 -92
- package/render/fx/water.tsl.js +1 -1
- package/render/layers.js +14 -0
- package/render/lighting.js +6 -5
- package/render/lightmap.js +142 -0
- package/render/lights.js +23 -201
- package/render/materials.js +44 -160
- package/render/neutral.js +23 -0
- package/render/occlusion.js +184 -0
- package/render/ownFrame.js +1 -1
- package/render/patches.js +34 -29
- package/render/postWebGL.js +11 -3
- package/render/probes.js +179 -122
- package/render/slots.js +4 -4
- package/render/terms.js +53 -101
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +333 -296
- package/types/gameplay.d.ts +65 -26
- package/types/generated/core/Audio.d.ts +1 -1
- package/types/generated/core/DebugOverrides.d.ts +14 -6
- package/types/generated/core/Input.d.ts +9 -2
- package/types/generated/core/page.d.ts +9 -2
- package/types/generated/modules/grid/Layer.d.ts +8 -0
- package/types/generated/modules/grid/index.d.ts +29 -5
- package/types/generated/modules/particles/Particles.d.ts +13 -6
- package/types/generated/modules/sky/Sky.d.ts +85 -18
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/water/Water.d.ts +50 -3
- package/types/generated/modules/weather/Weather.d.ts +33 -3
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +2 -2
- package/types/generated/render/PostFX.d.ts +53 -10
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +19 -44
- package/types/generated/render/occlusion.d.ts +13 -0
- package/types/physics.d.ts +5 -3
- package/types/tsl.d.ts +8 -0
- package/types/world.d.ts +376 -57
- package/ui/Focus.js +12 -2
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +8 -4
- package/ui/UI.js +10 -10
- package/ui/cursor.js +1 -1
- package/ui/theme.js +33 -27
- package/ui/touchPart.js +1 -1
- 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/styleParts.js +0 -114
- 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/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/examples/action/look.js +0 -5
- 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/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
|
@@ -28,17 +28,17 @@ import { xzOf } from '../../core/math.js';
|
|
|
28
28
|
import { placeY } from '../../core/ground.js';
|
|
29
29
|
import { buildModel, settle, fitKey, 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
33
|
import { whyBad, readParams, keysSchema } from '../../core/params.js';
|
|
34
34
|
import { stagesProblems, stagedFields, growStages } from './stages.js';
|
|
35
35
|
import { codedError } from '../../core/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', '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
|
|
41
|
+
// content.spawn gets its position as an argument, so only the id and the picture / goods keys of the same table
|
|
42
42
|
const SPAWN_KEYS = PLACE_KEYS.filter(k => !['template', 'place', 'x', 'z', 'floor'].includes(k));
|
|
43
43
|
|
|
44
44
|
const STRINGS = {
|
|
@@ -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
|
|
@@ -9,10 +9,13 @@
|
|
|
9
9
|
// 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
10
|
// so one object can carry "Open" and "Lock" as two interactions with different action names (each bound to the game's own key).
|
|
11
11
|
// The prompt is the UI part 'prompt' (default interactionPrompt.js, CSS class .threedog-prompt): replace it or turn it off with engine.ui.set('prompt', ...);
|
|
12
|
-
// prompt height
|
|
12
|
+
// prompt height interactions({ promptHeight }) (meters)
|
|
13
13
|
// hold: seconds turns the press into "keep it down": the engine counts progress on fixed steps and interrupts it on release, leaving reach, disabled or
|
|
14
14
|
// locked input, in one place, so no game re-writes a hold timer per verb; the prompt part gets progress 0-1 to draw.
|
|
15
15
|
// approach: true walks the actor's character there first (walkTo), then uses it: point-and-click, "talk to the shopkeeper across the room".
|
|
16
|
+
// 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
|
+
// 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
|
+
// 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.
|
|
16
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
|
|
17
20
|
// 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,
|
|
18
21
|
// 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)
|
|
@@ -25,6 +28,7 @@ import { promptPart } from './interactionPrompt.js';
|
|
|
25
28
|
|
|
26
29
|
import { readParams, keysSchema } from '../../core/params.js';
|
|
27
30
|
import { codedError } from '../../core/errorHints.js';
|
|
31
|
+
import { DEV } from '../../core/validate.js';
|
|
28
32
|
import { vec3 } from '../../core/math.js';
|
|
29
33
|
import { Cells } from '../../core/cells.js';
|
|
30
34
|
|
|
@@ -38,6 +42,10 @@ const V = new THREE.Vector3(), W = new THREE.Vector3(), O = new THREE.Vector3(),
|
|
|
38
42
|
// when the circle covers more cells than exist)
|
|
39
43
|
const CELL = 8;
|
|
40
44
|
|
|
45
|
+
// The line that makes an action usable; the preset only for the action it covers. The message carries it because this fault looks like a working game to
|
|
46
|
+
// every other tool, so whoever hits it needs the fix on the spot.
|
|
47
|
+
const bindLine = action => action === 'interact' ? 'createEngine({ bindings: { ...presets.bindings.interact } }), or engine.input.bind(presets.bindings.interact) (E / gamepad X)'
|
|
48
|
+
: `engine.input.bind('${action}', ['KeyX'])`;
|
|
41
49
|
const SETUP_FIX = "e.g. engine.use(interactions({ ...presets.interactions.nearest })) (import { presets } from 'threedog'), or interactions({ pick: 'nearest' | 'facing' | 'aim' | fn })";
|
|
42
50
|
|
|
43
51
|
export class Interactions {
|
|
@@ -50,7 +58,7 @@ export class Interactions {
|
|
|
50
58
|
this.engine = engine;
|
|
51
59
|
this.action = action;
|
|
52
60
|
this.radius = radius;
|
|
53
|
-
this.promptHeight = promptHeight ??
|
|
61
|
+
this.promptHeight = promptHeight ?? 2.4;
|
|
54
62
|
/**
|
|
55
63
|
* How the interaction in front of the actor is chosen; can be swapped at runtime (first person: 'aim', top-down: 'nearest') @type {'nearest' | 'facing' |
|
|
56
64
|
* 'aim' | Function}
|
|
@@ -81,6 +89,10 @@ export class Interactions {
|
|
|
81
89
|
this._shown = false;
|
|
82
90
|
/** The hold in progress { id, action, seconds, progress (0-1) }, null when none. Read-only: releasing the key stops it @type {any} */
|
|
83
91
|
this.holding = null;
|
|
92
|
+
/** @internal dev: an add since the last key check */ this._keysDue = false;
|
|
93
|
+
/** @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
|
+
this._spent = new Set(); this._counted = new Map();
|
|
95
|
+
engine.saves.register('interactions', { version: 1, save: () => ({ spent: [...this._spent], counted: Object.fromEntries(this._counted) }), load: d => this._load(d) });
|
|
84
96
|
}
|
|
85
97
|
|
|
86
98
|
/**
|
|
@@ -90,38 +102,73 @@ export class Interactions {
|
|
|
90
102
|
* radius defaults to interactions({ radius }) (2.5 m; Infinity = from anywhere, usually with approach). Add two with different actions to give one object
|
|
91
103
|
* two verbs. hold: seconds the key must stay down (progress goes to the prompt; release, leaving reach or disabled interrupts it: interaction:interrupt).
|
|
92
104
|
* 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); saved, and back on a new game. The save
|
|
106
|
+
* 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.add; nothing without hud()); declare it once at setup with hud.counter(name, { label, value: 0, max }), not on session:start.
|
|
93
108
|
* 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,
|
|
94
109
|
* a net peer's or an NPC's id when they run interaction.use), so per-actor rules never read engine.player.
|
|
95
110
|
* @example engine.interactions.add(door, { label: (o, { actor }) => owns(actor) ? 'Open' : 'Knock', onUse: (o, { actor }) => engine.ops.run('door.open', { id: o.name }, { actor }) });
|
|
96
111
|
* @example engine.interactions.add(door, { label: 'Open', onUse: open });
|
|
97
112
|
* engine.interactions.add(door, { label: 'Lock', action: 'lock', enabled: () => hasKey, onUse: lock }); // a second verb: define the 'lock' action's key
|
|
98
113
|
* first
|
|
114
|
+
* @example engine.interactions.add(shell, { id: 'shell-1', label: 'Pick up', once: true, counter: 'shells' }); // a mesh you built: gone after E, counted
|
|
99
115
|
* @example engine.interactions.add(well, { label: 'Pump', hold: 1.5, onUse: fill }); // keep E down 1.5 s
|
|
100
116
|
* engine.interactions.add(clerk, { label: 'Talk', radius: Infinity, approach: true, onUse: talk }); // from anywhere: walk over, then talk
|
|
101
117
|
* @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:
|
|
102
118
|
* const r = engine.ops.run('interaction.use'); if (!r.ok) say(r.code) // 'full' for a pickup in a full bag
|
|
103
119
|
*/
|
|
104
120
|
add(target, opts = {}) {
|
|
105
|
-
readParams('interactions.add()', keysSchema(['id', 'label', 'radius', 'action', 'onUse', 'enabled', 'height', 'hold', 'approach']), opts);
|
|
106
|
-
const { label = '', radius = this.radius, action = this.action, onUse, enabled = () => true, height, hold = 0, approach = false } = opts;
|
|
121
|
+
readParams('interactions.add()', keysSchema(['id', 'label', 'radius', 'action', 'onUse', 'enabled', 'height', 'hold', 'approach', 'once', 'counter']), opts);
|
|
122
|
+
const { label = '', radius = this.radius, action = this.action, onUse, enabled: allowed = () => true, height, hold = 0, approach = false, once = false, counter } = opts;
|
|
107
123
|
if (!(typeof hold === 'number' && hold >= 0)) throw codedError('interaction-option', `interactions.add(): hold is the seconds the key stays down (hold: 1.5), got ${JSON.stringify(hold)}`, TypeError);
|
|
108
124
|
if (!(radius > 0)) throw codedError('interaction-option', `interactions.add(): radius is meters > 0 (Infinity = from anywhere), got ${radius}`, TypeError);
|
|
109
|
-
|
|
110
|
-
|
|
125
|
+
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
|
+
// 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
|
+
// 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 in development, where the fix is one word
|
|
129
|
+
let id = opts.id ?? this.engine.world?.buildingId ?? (once && target?.name || null);
|
|
130
|
+
if (once && DEV && (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
|
+
id ??= 'interaction' + (++this._seq);
|
|
111
132
|
if (this.get(id)) id += '#' + (++this._seq);
|
|
112
133
|
let object = target;
|
|
113
134
|
if (!target?.isObject3D) { object = new THREE.Object3D(); vec3(target, object.position); }
|
|
114
135
|
// a fixed position never moves: its world position is known now; an object is measured once per pass (_at)
|
|
115
|
-
|
|
136
|
+
// 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;
|
|
138
|
+
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,
|
|
116
139
|
_n: this._order++, _en: null, _ix: null, _lx: NaN, _lz: NaN, _par: undefined };
|
|
117
140
|
if (!target?.isObject3D) it._p.copy(object.position);
|
|
141
|
+
if (once && this._spent.has(id)) object.visible = false; // added again after a load (a level rebuilt): still gone
|
|
118
142
|
this._byId.set(id, it);
|
|
119
143
|
this._index(it);
|
|
120
144
|
return { remove: () => { if (it._gone) return; it._gone = true; this._byId.delete(it.id); this._unindex(it); if (this.current === it) this.current = null; } };
|
|
121
145
|
}
|
|
146
|
+
/** @internal Every use ends here (key, click, hold, approach, op): once and counter count only a use that went through */
|
|
147
|
+
_run(it, actor) {
|
|
148
|
+
const r = it.onUse?.(it.object, { actor });
|
|
149
|
+
if (r?.ok === false) return r;
|
|
150
|
+
if (it.counter && this.engine.hud) { this.engine.hud.add(it.counter); this._counted.set(it.counter, (this._counted.get(it.counter) ?? 0) + 1); }
|
|
151
|
+
// 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
|
+
if (it.once) { this._spent.add(it.id); it.object.visible = false; }
|
|
153
|
+
return r;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* @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
|
+
* what uses added. Only things whose state changed are shown or hidden: a once item the game hid itself stays hidden
|
|
158
|
+
*/
|
|
159
|
+
_load({ spent, counted }) {
|
|
160
|
+
const was = this._spent; this._spent = new Set(spent);
|
|
161
|
+
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
|
+
for (const name of new Set([...this._counted.keys(), ...Object.keys(counted)])) {
|
|
163
|
+
const d = (counted[name] ?? 0) - (this._counted.get(name) ?? 0);
|
|
164
|
+
if (d) this.engine.hud?.add(name, d);
|
|
165
|
+
}
|
|
166
|
+
this._counted = new Map(Object.entries(counted));
|
|
167
|
+
}
|
|
122
168
|
/** @internal File a new item: unbounded reach in the plain list, else in the cells (a followed one is placed for real on the next refresh) */
|
|
123
169
|
_index(it) {
|
|
124
170
|
this._actions.set(it.action, (this._actions.get(it.action) ?? 0) + 1);
|
|
171
|
+
this._keysDue = true;
|
|
125
172
|
if (it.radius === Infinity) { this._wide.add(it); return; }
|
|
126
173
|
// a fixed one is filed at its position; a followed one at its own xz (_ix), apart from _p, the exact per-pass measurement
|
|
127
174
|
it._en = { id: '#' + it._n, position: it._at === Infinity ? it._p : (it._ix = { x: NaN, z: NaN }), it };
|
|
@@ -274,20 +321,33 @@ export class Interactions {
|
|
|
274
321
|
this._pass = ++this._passes;
|
|
275
322
|
try { this._update(); } finally { this._pass = 0; }
|
|
276
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* @internal Dev: an interaction whose action has no key cannot be reached by any player, yet everything else about it works, so nothing else would say so.
|
|
326
|
+
* Thrown from the frame hook, it freezes gameplay and shows in engine.error, describe() and the test tools. Only once running: code right after
|
|
327
|
+
* `await engine.start()` may still bind. Release builds skip it; there the op and the prompt still say so.
|
|
328
|
+
*/
|
|
329
|
+
_checkKeys() {
|
|
330
|
+
this._keysDue = false;
|
|
331
|
+
for (const a of this._actions.keys()) {
|
|
332
|
+
if (this.engine.input.isUnbound(a)) throw codedError('interaction-no-key', `interactions: action '${a}' has no key, so the player can never use what was added to it. Add: ${bindLine(a)}`);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
277
335
|
/** @internal */
|
|
278
336
|
_update() {
|
|
337
|
+
if (DEV && this._keysDue && this.engine.phase === 'running') this._checkKeys();
|
|
279
338
|
this.options.length = 0;
|
|
280
339
|
const best = this.current = this._actions.size > 1 ? this._perAction() : this.pick();
|
|
281
340
|
if (best && this._actions.size === 1) this.options.push({ action: best.action, id: best.id, label: labelOf(best, this.engine.actor) });
|
|
282
341
|
const input = this.engine.input;
|
|
283
342
|
const part = this.engine.ui.get('prompt');
|
|
284
343
|
if (!best || !input.enabled || !part) { if (this._shown) part?.hide(); this._shown = false; return; }
|
|
285
|
-
|
|
344
|
+
// never an empty name: an action that needs a key says it has none; one with no key on purpose (a touch button, click only) shows just its label
|
|
345
|
+
const label = labelOf(best, this.engine.actor), key = input.label(best.action) || (input.isUnbound(best.action) ? this.engine.t('input.noKey') : '');
|
|
286
346
|
best.object.getWorldPosition(V); V.y += best.height ?? this.promptHeight;
|
|
287
347
|
const s = worldToScreen(this.engine, V);
|
|
288
348
|
// progress: the running hold on this one (0-1), 0 for a hold not started, null for a plain press
|
|
289
349
|
const progress = this.holding?.id === best.id ? this.holding.progress : best.hold > 0 ? 0 : null;
|
|
290
|
-
part.update({ id: best.id, action: best.action, key, label, text: `${key} · ${label}
|
|
350
|
+
part.update({ id: best.id, action: best.action, key, label, text: key ? `${key} · ${label}` : label, x: s.x, y: s.y, onScreen: s.onScreen, use: this._use, options: this.options, progress });
|
|
291
351
|
this._shown = true;
|
|
292
352
|
}
|
|
293
353
|
/** @internal Several actions: fill options, return the default action's pick (else the first found) for the prompt */
|
|
@@ -332,17 +392,30 @@ const INTERACTION_PARAMS = {
|
|
|
332
392
|
export function interactions(opts) {
|
|
333
393
|
const o = readParams('interactions', INTERACTION_PARAMS, opts ?? {});
|
|
334
394
|
let i = null;
|
|
335
|
-
return { name: 'interactions', type: 'rules', provides: ['interactions'], label: 'Interactions', params: INTERACTION_PARAMS, options: o, noSkip: 'input and prompt state only', stage: 'gameplay',
|
|
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',
|
|
336
396
|
// o: the schema defaults are filled in, the class repeats none
|
|
337
397
|
install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.interactions': '交互' }, en: { 'module.interactions': 'interactions' } }); i = new Interactions(e, o, ctx.track); defineUse(e, i); return i; },
|
|
338
398
|
fixed(dt) { i.fixed(dt); }, frame() { i.update(); },
|
|
339
399
|
// interactions are "weak" info: when an NPC, pickup or entity already reported the same object, only add "interactable: xxx"
|
|
340
400
|
describe(e, ctx) {
|
|
341
|
-
|
|
401
|
+
// no key: not "interactable", and no plain "interact: X" on an NPC's line, because no player input reaches it
|
|
402
|
+
for (const it of i._byId.values()) if (it.enabled(it.object, { actor: e.actor })) {
|
|
403
|
+
const name = labelOf(it, e.actor), noKey = e.input.isUnbound(it.action);
|
|
404
|
+
ctx.near(it.object, { name, kind: noKey ? 'noKey' : 'interactable', use: noKey ? `${name} (no key bound for '${it.action}')` : name }, true);
|
|
405
|
+
}
|
|
342
406
|
if (i.current) return { current: labelOf(i.current, e.actor) };
|
|
343
407
|
} };
|
|
344
408
|
}
|
|
345
409
|
|
|
410
|
+
/**
|
|
411
|
+
* What keeps input locked, for the inputLocked result: a bare code sent a script through describe to learn that the title was still up.
|
|
412
|
+
* by: the top opaque input context without its ui- / win- prefix ('title', 'settings', 'dialogue', 'cutscene', a game's own context).
|
|
413
|
+
*/
|
|
414
|
+
function lockFacts(e) {
|
|
415
|
+
const top = (e.input.holders ?? []).filter(h => !h.pass).at(-1)?.context ?? 'unknown', by = top.replace(/^(ui|win)-/, '');
|
|
416
|
+
return by === 'title' ? { by, fix: "start a run: engine.applyState({ play: true }) or threedog state play=1 (session.newGame() alone leaves the title open)" } : { by };
|
|
417
|
+
}
|
|
418
|
+
|
|
346
419
|
/** The engine op interaction.use { id?, action? }: what the interact key, the prompt click, the dev bridge and tests all run */
|
|
347
420
|
function defineUse(e, i) {
|
|
348
421
|
const find = (id, action, ctx) => id !== undefined ? i.get(id) : i.pick(ctx.actor, action);
|
|
@@ -354,7 +427,9 @@ function defineUse(e, i) {
|
|
|
354
427
|
const it = find(id, action, ctx);
|
|
355
428
|
if (!it) return id === undefined ? 'nothingNear' : 'unknown';
|
|
356
429
|
if (!it.enabled(it.object, { actor: ctx.actor })) return 'disabled';
|
|
357
|
-
|
|
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
|
+
if (ctx.actor === e.actor && !e.input.enabled) return { code: 'inputLocked', facts: lockFacts(e) };
|
|
358
433
|
if (it.approach && !walkerOf(e, ctx.actor)) return 'cannotWalk';
|
|
359
434
|
const p = e.actorPosition(ctx.actor);
|
|
360
435
|
if (it.approach || !p) return true;
|
|
@@ -367,13 +442,13 @@ function defineUse(e, i) {
|
|
|
367
442
|
// 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)
|
|
368
443
|
run(e, { id, action }, ctx) {
|
|
369
444
|
const it = find(id, action, ctx);
|
|
370
|
-
if (!it.approach) return
|
|
445
|
+
if (!it.approach) return i._run(it, ctx.actor);
|
|
371
446
|
const ch = walkerOf(e, ctx.actor), q = it.object.getWorldPosition(new THREE.Vector3());
|
|
372
|
-
if (Math.hypot(q.x - ch.position.x, q.z - ch.position.z) <= APPROACH_ARRIVE + 0.3) return
|
|
447
|
+
if (Math.hypot(q.x - ch.position.x, q.z - ch.position.z) <= APPROACH_ARRIVE + 0.3) return i._run(it, ctx.actor);
|
|
373
448
|
// used after arrival, so checked again then: removed or disabled while walking = not used
|
|
374
|
-
return { approaching: ch.walkTo(q, { arrive: APPROACH_ARRIVE }).then(r => r.status === 'arrived' && !it._gone && it.enabled(it.object, { actor: ctx.actor }) ?
|
|
449
|
+
return { approaching: ch.walkTo(q, { arrive: APPROACH_ARRIVE }).then(r => r.status === 'arrived' && !it._gone && it.enabled(it.object, { actor: ctx.actor }) ? i._run(it, ctx.actor) : r) };
|
|
375
450
|
},
|
|
376
451
|
offers(e, ctx) { const it = find(undefined, undefined, ctx); return it ? [{ id: it.id }] : []; },
|
|
377
|
-
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 window or
|
|
452
|
+
reasons: { unknown: 'No interaction with this id', noKey: 'Its action has no key bound, so the player cannot reach it', 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' },
|
|
378
453
|
});
|
|
379
454
|
}
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
// Chest / corpse / shelf: inventory.container('chest-1', { capacity: 8 }).add('fish'); inventory.transfer('chest-1', 'player', 'fish', 2);
|
|
11
11
|
// Player actions with items are ops: inventory.transfer / inventory.use / inventory.drop (inventoryOps.js).
|
|
12
12
|
//
|
|
13
|
-
//
|
|
14
|
-
// window UI part 'inventory' (engine.ui.set('inventory', false | { drop: true } | yourPart)); body via
|
|
15
|
-
// list styling CSS classes .threedog-win-inventory .threedog-row ... (override in
|
|
13
|
+
// Picture:
|
|
14
|
+
// window UI part 'inventory' (engine.ui.set('inventory', false | { drop: true } | yourPart)); body via ui.templates.inventory(data, { esc, t, icon })
|
|
15
|
+
// list styling CSS classes .threedog-win-inventory .threedog-row ... (override in ui.css)
|
|
16
16
|
import { checkOptions, warnMissing, freezeDef } from '../../core/validate.js';
|
|
17
17
|
import { readParams } from '../../core/params.js';
|
|
18
18
|
import { codedError } from '../../core/errorHints.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Default 'dialogue' UI part: a box at the bottom with the speaker, the typed text, numbered choice buttons (the one under the choice cursor has
|
|
2
2
|
// .is-cursor) and a "continue" hint.
|
|
3
3
|
// It only draws what Dialogue hands it; a click calls d.advance() / d.choose(i), which run the ops dialogue.advance / dialogue.choose.
|
|
4
|
-
//
|
|
4
|
+
// Picture: CSS classes .threedog-dlg* (ui.css). A whole different box: engine.ui.set('dialogue', yourPart) (recipes/26-ui-parts.md).
|
|
5
5
|
import { injectUICSS } from '../../ui/UI.js';
|
|
6
6
|
/** @import { Engine, UIPart } from '../../types/core' */
|
|
7
7
|
/** @import { DialogueView } from '../../types/gameplay' */
|
|
@@ -11,7 +11,7 @@ import { injectUICSS, worldToScreen, placeAt, esc } from '../../ui/UI.js';
|
|
|
11
11
|
/** @import { Engine, UIPart } from '../../types/core' */
|
|
12
12
|
|
|
13
13
|
const CSS = `
|
|
14
|
-
.threedog-bubble{position:absolute;left:0;top:0;transform:translate(-50%,-100%);max-width:240px;padding:6px 10px;border-radius:
|
|
14
|
+
.threedog-bubble{position:absolute;left:0;top:0;transform:translate(-50%,-100%);max-width:240px;padding:6px 10px;border-radius:var(--threedog-radius-small);background:var(--threedog-bg);color:var(--threedog-fg);font:14px/1.35 var(--threedog-font);pointer-events:none;box-shadow:var(--threedog-shadow-small)}
|
|
15
15
|
.threedog-bubble b{display:block;font-size:12px;opacity:.75}
|
|
16
16
|
.threedog-bubbles-screen{position:absolute;left:50%;bottom:22%;transform:translateX(-50%);display:flex;flex-direction:column;align-items:center;gap:6px;pointer-events:none}
|
|
17
17
|
.threedog-bubbles-screen .threedog-bubble{position:static;transform:none}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Default 'prompt' UI part: the "E · Talk" label that follows the nearest interaction. Interactions picks the target and projects it to the screen;
|
|
2
|
-
// this only draws { x, y, text } and turns a click into view.use() (the op interaction.use).
|
|
2
|
+
// this only draws { x, y, text } and turns a click into view.use() (the op interaction.use). Picture: CSS class .threedog-prompt (ui.css).
|
|
3
3
|
import { injectUICSS, placeAt } from '../../ui/UI.js';
|
|
4
4
|
/** @import { Engine, UIPart } from '../../types/core' */
|
|
5
5
|
/** @import { PromptView } from '../../types/gameplay' */
|
|
@@ -5,7 +5,7 @@ export default {
|
|
|
5
5
|
api: ['add', 'get', 'pick'],
|
|
6
6
|
ops: ['interaction.use'],
|
|
7
7
|
events: ['interaction:hold', 'interaction:interrupt'],
|
|
8
|
-
saves: {}, //
|
|
8
|
+
saves: { interactions: 1 }, // only what once / counter used; the interactions themselves the game / world adds again when things are rebuilt on load
|
|
9
9
|
describe: true,
|
|
10
10
|
options: { pick: 'nearest' }, // the probe needs no key (the game binds it in real use)
|
|
11
11
|
probe: {
|
|
@@ -23,7 +23,7 @@ export function windowData(inv) {
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Default 'inventory' part: the list window. Rows of items with a use function get a Use button; options.drop adds a Drop button. Buttons run ops.
|
|
26
|
-
* The
|
|
26
|
+
* The game can replace the body with ui.templates.inventory(data, { esc, t, icon }).
|
|
27
27
|
* @internal
|
|
28
28
|
*/
|
|
29
29
|
export function inventoryWindow(e, o = {}) {
|
|
@@ -37,7 +37,7 @@ export function inventoryWindow(e, o = {}) {
|
|
|
37
37
|
<span class="threedog-count">×${it.count}</span>${acts}</div>`;
|
|
38
38
|
};
|
|
39
39
|
const draw = d => {
|
|
40
|
-
const tpl = e.
|
|
40
|
+
const tpl = e.ui.templates.inventory;
|
|
41
41
|
const body = tpl ? tpl(d, tools) : d.items.length ? `<div class="threedog-list">${d.items.map(row).join('')}</div>` : `<p class="threedog-empty">${esc(e.t('inventory.empty'))}</p>`;
|
|
42
42
|
el.innerHTML = `<div class="threedog-win-head"><span>${esc(d.title)}</span><span><span class="threedog-win-hint">${esc(d.hint)}</span> `
|
|
43
43
|
+ `<button class="threedog-btn threedog-close" type="button">${esc(e.t('common.close'))}</button></span></div>${body}`;
|
|
@@ -10,10 +10,12 @@
|
|
|
10
10
|
// some games turn that into a bag entry. And who touches it is any actor: the local user, a net peer on the host, an NPC; the item goes into that actor's
|
|
11
11
|
// container, never a fixed 'player' bag. Taking is the op pickup.take (net: 'peer'), so a client's press is sent to the host and the host decides.
|
|
12
12
|
//
|
|
13
|
-
//
|
|
14
|
-
// gray box;
|
|
13
|
+
// Picture: shape = a model name from an asset pack: model option or the item's define(id, { model }), else a model named 'pickup:<item>', else 'pickup', else a
|
|
14
|
+
// gray box; pickups({ color, size, lift }) for the plain values; engine.pickups.material is the three.js material the box and geometry-only models draw with;
|
|
15
|
+
// spawn(pos, { mesh }) puts the game's own object down instead.
|
|
15
16
|
import * as THREE from 'three';
|
|
16
|
-
import {
|
|
17
|
+
import { neutralMaterial } from '../../render/neutral.js';
|
|
18
|
+
import { copyPatches, isEngineMade, markEngineMade } from '../../render/patches.js';
|
|
17
19
|
import { xzOf } from '../../core/math.js';
|
|
18
20
|
import { placeY } from '../../core/ground.js';
|
|
19
21
|
import { warnOnce } from '../../core/validate.js';
|
|
@@ -26,15 +28,19 @@ import { codedError, coded } from '../../core/errorHints.js';
|
|
|
26
28
|
|
|
27
29
|
const STRINGS = { 'zh-CN': { 'module.pickups': '拾取物', 'pickups.take': '捡起 {name}' }, en: { 'module.pickups': 'pickups', 'pickups.take': 'Pick up {name}' } };
|
|
28
30
|
const SPAWN_KEYS = ['give', 'count', 'data', 'name', 'model', 'color', 'mesh', 'respawnSeconds', 'bob', 'id', 'initial', 'zone', 'radius', 'auto'];
|
|
29
|
-
const STYLE_KEYS = ['color', 'size', 'lift'];
|
|
30
31
|
const NO_ACTORS = [];
|
|
32
|
+
const DEFAULT_COLOR = 0xcccccc;
|
|
31
33
|
// A net host measures peers at the position they last sent (a few steps old): pickup.take allows this much beyond the radius so a fair press is not refused
|
|
32
34
|
const NET_SLACK = 1;
|
|
33
35
|
|
|
34
36
|
export class Pickups {
|
|
35
37
|
/** @internal track: the module's ctx.track */
|
|
36
|
-
constructor(engine, { radius = 2, showDistance = 60, takers } = {}, track) {
|
|
38
|
+
constructor(engine, { radius = 2, showDistance = 60, takers, color = DEFAULT_COLOR, size = 0.25, lift = 0.4 } = {}, track) {
|
|
37
39
|
this.engine = engine;
|
|
40
|
+
/** Edge of the placeholder box (meters), read when one is built */ this.size = size;
|
|
41
|
+
/** Height above the ground new pickups float at (meters) */ this.lift = lift;
|
|
42
|
+
/** @internal */ this._material = neutralMaterial('pickup', { color });
|
|
43
|
+
/** @internal copies of the material for a pickup's own color or a vertex-colored geometry: 'color' or 'color:vc' -> material */ this._copies = new Map();
|
|
38
44
|
/** Reach of pickups that set no radius (meters); auto pickups are taken within it */ this.radius = radius;
|
|
39
45
|
/** @internal pickups float, spin and have a model only within this distance of the stream sources */ this.showDistance = showDistance;
|
|
40
46
|
/**
|
|
@@ -58,6 +64,27 @@ export class Pickups {
|
|
|
58
64
|
present(this);
|
|
59
65
|
}
|
|
60
66
|
|
|
67
|
+
/**
|
|
68
|
+
* The three.js material of every placeholder box and geometry-only model. Set it to swap the look of all of them at once; it is used as given, with no patches added.
|
|
69
|
+
* A pickup with a color of its own (spawn({ color }), inventory.define(id, { color })) or a vertex-colored geometry draws with a copy of it carrying that color.
|
|
70
|
+
* A file model and a generator's own Object3D keep their materials.
|
|
71
|
+
* @example engine.pickups.material = new THREE.MeshStandardMaterial({ color: 0xffd24a, metalness: 0.8, roughness: 0.3 });
|
|
72
|
+
* @type {THREE.Material}
|
|
73
|
+
*/
|
|
74
|
+
get material() { return this._material; }
|
|
75
|
+
set material(m) {
|
|
76
|
+
if (!m?.isMaterial) throw codedError('pickup-misuse', `engine.pickups.material takes a three.js material, got ${m}. Example: engine.pickups.material = new THREE.MeshStandardMaterial({ color: 0xffd24a })`);
|
|
77
|
+
const old = this._material;
|
|
78
|
+
if (m === old) return;
|
|
79
|
+
this._material = m;
|
|
80
|
+
for (const c of this._copies.values()) c.dispose();
|
|
81
|
+
this._copies.clear();
|
|
82
|
+
if (isEngineMade(old)) old.dispose(); // a material the game gave stays the game's
|
|
83
|
+
const w = this.engine.world;
|
|
84
|
+
// only what is built now: a pickup out of reach has no model, and one built later asks for the current material
|
|
85
|
+
for (const r of w.query({ kind: 'pickup' })) w.view(r.id)?.traverse(o => { if (o.userData.pickupColor !== undefined) /** @type {any} */ (o).material = pickupMaterial(this, o); });
|
|
86
|
+
}
|
|
87
|
+
|
|
61
88
|
/**
|
|
62
89
|
* Place a pickup at position. give: an item id (goes into the picker's container, inventory.of(actor); needs inventory()) or a function
|
|
63
90
|
* (e, { actor, pickup }) => result for an instant effect (heal, score, power-up; no inventory needed). Returning { ok: false, code } (failure(code)) leaves it
|
|
@@ -92,7 +119,7 @@ export class Pickups {
|
|
|
92
119
|
const data = copyData('pickups.spawn', what, opts.data);
|
|
93
120
|
const def = { id, kind: 'pickup', ...(item && { item }), count, bob, ...(data && { data }), ...(name != null && { name }), ...(m != null && { model: m }), ...(color != null && { color }),
|
|
94
121
|
...(radius != null && { radius }), ...(auto && { auto: true }), ...(respawnSeconds > 0 && { respawn: respawnSeconds }), ...(zone != null && { zone }),
|
|
95
|
-
position: [x, placeY(e, `pickups.spawn('${what}')`, x, z, refY) +
|
|
122
|
+
position: [x, placeY(e, `pickups.spawn('${what}')`, x, z, refY) + this.lift, z] };
|
|
96
123
|
const rec = initial ? w.add(def, { initial }) : id != null && w.get(id) || w.add(def); // initial data: world decides whether it exists / was deleted from the save (null)
|
|
97
124
|
if (rec && (rec.kind !== 'pickup' || (rec.item ?? null) !== item)) throw codedError('pickup-prop-id', `pickup id '${id}' is already used by other data (${rec.kind}${rec.item ? ' ' + rec.item : ''}): use a different id`);
|
|
98
125
|
const wid = rec?.id ?? id;
|
|
@@ -160,7 +187,7 @@ export class Pickups {
|
|
|
160
187
|
|
|
161
188
|
const inReach = (rec, p, r) => { const dx = rec.position.x - p.x, dy = rec.position.y - (p.y ?? 0), dz = rec.position.z - p.z; return dx * dx + dy * dy + dz * dz <= r * r; };
|
|
162
189
|
|
|
163
|
-
/** Register how pickups
|
|
190
|
+
/** Register how pickups picture and respawn (once, on install) @internal */
|
|
164
191
|
function present(pk) {
|
|
165
192
|
const e = pk.engine, w = e.world;
|
|
166
193
|
w.present('pickup', {
|
|
@@ -172,7 +199,7 @@ function present(pk) {
|
|
|
172
199
|
const t = e.time.now('real'), x = rec.position.x;
|
|
173
200
|
o.rotation.y = t * 1.5 + x; o.position.y = rec.position.y + Math.sin(t * 2 + x) * 0.08;
|
|
174
201
|
},
|
|
175
|
-
// only detached: a game's mesh is the game's, a model clone shares geometry / material with its prototype (protoOf),
|
|
202
|
+
// only detached: a game's mesh is the game's, a model clone shares geometry / material with its prototype (protoOf), the material is shared by every pickup;
|
|
176
203
|
// the placeholder box is the one thing built here alone, so its geometry is freed
|
|
177
204
|
dispose: (rec, o) => { o.userData.useHandle?.remove(); e.detach(o); o.traverse(c => { if (c.userData.ownGeometry) /** @type {any} */ (c).geometry.dispose(); }); },
|
|
178
205
|
});
|
|
@@ -182,7 +209,7 @@ function present(pk) {
|
|
|
182
209
|
}
|
|
183
210
|
|
|
184
211
|
// A pickup's shape goes one way only: a model name from assets (same protoOf as content props / templates: file or code-generated, cache, bake and shadow rules are identical).
|
|
185
|
-
// Name order: the pickup's own model -> the item definition's model -> 'pickup:<item id>' in assets -> 'pickup' -> neutral grey-box placeholder (warns once).
|
|
212
|
+
// Name order: the pickup's own model -> the item definition's model -> 'pickup:<item id>' in assets -> 'pickup' -> neutral grey-box placeholder (warns once).
|
|
186
213
|
const NO_PICKUP = "pickups: no model for '{item}', so it lies on the ground as a gray box (a placeholder). Register a model in an asset pack and name it: "
|
|
187
214
|
+ "pickups.spawn(p, { model: 'gem' }) / inventory.define('{item}', { model: 'gem' }), or call the model 'pickup:{item}' (this item) / 'pickup' (every pickup without its own)";
|
|
188
215
|
const NO_NAME = "pickups: '{item}' has model '{model}', but no asset pack registers a model of that name (engine.assets.manifest({ models: { {model}: fn | '/models/{model}.glb' } })); using the gray placeholder box";
|
|
@@ -202,21 +229,21 @@ function pickupModelName(e, item, model) {
|
|
|
202
229
|
* file models must download and generators may read the dev cache, and none of that should make "a pickup nearby" appear a frame late.
|
|
203
230
|
*/
|
|
204
231
|
function model(pk, rec) {
|
|
205
|
-
const e = pk.engine, def = rec.item && e.inventory ? e.inventory.item(rec.item) : {}
|
|
232
|
+
const e = pk.engine, def = rec.item && e.inventory ? e.inventory.item(rec.item) : {};
|
|
206
233
|
let obj = pk._live.get(rec.id)?.mesh;
|
|
207
234
|
if (obj) obj.castShadow = true; // a mesh the game passed in stays the game's; only made to cast
|
|
208
235
|
else {
|
|
209
|
-
const color = rec.color ?? def.color ??
|
|
236
|
+
const color = rec.color ?? def.color ?? null, name = pickupModelName(e, rec.item ?? null, rec.model ?? def.model), holder = new THREE.Group();
|
|
210
237
|
holder.name = name ?? 'pickup'; holder.userData.name = holder.name; obj = holder;
|
|
211
238
|
const box = () => { // the neutral placeholder: also what a model that failed to build falls back to
|
|
212
|
-
const size =
|
|
213
|
-
m.userData.ownGeometry = true; holder.add(m);
|
|
239
|
+
const size = pk.size, m = shadowDefaults(new THREE.Mesh(new THREE.BoxGeometry(size, size, size)), {});
|
|
240
|
+
m.userData.ownGeometry = true; drawnBy(pk, m, color); holder.add(m);
|
|
214
241
|
};
|
|
215
242
|
if (!name) box();
|
|
216
243
|
else protoOf(e, pk, name).then(proto => {
|
|
217
244
|
const o = proto.obj.clone(); // geometry / materials stay the prototype's (shadow flags were settled once there, as for content props)
|
|
218
|
-
// generator gave only geometry:
|
|
219
|
-
if (proto.fromGeometry)
|
|
245
|
+
// generator gave only geometry: draw it with the pickups material in the item's own color (same color shares one); generators that return a full Object3D / file models stay as they are
|
|
246
|
+
if (proto.fromGeometry) drawnBy(pk, o, color);
|
|
220
247
|
holder.add(o);
|
|
221
248
|
}).catch(err => { warnOnce(`pickups: model '${name}' of '${rec.item ?? rec.id}' failed to build (${err?.message ?? err}); showing the gray placeholder box`); box(); });
|
|
222
249
|
}
|
|
@@ -233,12 +260,22 @@ function model(pk, rec) {
|
|
|
233
260
|
return obj;
|
|
234
261
|
}
|
|
235
262
|
|
|
236
|
-
/**
|
|
237
|
-
function
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
263
|
+
/** Mark a mesh as drawn by the pickups material (color: its own, or null) and give it that material @internal */
|
|
264
|
+
function drawnBy(pk, mesh, color) { mesh.userData.pickupColor = color; mesh.material = pickupMaterial(pk, mesh); }
|
|
265
|
+
|
|
266
|
+
/** The material of one marked mesh: pk.material itself, or a copy shared by every pickup of that color (and vertex colors or not) @internal */
|
|
267
|
+
function pickupMaterial(pk, mesh) {
|
|
268
|
+
const color = mesh.userData.pickupColor, vc = !!mesh.geometry.attributes.color, base = pk.material;
|
|
269
|
+
if (color == null && !vc) return base;
|
|
270
|
+
const key = color + (vc ? ':vc' : '');
|
|
271
|
+
if (!pk._copies.has(key)) {
|
|
272
|
+
const m = copyPatches(base, base.clone());
|
|
273
|
+
if (color != null) /** @type {any} */ (m).color?.set(color);
|
|
274
|
+
if (vc) m.vertexColors = true;
|
|
275
|
+
if (isEngineMade(base)) markEngineMade(m);
|
|
276
|
+
pk._copies.set(key, m);
|
|
277
|
+
}
|
|
278
|
+
return pk._copies.get(key);
|
|
242
279
|
}
|
|
243
280
|
|
|
244
281
|
/** The op pickup.take { id }: the interact key, auto pickups, a net peer's request, the dev bridge and tests all run it, as ctx.actor @internal */
|
|
@@ -269,12 +306,15 @@ const PICKUP_PARAMS = {
|
|
|
269
306
|
radius: { type: 'number', default: 2, min: 0, desc: 'reach of pickups that set no radius (meters); auto pickups are taken within it' },
|
|
270
307
|
showDistance: { type: 'number', default: 60, min: 0, desc: 'pickups have a model, float and spin only within this distance of the stream sources (meters)' },
|
|
271
308
|
takers: { type: 'any', optional: true, desc: 'e => actor ids that walk into auto pickups (default engine.actor, plus net peers on a host)' },
|
|
309
|
+
color: { type: 'any', default: DEFAULT_COLOR, desc: 'color of the placeholder box and geometry-only models when the pickup and its item set none' },
|
|
310
|
+
size: { type: 'number', default: 0.25, min: 0, desc: 'edge of the placeholder box (meters)' },
|
|
311
|
+
lift: { type: 'number', default: 0.4, desc: 'height above the ground a pickup floats at (meters)' },
|
|
272
312
|
};
|
|
273
313
|
|
|
274
314
|
/**
|
|
275
315
|
* Pickups module: things on the ground that give whoever takes them an item (into that actor's container) or an instant effect. Installs engine.pickups and
|
|
276
316
|
* the op pickup.take. Needs world() first; interactions() for the key prompt (auto: true pickups need none); inventory() only for give: itemId.
|
|
277
|
-
* Options: radius (default reach, 2 m), showDistance (60 m), takers (who walks into auto pickups).
|
|
317
|
+
* Options: radius (default reach, 2 m), showDistance (60 m), takers (who walks into auto pickups), color, size, lift (the placeholder's plain values); engine.pickups.material for the picture.
|
|
278
318
|
* @example engine.use(openWorld(), interactions({ ...presets.interactions.nearest }), inventory(), pickups())
|
|
279
319
|
* @example engine.use(world(), pickups({ radius: 1 })) // coins and health packs only: auto pickups with give functions, no inventory, no prompt
|
|
280
320
|
*/
|
|
@@ -285,8 +325,6 @@ export function pickups(opts = {}) {
|
|
|
285
325
|
name: 'pickups', type: 'rules', label: 'Pickups', params: PICKUP_PARAMS, options: o, requires: ['world'], optional: ['interactions', 'inventory', 'net'], stage: 'gameplay',
|
|
286
326
|
noSkip: 'auto pickups are spatial; respawn follows the game clock',
|
|
287
327
|
install(e, ctx) {
|
|
288
|
-
// same rule as style.weather: style sections a module reads go through readParams; the 0.2 style.pickup.model (no longer read) names the new form first (in dev), never silently does nothing
|
|
289
|
-
if (e.style.pickup) readParams('style.pickup', keysSchema(STYLE_KEYS), e.style.pickup);
|
|
290
328
|
pk = new Pickups(e, opts, ctx.track); defineTake(e, pk); return pk;
|
|
291
329
|
},
|
|
292
330
|
fixed() { pk._auto(); },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The quest log window as the UI part 'questLog'. Quests keeps the behavior through engine.ui (the J key toggles it; open = UI focus stack, input lock,
|
|
2
2
|
// Esc closes, ui:open / ui:close 'questLog'); the part only draws { title, key, quests, close() }. Replace it or turn it off with engine.ui.set('questLog', ...).
|
|
3
|
-
// Default
|
|
3
|
+
// Default picture: a .threedog-win window; its body can be replaced by ui.templates.quests({ quests }, { esc, t }) or restyled via .threedog-quest*.
|
|
4
4
|
import { injectUICSS, esc } from '../../ui/UI.js';
|
|
5
5
|
/** @import { Engine, UIPart } from '../../types/core' */
|
|
6
6
|
/** @import { QuestLogView } from '../../types/gameplay' */
|
|
@@ -25,7 +25,7 @@ function questLogPart(engine) {
|
|
|
25
25
|
const draw = v => {
|
|
26
26
|
if (!w) { w = document.createElement('div'); w.className = 'threedog-ui threedog-win threedog-win-quests'; engine.uiRoot.appendChild(w); }
|
|
27
27
|
w.hidden = false;
|
|
28
|
-
const tpl = engine.
|
|
28
|
+
const tpl = engine.ui.templates.quests;
|
|
29
29
|
w.innerHTML = `<div class="threedog-win-head"><span>${esc(v.title)}</span><span><span class="threedog-win-hint">${esc(v.key)}</span> <button class="threedog-btn threedog-close" type="button">${esc(engine.t('common.close'))}</button></span></div>${tpl ? tpl(v, tools) : body(v)}`;
|
|
30
30
|
w.querySelector('.threedog-close').onclick = () => v.close();
|
|
31
31
|
};
|
package/modules/grid/Layer.js
CHANGED
|
@@ -42,6 +42,19 @@ export class Layer {
|
|
|
42
42
|
/** @internal 'i,j' -> authored data (content/grids.js layers): what the save diffs against */ this._base = new Map();
|
|
43
43
|
/** @internal the last save diff applied, so a baseline set after the load (content after the save) still gets it */ this._diff = null;
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* The three.js material of this layer's tiles (null when it draws none: a data layer, tiles: false or your own part). Set it to swap the picture, used as given.
|
|
47
|
+
* Tile colors are vertex colors, so a material with vertexColors: true shows them; without it, its own color covers every tile.
|
|
48
|
+
* @example field.layer('soil').material = new THREE.MeshStandardMaterial({ vertexColors: true, roughness: 1 });
|
|
49
|
+
* @type {import('three').Material | null}
|
|
50
|
+
*/
|
|
51
|
+
get material() { return this.grid._owner._tiles.get(this)?.mesh?.material ?? null; }
|
|
52
|
+
set material(m) {
|
|
53
|
+
const mesh = this.grid._owner._tiles.get(this)?.mesh;
|
|
54
|
+
if (!mesh) throw codedError('grids-misuse', `layer '${this.name}'.material: this layer draws no default tiles; give it a picture first: grid.layer('${this.name}', { tiles: true })`);
|
|
55
|
+
if (!m?.isMaterial) throw codedError('grids-misuse', `layer '${this.name}'.material takes a three.js material, got ${m}`);
|
|
56
|
+
mesh.material = m;
|
|
57
|
+
}
|
|
45
58
|
/** @internal */
|
|
46
59
|
_guard(what) { DEV && this.grid.engine.ops.guard(`grid layer ${this.grid.name}.${this.name}.${what}`); }
|
|
47
60
|
/**
|