threedog 0.8.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 +219 -4
- package/README.md +6 -6
- package/core/assets/Animator.js +2 -0
- package/core/assets/Assets.js +44 -13
- package/core/assets/assetEntry.js +87 -22
- package/core/assets/assetHot.js +2 -1
- package/core/assets/assetReport.js +1 -2
- package/core/audio/Audio.js +24 -5
- package/core/base/I18n.js +6 -3
- package/core/base/Random.js +3 -1
- package/core/base/Vars.js +14 -4
- package/core/base/errorCodes.js +54 -16
- package/core/base/errorHints.js +12 -1
- package/core/base/errors.js +6 -4
- package/core/base/events.generated.js +10 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +15 -8
- package/core/base/params.js +2 -2
- package/core/{saves → base}/saveValues.js +24 -6
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/validate.js +8 -29
- package/core/engine/Engine.js +61 -18
- package/core/engine/Loading.js +30 -3
- package/core/engine/copies.js +1 -1
- package/core/engine/headlessLoad.js +30 -13
- package/core/engine/lifecycle.js +30 -25
- package/core/engine/loop.js +22 -4
- package/core/engine/moduleSlots.js +91 -15
- package/core/engine/moduleTypes.js +13 -0
- package/core/engine/modules.js +248 -62
- package/core/engine/page.js +25 -8
- package/core/engine/plugins.js +15 -3
- package/core/engine/services.js +3 -0
- package/core/engine/startup.js +46 -36
- package/core/input/Input.js +39 -19
- package/core/input/inputKeyboard.js +39 -0
- package/core/input/inputPad.js +23 -2
- package/core/input/inputPointer.js +3 -1
- package/core/input/inputSeat.js +66 -0
- package/core/input/inputTouch.js +23 -6
- package/core/inspect/DebugOverrides.js +13 -2
- package/core/inspect/Describe.js +10 -6
- package/core/inspect/Inspect.js +31 -4
- package/core/inspect/UrlState.js +14 -10
- package/core/inspect/catalog.js +12 -5
- package/core/inspect/describeRender.js +3 -2
- package/core/inspect/describeText.js +6 -2
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/inspect/pictureWriters.js +117 -33
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/ops/Ops.js +32 -7
- package/core/ops/control.js +48 -23
- package/core/ops/holds.js +4 -3
- package/core/ops/opsAtomic.js +18 -6
- package/core/ops/opsCheck.js +7 -5
- package/core/ops/opsFail.js +5 -7
- package/core/ops/opsRun.js +2 -2
- package/core/ops/owned.js +20 -3
- package/core/ops/sharedPoint.js +7 -10
- package/core/ops/stacks.js +22 -1
- package/core/saves/SaveStore.js +52 -26
- package/core/saves/Saves.js +122 -27
- package/core/saves/saveApply.js +159 -61
- package/core/saves/saveFiles.js +30 -25
- package/core/saves/saveVersions.js +20 -6
- package/core/saves/session.js +76 -33
- package/core/saves/stateReplace.js +184 -0
- package/core/scene/Rays.js +21 -5
- package/core/scene/Views.js +6 -6
- package/core/scene/adaptive.js +13 -10
- package/core/scene/canvasBox.js +2 -0
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/scene/grid.js +2 -0
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +52 -17
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/scene/sceneDelta.js +3 -3
- package/core/scene/sceneMethods.js +11 -6
- package/core/scene/stepPoses.js +6 -1
- package/core/scene/thingExplain.js +1 -1
- package/core/scene/thingOps.js +22 -14
- package/core/scene/things.js +1 -1
- package/core/scene/tier.js +10 -0
- package/core/scene/view.js +126 -9
- package/core/stream/Batching.js +0 -1
- package/core/stream/Stream.js +24 -12
- package/core/stream/batchGroups.js +1 -0
- package/core/stream/scatter.js +5 -2
- package/core/stream/streamSources.js +2 -1
- package/core/threads/Commits.js +12 -7
- package/core/threads/Jobs.js +15 -5
- package/core/threads/Threads.js +5 -2
- package/core/time/Clock.js +3 -1
- package/core/time/skip.js +10 -4
- package/core/time/time.js +16 -10
- package/docs/AI.md +89 -72
- package/docs/API.md +18 -14
- package/docs/CODEMAP.md +68 -40
- package/docs/COMMANDS.md +22 -23
- package/docs/CONVENTIONS.md +120 -17
- package/docs/MIGRATING-0.8.md +2 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +65 -12
- package/docs/api/cameraRig.md +3 -0
- package/docs/api/characters.md +13 -7
- package/docs/api/collider3d.md +9 -0
- package/docs/api/content.md +16 -15
- package/docs/api/dialogue.md +2 -1
- package/docs/api/engine.md +18 -16
- package/docs/api/events.md +14 -4
- package/docs/api/ground.md +2 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +2 -1
- package/docs/api/interactions.md +1 -1
- package/docs/api/inventory.md +1 -1
- package/docs/api/level.md +3 -2
- package/docs/api/nav.md +4 -2
- package/docs/api/particles.md +8 -5
- package/docs/api/pickups.md +1 -1
- package/docs/api/post.md +3 -4
- package/docs/api/quests.md +4 -2
- package/docs/api/rays.md +2 -0
- package/docs/api/rigid.md +3 -2
- package/docs/api/saves.md +8 -7
- package/docs/api/stream.md +4 -5
- package/docs/api/terrain.md +3 -4
- package/docs/api/terrainDraw.md +1 -1
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +3 -1
- package/docs/api/triggers.md +2 -0
- package/docs/api/vegetationDraw.md +1 -1
- package/docs/api/water.md +6 -2
- package/docs/api/weather.md +19 -4
- package/docs/api/weatherDraw.md +1 -1
- package/docs/api/world.md +1 -1
- package/docs/recipes/01-new-game.md +3 -3
- package/docs/recipes/02-npc.md +3 -4
- package/docs/recipes/03-items-pickups.md +11 -11
- package/docs/recipes/04-quests.md +2 -0
- package/docs/recipes/05-props-bake.md +9 -9
- package/docs/recipes/06-clock-events.md +6 -6
- package/docs/recipes/07-flow-scenes-pause.md +18 -15
- package/docs/recipes/08-weather-sky.md +5 -5
- package/docs/recipes/09-materials-lights-models.md +3 -3
- package/docs/recipes/10-blender-level.md +16 -4
- package/docs/recipes/11-vehicles.md +18 -6
- package/docs/recipes/12-navmesh.md +52 -8
- package/docs/recipes/13-animation.md +34 -8
- package/docs/recipes/14-custom-module.md +20 -8
- package/docs/recipes/15-perf.md +4 -4
- package/docs/recipes/16-dev-bridge.md +9 -8
- package/docs/recipes/18-world.md +13 -5
- package/docs/recipes/19-shooting-picking.md +3 -2
- package/docs/recipes/20-content-actions-save.md +26 -6
- package/docs/recipes/21-camera.md +17 -23
- package/docs/recipes/22-shop-gold.md +21 -12
- package/docs/recipes/23-ops.md +19 -15
- package/docs/recipes/26-ui-parts.md +3 -2
- package/docs/recipes/27-net.md +3 -3
- package/docs/recipes/28-terrain.md +3 -3
- package/docs/recipes/29-grid.md +1 -1
- package/docs/recipes/30-templates.md +10 -13
- package/docs/recipes/31-audio.md +2 -2
- package/docs/recipes/32-action-game.md +6 -5
- package/docs/recipes/33-stream-sources.md +4 -1
- package/docs/recipes/34-environment-lighting.md +7 -8
- package/docs/recipes/35-picture-from-reference.md +13 -9
- package/docs/recipes/36-ground-plants.md +3 -2
- package/docs/recipes/40-scene.md +11 -10
- package/docs/recipes/43-shader-patches-surfaces.md +7 -7
- package/docs/recipes/44-water-weather-hooks.md +9 -8
- package/docs/recipes/45-cascaded-shadows.md +3 -4
- package/docs/recipes/46-blender-art-route.md +3 -3
- package/docs/recipes/49-game-module-contract.md +2 -1
- package/docs/recipes/50-own-renderer.md +1 -0
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +4 -4
- package/docs/recipes/55-mods-time-wrap.md +5 -4
- package/docs/recipes/56-webgpu-tsl.md +12 -1
- package/docs/recipes/57-control.md +30 -10
- package/docs/recipes/58-input.md +13 -0
- package/docs/recipes/60-judge-the-picture.md +1 -1
- package/docs/recipes/62-picture-code.md +106 -48
- package/docs/recipes/63-third-person-start.md +2 -1
- package/docs/recipes/64-particles.md +53 -4
- package/docs/recipes/65-swarm.md +2 -2
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +3 -3
- package/examples/perf-island/.threedog/content-index.json +1 -1
- package/examples/perf-island/GAMEMAP.md +3 -3
- package/examples/perf-island/main.js +2 -2
- package/examples/plain-picture/GAMEMAP.md +3 -1
- package/examples/rc2d/GAMEMAP.md +1 -1
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +3 -3
- package/examples/webgpu-tsl/GAMEMAP.md +1 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +5 -4
- package/examples/world/main.js +3 -3
- package/index.d.ts +8 -5
- package/index.js +22 -1
- package/llms.txt +2 -1
- package/modules/ambience/Ambience.js +5 -3
- package/modules/calendar/index.js +7 -5
- package/modules/camera/FirstPersonCamera.js +3 -3
- package/modules/camera/FixedCamera.js +34 -20
- package/modules/camera/FollowCamera.js +20 -11
- package/modules/camera/RtsCamera.js +1 -0
- package/modules/camera/common.js +33 -22
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +136 -43
- package/modules/characters/NPC.js +60 -28
- package/modules/characters/assetModel.js +2 -2
- package/modules/characters/astar.js +47 -28
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +94 -34
- package/modules/characters/moveHelpers.js +80 -15
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +6 -4
- package/modules/characters/movers/rapier.js +12 -5
- package/modules/characters/movers/simple.js +25 -12
- package/modules/characters/movers/support.js +18 -7
- package/modules/characters/npcAvoid.js +15 -12
- package/modules/characters/npcSim.js +75 -25
- package/modules/characters/npcView.js +13 -6
- package/modules/characters/pathAsync.js +74 -24
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/player.js +59 -47
- package/modules/characters/seat.js +56 -0
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +31 -18
- package/modules/collision/Collision.js +44 -26
- package/modules/collision/contract.js +2 -2
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +1 -1
- package/modules/content/fields.js +3 -3
- package/modules/content/ids.js +3 -1
- package/modules/content/index.js +83 -27
- package/modules/content/loader.js +110 -130
- package/modules/content/markers.js +1 -1
- package/modules/content/models.js +48 -14
- package/modules/content/packs.js +2 -1
- package/modules/content/places.js +5 -4
- package/modules/content/props.js +8 -6
- package/modules/content/rules.js +29 -47
- package/modules/content/templates.js +66 -35
- package/modules/content/words.js +19 -6
- package/modules/debug/DebugPanel.js +4 -2
- package/modules/flow/contract.js +1 -0
- package/modules/flow/index.js +24 -14
- package/modules/gameplay/Container.js +5 -2
- package/modules/gameplay/Containers.js +9 -1
- package/modules/gameplay/Dialogue.js +82 -25
- package/modules/gameplay/Interactions.js +61 -32
- package/modules/gameplay/Inventory.js +56 -13
- package/modules/gameplay/Quests.js +133 -24
- package/modules/gameplay/boxOps.js +7 -0
- package/modules/gameplay/dialogueBubbles.js +14 -9
- package/modules/gameplay/inventoryOps.js +11 -7
- package/modules/gameplay/pickups.js +43 -16
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +6 -1
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +8 -4
- package/modules/grid/index.js +21 -15
- package/modules/grid/ops.js +43 -46
- package/modules/grid/tiles.js +1 -1
- package/modules/hlod/index.js +6 -3
- package/modules/hud/index.js +6 -4
- package/modules/hud/parts.js +4 -4
- package/modules/level/contract.js +2 -2
- package/modules/level/heightfield.js +17 -21
- package/modules/level/index.js +83 -26
- package/modules/level/load.js +165 -48
- package/modules/level/nodes.js +34 -16
- package/modules/lights/index.js +6 -3
- package/modules/lights/sources.js +3 -1
- package/modules/music/Music.js +4 -2
- package/modules/nav/contract.js +7 -5
- package/modules/nav/index.js +174 -44
- package/modules/nav/navPath.js +45 -10
- package/modules/net/index.js +1 -1
- package/modules/particles/Particles.js +85 -22
- package/modules/particles/effect.js +80 -28
- package/modules/particles/shaders.js +17 -0
- package/modules/photo/Photo.js +12 -10
- package/modules/rigid/RigidBodies.js +200 -57
- package/modules/rigid/Vehicles.js +15 -5
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +55 -44
- package/modules/rigid/ragdollBones.js +83 -33
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +46 -15
- package/modules/settings/Settings.js +84 -37
- package/modules/settings/apply.js +15 -8
- package/modules/settings/sections.js +7 -4
- package/modules/settings/strings.js +2 -2
- package/modules/sky/skyModule.js +3 -1
- package/modules/swarm/Swarm.js +16 -6
- package/modules/terrain/ChunkManager.js +10 -16
- package/modules/terrain/index.js +17 -11
- package/modules/terrain/terrainEdit.js +13 -2
- package/modules/terrain/terrainGen.js +5 -3
- package/modules/terrain/terrainShape.js +1 -1
- package/modules/timeline/Timeline.js +58 -26
- package/modules/timeline/Tween.js +19 -13
- package/modules/timeline/shots.js +19 -10
- package/modules/triggers/index.js +87 -20
- package/modules/vegetation/Vegetation.js +4 -3
- package/modules/vegetation/draw.js +16 -0
- package/modules/vegetation/groundChunks.js +10 -7
- package/modules/vegetation/index.js +30 -7
- package/modules/water/Water.js +6 -2
- package/modules/weather/Weather.js +16 -15
- package/modules/weather/weatherDraw.js +7 -6
- package/modules/world/World.js +20 -7
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +13 -6
- package/modules/world/persist.js +23 -8
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +13 -7
- package/modules/world/sim.js +74 -23
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +31 -6
- package/modules/world/thingSource.js +16 -3
- package/modules/world/views.js +19 -8
- package/package.json +7 -1
- package/render/PostFX.js +47 -29
- package/render/backend.js +5 -1
- package/render/fx/particles.tsl.js +8 -6
- package/render/fx/postWebGPU.tsl.js +3 -3
- package/render/layers.js +1 -1
- package/render/lightmap.js +23 -3
- package/render/occlusion.js +43 -12
- package/render/patches.js +2 -2
- package/render/postWebGL.js +4 -3
- package/render/probes.js +25 -0
- package/render/shadows.js +2 -2
- package/types/core.d.ts +142 -55
- package/types/gameplay.d.ts +92 -40
- package/types/generated/core/base/I18n.d.ts +2 -2
- package/types/generated/core/input/Input.d.ts +16 -2
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/inspect/DebugOverrides.d.ts +15 -1
- package/types/generated/core/ops/Ops.d.ts +2 -1
- package/types/generated/core/ops/control.d.ts +12 -2
- package/types/generated/core/saves/Saves.d.ts +26 -6
- package/types/generated/core/saves/session.d.ts +1 -1
- package/types/generated/core/scene/Views.d.ts +1 -1
- package/types/generated/core/stream/Stream.d.ts +6 -4
- package/types/generated/modules/grid/Grid.d.ts +1 -0
- package/types/generated/modules/particles/Particles.d.ts +4 -3
- package/types/generated/modules/timeline/Timeline.d.ts +5 -4
- package/types/generated/modules/weather/Weather.d.ts +1 -7
- package/types/generated/modules/world/World.d.ts +6 -4
- package/types/generated/render/PostFX.d.ts +6 -14
- package/types/nav.d.ts +36 -4
- package/types/physics.d.ts +55 -7
- package/types/pixel.d.ts +75 -0
- package/types/world.d.ts +14 -8
- package/ui/Parts.js +9 -2
- package/ui/theme.js +2 -2
- package/core/scene/engineCamera.js +0 -32
- package/modules/camera/projection.js +0 -21
|
@@ -12,27 +12,35 @@
|
|
|
12
12
|
// quests.start('first-photo');
|
|
13
13
|
// A step can be parallel goals { text?, all: [{ text, done, target, optional }] } (done when every non-optional part is done, in any order);
|
|
14
14
|
// a quest can fail: fail: e => bool is checked while it is active, then onFail runs, quest:fail fires, and start(id) may begin it again.
|
|
15
|
+
// Reward: the quest finishes either way. A reward that answers with a failure (content.run's answer, or { ok: false, code } from a function) is decided in _pay, the one place
|
|
16
|
+
// for it: the game's onUnpaid if it has one; else the items that did not fit are owed (saved, in list()) and go into the bag when there is room. Either way quest:unpaid fires.
|
|
15
17
|
// Saves name steps and parts by id (step / part id: 'mayor'), else by position; give them ids once the game ships, so inserting a step later
|
|
16
|
-
// does not move players to another step. Save shape (version
|
|
17
|
-
// [partId] } } } }.
|
|
18
|
+
// does not move players to another step. Save shape (version 3): { state: { questId: { step?: stepId, done?, failed?, owed?: { itemId: n }, parts?: [partId met], got?: { stepId:
|
|
19
|
+
// [partId] }, visited?: [stepId left] } } }.
|
|
20
|
+
// A step goes to the next in the list unless it has `next`: a step id, or e => id chosen when the step is done (branches; visited says which ran); false finishes the quest there.
|
|
18
21
|
// The log window is the UI part 'questLog' (questLog.js): replace it or turn it off with engine.ui.set('questLog', ...) (recipes/26-ui-parts.md).
|
|
22
|
+
import { keepTable } from '../../core/base/sections.js';
|
|
19
23
|
import { toast, toggleOnKey } from '../../ui/UI.js';
|
|
20
24
|
import { questLogWindow } from './questLog.js';
|
|
21
25
|
import { warnMissing, warnOnce, DEV } from '../../core/base/validate.js';
|
|
22
26
|
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
23
27
|
import { codedError } from '../../core/base/errorHints.js';
|
|
24
28
|
import { reportError } from '../../core/base/errors.js';
|
|
29
|
+
import { isPlainObject } from '../../core/base/util.js';
|
|
30
|
+
import { failure, isRunFailure } from '../../core/ops/opsFail.js';
|
|
31
|
+
import { refuseSave } from '../../core/base/saveValues.js';
|
|
25
32
|
import { toSaved, fromSaved, migrateV1, stepId } from './questSave.js';
|
|
26
33
|
|
|
27
34
|
const STRINGS = {
|
|
28
|
-
'zh-CN': { 'module.quests': '任务', 'quests.title': '任务日志', 'quests.action': '任务', 'quests.empty': '还没有任务。', 'quests.new': '新任务:{title}', 'quests.done': '任务完成:{title}', 'quests.doneTag': '(已完成)', 'quests.failed': '任务失败:{title}' },
|
|
29
|
-
en: { 'module.quests': 'quests', 'quests.title': 'Journal', 'quests.action': 'Journal', 'quests.empty': 'No quests yet.', 'quests.new': 'New quest: {title}', 'quests.done': 'Quest complete: {title}', 'quests.doneTag': ' (done)', 'quests.failed': 'Quest failed: {title}' },
|
|
35
|
+
'zh-CN': { 'module.quests': '任务', 'quests.title': '任务日志', 'quests.action': '任务', 'quests.empty': '还没有任务。', 'quests.new': '新任务:{title}', 'quests.done': '任务完成:{title}', 'quests.unpaid': '奖励未能发放:{title}', 'quests.doneTag': '(已完成)', 'quests.failed': '任务失败:{title}' },
|
|
36
|
+
en: { 'module.quests': 'quests', 'quests.title': 'Journal', 'quests.action': 'Journal', 'quests.empty': 'No quests yet.', 'quests.new': 'New quest: {title}', 'quests.done': 'Quest complete: {title}', 'quests.unpaid': 'Reward not given: {title}', 'quests.doneTag': ' (done)', 'quests.failed': 'Quest failed: {title}' },
|
|
30
37
|
};
|
|
31
38
|
|
|
32
39
|
/** A step's text; a parallel step without its own text lists its required parts */
|
|
33
40
|
const stepText = st => st.text ?? st.all.filter(p => !p.optional).map(p => p.text).join(' / ');
|
|
34
41
|
export class Quests {
|
|
35
|
-
constructor(engine, { action, checkInterval, notify } = {},
|
|
42
|
+
constructor(engine, { action, checkInterval, notify } = {}, ctx) {
|
|
43
|
+
const { track } = ctx;
|
|
36
44
|
this.engine = engine;
|
|
37
45
|
this.defs = new Map();
|
|
38
46
|
/** @internal id -> { step, done, failed?, parts? (parts done in the current parallel step), got? (parts met in finished parallel steps) }; read it with state(id) */
|
|
@@ -45,9 +53,9 @@ export class Quests {
|
|
|
45
53
|
engine.i18n.add(STRINGS);
|
|
46
54
|
// declared only: the game binds the key (presets.bindings.quests or its own; [] = no key), so every key in a game comes from one bindings table
|
|
47
55
|
track(engine.input.action(action, { label: 'quests.action', owner: 'quests' }));
|
|
48
|
-
this.win = questLogWindow(engine, this,
|
|
56
|
+
this.win = questLogWindow(engine, this, ctx); // { open, toggle, refresh } over engine.ui
|
|
49
57
|
// saved by stable step ids (questSave.js); version 1 saved positions
|
|
50
|
-
|
|
58
|
+
ctx.saves.register('quests', { atomic: true, version: 3, migrate: { 1: d => migrateV1(this.defs, d), 2: d => d }, save: () => this._save(), load: d => this._load(d) });
|
|
51
59
|
}
|
|
52
60
|
|
|
53
61
|
/**
|
|
@@ -62,18 +70,24 @@ export class Quests {
|
|
|
62
70
|
* @param {string} id
|
|
63
71
|
* @param {any} def
|
|
64
72
|
*/
|
|
73
|
+
/** @internal A failed content load puts the definitions back, and the progress define took from the save (core/base/sections.js undo): the function that does it @returns {() => void} */
|
|
74
|
+
undoPoint() {
|
|
75
|
+
const defs = keepTable(this.defs), saved = { ...this._saved }, progress = { ...this._progress };
|
|
76
|
+
return () => { defs(); this._saved = saved; this._progress = progress; };
|
|
77
|
+
}
|
|
65
78
|
define(id, def) {
|
|
66
79
|
const at = `quests.define('${id}')`;
|
|
67
|
-
readParams(at, keysSchema(['title', 'desc', 'steps', 'reward', 'fail', 'onFail']), def);
|
|
80
|
+
readParams(at, keysSchema(['title', 'desc', 'steps', 'reward', 'onUnpaid', 'fail', 'onFail']), def);
|
|
68
81
|
if (!Array.isArray(def?.steps)) throw codedError('quest-step', `${at}: steps is a list of steps, e.g. steps: [{ text: 'Find the key', done: e => e.vars.flag('key') }]; got ${JSON.stringify(def?.steps)}`); // every later read needs it, and this one names the quest
|
|
69
82
|
for (const s of def.steps) {
|
|
70
83
|
if (!s.all && (typeof s.done !== 'function' || s.optional !== undefined)) throw codedError('quest-step', `${at}: a step needs done (a function), or all: [parts] for parallel goals; optional goes on a part inside all`);
|
|
71
|
-
readParams(`${at} steps`, keysSchema(s.all ? ['id', 'text', 'all'] : ['id', 'text', 'done', 'target']), s);
|
|
84
|
+
readParams(`${at} steps`, keysSchema(s.all ? ['id', 'text', 'all', 'next'] : ['id', 'text', 'done', 'target', 'next']), s);
|
|
72
85
|
for (const p of s.all || []) readParams(`${at} parallel part`, keysSchema(['id', 'text', 'done', 'target', 'optional']), p);
|
|
73
86
|
if (s.all && !s.all.some(p => !p.optional)) throw codedError('quest-step', `${at}: a parallel step needs at least one part without optional: true, or it would finish at once`);
|
|
74
87
|
}
|
|
75
88
|
const ids = def.steps.map((_, i) => stepId(def, i)), dup = ids.find((x, i) => ids.indexOf(x) !== i);
|
|
76
89
|
if (dup != null) throw codedError('quest-step', `${at}: two steps have the id '${dup}'; step ids must be unique (saves find a step by it)`);
|
|
90
|
+
for (const s of def.steps) if (s.next != null && s.next !== false && typeof s.next !== 'function' && !ids.includes(s.next)) throw codedError('quest-step', `${at}: next is a step id or e => id; '${s.next}' is not a step of this quest (${ids.join(', ')})`);
|
|
77
91
|
this.defs.set(id, def);
|
|
78
92
|
if (id in this._saved) { this._progress[id] = fromSaved(id, def, this._saved[id]); delete this._saved[id]; this.win.refresh(); }
|
|
79
93
|
return this;
|
|
@@ -88,18 +102,20 @@ export class Quests {
|
|
|
88
102
|
get _period() { return Math.max(1, Math.round(this.checkInterval * 60)); } // 60 = the engine's fixed steps per second
|
|
89
103
|
/** @internal */
|
|
90
104
|
_load(d) {
|
|
105
|
+
const quest = q => isPlainObject(q) && (q.visited == null || Array.isArray(q.visited)) && (q.parts == null || Array.isArray(q.parts)) && (q.got == null || (isPlainObject(q.got) && Object.values(q.got).every(Array.isArray)));
|
|
106
|
+
if (d != null && !(isPlainObject(d) && (d.state == null || (isPlainObject(d.state) && Object.values(d.state).every(quest))))) refuseSave('quests', 'the part', 'must be { state: { quest id: { step, done, parts, got } } }', d);
|
|
91
107
|
this._progress = {}; this._saved = {}; this._t = Number.isInteger(d?.checkIn) ? d.checkIn : 0;
|
|
92
108
|
for (const [id, q] of Object.entries(d?.state || {})) { const def = this.defs.get(id); if (def) this._progress[id] = fromSaved(id, def, q); else this._saved[id] = q; }
|
|
93
109
|
this.win.refresh();
|
|
94
110
|
}
|
|
95
111
|
/**
|
|
96
|
-
* Quest list (for custom UI): unfinished first. A parallel step has parts [{ text, target, done, optional }]; its text defaults to the required parts joined.
|
|
112
|
+
* Quest list (for custom UI): unfinished first. A step is done once the quest has left it, so a step `next` jumped over stays not done, and the step a loop came back to is current. A parallel step has parts [{ text, target, done, optional }]; its text defaults to the required parts joined.
|
|
97
113
|
*/
|
|
98
114
|
list() {
|
|
99
115
|
return Object.entries(this._progress).filter(([id]) => this.defs.has(id)).sort((a, b) => a[1].done - b[1].done).map(([id, s]) => {
|
|
100
|
-
const d = this.defs.get(id), live = !s.done && !s.failed;
|
|
101
|
-
return { id, title: d.title, desc: d.desc, done: s.done, failed: !!s.failed, steps: d.steps.map((st, i) => {
|
|
102
|
-
const now = live && i === s.step, row = { text: st.text, target: st.target, done:
|
|
116
|
+
const d = this.defs.get(id), live = !s.done && !s.failed, ran = new Set(s.visited);
|
|
117
|
+
return { id, title: d.title, desc: d.desc, done: s.done, failed: !!s.failed, ...(s.owed && { owed: { ...s.owed } }), steps: d.steps.map((st, i) => {
|
|
118
|
+
const now = live && i === s.step, row = { text: st.text, target: st.target, done: !now && ran.has(stepId(d, i)), current: now };
|
|
103
119
|
if (st.all) {
|
|
104
120
|
const met = now ? s.parts : s.got?.[i];
|
|
105
121
|
row.parts = st.all.map((p, k) => ({ text: p.text, target: p.target, optional: !!p.optional, done: !!met?.[k] || (row.done && !p.optional) }));
|
|
@@ -127,13 +143,13 @@ export class Quests {
|
|
|
127
143
|
else if (typeof this.notify === 'function') this.notify({ type, id, text });
|
|
128
144
|
}
|
|
129
145
|
/**
|
|
130
|
-
* One quest's progress as plain values: { step (index of the current step), steps (how many), done, failed, active } or null when it has not started.
|
|
146
|
+
* One quest's progress as plain values: { step (index of the current step), steps (how many), done, failed, active, visited (ids of the steps left) } or null when it has not started.
|
|
131
147
|
* A copy: change progress with start / advance, never by writing it.
|
|
132
148
|
* @param {string} id
|
|
133
149
|
*/
|
|
134
150
|
state(id) {
|
|
135
151
|
const s = this._progress[id], d = this.defs.get(id);
|
|
136
|
-
return s && d ? { step: s.step, steps: d.steps.length, done: !!s.done, failed: !!s.failed, active: !s.done && !s.failed } : null;
|
|
152
|
+
return s && d ? { step: s.step, steps: d.steps.length, done: !!s.done, failed: !!s.failed, active: !s.done && !s.failed, visited: [...s.visited ?? []] } : null;
|
|
137
153
|
}
|
|
138
154
|
/**
|
|
139
155
|
* Finish the current step by hand (a step the game completes from its own code: a cutscene ended, a boss fell) and go on; the last step completes the
|
|
@@ -142,23 +158,69 @@ export class Quests {
|
|
|
142
158
|
*/
|
|
143
159
|
advance(id) {
|
|
144
160
|
const s = this._progress[id], d = this.defs.get(id), e = this.engine;
|
|
145
|
-
if (!s || !d || s.done || s.failed) return false;
|
|
161
|
+
if (!s || !d || s.done || s.failed || s.step >= d.steps.length) return false; // past the last step: a quest:step listener, the quest is finishing
|
|
146
162
|
DEV && e.ops.guard('quests.advance');
|
|
147
|
-
|
|
163
|
+
this._leave(id, s, d); e.events.emit('quest:step', { id, step: s.step });
|
|
148
164
|
this._finishOrSay(id, s, d, true);
|
|
149
165
|
return true;
|
|
150
166
|
}
|
|
167
|
+
/** @internal go from the finished step to the next: its `next` (an id, or e => id asked now) else the following one; the step left goes into visited */
|
|
168
|
+
_leave(id, s, d) {
|
|
169
|
+
const here = stepId(d, s.step), st = d.steps[s.step];
|
|
170
|
+
let want = st.next;
|
|
171
|
+
if (typeof want === 'function') { try { want = want(this.engine); } catch (err) { reportError(this.engine, err, `quest '${id}' next`, { soft: true }); want = undefined; } }
|
|
172
|
+
(s.visited ??= []).includes(here) || s.visited.push(here);
|
|
173
|
+
delete s.parts;
|
|
174
|
+
const to = want == null ? s.step + 1 : want === false ? d.steps.length : d.steps.findIndex((_, i) => stepId(d, i) === want);
|
|
175
|
+
if (to < 0) { reportError(this.engine, codedError('quest-step', `quest '${id}': step '${here}' chose next '${want}', which is not a step; going to the following step`), 'quest next', { soft: true }); s.step++; } else s.step = to;
|
|
176
|
+
}
|
|
151
177
|
/** @internal after steps moved: complete the quest at the end, else announce the new step */
|
|
152
178
|
_finishOrSay(id, s, d, advanced) {
|
|
179
|
+
if (s.done || s.failed) return; // a quest:step listener already took it to its end: the reward is paid once
|
|
153
180
|
if (s.step >= d.steps.length) {
|
|
154
181
|
s.done = true;
|
|
155
|
-
|
|
156
|
-
// The failure is reported (soft, no freeze) and the rest goes on; content.run applies every other effect of the reward before it rethrows
|
|
157
|
-
try { d.reward?.(this.engine); } catch (err) { reportError(this.engine, err, `quest '${id}' reward`, { soft: true }); }
|
|
182
|
+
const paid = this._ask(id, 'reward', d.reward);
|
|
158
183
|
this._say('done', id, this.engine.t('quests.done', { title: d.title })); this.engine.events.emit('quest:done', { id });
|
|
184
|
+
this._pay(id, s, d, paid);
|
|
159
185
|
} else if (advanced) this._say('step', id, stepText(d.steps[s.step]));
|
|
160
186
|
if (advanced) this.win.refresh();
|
|
161
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* @internal Run a reward or onFail and read its answer. The quest has already moved on, so one that throws must not stop here: quest:done and the toast would be lost and the
|
|
190
|
+
* reward half given. It is reported (soft, no freeze) and answers as a failure, with what the words beside it said (words.js)
|
|
191
|
+
*/
|
|
192
|
+
_ask(id, what, fn, ...args) {
|
|
193
|
+
try { return fn?.(this.engine, ...args); } catch (err) {
|
|
194
|
+
reportError(this.engine, err, `quest '${id}' ${what}`, { soft: true });
|
|
195
|
+
return err.answer?.ok === false ? err.answer : failure('error');
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* @internal The one place that says what a reward not given means. What happens to it is the game's: onUnpaid decides, and then nothing is kept. Without one the safe default
|
|
200
|
+
* keeps what can be given later as a debt and tells the player. Function rewards and other words cannot be asked twice (they may have half run), so they are only reported
|
|
201
|
+
*/
|
|
202
|
+
_pay(id, s, d, answer) {
|
|
203
|
+
if (!isRunFailure(answer)) return;
|
|
204
|
+
const failed = answer.facts.failed ?? [{ word: 'reward', code: answer.code, facts: answer.facts }];
|
|
205
|
+
if (d.onUnpaid) this._ask(id, 'onUnpaid', d.onUnpaid, answer);
|
|
206
|
+
else {
|
|
207
|
+
for (const f of failed) for (const [item, n] of Object.entries(f.word === 'give' ? f.facts.left : {})) (s.owed ??= {})[item] = (s.owed?.[item] ?? 0) + n;
|
|
208
|
+
this._say('unpaid', id, this.engine.t('quests.unpaid', { title: d.title }));
|
|
209
|
+
}
|
|
210
|
+
this.engine.events.emit('quest:unpaid', { id, code: answer.code, failed, owed: s.owed ? { ...s.owed } : null });
|
|
211
|
+
}
|
|
212
|
+
/** @internal Pay a debt as far as it fits. Only when something does: add in a full bag tells the player so, and this asks twice a second. A debt that throws (the item is gone from the game) cannot be paid, ever */
|
|
213
|
+
_collect(id, s) {
|
|
214
|
+
const e = this.engine, bag = e.inventory?.of(e.ops.actor);
|
|
215
|
+
const answer = bag && this._ask(id, 'owed reward', () => {
|
|
216
|
+
for (const [item, n] of Object.entries(s.owed)) {
|
|
217
|
+
if ((bag.room?.(item) ?? 1) < 1) continue; // room is the engine bag's; a replacement without it is just asked
|
|
218
|
+
const r = bag.add(item, n), got = r.ok ? r.added : 0;
|
|
219
|
+
if (got < n) s.owed[item] = n - got; else delete s.owed[item];
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
if (isRunFailure(answer) || !Object.keys(s.owed).length) delete s.owed;
|
|
223
|
+
}
|
|
162
224
|
isDone(id) { return !!this._progress[id]?.done; }
|
|
163
225
|
isActive(id) { const s = this._progress[id]; return !!s && !s.done && !s.failed; }
|
|
164
226
|
isFailed(id) { return !!this._progress[id]?.failed; }
|
|
@@ -166,11 +228,13 @@ export class Quests {
|
|
|
166
228
|
check() {
|
|
167
229
|
const e = this.engine;
|
|
168
230
|
for (const [id, s] of Object.entries(this._progress)) {
|
|
231
|
+
if (s.owed) this._collect(id, s);
|
|
169
232
|
if (s.done || s.failed) continue;
|
|
170
233
|
const d = this.defs.get(id); if (!d) continue;
|
|
171
234
|
if (d.fail?.(e)) { this._fail(id, s, d); continue; }
|
|
172
235
|
let advanced = false;
|
|
173
|
-
|
|
236
|
+
// at most one pass over the steps per check: a `next` that loops back to a step already done must wait for the next check, not hang
|
|
237
|
+
for (let n = 0; n < d.steps.length && s.step < d.steps.length && this._stepDone(id, s, d.steps[s.step]); n++) { DEV && e.ops.guard('quests.advance'); this._leave(id, s, d); advanced = true; e.events.emit('quest:step', { id, step: s.step }); }
|
|
174
238
|
this._finishOrSay(id, s, d, advanced);
|
|
175
239
|
}
|
|
176
240
|
}
|
|
@@ -193,7 +257,7 @@ export class Quests {
|
|
|
193
257
|
_fail(id, s, d) {
|
|
194
258
|
DEV && this.engine.ops.guard('quests.fail');
|
|
195
259
|
s.failed = true;
|
|
196
|
-
d.onFail
|
|
260
|
+
this._ask(id, 'onFail', d.onFail);
|
|
197
261
|
this._say('fail', id, this.engine.t('quests.failed', { title: d.title }));
|
|
198
262
|
this.engine.events.emit('quest:fail', { id });
|
|
199
263
|
this.win.refresh();
|
|
@@ -206,6 +270,48 @@ const QUEST_PARAMS = {
|
|
|
206
270
|
notify: { type: 'any', default: true, desc: 'true = toast, false = silent, or a function ({ type, id, text }) => void' },
|
|
207
271
|
};
|
|
208
272
|
|
|
273
|
+
/**
|
|
274
|
+
* The quests section of content data, and its startQuest effect word. A step target can be a place, { place, x, z }, { x, z }, { npc: 'id' } (follows the NPC: the
|
|
275
|
+
* position is read each frame) or { nearest: itemId } (the nearest pickup). A step may be parallel goals { text?, all: [{ text, done, target, optional }] };
|
|
276
|
+
* fail / onFail are a condition and an effect like done / reward
|
|
277
|
+
*/
|
|
278
|
+
function questContent() {
|
|
279
|
+
const startOn = new Map();
|
|
280
|
+
const targets = q => q.steps.flatMap(s => s.all ?? [s]).map(s => s.target).filter(Boolean);
|
|
281
|
+
const listen = (e, track, id, event) => startOn.set(id, { event, on: track(e.events.on(event, () => e.quests?.start(id))) });
|
|
282
|
+
return {
|
|
283
|
+
desc: 'quests (id -> title, steps, reward; a step can have a target position)',
|
|
284
|
+
references: d => Object.entries(d).flatMap(([id, q]) => targets(q).flatMap(t => [
|
|
285
|
+
...(t.npc ? [{ section: 'npcs', id: t.npc, at: `quests.${id}` }] : []), ...(t.nearest ? [{ section: 'items', id: t.nearest, at: `quests.${id}` }] : [])])),
|
|
286
|
+
effects: { startQuest: { ref: 'quest', desc: 'start a quest', describe: v => `start quest ${v}`, run: (e, v) => e.quests.start(v) } },
|
|
287
|
+
undo(d, { engine: e, track }) {
|
|
288
|
+
const back = e.quests.undoPoint(), was = new Map(startOn);
|
|
289
|
+
return () => {
|
|
290
|
+
back();
|
|
291
|
+
for (const id of Object.keys(d)) {
|
|
292
|
+
startOn.get(id)?.on.remove(); startOn.delete(id);
|
|
293
|
+
if (was.has(id)) listen(e, track, id, was.get(id).event);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
},
|
|
297
|
+
commit(d, { engine: e, content, where, track }) {
|
|
298
|
+
const target = t => t == null ? undefined : t.npc ? () => e.npcs?.get(t.npc)?.position : t.nearest ? t : where(typeof t === 'string' ? { place: t } : t);
|
|
299
|
+
const goal = s => ({ ...(s.id != null && { id: s.id }), text: s.text, done: () => content.test(s.done), target: target(s.target), ...(s.optional && { optional: true }), ...(s.next != null && { next: s.next }) }); // id: stable for saves
|
|
300
|
+
for (const [id, q] of Object.entries(d)) {
|
|
301
|
+
e.quests.define(id, {
|
|
302
|
+
title: q.title, desc: q.desc,
|
|
303
|
+
steps: q.steps.map(s => s.all ? { ...(s.id != null && { id: s.id }), text: s.text, all: s.all.map(goal), ...(s.next != null && { next: s.next }) } : goal(s)),
|
|
304
|
+
reward: q.reward && (() => content.run(q.reward)),
|
|
305
|
+
...(q.onUnpaid && { onUnpaid: () => content.run(q.onUnpaid) }),
|
|
306
|
+
...(q.fail && { fail: () => content.test(q.fail) }), ...(q.onFail && { onFail: () => content.run(q.onFail) }),
|
|
307
|
+
});
|
|
308
|
+
startOn.get(id)?.on.remove(); // loading the same quest again: replace the old listener instead of attaching twice
|
|
309
|
+
if (q.startOn) listen(e, track, id, q.startOn);
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
209
315
|
/**
|
|
210
316
|
* Quests module. Installs engine.quests. The 'quests' action opens the quest log; the game binds it (presets.bindings.quests has J / gamepad Select) @example
|
|
211
317
|
* engine.use(quests()); engine.input.bind(presets.bindings.quests)
|
|
@@ -214,9 +320,10 @@ export function quests(opts = {}) {
|
|
|
214
320
|
const o = readParams('quests', QUEST_PARAMS, opts);
|
|
215
321
|
let q = null;
|
|
216
322
|
return {
|
|
217
|
-
|
|
323
|
+
content: { quests: questContent() },
|
|
324
|
+
name: 'quests', skipKind: 'approx', type: 'rules', provides: ['quests'], label: 'Quests', params: QUEST_PARAMS, options: o,
|
|
218
325
|
// o: the schema defaults are filled in, the class repeats none
|
|
219
|
-
install(e, ctx) { q = new Quests(e, o, ctx
|
|
326
|
+
install(e, ctx) { q = new Quests(e, o, ctx); return q; },
|
|
220
327
|
// Check quests in the fixed step (game time; not while frozen or flow is paused, so no rewards are granted while paused)
|
|
221
328
|
fixed() { if (--q._t <= 0) { q._t = q._period; q.check(); } },
|
|
222
329
|
// engine.skip: the countdown lands where stepping would have left it; conditions are checked once, on the last segment, if a check fell inside
|
|
@@ -246,3 +353,5 @@ export function quests(opts = {}) {
|
|
|
246
353
|
},
|
|
247
354
|
};
|
|
248
355
|
}
|
|
356
|
+
|
|
357
|
+
export const handRolled = [{ kind: 'quests', seen: 'a quest list of its own', use: 'the quests module: steps, rewards, markers and the log, saved with the game (recipe 04)', quiet: /\b(engine|e|eng|ctx)\.quests\b|\bquests\(\s*[{)]/, code: /(?:\b(?:const|let|var)\s+|\bthis\.)(?:quests?|questLog|missions?|objectives?)(?:List|Log|Data|s)?\s*=\s*(?:\[\s*\]|\{\s*\}|new Map\b)/i }];
|
|
@@ -2,12 +2,19 @@
|
|
|
2
2
|
// the room check and its dev messages, and reading a saved list.
|
|
3
3
|
import { toast } from '../../ui/UI.js';
|
|
4
4
|
import { warnOnce, fmt } from '../../core/base/validate.js';
|
|
5
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
5
6
|
|
|
6
7
|
const STRINGS = {
|
|
7
8
|
full: 'Container {box} has no room for {id} (capacity {cap} slots, maxWeight {mw}): add returns false. Raise capacity / maxWeight, or remove something first',
|
|
8
9
|
partial: 'Only {fit} of {n} {id} fit in container {box} (stack {stack} per slot, capacity {cap} slots, maxWeight {mw}); add still returns the entry key. Raise capacity / maxWeight or the item\'s stack',
|
|
9
10
|
badRow: "container '{box}': dropped a saved entry that is not { id: string, count: whole number 1..2^53-1, data?: plain object } ({got}); the save was edited by hand or is damaged",
|
|
10
11
|
};
|
|
12
|
+
/** The one quantity rule of add / remove / setData / transfer / trade (saves already demand it): a whole number >= 1. Pieces are discrete, so 0, -2, 1.5, NaN
|
|
13
|
+
* and values past 2^53 are a bug in the caller; checked in every build and before anything is written, since a negative remove would otherwise ADD stock @internal */
|
|
14
|
+
export function checkCount(where, name, n) {
|
|
15
|
+
if (!Number.isSafeInteger(n) || n < 1) throw codedError('container', `${where}: ${name} must be a whole number >= 1, got ${n}. Example: bag.remove('arrow', 3)`);
|
|
16
|
+
return n;
|
|
17
|
+
}
|
|
11
18
|
// order-independent signature: entries with equal data stack together whatever the key order
|
|
12
19
|
export const sig = v => v === undefined ? '' : v && typeof v === 'object'
|
|
13
20
|
? (Array.isArray(v) ? `[${v.map(sig)}]` : `{${Object.keys(v).sort().map(k => JSON.stringify(k) + ':' + sig(v[k]))}}`) : JSON.stringify(v);
|
|
@@ -8,10 +8,12 @@
|
|
|
8
8
|
// default below; replace it with engine.ui.set('dialogue.bubble', ...)). Events: dialogue:bubble { speaker, text, at } when a line shows.
|
|
9
9
|
import * as THREE from 'three';
|
|
10
10
|
import { injectUICSS, worldToScreen, placeAt, esc } from '../../ui/UI.js';
|
|
11
|
+
import { vec3 } from '../../core/base/math.js';
|
|
11
12
|
/** @import { Engine, UIPart } from '../../types/core' */
|
|
12
13
|
|
|
13
14
|
const CSS = `
|
|
14
15
|
.threedog-bubble{position:absolute;left:0;top:0;transform:translate(-50%,-100%);max-width:240px;padding:6px 10px;border-radius:var(--threedog-radius-small);background:var(--threedog-bg);color:var(--threedog-fg);font:14px/1.35 var(--threedog-font);pointer-events:none;box-shadow:var(--threedog-shadow-small)}
|
|
16
|
+
.threedog-bubble button{display:block;pointer-events:auto;margin-top:4px;font:inherit;cursor:pointer}
|
|
15
17
|
.threedog-bubble b{display:block;font-size:12px;opacity:.75}
|
|
16
18
|
.threedog-bubbles-screen{position:absolute;left:50%;bottom:22%;transform:translateX(-50%);display:flex;flex-direction:column;align-items:center;gap:6px;pointer-events:none}
|
|
17
19
|
.threedog-bubbles-screen .threedog-bubble{position:static;transform:none}
|
|
@@ -27,7 +29,8 @@ const _v = new THREE.Vector3();
|
|
|
27
29
|
export function bubblePart(e) {
|
|
28
30
|
injectUICSS(CSS);
|
|
29
31
|
const el = document.createElement('div'); el.className = 'threedog-ui threedog-bubble'; el.hidden = true;
|
|
30
|
-
let html = null, parent = null;
|
|
32
|
+
let html = null, parent = null, pick = null;
|
|
33
|
+
el.addEventListener('click', ev => { const i = ev.target.closest?.('button')?.dataset.i; if (i != null) pick?.(+i); }); // a choice asked by a bubble line
|
|
31
34
|
return {
|
|
32
35
|
el,
|
|
33
36
|
update(d) {
|
|
@@ -35,7 +38,8 @@ export function bubblePart(e) {
|
|
|
35
38
|
if (parent !== want) { parent = want; want.appendChild(el); }
|
|
36
39
|
el.hidden = !d.onScreen;
|
|
37
40
|
if (!d.screen) placeAt(el, d.x, d.y);
|
|
38
|
-
|
|
41
|
+
pick = d.choose ?? null;
|
|
42
|
+
const h = `${d.speaker ? `<b>${esc(d.speaker)}</b>` : ''}${esc(d.text)}${(d.choices ?? []).map((c, i) => `<button data-i="${i}">${esc(c)}</button>`).join('')}`;
|
|
39
43
|
if (h !== html) { html = h; el.innerHTML = h; } // called every frame: rebuild only when the line changed
|
|
40
44
|
},
|
|
41
45
|
hide() { el.hidden = true; },
|
|
@@ -62,23 +66,23 @@ export class Bubbles {
|
|
|
62
66
|
if (at == null) return { x: 0, y: 0, onScreen: true, screen: true };
|
|
63
67
|
if (at.isObject3D) at.getWorldPosition(_v);
|
|
64
68
|
else if (typeof at === 'string') { const q = e.actorPosition?.(at); if (!q) return { x: 0, y: 0, onScreen: false, screen: false }; _v.set(q.x, q.y ?? 0, q.z); }
|
|
65
|
-
else
|
|
69
|
+
else vec3(at, _v); // every position form the engine takes: [x, y, z] here read as no position at all
|
|
66
70
|
_v.y += height;
|
|
67
71
|
const s = worldToScreen(e, _v);
|
|
68
72
|
return { x: s.x, y: s.y, onScreen: s.onScreen, screen: false };
|
|
69
73
|
}
|
|
70
74
|
/**
|
|
71
75
|
* Queue one line on a speaker. Returns a Promise (resolves when the line has been shown for its seconds) with remove() (drop it now; resolves too).
|
|
72
|
-
* @param {any} at @param {string} text @param {{ speaker?: string, seconds?: number, queue?: boolean, height?: number }} o
|
|
76
|
+
* @param {any} at @param {string} text @param {{ speaker?: string, seconds?: number, queue?: boolean, height?: number, run?: number | null, choices?: string[] | null }} o
|
|
73
77
|
*/
|
|
74
|
-
say(at, text, { speaker = '', seconds, queue = true, height = 2.2 } = {}) {
|
|
78
|
+
say(at, text, { speaker = '', seconds, queue = true, height = 2.2, run = null, choices = null } = {}) {
|
|
75
79
|
const key = at ?? 'screen:' + speaker;
|
|
76
80
|
let s = this.lines.get(key);
|
|
77
81
|
if (!s) { s = { at, part: this.engine.ui.create('dialogue.bubble'), cur: null, queue: [] }; this.lines.set(key, s); }
|
|
78
82
|
let line;
|
|
79
83
|
const p = new Promise(res => {
|
|
80
84
|
// reading time: holdSeconds plus about 15 characters a second, so a long line stays longer than a shout
|
|
81
|
-
line = { speaker, text: String(text ?? ''), left: seconds ?? this.d.holdSeconds + String(text ?? '').length / 15, height, done: res };
|
|
85
|
+
line = { speaker, text: String(text ?? ''), left: seconds ?? this.d.holdSeconds + String(text ?? '').length / 15, height, run, choices, done: res };
|
|
82
86
|
});
|
|
83
87
|
p.remove = () => this._drop(key, line);
|
|
84
88
|
if (!queue && s.cur) { s.cur.done(); s.cur = null; s.queue.forEach(l => l.done()); s.queue = []; }
|
|
@@ -105,11 +109,12 @@ export class Bubbles {
|
|
|
105
109
|
for (const [key, s] of this.lines) {
|
|
106
110
|
if (!s.cur) continue;
|
|
107
111
|
if ((s.cur.left -= dt) <= 0) { this._next(key, s); if (!this.lines.has(key)) continue; }
|
|
108
|
-
|
|
112
|
+
const c = s.cur, ops = this.engine.ops;
|
|
113
|
+
s.part?.update?.({ speaker: c.speaker, text: c.text, ...(c.choices && { choices: c.choices, run: c.run, choose: index => ops.run('dialogue.choose', { index, run: c.run }, { source: 'player', actor: this.d._asks.get(c.run)?.actor }) }), ...this._place(s.at, c.height) });
|
|
109
114
|
}
|
|
110
115
|
}
|
|
111
|
-
/** Lines showing now: [{ speaker, text, queued }] */
|
|
112
|
-
list() { return [...this.lines.values()].filter(s => s.cur).map(s => ({ speaker: s.cur.speaker, text: s.cur.text, queued: s.queue.length })); }
|
|
116
|
+
/** Lines showing now: [{ speaker, text, queued }], plus run and choices on a line waiting for a choice (dialogue({ bubbleChoice: 'ask' })) */
|
|
117
|
+
list() { return [...this.lines.values()].filter(s => s.cur).map(s => ({ speaker: s.cur.speaker, text: s.cur.text, queued: s.queue.length, ...(s.cur.choices && { run: s.cur.run, choices: s.cur.choices }) })); }
|
|
113
118
|
/** session:end: drop every line without resolving (awaiting code belonged to the old playthrough) @internal */
|
|
114
119
|
clear() { for (const s of this.lines.values()) s.part?.dispose?.(); this.lines.clear(); }
|
|
115
120
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// engine.ui.set('inventory', { drop: true }) default window with a Drop button per row
|
|
6
6
|
// engine.ui.set('inventory', (engine) => ({ show: d => …, update: d => …, hide: () => …, dispose: () => … })) your own
|
|
7
7
|
import { esc, iconHTML as icon, injectUICSS } from '../../ui/UI.js';
|
|
8
|
+
import { isRunFailure } from '../../core/ops/opsFail.js';
|
|
8
9
|
|
|
9
10
|
/** Texts of the inventory window, the got / full toasts and the ops (zh-CN and en) @internal */
|
|
10
11
|
export const INVENTORY_STRINGS = {
|
|
@@ -65,11 +66,11 @@ export function inventoryWindow(e, o = {}) {
|
|
|
65
66
|
const posOf = (e, actor) => actor === 'player' && !e.player ? null : e.actorPosition(actor);
|
|
66
67
|
|
|
67
68
|
/** Define inventory.transfer / inventory.use / inventory.drop @internal */
|
|
68
|
-
export function defineInventoryOps(e, inv) {
|
|
69
|
+
export function defineInventoryOps(e, ctx, inv) {
|
|
69
70
|
const box = id => inv._containers.map.get(id);
|
|
70
71
|
const own = ctx => inv.of(ctx.actor); // the bag of whoever runs the op (a net peer, an NPC, the local user), never a fixed 'player'
|
|
71
72
|
// moving items between containers by hand (an inventory / chest window, drag and drop) is a player decision
|
|
72
|
-
|
|
73
|
+
ctx.ops.define('inventory.transfer', {
|
|
73
74
|
desc: 'Move items between containers (a bag of an actor has the actor id, the local one is player); item is an item id or an entry key (sword#3)', args: { from: 'string', to: 'string', item: 'string', n: 'int?' },
|
|
74
75
|
can(e, { from, to, item, n = 1 }) {
|
|
75
76
|
const a = box(from), b = box(to);
|
|
@@ -82,7 +83,7 @@ export function defineInventoryOps(e, inv) {
|
|
|
82
83
|
// Replace-when-full recipe: one op takes A and gives B, all or nothing. Undo with engine.ops.undo('inventory.trade', args, value).
|
|
83
84
|
// engine.ops.run('inventory.trade', { take: 'rusty_key', give: 'gold_key' }) // { ok: true, value } or { ok: false, code: 'full' | 'notEnough', facts, nextActions }
|
|
84
85
|
const at = (a, ctx) => a.container != null ? box(a.container) : own(ctx);
|
|
85
|
-
|
|
86
|
+
ctx.ops.define('inventory.trade', {
|
|
86
87
|
desc: "Trade in the actor's container: take an item (or entry key) and give another in one all-or-nothing step; works with a full bag when the taken item frees the room",
|
|
87
88
|
args: { take: 'string', give: 'string', takeN: 'int?', giveN: 'int?', container: 'string?' },
|
|
88
89
|
can(e, a, ctx) {
|
|
@@ -97,8 +98,10 @@ export function defineInventoryOps(e, inv) {
|
|
|
97
98
|
},
|
|
98
99
|
reasons: { noContainer: 'No container with that id (container arg; default the actor)', notEnough: 'The container does not hold the item to give up', full: 'The new item does not fit even after the old one is removed' },
|
|
99
100
|
});
|
|
100
|
-
|
|
101
|
-
desc: "Use an item from the actor's container: runs the item's use(e, info); consume: true removes one first", args: { item: 'string' },
|
|
101
|
+
ctx.ops.define('inventory.use', {
|
|
102
|
+
desc: "Use an item from the actor's container: runs the item's use(e, info); consume: true removes one first; a use that answers { ok: false, code } or throws was not used, so all of it goes back, the item too", args: { item: 'string' },
|
|
103
|
+
// consume stays before use, for the room it frees (a potion that leaves a bottle in a full bag), so taking it back is the atomic rollback's job
|
|
104
|
+
atomic: true,
|
|
102
105
|
can(e, { item }, ctx) {
|
|
103
106
|
const en = own(ctx)._of(item)[0];
|
|
104
107
|
if (!en) return 'notEnough';
|
|
@@ -109,13 +112,14 @@ export function defineInventoryOps(e, inv) {
|
|
|
109
112
|
run(e, { item }, ctx) {
|
|
110
113
|
const c = own(ctx), en = c._of(item)[0], def = inv.item(en.id), info = { actor: ctx.actor, item: en.id, key: en.key, data: en.data };
|
|
111
114
|
if (def.consume) c.remove(en.key, 1);
|
|
112
|
-
def.use(e, info);
|
|
115
|
+
const r = def.use(e, info);
|
|
116
|
+
if (isRunFailure(r)) return r;
|
|
113
117
|
e.events.emit('item:use', info);
|
|
114
118
|
return en.key;
|
|
115
119
|
},
|
|
116
120
|
reasons: { notEnough: 'The actor does not have it', notUsable: 'The item has no use function' },
|
|
117
121
|
});
|
|
118
|
-
|
|
122
|
+
ctx.ops.define('inventory.drop', {
|
|
119
123
|
desc: "Drop items from the actor's container on the ground as a pickup (keeps their data)", args: { item: 'string', n: 'int?' },
|
|
120
124
|
can(e, { item, n = 1 }, ctx) {
|
|
121
125
|
if (!own(ctx).has(item, n)) return 'notEnough';
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// gray box; pickups({ color, size, lift }) for the plain values; engine.pickups.material is the three.js material the box and geometry-only models draw with;
|
|
15
15
|
// spawn(pos, { mesh }) puts the game's own object down instead.
|
|
16
16
|
import * as THREE from 'three';
|
|
17
|
+
import { clone as skeletonClone } from 'three/addons/utils/SkeletonUtils.js';
|
|
17
18
|
import { neutralMaterial } from '../../render/neutral.js';
|
|
18
19
|
import { copyPatches, isEngineMade, markEngineMade } from '../../render/patches.js';
|
|
19
20
|
import { xzOf, yOf } from '../../core/base/math.js';
|
|
@@ -32,10 +33,11 @@ const NO_ACTORS = [];
|
|
|
32
33
|
const DEFAULT_COLOR = 0xcccccc;
|
|
33
34
|
// A net host measures peers at the position they last sent (a few steps old): pickup.take allows this much beyond the radius so a fair press is not refused
|
|
34
35
|
const NET_SLACK = 1;
|
|
36
|
+
const seatActors = e => e.input.seats.flatMap(s => s.actor && s.actor !== e.actor ? [s.actor] : NO_ACTORS);
|
|
35
37
|
|
|
36
38
|
export class Pickups {
|
|
37
|
-
/** @internal
|
|
38
|
-
constructor(engine, { radius, showDistance, takers, color, size, lift }, track) {
|
|
39
|
+
/** @internal ctx: the module's ctx */
|
|
40
|
+
constructor(engine, { radius, showDistance, takers, color, size, lift }, { track }) {
|
|
39
41
|
this.engine = engine;
|
|
40
42
|
/** Edge of the placeholder box (meters), read when one is built */ this.size = size;
|
|
41
43
|
/** Height above the ground new pickups float at (meters) */ this.lift = lift;
|
|
@@ -44,11 +46,11 @@ export class Pickups {
|
|
|
44
46
|
/** Reach of pickups that set no radius (meters); auto pickups are taken within it */ this.radius = radius;
|
|
45
47
|
/** @internal pickups float, spin and have a model only within this distance of the stream sources */ this.showDistance = showDistance;
|
|
46
48
|
/**
|
|
47
|
-
* Who can walk into auto pickups: () => actor ids. Default: engine.actor, plus every net peer on a host; none on a net client (the host takes them for it,
|
|
49
|
+
* Who can walk into auto pickups: () => actor ids. Default: engine.actor and every seat's actor, plus every net peer on a host; none on a net client (the host takes them for it,
|
|
48
50
|
* from the positions it is sent). A game with NPCs that collect coins returns their ids too.
|
|
49
51
|
* @type {(e: any) => string[]}
|
|
50
52
|
*/
|
|
51
|
-
this.takers = takers ?? (e => e.net?.role === 'client' ? NO_ACTORS :
|
|
53
|
+
this.takers = takers ?? (e => e.net?.role === 'client' ? NO_ACTORS : [e.actor, ...seatActors(e), ...(e.net?.peers.map(p => p.actor) ?? NO_ACTORS)]);
|
|
52
54
|
// world id -> what cannot go in saved data: the game's mesh, a give function. Spawning the same id again (content / setup code on load) sets them again
|
|
53
55
|
/** @internal */ this._live = new Map();
|
|
54
56
|
// the reach query around each taker uses the largest auto radius in the world, read from the records rather than from spawn calls:
|
|
@@ -61,7 +63,7 @@ export class Pickups {
|
|
|
61
63
|
// a record gone (taken without respawn, removed, not in a loaded save): its live parts are no longer needed for a rebuild
|
|
62
64
|
track(engine.events.on('world:remove', ({ id, kind }) => { this._live.delete(id); dirty({ kind }); }));
|
|
63
65
|
track(engine.events.on('world:load', () => { this._autoDirty = true; for (const id of this._live.keys()) if (!engine.world.get(id)) this._live.delete(id); }));
|
|
64
|
-
present(this);
|
|
66
|
+
present(this, track);
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
/**
|
|
@@ -188,24 +190,25 @@ export class Pickups {
|
|
|
188
190
|
const inReach = (rec, p, r) => { const dx = rec.position.x - p.x, dy = rec.position.y - (p.y ?? 0), dz = rec.position.z - p.z; return dx * dx + dy * dy + dz * dz <= r * r; };
|
|
189
191
|
|
|
190
192
|
/** Register how pickups picture and respawn (once, on install) @internal */
|
|
191
|
-
function present(pk) {
|
|
193
|
+
function present(pk, track) {
|
|
192
194
|
const e = pk.engine, w = e.world;
|
|
193
|
-
w.present('pickup', {
|
|
195
|
+
track(w.present('pickup', {
|
|
194
196
|
radius: pk.showDistance,
|
|
195
197
|
show: rec => rec.until == null, // waiting to respawn: no model
|
|
196
198
|
build: rec => model(pk, rec),
|
|
197
199
|
update: (rec, o) => { // bobbing spin: world places the model at the data position each frame first, this adds the bob on top
|
|
200
|
+
if (!rec.auto && o.userData.useFrom !== e.interactions) { w.rebuild(rec.id); return; } // its use lives in the interactions module it was built with: another one starts empty
|
|
198
201
|
if (rec.bob === false) return;
|
|
199
202
|
const t = e.time.now('real'), x = rec.position.x;
|
|
200
203
|
o.rotation.y = t * 1.5 + x; o.position.y = rec.position.y + Math.sin(t * 2 + x) * 0.08;
|
|
201
204
|
},
|
|
202
205
|
// only detached: a game's mesh is the game's, a model clone shares geometry / material with its prototype (protoOf), the material is shared by every pickup;
|
|
203
206
|
// the placeholder box is the one thing built here alone, so its geometry is freed
|
|
204
|
-
dispose: (rec, o) => { o.userData.useHandle?.remove();
|
|
205
|
-
});
|
|
207
|
+
dispose: (rec, o) => { o.userData.useHandle?.remove(); o.removeFromParent(); o.traverse(c => { if (c.userData.ownGeometry) /** @type {any} */ (c).geometry.dispose(); }); },
|
|
208
|
+
}));
|
|
206
209
|
// waiting to respawn: when due (game clock) clear until and return to the ground. Far ones are also checked once a second, so they grow back on time even when not nearby
|
|
207
210
|
const wake = rec => { if (rec.until != null && e.clock.now >= rec.until) w.set(rec.id, { until: undefined }); };
|
|
208
|
-
w.simulate('pickup', { near: wake, far: wake });
|
|
211
|
+
track(w.simulate('pickup', { near: wake, far: wake }));
|
|
209
212
|
}
|
|
210
213
|
|
|
211
214
|
// A pickup's shape goes one way only: a model name from assets (same protoOf as content props / templates: file or code-generated, cache, bake and shadow rules are identical).
|
|
@@ -240,7 +243,7 @@ function model(pk, rec) {
|
|
|
240
243
|
};
|
|
241
244
|
if (!name) box();
|
|
242
245
|
else protoOf(e, pk, name).then(proto => {
|
|
243
|
-
const o = proto.obj
|
|
246
|
+
const o = skeletonClone(proto.obj); // own bones if it is skinned; geometry / materials stay the prototype's (shadow flags were settled once there, as for content props)
|
|
244
247
|
// generator gave only geometry: draw it with the pickups material in the item's own color (same color shares one); generators that return a full Object3D / file models stay as they are
|
|
245
248
|
if (proto.fromGeometry) drawnBy(pk, o, color);
|
|
246
249
|
holder.add(o);
|
|
@@ -248,6 +251,7 @@ function model(pk, rec) {
|
|
|
248
251
|
}
|
|
249
252
|
if (rec.auto) return obj; // taken by walking into it: no key prompt
|
|
250
253
|
if (!e.interactions) { warnOnce(coded('module-needs', 'Pickups without auto: true are taken with the interact key: install interactions() first.')); return obj; }
|
|
254
|
+
obj.userData.useFrom = e.interactions;
|
|
251
255
|
obj.userData.useHandle = e.interactions.add(obj, {
|
|
252
256
|
id: rec.id,
|
|
253
257
|
label: () => e.t('pickups.take', { name: pk._name(rec) }), radius: rec.radius ?? pk.radius,
|
|
@@ -278,8 +282,8 @@ function pickupMaterial(pk, mesh) {
|
|
|
278
282
|
}
|
|
279
283
|
|
|
280
284
|
/** The op pickup.take { id }: the interact key, auto pickups, a net peer's request, the dev bridge and tests all run it, as ctx.actor @internal */
|
|
281
|
-
function defineTake(e, pk) {
|
|
282
|
-
|
|
285
|
+
function defineTake(e, ctx, pk) {
|
|
286
|
+
ctx.ops.define('pickup.take', {
|
|
283
287
|
desc: "Take a pickup off the ground: its item goes into the actor's container (or its give function runs for the actor)",
|
|
284
288
|
args: { id: 'string' },
|
|
285
289
|
net: 'peer', // a client's press is sent to the host, which runs it as that peer: the item lands in the peer's bag there and syncs back
|
|
@@ -304,12 +308,32 @@ function defineTake(e, pk) {
|
|
|
304
308
|
const PICKUP_PARAMS = {
|
|
305
309
|
radius: { type: 'number', default: 2, min: 0, desc: 'reach of pickups that set no radius (meters); auto pickups are taken within it' },
|
|
306
310
|
showDistance: { type: 'number', default: 60, min: 0, desc: 'pickups have a model, float and spin only within this distance of the stream sources (meters)' },
|
|
307
|
-
takers: { type: 'any', optional: true, desc: 'e => actor ids that walk into auto pickups (default engine.actor, plus net peers on a host)' },
|
|
311
|
+
takers: { type: 'any', optional: true, desc: 'e => actor ids that walk into auto pickups (default engine.actor and the seats, plus net peers on a host)' },
|
|
308
312
|
color: { type: 'any', default: DEFAULT_COLOR, desc: 'color of the placeholder box and geometry-only models when the pickup and its item set none' },
|
|
309
313
|
size: { type: 'number', default: 0.25, min: 0, desc: 'edge of the placeholder box (meters)' },
|
|
310
314
|
lift: { type: 'number', default: 0.4, desc: 'height above the ground a pickup floats at (meters)' },
|
|
311
315
|
};
|
|
312
316
|
|
|
317
|
+
/**
|
|
318
|
+
* The pickups section of content data: data goes into world (kind 'pickup'). Without a written id: `pickup:<item>:<index in the pickups array>`, stable for the
|
|
319
|
+
* same content (when inserting in the middle, give existing entries an id). Taken / respawning is state
|
|
320
|
+
*/
|
|
321
|
+
const PICKUP_CONTENT = {
|
|
322
|
+
desc: 'pickups on the ground (list)',
|
|
323
|
+
live: true,
|
|
324
|
+
references: d => d.filter(p => typeof p.item === 'string').map((p, i) => ({ section: 'items', id: p.item, at: `pickups[${i}]` })),
|
|
325
|
+
validate(d, { ids, pickupId }) {
|
|
326
|
+
d.forEach((p, i) => { const label = `pickups[${i}] (${p.item})`; if (p.id != null) ids.claim(pickupId(p, i), label); else ids.unnamed(pickupId(p, i), label); });
|
|
327
|
+
},
|
|
328
|
+
commit(d, { engine: e, where, zone, origin, pickupId }) {
|
|
329
|
+
d.forEach((p, i) => {
|
|
330
|
+
const id = pickupId(p, i);
|
|
331
|
+
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: zone(p) });
|
|
332
|
+
origin(id, d, i);
|
|
333
|
+
});
|
|
334
|
+
},
|
|
335
|
+
};
|
|
336
|
+
|
|
313
337
|
/**
|
|
314
338
|
* Pickups module: things on the ground that give whoever takes them an item (into that actor's container) or an instant effect. Installs engine.pickups and
|
|
315
339
|
* the op pickup.take. Needs world() first; interactions() for the key prompt (auto: true pickups need none); inventory() only for give: itemId.
|
|
@@ -321,10 +345,11 @@ export function pickups(opts = {}) {
|
|
|
321
345
|
const o = readParams('pickups', PICKUP_PARAMS, opts);
|
|
322
346
|
let pk = null;
|
|
323
347
|
return {
|
|
324
|
-
|
|
348
|
+
content: { pickups: PICKUP_CONTENT },
|
|
349
|
+
name: 'pickups', skipKind: 'exact', type: 'rules', label: 'Pickups', params: PICKUP_PARAMS, options: o, requires: ['world'], optional: ['interactions', 'inventory', 'net'], stage: 'gameplay',
|
|
325
350
|
noSkip: 'auto pickups are spatial; respawn follows the game clock',
|
|
326
351
|
install(e, ctx) {
|
|
327
|
-
pk = new Pickups(e, o, ctx
|
|
352
|
+
pk = new Pickups(e, o, ctx); defineTake(e, ctx, pk); return pk; // o: the schema defaults are filled in, the class repeats none
|
|
328
353
|
},
|
|
329
354
|
fixed() { pk._auto(); },
|
|
330
355
|
describe(e, ctx) { // use the model if present (same object the interactions module reports, merged into one entry); far away only data
|
|
@@ -333,3 +358,5 @@ export function pickups(opts = {}) {
|
|
|
333
358
|
},
|
|
334
359
|
};
|
|
335
360
|
}
|
|
361
|
+
|
|
362
|
+
export const handRolled = 'none: a pickup by hand is a distance check with no word that sets it apart';
|
|
@@ -39,10 +39,12 @@ function questLogPart(engine) {
|
|
|
39
39
|
* @returns {{ readonly open: boolean, toggle(on?: boolean): void, refresh(): void }}
|
|
40
40
|
* @internal
|
|
41
41
|
*/
|
|
42
|
-
export function questLogWindow(e, q,
|
|
42
|
+
export function questLogWindow(e, q, ctx) {
|
|
43
|
+
const { track } = ctx;
|
|
43
44
|
/** @returns {QuestLogView} */
|
|
44
45
|
const view = () => ({ title: e.t('quests.title'), key: e.input.label(q.action), quests: q.list(), close: () => e.ui.close(NAME) });
|
|
45
|
-
|
|
46
|
+
ctx.ui.define(NAME, questLogPart, { modal: { cancel: eng => eng.ui.close(NAME), data: view } });
|
|
47
|
+
track(e.events.on('session:end', () => e.ui.close(NAME))); // it shows the playthrough that ended
|
|
46
48
|
const win = {
|
|
47
49
|
get open() { return e.ui.isOpen(NAME); },
|
|
48
50
|
toggle(on = !win.open) { if (on) e.ui.open(NAME); else e.ui.close(NAME); },
|