threedog 0.2.0 → 0.5.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 +290 -0
- package/README.md +9 -8
- package/core/Animator.js +15 -12
- package/core/Assets.js +83 -16
- package/core/Audio.js +45 -38
- package/core/Baked.js +32 -8
- package/core/Batching.js +102 -15
- package/core/Budget.js +39 -18
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +45 -10
- package/core/Describe.js +104 -43
- package/core/Engine.js +190 -57
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +168 -79
- package/core/Inspect.js +2 -2
- package/core/InspectMaterials.js +85 -0
- package/core/InspectPerf.js +61 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +5 -5
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +14 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +25 -9
- package/core/Views.js +9 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +22 -5
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +38 -11
- package/core/assetManifest.js +48 -9
- package/core/assetReport.js +1 -1
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +5 -2
- package/core/cells.js +62 -0
- package/core/checks.js +10 -8
- package/core/chunkStream.js +87 -0
- package/core/control.js +149 -0
- package/core/copies.js +32 -0
- package/core/dayTime.js +12 -6
- package/core/debugView.js +82 -15
- package/core/describeRender.js +43 -17
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +438 -19
- package/core/errorHints.js +37 -141
- package/core/errors.js +31 -8
- package/core/events.generated.js +12 -7
- package/core/gameLights.js +62 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +128 -0
- package/core/gridLoad.js +20 -0
- package/core/ground.js +6 -4
- package/core/headlessLoad.js +55 -0
- package/core/holds.js +78 -50
- package/core/inputContext.js +11 -7
- package/core/inputDefaults.js +24 -21
- package/core/inputPad.js +1 -1
- package/core/inputPointer.js +1 -1
- package/core/inputTouch.js +2 -2
- package/core/lifecycle.js +48 -12
- package/core/lightWatch.js +6 -4
- package/core/look/coreParts.js +137 -30
- package/core/look/part.js +175 -95
- package/core/look/points.js +255 -0
- package/core/look/report.js +34 -17
- package/core/look/shadowPart.js +63 -0
- package/core/look/state.js +45 -0
- package/core/look/write.js +12 -28
- package/core/loop.js +101 -37
- package/core/math.js +11 -3
- package/core/moduleSlots.js +75 -0
- package/core/moduleTypes.js +73 -0
- package/core/modules.js +145 -27
- package/core/movement.js +2 -2
- package/core/namedModel.js +70 -0
- package/core/opsCheck.js +3 -3
- package/core/opsFail.js +15 -6
- package/core/opsGuard.js +4 -4
- package/core/opsRun.js +4 -3
- package/core/owned.js +168 -0
- package/core/page.js +2 -1
- package/core/params.js +30 -8
- package/core/plugins.js +277 -0
- package/core/saveApply.js +99 -17
- package/core/saveFiles.js +8 -6
- package/core/saveValues.js +46 -0
- package/core/saveVersions.js +20 -3
- package/core/scatter.js +48 -19
- package/core/sceneDelta.js +203 -0
- package/core/sceneMethods.js +35 -30
- package/core/screenToGround.js +1 -1
- package/core/services.js +27 -11
- package/core/session.js +28 -25
- package/core/shaderCost.js +78 -0
- package/core/shadowTypes.js +2 -1
- package/core/sharedPoint.js +317 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +34 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -11
- package/core/streamSources.js +0 -11
- package/core/styleParts.js +65 -47
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +2 -2
- package/core/thingOps.js +29 -6
- package/core/things.js +21 -11
- package/core/threadPure.js +7 -3
- package/core/threePatches.js +47 -0
- package/core/tier.js +21 -10
- package/core/time.js +236 -0
- package/core/uiClock.js +25 -0
- package/core/util.js +7 -1
- package/core/validate.js +65 -86
- package/core/wrap.js +106 -0
- package/docs/AI.md +89 -97
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +224 -149
- package/docs/COMMANDS.md +57 -34
- package/docs/CONVENTIONS.md +92 -30
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +228 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +79 -27
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +12 -9
- package/docs/api/audio.md +10 -14
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -25
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +9 -6
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +65 -62
- package/docs/api/events.md +19 -14
- package/docs/api/grids.md +3 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +11 -6
- package/docs/api/interactions.md +7 -5
- package/docs/api/inventory.md +17 -16
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +15 -0
- package/docs/api/post.md +5 -4
- package/docs/api/quests.md +2 -3
- package/docs/api/rigid.md +16 -14
- package/docs/api/saves.md +6 -4
- package/docs/api/settings.md +2 -3
- package/docs/api/sky.md +11 -44
- package/docs/api/stream.md +1 -1
- package/docs/api/style.md +31 -29
- package/docs/api/terrain.md +9 -6
- package/docs/api/terrainLook.md +10 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +30 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +12 -8
- package/docs/api/vegetationLook.md +10 -0
- package/docs/api/water.md +4 -20
- package/docs/api/weather.md +5 -15
- package/docs/api/weatherLook.md +10 -0
- package/docs/api/world.md +2 -1
- package/docs/recipes/01-new-game.md +71 -59
- package/docs/recipes/02-npc.md +46 -29
- package/docs/recipes/03-items-pickups.md +38 -24
- package/docs/recipes/04-quests.md +34 -27
- package/docs/recipes/05-props-bake.md +154 -18
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +41 -10
- package/docs/recipes/08-weather-sky.md +146 -37
- package/docs/recipes/09-style.md +218 -0
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +34 -10
- package/docs/recipes/14-custom-module.md +65 -34
- package/docs/recipes/15-perf.md +35 -6
- package/docs/recipes/16-dev-bridge.md +65 -41
- package/docs/recipes/18-world.md +21 -8
- package/docs/recipes/19-shooting-picking.md +12 -11
- package/docs/recipes/20-content-actions-save.md +63 -25
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +18 -18
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +12 -6
- package/docs/recipes/28-terrain.md +35 -2
- package/docs/recipes/29-grid.md +71 -33
- package/docs/recipes/30-templates.md +64 -12
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +35 -2
- package/docs/recipes/34-environment-lighting.md +27 -4
- package/docs/recipes/35-style-from-reference.md +115 -51
- package/docs/recipes/36-sky-ground-plant-looks.md +37 -35
- package/docs/recipes/37-terrain-look-hooks.md +37 -15
- package/docs/recipes/38-environment-look-hooks.md +64 -48
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +3 -3
- package/docs/recipes/43-shader-patches-surface-looks.md +171 -74
- package/docs/recipes/44-water-weather-look-hooks.md +30 -21
- package/docs/recipes/45-cascaded-shadows.md +17 -8
- package/docs/recipes/46-blender-art-route.md +4 -4
- package/docs/recipes/47-island-snow-backdrop.md +11 -10
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +46 -33
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +4 -4
- package/docs/recipes/52-look.md +228 -54
- package/docs/recipes/53-ground-up-close.md +58 -0
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +112 -0
- package/docs/recipes/56-webgpu-tsl.md +260 -0
- package/docs/recipes/57-control.md +65 -0
- package/docs/recipes/58-input.md +57 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +55 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +17 -13
- package/examples/action/assets.js +8 -0
- package/examples/action/content/actions.js +1 -1
- package/examples/action/content/audio.js +5 -5
- package/examples/action/look.js +1 -1
- package/examples/action/main.js +10 -13
- package/examples/action/models.js +24 -23
- package/examples/pullable.json +111 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +83 -0
- package/examples/rc2d/README.md +52 -0
- package/examples/rc2d/main.js +63 -0
- package/examples/rc2d/rc2d.js +197 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +13 -11
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/main.js +17 -12
- package/examples/sheepisland/style/index.js +6 -6
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +15 -16
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/npcs.js +1 -1
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +18 -17
- package/examples/styletest/models.js +1 -1
- package/examples/styletest/params.js +3 -3
- package/examples/techniques/contact-shadows/README.md +92 -0
- package/examples/techniques/contact-shadows/contactShadows.js +51 -0
- package/examples/techniques/contact-shadows/main.js +53 -0
- package/examples/techniques/day-night-grade/README.md +86 -0
- package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
- package/examples/techniques/day-night-grade/main.js +51 -0
- package/examples/techniques/interior-light/README.md +103 -0
- package/examples/techniques/interior-light/interiorLight.js +45 -0
- package/examples/techniques/interior-light/main.js +124 -0
- package/examples/techniques/modular-building/README.md +125 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +47 -0
- package/examples/techniques/night-lights/README.md +94 -0
- package/examples/techniques/night-lights/main.js +70 -0
- package/examples/techniques/night-lights/nightLights.js +91 -0
- package/examples/techniques/outlines-and-rim/README.md +59 -0
- package/examples/techniques/outlines-and-rim/main.js +84 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- package/examples/techniques/procedural-animation/README.md +77 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +45 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
- package/examples/techniques/procedural-surface/README.md +67 -0
- package/examples/techniques/procedural-surface/main.js +103 -0
- package/examples/techniques/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +75 -0
- package/examples/techniques/stylized-shading/main.js +93 -0
- package/examples/techniques/stylized-shading/shading.js +131 -0
- package/examples/techniques/sun-and-key-light/README.md +135 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
- package/examples/techniques/sun-and-key-light/main.js +95 -0
- package/examples/techniques/wet-road/README.md +99 -0
- package/examples/techniques/wet-road/main.js +68 -0
- package/examples/techniques/wet-road/wetRoad.js +209 -0
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/webgpu-tsl/GAMEMAP.md +84 -0
- package/examples/webgpu-tsl/README.md +42 -0
- package/examples/webgpu-tsl/main.js +21 -0
- package/examples/webgpu-tsl/tslScene.js +75 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/examples/world/GAMEMAP.md +22 -15
- package/examples/world/art/humanoid.js +42 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +58 -0
- package/examples/world/art/shapes.js +9 -0
- package/examples/world/assets.js +6 -0
- package/examples/world/content/audio.js +5 -5
- package/examples/world/content/npcs.js +2 -2
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/rules.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +17 -13
- package/examples/world/style/index.js +61 -0
- package/examples/world/style/plugins/10-bloom.js +5 -0
- package/index.d.ts +50 -45
- package/index.js +27 -22
- package/llms.txt +20 -12
- package/modules/ambience/Ambience.js +34 -23
- package/modules/calendar/Calendar.js +163 -0
- package/modules/calendar/contract.js +21 -0
- package/modules/calendar/index.js +81 -0
- package/modules/{sky → calendar}/schedule.js +17 -16
- package/modules/calendar/seasons.js +55 -0
- package/modules/camera/FirstPersonCamera.js +6 -15
- package/modules/camera/FixedCamera.js +33 -15
- package/modules/camera/FollowCamera.js +90 -16
- package/modules/camera/RtsCamera.js +18 -17
- package/modules/camera/common.js +70 -19
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +196 -59
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +27 -8
- package/modules/characters/behaviors.js +2 -1
- package/modules/characters/contract.js +13 -0
- package/modules/characters/footsteps.js +1 -1
- package/modules/characters/index.js +87 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +97 -19
- package/modules/characters/movers/manual.js +20 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +172 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +12 -8
- package/modules/characters/npcView.js +44 -16
- package/modules/characters/pathAsync.js +7 -3
- package/modules/characters/playerStrings.js +4 -3
- package/modules/characters/proceduralRig.js +46 -10
- package/modules/characters/useModel.js +1 -1
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +65 -25
- package/modules/collision/grid.js +8 -6
- package/modules/content/explain.js +2 -2
- package/modules/content/fields.js +102 -0
- package/modules/content/ids.js +8 -6
- package/modules/content/index.js +97 -28
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +11 -40
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +16 -9
- package/modules/content/rules.js +58 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +121 -30
- package/modules/debug/DebugPanel.js +24 -17
- package/modules/flow/contract.js +16 -0
- package/modules/flow/index.js +21 -15
- package/modules/gameplay/Container.js +41 -32
- package/modules/gameplay/Containers.js +30 -15
- package/modules/gameplay/Dialogue.js +113 -55
- package/modules/gameplay/Interactions.js +193 -67
- package/modules/gameplay/Inventory.js +69 -73
- package/modules/gameplay/Quests.js +75 -39
- package/modules/gameplay/boxOps.js +3 -3
- package/modules/gameplay/dialogue.contract.js +21 -0
- package/modules/gameplay/dialogueBox.js +4 -2
- package/modules/gameplay/dialogueBubbles.js +116 -0
- package/modules/gameplay/interactionPrompt.js +4 -1
- package/modules/gameplay/interactions.contract.js +16 -0
- package/modules/gameplay/inventory.contract.js +23 -0
- package/modules/gameplay/inventoryOps.js +18 -16
- package/modules/gameplay/pickups.js +268 -85
- package/modules/gameplay/questLog.js +4 -4
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +14 -13
- package/modules/grid/index.js +60 -36
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +15 -16
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +6 -5
- package/modules/hlod/index.js +51 -19
- package/modules/hud/index.js +35 -20
- package/modules/hud/parts.js +20 -7
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +45 -20
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +42 -18
- package/modules/music/Music.js +38 -21
- package/modules/music/rules.js +1 -1
- package/modules/nav/index.js +48 -42
- package/modules/net/Client.js +13 -6
- package/modules/net/Host.js +19 -5
- package/modules/net/Net.js +2 -1
- package/modules/net/index.js +13 -8
- package/modules/net/sync.js +9 -8
- package/modules/net/transports.js +77 -27
- package/modules/particles/Particles.js +23 -14
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +39 -11
- package/modules/photo/Photo.js +53 -36
- package/modules/rigid/RigidBodies.js +194 -32
- package/modules/rigid/Vehicles.js +18 -15
- package/modules/rigid/sync.js +62 -17
- package/modules/settings/Settings.js +57 -52
- package/modules/settings/apply.js +38 -3
- package/modules/settings/sections.js +5 -3
- package/modules/settings/strings.js +3 -2
- package/modules/settings/view.js +5 -3
- package/modules/sky/Sky.js +88 -176
- package/modules/sky/cascades.js +86 -25
- package/modules/sky/cascades.tsl.js +82 -0
- package/modules/sky/clouds.js +34 -19
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +83 -13
- package/modules/sky/fog.js +140 -95
- package/modules/sky/frame.js +112 -44
- package/modules/sky/look.js +22 -19
- package/modules/sky/lookFog.js +48 -52
- package/modules/sky/lookShadow.js +53 -41
- package/modules/sky/lookSky.js +82 -21
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +41 -19
- package/modules/sky/shadow.js +44 -20
- package/modules/sky/skyModule.js +45 -33
- package/modules/sky/tint.js +61 -0
- package/modules/terrain/ChunkManager.js +175 -108
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/index.js +105 -50
- package/modules/terrain/look.js +83 -0
- package/modules/terrain/lookGround.js +21 -16
- package/modules/terrain/terrainDefaults.js +1 -1
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +5 -3
- package/modules/terrain/terrainIsland.js +5 -4
- package/modules/terrain/terrainShape.js +12 -12
- package/modules/terrain/terrainShapeMain.js +8 -7
- package/modules/terrain/terrainTexture.js +21 -19
- package/modules/timeline/Timeline.js +95 -43
- package/modules/timeline/Tween.js +18 -10
- package/modules/timeline/letterbox.js +2 -2
- package/modules/timeline/shots.js +5 -1
- package/modules/triggers/index.js +107 -76
- package/modules/vegetation/Vegetation.js +190 -102
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +31 -10
- package/modules/vegetation/look.js +119 -0
- package/modules/vegetation/lookWind.js +71 -10
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +45 -0
- package/modules/water/Water.js +65 -27
- package/modules/water/look.js +29 -18
- package/modules/water/surface.js +64 -25
- package/modules/water/surfaceDefaults.js +3 -0
- package/modules/weather/Weather.js +62 -104
- package/modules/weather/look.js +1 -2
- package/modules/weather/particles.js +24 -9
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherLook.js +135 -0
- package/modules/world/World.js +24 -7
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -4
- package/modules/world/persist.js +62 -2
- package/modules/world/pos.js +3 -2
- package/modules/world/records.js +8 -6
- package/modules/world/sim.js +60 -20
- package/modules/world/simFar.js +4 -3
- package/modules/world/state.js +3 -2
- package/modules/world/thingSource.js +1 -1
- package/modules/world/views.js +7 -5
- package/package.json +8 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +150 -45
- package/render/effects.js +130 -38
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +26 -0
- package/render/fx/lighting.tsl.js +28 -0
- package/render/fx/nodeErrors.tsl.js +68 -0
- package/render/fx/noise.tsl.js +12 -0
- package/render/fx/objectOrigin.tsl.js +42 -0
- package/render/fx/particles.tsl.js +139 -0
- package/render/fx/patchNodes.tsl.js +403 -0
- package/render/fx/postWebGPU.tsl.js +158 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +260 -0
- package/render/fx/uniforms.tsl.js +67 -0
- package/render/fx/water.tsl.js +53 -0
- package/render/fx/wind.tsl.js +22 -0
- package/render/fxNumbers.js +36 -0
- package/render/hotGlsl.js +24 -0
- package/render/lighting.js +66 -14
- package/render/lights.js +223 -4
- package/render/lookGlow.js +139 -0
- package/render/lookSurface.js +99 -36
- package/render/materials.js +71 -52
- package/render/modeling.js +73 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +311 -34
- package/render/postLook.js +124 -46
- package/render/postWebGL.js +197 -0
- package/render/probes.js +231 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/surface.js +53 -17
- package/render/terms.js +211 -0
- package/render/uniformDecl.js +3 -2
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +620 -244
- package/types/gameplay.d.ts +494 -318
- package/types/generated/core/Audio.d.ts +26 -42
- package/types/generated/core/Batching.d.ts +6 -2
- package/types/generated/core/Budget.d.ts +2 -8
- package/types/generated/core/DebugOverrides.d.ts +44 -3
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +102 -31
- package/types/generated/core/Ops.d.ts +31 -0
- package/types/generated/core/Random.d.ts +2 -2
- package/types/generated/core/Saves.d.ts +10 -2
- package/types/generated/core/Stream.d.ts +1 -1
- package/types/generated/core/Threads.d.ts +4 -1
- package/types/generated/core/Views.d.ts +0 -1
- package/types/generated/core/audioVoice.d.ts +17 -9
- package/types/generated/core/control.d.ts +55 -0
- package/types/generated/core/session.d.ts +2 -1
- package/types/generated/modules/ambience/Ambience.d.ts +0 -9
- package/types/generated/modules/calendar/Calendar.d.ts +84 -0
- package/types/generated/modules/calendar/index.d.ts +10 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Grid.d.ts +61 -25
- package/types/generated/modules/grid/Layer.d.ts +5 -5
- package/types/generated/modules/grid/index.d.ts +29 -17
- package/types/generated/modules/music/Music.d.ts +5 -3
- package/types/generated/modules/net/index.d.ts +3 -3
- package/types/generated/modules/net/transports.d.ts +12 -3
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/sky/Sky.d.ts +12 -104
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/weather/Weather.d.ts +17 -18
- package/types/generated/modules/weather/weatherLook.d.ts +12 -0
- package/types/generated/modules/world/World.d.ts +18 -3
- package/types/generated/render/PostFX.d.ts +67 -30
- package/types/generated/render/materials.d.ts +26 -20
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/patches.d.ts +16 -2
- package/types/generated/ui/UI.d.ts +6 -3
- package/types/nav.d.ts +6 -0
- package/types/physics.d.ts +137 -44
- package/types/style.d.ts +125 -92
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +164 -110
- package/ui/Focus.js +25 -14
- package/ui/LoadingScreen.js +1 -1
- package/ui/Parts.js +27 -11
- package/ui/UI.js +20 -10
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +9 -6
- package/ui/touchPart.js +1 -1
- package/core/claims.js +0 -51
- package/core/look/layers.js +0 -136
- package/core/renamed.js +0 -21
- package/docs/api/entities.md +0 -61
- package/docs/recipes/09-style-pack.md +0 -234
- package/examples/styletest/overrides.js +0 -33
- package/examples/styletest/panel.js +0 -135
- package/modules/entities/Entities.js +0 -243
- package/modules/entities/build.js +0 -25
- package/modules/entities/index.js +0 -4
- package/modules/sky/calendar.js +0 -80
- package/modules/sky/layers.js +0 -69
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/world/cells.js +0 -42
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
// Positions are always a single argument (Vector3 / Object3D / [x, y, z] / { x, z }); sizes go in the options object:
|
|
6
6
|
// const h = engine.collision.addBox(house, { halfWidth: 3, halfDepth: 2, rotation: 0.3 }); h.remove();
|
|
7
7
|
import { xzOf } from '../../core/math.js';
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
import { readParams, keysSchema } from '../../core/params.js';
|
|
10
10
|
import { CollisionGrid, gridBlocks } from './grid.js';
|
|
11
|
+
import { codedError } from '../../core/errorHints.js';
|
|
11
12
|
|
|
12
13
|
/** One axis of the slab test: narrows S.t0 / S.t1 to where the ray is inside |o + d t| <= h; false when it misses */
|
|
13
14
|
function slab(S, o, d, h) {
|
|
@@ -17,7 +18,7 @@ function slab(S, o, d, h) {
|
|
|
17
18
|
return S.t0 <= S.t1;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
const BOX_KEYS = ['halfWidth', 'halfDepth', 'rotation', 'height', 'y'], CIRCLE_KEYS = ['radius', 'height'], SEG_KEYS = ['thickness', 'height', 'y'], BLOCK_KEYS = ['bounds'];
|
|
21
|
+
const BOX_KEYS = ['halfWidth', 'halfDepth', 'rotation', 'height', 'y', 'occluder'], CIRCLE_KEYS = ['radius', 'height', 'occluder'], SEG_KEYS = ['thickness', 'height', 'y', 'occluder'], BLOCK_KEYS = ['bounds'];
|
|
21
22
|
|
|
22
23
|
export class Collision {
|
|
23
24
|
/**
|
|
@@ -28,8 +29,10 @@ export class Collision {
|
|
|
28
29
|
constructor(engine, { maxClimb = engine.movement.slopeRatio, canopyHeight = 5, cameraPad = 0.5, cameraMin = 1.5, walkableWaterMargin = 0.2, cameraOcclusion = 'colliders' } = {}) {
|
|
29
30
|
this.engine = engine;
|
|
30
31
|
Object.assign(this, { maxClimb, canopyHeight, cameraPad, cameraMin, walkableWaterMargin, cameraOcclusion });
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
// Sets, not arrays: they keep insertion order (forEachStatic and every consumer see colliders in the order added) and delete in O(1),
|
|
33
|
+
// where an array filter per remove made unloading n colliders O(n^2)
|
|
34
|
+
/** manually added circle colliders {x, z, r, h} @type {Set<any>} */ this.circles = new Set();
|
|
35
|
+
/** rectangles {x, z, hw, hd, rot, h} @type {Set<any>} */ this.boxes = new Set();
|
|
33
36
|
this._grid = new CollisionGrid(); // grid index: resolve / camera look only nearby instead of scanning all (circles / boxes change only via addCircle / addBox)
|
|
34
37
|
this._blocked = []; // addBlocked fields {fn, bounds}; empty = zero cost
|
|
35
38
|
this.blockedVersion = 0; // +1 on addBlocked / remove: async paths re-sample their cached ground rasters
|
|
@@ -41,43 +44,72 @@ export class Collision {
|
|
|
41
44
|
}
|
|
42
45
|
/** Iterate all manually added static colliders (for the physics module): fn('box' | 'circle', data) */
|
|
43
46
|
forEachStatic(fn) { for (const b of this.boxes) fn('box', b); for (const c of this.circles) fn('circle', c); }
|
|
47
|
+
/**
|
|
48
|
+
* Keep an outside copy of the static colliders (boxes and circles) in step, e.g. physics colliders or navmesh obstacles. add(type, data) builds the
|
|
49
|
+
* copy of one collider and returns it; remove(piece, data) drops one. sync() does the work only when `version` moved since the last sync, then adds
|
|
50
|
+
* what is new (in forEachStatic order) and removes what is gone; returns whether anything was compared. clear() forgets every piece without calling
|
|
51
|
+
* remove (the outside world they lived in was thrown away) so the next sync builds all again.
|
|
52
|
+
* Why one shared mirror: nav and rigid each had their own copy of this diff, and the two copies drifted (one checked readiness, the other a version
|
|
53
|
+
* field of its own); a third consumer would copy it a third time.
|
|
54
|
+
* @param {{ add: (type: 'box' | 'circle', data: any) => any, remove: (piece: any, data: any) => void }} fns
|
|
55
|
+
*/
|
|
56
|
+
mirror({ add, remove }) {
|
|
57
|
+
const pieces = new Map(), col = this;
|
|
58
|
+
const seen = new Set();
|
|
59
|
+
let version = -1;
|
|
60
|
+
return {
|
|
61
|
+
sync() {
|
|
62
|
+
if (col.version === version) return false;
|
|
63
|
+
version = col.version; seen.clear();
|
|
64
|
+
col.forEachStatic((type, o) => { seen.add(o); if (!pieces.has(o)) pieces.set(o, add(type, o)); });
|
|
65
|
+
for (const [o, p] of pieces) if (!seen.has(o)) { pieces.delete(o); remove(p, o); }
|
|
66
|
+
seen.clear();
|
|
67
|
+
return true;
|
|
68
|
+
},
|
|
69
|
+
clear() { pieces.clear(); version = -1; },
|
|
70
|
+
get size() { return pieces.size; },
|
|
71
|
+
};
|
|
72
|
+
}
|
|
44
73
|
|
|
45
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* Add a circle collider (pillar, statue, campfire): position is the centre, radius (default 0.5), height (default 6).
|
|
76
|
+
* occluder: false keeps it from pulling the follow camera in (walkers are still stopped), e.g. forest trunks the camera may pass through. Returns a handle { remove() }
|
|
77
|
+
*/
|
|
46
78
|
addCircle(position, opts = {}) {
|
|
47
|
-
|
|
48
|
-
const [x, z] = xzOf(position), c = { x, z, r: opts.radius ?? 0.5, h: opts.height ?? 6 };
|
|
49
|
-
this.circles.
|
|
50
|
-
return { remove: () => { if (!this.circles.
|
|
79
|
+
readParams('collision.addCircle()', keysSchema(CIRCLE_KEYS), opts); if (typeof opts !== 'object') opts = {};
|
|
80
|
+
const [x, z] = xzOf(position), c = { x, z, r: opts.radius ?? 0.5, h: opts.height ?? 6, occ: opts.occluder !== false };
|
|
81
|
+
this.circles.add(c); this._grid.add(c, false); this.version++;
|
|
82
|
+
return { remove: () => { if (!this.circles.delete(c)) return; this._grid.remove(c); this.version++; } };
|
|
51
83
|
}
|
|
52
84
|
/**
|
|
53
85
|
* Add a rectangle collider (house, fence): position is the centre; halfWidth / halfDepth (default 1), rotation about the Y axis (radians),
|
|
54
|
-
* height (default 6), y is the box bottom height (omit to sit on the ground; set it for walls on platforms in levels). Returns a handle { remove() }
|
|
86
|
+
* height (default 6), y is the box bottom height (omit to sit on the ground; set it for walls on platforms in levels); occluder: false as in addCircle. Returns a handle { remove() }
|
|
55
87
|
*/
|
|
56
88
|
addBox(position, opts = {}) {
|
|
57
|
-
|
|
89
|
+
readParams('collision.addBox()', keysSchema(BOX_KEYS), opts); if (typeof opts !== 'object') opts = {};
|
|
58
90
|
const [x, z] = xzOf(position), hw = opts.halfWidth ?? 1, hd = opts.halfDepth ?? 1, rot = opts.rotation ?? 0;
|
|
59
|
-
const b = { x, z, hw, hd, rot, h: opts.height ?? 6, y: opts.y, c: Math.cos(rot), s: Math.sin(rot), r: Math.hypot(hw, hd) };
|
|
60
|
-
this.boxes.
|
|
61
|
-
return { remove: () => { if (!this.boxes.
|
|
91
|
+
const b = { x, z, hw, hd, rot, h: opts.height ?? 6, y: opts.y, c: Math.cos(rot), s: Math.sin(rot), r: Math.hypot(hw, hd), occ: opts.occluder !== false };
|
|
92
|
+
this.boxes.add(b); this._grid.add(b, true); this.version++;
|
|
93
|
+
return { remove: () => { if (!this.boxes.delete(b)) return; this._grid.remove(b); this.version++; } };
|
|
62
94
|
}
|
|
63
95
|
/**
|
|
64
|
-
* Add a thin wall along the line a -> b (fence, wall; positions like addBox). thickness (default 0.3), height (default 6), y as in addBox.
|
|
96
|
+
* Add a thin wall along the line a -> b (fence, wall; positions like addBox). thickness (default 0.3), height (default 6), y and occluder as in addBox.
|
|
65
97
|
* It is a rotated box in the same grid, so a gap between two segments is a gate. Returns a handle { remove() }
|
|
66
98
|
*/
|
|
67
99
|
addSegment(a, b, opts = {}) {
|
|
68
|
-
|
|
100
|
+
readParams('collision.addSegment()', keysSchema(SEG_KEYS), opts); if (typeof opts !== 'object') opts = {};
|
|
69
101
|
const [ax, az] = xzOf(a), [bx, bz] = xzOf(b);
|
|
70
102
|
// box-local +x is (cos r, -sin r) in world, so r = -atan2(dz, dx)
|
|
71
|
-
return this.addBox([(ax + bx) / 2, 0, (az + bz) / 2], { halfWidth: Math.hypot(bx - ax, bz - az) / 2, halfDepth: (opts.thickness ?? 0.3) / 2, rotation: -Math.atan2(bz - az, bx - ax), height: opts.height, y: opts.y });
|
|
103
|
+
return this.addBox([(ax + bx) / 2, 0, (az + bz) / 2], { halfWidth: Math.hypot(bx - ax, bz - az) / 2, halfDepth: (opts.thickness ?? 0.3) / 2, rotation: -Math.atan2(bz - az, bx - ax), height: opts.height, y: opts.y, occluder: opts.occluder });
|
|
72
104
|
}
|
|
73
105
|
/**
|
|
74
106
|
* Mark ground as impassable where fn(x, z) is true (river, lava, cliff edge). Walkers are stopped at its edge (sliding along it) and walkable() says no.
|
|
75
|
-
* fn must be pure and deterministic (no clock, no random). bounds { minX, maxX, minZ, maxZ } skips fn outside it. A bridge: have fn return false over it,
|
|
107
|
+
* fn must be pure and deterministic (no clock, no random). bounds { minX, maxX, minZ, maxZ } (world metres, the field's x / z extent) skips fn outside it. A bridge: have fn return false over it,
|
|
76
108
|
* or keep the water field exact and let fn test `!onBridge(x, z)`. findPathAsync samples fn into its ground raster (1 m cells), so give bounds to keep that cheap. Returns a handle { remove() }
|
|
77
109
|
*/
|
|
78
110
|
addBlocked(fn, opts = {}) {
|
|
79
|
-
|
|
80
|
-
if (typeof fn !== 'function') throw
|
|
111
|
+
readParams('collision.addBlocked()', keysSchema(BLOCK_KEYS), opts); if (typeof opts !== 'object') opts = {};
|
|
112
|
+
if (typeof fn !== 'function') throw codedError('collision-misuse', 'collision.addBlocked(fn): fn(x, z) => boolean is required');
|
|
81
113
|
const f = { fn, bounds: opts.bounds ?? null }; this._blocked.push(f); this.version++; this.blockedVersion++;
|
|
82
114
|
return { remove: () => { if (!this._blocked.includes(f)) return; this._blocked = this._blocked.filter(o => o !== f); this.version++; this.blockedVersion++; } };
|
|
83
115
|
}
|
|
@@ -91,11 +123,11 @@ export class Collision {
|
|
|
91
123
|
}
|
|
92
124
|
return false;
|
|
93
125
|
}
|
|
94
|
-
/** Add collision from a three.js object's bounding box (common for house models), pad grows it outward (m). Returns a handle { remove() } */
|
|
95
|
-
addObject(obj, { pad = 0 } = {}) {
|
|
126
|
+
/** Add collision from a three.js object's bounding box (common for house models), pad grows it outward (m), occluder as in addBox. Returns a handle { remove() } */
|
|
127
|
+
addObject(obj, { pad = 0, occluder = true } = {}) {
|
|
96
128
|
obj.updateMatrixWorld(true);
|
|
97
129
|
const THREE = this.engine.THREE, box = new THREE.Box3().setFromObject(obj), c = box.getCenter(new THREE.Vector3()), s = box.getSize(new THREE.Vector3());
|
|
98
|
-
return this.addBox(c, { halfWidth: s.x / 2 + pad, halfDepth: s.z / 2 + pad, height: s.y });
|
|
130
|
+
return this.addBox(c, { halfWidth: s.x / 2 + pad, halfDepth: s.z / 2 + pad, height: s.y, occluder });
|
|
99
131
|
}
|
|
100
132
|
|
|
101
133
|
// The per-frame walkers below pass state through fields instead of building callbacks: resolve() and cameraDistance() run every step / frame.
|
|
@@ -156,7 +188,7 @@ export class Collision {
|
|
|
156
188
|
}
|
|
157
189
|
/** @internal */
|
|
158
190
|
_lineClear(a, b, opts) {
|
|
159
|
-
|
|
191
|
+
readParams('collision.lineClear()', keysSchema(['radius', 'who']), opts); if (typeof opts !== 'object') opts = {};
|
|
160
192
|
const rad = opts.radius ?? 0;
|
|
161
193
|
const A = this._vec(a), B = this._vec(b), dx = B.x - A.x, dz = B.z - A.z, dy = B.y - A.y;
|
|
162
194
|
const S = this._lineS;
|
|
@@ -257,6 +289,7 @@ export class Collision {
|
|
|
257
289
|
const list = this._grid.query(from.x + sx / 2, from.z + sz / 2, len / 2 + 1);
|
|
258
290
|
for (let i = 0; i < list.length; i++) {
|
|
259
291
|
const it = list[i];
|
|
292
|
+
if (!it.occ) continue; // occluder: false (addCircle / addBox)
|
|
260
293
|
if (it._b) this._camBox(it); else this._camCircle(it.x, it.z, it.r);
|
|
261
294
|
}
|
|
262
295
|
best = S.best;
|
|
@@ -270,5 +303,12 @@ const COLLISION_PARAMS = keysSchema(['maxClimb', 'canopyHeight', 'cameraPad', 'c
|
|
|
270
303
|
/** Collision module: lightweight character walking collision, covers the whole map. Once installed: engine.collision */
|
|
271
304
|
export function collision(opts = {}) {
|
|
272
305
|
readParams('collision', COLLISION_PARAMS, opts);
|
|
273
|
-
|
|
306
|
+
let c = null;
|
|
307
|
+
return { name: 'collision', type: 'world', provides: ['collision'], params: COLLISION_PARAMS, options: opts, label: 'Collision', install(e) { e.i18n.add({ 'zh-CN': { 'module.collision': '碰撞' }, en: { 'module.collision': 'collision' } }); return (c = new Collision(e, opts)); },
|
|
308
|
+
// counts of what blocks walking, and whether the player's own spot is walkable: answers "why can the player not go there" without stepping
|
|
309
|
+
describe(e) {
|
|
310
|
+
const p = e.player?.position;
|
|
311
|
+
return { circles: c.circles.size, boxes: c.boxes.size, fields: c._blocked.length, cameraOcclusion: c.cameraOcclusion,
|
|
312
|
+
...(p ? { atPlayer: { walkable: c.groundWalkable(p.x, p.z), blocked: c.blockedAt(p.x, p.z) } } : {}) };
|
|
313
|
+
} };
|
|
274
314
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Grid index of colliders: register each by bounding circle in the cells it covers; queries look at a few nearby cells instead of scanning all colliders.
|
|
2
2
|
// Results are ordered circles first, then boxes, each in insertion order, exactly the callback order of a linear scan (resolve edits the position in turn, so a different order changes the result).
|
|
3
|
+
// Worker-safe (no imports): the path worker (characters/pathJob.js) rebuilds the same grid from the colliders it mirrors.
|
|
3
4
|
const CELL = 8, MAX_CELLS = 64, KEY = 1048576; // colliders too large (covering > 64 cells) skip the grid and are scanned linearly, so registration cost does not blow up
|
|
4
5
|
const byOrder = (a, b) => a._b - b._b || a._o - b._o;
|
|
5
6
|
|
|
@@ -15,30 +16,31 @@ function take(out, it, x, z, range, st) {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export class CollisionGrid {
|
|
18
|
-
constructor() { this.cells = new Map(); this.big =
|
|
19
|
+
constructor() { this.cells = new Map(); this.big = new Set(); this.seq = 0; this.stamp = 0; this.out = []; }
|
|
19
20
|
/** Register; item needs x, z, r. isBox puts it after circles in the callback order */
|
|
20
21
|
add(item, isBox) {
|
|
21
22
|
item._o = this.seq++; item._b = isBox ? 1 : 0;
|
|
22
23
|
const [x0, x1, z0, z1] = cellRange(item);
|
|
23
|
-
if ((x1 - x0 + 1) * (z1 - z0 + 1) > MAX_CELLS) { this.big.
|
|
24
|
+
if ((x1 - x0 + 1) * (z1 - z0 + 1) > MAX_CELLS) { this.big.add(item); return; }
|
|
24
25
|
for (let i = x0; i <= x1; i++) for (let j = z0; j <= z1; j++) {
|
|
25
26
|
const k = i * KEY + j; let c = this.cells.get(k); if (!c) this.cells.set(k, c = []); c.push(item);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
remove(item) {
|
|
29
|
-
|
|
30
|
+
if (this.big.delete(item)) return;
|
|
30
31
|
const [x0, x1, z0, z1] = cellRange(item);
|
|
31
32
|
for (let i = x0; i <= x1; i++) for (let j = z0; j <= z1; j++) {
|
|
32
33
|
const k = i * KEY + j, c = this.cells.get(k); if (!c) continue;
|
|
33
|
-
|
|
34
|
+
// swap-remove: order inside a cell does not matter (query sorts by insertion order), and splice shifted the rest of a crowded cell every time
|
|
35
|
+
const at = c.indexOf(item); if (at < 0) continue;
|
|
36
|
+
c[at] = c[c.length - 1]; c.pop(); if (!c.length) this.cells.delete(k);
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
/** Colliders intersecting the circle at (x, z) with radius range (exactly filtered, sorted). The returned array is reused by the next query, do not keep it */
|
|
37
40
|
query(x, z, range) {
|
|
38
41
|
const out = this.out; out.length = 0;
|
|
39
42
|
const st = ++this.stamp;
|
|
40
|
-
const
|
|
41
|
-
for (let i = 0; i < big.length; i++) take(out, big[i], x, z, range, st);
|
|
43
|
+
for (const it of this.big) take(out, it, x, z, range, st);
|
|
42
44
|
const x0 = Math.floor((x - range) / CELL), x1 = Math.floor((x + range) / CELL), z0 = Math.floor((z - range) / CELL), z1 = Math.floor((z + range) / CELL);
|
|
43
45
|
for (let i = x0; i <= x1; i++) for (let j = z0; j <= z1; j++) {
|
|
44
46
|
const c = this.cells.get(i * KEY + j);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Content's contribution to thing.explain(): rules read from the thing's template (collide, static, interact), which win over the world record's own.
|
|
2
|
-
|
|
2
|
+
import { orNull } from '../../core/util.js';
|
|
3
3
|
|
|
4
4
|
/** @internal */
|
|
5
5
|
export function contentExplain(e, t, out) {
|
|
6
|
-
const def = t.template ?
|
|
6
|
+
const def = t.template ? orNull(() => e.content.template(t.template)) : null;
|
|
7
7
|
if (!def) return;
|
|
8
8
|
Object.assign(out.rules, {
|
|
9
9
|
blocksMovement: def.collide ?? false, pickable: def.static !== false,
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Field descriptions of content entries: one table per entry shape, in the core/params.js spec format (no second format).
|
|
2
|
+
// Three sources, one result (engine.content.fields(), content-check, the template loader all go through here):
|
|
3
|
+
// 1. placement fields of the engine's files (rules.js PLACEMENT_FIELDS: props, props.template, props.grid, pickups, views)
|
|
4
|
+
// 2. a template's state fields: the default is the value in state (the one place it is written), the type is inferred from it; the template's
|
|
5
|
+
// optional `fields` adds range / values / desc: crop: { state: { stage: 0 }, fields: { stage: { type: 'int', min: 0, max: 4 } } }
|
|
6
|
+
// 3. a game kind's `fields` (rules.js kinds.<name>.fields): the keys of each entry of content/<name>.js
|
|
7
|
+
// Why `default` is refused inside fields: a default written twice (state and fields) drifts; the value in state / the data is the only one.
|
|
8
|
+
// Node-safe (no three): packages/tools/content-check imports this file directly.
|
|
9
|
+
import { PLACEMENT_FIELDS } from './rules.js';
|
|
10
|
+
import { parseSpec, whyBad } from '../../core/params.js';
|
|
11
|
+
import { closest, fmt } from '../../core/validate.js';
|
|
12
|
+
|
|
13
|
+
const STRINGS = {
|
|
14
|
+
noDefault: "{where}: fields.{key} has a default; defaults live only in {home} (one place), fields hold only type, min, max, values, desc",
|
|
15
|
+
notState: "{where}: fields.{key} names no state field{hint}; fields describe the keys of state ({list})",
|
|
16
|
+
stateBad: '{where}: state.{key} = {got} does not fit fields.{key}: {why}',
|
|
17
|
+
unknown: "{where}: unknown field '{key}'{hint}. Fields: {list}",
|
|
18
|
+
bad: '{where}: {key} {why}',
|
|
19
|
+
required: '{where}: {key} is required',
|
|
20
|
+
reserved: "{where}: state.{key} is a world record field of every instance (id, kind, position): rename the state field",
|
|
21
|
+
};
|
|
22
|
+
// state is spread onto the instance record after id / kind / position, so a state field with one of these names silently overwrote it
|
|
23
|
+
const RECORD_KEYS = ['id', 'kind', 'position'];
|
|
24
|
+
const hintOf = (k, list) => { const c = closest(k, list); return c ? ` (did you mean '${c}'?)` : ''; };
|
|
25
|
+
|
|
26
|
+
/** The spec type a value has, so a state default needs no written type ('number' for any number: an int default may still take 2.5) */
|
|
27
|
+
function typeOf(v) {
|
|
28
|
+
if (typeof v === 'boolean') return 'bool';
|
|
29
|
+
if (typeof v === 'number') return 'number';
|
|
30
|
+
if (typeof v === 'string') return 'string';
|
|
31
|
+
if (Array.isArray(v)) return 'array';
|
|
32
|
+
if (v && typeof v === 'object') return 'object';
|
|
33
|
+
return 'any';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Parse a whole table, collecting problems instead of throwing (content-check wants every message, the engine throws the first) */
|
|
37
|
+
function parseAll(where, specs, problems) {
|
|
38
|
+
const out = {};
|
|
39
|
+
for (const [key, spec] of Object.entries(specs)) {
|
|
40
|
+
try { out[key] = parseSpec(where, key, spec, msg => new Error(msg)); } catch (err) { problems.push(err.message); }
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const placementCache = new Map();
|
|
46
|
+
/** Parsed placement fields of an engine entry shape ('props', 'props.template', 'props.grid', 'pickups', 'views'), or null */
|
|
47
|
+
export function placementShape(shape) {
|
|
48
|
+
if (!PLACEMENT_FIELDS[shape]) return null;
|
|
49
|
+
if (!placementCache.has(shape)) placementCache.set(shape, parseAll(`content ${shape}`, PLACEMENT_FIELDS[shape], []));
|
|
50
|
+
return placementCache.get(shape);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A content `fields` table (template or game kind) -> { shape, problems }. With state (a template): every key must be a state key, the type is
|
|
55
|
+
* inferred from the state value when not written, the state value must fit; state keys without an entry get { type: inferred }.
|
|
56
|
+
* @param {string} where e.g. "template 'crop'" or "kind 'recipes'"
|
|
57
|
+
* @param {Record<string, any> | undefined} fields
|
|
58
|
+
* @param {Record<string, any> | null} [state]
|
|
59
|
+
*/
|
|
60
|
+
export function fieldsShape(where, fields, state = null) {
|
|
61
|
+
const problems = [], specs = {}, home = state ? 'state' : 'the data itself (or the code that reads it)';
|
|
62
|
+
const stateKeys = state ? Object.keys(state) : null;
|
|
63
|
+
if (fields !== undefined && (!fields || typeof fields !== 'object' || Array.isArray(fields))) return { shape: {}, problems: [`${where}: fields must be an object { key: 'int?' | { type, min, max, values, desc } }`] };
|
|
64
|
+
for (const [key, spec] of Object.entries(fields || {})) {
|
|
65
|
+
if (stateKeys && !stateKeys.includes(key)) { problems.push(fmt(STRINGS.notState, { where, key, hint: hintOf(key, stateKeys), list: stateKeys.join(', ') || 'none' })); continue; }
|
|
66
|
+
if (spec && typeof spec === 'object' && 'default' in spec) { problems.push(fmt(STRINGS.noDefault, { where, key, home })); continue; }
|
|
67
|
+
// a template may leave the type out ({ min: 0, max: 4 }): it is the state value's type
|
|
68
|
+
specs[key] = state && spec && typeof spec === 'object' && !('type' in spec) ? { type: typeOf(state[key]), ...spec } : spec;
|
|
69
|
+
}
|
|
70
|
+
for (const key of stateKeys || []) if (RECORD_KEYS.includes(key)) problems.push(fmt(STRINGS.reserved, { where, key }));
|
|
71
|
+
for (const key of stateKeys || []) specs[key] ??= { type: typeOf(state[key]), optional: true };
|
|
72
|
+
const shape = parseAll(where, specs, problems);
|
|
73
|
+
for (const key of stateKeys || []) {
|
|
74
|
+
if (!shape[key]) continue;
|
|
75
|
+
shape[key].optional = true; // a placement may leave any state field out: the state value fills it
|
|
76
|
+
const why = whyBad(shape[key], state[key]);
|
|
77
|
+
if (why) problems.push(fmt(STRINGS.stateBad, { where, key, got: JSON.stringify(state[key]), why }));
|
|
78
|
+
}
|
|
79
|
+
return { shape, problems };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Problems of one entry against a parsed shape: unknown keys (with the closest name), values of the wrong type, out of range or not in values,
|
|
84
|
+
* and (required: true) missing non-optional keys. Returns messages; an empty list = fine.
|
|
85
|
+
* @param {string} where e.g. 'prop #3'
|
|
86
|
+
* @param {Record<string, any>} entry
|
|
87
|
+
* @param {Record<string, any>} shape
|
|
88
|
+
* @param {{ required?: boolean, also?: Record<string, any> }} [opts] also: more parsed fields allowed on this entry (a template's state fields)
|
|
89
|
+
*/
|
|
90
|
+
export function entryProblems(where, entry, shape, { required = false, also = null } = {}) {
|
|
91
|
+
const all = also ? { ...shape, ...also } : shape, keys = Object.keys(all), out = [];
|
|
92
|
+
if (!entry || typeof entry !== 'object') return out;
|
|
93
|
+
for (const [key, v] of Object.entries(entry)) {
|
|
94
|
+
const s = all[key];
|
|
95
|
+
if (!s) { out.push(fmt(STRINGS.unknown, { where, key, hint: hintOf(key, keys), list: keys.join(', ') })); continue; }
|
|
96
|
+
if (v === undefined) continue;
|
|
97
|
+
const why = whyBad(s, v);
|
|
98
|
+
if (why) out.push(fmt(STRINGS.bad, { where, key, why }));
|
|
99
|
+
}
|
|
100
|
+
if (required) for (const key of keys) if (!all[key].optional && entry[key] === undefined) out.push(fmt(STRINGS.required, { where, key }));
|
|
101
|
+
return out;
|
|
102
|
+
}
|
package/modules/content/ids.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// Two entries with the same id in one load are an error with the fix. Source lines ("defined in content/props.js:14") come from the dev-only
|
|
9
9
|
// line tables of packages/tools/vite/vite-threedog-content-src.js (srcOf); a release build has none.
|
|
10
10
|
import { DEV, warnOnce, fmt } from '../../core/validate.js';
|
|
11
|
+
import { codedError } from '../../core/errorHints.js';
|
|
11
12
|
|
|
12
13
|
const STRINGS = {
|
|
13
14
|
badId: 'content: id "{id}" ({what}) may not contain "#" or "/": "#" is for records made during play and "/" for level-model nodes. Write it with - _ . or :, e.g. "{fix}"',
|
|
@@ -32,8 +33,9 @@ const tableOf = v => (DEV && v && typeof v === 'object' && globalThis.__threedog
|
|
|
32
33
|
* @internal
|
|
33
34
|
*/
|
|
34
35
|
export function srcOf(container, key) {
|
|
35
|
-
const t = tableOf(container);
|
|
36
|
-
return
|
|
36
|
+
const t = tableOf(container), a = t?.at[key];
|
|
37
|
+
if (typeof a === 'string') return a; // a kind joined from several files (parts.js): each entry names its own file
|
|
38
|
+
return t ? `${t.file}:${a ?? t.line}` : null;
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
/** Per content.load: catches duplicate ids across props, pickups, NPCs, containers and grid items, and collects stateful entries without an id @internal */
|
|
@@ -41,9 +43,9 @@ export class IdCheck {
|
|
|
41
43
|
constructor() { this.seen = new Map(); this.missing = []; }
|
|
42
44
|
/** An authored id: format check, and an error if this load already used it @param {string} id @param {string} what e.g. "props[3] (template chest)" */
|
|
43
45
|
claim(id, what) {
|
|
44
|
-
if (typeof id === 'string' && /[#/]/.test(id)) throw
|
|
46
|
+
if (typeof id === 'string' && /[#/]/.test(id)) throw codedError('content-id', fmt(STRINGS.badId, { id, what, fix: id.replace(/[#/]/g, '-') }));
|
|
45
47
|
const a = this.seen.get(id);
|
|
46
|
-
if (a) throw
|
|
48
|
+
if (a) throw codedError('content-id', fmt(STRINGS.dup, { id, a, b: what }));
|
|
47
49
|
this.seen.set(id, what);
|
|
48
50
|
}
|
|
49
51
|
/** A stateful entry relies on its index id */
|
|
@@ -65,8 +67,8 @@ export class IdCheck {
|
|
|
65
67
|
*/
|
|
66
68
|
export function applyRenames(e, map) {
|
|
67
69
|
for (const [a, b] of Object.entries(map || {})) {
|
|
68
|
-
if (b !== null && typeof b !== 'string') throw
|
|
69
|
-
if (typeof b === 'string' && b.includes('#')) throw
|
|
70
|
+
if (b !== null && typeof b !== 'string') throw codedError('content-id', fmt(RENAME_STRINGS.shape, { id: a, got: JSON.stringify(b) }));
|
|
71
|
+
if (typeof b === 'string' && b.includes('#')) throw codedError('content-id', fmt(RENAME_STRINGS.badTarget, { a, b }));
|
|
70
72
|
}
|
|
71
73
|
const stuck = e.world?.renameIds(map) ?? [];
|
|
72
74
|
e.inventory?.renameIds(map);
|
package/modules/content/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
// Content loader:
|
|
2
|
-
// zones, props).
|
|
1
|
+
// Content loader: game data files into the engine.
|
|
2
|
+
// It hands the plain data in content/*.js to the modules (items, pickups, vegetation, NPCs, dialogues, quests, key actions, trigger zones, props).
|
|
3
3
|
// engine.use(content());
|
|
4
|
-
// engine.assets.manifest(
|
|
4
|
+
// engine.assets.manifest(yourAssets); // models content names (an asset pack; content never holds paths or code)
|
|
5
5
|
// engine.content.load(data, { places: { home: { x, z } } }); // or several packs at once: load([base, dlc, level]) (packs.js)
|
|
6
6
|
// Condition/effect vocabulary is in rules.js. Games add condition words (content/rules.js, or content.condition(name, { test }) in code);
|
|
7
7
|
// a game's own actions are ops, called from content with { op: ['noun.verb', args] } and tested with { can: [...] }.
|
|
8
8
|
// Op names used in content are checked when the game becomes ready (did you mean...).
|
|
9
|
-
// Templates (content/templates.js): reusable objects placed from props.js ({ template, x, z }) or engine.spawn; see templates.js.
|
|
9
|
+
// Templates (content/templates.js): reusable objects placed from props.js ({ template, x, z }) or engine.content.spawn; see templates.js.
|
|
10
10
|
// Props (content/props.js) and pickups (pickups.js) are stored in engine.world (requires world(); openWorld() includes it; see props.js for the stable id
|
|
11
11
|
// rule),
|
|
12
12
|
// models and collision are built only near the focus; move / remove with engine.world.move / remove, saved with the save. Procedural models of vegetation and
|
|
13
|
-
// props go through
|
|
13
|
+
// props go through core/namedModel.js protoOf (name = model name; the same path pickups and vegetation use):
|
|
14
14
|
// baked files from npm run bake are read from file, otherwise cached automatically in dev. Models arrive asynchronously: the loading screen of start() waits
|
|
15
15
|
// for them (isReady) before the game counts as ready.
|
|
16
16
|
// Repeated load: a quest's startOn and a trigger's enter/exit effects do not attach listeners twice (the later load overrides the same name).
|
|
@@ -28,6 +28,10 @@ import { templateOf, spawnTemplate, placeTemplate } from './templates.js';
|
|
|
28
28
|
import { packsOf } from './packs.js';
|
|
29
29
|
import { placeY } from '../../core/ground.js';
|
|
30
30
|
import { IdCheck } from './ids.js';
|
|
31
|
+
import { PLACEMENT_FIELDS } from './rules.js';
|
|
32
|
+
import { placementShape, fieldsShape } from './fields.js';
|
|
33
|
+
import { schemaInfo } from '../../core/params.js';
|
|
34
|
+
import { codedError } from '../../core/errorHints.js';
|
|
31
35
|
|
|
32
36
|
export function content() {
|
|
33
37
|
let e = null, places = {};
|
|
@@ -35,21 +39,35 @@ export function content() {
|
|
|
35
39
|
const pending = new Set();
|
|
36
40
|
const st = {
|
|
37
41
|
triggers: {}, subs: null, startOn: new Map(), ops: new Set(), kinds: {},
|
|
42
|
+
marks: new Map(), // marker id -> [position, label]: what the marker effect shows (the content save part)
|
|
38
43
|
templates: new Map(), templateViews: new Set(), // template name -> frozen definition; names whose presenter is registered
|
|
44
|
+
templateSims: new Set(), // names whose world.simulate (stages / update) is registered
|
|
39
45
|
templateSrc: new Map(), // dev: template name -> 'content/templates.js:12'
|
|
46
|
+
templateFields: new Map(), // template name -> parsed state fields (fields.js), for placement checks and content.fields()
|
|
40
47
|
levelPlace: name => !!name && !(name in places) && !!e.level?.marker(name),
|
|
41
48
|
wait: p => { pending.add(p); p.catch(err => reportError(e, err, 'content model', { soft: true })).finally(() => pending.delete(p)); },
|
|
42
49
|
};
|
|
43
50
|
const conds = new Map(Object.entries(CONDITIONS).map(([k, d]) => [k, { ...d, test: BUILTIN_TESTS[k] }]));
|
|
44
51
|
const effects = new Map(Object.entries(EFFECTS).map(([k, d]) => [k, { ...d, run: BUILTIN_RUNS[k] }]));
|
|
45
52
|
// convert content notation to runtime values by ref (clock time -> fraction, place -> { x, z })
|
|
46
|
-
const norm = (ref, v) => ref === 'clock' ? parseClock(v, e.
|
|
53
|
+
const norm = (ref, v) => ref === 'clock' ? parseClock(v, e.calendar?.hoursPerDay ?? 24) : ref === 'position' ? api.where(typeof v === 'string' ? { place: v } : v) : v;
|
|
47
54
|
|
|
48
55
|
const api = {
|
|
49
56
|
/** All vegetation models are ready and the models of nearby world data such as props are built (world.ready) */
|
|
50
57
|
get ready() { return pending.size === 0 && (!e.world || e.world.ready); },
|
|
51
58
|
/** marker markers added by the marker effect: id -> hud marker */
|
|
52
59
|
markers: new Map(),
|
|
60
|
+
/**
|
|
61
|
+
* @internal the marker / clearMarker effects: set (v = position) or clear (v = null) marker id. What is shown is playthrough state, kept in
|
|
62
|
+
* the 'content' save part, so a load shows the save's markers and a new game none of the old ones (review 0.4 modules-a B5)
|
|
63
|
+
*/
|
|
64
|
+
_mark(id, v, label) {
|
|
65
|
+
api.markers.get(id)?.remove(); api.markers.delete(id); st.marks.delete(id);
|
|
66
|
+
if (!v) return;
|
|
67
|
+
st.marks.set(id, [v, label ?? null]);
|
|
68
|
+
const m = e.hud?.marker(v, { label });
|
|
69
|
+
if (m) api.markers.set(id, m);
|
|
70
|
+
},
|
|
53
71
|
/**
|
|
54
72
|
* Load content data: one pack (the object of content/index.js) or a list of packs loaded together in order, where an id defined by two packs is an error
|
|
55
73
|
* (packs.js).
|
|
@@ -68,24 +86,37 @@ export function content() {
|
|
|
68
86
|
},
|
|
69
87
|
/** Register a condition word: condition('timeAfter', { ref: 'clock', desc, test: (e, value) => ... }) */
|
|
70
88
|
condition(name, def) { conds.set(name, def); return api; },
|
|
71
|
-
/**
|
|
72
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Whether a condition holds (object = all listed items hold, array = every item holds, function = called directly as fn(e, { actor })).
|
|
91
|
+
* actor: whose bag { has } / { lacks } look in (default: the running op's actor, else engine.actor), so a net peer's dialogue checks the peer's bag.
|
|
92
|
+
* @example engine.content.test({ has: { berry: 3 } }, { actor: 'peer-2' })
|
|
93
|
+
* @param {any} c
|
|
94
|
+
* @param {{ actor?: string }} [opts]
|
|
95
|
+
*/
|
|
96
|
+
test(c, { actor = e.ops.actor } = {}) {
|
|
73
97
|
if (!c) return true;
|
|
74
|
-
|
|
98
|
+
const ctx = { actor };
|
|
99
|
+
if (typeof c === 'function') return !!c(e, ctx);
|
|
75
100
|
return list(c).every(x => Object.entries(x).every(([k, v]) => {
|
|
76
101
|
const d = conds.get(k);
|
|
77
102
|
if (!d) { warnMissing('condition', k, [...conds.keys()]); return false; }
|
|
78
|
-
return !!d.test(e, norm(d.ref, v), v);
|
|
103
|
+
return !!d.test(e, norm(d.ref, v), v, ctx);
|
|
79
104
|
}));
|
|
80
105
|
},
|
|
81
|
-
/**
|
|
82
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Run an effect (object, array or function fn(e, { actor })). actor: whose bag { give } / { take } change (default: the running op's actor, else
|
|
108
|
+
* engine.actor), so a reward lands in the bag of whoever earned it.
|
|
109
|
+
* @param {any} a
|
|
110
|
+
* @param {{ actor?: string }} [opts]
|
|
111
|
+
*/
|
|
112
|
+
run(a, { actor = e.ops.actor } = {}) {
|
|
83
113
|
if (!a) return;
|
|
84
|
-
|
|
114
|
+
const ctx = { actor };
|
|
115
|
+
if (typeof a === 'function') return a(e, ctx);
|
|
85
116
|
for (const x of list(a)) for (const [k, v] of Object.entries(x)) {
|
|
86
117
|
const d = effects.get(k);
|
|
87
118
|
if (!d) { warnMissing('effect', k, [...effects.keys()]); continue; }
|
|
88
|
-
d.run(e, norm(d.ref, v), v);
|
|
119
|
+
d.run(e, norm(d.ref, v), v, ctx);
|
|
89
120
|
}
|
|
90
121
|
},
|
|
91
122
|
/**
|
|
@@ -95,11 +126,52 @@ export function content() {
|
|
|
95
126
|
* @returns {Readonly<Record<string, any>>}
|
|
96
127
|
*/
|
|
97
128
|
template(name) { return templateOf(st, name); },
|
|
129
|
+
/**
|
|
130
|
+
* Place a new instance of a content template at runtime (a gameplay change: call it inside an op or a fixed step); saved whole.
|
|
131
|
+
* Returns the world record (kind = template name; without fields.id the id is numbered `<template>#<n>`, e.g. 'chest#3').
|
|
132
|
+
* at is a ground position ({ x, z }, [x, y, z] or an object); fields may set id, rot, scale, y (height above ground), items (container start goods)
|
|
133
|
+
* and the template's state fields (stage too, for a template with stages).
|
|
134
|
+
* @example engine.ops.define('chest.build', { run: (e, { x, z }) => e.content.spawn('chest', { x, z }, { items: { stick: 3 } }).id });
|
|
135
|
+
* @param {string} name
|
|
136
|
+
* @param {any} at
|
|
137
|
+
* @param {{ id?: string, rot?: number, scale?: number, y?: number, items?: Record<string, number>, [state: string]: any }} [fields]
|
|
138
|
+
* @returns {import('../world/World.js').WorldRecord}
|
|
139
|
+
*/
|
|
140
|
+
spawn(name, at, fields) { return spawnTemplate(e, st, name, at, fields); },
|
|
98
141
|
/**
|
|
99
142
|
* @internal A level-model node with the custom property template: an authored instance with id `<level>/<node>` (level module).
|
|
100
143
|
* entry is a props-style entry ({ template, id, x, z, floor, rot, scale, state fields }); origin = { level, node }
|
|
101
144
|
*/
|
|
102
145
|
placeNode(entry, zone, origin) { placeTemplate(e, api, st, entry, 0, zone, null, origin); },
|
|
146
|
+
/**
|
|
147
|
+
* The fields one content entry may have, in the core/params.js format ({ key: { type, optional?, default?, min?, max?, values?, desc? } }):
|
|
148
|
+
* what an editor panel lists and what content-check validates against (one table, rules.js PLACEMENT_FIELDS + the template / kind `fields`).
|
|
149
|
+
* name: a template name (its placement fields plus its state fields; default = the value in state), an engine entry shape
|
|
150
|
+
* ('props', 'props.template', 'props.grid', 'pickups', 'views'), a game kind with fields (content/rules.js kinds), or a world record id
|
|
151
|
+
* (answers for the shape that record came from).
|
|
152
|
+
* @example engine.content.fields('crop').stage // { type: 'int', optional: true, default: 0, min: 0, max: 4 }
|
|
153
|
+
* @example engine.content.fields('props').rot // { type: 'number', optional: true, desc: 'facing around the vertical axis, radians' }
|
|
154
|
+
* @param {string} name
|
|
155
|
+
* @returns {Record<string, { type: string, optional?: boolean, default?: any, min?: number, max?: number, values?: any[], desc?: string }>}
|
|
156
|
+
*/
|
|
157
|
+
fields(name) {
|
|
158
|
+
if (st.templates.has(name)) {
|
|
159
|
+
const state = st.templates.get(name).state ?? {}, own = schemaInfo(st.templateFields.get(name));
|
|
160
|
+
for (const k in own) own[k].default = structuredClone(state[k]); // the default is the state value: written once, in state
|
|
161
|
+
return { ...schemaInfo(placementShape('props.template')), ...own };
|
|
162
|
+
}
|
|
163
|
+
if (PLACEMENT_FIELDS[name]) return schemaInfo(placementShape(name));
|
|
164
|
+
const kind = st.kinds[name];
|
|
165
|
+
if (kind?.fields) {
|
|
166
|
+
const { shape, problems } = fieldsShape(`kind '${name}'`, kind.fields);
|
|
167
|
+
if (problems.length) throw codedError('content-misuse', problems.join('; '));
|
|
168
|
+
return schemaInfo(shape);
|
|
169
|
+
}
|
|
170
|
+
const rec = e.world?.get(name);
|
|
171
|
+
if (rec) return api.fields(rec.kind === 'prop' ? 'props' : rec.kind === 'pickup' ? 'pickups' : rec.kind);
|
|
172
|
+
const known = [...st.templates.keys(), ...Object.keys(PLACEMENT_FIELDS), ...Object.keys(st.kinds).filter(k => st.kinds[k]?.fields)];
|
|
173
|
+
throw codedError('unknown-name', `content.fields: ${missingText('field table', name, known)} (a template name, ${Object.keys(PLACEMENT_FIELDS).join(' / ')}, a game kind with fields, or a world record id)`);
|
|
174
|
+
},
|
|
103
175
|
/** @internal dev: where a template is defined ('content/templates.js:12'), null if unknown */
|
|
104
176
|
templateSource(name) { return st.templateSrc.get(name) ?? null; },
|
|
105
177
|
/** Place name -> position { x, z } plus y when the place has a height (level markers, places given with y); null if not found */
|
|
@@ -116,7 +188,7 @@ export function content() {
|
|
|
116
188
|
*/
|
|
117
189
|
where(p) {
|
|
118
190
|
const base = p.place ? api.place(p.place) : null;
|
|
119
|
-
if (p.place && !base) throw
|
|
191
|
+
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`);
|
|
120
192
|
const x = (base?.x ?? 0) + (p.x ?? 0), z = (base?.z ?? 0) + (p.z ?? 0), floor = p.floor ?? base?.y;
|
|
121
193
|
if (floor === undefined && p.y === undefined) return { x, z };
|
|
122
194
|
return { x, y: placeY(e, `content.where(${JSON.stringify(p.place ?? { x: p.x, z: p.z })})`, x, z, floor) + (p.y ?? 0), z };
|
|
@@ -125,24 +197,21 @@ export function content() {
|
|
|
125
197
|
_floorOf(p) { return p.floor ?? (p.place ? api.place(p.place)?.y : undefined); },
|
|
126
198
|
};
|
|
127
199
|
return {
|
|
128
|
-
name: 'content', label: 'Content',
|
|
129
|
-
optional: ['level', '
|
|
130
|
-
install(engine) {
|
|
200
|
+
name: 'content', type: 'rules', label: 'Content',
|
|
201
|
+
optional: ['level', 'calendar', 'inventory', 'pickups', 'quests', 'particles', 'hud', 'vegetation', 'dialogue', 'triggers', 'collision', 'world', 'interactions', 'grids', 'rigid'],
|
|
202
|
+
install(engine, ctx) { engine.i18n.add({ 'zh-CN': { 'module.content': '内容' }, en: { 'module.content': 'content' } });
|
|
131
203
|
e = engine;
|
|
204
|
+
st.track = ctx.track; // loader.js subscribes on the first content.load: those listeners belong to the module too
|
|
132
205
|
engine.explainWith(contentExplain);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
* Installed by content(), so it exists once the content module is used.
|
|
138
|
-
* @example engine.ops.define('chest.build', { run: (e, { x, z }) => e.spawn('chest', { x, z }, { items: { stick: 3 } }).id });
|
|
139
|
-
*/
|
|
140
|
-
e.spawn = (name, at, fields) => spawnTemplate(e, st, name, at, fields);
|
|
206
|
+
e.saves.register('content', {
|
|
207
|
+
save: () => ({ marks: [...st.marks].map(([id, [v, label]]) => [id, v, label]) }),
|
|
208
|
+
load: d => { for (const id of [...st.marks.keys()]) api._mark(id, null); for (const [id, v, label] of d?.marks || []) api._mark(id, v, label ?? undefined); },
|
|
209
|
+
});
|
|
141
210
|
// content may name ops that main.js defines after load: check once everything is set up, and again for loads after that
|
|
142
211
|
const check = () => {
|
|
143
|
-
for (const name of st.ops) if (!e.ops.defs.has(name)) throw
|
|
212
|
+
for (const name of st.ops) if (!e.ops.defs.has(name)) throw codedError('unknown-name', `content: ${missingText('op', name, [...e.ops.defs.keys()])} (used in { op } / { can })`);
|
|
144
213
|
};
|
|
145
|
-
e.events.on('engine:ready', check);
|
|
214
|
+
ctx.track(e.events.on('engine:ready', check));
|
|
146
215
|
st.checkOps = () => { if (e.ready) check(); };
|
|
147
216
|
return api;
|
|
148
217
|
},
|