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
|
@@ -4,16 +4,15 @@
|
|
|
4
4
|
// a world coordinate.
|
|
5
5
|
// Optional floor (reference height on multi-layer ground) and y (meters above that ground): see content.where.
|
|
6
6
|
import { toast } from '../../ui/UI.js';
|
|
7
|
-
import {
|
|
8
|
-
import { vegetationModel } from '../../core/namedModel.js';
|
|
7
|
+
import { vegetationModel } from '../../core/assets/namedModel.js';
|
|
9
8
|
import { addProps, needWorld } from './props.js';
|
|
10
9
|
import { defineTemplates } from './templates.js';
|
|
11
10
|
import { srcOf, applyRenames, pickupId } from './ids.js';
|
|
12
|
-
import { DEV, warnOnce } from '../../core/validate.js';
|
|
13
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
14
|
-
import { NO_GAME_EFFECTS, contentFiles, kindProblems, unknownContent
|
|
15
|
-
import { codedError, coded } from '../../core/errorHints.js';
|
|
16
|
-
import { reportError } from '../../core/errors.js';
|
|
11
|
+
import { DEV, warnOnce } from '../../core/base/validate.js';
|
|
12
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
13
|
+
import { NO_GAME_EFFECTS, contentFiles, kindProblems, unknownContent } from './rules.js';
|
|
14
|
+
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
15
|
+
import { reportError } from '../../core/base/errors.js';
|
|
17
16
|
|
|
18
17
|
const each = (o, fn) => Object.entries(o || {}).forEach(([k, v]) => fn(k, v));
|
|
19
18
|
const all = (o, fn) => Object.entries(o || {}).every(([k, n]) => fn(k, n));
|
|
@@ -50,10 +49,9 @@ const markerId = raw => raw.id ?? (typeof raw === 'string' ? raw : raw.place ??
|
|
|
50
49
|
/**
|
|
51
50
|
* Load one content pack. c is the merged object of content/index.js (or one pack of a list); api is engine.content; ids is the IdCheck shared by every pack of
|
|
52
51
|
* this load call (ids.js); st is the content module's load state (shared across repeated load calls):
|
|
53
|
-
* { triggers: merged trigger table, subs: listener handles, startOn: quest id -> listener handle,
|
|
54
|
-
* levelPlace(name) }
|
|
52
|
+
* { triggers: merged trigger table, subs: listener handles, startOn: quest id -> listener handle, levelPlace(name) }
|
|
55
53
|
* Order: vocabulary -> key actions -> vegetation -> items -> containers -> pickups -> NPCs -> dialogues -> quests -> trigger zones -> templates -> props.
|
|
56
|
-
* Pickups, props and NPCs are initial world data: the save records only changes and removals, independent of load order (rules at the top of world/
|
|
54
|
+
* Pickups, props and NPCs are initial world data: the save records only changes and removals, independent of load order (rules at the top of world/persist.js).
|
|
57
55
|
* Positions that use level markers (not in places) belong to the current level: pickup, prop and NPC data carry a zone (= current level name,
|
|
58
56
|
* engine.world.zone),
|
|
59
57
|
* a level change only tears down models and they are rebuilt on return, with taken / moved / removed state intact; trigger zones are not data and are removed
|
|
@@ -81,15 +79,15 @@ export function loadContent(e, api, c, st, ids) {
|
|
|
81
79
|
// a pack's actions are the game's own (owner 'game'): loading the pack again replaces them, it is not a second binder
|
|
82
80
|
each(c.actions, (name, a) => e.input.action(name, { label: a.label, keys: a.keys, ...(a.context ? { context: a.context } : {}) }));
|
|
83
81
|
|
|
84
|
-
// audio: sounds / footsteps by name into engine.audio.config, rules to ambience() / music() (core/audioRules.js). A pack loaded again
|
|
82
|
+
// audio: sounds / footsteps by name into engine.audio.config, rules to ambience() / music() (core/audio/audioRules.js). A pack loaded again
|
|
85
83
|
// replaces its own rules (hot reload): a named pack by its name, an unnamed one by the data object itself, so loading the same object
|
|
86
84
|
// twice never stacks its rules (a fresh key per load did); two different unnamed objects both keep theirs
|
|
87
85
|
if (c.audio) e.audio.contentPack(c.name ? 'pack:' + c.name : c, c.name ? `pack "${c.name}"` : 'pack (no name)', c.audio);
|
|
88
86
|
|
|
89
|
-
// views: named fixed camera views (core/Views.js); defining a name again replaces it, so a hot reload just works
|
|
87
|
+
// views: named fixed camera views (core/scene/Views.js); defining a name again replaces it, so a hot reload just works
|
|
90
88
|
each(c.views, (name, v) => e.views.define(name, v));
|
|
91
89
|
|
|
92
|
-
// vegetation: model names resolve through vegetationModel (
|
|
90
|
+
// vegetation: model names resolve through vegetationModel (core/assets/namedModel.js, the same resolver vegetation.define uses for a name); register all
|
|
93
91
|
// kinds at the same moment once all models are ready
|
|
94
92
|
// (each registration rebuilds terrain chunks; registering one by one would rebuild several times at start). content's isReady waits for them
|
|
95
93
|
const veg = [];
|
|
@@ -115,7 +113,6 @@ export function loadContent(e, api, c, st, ids) {
|
|
|
115
113
|
origin(id, c.pickups, i);
|
|
116
114
|
});
|
|
117
115
|
|
|
118
|
-
const hpd = e.calendar?.hoursPerDay ?? 24;
|
|
119
116
|
each(c.npcs, (id, n) => { // the key in content is the NPC's stable id (used by saves and quest targets)
|
|
120
117
|
const plan = n.schedule ?? [];
|
|
121
118
|
ids.claim(id, `npcs.${id}`);
|
|
@@ -123,7 +120,7 @@ export function loadContent(e, api, c, st, ids) {
|
|
|
123
120
|
// The content form owns start / schedule (clock strings, places) and the id (the key), so those are translated below and not passed as written
|
|
124
121
|
readParams(`content npcs.${id}`, keysSchema([...e.npcs.optionKeys.filter(k => !['id', 'position', 'zone', 'initial'].includes(k)), 'start']), n);
|
|
125
122
|
const { start: _s, schedule: _p, ...rest } = n;
|
|
126
|
-
e.npcs.add({ ...rest, id, schedule: plan.map(s => ({ at:
|
|
123
|
+
e.npcs.add({ ...rest, id, schedule: plan.map(s => ({ at: s.at, position: where(s) })), position: where(n.start || plan[0]), zone: zoneOf(n.start, ...plan), initial: true });
|
|
127
124
|
origin(id, c.npcs, id);
|
|
128
125
|
});
|
|
129
126
|
|
|
@@ -162,7 +159,7 @@ export function loadContent(e, api, c, st, ids) {
|
|
|
162
159
|
...(q.fail && { fail: () => api.test(q.fail) }), ...(q.onFail && { onFail: () => api.run(q.onFail) }),
|
|
163
160
|
});
|
|
164
161
|
st.startOn.get(id)?.remove(); // loading the same quest again: replace the old listener instead of attaching twice
|
|
165
|
-
if (q.startOn) st.startOn.set(id, e.events.on(q.startOn, () => e.quests.start(id)));
|
|
162
|
+
if (q.startOn) st.startOn.set(id, st.track(e.events.on(q.startOn, () => e.quests.start(id))));
|
|
166
163
|
});
|
|
167
164
|
|
|
168
165
|
// trigger zones: fromLevel = the level's trigger_<tag> marker; otherwise placed by position. Enter/exit effects look up the merged table, and the listener is
|
|
@@ -191,7 +188,7 @@ export function loadContent(e, api, c, st, ids) {
|
|
|
191
188
|
if (c.props?.length) addProps(e, api, c.props, st, zoneOf, ids);
|
|
192
189
|
|
|
193
190
|
// game kinds last: their data may name the items, NPCs and places loaded above
|
|
194
|
-
each(st.kinds, (name, k) => { if (c[name] !== undefined) k.load(e, c[name], api); });
|
|
191
|
+
each(st.kinds, (name, k) => { if (c[name] !== undefined) k.load?.(e, c[name], api); });
|
|
195
192
|
}
|
|
196
193
|
|
|
197
194
|
/** Op names that content data refers to ({ op: [...] } / { can: [...] } anywhere), checked against engine.ops once the game is ready */
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// What the marker / clearMarker effects show: playthrough state, kept in the 'content' save part, so a load shows the save's markers and a new game none of the old
|
|
2
|
+
// ones. st.marks holds id -> [position, label]; api.markers holds the hud markers on screen now.
|
|
3
|
+
import { refuseSave } from '../../core/saves/saveValues.js';
|
|
4
|
+
|
|
5
|
+
/** content._mark: set (v = position) or clear (v = null) marker id */
|
|
6
|
+
export function setMark(e, api, st, id, v, label) {
|
|
7
|
+
api.markers.get(id)?.remove(); api.markers.delete(id); st.marks.delete(id);
|
|
8
|
+
if (!v) return;
|
|
9
|
+
st.marks.set(id, [v, label ?? null]);
|
|
10
|
+
const m = e.hud?.marker(v, { label });
|
|
11
|
+
if (m) api.markers.set(id, m);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** The 'content' save part */
|
|
15
|
+
export function marksPart(api, st) {
|
|
16
|
+
return {
|
|
17
|
+
save: () => ({ marks: [...st.marks].map(([id, [v, label]]) => [id, v, label]) }),
|
|
18
|
+
load: d => {
|
|
19
|
+
const marks = d?.marks ?? [];
|
|
20
|
+
if (!Array.isArray(marks) || !marks.every(m => Array.isArray(m) && typeof m[0] === 'string')) refuseSave('content', 'marks', 'must be a list of [id, value, label]', marks);
|
|
21
|
+
for (const id of [...st.marks.keys()]) api._mark(id, null);
|
|
22
|
+
for (const [id, v, label] of marks) api._mark(id, v, label ?? undefined);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -1,39 +1,87 @@
|
|
|
1
|
-
// Models of placed content records: clone the shared prototype of a model name (core/namedModel.js protoOf, the one path every system uses),
|
|
1
|
+
// Models of placed content records: clone the shared prototype of a model name (core/assets/namedModel.js protoOf, the one path every system uses),
|
|
2
2
|
// align it and its collision to the record (props and template instances).
|
|
3
|
-
import { protoOf } from '../../core/namedModel.js';
|
|
4
|
-
import {
|
|
3
|
+
import { protoOf } from '../../core/assets/namedModel.js';
|
|
4
|
+
import { wrapLod } from '../../core/assets/assetLod.js';
|
|
5
|
+
import { Vector3 } from 'three';
|
|
6
|
+
import { list } from '../../core/base/util.js';
|
|
7
|
+
|
|
8
|
+
const BASE_BAND = 0.2; // the share of the model's height above the ground that counts as its base
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Where a model stands, in model space, measured once per prototype: { x, z } centre and width of the base (its larger side, so a plain box keeps the same radius).
|
|
12
|
+
* Why this measure: the base is the geometry in the lowest fifth of the height above y = 0 (above its lowest point when it floats), clipped from the triangles, because a crown or an arm starts higher, a tall box has no vertex halfway up and a boulder's belly is what walkers hit.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export function baseOf(proto) {
|
|
16
|
+
if (proto.base) return proto.base;
|
|
17
|
+
const meshes = [], p = new Vector3();
|
|
18
|
+
let bottom = Infinity, top = -Infinity, instanced = false;
|
|
19
|
+
proto.obj.updateMatrixWorld(true);
|
|
20
|
+
proto.obj.traverse(m => {
|
|
21
|
+
if (!m.isMesh || !m.geometry?.attributes.position) return;
|
|
22
|
+
instanced ||= !!(m.isInstancedMesh || m.isBatchedMesh);
|
|
23
|
+
const pos = m.geometry.attributes.position, at = new Float32Array(pos.count * 3);
|
|
24
|
+
for (let i = 0; i < pos.count; i++) {
|
|
25
|
+
p.fromBufferAttribute(pos, i).applyMatrix4(m.matrixWorld).toArray(at, i * 3);
|
|
26
|
+
bottom = Math.min(bottom, p.y); top = Math.max(top, p.y);
|
|
27
|
+
}
|
|
28
|
+
meshes.push({ at, index: m.geometry.index });
|
|
29
|
+
});
|
|
30
|
+
const low = top > 0 ? Math.max(bottom, 0) : bottom, high = low + (top - low) * BASE_BAND;
|
|
31
|
+
let x0 = Infinity, x1 = -Infinity, z0 = Infinity, z1 = -Infinity;
|
|
32
|
+
const take = (x, z) => { x0 = Math.min(x0, x); x1 = Math.max(x1, x); z0 = Math.min(z0, z); z1 = Math.max(z1, z); };
|
|
33
|
+
const edge = (at, a, b) => {
|
|
34
|
+
const ay = at[a + 1], by = at[b + 1];
|
|
35
|
+
if (ay >= low && ay <= high) take(at[a], at[a + 2]);
|
|
36
|
+
for (const y of [low, high]) if ((ay - y) * (by - y) < 0) { const t = (y - ay) / (by - ay); take(at[a] + (at[b] - at[a]) * t, at[a + 2] + (at[b + 2] - at[a + 2]) * t); }
|
|
37
|
+
};
|
|
38
|
+
for (const { at, index } of meshes) {
|
|
39
|
+
const n = index ? index.count : at.length / 3, v = i => (index ? index.getX(i) : i) * 3;
|
|
40
|
+
for (let i = 0; i + 2 < n; i += 3) { const a = v(i), b = v(i + 1), c = v(i + 2); edge(at, a, b); edge(at, b, c); edge(at, c, a); }
|
|
41
|
+
}
|
|
42
|
+
// shortcut: instanced parts and models without triangles (points, lines, sprites) use the bounding box; measure their instances if a prop ever needs it
|
|
43
|
+
const { size, center } = proto;
|
|
44
|
+
return proto.base = instanced || x0 > x1 ? { x: center.x, z: center.z, width: Math.max(size.x, size.z) }
|
|
45
|
+
: { x: (x0 + x1) / 2, z: (z0 + z1) / 2, width: Math.max(x1 - x0, z1 - z0) };
|
|
46
|
+
}
|
|
5
47
|
|
|
6
48
|
/**
|
|
7
49
|
* Align a built model and its collision to the record (once when built, again after the record moved or rot / scale changed).
|
|
8
|
-
*
|
|
50
|
+
* solid = { collide, static } comes from the prop record, or from the template definition for template instances.
|
|
51
|
+
* A circle stands on the model's base (baseOf); { circle: radius } gives the radius in model meters, so it follows the scale as the model does.
|
|
9
52
|
* mul: a template stage's scale, multiplied onto the record's own scale (the record keeps only its authored scale). @internal
|
|
10
53
|
*/
|
|
11
|
-
export function settle(e, rec, o,
|
|
54
|
+
export function settle(e, rec, o, solid, mul = 1) {
|
|
12
55
|
const { x, z } = rec.position, rot = rec.rot ?? 0, scale = (rec.scale ?? 1) * mul, ud = o.userData;
|
|
13
|
-
ud.fit =
|
|
56
|
+
ud.fit = { x, z, rot, scale };
|
|
14
57
|
rec.position.y = e.surface(x, z, rec.floor) + (rec.offsetY ?? 0);
|
|
15
58
|
o.position.y = rec.position.y; o.rotation.y = rot; o.scale.setScalar(scale);
|
|
16
59
|
ud.unstatic?.remove(); ud.unstatic = null;
|
|
17
60
|
for (const h of ud.colliders.splice(0)) h.remove();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
61
|
+
// a solid prop blocks the camera with its whole mesh, not only its footprint collider: crowns and eaves stand outside the footprint, and no game code should have to say so
|
|
62
|
+
const blocks = !!solid.collide && solid.collide.occluder !== false && solid.occluder !== false;
|
|
63
|
+
if (solid.static !== false && e.rays) { o.updateMatrixWorld(true); ud.unstatic = e.rays.addStatic(o, { occluder: blocks }); }
|
|
64
|
+
if (!solid.collide || !e.collision) return;
|
|
65
|
+
const { collide } = solid, set = typeof collide === 'object' ? collide : null, base = set || collide === 'circle' ? baseOf(ud.proto) : null;
|
|
66
|
+
const size = ud.proto.size.clone().multiplyScalar(scale), c = base ?? ud.proto.center, ox = c.x * scale, oz = c.z * scale;
|
|
67
|
+
const cx = x + ox * Math.cos(rot) + oz * Math.sin(rot), cz = z - ox * Math.sin(rot) + oz * Math.cos(rot);
|
|
68
|
+
ud.colliders.push(base
|
|
69
|
+
? e.collision.addCircle({ x: cx, z: cz }, { radius: (set?.circle ?? base.width / 2) * scale, height: size.y, occluder: blocks })
|
|
70
|
+
: e.collision.addBox({ x: cx, z: cz }, { halfWidth: size.x / 2, halfDepth: size.z / 2, rotation: rot, height: size.y, occluder: blocks }));
|
|
25
71
|
}
|
|
26
|
-
/**
|
|
27
|
-
export const
|
|
72
|
+
/** Is the model still as settle aligned it? update asks every frame for every built prop, because world.move sends no event: four compares, no text @internal */
|
|
73
|
+
export const fits = (o, rec, mul = 1) => { const f = o.userData.fit, p = rec.position; return f.x === p.x && f.z === p.z && f.rot === (rec.rot ?? 0) && f.scale === (rec.scale ?? 1) * mul; };
|
|
28
74
|
|
|
29
75
|
/** Clone the shared prototype of a model for one record and align it (props and template instances) @internal */
|
|
30
|
-
export async function buildModel(e, api, rec, model,
|
|
31
|
-
const proto = await protoOf(e, api, model),
|
|
76
|
+
export async function buildModel(e, api, rec, model, solid, mul = 1) {
|
|
77
|
+
const proto = await protoOf(e, api, model), name = list(model)[0], lod = rec.lod ?? solid.lod;
|
|
78
|
+
// settle below measures proto, never o, so collision stays the full model's; the record keeps only the word `lod`, so a save holds no level
|
|
79
|
+
const o = lod ? await wrapLod(e.assets, name, proto.obj.clone(), { distances: Array.isArray(lod) ? lod : undefined, scale: (rec.scale ?? 1) * mul }) : proto.obj.clone();
|
|
32
80
|
o.name ||= name; o.userData.name ??= name;
|
|
33
81
|
o.userData.proto = proto; o.userData.colliders = [];
|
|
34
82
|
if (rec.batch === false) o.userData.batch = false; // opt out of engine.batching for this record
|
|
35
83
|
o.position.set(rec.position.x, 0, rec.position.z); // world puts the model on the record after build; height and collision are aligned here
|
|
36
|
-
settle(e, rec, o,
|
|
84
|
+
settle(e, rec, o, solid, mul);
|
|
37
85
|
return o;
|
|
38
86
|
}
|
|
39
87
|
/** Tear down only: geometry and material belong to the shared prototype, the next build clones it again @internal */
|
package/modules/content/packs.js
CHANGED
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
// - a pack may carry name: 'forest-dlc' for error messages; no other extra key (unknown keys are errors)
|
|
11
11
|
// Content references assets by name only: a model written as a file path or a function is reported here in dev (the static check is
|
|
12
12
|
// npm run check -> content-check, packages/tools/content-check/world.mjs).
|
|
13
|
-
import { DEV, warnOnce, fmt } from '../../core/validate.js';
|
|
14
|
-
import { codedError } from '../../core/errorHints.js';
|
|
15
|
-
import { isPlainObject } from '../../core/util.js';
|
|
13
|
+
import { DEV, warnOnce, fmt } from '../../core/base/validate.js';
|
|
14
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
15
|
+
import { isPlainObject } from '../../core/base/util.js';
|
|
16
16
|
|
|
17
17
|
const STRINGS = {
|
|
18
18
|
dup: 'content.load: {key}.{id} is defined by both {a} and {b}. Packs loaded together may not share an id: rename one, or drop it from one pack',
|
package/modules/content/parts.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
// gets its position in the joined array as id, and content check, write-back and the game must agree on it), and the dev line table must keep
|
|
5
5
|
// naming the right file ("defined in content/props/town.js:14").
|
|
6
6
|
// content/index.js: const props = contentParts(import.meta.glob('./props/*.js', { eager: true }));
|
|
7
|
-
import { DEV } from '../../core/validate.js';
|
|
8
|
-
import { codedError } from '../../core/errorHints.js';
|
|
7
|
+
import { DEV } from '../../core/base/validate.js';
|
|
8
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Join the modules of one content folder into one array / object (what a single content/<kind>.js would export).
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Places in content: named positions (a pack's places file, the places option, level markers) and the position notation { place?, x?, z?, floor?, y? }.
|
|
2
|
+
// api is engine.content: where and offset read a place through api.place, so a wrapped place is the one they use.
|
|
3
|
+
import { placeY } from '../../core/scene/ground.js';
|
|
4
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
5
|
+
|
|
6
|
+
/** content.load: add the packs' places, then the places option on top. A text entry in a place file waits for the option */
|
|
7
|
+
export function addPlaces(places, packs, given) {
|
|
8
|
+
const pl = {};
|
|
9
|
+
for (const p of packs) for (const [name, at] of Object.entries(p.places ?? {})) if (at && typeof at === 'object') pl[name] = at;
|
|
10
|
+
Object.assign(pl, given);
|
|
11
|
+
for (const [name, p] of Object.entries(pl)) if (p?.rot !== undefined && !Number.isFinite(p.rot)) throw codedError('content-place', `Place "${name}": rot must be a number of radians about Y, got ${JSON.stringify(p.rot)}`);
|
|
12
|
+
Object.assign(places, pl);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** content.place */
|
|
16
|
+
export function placeOf(e, places, name) {
|
|
17
|
+
const p = places[name] ?? e.level?.marker(name)?.position;
|
|
18
|
+
return p ? { x: p.x, z: p.z, ...(p.y !== undefined && { y: p.y }), ...(p.rot !== undefined && { rot: p.rot }) } : null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** content.offset */
|
|
22
|
+
export function offsetFrom(api, place, x, z) {
|
|
23
|
+
const base = place ? api.place(place) : null, dx = x - (base?.x ?? 0), dz = z - (base?.z ?? 0), c = Math.cos(base?.rot ?? 0), s = Math.sin(base?.rot ?? 0);
|
|
24
|
+
return { x: dx * c - dz * s, z: dx * s + dz * c };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** content.where */
|
|
28
|
+
export function whereOf(e, api, p) {
|
|
29
|
+
const base = p.place ? api.place(p.place) : null;
|
|
30
|
+
if (p.place && !base) throw codedError('content-place', `Place "${p.place}" not found: give its coordinates in the places of content.load, or add this marker to the level`);
|
|
31
|
+
const ox = p.x ?? 0, oz = p.z ?? 0, c = Math.cos(base?.rot ?? 0), s = Math.sin(base?.rot ?? 0);
|
|
32
|
+
const x = (base?.x ?? 0) + ox * c + oz * s, z = (base?.z ?? 0) - ox * s + oz * c, floor = p.floor ?? base?.y;
|
|
33
|
+
if (floor === undefined && p.y === undefined) return { x, z };
|
|
34
|
+
return { x, y: placeY(e, `content.where(${JSON.stringify(p.place ?? { x: p.x, z: p.z })})`, x, z, floor) + (p.y ?? 0), z };
|
|
35
|
+
}
|
package/modules/content/props.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Props (each item of content/props.js): data is a plain record in engine.world with kind 'prop'; model and collision are "presentation that exists only when
|
|
2
2
|
// near".
|
|
3
|
-
// record: { id, kind: 'prop', position: {x,y,z}, model, rot?, scale?, collide?, offsetY?, static?, batch?, zone? } (plain values only)
|
|
3
|
+
// record: { id, kind: 'prop', position: {x,y,z}, model, rot?, scale?, collide?, occluder?, offsetY?, static?, batch?, source?, zone? } (plain values only)
|
|
4
|
+
// rot = the entry's rot plus its place's. source names the arrangement an entry was copied from: a tag for world.query, nothing at runtime reads it.
|
|
4
5
|
// Initial world data (initial: true on add): the save records only moves / removals, independent of content.load running before or after loading a save;
|
|
5
6
|
// positions using level markers carry a zone (data is kept across level changes).
|
|
6
7
|
// id: the written id if content gives one; otherwise `prop:<model name>:<index in this props array>` (same on every load of the same content, no collisions).
|
|
@@ -12,14 +13,14 @@
|
|
|
12
13
|
// collision: built / torn down with the model (only things near the player need to block), so props beyond the collision radius take no space in the collision
|
|
13
14
|
// table.
|
|
14
15
|
// An entry with template (instead of model) is an instance of a content template: see templates.js.
|
|
15
|
-
import { buildModel, settle,
|
|
16
|
+
import { buildModel, settle, fits, unbuildModel } from './models.js';
|
|
16
17
|
import { placeTemplate } from './templates.js';
|
|
17
18
|
import { srcOf } from './ids.js';
|
|
18
|
-
import { placeY } from '../../core/ground.js';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
|
|
19
|
+
import { placeY } from '../../core/scene/ground.js';
|
|
20
|
+
import { PLACEMENT_FIELDS, collideProblem } from './rules.js';
|
|
21
|
+
import { list } from '../../core/base/util.js';
|
|
22
|
+
import { DEV, fmt, closest } from '../../core/base/validate.js';
|
|
23
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
23
24
|
|
|
24
25
|
/** Stable id of a prop: the written id if given, otherwise "model name + array index" */
|
|
25
26
|
const propId = (p, i) => p.id ?? `prop:${list(p.model)[0]}:${i}`;
|
|
@@ -35,16 +36,20 @@ export function addProps(e, api, props, st, zoneOf, ids) {
|
|
|
35
36
|
const at = DEV ? srcOf(props, i) : null;
|
|
36
37
|
if (p.template) return placeTemplate(e, api, st, p, i, zoneOf(p), ids, at); // an instance of a content template (templates.js), not a plain prop
|
|
37
38
|
if (p.grid) return placeGridItem(e, p, i, zoneOf(p), ids, at); // a pre-placed grid item (grid module)
|
|
39
|
+
const collide = collideProblem(p.collide);
|
|
40
|
+
if (collide) throw codedError('content-misuse', `props[${i}] (model ${JSON.stringify(p.model)}): collide ${collide}`);
|
|
38
41
|
const id = propId(p, i), { x, y, z } = api.where(p), zone = zoneOf(p), floor = api._floorOf(p);
|
|
39
42
|
if (p.id != null) ids.claim(p.id, `props[${i}] (model ${JSON.stringify(p.model)})`);
|
|
40
43
|
// compute y from the ground now (same as when the model is built): unmoved props equal the content and stay out of the save
|
|
41
44
|
const def = { id, kind: 'prop', position: { x, y: y ?? placeY(e, `props[${i}] (model ${JSON.stringify(p.model)})`, x, z), z }, model: p.model };
|
|
42
|
-
for (const k of ['
|
|
45
|
+
for (const k of ['scale', 'collide', 'occluder', 'static', 'batch', 'lod', 'source']) if (p[k] !== undefined) def[k] = p[k];
|
|
46
|
+
const rot = api._facingOf(p);
|
|
47
|
+
if (rot !== undefined) def.rot = rot;
|
|
43
48
|
if (p.y) def.offsetY = p.y;
|
|
44
49
|
if (floor !== undefined) def.floor = floor; // kept so a moved prop lands on the same storey
|
|
45
50
|
if (zone != null) def.zone = zone;
|
|
46
51
|
const rec = world.add(def, { initial: true });
|
|
47
|
-
if (rec && (rec.kind !== 'prop' || JSON.stringify(rec.model) !== JSON.stringify(p.model))) throw codedError('
|
|
52
|
+
if (rec && (rec.kind !== 'prop' || JSON.stringify(rec.model) !== JSON.stringify(p.model))) throw codedError('world-id', `Prop id "${id}" is already used by other data (${rec.kind}${rec.model ? ' ' + JSON.stringify(rec.model) : ''}): give this item a different id, e.g. { id: '${id}-2', model: ... }`);
|
|
48
53
|
if (DEV) world.setOrigin(id, { definedAt: at, model: p.model });
|
|
49
54
|
});
|
|
50
55
|
}
|
|
@@ -71,13 +76,13 @@ function placeGridItem(e, p, i, zone, ids, at) {
|
|
|
71
76
|
ids.claim(p.id, `props[${i}] (grid ${p.grid} item ${p.item})`);
|
|
72
77
|
const { kind, fields } = e.grids.placement(p.grid, p.item, p.cell, p.rotation ?? 0);
|
|
73
78
|
const rec = e.world.add({ id: p.id, kind, ...fields, ...structuredClone(p.fields ?? {}), ...(zone != null && { zone }) }, { initial: true });
|
|
74
|
-
if (rec && rec.kind !== kind) throw codedError('
|
|
79
|
+
if (rec && rec.kind !== kind) throw codedError('world-id', `grid item id "${p.id}" is already used by other data (kind ${rec.kind}): give it a different id`);
|
|
75
80
|
if (DEV) e.world.setOrigin(p.id, { definedAt: at });
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
/** Dev error when the world module is not installed */
|
|
79
84
|
export function needWorld(e) {
|
|
80
|
-
if (!e.world) throw codedError('
|
|
85
|
+
if (!e.world) throw codedError('module-needs', 'content has props or pickups, whose data is stored in world: call engine.use(world()) first (the openWorld() preset already installs it)');
|
|
81
86
|
return e.world;
|
|
82
87
|
}
|
|
83
88
|
|
|
@@ -85,12 +90,12 @@ export function needWorld(e) {
|
|
|
85
90
|
function presentProps(e, api, world, st) {
|
|
86
91
|
if (st.propsPresenter) return;
|
|
87
92
|
|
|
88
|
-
st.propsPresenter = world.present('prop', {
|
|
93
|
+
st.propsPresenter = st.track(world.present('prop', {
|
|
89
94
|
// build by view distance: follows the terrain view distance (fog distance if no terrain), also when changed at runtime
|
|
90
95
|
radius: () => Math.max(world.radius, e.stream.activeRadius),
|
|
91
96
|
build: rec => buildModel(e, api, rec, rec.model, rec), // a failed model generation is reported by world (does not block loading), retried when near again
|
|
92
97
|
// moved / rot or scale changed (world.move sends no event, so compare here): world already put the model at the new position; collision and rays follow
|
|
93
|
-
update(rec, o) { if (o
|
|
98
|
+
update(rec, o) { if (!fits(o, rec)) settle(e, rec, o, rec); },
|
|
94
99
|
dispose: (rec, o) => unbuildModel(e, o),
|
|
95
|
-
});
|
|
100
|
+
}));
|
|
96
101
|
}
|
package/modules/content/rules.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Content vocabulary: the "conditions" and "effects" that content files (content/*.js) can use. Shared by the loader, the validator packages/tools/content-check.mjs and the map packages/tools/gamemap.mjs.
|
|
2
|
-
// Plain data + small functions, no import of three
|
|
2
|
+
// Plain data + small functions, no import of three and nothing from the engine but node-safe core/base/util.js (the validator reads it directly in node). Real execution is in loader.js.
|
|
3
3
|
//
|
|
4
4
|
// Conditions (quest step done, dialogue option if, line variant if): several items in one object must all hold; array = every item holds
|
|
5
5
|
// { flag: 'metFisher' } { notFlag: 'x' } { has: { berry: 3 } } { lacks: { film: 6 } } { counter: { sunsetPhotos: 1 } }
|
|
@@ -19,14 +19,16 @@
|
|
|
19
19
|
//
|
|
20
20
|
// Game content kinds: the same content/rules.js may export kinds: { name: { desc, load, check, map } }, so a game keeps its own data
|
|
21
21
|
// (enemies, recipes, loot tables, waves, shop stock) in content/<name>.js. The loader, content-check and GAMEMAP all read this one table:
|
|
22
|
-
// desc one line (map, file list) · load(e, data, content) hands the data to the game when engine.content.load runs (
|
|
22
|
+
// desc one line (map, file list) · load(e, data, content) hands the data to the game when engine.content.load runs (optional: a game that imports the file itself needs none)
|
|
23
23
|
// check(data, ctx) optional validation in npm run check: ctx.err(msg) / ctx.warn(msg); ctx.data is all content (items, npcs…), ctx.known(obj) lists ids
|
|
24
24
|
// map(data) optional GAMEMAP lines (default: the number of entries and their ids)
|
|
25
|
-
// fields optional { key: 'int?' | { type, min, max, values, desc } } (core/params.js format, no default): the keys of each entry; content-check
|
|
25
|
+
// fields optional { key: 'int?' | { type, min, max, values, desc } } (core/base/params.js format, no default): the keys of each entry; content-check
|
|
26
26
|
// reports unknown keys (did you mean), wrong types, out of range, and missing required keys; engine.content.fields(name) returns it
|
|
27
27
|
// export default { kinds: { recipes: { desc: 'crafting recipes (id -> { needs: { item: n }, makes })', load: (e, data) => e.crafting.add(data),
|
|
28
28
|
// check: (data, ctx) => { for (const [id, r] of Object.entries(data)) if (!ctx.data.items?.[r.makes]) ctx.err(`recipe ${id} makes unknown item ${r.makes}`); } } } };
|
|
29
29
|
|
|
30
|
+
import { list, isObject } from '../../core/base/util.js';
|
|
31
|
+
|
|
30
32
|
const counts = o => Object.entries(o || {}).map(([k, n]) => `${k}×${n}`).join('、');
|
|
31
33
|
const opText = v => Array.isArray(v) ? `${v[0]}${v[1] ? ' ' + Object.entries(v[1]).map(([k, x]) => `${k}=${x}`).join(' ') : ''}` : String(v);
|
|
32
34
|
const posText = v => typeof v === 'string' ? v : v.place ? `${v.place}${v.x || v.z ? `(${v.x ?? 0},${v.z ?? 0})` : ''}` : `(${v.x},${v.z})`;
|
|
@@ -49,7 +51,8 @@ const RULE_STRINGS = {
|
|
|
49
51
|
toast: { ref: 'text', desc: 'show a toast', describe: v => `toast "${v}"` },
|
|
50
52
|
particles: { ref: 'particles', desc: 'play particles', describe: v => `particles ${v.name}×${v.count ?? ''}` },
|
|
51
53
|
marker: { ref: 'position', desc: 'add an objective marker (hud module)', describe: v => `marker ${posText(v)}${v.label ? `"${v.label}"` : ''}` },
|
|
52
|
-
|
|
54
|
+
// raw: the value names the marker (content-check still reads it as a place); a place that is gone, on a level left behind, must not stop the clearing
|
|
55
|
+
clearMarker: { ref: 'position', raw: true, desc: 'remove an objective marker', describe: v => `remove marker ${posText(v)}` },
|
|
53
56
|
op: { ref: 'op', desc: "run a game op (engine.ops.run); the game's own actions are ops", describe: v => `op ${opText(v)}` },
|
|
54
57
|
},
|
|
55
58
|
// content file name -> description (only these files are recognized in content/)
|
|
@@ -57,13 +60,13 @@ const RULE_STRINGS = {
|
|
|
57
60
|
items: 'items (id -> name, icon, description); also export startItems for starting items',
|
|
58
61
|
pickups: 'pickups on the ground (list)',
|
|
59
62
|
containers: 'chests / shelves (container id -> { capacity, items: starting goods }; starting goods are placed only the first time, then saved)',
|
|
60
|
-
npcs: 'NPCs (id -> name, schedule,
|
|
63
|
+
npcs: 'NPCs (id -> name, schedule, interact)',
|
|
61
64
|
dialogues: 'dialogues (id -> speaker, nodes)',
|
|
62
65
|
quests: 'quests (id -> title, steps, reward; a step can have a target position)',
|
|
63
66
|
actions: 'own key actions of the game (action name -> default key, label)',
|
|
64
|
-
places: 'place names (coordinates computed at runtime in main.js)',
|
|
67
|
+
places: 'place names (name -> { x, z, y?, rot? }; rot turns everything placed there about Y; coordinates may be computed at runtime in main.js)',
|
|
65
68
|
triggers: 'trigger zones (tag -> position / from level, enter/exit effects)',
|
|
66
|
-
level: 'level markers (spawn point, NPCs, trigger zones)',
|
|
69
|
+
level: 'level markers (spawn point, NPCs, trigger zones) of a code-built level: for the tools (content checks, GAMEMAP); load() accepts the file and does not read it',
|
|
67
70
|
vegetation: 'vegetation (name -> model, growth rule)',
|
|
68
71
|
props: 'props (list: model, position, facing, collision; or { template, x, z } = an instance of a template; or { id, grid, item, cell } = a grid item), streamed in on demand',
|
|
69
72
|
templates: 'reusable objects (name -> model, collide, interact, container, sound, animate, state defaults, physics body); shared read-only definitions',
|
|
@@ -71,36 +74,40 @@ const RULE_STRINGS = {
|
|
|
71
74
|
views: 'named fixed camera views (name -> { position: [x, y, z], target?: [x, y, z], fov? }); engine.views.show(name), ?view=name, npm run shot -- -w game --view name',
|
|
72
75
|
grids: 'placement grids (name -> { cell, origin, size, zone?, flat? }); layout rules, not saved',
|
|
73
76
|
renames: "renamed or deleted authored ids (old id -> new id, or null = deleted on purpose): the player's saved changes follow the new id",
|
|
74
|
-
rules: 'condition words added by the game ({ conditions }); actions are ops, not effect words',
|
|
77
|
+
rules: 'condition words and data kinds added by the game ({ conditions, kinds }); actions are ops, not effect words',
|
|
75
78
|
},
|
|
76
|
-
// Placement fields: the keys one entry of a content file may have, in the core/params.js spec format. Declared once here, read by the loader
|
|
79
|
+
// Placement fields: the keys one entry of a content file may have, in the core/base/params.js spec format. Declared once here, read by the loader
|
|
77
80
|
// (unknown keys), content-check (unknown keys with did-you-mean, wrong type, out of range, not in values) and engine.content.fields() (an editor
|
|
78
81
|
// panel's rows), so the three cannot drift apart. props has three entry shapes: a plain model ('props'), a template instance ('props.template',
|
|
79
82
|
// plus the template's state fields) and a grid item ('props.grid'). Required-ness of x / z / model is checked by the content rules themselves
|
|
80
83
|
// (x, z are optional when place is given), so they are marked optional here.
|
|
81
84
|
fields: (() => {
|
|
82
85
|
const at = {
|
|
83
|
-
place: { type: 'string', optional: true, desc:
|
|
86
|
+
place: { type: 'string', optional: true, desc: "place name (places.js / level marker); x and z are then offsets from it and turn with the place's rot" },
|
|
84
87
|
x: { type: 'number', optional: true, desc: 'meters along x (offset from place when place is given)' },
|
|
85
88
|
z: { type: 'number', optional: true, desc: 'meters along z (offset from place when place is given)' },
|
|
86
89
|
floor: { type: 'number', optional: true, desc: 'reference height of the storey it stands on (multi-layer ground)' },
|
|
87
90
|
y: { type: 'number', optional: true, desc: 'meters above the ground it stands on' },
|
|
88
91
|
};
|
|
89
|
-
const
|
|
92
|
+
const pose = {
|
|
90
93
|
rot: { type: 'number', optional: true, desc: 'facing around the vertical axis, radians' },
|
|
91
94
|
scale: { type: 'number', optional: true, min: 0, desc: 'uniform scale (1 = model size)' },
|
|
92
95
|
};
|
|
96
|
+
// a plain tag, so world.query({ where: r => r.source === 'stall' }) finds every copy of one arrangement; nothing else reads it
|
|
97
|
+
const copied = { source: { type: 'string', optional: true, desc: 'name of the arrangement this entry was copied from; queryable, no other effect' } };
|
|
93
98
|
return {
|
|
94
99
|
props: {
|
|
95
100
|
id: { type: 'string', optional: true, desc: 'stable id (needed when entries are later inserted in the middle)' },
|
|
96
|
-
model: { type: 'any', desc: "model name, or [name, ...args] for a generated model" }, ...at, ...
|
|
97
|
-
collide: { type: 'any', optional: true,
|
|
101
|
+
model: { type: 'any', desc: "model name, or [name, ...args] for a generated model" }, ...at, ...pose, ...copied,
|
|
102
|
+
collide: { type: 'any', optional: true, desc: "collision: 'box', 'circle', { circle: radius, occluder?: false }, or false = none" },
|
|
103
|
+
occluder: { type: 'bool', optional: true, desc: 'false = a solid prop the follow camera may pass through (walkers are still stopped)' },
|
|
98
104
|
static: { type: 'bool', optional: true, desc: 'never moves (may be merged into one draw call)' },
|
|
99
105
|
batch: { type: 'bool', optional: true, desc: 'false = never batch this copy' },
|
|
106
|
+
lod: { type: 'any', optional: true, desc: 'true = lower-detail levels far away (threedog assets optimize --lod), or rising distances in meters like [40, 120]; such a copy is never batched' },
|
|
100
107
|
},
|
|
101
108
|
'props.template': {
|
|
102
109
|
template: { type: 'string', desc: 'template name (content/templates.js)' },
|
|
103
|
-
id: { type: 'string', optional: true, desc: 'stable id; instances with state should have one' }, ...at, ...
|
|
110
|
+
id: { type: 'string', optional: true, desc: 'stable id; instances with state should have one' }, ...at, ...pose, ...copied,
|
|
104
111
|
items: { type: 'object', optional: true, desc: "starting goods of the instance's container { itemId: count }" },
|
|
105
112
|
},
|
|
106
113
|
'props.grid': {
|
|
@@ -145,8 +152,15 @@ export const EFFECTS = RULE_STRINGS.effects;
|
|
|
145
152
|
export const REFS = RULE_STRINGS.refs;
|
|
146
153
|
/** content file name -> description */
|
|
147
154
|
export const CONTENT_FILES = RULE_STRINGS.files;
|
|
148
|
-
/** content entry shape -> { key: field spec } (core/params.js format): 'props', 'props.template', 'props.grid', 'pickups', 'views'. Read via fields.js */
|
|
155
|
+
/** content entry shape -> { key: field spec } (core/base/params.js format): 'props', 'props.template', 'props.grid', 'pickups', 'views'. Read via fields.js */
|
|
149
156
|
export const PLACEMENT_FIELDS = RULE_STRINGS.fields;
|
|
157
|
+
/** Why a prop's or template's `collide` is wrong, or null. One rule for the load and content-check: a mistyped object must not quietly become a box */
|
|
158
|
+
export function collideProblem(v) {
|
|
159
|
+
if (v === undefined || v === false || v === 'box' || v === 'circle') return null;
|
|
160
|
+
const form = isObject(v) && Object.keys(v).every(k => k === 'circle' || k === 'occluder');
|
|
161
|
+
if (form && Number.isFinite(v.circle) && v.circle > 0 && (v.occluder === undefined || typeof v.occluder === 'boolean')) return null;
|
|
162
|
+
return `must be one of false, "box", "circle" or { circle: radius in meters above 0, occluder?: false }, got ${JSON.stringify(v)}`;
|
|
163
|
+
}
|
|
150
164
|
/** Clock time notation 'HH:MM' (24-hour) */
|
|
151
165
|
export const CLOCK_RE = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
152
166
|
|
|
@@ -160,22 +174,20 @@ export function contentFiles(game = {}) {
|
|
|
160
174
|
for (const [name, k] of Object.entries(game?.kinds || {})) out[name] ??= k?.desc || 'game data kind';
|
|
161
175
|
return out;
|
|
162
176
|
}
|
|
163
|
-
/** Problems with a game's kinds table (name clashes with an engine file, no
|
|
177
|
+
/** Problems with a game's kinds table (name clashes with an engine file, a load that is no function): a list of messages */
|
|
164
178
|
export function kindProblems(game = {}) {
|
|
165
179
|
return Object.entries(game?.kinds || {}).flatMap(([name, k]) => [
|
|
166
180
|
...(CONTENT_FILES[name] || name === 'startItems' ? [`kind "${name}" is an engine content file name: pick another name (engine files: ${Object.keys(CONTENT_FILES).join(', ')})`] : []),
|
|
167
|
-
...(typeof k
|
|
181
|
+
...(k?.load !== undefined && typeof k.load !== 'function' ? [`kind "${name}": load must be a function (e, data) => …, or left out when the game imports the file itself`] : []),
|
|
168
182
|
]);
|
|
169
183
|
}
|
|
170
184
|
/** Error text for a content name that is neither an engine file nor a registered kind */
|
|
171
185
|
export const unknownContent = (name, game) => `unknown content "${name}". Known: ${Object.keys(contentFiles(game)).join(', ')}. `
|
|
172
|
-
+ `For the game's own data, register it in content/rules.js: export default { kinds: { ${name}: { desc: '…', load: (e, data) => { … } } } }`;
|
|
173
|
-
/** Error text
|
|
174
|
-
export const NO_GAME_EFFECTS = "content/rules.js:
|
|
186
|
+
+ `For the game's own data, register it in content/rules.js: export default { kinds: { ${name}: { desc: '…', load: (e, data) => { … } } } }, and list \`rules\` in content/index.js too: the loader only knows what it is handed`;
|
|
187
|
+
/** Error text for an effects key in a game's content/rules.js */
|
|
188
|
+
export const NO_GAME_EFFECTS = "content/rules.js: effects is not a key here. Register the action as an op (engine.ops.define('noun.verb', { can, run }) in main.js) "
|
|
175
189
|
+ "and call it from content with { op: ['noun.verb', { args }] }; see recipes/23-ops.md";
|
|
176
190
|
|
|
177
|
-
/** Wrap a single value into an array (a model written as 'tree' or ['tree', ...args]); the one copy for the content files @param {any} v @returns {any[]} */
|
|
178
|
-
export const list = v => (Array.isArray(v) ? v : [v]);
|
|
179
191
|
const say = (vocab, x) => Object.entries(x).map(([k, v]) => vocab[k]?.describe?.(v) ?? `${k} ${JSON.stringify(v)}`);
|
|
180
192
|
|
|
181
193
|
/** Describe a condition as one human-readable sentence (for the map); vocab defaults to the engine vocabulary */
|
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
// canGrow: (rec, e) => rec.watered }
|
|
6
6
|
// Why the stage lives on the record and not on a separate registry: the record is what world saves, what content-check / content.fields() describe
|
|
7
7
|
// and what the editor edits, so `stage` is an ordinary state field (default 0, range 0..n-1) and `stageAt` (engine.clock.now when it entered the stage)
|
|
8
|
-
// sits beside it. Growth is counted in
|
|
8
|
+
// sits beside it. Growth is counted in calendar seconds (clock.now), so a far record, a loaded save or a time skip all catch up in one pass.
|
|
9
9
|
// Node-safe (no three): content-check imports this file directly, so the engine and the check accept the same stages.
|
|
10
|
-
import { closest } from '../../core/validate.js';
|
|
10
|
+
import { closest } from '../../core/base/validate.js';
|
|
11
|
+
import { isModelName } from '../../core/base/util.js';
|
|
11
12
|
|
|
12
13
|
const STAGE_KEYS = ['name', 'duration', 'scale', 'model'];
|
|
13
|
-
const isModel = m => typeof m === 'string' || (Array.isArray(m) && typeof m[0] === 'string');
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* Problems of a template's stages list (empty list = fine). Every stage but the last needs a duration (
|
|
16
|
+
* Problems of a template's stages list (empty list = fine). Every stage but the last needs a duration (calendar seconds spent there); the last may omit it
|
|
17
17
|
* (stays there). model is a model name like the template's own model (no functions: stages are data an editor can show and content-check can read).
|
|
18
18
|
* @param {string} where e.g. "template 'crop'"
|
|
19
19
|
* @param {any} stages
|
|
@@ -37,12 +37,12 @@ export function stagesProblems(where, stages) {
|
|
|
37
37
|
else if (names.has(s.name)) out.push(`${at}: name '${s.name}' is used by an earlier stage; stage names must differ`);
|
|
38
38
|
else names.add(s.name);
|
|
39
39
|
const last = i === stages.length - 1;
|
|
40
|
-
if (s.duration === undefined) { if (!last) out.push(`${at} needs duration (
|
|
41
|
-
else if (!Number.isFinite(s.duration) || s.duration <= 0) out.push(`${at}: duration must be a positive number of
|
|
40
|
+
if (s.duration === undefined) { if (!last) out.push(`${at} needs duration (calendar seconds spent in this stage); only the last stage may leave it out`); }
|
|
41
|
+
else if (!Number.isFinite(s.duration) || s.duration <= 0) out.push(`${at}: duration must be a positive number of calendar seconds, got ${JSON.stringify(s.duration)}`);
|
|
42
42
|
if (s.scale !== undefined && (!Number.isFinite(s.scale) || s.scale <= 0)) {
|
|
43
43
|
out.push(`${at}: scale must be a positive number (multiplies the instance scale), got ${JSON.stringify(s.scale)}`);
|
|
44
44
|
}
|
|
45
|
-
if (s.model !== undefined && !
|
|
45
|
+
if (s.model !== undefined && !isModelName(s.model)) out.push(`${at}: model must be a model name (like the template's model), got ${JSON.stringify(s.model)}`);
|
|
46
46
|
});
|
|
47
47
|
return out;
|
|
48
48
|
}
|