threedog 0.7.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -12
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -19
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/{core → render}/shadows.js +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Grid.d.ts +1 -0
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +5 -4
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
|
@@ -4,17 +4,18 @@
|
|
|
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 { parseClock } from '../../core/dayTime.js';
|
|
8
|
-
import { vegetationModel } from '../../core/namedModel.js';
|
|
9
|
-
import { addProps, needWorld } from './props.js';
|
|
10
|
-
import { defineTemplates } from './templates.js';
|
|
11
7
|
import { srcOf, applyRenames, pickupId } from './ids.js';
|
|
12
|
-
import { DEV, warnOnce } from '../../core/validate.js';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
8
|
+
import { DEV, warnOnce } from '../../core/base/validate.js';
|
|
9
|
+
import { NO_GAME_EFFECTS, contentFiles, kindProblems, unknownContent } from './rules.js';
|
|
10
|
+
import { sectionHomes } from '../../core/inspect/metadata.generated.js';
|
|
11
|
+
import { sectionsOf, runSections, keepTable } from '../../core/base/sections.js';
|
|
12
|
+
import { whenTurnFree, whileRestoring, liveTurn } from '../../core/saves/stateReplace.js';
|
|
13
|
+
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
14
|
+
import { failure } from '../../core/ops/opsFail.js';
|
|
15
|
+
|
|
16
|
+
// data order, not ownership: a place or template must exist before what stands on it. A section not listed runs after these. Rules, actions, audio, views and renames run before all of them (loadSteps)
|
|
17
|
+
const ORDER = ['level', 'vegetation', 'items', 'startItems', 'containers', 'pickups', 'npcs', 'dialogues', 'quests', 'triggers', 'grids', 'templates', 'props'];
|
|
18
|
+
const isEmpty = d => d == null || (typeof d === 'object' && Object.keys(d).length === 0);
|
|
18
19
|
const each = (o, fn) => Object.entries(o || {}).forEach(([k, v]) => fn(k, v));
|
|
19
20
|
const all = (o, fn) => Object.entries(o || {}).every(([k, n]) => fn(k, n));
|
|
20
21
|
|
|
@@ -25,9 +26,9 @@ const all = (o, fn) => Object.entries(o || {}).every(([k, n]) => fn(k, n));
|
|
|
25
26
|
const inv = (e, word, ctx) => e.inventory?.of(ctx?.actor ?? e.ops.actor) ?? (() => { throw codedError('content-misuse', `content word { ${word} } needs the inventory module: add inventory() to engine.use(...), `
|
|
26
27
|
+ 'or track the thing with a flag / counter ({ setFlag } / { bump }) or a game condition word instead'); })();
|
|
27
28
|
|
|
28
|
-
/** Execution part of the engine's built-in words (descriptions are in rules.js) */
|
|
29
|
+
/** Execution part of the engine's built-in words (descriptions are in rules.js). A run answers by returning a failure ({ ok: false, code, facts }); runWords hands it up */
|
|
29
30
|
export const BUILTIN_TESTS = {
|
|
30
|
-
can: (e, v) => e.ops.can(v[0], v[1] ?? {}).ok,
|
|
31
|
+
can: (e, v, raw, ctx) => e.ops.can(v[0], v[1] ?? {}, { actor: ctx?.actor }).ok,
|
|
31
32
|
flag: (e, v) => !!e.vars.flag(v),
|
|
32
33
|
notFlag: (e, v) => !e.vars.flag(v),
|
|
33
34
|
has: (e, v, raw, ctx) => all(v, (id, n) => inv(e, 'has', ctx).has(id, n)),
|
|
@@ -35,11 +36,19 @@ export const BUILTIN_TESTS = {
|
|
|
35
36
|
counter: (e, v) => all(v, (k, n) => e.vars.counter(k) >= n),
|
|
36
37
|
};
|
|
37
38
|
export const BUILTIN_RUNS = {
|
|
38
|
-
op: (e, v) =>
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
op: (e, v, raw, ctx) => e.ops.run(v[0], v[1] ?? {}, { actor: ctx?.actor }),
|
|
40
|
+
setFlag: (e, v) => e.vars.setFlag(v),
|
|
41
|
+
// add keeps what fits and calls that ok, so the rest is this word's to report; facts.left is exactly what { give } could still pay later
|
|
42
|
+
give(e, v, raw, ctx) {
|
|
43
|
+
const left = {};
|
|
44
|
+
each(v, (id, n) => { const r = inv(e, 'give', ctx).add(id, n), got = r.ok ? r.added : 0; if (got < n) left[id] = n - got; });
|
|
45
|
+
return Object.keys(left).length ? failure({ code: 'full', facts: { left } }) : undefined;
|
|
46
|
+
},
|
|
47
|
+
take(e, v, raw, ctx) {
|
|
48
|
+
const short = Object.entries(v).filter(([id, n]) => !inv(e, 'take', ctx).remove(id, n)).map(([id]) => id);
|
|
49
|
+
return short.length ? failure({ code: 'notEnough', facts: { short } }) : undefined;
|
|
50
|
+
},
|
|
41
51
|
bump: (e, v) => e.vars.bump(v),
|
|
42
|
-
startQuest: (e, v) => e.quests.start(v),
|
|
43
52
|
toast: (e, v) => toast(e, v),
|
|
44
53
|
particles: (e, v) => e.particles.emit(v.name, v.at, { count: v.count }),
|
|
45
54
|
marker: (e, v, raw) => e.content._mark(markerId(raw), v, raw.label), // the same marker again replaces the old one
|
|
@@ -48,150 +57,118 @@ export const BUILTIN_RUNS = {
|
|
|
48
57
|
const markerId = raw => raw.id ?? (typeof raw === 'string' ? raw : raw.place ?? `${raw.x},${raw.z}`);
|
|
49
58
|
|
|
50
59
|
/**
|
|
51
|
-
* Load
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
60
|
+
* Load content packs as one transaction (core/base/sections.js): every pack is checked and prepared before any commits, and whatever fails after that takes every commit
|
|
61
|
+
* back, so a refused load changed nothing. packs are the merged objects of content/index.js; api is engine.content; ids is the IdCheck of this load call (ids.js); st is
|
|
62
|
+
* the content module's load state (shared across repeated load calls): { kinds, ops, sectionIds, refs, levelPlace(name), wait(promise) }; places are this load's new places;
|
|
63
|
+
* turn says it belongs to the state replacement running now (stateReplace.js). checkOps refuses op names nothing defines; a replay passes none, its pack was checked when it came.
|
|
64
|
+
* Returns the Promise of the transaction, or nothing when it ended on this tick.
|
|
65
|
+
* Order per pack: vocabulary -> key actions, audio, views (core services) -> renames -> the modules' sections in ORDER -> any other section -> game kinds. Packs commit in
|
|
66
|
+
* load order, so a later pack stands on an earlier one; with a level file to wait for the whole load commits after it, on the new level's markers. A load waits for the one
|
|
67
|
+
* before it (st.queue) and goes down with it: a level that failed leaves nothing to stand on. A load with its turn does neither: the load before it may be waiting for that very
|
|
68
|
+
* replacement to end, and what a load() brings in is part of the state it builds, not of the line outside. content's isReady waits for all of it.
|
|
69
|
+
* What a section's data means belongs to the module that owns it: replacing the quests module replaces the quests format.
|
|
70
|
+
* 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
71
|
* 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
72
|
* engine.world.zone),
|
|
59
73
|
* 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
|
|
60
74
|
* on level change (level.track).
|
|
61
75
|
*/
|
|
62
|
-
export function loadContent(e, api,
|
|
76
|
+
export function loadContent(e, api, packs, st, ids, places = {}, turn, checkOps) {
|
|
63
77
|
const { where } = api;
|
|
64
78
|
const origin = (id, list, key) => { if (DEV) e.world?.setOrigin(id, { definedAt: srcOf(list, key) }); };
|
|
65
79
|
const onLevel = (...ps) => ps.some(p => p && typeof p === 'object' ? st.levelPlace(p.place) : st.levelPlace(p));
|
|
66
80
|
const bind = (h, ...ps) => { if (h && onLevel(...ps)) e.level?.track(h); return h; };
|
|
67
81
|
const zoneOf = (...ps) => onLevel(...ps) ? e.world?.zone ?? null : null;
|
|
82
|
+
const sections = sectionsOf(e), kinds = { ...st.kinds };
|
|
83
|
+
const list = [{ s: {
|
|
84
|
+
undo: () => keepLoad(e, st),
|
|
85
|
+
// the first commit of the load, so a refusal leaves the rest uncommitted: a game kind's load has no undo. Not in validate: a load waiting for a file may meet an op defined meanwhile
|
|
86
|
+
commit() { Object.assign(st.places, places); for (const p of packs) collectOps(p, st.ops); checkOps?.(); },
|
|
87
|
+
} }];
|
|
88
|
+
for (const pack of packs) list.push(...loadSteps(e, api, pack, st), ...packSections(e, pack, st, sections, kinds));
|
|
89
|
+
// track: these listeners run content words, so they go with the content module
|
|
90
|
+
const inTurn = liveTurn(e, turn), after = inTurn ? null : st.queue, c = { engine: e, content: api, where, bind, zone: zoneOf, ids, origin, pickupId, track: st.track, after };
|
|
91
|
+
// a commit writes state, so it lands between replacements, never inside one: a pack that waited on a file through a load commits on the state that load left
|
|
92
|
+
const commits = fn => { const r = e.ops.allow(fn); if (r) whileRestoring(e, r); return r; }; // only a failure whose undo has to wait gives a result
|
|
93
|
+
const run = runSections(list, c, { after, around: fn => whenTurnFree(e, () => commits(fn), turn) });
|
|
94
|
+
if (!run || inTurn) return run;
|
|
95
|
+
const tail = st.queue = run.finally(() => { if (st.queue === tail) st.queue = null; });
|
|
96
|
+
return tail;
|
|
97
|
+
}
|
|
68
98
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
99
|
+
/** The undo of a whole load: the world, which several sections write, and the tables content itself fills */
|
|
100
|
+
function keepLoad(e, st) {
|
|
101
|
+
const world = e.world?.undoPoint();
|
|
102
|
+
const tables = [st.conds, st.ops, st.templates, st.templateFields, st.templateSrc].map(keepTable);
|
|
103
|
+
const { templateViews, templateSims } = st, was = { kinds: { ...st.kinds }, places: { ...st.places }, sectionIds: structuredClone(st.sectionIds), refs: st.refs.length };
|
|
104
|
+
const views = new Set(templateViews.keys()), sims = new Set(templateSims.keys());
|
|
105
|
+
return () => {
|
|
106
|
+
world?.();
|
|
107
|
+
for (const fn of tables) fn();
|
|
108
|
+
st.kinds = was.kinds; st.places = was.places; st.sectionIds = was.sectionIds; st.refs.length = was.refs;
|
|
109
|
+
for (const [map, had] of [[templateViews, views], [templateSims, sims]]) for (const [name, h] of map) if (!had.has(name)) { h.remove(); map.delete(name); }
|
|
110
|
+
};
|
|
111
|
+
}
|
|
80
112
|
|
|
113
|
+
/** What a pack registers with the core services and the vocabulary its sections read, as steps of the transaction */
|
|
114
|
+
function loadSteps(e, api, c, st) {
|
|
115
|
+
const steps = [];
|
|
116
|
+
// game kinds stay registered across loads, so a later content.load({ recipes }) without rules still finds them
|
|
117
|
+
if (c.rules) steps.push({ commit() { each(c.rules.conditions, (name, d) => api.condition(name, d)); Object.assign(st.kinds, c.rules.kinds); } });
|
|
81
118
|
// a pack's actions are the game's own (owner 'game'): loading the pack again replaces them, it is not a second binder
|
|
82
|
-
each(c.actions, (name, a) => e.input.action(name, { label: a.label, keys: a.keys, ...(a.context ? { context: a.context } : {}) }));
|
|
83
|
-
|
|
84
|
-
// audio: sounds / footsteps by name into engine.audio.config, rules to ambience() / music() (core/audioRules.js). A pack loaded again
|
|
119
|
+
if (c.actions) steps.push({ undo: () => e.input.keepActions(Object.keys(c.actions)), commit: () => each(c.actions, (name, a) => e.input.action(name, { label: a.label, keys: a.keys, ...(a.context ? { context: a.context } : {}) })) });
|
|
120
|
+
// audio: sounds / footsteps by name into engine.audio.config, rules to ambience() / music() (core/audio/audioRules.js). A pack loaded again
|
|
85
121
|
// 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
122
|
// twice never stacks its rules (a fresh key per load did); two different unnamed objects both keep theirs
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// views: named fixed camera views (core/Views.js); defining a name again replaces it, so a hot reload just works
|
|
90
|
-
each(c.views, (name, v) => e.views.define(name, v));
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
each(c.vegetation, (name, { model: m, lod, ...rest }) => {
|
|
97
|
-
veg.push(Promise.all([vegetationModel(e, m), lod && vegetationModel(e, lod)])
|
|
98
|
-
.then(([main, low]) => [name, { ...rest, ...main, ...(low && { lodGeometry: low.model ?? low.geometry }) }])
|
|
99
|
-
.catch(err => { reportError(e, err, `content vegetation ${name}: model generation`, { soft: true }); return null; })); // one failure does not affect the others
|
|
100
|
-
});
|
|
101
|
-
if (veg.length) st.wait(Promise.all(veg).then(list => { for (const v of list) if (v) e.vegetation.define(v[0], v[1]); }));
|
|
102
|
-
|
|
103
|
-
each(c.items, (id, d) => e.inventory.define(id, d));
|
|
104
|
-
each(c.startItems, (id, n) => e.inventory.add(id, n, { silent: true }));
|
|
105
|
-
// containers: starting goods are placed only the first time (if the save already has the container, the save wins; no refill after it was emptied and
|
|
106
|
-
// reloaded)
|
|
107
|
-
each(c.containers, (id, d) => { ids.claim(id, `containers.${id}`); e.inventory.container(id, { capacity: d.capacity, items: d.items }); });
|
|
108
|
-
// pickups: data goes into world (kind 'pickup'). id: the written id if given, else `pickup:<item>:<index in the pickups array>` (stable for the same content;
|
|
109
|
-
// when inserting in the middle, give existing entries an id)
|
|
110
|
-
if (c.pickups?.length && !e.pickups) throw codedError('module-needs', 'content pickups lie on the ground as pickups: add pickups() to engine.use(...) after world() (and inventory() for item pickups)');
|
|
111
|
-
c.pickups?.forEach((p, i) => {
|
|
112
|
-
const id = pickupId(p, i);
|
|
113
|
-
if (p.id != null) ids.claim(id, `pickups[${i}] (${p.item})`); else ids.unnamed(id, `pickups[${i}] (${p.item})`); // taken / respawning is state
|
|
114
|
-
e.pickups.spawn(where(p), { give: p.item, id, count: p.count, data: p.data, radius: p.radius, auto: p.auto, respawnSeconds: p.respawn, initial: true, zone: zoneOf(p) });
|
|
115
|
-
origin(id, c.pickups, i);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
const hpd = e.calendar?.hoursPerDay ?? 24;
|
|
119
|
-
each(c.npcs, (id, n) => { // the key in content is the NPC's stable id (used by saves and quest targets)
|
|
120
|
-
const plan = n.schedule ?? [];
|
|
121
|
-
ids.claim(id, `npcs.${id}`);
|
|
122
|
-
// every documented npcs.add option can be written in content (arriveDistance, interact, speed...); the same option table checks the spelling.
|
|
123
|
-
// 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
|
-
readParams(`content npcs.${id}`, keysSchema([...e.npcs.optionKeys.filter(k => !['id', 'position', 'zone', 'initial'].includes(k)), 'start']), n);
|
|
125
|
-
const { start: _s, schedule: _p, ...rest } = n;
|
|
126
|
-
e.npcs.add({ ...rest, id, schedule: plan.map(s => ({ at: parseClock(s.at, hpd), position: where(s) })), position: where(n.start || plan[0]), zone: zoneOf(n.start, ...plan), initial: true });
|
|
127
|
-
origin(id, c.npcs, id);
|
|
128
|
-
});
|
|
123
|
+
const key = c.name ? 'pack:' + c.name : c;
|
|
124
|
+
if (c.audio) steps.push({ undo: () => e.audio.keepPack(key), commit: () => e.audio.contentPack(key, c.name ? `pack "${c.name}"` : 'pack (no name)', c.audio) });
|
|
125
|
+
// views: named fixed camera views (core/scene/Views.js); defining a name again replaces it, so a hot reload just works
|
|
126
|
+
if (c.views) steps.push({ undo: () => keepTable(e.views.map), commit: () => each(c.views, (name, v) => e.views.define(name, v)) });
|
|
127
|
+
// saved state under an old id must reach the new id before anything is placed under it. The world goes back with keepLoad
|
|
128
|
+
let goods = null;
|
|
129
|
+
if (c.renames) steps.push({ undo: () => () => goods?.(), commit() { goods = applyRenames(e, c.renames); } });
|
|
130
|
+
return steps.map(s => ({ s }));
|
|
131
|
+
}
|
|
129
132
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
/** The sections of one pack, in ORDER. Every check that needs no commit runs here, before anything of the load commits. Game kinds are sections too, after the modules' */
|
|
134
|
+
function packSections(e, pack, st, modules, kinds) {
|
|
135
|
+
if (pack.rules?.effects) throw codedError('content-misuse', NO_GAME_EFFECTS);
|
|
136
|
+
const bad = kindProblems(pack.rules);
|
|
137
|
+
if (bad.length) throw codedError('content-misuse', 'content/rules.js: ' + bad.join('; '));
|
|
138
|
+
Object.assign(kinds, pack.rules?.kinds);
|
|
139
|
+
const known = { ...contentFiles({ kinds }), ...Object.fromEntries(modules) };
|
|
140
|
+
for (const k of Object.keys(pack)) if (k !== 'name' && !known[k]) throw codedError('unknown-option', 'content.load: ' + unknownContent(k, { kinds }));
|
|
141
|
+
const sections = new Map(modules);
|
|
142
|
+
for (const [name, k] of Object.entries(kinds)) {
|
|
143
|
+
if (sections.has(name)) throw codedError('content-misuse', `content kind "${name}" is also a section of module ${sections.get(name).owner}: keep one`);
|
|
144
|
+
sections.set(name, { owner: 'game', commit: (data, c) => k.load?.(e, data, c.content) });
|
|
145
|
+
}
|
|
146
|
+
const rank = n => { const i = ORDER.indexOf(n); return i < 0 ? ORDER.length : i; };
|
|
147
|
+
for (const name of Object.keys(pack)) {
|
|
148
|
+
const home = sectionHomes[name];
|
|
149
|
+
if (home && !sections.has(name) && !isEmpty(pack[name])) throw codedError('module-needs', `content ${name}: no installed module reads this section. Add ${home} to engine.use(...), or a module with content: { ${name}: { commit } }`);
|
|
150
|
+
}
|
|
151
|
+
const done = (name, s) => r => {
|
|
152
|
+
if (typeof r?.then === 'function') st.wait(r);
|
|
153
|
+
st.gaveWay.get(pack)?.delete(name);
|
|
154
|
+
note(st, name, s, pack[name]);
|
|
138
155
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
nodes[nid] = {
|
|
143
|
-
...n, speaker: n.speaker ?? d.speaker,
|
|
144
|
-
text: Array.isArray(n.text) ? variants(`dialogues.${id}.nodes.${nid}.text`, n.text) : n.text,
|
|
145
|
-
do: n.do && (() => api.run(n.do)),
|
|
146
|
-
choices: n.choices?.map(ch => ({ ...ch, if: ch.if && (() => api.test(ch.if)), do: ch.do && (() => api.run(ch.do)) })),
|
|
147
|
-
};
|
|
148
|
-
});
|
|
149
|
-
e.dialogue.define(id, nodes);
|
|
150
|
-
});
|
|
156
|
+
const gaveWay = name => () => { if (!st.gaveWay.has(pack)) st.gaveWay.set(pack, new Set()); st.gaveWay.get(pack).add(name); };
|
|
157
|
+
return [...sections].filter(([name]) => pack[name] != null).sort(([a], [b]) => rank(a) - rank(b)).map(([name, s]) => ({ s, data: pack[name], done: done(name, s), gaveWay: gaveWay(name) }));
|
|
158
|
+
}
|
|
151
159
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
e.quests.define(id, {
|
|
159
|
-
title: q.title, desc: q.desc,
|
|
160
|
-
steps: q.steps.map(s => s.all ? { ...(s.id != null && { id: s.id }), text: s.text, all: s.all.map(goal) } : goal(s)),
|
|
161
|
-
reward: q.reward && (() => api.run(q.reward)),
|
|
162
|
-
...(q.fail && { fail: () => api.test(q.fail) }), ...(q.onFail && { onFail: () => api.run(q.onFail) }),
|
|
163
|
-
});
|
|
164
|
-
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)));
|
|
166
|
-
});
|
|
160
|
+
/** What the reference check (checkRefs) needs from a section just loaded */
|
|
161
|
+
function note(st, name, s, data) {
|
|
162
|
+
const ids = st.sectionIds[name] ??= new Set();
|
|
163
|
+
for (const k of Array.isArray(data) ? data.map(x => x?.id) : Object.keys(data)) if (k != null) ids.add(k);
|
|
164
|
+
st.refs.push(...s.references?.(data) ?? []);
|
|
165
|
+
}
|
|
167
166
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (Object.values(c.triggers).some(t => t.fromLevel)) e.triggers.fromMarkers();
|
|
173
|
-
each(c.triggers, (tag, t) => {
|
|
174
|
-
if (!t.fromLevel) bind(e.triggers.add({ ...t, tag, position: where(t.position), onEnter: null, onExit: null }), t.position);
|
|
175
|
-
});
|
|
176
|
-
st.subs ??= [
|
|
177
|
-
// the effects act for whoever crossed the zone (a { give } lands in that actor's bag); a zone emptied by removal has no id: engine.actor
|
|
178
|
-
st.track(e.events.on('trigger:enter', ({ tag, id }) => api.run(st.triggers[tag]?.onEnter, { actor: id ?? e.actor }))),
|
|
179
|
-
st.track(e.events.on('trigger:exit', ({ tag, id }) => api.run(st.triggers[tag]?.onExit, { actor: id ?? e.actor }))),
|
|
180
|
-
];
|
|
167
|
+
/** Ids a section names in a section that was loaded and does not have them. Only when that section was loaded: a game may define its items in code */
|
|
168
|
+
export function checkRefs(st) {
|
|
169
|
+
for (const { section, id, at } of st.refs.splice(0)) {
|
|
170
|
+
if (st.sectionIds[section] && !st.sectionIds[section].has(id)) warnOnce(coded('content-misuse', `content ${at}: ${section} has no "${id}"`), `${at}:${id}`);
|
|
181
171
|
}
|
|
182
|
-
|
|
183
|
-
// grids (layout rules, not saved) before props: a props entry with grid places an item on one; a repeated load keeps the grid that exists
|
|
184
|
-
each(c.grids, (name, g) => {
|
|
185
|
-
if (!e.grids) throw codedError('content-misuse', `content grids: install grids() to use grid "${name}"`);
|
|
186
|
-
if (!e.grids.get(name)) e.grids.add(name, g);
|
|
187
|
-
});
|
|
188
|
-
// templates before props: a props entry with template places an instance of it
|
|
189
|
-
if (c.templates) { needWorld(e); defineTemplates(e, api, st, c.templates); }
|
|
190
|
-
// props: data goes into world (kind 'prop'); models and collision are built nearby and torn down when far by present in props.js
|
|
191
|
-
if (c.props?.length) addProps(e, api, c.props, st, zoneOf, ids);
|
|
192
|
-
|
|
193
|
-
// 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); });
|
|
195
172
|
}
|
|
196
173
|
|
|
197
174
|
/** 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/base/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,8 +1,12 @@
|
|
|
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
|
|
3
|
+
import * as THREE from 'three';
|
|
4
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
5
|
+
import { protoOf } from '../../core/assets/namedModel.js';
|
|
6
|
+
import { wrapLod } from '../../core/assets/assetLod.js';
|
|
4
7
|
import { Vector3 } from 'three';
|
|
5
|
-
import {
|
|
8
|
+
import { clone as skeletonClone } from 'three/addons/utils/SkeletonUtils.js';
|
|
9
|
+
import { list } from '../../core/base/util.js';
|
|
6
10
|
|
|
7
11
|
const BASE_BAND = 0.2; // the share of the model's height above the ground that counts as its base
|
|
8
12
|
|
|
@@ -51,35 +55,68 @@ export function baseOf(proto) {
|
|
|
51
55
|
* mul: a template stage's scale, multiplied onto the record's own scale (the record keeps only its authored scale). @internal
|
|
52
56
|
*/
|
|
53
57
|
export function settle(e, rec, o, solid, mul = 1) {
|
|
54
|
-
const { x, z } = rec.position, rot = rec
|
|
55
|
-
ud.fit =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
const { x, z } = rec.position, rot = rotOf(rec), sv = scaleOf(rec, mul), ud = o.userData;
|
|
59
|
+
ud.fit = fitOf(rec, mul); ud.shape = shapeOf(rec, mul); ud.holder = holderOf(e, rec);
|
|
60
|
+
const tilted = isTilted(rec);
|
|
61
|
+
if (tilted && solid.collide && !e.collider3d) throw tiltError(rec);
|
|
62
|
+
// ground: false keeps the written height (a floating or hung model); a body's height is the solver's (templates.js addBody). The height comes from the ground, not from play,
|
|
63
|
+
// so it stays out of the save (world.rest), and a ground ray's rounding (1e-16 off a turned level) is no new height: a load would write a change for it
|
|
64
|
+
const y = e.surface(x, z, rec.floor) + (rec.offsetY ?? 0);
|
|
65
|
+
if (rec.ground !== false && !solid.body && Math.abs(rec.position.y - y) > 1e-6 && !e.world.rest(rec.id, { x, y, z })) rec.position.y = y;
|
|
66
|
+
o.position.y = rec.position.y; o.rotation.set(rot[0], rot[1], rot[2]); o.scale.set(sv[0], sv[1], sv[2]);
|
|
58
67
|
ud.unstatic?.remove(); ud.unstatic = null;
|
|
59
68
|
for (const h of ud.colliders.splice(0)) h.remove();
|
|
60
69
|
// 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
|
|
61
70
|
const blocks = !!solid.collide && solid.collide.occluder !== false && solid.occluder !== false;
|
|
62
71
|
if (solid.static !== false && e.rays) { o.updateMatrixWorld(true); ud.unstatic = e.rays.addStatic(o, { occluder: blocks }); }
|
|
63
|
-
if (!solid.collide
|
|
72
|
+
if (!solid.collide) return;
|
|
64
73
|
const { collide } = solid, set = typeof collide === 'object' ? collide : null, base = set || collide === 'circle' ? baseOf(ud.proto) : null;
|
|
65
|
-
const size = ud.proto.size.clone().
|
|
66
|
-
|
|
74
|
+
const size = ud.proto.size.clone().multiply(new THREE.Vector3(...sv));
|
|
75
|
+
if (tilted) { // a turned-over solid is not a footprint on the ground: the three-axis provider holds it (o.quaternion carries the same turn the model has)
|
|
76
|
+
const mid = ud.proto.center.clone().multiply(new THREE.Vector3(...sv)).applyQuaternion(o.quaternion).add(o.position);
|
|
77
|
+
ud.colliders.push(e.collider3d.addSolid(base
|
|
78
|
+
? { position: [mid.x, mid.y, mid.z], radius: (set?.circle ?? base.width / 2) * Math.max(sv[0], sv[2]) }
|
|
79
|
+
: { position: [mid.x, mid.y, mid.z], size: [size.x, size.y, size.z], rotation: rot }));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (!e.collision) return;
|
|
83
|
+
const c = base ?? ud.proto.center, ox = c.x * sv[0], oz = c.z * sv[2];
|
|
84
|
+
const cx = x + ox * Math.cos(rot[1]) + oz * Math.sin(rot[1]), cz = z - ox * Math.sin(rot[1]) + oz * Math.cos(rot[1]);
|
|
67
85
|
ud.colliders.push(base
|
|
68
|
-
? e.collision.addCircle({ x: cx, z: cz }, { radius: (set?.circle ?? base.width / 2) *
|
|
69
|
-
: e.collision.addBox({ x: cx, z: cz }, { halfWidth: size.x / 2, halfDepth: size.z / 2, rotation: rot, height: size.y, occluder: blocks }));
|
|
86
|
+
? e.collision.addCircle({ x: cx, z: cz }, { radius: (set?.circle ?? base.width / 2) * Math.max(sv[0], sv[2]), height: size.y, occluder: blocks })
|
|
87
|
+
: e.collision.addBox({ x: cx, z: cz }, { halfWidth: size.x / 2, halfDepth: size.z / 2, rotation: rot[1], height: size.y, occluder: blocks }));
|
|
70
88
|
}
|
|
71
|
-
/**
|
|
72
|
-
|
|
89
|
+
/** Is the model still as settle aligned it, with its collider in the holder installed now (a new one starts empty; with none there is nothing to do yet)? update asks every frame for every built prop, because world.move sends no event @internal */
|
|
90
|
+
/** rot / scale of a record as [x, y, z]: a number is the facing about Y and a uniform scale, as it always was; an array sets each axis (the model's Euler order XYZ) */
|
|
91
|
+
export const rotOf = rec => Array.isArray(rec.rot) ? rec.rot : [0, rec.rot ?? 0, 0];
|
|
92
|
+
export const scaleOf = (rec, mul = 1) => (Array.isArray(rec.scale) ? rec.scale : [rec.scale ?? 1, rec.scale ?? 1, rec.scale ?? 1]).map(v => v * mul);
|
|
93
|
+
const fitOf = (rec, mul) => JSON.stringify([rec.position.x, rec.position.z, rec.ground === false ? rec.position.y : null, rotOf(rec), scaleOf(rec, mul)]);
|
|
94
|
+
export const fits = (e, o, rec, mul = 1) => { const h = holderOf(e, rec); return (!h || o.userData.holder === h) && o.userData.fit === fitOf(rec, mul); };
|
|
95
|
+
const shapeOf = (rec, mul) => JSON.stringify([rotOf(rec), scaleOf(rec, mul)]);
|
|
96
|
+
/** The turn and size it was built with still hold (a body moves itself, so its place says nothing) @internal */
|
|
97
|
+
export const fitsShape = (o, rec, mul = 1) => o.userData.shape === shapeOf(rec, mul);
|
|
98
|
+
/** A tilted solid needs the three-axis provider (collider3d); the same error at load (props.js) and at build, so a mistake shows once, early @internal */
|
|
99
|
+
export const tiltError = rec => codedError('content-misuse', `prop ${JSON.stringify(rec.id ?? rec.model)}: collide on a model turned about x or z (rot ${JSON.stringify(rec.rot)}) needs a collider3d provider: install rigid() (or your own collider3d), or set collide: false`);
|
|
100
|
+
export const isTilted = rec => { const r = rotOf(rec); return !!(r[0] || r[2]); };
|
|
101
|
+
const holderOf = (e, rec) => isTilted(rec) ? e.collider3d : e.collision;
|
|
73
102
|
|
|
74
|
-
/** Clone the shared prototype of a model for one record and align it (props and template instances) @internal */
|
|
103
|
+
/** Clone the shared prototype of a model for one record and align it (props and template instances). skeletonClone: a skinned part of a plain clone keeps the prototype's bones and draws where they stand @internal */
|
|
75
104
|
export async function buildModel(e, api, rec, model, solid, mul = 1) {
|
|
76
|
-
const proto = await protoOf(e, api, model),
|
|
105
|
+
const proto = await protoOf(e, api, model), name = list(model)[0], lod = rec.lod ?? solid.lod;
|
|
106
|
+
// 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
|
|
107
|
+
const o = lod ? await wrapLod(e.assets, name, skeletonClone(proto.obj), { distances: Array.isArray(lod) ? lod : undefined, scale: Math.max(...scaleOf(rec, mul)) }) : skeletonClone(proto.obj);
|
|
77
108
|
o.name ||= name; o.userData.name ??= name;
|
|
78
109
|
o.userData.proto = proto; o.userData.colliders = [];
|
|
110
|
+
o.userData.refit = r => { if (!solid.body && !fits(e, o, r, mul)) settle(e, r, o, solid, mul); }; // a body places itself; a stale solid or mul is put right by the presenter's next update
|
|
111
|
+
// a file model only: a generator's prototype is pinned for good (Assets.cached), so nothing could free it. The built prop counts in describe().assets until it is torn down
|
|
112
|
+
if (!e.assets.builder(name)) o.userData.lease = await e.assets.lease(name);
|
|
79
113
|
if (rec.batch === false) o.userData.batch = false; // opt out of engine.batching for this record
|
|
80
114
|
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
|
|
81
115
|
settle(e, rec, o, solid, mul);
|
|
82
116
|
return o;
|
|
83
117
|
}
|
|
118
|
+
/** ctx.feeds: every built solid goes into the holder installed now, so the line after use() reads it. The presenters' update asks the same every frame, for what moved @internal */
|
|
119
|
+
export const refit = e => { for (const rec of e.world?.query({}) ?? []) e.world.view(rec.id)?.userData.refit?.(rec); };
|
|
120
|
+
|
|
84
121
|
/** Tear down only: geometry and material belong to the shared prototype, the next build clones it again @internal */
|
|
85
|
-
export function unbuildModel(e, o) { o.userData.unstatic?.remove(); for (const h of o.userData.colliders) h.remove();
|
|
122
|
+
export function unbuildModel(e, o) { o.userData.lease?.remove(); o.userData.unstatic?.remove(); for (const h of o.userData.colliders) h.remove(); o.removeFromParent(); }
|
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',
|
|
@@ -47,7 +47,8 @@ export function packsOf(data) {
|
|
|
47
47
|
packs.forEach((p, i) => {
|
|
48
48
|
if (!isPlainObject(p)) throw codedError('content-pack', fmt(STRINGS.notPack, { at: i + 1, got: Array.isArray(p) ? 'an array' : typeof p }));
|
|
49
49
|
for (const [key, v] of Object.entries(p)) {
|
|
50
|
-
if (key === '
|
|
50
|
+
if (key === 'level' && (typeof v === 'string' || v?.isObject3D)) claim('level', { level: 1 }, i); // a load has one transaction: the second level would drop the first with all that stands on it
|
|
51
|
+
else if (key === 'rules') { claim('rules.conditions', v?.conditions, i); claim('rules.kinds', v?.kinds, i); }
|
|
51
52
|
// audio: named tables are ids (a sound in two packs is an error), rule lists concatenate
|
|
52
53
|
else if (key === 'audio') { claim('audio.sounds', v?.sounds, i); claim('audio.footsteps', v?.footsteps, i); claim('audio.music.tracks', v?.music?.tracks, i); }
|
|
53
54
|
else if (key !== 'name' && !NOT_KEYED.has(key) && isPlainObject(v)) claim(key, v, i);
|
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,36 @@
|
|
|
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
|
+
import { placeProblem } from './rules.js';
|
|
6
|
+
|
|
7
|
+
/** content.load: the packs' places, then the places option on top, checked. A text entry in a place file waits for the option */
|
|
8
|
+
export function placesOf(packs, given) {
|
|
9
|
+
const pl = {};
|
|
10
|
+
for (const p of packs) for (const [name, at] of Object.entries(p.places ?? {})) if (at && typeof at === 'object') pl[name] = at;
|
|
11
|
+
Object.assign(pl, given);
|
|
12
|
+
for (const [name, p] of Object.entries(pl)) { const bad = placeProblem(p); if (bad) throw codedError('content-place', `Place "${name}": ${bad}`); }
|
|
13
|
+
return pl;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** content.place */
|
|
17
|
+
export function placeOf(e, places, name) {
|
|
18
|
+
const p = places[name] ?? e.level?.marker(name)?.position;
|
|
19
|
+
return p ? { x: p.x, z: p.z, ...(p.y !== undefined && { y: p.y }), ...(p.rot !== undefined && { rot: p.rot }) } : null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** content.offset */
|
|
23
|
+
export function offsetFrom(api, place, x, z) {
|
|
24
|
+
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);
|
|
25
|
+
return { x: dx * c - dz * s, z: dx * s + dz * c };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** content.where */
|
|
29
|
+
export function whereOf(e, api, p) {
|
|
30
|
+
const base = p.place ? api.place(p.place) : null;
|
|
31
|
+
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`);
|
|
32
|
+
const ox = p.x ?? 0, oz = p.z ?? 0, c = Math.cos(base?.rot ?? 0), s = Math.sin(base?.rot ?? 0);
|
|
33
|
+
const x = (base?.x ?? 0) + ox * c + oz * s, z = (base?.z ?? 0) - ox * s + oz * c, floor = p.floor ?? base?.y;
|
|
34
|
+
if (floor === undefined && p.y === undefined) return { x, z };
|
|
35
|
+
return { x, y: placeY(e, `content.where(${JSON.stringify(p.place ?? { x: p.x, z: p.z })})`, x, z, floor) + (p.y ?? 0), z };
|
|
36
|
+
}
|