castle-web-cli 0.4.231 → 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/serverBundle.js +5 -3
- package/kits/hub-game/CLAUDE.md +26 -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 +194 -4
- package/kits/hub-game/code/client/grab.js +31 -7
- package/kits/hub-game/code/client/hats.js +26 -0
- package/kits/hub-game/code/client/hookLayer.js +30 -3
- package/kits/hub-game/code/client/hudClear.js +126 -0
- package/kits/hub-game/code/client/state.js +22 -0
- package/kits/hub-game/code/client/tiers.js +31 -6
- package/kits/hub-game/code/client/together.js +66 -1
- 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 +296 -11
- package/kits/hub-game/code/server/hub.js +63 -2
- package/kits/hub-game/code/server/manifest.js +48 -3
- package/kits/hub-game/code/server/party.js +11 -0
- 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 +253 -5
- package/kits/hub-game/docs/contract.md +204 -8
- 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 +186 -3
- 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 +513 -0
- package/kits/hub-game/scripts/test-hud-clear.mjs +676 -0
- package/kits/hub-game/scripts/test-manifest.mjs +75 -0
- package/kits/hub-game/scripts/test-party.mjs +22 -1
- package/kits/hub-game/scripts/test-say.mjs +59 -2
- package/kits/hub-game/scripts/test-tiers.mjs +190 -2
- package/kits/hub-game/scripts/test-try-on.mjs +940 -0
- package/kits/physics-2d/castle.json +1 -1
- package/kits/physics-2d/engine/scene.js +35 -0
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +44 -0
- package/kits/physics-3d/CLAUDE.md +252 -0
- package/kits/physics-3d/behaviors/Player.jsx +363 -2
- package/kits/physics-3d/castle.json +2 -2
- package/kits/physics-3d/docs/pxmodel-format.md +4 -0
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +32 -0
- package/kits/physics-3d/engine3d/optimize.js +49 -0
- package/kits/physics-3d/engine3d/orbitinput.js +277 -0
- package/kits/physics-3d/engine3d/world3d.js +81 -25
- 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 +12 -2
- 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-static-actors.mjs +6 -1
- package/kits/physics-3d/scripts/test-static-passes.mjs +1 -1
- package/kits/physics-3d/scripts/test-steady-hover.mjs +633 -0
- package/kits/physics-3d/systems/physics3d.js +91 -6
- package/package.json +1 -1
|
@@ -405,6 +405,17 @@ export function coming(h, doorId) {
|
|
|
405
405
|
return n;
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
+
// Cues (v1.23): the door of a player's live party proposal -- one they made,
|
|
409
|
+
// or one they were asked about and have not answered -- or null.
|
|
410
|
+
export function proposalDoor(h, playerId) {
|
|
411
|
+
const partyId = h.party.of.get(keyOf(h, playerId));
|
|
412
|
+
const proposal = partyId ? h.party.proposals.get(partyId) : null;
|
|
413
|
+
if (!proposal || proposal.until <= Date.now()) {
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
return proposal.by === playerId || proposal.asked.has(playerId) ? proposal.door : null;
|
|
417
|
+
}
|
|
418
|
+
|
|
408
419
|
// `hub.partyOf(playerId)`: the other members of their party who are here.
|
|
409
420
|
export function matesHere(h, playerId) {
|
|
410
421
|
const partyId = h.party.of.get(keyOf(h, playerId));
|
|
@@ -29,7 +29,10 @@ export function newSayState() {
|
|
|
29
29
|
return { sayRate: new Map() };
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
// `d` is the hub layer's own: `{ h, blockedPairs, jumpDoors }
|
|
32
|
+
// `d` is the hub layer's own: `{ h, blockedPairs, jumpDoors }`, and under cues
|
|
33
|
+
// (v1.23, a deck whose manifest sets `cues`) `{ cues: true, goDoors(h),
|
|
34
|
+
// proposalDoor(h, playerId) }`: the doors the Doors list may go to, and the
|
|
35
|
+
// door of the player's live party proposal.
|
|
33
36
|
export function message(d, player, data) {
|
|
34
37
|
const h = d.h;
|
|
35
38
|
const playerId = player?.playerId;
|
|
@@ -52,7 +55,10 @@ export function message(d, player, data) {
|
|
|
52
55
|
best = { dist, id: door.id };
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
|
-
|
|
58
|
+
// Cues: the door their party is going to comes first, while that
|
|
59
|
+
// proposal is open and the place still has the door.
|
|
60
|
+
const proposed = d.cues ? d.proposalDoor(h, playerId) : null;
|
|
61
|
+
out.door = (proposed && d.goDoors(h).some((door) => door.id === proposed) ? proposed : null) ?? best?.id ?? null;
|
|
56
62
|
}
|
|
57
63
|
} else {
|
|
58
64
|
return;
|
|
@@ -8,6 +8,15 @@
|
|
|
8
8
|
// The snapshot's `hubWear` is playerId -> wearable for helloed players who
|
|
9
9
|
// wear one, without anyone a block hides from someone here: theirs go to each
|
|
10
10
|
// player who may see them alone (`hub-wear`), as their avatars do (`hub-av`).
|
|
11
|
+
//
|
|
12
|
+
// A try-on (v1.28, `hub.tryOn(playerId, spec | null)`) is a wearable this
|
|
13
|
+
// place shows on a player instead of their own until it clears it: a hat on a
|
|
14
|
+
// shop's mat, a costume for a visit. It is kept here only (`trying`), never
|
|
15
|
+
// sent to ghost and never read back, so what the player owns is untouched;
|
|
16
|
+
// clients are told in `hubTry` and `hub-try`, the shape of `hubWear` and
|
|
17
|
+
// `hub-wear`, and draw it over the saved one. `trying` is empty until a place
|
|
18
|
+
// calls `hub.tryOn`, and every branch for it asks that first: a place that
|
|
19
|
+
// never does sends what it always did.
|
|
11
20
|
|
|
12
21
|
import { warnOnce } from './actors.js';
|
|
13
22
|
|
|
@@ -27,6 +36,14 @@ export function newWearState() {
|
|
|
27
36
|
wearSent: new Map(),
|
|
28
37
|
// playerId -> JSON of the wearables last sent to that player alone
|
|
29
38
|
sentWearMe: new Map(),
|
|
39
|
+
// playerId -> the wearable this place shows on them instead of their own
|
|
40
|
+
// (v1.28 `hub.tryOn`); empty in a place that never calls it
|
|
41
|
+
trying: new Map(),
|
|
42
|
+
// playerId -> JSON of the try-ons last sent to that player alone, or
|
|
43
|
+
// `RESEND` for a client that joined afresh and is to be told again
|
|
44
|
+
sentTryMe: new Map(),
|
|
45
|
+
// whether any player was ever sent try-ons alone (`hub-try`)
|
|
46
|
+
tryAloneUsed: false,
|
|
30
47
|
};
|
|
31
48
|
}
|
|
32
49
|
|
|
@@ -52,17 +69,27 @@ export function cleanWearable(spec) {
|
|
|
52
69
|
return { kind, color: color.toLowerCase(), rarity };
|
|
53
70
|
}
|
|
54
71
|
|
|
72
|
+
// What `hub.wear` and `hub.tryOn` (`api`) take: the wearable, `null` to clear,
|
|
73
|
+
// or `undefined` for one refused and logged once -- a player who is not here,
|
|
74
|
+
// or a spec that is not a wearable.
|
|
75
|
+
function asked(h, api, playerId, spec) {
|
|
76
|
+
if (typeof playerId !== 'string' || !(h.players.has(playerId) || h.sim?.players.has(playerId))) {
|
|
77
|
+
warnOnce(h, `${api}:${playerId}`, `hub.${api}: "${playerId}" is not a player here`);
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
const clean = cleanWearable(spec === undefined ? null : spec);
|
|
81
|
+
if (clean === undefined) {
|
|
82
|
+
warnOnce(h, `${api}:spec`, `hub.${api}: a wearable is { kind, color: "#rrggbb", rarity: 0-9 } or null`);
|
|
83
|
+
}
|
|
84
|
+
return clean;
|
|
85
|
+
}
|
|
86
|
+
|
|
55
87
|
// `hub.wear(playerId, spec | null)`: true when it took. `platform` is the
|
|
56
88
|
// host's hub ops or null; `userId` the player's, or null for a guest, whose
|
|
57
89
|
// wearable is this session's alone; `refused` logs a refusal once.
|
|
58
90
|
export function wear(h, playerId, spec, { platform, userId, refused }) {
|
|
59
|
-
|
|
60
|
-
warnOnce(h, `wear:${playerId}`, `hub.wear: "${playerId}" is not a player here`);
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
const clean = cleanWearable(spec === undefined ? null : spec);
|
|
91
|
+
const clean = asked(h, 'wear', playerId, spec);
|
|
64
92
|
if (clean === undefined) {
|
|
65
|
-
warnOnce(h, 'wear:spec', 'hub.wear: a wearable is { kind, color: "#rrggbb", rarity: 0-9 } or null');
|
|
66
93
|
return false;
|
|
67
94
|
}
|
|
68
95
|
if (clean) {
|
|
@@ -84,6 +111,22 @@ export function wear(h, playerId, spec, { platform, userId, refused }) {
|
|
|
84
111
|
return true;
|
|
85
112
|
}
|
|
86
113
|
|
|
114
|
+
// `hub.tryOn(playerId, spec | null)` (v1.28): true when it took. Shown on the
|
|
115
|
+
// player in this place until `null`, their leaving or the place's end; the
|
|
116
|
+
// wearable they own (`wearing`, ghost's) is neither read nor written.
|
|
117
|
+
export function tryOn(h, playerId, spec) {
|
|
118
|
+
const clean = asked(h, 'tryOn', playerId, spec);
|
|
119
|
+
if (clean === undefined) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
if (clean) {
|
|
123
|
+
h.trying.set(playerId, clean);
|
|
124
|
+
} else {
|
|
125
|
+
h.trying.delete(playerId);
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
|
|
87
130
|
// Ghost's word on a player's wearable, from the arrival read: kept unless the
|
|
88
131
|
// game set one since the read began. A ghost older than wearables says
|
|
89
132
|
// nothing, which changes nothing.
|
|
@@ -106,8 +149,17 @@ export function applyRead(h, playerId, wearRev, read) {
|
|
|
106
149
|
// Everyone's wearables, for everyone: helloed players only, without the ones
|
|
107
150
|
// a block hides from someone here.
|
|
108
151
|
export function wearingOf(h, hidden) {
|
|
152
|
+
return shownOf(h, h.wearing, hidden);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Everyone's try-ons (v1.28), for everyone, under the same two rules.
|
|
156
|
+
export function tryingOf(h, hidden) {
|
|
157
|
+
return shownOf(h, h.trying, hidden);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function shownOf(h, worn, hidden) {
|
|
109
161
|
const out = {};
|
|
110
|
-
for (const [playerId, wearable] of
|
|
162
|
+
for (const [playerId, wearable] of worn) {
|
|
111
163
|
if (h.players.get(playerId)?.hello && !hidden?.has(playerId)) {
|
|
112
164
|
out[playerId] = wearable;
|
|
113
165
|
}
|
|
@@ -118,18 +170,69 @@ export function wearingOf(h, hidden) {
|
|
|
118
170
|
// The wearables of players in a hidden pair, each to the players who may see
|
|
119
171
|
// them, when they change. A session with no blocks sends nothing here.
|
|
120
172
|
export function sendOverrides(h, hidden) {
|
|
173
|
+
sendAlone(h, hidden, h.wearing, h.sentWearMe, (out) => ({ k: 'hub-wear', hubWear: out }));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// The same for try-ons (v1.28, `hub-try`). Asked only once a place has
|
|
177
|
+
// called `hub.tryOn` (`tryOnUsed`).
|
|
178
|
+
export function sendTryOverrides(h, hidden) {
|
|
179
|
+
sendAlone(h, hidden, h.trying, h.sentTryMe, (out) => {
|
|
180
|
+
h.tryAloneUsed = true;
|
|
181
|
+
return { k: 'hub-try', hubTry: out };
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// A client joined afresh (a hello that is not an avatar change: a reconnect,
|
|
186
|
+
// a reloaded page that resumed its player id). What it holds of `hub-try` is
|
|
187
|
+
// not known -- nothing, or a map from before it dropped out -- so it is sent
|
|
188
|
+
// the map as it is now, empty or not, on the next tick it has a body. Only in
|
|
189
|
+
// a place that has ever sent one: anywhere else no client holds any.
|
|
190
|
+
const RESEND = 'resend';
|
|
191
|
+
|
|
192
|
+
export function joinedAfresh(h, playerId) {
|
|
193
|
+
if (h.tryAloneUsed) {
|
|
194
|
+
h.sentTryMe.set(playerId, RESEND);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// A try-on is taken for a player with a body who has not said hello (as
|
|
199
|
+
// `hub.wear` takes one), and such a player's going is not a `forget`: drop
|
|
200
|
+
// what is kept for anyone who is neither known to the place nor in the
|
|
201
|
+
// simulation, so both maps hold only players who are here.
|
|
202
|
+
export function pruneTries(h) {
|
|
203
|
+
for (const kept of [h.trying, h.sentTryMe]) {
|
|
204
|
+
for (const playerId of [...kept.keys()]) {
|
|
205
|
+
if (!h.players.has(playerId) && !h.sim?.players.has(playerId)) {
|
|
206
|
+
kept.delete(playerId);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// The place is ending: every try-on with it.
|
|
213
|
+
export function endTries(h) {
|
|
214
|
+
h.trying.clear();
|
|
215
|
+
h.sentTryMe.clear();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Whether this place has a try-on up, or has told someone of one alone.
|
|
219
|
+
export function tryOnUsed(h) {
|
|
220
|
+
return h.trying.size > 0 || h.sentTryMe.size > 0;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function sendAlone(h, hidden, worn, sent, message) {
|
|
121
224
|
for (const playerId of h.sim.players.keys()) {
|
|
122
225
|
const out = {};
|
|
123
226
|
for (const shrouded of hidden?.keys() ?? []) {
|
|
124
|
-
const wearable =
|
|
227
|
+
const wearable = worn.get(shrouded);
|
|
125
228
|
if (wearable && h.players.get(shrouded)?.hello && !hidden.get(playerId)?.has(shrouded)) {
|
|
126
229
|
out[shrouded] = wearable;
|
|
127
230
|
}
|
|
128
231
|
}
|
|
129
232
|
const json = JSON.stringify(out);
|
|
130
|
-
if ((
|
|
131
|
-
|
|
132
|
-
h.session?.send(playerId,
|
|
233
|
+
if ((sent.get(playerId) ?? '{}') !== json) {
|
|
234
|
+
sent.set(playerId, json);
|
|
235
|
+
h.session?.send(playerId, message(out));
|
|
133
236
|
}
|
|
134
237
|
}
|
|
135
238
|
}
|
|
@@ -139,4 +242,6 @@ export function forget(h, playerId) {
|
|
|
139
242
|
h.wearRev.delete(playerId);
|
|
140
243
|
h.wearSent.delete(playerId);
|
|
141
244
|
h.sentWearMe.delete(playerId);
|
|
245
|
+
h.trying.delete(playerId);
|
|
246
|
+
h.sentTryMe.delete(playerId);
|
|
142
247
|
}
|
|
@@ -73,6 +73,38 @@ const TICKETS_MAX = 4;
|
|
|
73
73
|
// How often a place asks the host who of the player's friends is in its other
|
|
74
74
|
// layers, while the player is there and idle.
|
|
75
75
|
const FRIENDS_EVERY_MS = 20000;
|
|
76
|
+
// Cues (v1.23): while someone here is not named by the host as a friend, the
|
|
77
|
+
// host is asked again a few times (`together.due`) -- one such ask in this
|
|
78
|
+
// long at most on average, however many come in: 15 a minute (16 in the
|
|
79
|
+
// worst-placed one), never a 2 s poll. v1.32: counted as two in any twice this long, this far apart at
|
|
80
|
+
// least, so an ask the host answered a moment too soon (it knows a join
|
|
81
|
+
// within a few seconds) is put again while it matters.
|
|
82
|
+
const FRIENDS_EARLY_MS = 4000;
|
|
83
|
+
const FRIENDS_EARLY_PAIR_MS = 2000;
|
|
84
|
+
// ...and never this soon after any ask, the cadence's own included (v1.31:
|
|
85
|
+
// 1 s, with the first extra ask 1 s after someone is seen; were 2 s).
|
|
86
|
+
const FRIENDS_EARLY_AFTER_MS = 1000;
|
|
87
|
+
// Cues: a friend found already here is told to the player when no other
|
|
88
|
+
// toast is up, and not at all once this long has passed.
|
|
89
|
+
const HERE_CUE_MS = 15000;
|
|
90
|
+
// Cues: the party the place first tells a session about is the one the player
|
|
91
|
+
// already had; only a change after this long is a join worth a toast.
|
|
92
|
+
const PARTY_SETTLE_MS = 5000;
|
|
93
|
+
const PARTY_CARRY_MS = 30000;
|
|
94
|
+
// Cues: an accepted invitation is this player's own join for this long.
|
|
95
|
+
const PARTY_ACCEPT_MS = 10000;
|
|
96
|
+
// Cues: the chat field's own words. The field is about 20 characters wide,
|
|
97
|
+
// so the whole sentence is its accessible label and the note above it.
|
|
98
|
+
const CHAT_HINT = {
|
|
99
|
+
on: 'To your follows…',
|
|
100
|
+
// v1.29: one field and one sentence for every reason it cannot be used, so
|
|
101
|
+
// neither says which reason it is (never a player's age).
|
|
102
|
+
off: 'Friends only',
|
|
103
|
+
why: 'Typed chat is for friends who follow each other. Emotes work with everyone.',
|
|
104
|
+
label: 'Message · only players you follow each other with',
|
|
105
|
+
};
|
|
106
|
+
// Cues (v1.29): how long a player back from a game is offered it again.
|
|
107
|
+
const AGAIN_ASK_MS = 20000;
|
|
76
108
|
// Starting next to a friend: how long after walking in a friend found here
|
|
77
109
|
// still moves the player beside them, and how far the player may have walked.
|
|
78
110
|
const START_NEAR_MS = 12000;
|
|
@@ -193,8 +225,25 @@ class HubSystem {
|
|
|
193
225
|
this.playAsked = new Map();
|
|
194
226
|
// A friend who went through a door while the question could not be put.
|
|
195
227
|
this.wentAsk = null;
|
|
228
|
+
// Cues (v1.29): the game this player just came back from, offered again.
|
|
229
|
+
this.againAsk = null;
|
|
196
230
|
this.chat = makeChat();
|
|
197
231
|
this.namesTouched = new WeakMap();
|
|
232
|
+
// Cues (v1.23), all unused in a deck without `hub.cues`: when the host
|
|
233
|
+
// was last asked early for the friends; friends found already here, not
|
|
234
|
+
// yet told; the friend the player was just put beside; the roster as of
|
|
235
|
+
// the last frame; and the party as of the last frame, with what tells a
|
|
236
|
+
// party the player already had from one they just joined.
|
|
237
|
+
this.friendsEarlyAt = -Infinity;
|
|
238
|
+
this.friendsEarlyBeforeAt = -Infinity;
|
|
239
|
+
this.friendsSentAt = -Infinity;
|
|
240
|
+
this.hereCues = [];
|
|
241
|
+
this.besideTold = null;
|
|
242
|
+
this.rosterSeen = new Set();
|
|
243
|
+
this.partyLast = null;
|
|
244
|
+
this.partySettleUntil = 0;
|
|
245
|
+
this.partyCarryUntil = 0;
|
|
246
|
+
this.partyAccepted = null;
|
|
198
247
|
}
|
|
199
248
|
|
|
200
249
|
// Other players' names in a town: near ones only, and smaller
|
|
@@ -281,6 +330,11 @@ class HubSystem {
|
|
|
281
330
|
this.sound.frame(scene, local, !this.trip);
|
|
282
331
|
if (this.trip || held || this.talk.typing() || this.chrome.chatFocused?.()) {
|
|
283
332
|
lockInput(scene);
|
|
333
|
+
// Under the engine's orbit camera key the player's drags and wheel do
|
|
334
|
+
// not move the trip's camera, nor queue up for after it.
|
|
335
|
+
if (this.trip && scene.cameraControl === 'orbit') {
|
|
336
|
+
scene.lookInput?.lock?.();
|
|
337
|
+
}
|
|
284
338
|
}
|
|
285
339
|
// Grabbing and throwing (v1.3), in a place that offers it: after this
|
|
286
340
|
// frame's physics step, before the multiplayer kit reports what it owns.
|
|
@@ -388,6 +442,7 @@ class HubSystem {
|
|
|
388
442
|
this.together.clear();
|
|
389
443
|
this.playAsk = null;
|
|
390
444
|
this.wentAsk = null;
|
|
445
|
+
this.againAsk = null;
|
|
391
446
|
this.playAsked.clear();
|
|
392
447
|
}
|
|
393
448
|
|
|
@@ -410,10 +465,22 @@ class HubSystem {
|
|
|
410
465
|
applyWear(scene) {
|
|
411
466
|
const self = scene.multiplayer?.net?.selfId?.() ?? null;
|
|
412
467
|
const style = Avatar.style();
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
468
|
+
const indexOf = (playerId) => (playerId === self ? Avatar.current(scene) : Hub.hub.avatars.get(playerId));
|
|
469
|
+
this.wear.frame(
|
|
470
|
+
scene,
|
|
471
|
+
scene.actorWith('Player'),
|
|
472
|
+
Hub.hub.wearing,
|
|
473
|
+
(playerId) => {
|
|
474
|
+
const index = indexOf(playerId);
|
|
475
|
+
return Avatar.top(index, Avatar.drawn(scene.files, index, style));
|
|
476
|
+
},
|
|
477
|
+
undefined,
|
|
478
|
+
// Asked only for a player wearing a hat.
|
|
479
|
+
(playerId) => {
|
|
480
|
+
const index = indexOf(playerId);
|
|
481
|
+
return Avatar.hatFit(index, Avatar.drawn(scene.files, index, style));
|
|
482
|
+
},
|
|
483
|
+
);
|
|
417
484
|
}
|
|
418
485
|
|
|
419
486
|
// The place's tuning of this player's own controller (`hub.tune`): the
|
|
@@ -482,8 +549,19 @@ class HubSystem {
|
|
|
482
549
|
this.together.clear();
|
|
483
550
|
this.playAsk = null;
|
|
484
551
|
this.wentAsk = null;
|
|
552
|
+
this.againAsk = null;
|
|
485
553
|
this.playAsked.clear();
|
|
486
554
|
this.chat.reset();
|
|
555
|
+
if (Hub.deck.cues) {
|
|
556
|
+
this.hereCues = [];
|
|
557
|
+
this.besideTold = null;
|
|
558
|
+
this.rosterSeen = new Set();
|
|
559
|
+
// The party this session is first told of is the one the player had.
|
|
560
|
+
this.partyCarryUntil = this.partyLast?.members ? performance.now() + PARTY_CARRY_MS : 0;
|
|
561
|
+
this.partyLast = null;
|
|
562
|
+
this.partySettleUntil = performance.now() + PARTY_SETTLE_MS;
|
|
563
|
+
this.partyAccepted = null;
|
|
564
|
+
}
|
|
487
565
|
}
|
|
488
566
|
this.helloNet = net;
|
|
489
567
|
this.helloAvatar = avatar;
|
|
@@ -1047,11 +1125,39 @@ class HubSystem {
|
|
|
1047
1125
|
}
|
|
1048
1126
|
const place = Hub.hub.place;
|
|
1049
1127
|
const idle = !this.trip && this.pendingEnd === null && (mp.joinState?.() ?? 'joined') === 'joined';
|
|
1050
|
-
if (!place || place.result || !idle
|
|
1128
|
+
if (!place || place.result || !idle) {
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
// Cues (v1.23): someone here is not named by the host as a friend, and
|
|
1132
|
+
// may be one it has not heard is here yet (it learns presence on a
|
|
1133
|
+
// heartbeat), so the host is asked again when `together.due` says, not
|
|
1134
|
+
// at the end of its 20 s. Every bound is measured from asks that were
|
|
1135
|
+
// really sent: at most two such asks in any 8 s, 2 s apart, none within
|
|
1136
|
+
// 1 s of any ask.
|
|
1137
|
+
// One that cannot be sent (a trip, a join still pending) reaches none of
|
|
1138
|
+
// this and is simply tried again when it can be, owing nothing it missed.
|
|
1139
|
+
const onTime = now - this.friendsAt >= FRIENDS_EVERY_MS;
|
|
1140
|
+
const early =
|
|
1141
|
+
!onTime &&
|
|
1142
|
+
Hub.deck.cues &&
|
|
1143
|
+
now - this.friendsEarlyAt >= FRIENDS_EARLY_PAIR_MS &&
|
|
1144
|
+
now - this.friendsEarlyBeforeAt >= 2 * FRIENDS_EARLY_MS &&
|
|
1145
|
+
now - this.friendsSentAt >= FRIENDS_EARLY_AFTER_MS &&
|
|
1146
|
+
this.together.due(this.friendsAll, now);
|
|
1147
|
+
if (!onTime && !early) {
|
|
1051
1148
|
return;
|
|
1052
1149
|
}
|
|
1053
1150
|
this.friendsAt = now;
|
|
1054
1151
|
this.friendsAsking = true;
|
|
1152
|
+
if (Hub.deck.cues) {
|
|
1153
|
+
// Sent: the bounds count from here, and the steps come due are spent.
|
|
1154
|
+
this.friendsSentAt = now;
|
|
1155
|
+
if (early) {
|
|
1156
|
+
this.friendsEarlyBeforeAt = this.friendsEarlyAt;
|
|
1157
|
+
this.friendsEarlyAt = now;
|
|
1158
|
+
}
|
|
1159
|
+
this.together.asked(now);
|
|
1160
|
+
}
|
|
1055
1161
|
const key = this.sceneKey;
|
|
1056
1162
|
Promise.resolve(castleSdk.Hub.friends())
|
|
1057
1163
|
.then((answer) => {
|
|
@@ -1172,6 +1278,8 @@ class HubSystem {
|
|
|
1172
1278
|
this.startNear = null;
|
|
1173
1279
|
if (name) {
|
|
1174
1280
|
this.toast = { text: `You're next to ${name}`, until: now + TOAST_MS };
|
|
1281
|
+
// Cues: this friend has been told; "is here" would say it twice.
|
|
1282
|
+
this.besideTold = start.asked;
|
|
1175
1283
|
}
|
|
1176
1284
|
return;
|
|
1177
1285
|
}
|
|
@@ -1264,6 +1372,14 @@ class HubSystem {
|
|
|
1264
1372
|
if (invite) {
|
|
1265
1373
|
return { key: `invite:${invite.from}`, kind: 'invite', from: invite.from, text: `${invite.username ?? 'Someone'} invited you to their party`, yes: 'Join party', no: 'No thanks' };
|
|
1266
1374
|
}
|
|
1375
|
+
// Cues (v1.29): back from a game with nothing else asked -- the same game
|
|
1376
|
+
// again, with the party when there is one (the Doors list's own Go).
|
|
1377
|
+
const again = Hub.deck.cues ? this.againAsk : null;
|
|
1378
|
+
const door = again && performance.now() < again.until ? Hub.hub.doors.find((d) => d.id === again.door) : null;
|
|
1379
|
+
if (door) {
|
|
1380
|
+
const together = Hub.hub.party.members?.length && !door.solo;
|
|
1381
|
+
return { key: `again:${again.door}:${again.until}`, kind: 'again', door: door.id, text: `Play ${door.title ?? 'that'} again${together ? ' together' : ''}?`, yes: together ? 'Go together' : 'Play again', no: 'Not now' };
|
|
1382
|
+
}
|
|
1267
1383
|
return null;
|
|
1268
1384
|
}
|
|
1269
1385
|
|
|
@@ -1272,6 +1388,19 @@ class HubSystem {
|
|
|
1272
1388
|
if (!net || !ask) {
|
|
1273
1389
|
return;
|
|
1274
1390
|
}
|
|
1391
|
+
if (ask.kind === 'again') {
|
|
1392
|
+
// Only the offer that is up: one whose time ran out, or that a later
|
|
1393
|
+
// return replaced, is answered by nothing.
|
|
1394
|
+
const again = this.againAsk;
|
|
1395
|
+
if (!Hub.deck.cues || !again || ask.key !== `again:${again.door}:${again.until}` || performance.now() >= again.until) {
|
|
1396
|
+
return;
|
|
1397
|
+
}
|
|
1398
|
+
this.againAsk = null;
|
|
1399
|
+
if (yes) {
|
|
1400
|
+
this.goDoor(scene, Hub.hub.doors.find((d) => d.id === again.door));
|
|
1401
|
+
}
|
|
1402
|
+
return;
|
|
1403
|
+
}
|
|
1275
1404
|
if (ask.kind === 'play') {
|
|
1276
1405
|
// "Back soon" (no door on the question): OK stays, the other button
|
|
1277
1406
|
// goes to wait at the door.
|
|
@@ -1288,6 +1417,67 @@ class HubSystem {
|
|
|
1288
1417
|
net.send({ k: 'hub-party', op: yes ? 'go-yes' : 'go-no', id: ask.id });
|
|
1289
1418
|
} else {
|
|
1290
1419
|
net.send({ k: 'hub-party', op: yes ? 'accept' : 'decline', from: ask.from });
|
|
1420
|
+
if (Hub.deck.cues && yes) {
|
|
1421
|
+
// Cues: the party that comes of this is one the player joined.
|
|
1422
|
+
this.partyAccepted = { from: ask.from, username: Hub.hub.party.invite?.username ?? null, until: performance.now() + PARTY_ACCEPT_MS };
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
// Cues (v1.23): the friends found already in this layer are told to the
|
|
1428
|
+
// player ("amy is here") and pointed to, one at a time and never over
|
|
1429
|
+
// another toast -- the result line of a game just left, or "You're next to
|
|
1430
|
+
// amy", which says it already.
|
|
1431
|
+
cueHere(now) {
|
|
1432
|
+
const waiting = [];
|
|
1433
|
+
for (const who of this.hereCues) {
|
|
1434
|
+
// Gone, or no longer a friend the player can see, since it was queued:
|
|
1435
|
+
// nothing is said of someone who is not here.
|
|
1436
|
+
if (this.besideTold === who.playerId || now > who.until || !this.together.close(who.playerId)) {
|
|
1437
|
+
continue;
|
|
1438
|
+
}
|
|
1439
|
+
// A start beside a friend still to be asked for, or asked for this one:
|
|
1440
|
+
// its own toast may be about to say it.
|
|
1441
|
+
if ((this.startNear && (!this.startNear.asked || this.startNear.asked === who.playerId)) || now < this.toast.until) {
|
|
1442
|
+
waiting.push(who);
|
|
1443
|
+
continue;
|
|
1444
|
+
}
|
|
1445
|
+
this.toast = { text: `${who.username ?? 'A friend'} is here · People to join`, until: now + TOAST_MS };
|
|
1446
|
+
this.together.ping(who.playerId, now, true);
|
|
1447
|
+
}
|
|
1448
|
+
this.hereCues = waiting;
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
// Cues (v1.23): a party that gained someone says so -- "You joined amy's
|
|
1452
|
+
// party" to the one who accepted, "bo joined your party" to the rest. Not
|
|
1453
|
+
// the party a session is first told of (the player had it already), and
|
|
1454
|
+
// not a member back from a game (one fewer is away).
|
|
1455
|
+
cueParty(net, now) {
|
|
1456
|
+
if (this.trip) {
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
const cur = Hub.hub.party;
|
|
1460
|
+
const prev = this.partyLast;
|
|
1461
|
+
this.partyLast = { members: cur.members ? [...cur.members] : null, away: cur.away };
|
|
1462
|
+
if (!prev || now < this.partySettleUntil) {
|
|
1463
|
+
return;
|
|
1464
|
+
}
|
|
1465
|
+
const gained = (cur.members ?? []).filter((id) => !prev.members?.includes(id));
|
|
1466
|
+
if (!gained.length || cur.away < prev.away) {
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
if (!prev.members && now < this.partyCarryUntil) {
|
|
1470
|
+
this.partyCarryUntil = 0;
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
const accepted = this.partyAccepted;
|
|
1474
|
+
this.partyAccepted = null;
|
|
1475
|
+
const nameOf = (playerId) => net?.others?.().get(playerId) || null;
|
|
1476
|
+
if (accepted && now < accepted.until && cur.members.includes(accepted.from)) {
|
|
1477
|
+
const name = accepted.username ?? nameOf(accepted.from);
|
|
1478
|
+
this.toast = { text: name ? `You joined ${name}'s party` : 'You joined the party', until: now + TOAST_MS };
|
|
1479
|
+
} else {
|
|
1480
|
+
this.toast = { text: `${nameOf(gained[0]) ?? 'Someone'} joined your party`, until: now + TOAST_MS };
|
|
1291
1481
|
}
|
|
1292
1482
|
}
|
|
1293
1483
|
|
|
@@ -1866,6 +2056,11 @@ class HubSystem {
|
|
|
1866
2056
|
faceArrival(scene) {
|
|
1867
2057
|
if (Hub.hub.arrivedFacing !== null) {
|
|
1868
2058
|
scene.persistent.camAngle = Math.PI - Hub.hub.arrivedFacing;
|
|
2059
|
+
// Under the engine's orbit camera key the character's facing is not
|
|
2060
|
+
// PI - camAngle: it is asked for.
|
|
2061
|
+
if (scene.cameraControl === 'orbit') {
|
|
2062
|
+
scene.faceRequest = Hub.hub.arrivedFacing;
|
|
2063
|
+
}
|
|
1869
2064
|
Hub.hub.faced = true;
|
|
1870
2065
|
}
|
|
1871
2066
|
}
|
|
@@ -1914,6 +2109,11 @@ class HubSystem {
|
|
|
1914
2109
|
if (trip.target.arrive?.returning && r) {
|
|
1915
2110
|
this.toast = { text: `Back from ${resultLine(r)}`, until: performance.now() + TOAST_MS };
|
|
1916
2111
|
}
|
|
2112
|
+
if (Hub.deck.cues && trip.target.arrive?.returning && trip.target.arrive.door) {
|
|
2113
|
+
// Cues: a next step, put once the player is back in the town, whether
|
|
2114
|
+
// or not the game had a result to tell.
|
|
2115
|
+
this.againAsk = { door: trip.target.arrive.door, until: performance.now() + AGAIN_ASK_MS };
|
|
2116
|
+
}
|
|
1917
2117
|
}
|
|
1918
2118
|
|
|
1919
2119
|
// Swing a door leaf open by `amount` (0 shut, 1 open) about its left edge,
|
|
@@ -1976,9 +2176,21 @@ class HubSystem {
|
|
|
1976
2176
|
}
|
|
1977
2177
|
// A friend or party member who just came in: say so, and point to them.
|
|
1978
2178
|
for (const who of town ? this.together.arrivals() : []) {
|
|
2179
|
+
// Cues: one who was here already (`here`, never set without cues)
|
|
2180
|
+
// waits its turn in `cueHere`.
|
|
2181
|
+
if (who.here) {
|
|
2182
|
+
this.hereCues.push({ ...who, until: now + HERE_CUE_MS });
|
|
2183
|
+
continue;
|
|
2184
|
+
}
|
|
1979
2185
|
this.toast = { text: `${who.username ?? 'A friend'} is here · People to join`, until: now + TOAST_MS };
|
|
1980
2186
|
this.together.ping(who.playerId, now, true);
|
|
1981
2187
|
}
|
|
2188
|
+
if (Hub.deck.cues && town) {
|
|
2189
|
+
this.cueHere(now);
|
|
2190
|
+
}
|
|
2191
|
+
if (Hub.deck.cues && place !== null && !inGame) {
|
|
2192
|
+
this.cueParty(scene.multiplayer?.net, now);
|
|
2193
|
+
}
|
|
1982
2194
|
// Quick reactions and phrases, in every place; what was said, as bubbles
|
|
1983
2195
|
// (below, with the labels) and a short feed.
|
|
1984
2196
|
const net = scene.multiplayer?.net;
|
|
@@ -2000,6 +2212,22 @@ class HubSystem {
|
|
|
2000
2212
|
this.playAsk = { from: playerId, name, door, until: now + PLAY_ASK_MS };
|
|
2001
2213
|
},
|
|
2002
2214
|
);
|
|
2215
|
+
// Cues: someone new in the roster may be one this player can chat with,
|
|
2216
|
+
// so the host is asked soon, not at the end of its idle wait. In a town
|
|
2217
|
+
// only, like every cue: a game behind one of its doors is drawn by this
|
|
2218
|
+
// client too, and is left exactly as it was.
|
|
2219
|
+
const cuesHere = Hub.deck.cues && place !== null && !inGame;
|
|
2220
|
+
if (cuesHere) {
|
|
2221
|
+
const here = new Set(net?.others?.().keys() ?? []);
|
|
2222
|
+
let fresh = false;
|
|
2223
|
+
for (const playerId of here) {
|
|
2224
|
+
fresh ||= !this.rosterSeen.has(playerId);
|
|
2225
|
+
}
|
|
2226
|
+
this.rosterSeen = here;
|
|
2227
|
+
if (fresh) {
|
|
2228
|
+
this.chat.soon(now);
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2003
2231
|
// Free-text chat, where the host has it: ghost says whom this player may
|
|
2004
2232
|
// chat with (they follow each other and both are over 13); the kit only
|
|
2005
2233
|
// shows what it is handed.
|
|
@@ -2033,6 +2261,15 @@ class HubSystem {
|
|
|
2033
2261
|
const chatPart = this.chat.available() && this.chat.peers !== null
|
|
2034
2262
|
? { input: this.chat.canChat && reach.length > 0, note: chatNote }
|
|
2035
2263
|
: null;
|
|
2264
|
+
// Cues: the field itself says who reads a line, or in a few words why it
|
|
2265
|
+
// cannot be used (the note has the long form).
|
|
2266
|
+
if (chatPart && cuesHere) {
|
|
2267
|
+
if (!chatPart.input) {
|
|
2268
|
+
chatPart.note = CHAT_HINT.why;
|
|
2269
|
+
}
|
|
2270
|
+
chatPart.placeholder = chatPart.input ? CHAT_HINT.on : CHAT_HINT.off;
|
|
2271
|
+
chatPart.label = chatPart.input ? CHAT_HINT.label : CHAT_HINT.why;
|
|
2272
|
+
}
|
|
2036
2273
|
chrome.setSay?.(free ? { reactions: REACTIONS, phrases: this.say.phrases(), chat: chatPart } : null);
|
|
2037
2274
|
chrome.setFeed?.(idle && place !== null ? this.say.feed() : []);
|
|
2038
2275
|
// Standing still beside someone: a small button invites them.
|
|
@@ -2058,6 +2295,12 @@ class HubSystem {
|
|
|
2058
2295
|
} else if (spec?.timer?.until !== undefined) {
|
|
2059
2296
|
timer = Math.max(0, (spec.timer.until - Hub.simNow()) / 1000);
|
|
2060
2297
|
}
|
|
2298
|
+
// A place that asks (`hud.clear`, v1.26) has its HUD kept short and its
|
|
2299
|
+
// labels kept out from under it; any other is drawn as it always was.
|
|
2300
|
+
if (place?.hud?.clear === true || this.hudClear) {
|
|
2301
|
+
this.hudClear = place?.hud?.clear === true;
|
|
2302
|
+
chrome.setHudClear?.(this.hudClear);
|
|
2303
|
+
}
|
|
2061
2304
|
chrome.setHud(idle || this.trip?.phase === 'revealing' ? spec : null, timer);
|
|
2062
2305
|
|
|
2063
2306
|
const cam = scene.three?.camera;
|
|
@@ -2127,6 +2370,11 @@ class HubSystem {
|
|
|
2127
2370
|
const showRibbon = !inGame && idle && r && Date.now() - r.at < RIBBON_MS && lt && cam;
|
|
2128
2371
|
chrome.setRibbon(showRibbon ? project(cam, lt.x, lt.y + 1.7, lt.z, view) : null, r ? `🏅 ${resultLine(r)}` : '');
|
|
2129
2372
|
chrome.setToast(now < this.toast.until ? this.toast.text : '');
|
|
2373
|
+
// A clear HUD (v1.26): everything drawn above is measured, then moved
|
|
2374
|
+
// out from under it, once for the frame. Never said in any other place.
|
|
2375
|
+
if (this.hudClear) {
|
|
2376
|
+
chrome.flushHudClear?.();
|
|
2377
|
+
}
|
|
2130
2378
|
}
|
|
2131
2379
|
|
|
2132
2380
|
// The People list's rows. In a town: everyone here and the player's
|