castle-web-cli 0.4.230 → 0.4.232
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/dist/castle-host/host.js +81 -0
- package/dist/devSaveStorage.d.ts +36 -0
- package/dist/devSaveStorage.js +469 -0
- package/dist/devSessionChild.js +22 -12
- package/dist/devSessionServer.js +8 -2
- package/dist/devSessionStorage.d.ts +9 -0
- package/dist/devSessionStorage.js +66 -1
- package/dist/init.js +1 -1
- package/dist/serve.js +5 -1
- package/dist/serverBundle.js +5 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +148 -1
- package/kits/base/sdk/castle.d.ts +4 -0
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +15 -0
- package/kits/base/sdk/multiplayer.js +52 -4
- package/kits/base/sdk/save.d.ts +197 -0
- package/kits/base/sdk/save.js +525 -0
- package/kits/base/sdk/saveCoordinator.d.ts +39 -0
- package/kits/base/sdk/saveCoordinator.js +252 -0
- package/kits/base/sdk/server/storage.d.ts +3 -2
- package/kits/base/sdk/server/storage.js +25 -5
- package/kits/base/sdk/server/wrapper.d.ts +4 -0
- package/kits/base/sdk/server/wrapper.js +2 -0
- package/kits/base/sdk/store.d.ts +3 -2
- package/kits/base/sdk/store.js +5 -0
- package/kits/hub-game/CLAUDE.md +29 -4
- package/kits/hub-game/code/client/avatar.js +39 -0
- package/kits/hub-game/code/client/chat.js +12 -0
- package/kits/hub-game/code/client/chrome.js +237 -13
- package/kits/hub-game/code/client/grab.js +166 -7
- package/kits/hub-game/code/client/hats.js +26 -0
- package/kits/hub-game/code/client/hookLayer.js +36 -3
- package/kits/hub-game/code/client/hudClear.js +126 -0
- package/kits/hub-game/code/client/state.js +35 -1
- package/kits/hub-game/code/client/talk.js +10 -36
- package/kits/hub-game/code/client/tiers.js +505 -0
- package/kits/hub-game/code/client/together.js +144 -4
- package/kits/hub-game/code/client/wear.js +96 -14
- package/kits/hub-game/code/server/actors.js +5 -0
- package/kits/hub-game/code/server/grab.js +299 -13
- package/kits/hub-game/code/server/hub.js +162 -7
- package/kits/hub-game/code/server/manifest.js +80 -8
- package/kits/hub-game/code/server/npcs.js +21 -33
- package/kits/hub-game/code/server/party.js +75 -6
- package/kits/hub-game/code/server/say.js +8 -2
- package/kits/hub-game/code/server/wear.js +116 -11
- package/kits/hub-game/code/systems/hub.js +386 -21
- package/kits/hub-game/docs/contract.md +285 -19
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/test-chat.mjs +32 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +511 -0
- package/kits/hub-game/scripts/test-grab.mjs +857 -3
- package/kits/hub-game/scripts/test-hats.mjs +229 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +721 -0
- package/kits/hub-game/scripts/test-hud-clear.mjs +676 -0
- package/kits/hub-game/scripts/test-manifest.mjs +122 -1
- package/kits/hub-game/scripts/test-npcs.mjs +34 -24
- package/kits/hub-game/scripts/test-party.mjs +108 -4
- package/kits/hub-game/scripts/test-say.mjs +59 -2
- package/kits/hub-game/scripts/test-tiers.mjs +854 -0
- package/kits/hub-game/scripts/test-together.mjs +33 -1
- package/kits/hub-game/scripts/test-try-on.mjs +940 -0
- package/kits/physics-2d/CLAUDE.md +2 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +127 -0
- package/kits/physics-2d/package.json +1 -1
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +298 -0
- package/kits/physics-3d/CLAUDE.md +531 -0
- package/kits/physics-3d/behaviors/Player.jsx +437 -3
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/pxmodel-format.md +4 -0
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +33 -1
- package/kits/physics-3d/engine3d/actornode.js +253 -0
- package/kits/physics-3d/engine3d/nearshadows.js +600 -0
- package/kits/physics-3d/engine3d/optimize.js +49 -0
- package/kits/physics-3d/engine3d/orbitinput.js +277 -0
- package/kits/physics-3d/engine3d/unchanged.js +153 -0
- package/kits/physics-3d/engine3d/world3d.js +525 -11
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/Player.before-orbit.mjs +310 -0
- package/kits/physics-3d/scripts/Scene3DPlayer.before-orbit.jsx +337 -0
- package/kits/physics-3d/scripts/test-camera-follow.mjs +543 -0
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2105 -0
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +787 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +1073 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +667 -0
- package/kits/physics-3d/scripts/test-static-passes.mjs +459 -0
- package/kits/physics-3d/scripts/test-static-physics.mjs +128 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +633 -0
- package/kits/physics-3d/systems/physics3d.js +273 -9
- package/package.json +1 -1
|
@@ -9,10 +9,12 @@ import * as Avatars from '@imports/castle.multiplayer-3d/code/client/avatars.js'
|
|
|
9
9
|
import * as Avatar from './avatar.js';
|
|
10
10
|
import * as Cabinets from './cabinets.js';
|
|
11
11
|
import { firstJoinFor } from './firstJoin.js';
|
|
12
|
-
import { hub } from './state.js';
|
|
12
|
+
import { deck, hub, wearingNow } from './state.js';
|
|
13
13
|
|
|
14
14
|
// Root-anchored: the deck's own castle.json once this kit is imported.
|
|
15
15
|
const castleJson = Object.values(import.meta.glob('/castle.json', { eager: true, import: 'default' }))[0] ?? {};
|
|
16
|
+
deck.tiers = castleJson?.hub?.tiers === true;
|
|
17
|
+
deck.cues = castleJson?.hub?.cues === true;
|
|
16
18
|
|
|
17
19
|
let files = null;
|
|
18
20
|
// The scene and multiplayer system of the newest snapshot, for a message that
|
|
@@ -41,9 +43,10 @@ function setAvatars(scene, system) {
|
|
|
41
43
|
hub.avatars = next;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
// Everyone's wearables with this player's own over them (v1.4)
|
|
46
|
+
// Everyone's wearables with this player's own over them (v1.4), and over
|
|
47
|
+
// those whatever the place is showing on a player (v1.28, `hub.tryOn`).
|
|
45
48
|
function setWearing() {
|
|
46
|
-
hub.wearing =
|
|
49
|
+
hub.wearing = wearingNow();
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
function wearMap(value) {
|
|
@@ -84,6 +87,10 @@ export default {
|
|
|
84
87
|
// A jump to a door: the camera turns to look at it.
|
|
85
88
|
if (typeof msg.facing === 'number') {
|
|
86
89
|
(scene.persistent ??= {}).camAngle = Math.PI - msg.facing;
|
|
90
|
+
// Under the engine's orbit camera key the facing is asked for.
|
|
91
|
+
if (scene.cameraControl === 'orbit') {
|
|
92
|
+
scene.faceRequest = msg.facing;
|
|
93
|
+
}
|
|
87
94
|
}
|
|
88
95
|
// Beside a player: the hub system says whom (a start next to a friend).
|
|
89
96
|
if (typeof msg.to === 'string') {
|
|
@@ -95,6 +102,11 @@ export default {
|
|
|
95
102
|
Object.assign(hub.whereAt, msg.at && typeof msg.at === 'object' ? msg.at : {});
|
|
96
103
|
hub.whereAtAt = performance.now();
|
|
97
104
|
break;
|
|
105
|
+
case 'hub-went':
|
|
106
|
+
if (hub.wentEvents.length < 32 && Array.isArray(msg.players) && typeof msg.door === 'string') {
|
|
107
|
+
hub.wentEvents.push(msg);
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
98
110
|
case 'hub-said':
|
|
99
111
|
if (hub.saidEvents.length < 64) {
|
|
100
112
|
hub.saidEvents.push(msg);
|
|
@@ -116,6 +128,11 @@ export default {
|
|
|
116
128
|
hub.wearMe = wearMap(msg.hubWear);
|
|
117
129
|
setWearing();
|
|
118
130
|
break;
|
|
131
|
+
case 'hub-try':
|
|
132
|
+
// v1.28: try-ons of players in a hidden pair this player may see.
|
|
133
|
+
hub.tryMe = wearMap(msg.hubTry);
|
|
134
|
+
setWearing();
|
|
135
|
+
break;
|
|
119
136
|
case 'hub-labels':
|
|
120
137
|
hub.labelsMe = msg.labels && typeof msg.labels === 'object' ? msg.labels : {};
|
|
121
138
|
break;
|
|
@@ -176,6 +193,18 @@ export default {
|
|
|
176
193
|
hub.wearAll = wearMap(msg.hubWear);
|
|
177
194
|
setWearing();
|
|
178
195
|
}
|
|
196
|
+
// v1.28: only a place that shows a try-on sends this. A snapshot (it
|
|
197
|
+
// carries `hubPlace`) without one means none is up. `tryMe` is not the
|
|
198
|
+
// snapshot's to clear: the place sends `hub-try` on the tick before a
|
|
199
|
+
// joiner's snapshot, and sends it again, empty or not, to a client that
|
|
200
|
+
// rejoins.
|
|
201
|
+
if (msg.hubTry && typeof msg.hubTry === 'object') {
|
|
202
|
+
hub.tryAll = wearMap(msg.hubTry);
|
|
203
|
+
setWearing();
|
|
204
|
+
} else if (msg.hubPlace && hub.tryAll.size > 0) {
|
|
205
|
+
hub.tryAll = new Map();
|
|
206
|
+
setWearing();
|
|
207
|
+
}
|
|
179
208
|
if ('hud' in msg) {
|
|
180
209
|
hub.hud = msg.hud ?? null;
|
|
181
210
|
}
|
|
@@ -203,6 +232,10 @@ export default {
|
|
|
203
232
|
if (msg.labels) {
|
|
204
233
|
hub.labels = msg.labels;
|
|
205
234
|
}
|
|
235
|
+
// v1.27: only a place that keeps an object for a player sends this.
|
|
236
|
+
if (msg.hubKept && typeof msg.hubKept === 'object') {
|
|
237
|
+
hub.keptFor = new Map(Object.entries(msg.hubKept));
|
|
238
|
+
}
|
|
206
239
|
// v1.6: only a place that turns idle play on sends these.
|
|
207
240
|
if (msg.hubEmotes && typeof msg.hubEmotes === 'object') {
|
|
208
241
|
hub.emotes = msg.hubEmotes;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// A clear HUD (contract v1.26, a place's `hud: { clear: true }`): the sizes
|
|
2
|
+
// and the geometry, with no DOM in them so `scripts/test-hud-clear.mjs` can
|
|
3
|
+
// hold them. The chrome (`chrome.js`) calls these only in a place that asks;
|
|
4
|
+
// a place that does not is drawn by the code it always was.
|
|
5
|
+
//
|
|
6
|
+
// Three rules. (1) A big line with a text line under it is drawn smaller, and
|
|
7
|
+
// always on one line, so the text stays in view; a big line alone keeps its
|
|
8
|
+
// 56 px. (2) What the chrome places over the world (labels, speech, marks,
|
|
9
|
+
// pointers, a cabinet's card, the result ribbon) is moved to just under the
|
|
10
|
+
// HUD's box when it would lie over it, never hidden and never off the bottom
|
|
11
|
+
// of the view. (3) On a short view (a
|
|
12
|
+
// phone on its side) the text keeps to two lines and the box to a share of
|
|
13
|
+
// the height.
|
|
14
|
+
|
|
15
|
+
// The big line as it always was, and as it is alone.
|
|
16
|
+
export const BIG_PX = 56;
|
|
17
|
+
// The big line over a text line, on a tall view and on a short one.
|
|
18
|
+
export const BIG_WITH_TEXT_PX = 32;
|
|
19
|
+
export const BIG_WITH_TEXT_SHORT_PX = 28;
|
|
20
|
+
// A long big line shrinks to fit, never below this; past it the line is cut
|
|
21
|
+
// with an ellipsis rather than wrapped.
|
|
22
|
+
export const BIG_MIN_PX = 18;
|
|
23
|
+
// The HUD box's own widest (`maxWidth: 70vw`) and its width when nothing in
|
|
24
|
+
// it is wider (it hangs from the middle of the screen, so half the view).
|
|
25
|
+
const HUD_MAX_SHARE = 0.7;
|
|
26
|
+
const HUD_MIN_SHARE = 0.5;
|
|
27
|
+
// A view this short or shorter, and wider than it is tall, is a phone on its
|
|
28
|
+
// side. (Not height alone: the web player's portrait card on a 360 px phone is
|
|
29
|
+
// about 475 px tall, and is a tall view.)
|
|
30
|
+
export const SHORT_VIEW_H = 480;
|
|
31
|
+
export const SHORT_TEXT_LINES = 2;
|
|
32
|
+
export const SHORT_HUD_SHARE = 0.4;
|
|
33
|
+
// Clear air kept between the HUD's box and what is moved under it.
|
|
34
|
+
export const HUD_GAP = 6;
|
|
35
|
+
|
|
36
|
+
// How wide a string is at weight 800 in the system face, in ems. An estimate
|
|
37
|
+
// on the wide side: the chrome measures the drawn line after and shrinks it
|
|
38
|
+
// again if this fell short (`fitPx`).
|
|
39
|
+
export function bigEms(text) {
|
|
40
|
+
let ems = 0;
|
|
41
|
+
for (const ch of String(text)) {
|
|
42
|
+
if (ch === ' ') {
|
|
43
|
+
ems += 0.3;
|
|
44
|
+
} else if (/[.,:;!'|]/.test(ch)) {
|
|
45
|
+
ems += 0.34;
|
|
46
|
+
} else if (/[0-9]/.test(ch)) {
|
|
47
|
+
ems += 0.64;
|
|
48
|
+
} else if (/[MW@%]/.test(ch) || ch.codePointAt(0) > 0x2000) {
|
|
49
|
+
ems += 1;
|
|
50
|
+
} else if (/[a-z]/.test(ch)) {
|
|
51
|
+
ems += 0.6;
|
|
52
|
+
} else {
|
|
53
|
+
ems += 0.74;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return ems;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// The HUD's layout for what it shows. `viewW`/`viewH` are the view in CSS
|
|
60
|
+
// pixels; `reserve` is the width taken at each side of the big line's row (the
|
|
61
|
+
// Back button and its margin), 0 for none.
|
|
62
|
+
// bigPx the big line's font size
|
|
63
|
+
// bigOneLine whether it is held to one line (cut with an ellipsis)
|
|
64
|
+
// bigMaxWidth the widest the big line may be, or null for no limit
|
|
65
|
+
// textLines how many lines the text keeps to, or null for no limit
|
|
66
|
+
// maxHeight the tallest the box may be, or null for no limit
|
|
67
|
+
export function hudLayout({ big, text, viewW, viewH, reserve = 0 }) {
|
|
68
|
+
const short = viewH <= SHORT_VIEW_H && viewW > viewH;
|
|
69
|
+
const layout = {
|
|
70
|
+
bigPx: BIG_PX,
|
|
71
|
+
bigOneLine: false,
|
|
72
|
+
bigMaxWidth: null,
|
|
73
|
+
textLines: short ? SHORT_TEXT_LINES : null,
|
|
74
|
+
maxHeight: short ? Math.round(viewH * SHORT_HUD_SHARE) : null,
|
|
75
|
+
};
|
|
76
|
+
if (!big || !text) {
|
|
77
|
+
return layout;
|
|
78
|
+
}
|
|
79
|
+
const avail = Math.max(
|
|
80
|
+
Math.round(viewW * HUD_MIN_SHARE),
|
|
81
|
+
Math.min(Math.round(viewW * HUD_MAX_SHARE), Math.floor(viewW - 2 * reserve)),
|
|
82
|
+
);
|
|
83
|
+
const base = short ? BIG_WITH_TEXT_SHORT_PX : BIG_WITH_TEXT_PX;
|
|
84
|
+
const ems = bigEms(big);
|
|
85
|
+
layout.bigPx = ems * base <= avail ? base : Math.max(BIG_MIN_PX, Math.floor(avail / ems));
|
|
86
|
+
layout.bigOneLine = true;
|
|
87
|
+
layout.bigMaxWidth = avail;
|
|
88
|
+
return layout;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// A line drawn at `px` that needs `needed` pixels where it has `room`: the
|
|
92
|
+
// size at which it fits, never below the least.
|
|
93
|
+
export function fitPx(px, room, needed) {
|
|
94
|
+
if (!(needed > room) || !(room > 0)) {
|
|
95
|
+
return px;
|
|
96
|
+
}
|
|
97
|
+
return Math.max(BIG_MIN_PX, Math.min(px, Math.floor((px * room) / needed)));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// The box of something the chrome hangs from a point: `anchor` "bottom" is
|
|
101
|
+
// centred over the point with its bottom edge on it (a label, a chip over a
|
|
102
|
+
// friend), "center" is centred on it (a chip at the screen's edge).
|
|
103
|
+
export function boxAt(x, y, width, height, anchor = 'bottom') {
|
|
104
|
+
const top = anchor === 'center' ? y - height / 2 : y - height;
|
|
105
|
+
return { left: x - width / 2, right: x + width / 2, top, bottom: top + height };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// How far down `box` must move to lie clear under the HUD's box (`hud`, or
|
|
109
|
+
// null while no HUD is drawn): 0 when it is beside it, over it or already
|
|
110
|
+
// under it. Both are { left, right, top, bottom } in CSS pixels. Nothing is
|
|
111
|
+
// pushed off the bottom of the view (`viewH`, when given): a box too tall to
|
|
112
|
+
// lie both under the HUD and whole on screen moves only as far as keeps its
|
|
113
|
+
// bottom edge in view, the HUD left over its top, and one already at or past
|
|
114
|
+
// the bottom is not moved.
|
|
115
|
+
export function pushBelow(box, hud, gap = HUD_GAP, viewH = Infinity) {
|
|
116
|
+
if (!hud) {
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
if (box.right <= hud.left || box.left >= hud.right) {
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
122
|
+
if (box.bottom <= hud.top || box.top >= hud.bottom + gap) {
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
125
|
+
return Math.max(0, Math.min(hud.bottom + gap - box.top, viewH - box.bottom));
|
|
126
|
+
}
|
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
// (`code/systems/hub.js`). One module instance per page; `clear` runs on every
|
|
4
4
|
// session switch.
|
|
5
5
|
|
|
6
|
+
// What the deck's own castle.json asks of the hub client, read once by the
|
|
7
|
+
// hook layer (`hookLayer.js`) as the page loads. Not cleared on a session
|
|
8
|
+
// switch: it is the page's deck, whichever place is playing.
|
|
9
|
+
export const deck = {
|
|
10
|
+
// `hub.tiers`: a cheaper picture on a slow device (`tiers.js`).
|
|
11
|
+
tiers: false,
|
|
12
|
+
// `hub.cues` (v1.23): a town says more about the friends and party a player
|
|
13
|
+
// came with -- a friend already here, who reads chat, the door a friend
|
|
14
|
+
// went to, who joined the party. Every such branch asks this first.
|
|
15
|
+
cues: false,
|
|
16
|
+
};
|
|
17
|
+
|
|
6
18
|
export const hub = {
|
|
7
19
|
// the place's public manifest (`hubPlace`), or null before the first snapshot
|
|
8
20
|
place: null,
|
|
@@ -18,6 +30,11 @@ export const hub = {
|
|
|
18
30
|
wearing: new Map(),
|
|
19
31
|
wearAll: new Map(),
|
|
20
32
|
wearMe: new Map(),
|
|
33
|
+
// playerId -> a wearable the place shows on that player instead of their
|
|
34
|
+
// own until it clears it (`hubTry`, v1.28 `hub.tryOn`), with this player's
|
|
35
|
+
// own (`hub-try`) over it; both empty in a place that never tries one on
|
|
36
|
+
tryAll: new Map(),
|
|
37
|
+
tryMe: new Map(),
|
|
21
38
|
// the declared HUD, this player's override of it, and the page time each
|
|
22
39
|
// arrived (a timer is read against the simulation clock below)
|
|
23
40
|
hud: null,
|
|
@@ -46,6 +63,9 @@ export const hub = {
|
|
|
46
63
|
// what players said since the hub system last looked (`hub-said`, v1.11):
|
|
47
64
|
// { player, r } (a reaction) or { player, p, door } (a phrase)
|
|
48
65
|
saidEvents: [],
|
|
66
|
+
// who went through which door since the hub system last looked
|
|
67
|
+
// (`hub-went`, v1.15): { players, door }
|
|
68
|
+
wentEvents: [],
|
|
49
69
|
// playerId -> { text, color }: the tag the place put over that player
|
|
50
70
|
marks: {},
|
|
51
71
|
// copy id -> { from, x, y, z, rotationY }: actors the place spawned, and
|
|
@@ -57,7 +77,7 @@ export const hub = {
|
|
|
57
77
|
// player ids the place is holding still
|
|
58
78
|
held: new Set(),
|
|
59
79
|
// actor id -> { text, style }, and this player's own over them (an NPC's
|
|
60
|
-
// reply to
|
|
80
|
+
// reply to this player)
|
|
61
81
|
labels: {},
|
|
62
82
|
labelsMe: {},
|
|
63
83
|
// the facing the place gave this player on arrival, or null until it has,
|
|
@@ -70,6 +90,9 @@ export const hub = {
|
|
|
70
90
|
npcEvents: [],
|
|
71
91
|
// the place's answers about a hold (`grab.js`, v1.3): hub-grab-deny, hub-drop
|
|
72
92
|
grabEvents: [],
|
|
93
|
+
// actor id -> the only player who may grab it (`hubKept`, v1.27); empty in
|
|
94
|
+
// a place that keeps nothing
|
|
95
|
+
keptFor: new Map(),
|
|
73
96
|
// Idle play (v1.6, `idle.js`, `sound.js`): playerId -> { id, at, until } (an
|
|
74
97
|
// emote playing, simulation ms), playerId -> the seat actor they sit on,
|
|
75
98
|
// actorId -> { file, volume, radius, since } (a loop playing there), and the
|
|
@@ -92,6 +115,8 @@ export function clear() {
|
|
|
92
115
|
hub.wearing.clear();
|
|
93
116
|
hub.wearAll.clear();
|
|
94
117
|
hub.wearMe.clear();
|
|
118
|
+
hub.tryAll.clear();
|
|
119
|
+
hub.tryMe.clear();
|
|
95
120
|
hub.hud = null;
|
|
96
121
|
hub.hudMe = null;
|
|
97
122
|
hub.hidden.clear();
|
|
@@ -110,7 +135,9 @@ export function clear() {
|
|
|
110
135
|
hub.labelsMe = {};
|
|
111
136
|
hub.npcEvents.length = 0;
|
|
112
137
|
hub.saidEvents.length = 0;
|
|
138
|
+
hub.wentEvents.length = 0;
|
|
113
139
|
hub.grabEvents.length = 0;
|
|
140
|
+
hub.keptFor = new Map();
|
|
114
141
|
hub.emotes = {};
|
|
115
142
|
hub.seated = {};
|
|
116
143
|
hub.sounds = {};
|
|
@@ -121,6 +148,13 @@ export function clear() {
|
|
|
121
148
|
hub.commands.length = 0;
|
|
122
149
|
}
|
|
123
150
|
|
|
151
|
+
// What each player is drawn wearing: their own wearable, or the one the place
|
|
152
|
+
// is showing on them (v1.28), which wins while it is up and leaves the saved
|
|
153
|
+
// one to be drawn again when it goes.
|
|
154
|
+
export function wearingNow() {
|
|
155
|
+
return new Map([...hub.wearAll, ...hub.wearMe, ...hub.tryAll, ...hub.tryMe]);
|
|
156
|
+
}
|
|
157
|
+
|
|
124
158
|
export function avatarOf(playerId) {
|
|
125
159
|
return hub.avatars.has(playerId) ? hub.avatars.get(playerId) : null;
|
|
126
160
|
}
|
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
// mind or to the place's authored lines.
|
|
6
6
|
//
|
|
7
7
|
// With a mind, the player's words are a character turn on the world's socket
|
|
8
|
-
// (`requestCharacterTurn`): the server admits it or
|
|
9
|
-
// is read back with a status read, which is also
|
|
10
|
-
// over the NPC to
|
|
8
|
+
// (`requestCharacterTurn`) that names no listener: the server admits it or
|
|
9
|
+
// refuses it, and the reply is read back with a status read, which is also
|
|
10
|
+
// when the server shows it over the NPC to this player alone. What a player
|
|
11
|
+
// says to a character and what it answers is theirs: nobody else is sent
|
|
12
|
+
// either. Without one, the words are a plain
|
|
11
13
|
// message and the place answers. The place's notes for the character (what it
|
|
12
14
|
// knows right now: a ledger, a pad) come from the server as a prefix sent
|
|
13
15
|
// ahead of the player's words; the server admits only notes it issued, and the
|
|
@@ -19,7 +21,6 @@ const TALK_RANGE_M = 3.5;
|
|
|
19
21
|
const POLL_MS = 1200;
|
|
20
22
|
const POLL_LIMIT_MS = 90_000;
|
|
21
23
|
const INPUT_MAX = 280;
|
|
22
|
-
const LISTENERS_MAX = 7;
|
|
23
24
|
// A turn refused for stale notes is sent again once, with the newest.
|
|
24
25
|
const NOTES_RETRY_MS = 400;
|
|
25
26
|
// Lines the place said because the mind was not answering, and how the panel
|
|
@@ -41,7 +42,7 @@ const newId = () => globalThis.crypto?.randomUUID?.() ?? `${Date.now().toString(
|
|
|
41
42
|
export function makeTalk(chrome) {
|
|
42
43
|
const t = {
|
|
43
44
|
chrome,
|
|
44
|
-
// { npc, name, mind, character,
|
|
45
|
+
// { npc, name, mind, character, prefix } while a panel is open
|
|
45
46
|
open: null,
|
|
46
47
|
asking: null,
|
|
47
48
|
net: null,
|
|
@@ -76,8 +77,8 @@ function frame(t, scene, mp, idle) {
|
|
|
76
77
|
for (const msg of hub.npcEvents.splice(0)) {
|
|
77
78
|
if (msg.k === 'hub-npc') {
|
|
78
79
|
if (msg.open) {
|
|
79
|
-
t.open = { npc: msg.npc, name: msg.name, mind: Boolean(msg.mind), character: msg.character ?? null,
|
|
80
|
-
t.chrome.openTalk(msg.name
|
|
80
|
+
t.open = { npc: msg.npc, name: msg.name, mind: Boolean(msg.mind), character: msg.character ?? null, prefix: null };
|
|
81
|
+
t.chrome.openTalk(msg.name);
|
|
81
82
|
if (t.open.mind) {
|
|
82
83
|
registerParticipant(t, net);
|
|
83
84
|
}
|
|
@@ -103,7 +104,6 @@ function frame(t, scene, mp, idle) {
|
|
|
103
104
|
const near = idle && net && !t.open ? nearestNpc(scene) : null;
|
|
104
105
|
t.near = near;
|
|
105
106
|
t.chrome.talkPrompt(near ? near.name : null);
|
|
106
|
-
t.scene = scene;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
function nearestNpc(scene) {
|
|
@@ -183,7 +183,8 @@ async function turn(t, open, text) {
|
|
|
183
183
|
operationId,
|
|
184
184
|
characterId: open.character,
|
|
185
185
|
input: `${open.prefix ?? ''}${text}`,
|
|
186
|
-
|
|
186
|
+
// Nobody else hears a player's conversation with a character.
|
|
187
|
+
audience: { disclosure: 'participants', playerIds: [], characterIds: [] },
|
|
187
188
|
});
|
|
188
189
|
};
|
|
189
190
|
try {
|
|
@@ -230,30 +231,3 @@ async function turn(t, open, text) {
|
|
|
230
231
|
t.waiting = false;
|
|
231
232
|
}
|
|
232
233
|
}
|
|
233
|
-
|
|
234
|
-
// Who else hears this turn: the players drawn near the NPC now, at most seven.
|
|
235
|
-
// The server checks the same distance against its own poses.
|
|
236
|
-
function listeners(t, open) {
|
|
237
|
-
const scene = t.scene;
|
|
238
|
-
const mp = scene?.multiplayer;
|
|
239
|
-
const npc = scene?.getActor(open.npc)?.components.Transform;
|
|
240
|
-
if (!npc || !mp?.avatars?.actors) {
|
|
241
|
-
return [];
|
|
242
|
-
}
|
|
243
|
-
const near = [];
|
|
244
|
-
for (const [playerId, actorId] of mp.avatars.actors) {
|
|
245
|
-
const at = scene.getActor(actorId)?.components.Transform;
|
|
246
|
-
if (at) {
|
|
247
|
-
const d = Math.hypot(at.x - npc.x, at.z - npc.z);
|
|
248
|
-
// A little inside the server's range, so a player at its edge is not
|
|
249
|
-
// the reason a turn is refused.
|
|
250
|
-
if (d <= open.hearRange - 0.5) {
|
|
251
|
-
near.push({ playerId, d });
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return near
|
|
256
|
-
.sort((a, b) => a.d - b.d)
|
|
257
|
-
.slice(0, LISTENERS_MAX)
|
|
258
|
-
.map((p) => p.playerId);
|
|
259
|
-
}
|