castle-web-cli 0.4.228 → 0.4.230
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/agent-prompts.d.ts +11 -3
- package/dist/agent-prompts.js +153 -53
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +43 -33
- package/dist/api.d.ts +47 -2
- package/dist/api.js +85 -16
- package/dist/castle-host/host.d.ts +91 -0
- package/dist/castle-host/host.js +779 -3
- package/dist/castleJson.d.ts +59 -0
- package/dist/castleJson.js +267 -3
- package/dist/check.js +27 -1
- package/dist/cloudGit.d.ts +20 -1
- package/dist/cloudGit.js +267 -10
- package/dist/contentPack.d.ts +49 -0
- package/dist/contentPack.js +273 -0
- package/dist/devExperiments.d.ts +21 -0
- package/dist/devExperiments.js +139 -0
- package/dist/devHub.d.ts +55 -0
- package/dist/devHub.js +187 -0
- package/dist/devSessionChild.js +3 -1
- package/dist/devSessionServer.d.ts +14 -1
- package/dist/devSessionServer.js +229 -44
- package/dist/experimentAssignment.d.ts +15 -0
- package/dist/experimentAssignment.js +41 -0
- package/dist/importCheckHook.d.ts +40 -0
- package/dist/importCheckHook.js +171 -0
- package/dist/importRegression.d.ts +15 -0
- package/dist/importRegression.js +100 -0
- package/dist/importTrust.d.ts +2 -0
- package/dist/importTrust.js +27 -0
- package/dist/importUpdateHook.d.ts +18 -0
- package/dist/importUpdateHook.js +31 -8
- package/dist/importUpdateHookRunner.js +19 -7
- package/dist/imports.d.ts +16 -0
- package/dist/imports.js +145 -33
- package/dist/index.js +8 -1
- package/dist/init.d.ts +3 -0
- package/dist/init.js +125 -8
- package/dist/install.js +4 -1
- package/dist/localPaths.js +4 -0
- package/dist/login.js +2 -2
- package/dist/platformDoc.js +3 -8
- package/dist/playPagePolicy.js +3 -1
- package/dist/remix.js +5 -0
- package/dist/routerTaskReport.d.ts +28 -0
- package/dist/routerTaskReport.js +56 -0
- package/dist/save-deck.d.ts +18 -0
- package/dist/save-deck.js +145 -6
- package/dist/serve.d.ts +8 -0
- package/dist/serve.js +94 -13
- package/dist/serverBundle.d.ts +1 -1
- package/dist/serverBundle.js +5 -1
- package/dist/sourceLineage.d.ts +42 -0
- package/dist/sourceLineage.js +380 -0
- package/dist/webSourceSync.d.ts +11 -0
- package/dist/webSourceSync.js +26 -9
- package/kits/base/CLAUDE.md +2 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +301 -52
- package/kits/base/sdk/agent.js +4 -4
- package/kits/base/sdk/avatar.d.ts +12 -0
- package/kits/base/sdk/avatar.js +23 -0
- package/kits/base/sdk/castle.d.ts +6 -1
- package/kits/base/sdk/castle.js +3 -0
- package/kits/base/sdk/commands.d.ts +208 -0
- package/kits/base/sdk/commands.js +16 -0
- package/kits/base/sdk/context.d.ts +6 -0
- package/kits/base/sdk/experiments.d.ts +15 -0
- package/kits/base/sdk/experiments.js +83 -0
- package/kits/base/sdk/hub.d.ts +85 -0
- package/kits/base/sdk/hub.js +107 -0
- package/kits/base/sdk/multiplayer.d.ts +86 -6
- package/kits/base/sdk/multiplayer.js +157 -4
- package/kits/base/sdk/server/hub.d.ts +169 -0
- package/kits/base/sdk/server/hub.js +125 -0
- package/kits/base/sdk/server/platformHandle.d.ts +49 -2
- package/kits/base/sdk/server/storage.d.ts +55 -2
- package/kits/base/sdk/server/wrapper.d.ts +85 -6
- package/kits/base/sdk/server/wrapper.js +393 -30
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +13 -1
- package/kits/hub-game/.prettierrc +5 -0
- package/kits/hub-game/CLAUDE.md +146 -0
- package/kits/hub-game/blueprints/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
- package/kits/hub-game/castle.json +96 -0
- package/kits/hub-game/code/client/attention.js +133 -0
- package/kits/hub-game/code/client/avatar.js +288 -0
- package/kits/hub-game/code/client/cabinets.js +90 -0
- package/kits/hub-game/code/client/chat.js +135 -0
- package/kits/hub-game/code/client/chrome.js +1001 -0
- package/kits/hub-game/code/client/doorFrame.js +15 -0
- package/kits/hub-game/code/client/firstJoin.js +14 -0
- package/kits/hub-game/code/client/grab.js +241 -0
- package/kits/hub-game/code/client/hookLayer.js +230 -0
- package/kits/hub-game/code/client/idle.js +326 -0
- package/kits/hub-game/code/client/keys.js +48 -0
- package/kits/hub-game/code/client/pack.js +232 -0
- package/kits/hub-game/code/client/packFormat.js +397 -0
- package/kits/hub-game/code/client/say.js +127 -0
- package/kits/hub-game/code/client/sha256.js +80 -0
- package/kits/hub-game/code/client/sound.js +147 -0
- package/kits/hub-game/code/client/state.js +131 -0
- package/kits/hub-game/code/client/talk.js +259 -0
- package/kits/hub-game/code/client/together.js +365 -0
- package/kits/hub-game/code/client/wear.js +149 -0
- package/kits/hub-game/code/server/actors.js +627 -0
- package/kits/hub-game/code/server/blocks.js +103 -0
- package/kits/hub-game/code/server/cabinets.js +309 -0
- package/kits/hub-game/code/server/game.js +137 -0
- package/kits/hub-game/code/server/grab.js +247 -0
- package/kits/hub-game/code/server/history.js +96 -0
- package/kits/hub-game/code/server/hub.js +1904 -0
- package/kits/hub-game/code/server/idle.js +412 -0
- package/kits/hub-game/code/server/index.js +64 -0
- package/kits/hub-game/code/server/labels.js +59 -0
- package/kits/hub-game/code/server/manifest.js +527 -0
- package/kits/hub-game/code/server/npcs.js +745 -0
- package/kits/hub-game/code/server/party.js +381 -0
- package/kits/hub-game/code/server/place.js +43 -0
- package/kits/hub-game/code/server/say.js +83 -0
- package/kits/hub-game/code/server/wear.js +142 -0
- package/kits/hub-game/code/systems/hub.js +2230 -0
- package/kits/hub-game/docs/content-pack.md +151 -0
- package/kits/hub-game/docs/contract.md +1139 -0
- package/kits/hub-game/docs/style.md +137 -0
- package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
- package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
- package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
- package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
- package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
- package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
- package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
- package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
- package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
- package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
- package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
- package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
- package/kits/hub-game/eslint.config.js +20 -0
- package/kits/hub-game/fonts.generated.js +9 -0
- package/kits/hub-game/index.html +22 -0
- package/kits/hub-game/main.jsx +6 -0
- package/kits/hub-game/models/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/avatar-2.pxmodel +27 -0
- package/kits/hub-game/models/avatar-3.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
- package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
- package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
- package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
- package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
- package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
- package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
- package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
- package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
- package/kits/hub-game/package-lock.json +365 -0
- package/kits/hub-game/package.json +32 -0
- package/kits/hub-game/scenes/main.scene +318 -0
- package/kits/hub-game/scripts/check.mjs +339 -0
- package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
- package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
- package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
- package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
- package/kits/hub-game/scripts/pack.mjs +192 -0
- package/kits/hub-game/scripts/test-actors.mjs +666 -0
- package/kits/hub-game/scripts/test-attention.mjs +103 -0
- package/kits/hub-game/scripts/test-avatar.mjs +472 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
- package/kits/hub-game/scripts/test-blocks.mjs +351 -0
- package/kits/hub-game/scripts/test-chat.mjs +98 -0
- package/kits/hub-game/scripts/test-classic.mjs +590 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
- package/kits/hub-game/scripts/test-door.mjs +56 -0
- package/kits/hub-game/scripts/test-grab.mjs +331 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +1310 -0
- package/kits/hub-game/scripts/test-idle.mjs +518 -0
- package/kits/hub-game/scripts/test-interest.mjs +413 -0
- package/kits/hub-game/scripts/test-keys.mjs +50 -0
- package/kits/hub-game/scripts/test-manifest.mjs +224 -0
- package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
- package/kits/hub-game/scripts/test-npcs.mjs +714 -0
- package/kits/hub-game/scripts/test-pack.mjs +424 -0
- package/kits/hub-game/scripts/test-party.mjs +286 -0
- package/kits/hub-game/scripts/test-say.mjs +149 -0
- package/kits/hub-game/scripts/test-together.mjs +183 -0
- package/kits/hub-game/theme.style +3 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +101 -1
- package/kits/multiplayer-3d/code/server/players.js +4 -1
- package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
- package/kits/multiplayer-3d/code/server/world.js +20 -7
- package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/art.js +13 -0
- package/kits/physics-2d/engine/assets.js +4 -2
- package/kits/physics-2d/engine/scene.js +25 -5
- package/kits/physics-3d/CLAUDE.md +6 -1
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +32 -4
- package/kits/physics-3d/engine3d/artobjects.js +2 -2
- package/kits/physics-3d/engine3d/materials.js +29 -1
- package/kits/physics-3d/engine3d/world3d.js +65 -1
- package/kits/physics-3d/systems/physics3d.js +5 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +77 -7
- package/kits/real-time/code/client/gameHooks.js +63 -3
- package/kits/real-time/code/client/messages.js +7 -0
- package/kits/real-time/code/server/gameHooks.js +24 -0
- package/kits/real-time/code/server/session.js +390 -22
- package/package.json +2 -2
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
// Finding the people you came with, in a town (a place with no `result`): who
|
|
2
|
+
// of the players here is a friend, where each one is (asked of the place's
|
|
3
|
+
// server, `hub-where`), the rows the chrome's People list draws, and the
|
|
4
|
+
// pointers to the friends, and to anyone the player pressed Find on, who are
|
|
5
|
+
// too far away to see. A game draws none of it.
|
|
6
|
+
|
|
7
|
+
import { hub } from './state.js';
|
|
8
|
+
import { NAME_NEAR_M } from './attention.js';
|
|
9
|
+
|
|
10
|
+
// How often the place is asked where the tracked players are.
|
|
11
|
+
const WHERE_EVERY_MS = 1000;
|
|
12
|
+
// As many as the place answers about at once (`WHERE_MAX` on the server).
|
|
13
|
+
const TRACK_MAX = 12;
|
|
14
|
+
// Pointers on screen at once, nearest first.
|
|
15
|
+
const POINTERS_MAX = 3;
|
|
16
|
+
// A party's size (`PARTY_MAX` on the server), and how near someone must stand
|
|
17
|
+
// to be offered an invitation without opening the People list.
|
|
18
|
+
const PARTY_MAX = 8;
|
|
19
|
+
const NEAR_INVITE_M = 2.2;
|
|
20
|
+
// The invitation is offered after standing beside someone this long, for this long.
|
|
21
|
+
const NEAR_DWELL_MS = 1500;
|
|
22
|
+
const NEAR_OFFER_MS = 8000;
|
|
23
|
+
// How long an "Over here!" keeps the pointer on its speaker.
|
|
24
|
+
const PING_MS = 10000;
|
|
25
|
+
// A friend first seen this long after the session began has arrived (the
|
|
26
|
+
// ones here at the start were here already).
|
|
27
|
+
const ARRIVAL_AFTER_MS = 8000;
|
|
28
|
+
// The part of the screen an edge pointer keeps to: clear of the HUD above and
|
|
29
|
+
// the buttons below.
|
|
30
|
+
const EDGE = { side: 46, top: 84, bottom: 150 };
|
|
31
|
+
|
|
32
|
+
// `?hubFriends=all` on a page served from localhost: everyone here counts as
|
|
33
|
+
// a friend, since the dev serve has no host to say who is.
|
|
34
|
+
function devEveryone() {
|
|
35
|
+
try {
|
|
36
|
+
const { hostname, search } = globalThis.location ?? {};
|
|
37
|
+
return (hostname === 'localhost' || hostname === '127.0.0.1') && new URLSearchParams(search ?? '').get('hubFriends') === 'all';
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function makeTogether() {
|
|
44
|
+
const everyone = devEveryone();
|
|
45
|
+
let askedAt = -Infinity;
|
|
46
|
+
// playerId -> { userId, username, friend, party }: the friends and party
|
|
47
|
+
// members in this session and anyone being found, this frame
|
|
48
|
+
let tracked = new Map();
|
|
49
|
+
// Players the pointer is on because the player pressed Find on them.
|
|
50
|
+
const found = new Set();
|
|
51
|
+
// playerId -> until (page ms): a party member or friend who said "Over
|
|
52
|
+
// here!" gets the pointer for a little while, however near they are.
|
|
53
|
+
const pinged = new Map();
|
|
54
|
+
// The player stood beside, and since when (`beside`).
|
|
55
|
+
let near = { playerId: null, since: 0 };
|
|
56
|
+
// Every player seen in this session's roster (whether they came in after
|
|
57
|
+
// its first moments, and whether they have been announced), and the
|
|
58
|
+
// friends and party members who came in late, not yet told to the player.
|
|
59
|
+
const seen = new Map();
|
|
60
|
+
let seenSince = null;
|
|
61
|
+
const arrived = [];
|
|
62
|
+
// Where the last ask left off, when there are more players to ask about
|
|
63
|
+
// than one ask covers: they are worked through in turn.
|
|
64
|
+
let turn = 0;
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
// `friends` is the host's answer (`Hub.friends`: [{ userId, username,
|
|
68
|
+
// here, door? }]) or null. Marks who here is one, and asks the place
|
|
69
|
+
// where they, anyone being found and, while the People list is open, the
|
|
70
|
+
// rest of its rows are.
|
|
71
|
+
frame(mp, friends, active, now, listOpen = false) {
|
|
72
|
+
tracked = new Map();
|
|
73
|
+
const net = mp?.net;
|
|
74
|
+
if (!active || !net || !hub.place || hub.place.result) {
|
|
75
|
+
found.clear();
|
|
76
|
+
pinged.clear();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const ids = new Set((friends ?? []).map((f) => String(f.userId)));
|
|
80
|
+
const others = net.others?.() ?? new Map();
|
|
81
|
+
const rest = [];
|
|
82
|
+
for (const [playerId, username] of others) {
|
|
83
|
+
const userId = net.userId?.(playerId) ?? null;
|
|
84
|
+
const friend = everyone || Boolean(userId && ids.has(String(userId)));
|
|
85
|
+
const party = hub.party.members?.includes(playerId) === true;
|
|
86
|
+
if (friend || party || found.has(playerId)) {
|
|
87
|
+
tracked.set(playerId, { userId, username: username || null, friend, party });
|
|
88
|
+
} else {
|
|
89
|
+
rest.push(playerId);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// A friend or party member who turns up after the first moments here
|
|
93
|
+
// has arrived: the player is told (those already here were the start).
|
|
94
|
+
// When each player was first in the roster is kept apart from whether
|
|
95
|
+
// they are a friend: a friends answer that comes late must not announce
|
|
96
|
+
// someone who was here all along.
|
|
97
|
+
seenSince ??= now;
|
|
98
|
+
for (const playerId of others.keys()) {
|
|
99
|
+
if (!seen.has(playerId)) {
|
|
100
|
+
seen.set(playerId, { late: now - seenSince > ARRIVAL_AFTER_MS, told: false });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
for (const [playerId, t] of tracked) {
|
|
104
|
+
const first = seen.get(playerId);
|
|
105
|
+
if ((t.friend || t.party) && first && !first.told) {
|
|
106
|
+
first.told = true;
|
|
107
|
+
if (first.late) {
|
|
108
|
+
arrived.push({ playerId, username: t.username });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
for (const playerId of seen.keys()) {
|
|
113
|
+
if (!others.has(playerId)) {
|
|
114
|
+
seen.delete(playerId);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const playerId of found) {
|
|
118
|
+
if (!others.has(playerId)) {
|
|
119
|
+
found.delete(playerId);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (const [playerId, until] of pinged) {
|
|
123
|
+
if (!others.has(playerId) || until <= now) {
|
|
124
|
+
pinged.delete(playerId);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
for (const playerId of Object.keys(hub.whereAt)) {
|
|
128
|
+
if (!others.has(playerId)) {
|
|
129
|
+
delete hub.whereAt[playerId];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (now - askedAt < WHERE_EVERY_MS || (!tracked.size && !(listOpen && rest.length))) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
askedAt = now;
|
|
136
|
+
// More than one ask covers: each ask takes the next twelve in turn.
|
|
137
|
+
const all = listOpen ? [...tracked.keys(), ...rest] : [...tracked.keys()];
|
|
138
|
+
turn = turn >= all.length ? 0 : turn;
|
|
139
|
+
net.send({ k: 'hub-where', ids: all.slice(turn, turn + TRACK_MAX) });
|
|
140
|
+
turn += all.length > TRACK_MAX ? TRACK_MAX : 0;
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
// A new place: nobody is being found or has called.
|
|
144
|
+
clear() {
|
|
145
|
+
found.clear();
|
|
146
|
+
pinged.clear();
|
|
147
|
+
tracked = new Map();
|
|
148
|
+
near = { playerId: null, since: 0 };
|
|
149
|
+
seen.clear();
|
|
150
|
+
seenSince = null;
|
|
151
|
+
arrived.length = 0;
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
// The friends and party members who arrived since this was last asked.
|
|
155
|
+
arrivals: () => arrived.splice(0),
|
|
156
|
+
|
|
157
|
+
// Whom a player who just came in should start beside: a party member
|
|
158
|
+
// here first, else the first friend here in the host's order (ghost lists
|
|
159
|
+
// the most recently active first); `{ playerId, username }` or null.
|
|
160
|
+
startBeside() {
|
|
161
|
+
let friend = null;
|
|
162
|
+
for (const [playerId, t] of tracked) {
|
|
163
|
+
if (t.party) {
|
|
164
|
+
return { playerId, username: t.username };
|
|
165
|
+
}
|
|
166
|
+
if (t.friend && !friend) {
|
|
167
|
+
friend = { playerId, username: t.username };
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return friend;
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
// "Over here!" from a party member or a friend: the pointer goes to them.
|
|
174
|
+
ping(playerId, now, always = false) {
|
|
175
|
+
if (always || tracked.get(playerId)?.party || tracked.get(playerId)?.friend) {
|
|
176
|
+
pinged.set(playerId, now + PING_MS);
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
// Find, from the People list: the pointer goes on that player, or off.
|
|
181
|
+
find(playerId) {
|
|
182
|
+
if (!found.delete(playerId)) {
|
|
183
|
+
found.add(playerId);
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
// The People list's rows: the player's party first, then friends (here,
|
|
188
|
+
// then elsewhere), then everyone else here. Each has `actions`, the first
|
|
189
|
+
// the one drawn beside the name: Join goes to a party member or a friend
|
|
190
|
+
// (`goto` here, `jump` to another layer, `door` to the game they are
|
|
191
|
+
// in), Invite asks someone into the party, Find points the way to them.
|
|
192
|
+
// `canReport` is whether the host takes reports.
|
|
193
|
+
rows(mp, friends, canReport) {
|
|
194
|
+
const net = mp?.net;
|
|
195
|
+
const town = Boolean(hub.place && !hub.place.result);
|
|
196
|
+
const members = hub.party.members;
|
|
197
|
+
const room = !members || members.length + hub.party.away + 1 < PARTY_MAX;
|
|
198
|
+
const here = [];
|
|
199
|
+
const seen = new Set();
|
|
200
|
+
for (const [playerId, username] of net?.others?.() ?? []) {
|
|
201
|
+
const userId = net.userId?.(playerId) ?? null;
|
|
202
|
+
if (userId) {
|
|
203
|
+
seen.add(String(userId));
|
|
204
|
+
}
|
|
205
|
+
const t = town ? tracked.get(playerId) : null;
|
|
206
|
+
const actions = [];
|
|
207
|
+
if (t?.party || t?.friend) {
|
|
208
|
+
actions.push({ id: 'goto', text: 'Join' });
|
|
209
|
+
}
|
|
210
|
+
// Anyone standing on or by a door can be gone to the way Doors > Go
|
|
211
|
+
// goes: to that door's pad, which is no more than the Doors list offers.
|
|
212
|
+
const spot = town ? hub.whereAt[playerId] : null;
|
|
213
|
+
if (!t?.party && !t?.friend && spot?.door && hub.doors.some((d) => d.id === spot.door)) {
|
|
214
|
+
actions.push({ id: 'door', text: 'Go there' });
|
|
215
|
+
}
|
|
216
|
+
if (town && !t?.party) {
|
|
217
|
+
if (room) {
|
|
218
|
+
actions.push({ id: 'invite', text: 'Invite' });
|
|
219
|
+
}
|
|
220
|
+
if (!t?.friend) {
|
|
221
|
+
actions.push({ id: 'find', text: found.has(playerId) ? 'Stop' : 'Find' });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (canReport && userId) {
|
|
225
|
+
actions.push({ id: 'report', text: 'Report' });
|
|
226
|
+
}
|
|
227
|
+
here.push({
|
|
228
|
+
key: `p:${playerId}`,
|
|
229
|
+
playerId,
|
|
230
|
+
userId,
|
|
231
|
+
username: username || null,
|
|
232
|
+
rank: t?.party ? 0 : t?.friend ? 1 : 3,
|
|
233
|
+
mark: t?.party ? '● ' : t?.friend ? '★ ' : '',
|
|
234
|
+
where: town ? (hub.whereAt[playerId]?.where ?? 'in town') : null,
|
|
235
|
+
actions,
|
|
236
|
+
door: spot?.door ?? null,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
for (const f of town ? (friends ?? []) : []) {
|
|
240
|
+
if (!f?.userId || seen.has(String(f.userId))) {
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
// In a game behind one of this town's doors (a host that says so), or
|
|
244
|
+
// in another layer of the town.
|
|
245
|
+
const door = typeof f.door === 'string' ? hub.doors.find((d) => d.id === f.door) : null;
|
|
246
|
+
if (typeof f.door === 'string' && !door) {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
here.push({
|
|
250
|
+
key: `u:${f.userId}`,
|
|
251
|
+
playerId: null,
|
|
252
|
+
userId: String(f.userId),
|
|
253
|
+
username: f.username ?? null,
|
|
254
|
+
rank: 2,
|
|
255
|
+
mark: '★ ',
|
|
256
|
+
where: door ? `inside ${door.title ?? 'a game'}` : 'in another part of town',
|
|
257
|
+
actions: [{ id: door ? 'door' : 'jump', text: 'Join' }],
|
|
258
|
+
door: door?.id ?? null,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
// A stable sort: each group keeps the roster's order.
|
|
262
|
+
return here.sort((a, b) => a.rank - b.rank);
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
// The line over the People list for a player in a party, or null.
|
|
266
|
+
partyLine() {
|
|
267
|
+
const members = hub.party.members;
|
|
268
|
+
if (!members) {
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
const away = hub.party.away;
|
|
272
|
+
return `Your party · ${members.length + 1} here${away ? ` · ${away} in a game` : ''}`;
|
|
273
|
+
},
|
|
274
|
+
|
|
275
|
+
// The player stood beside (within `NEAR_INVITE_M`, their avatar drawn)
|
|
276
|
+
// who could be invited into the party: `{ playerId, username }`, or null.
|
|
277
|
+
// Offered only after standing by them a moment, and not for long: a
|
|
278
|
+
// button for everyone walked past, or one that never leaves, is clutter.
|
|
279
|
+
beside(scene, local, now = performance.now()) {
|
|
280
|
+
const lt = local?.components.Transform;
|
|
281
|
+
const mp = scene.multiplayer;
|
|
282
|
+
const members = hub.party.members;
|
|
283
|
+
if (!lt || !hub.place || hub.place.result || (members && members.length + hub.party.away + 1 >= PARTY_MAX)) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
let best = null;
|
|
287
|
+
for (const [playerId, username] of mp?.net?.others?.() ?? []) {
|
|
288
|
+
const actorId = mp.avatars?.actors?.get(playerId);
|
|
289
|
+
const at = actorId ? scene.getActor(actorId)?.components.Transform : null;
|
|
290
|
+
const d = at ? Math.hypot(at.x - lt.x, at.z - lt.z) : Infinity;
|
|
291
|
+
if (d <= NEAR_INVITE_M && !members?.includes(playerId) && (!best || d < best.d)) {
|
|
292
|
+
best = { d, playerId, username: username || null };
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (best?.playerId !== near.playerId) {
|
|
296
|
+
near = { playerId: best?.playerId ?? null, since: now };
|
|
297
|
+
}
|
|
298
|
+
const stood = now - near.since;
|
|
299
|
+
return best && stood >= NEAR_DWELL_MS && stood < NEAR_DWELL_MS + NEAR_OFFER_MS ? best : null;
|
|
300
|
+
},
|
|
301
|
+
|
|
302
|
+
// Where each friend here is on screen, for the ones too far to read a
|
|
303
|
+
// name over: `{ id, x, y, text, angle }` in CSS pixels, `angle` (radians,
|
|
304
|
+
// screen space) set when the friend is off screen and the chip sits at
|
|
305
|
+
// the edge pointing their way.
|
|
306
|
+
pointers(scene, local, cam, view) {
|
|
307
|
+
const lt = local?.components.Transform;
|
|
308
|
+
if (!lt || !cam || !tracked.size) {
|
|
309
|
+
return [];
|
|
310
|
+
}
|
|
311
|
+
const mp = scene.multiplayer;
|
|
312
|
+
const far = [];
|
|
313
|
+
for (const [playerId, { username }] of tracked) {
|
|
314
|
+
const actorId = mp?.avatars?.actors?.get(playerId);
|
|
315
|
+
const drawn = actorId ? scene.getActor(actorId)?.components.Transform : null;
|
|
316
|
+
const at = drawn ?? hub.whereAt[playerId];
|
|
317
|
+
if (!at) {
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
const d = Math.hypot(at.x - lt.x, at.z - lt.z);
|
|
321
|
+
if (d > NAME_NEAR_M || pinged.has(playerId)) {
|
|
322
|
+
far.push({ playerId, username, at, d });
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
far.sort((a, b) => a.d - b.d);
|
|
326
|
+
const out = [];
|
|
327
|
+
for (const { playerId, username, at, d } of far.slice(0, POINTERS_MAX)) {
|
|
328
|
+
out.push(pointerAt(cam, view, { x: at.x, y: (at.y ?? lt.y) + 1.9, z: at.z }, `to:${playerId}`, `${username ?? 'friend'} · ${Math.round(d)} m`));
|
|
329
|
+
}
|
|
330
|
+
return out;
|
|
331
|
+
},
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// One pointer at a point in the world: over it while it is on the clear part
|
|
336
|
+
// of the screen (`angle` null), else at the screen's edge along the way to it
|
|
337
|
+
// as the camera sees it. Friends (above) and a place's goal labels
|
|
338
|
+
// (`hub.label` with `style: "goal"`, contract v1.13) are drawn by it.
|
|
339
|
+
export function pointerAt(cam, view, at, id, text) {
|
|
340
|
+
const v = cam.position.clone().set(at.x, at.y, at.z);
|
|
341
|
+
const inView = v.clone().applyMatrix4(cam.matrixWorldInverse);
|
|
342
|
+
const ndc = v.project(cam);
|
|
343
|
+
const x = ((ndc.x + 1) / 2) * view.w;
|
|
344
|
+
const y = ((1 - ndc.y) / 2) * view.h;
|
|
345
|
+
const onScreen = inView.z < 0 && x >= EDGE.side && x <= view.w - EDGE.side && y >= EDGE.top && y <= view.h - EDGE.bottom;
|
|
346
|
+
if (onScreen) {
|
|
347
|
+
return { id, x, y, text, angle: null };
|
|
348
|
+
}
|
|
349
|
+
let dx = inView.x;
|
|
350
|
+
let dy = -inView.y;
|
|
351
|
+
const len = Math.hypot(dx, dy);
|
|
352
|
+
if (len < 1e-6) {
|
|
353
|
+
dx = 0;
|
|
354
|
+
dy = 1;
|
|
355
|
+
} else {
|
|
356
|
+
dx /= len;
|
|
357
|
+
dy /= len;
|
|
358
|
+
}
|
|
359
|
+
const cx = view.w / 2;
|
|
360
|
+
const cy = (EDGE.top + view.h - EDGE.bottom) / 2;
|
|
361
|
+
const reachX = dx === 0 ? Infinity : (view.w / 2 - EDGE.side) / Math.abs(dx);
|
|
362
|
+
const reachY = dy === 0 ? Infinity : (dy < 0 ? cy - EDGE.top : view.h - EDGE.bottom - cy) / Math.abs(dy);
|
|
363
|
+
const reach = Math.min(reachX, reachY);
|
|
364
|
+
return { id, x: cx + dx * reach, y: cy + dy * reach, text, angle: Math.atan2(dy, dx) };
|
|
365
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// What players wear on their avatars (contract §11, v1.4): the place sends
|
|
2
|
+
// playerId -> { kind, color, rarity } (`hubWear`), and this draws each one as a
|
|
3
|
+
// few glowing, non-solid Shape actors that follow the avatar's Transform every
|
|
4
|
+
// frame -- this player's own body included. Kinds this kit does not draw are
|
|
5
|
+
// not drawn. A piece is `wear:<playerId>:<n>`; it is despawned when the
|
|
6
|
+
// wearable changes or goes, or the avatar does, and retired with the
|
|
7
|
+
// multiplayer kit so it is never reported to the session as gone.
|
|
8
|
+
|
|
9
|
+
// Heights from the avatar's origin, the capsule's centre. A halo sits just
|
|
10
|
+
// over the avatar's own top and an orbit circles it (`top`, metres above its
|
|
11
|
+
// model's feet), so a short avatar wears them as close as a tall one, under
|
|
12
|
+
// its name tag.
|
|
13
|
+
const FEET_Y = -0.85;
|
|
14
|
+
const MODEL_FEET_Y = -0.7;
|
|
15
|
+
const HALO_GAP = 0.15;
|
|
16
|
+
export const DEFAULT_TOP = 1.65;
|
|
17
|
+
const ORBIT_RADIUS = 0.5;
|
|
18
|
+
const COLOR = /^#[0-9a-f]{6}$/i;
|
|
19
|
+
const MAX_RARITY = 9;
|
|
20
|
+
|
|
21
|
+
function shape(kind, color, rarity, size) {
|
|
22
|
+
return {
|
|
23
|
+
kind,
|
|
24
|
+
...size,
|
|
25
|
+
color,
|
|
26
|
+
emissive: color,
|
|
27
|
+
emissiveIntensity: 0.6 + rarity * 0.15,
|
|
28
|
+
roughness: 0.4,
|
|
29
|
+
metalness: 0.1,
|
|
30
|
+
solid: false,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// The pieces of a wearable, each a Shape and where it sits relative to the
|
|
35
|
+
// avatar at time `t` (seconds). Null for a kind this kit does not draw.
|
|
36
|
+
export function pieces(wearable, top = DEFAULT_TOP) {
|
|
37
|
+
const color = typeof wearable?.color === 'string' && COLOR.test(wearable.color) ? wearable.color.toLowerCase() : null;
|
|
38
|
+
const rarity = Number.isInteger(wearable?.rarity) ? Math.min(MAX_RARITY, Math.max(0, wearable.rarity)) : 0;
|
|
39
|
+
if (!color) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const grow = 1 + rarity * 0.05;
|
|
43
|
+
switch (wearable.kind) {
|
|
44
|
+
case 'halo':
|
|
45
|
+
return [
|
|
46
|
+
{
|
|
47
|
+
shape: shape('cylinder', color, rarity, { radius: 0.35 * grow, height: 0.04 }),
|
|
48
|
+
at: (t) => ({ x: 0, y: MODEL_FEET_Y + top + HALO_GAP + Math.sin(t * 2) * 0.03, z: 0 }),
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
case 'aura':
|
|
52
|
+
return [
|
|
53
|
+
{
|
|
54
|
+
shape: shape('cylinder', color, rarity, { radius: 0.6 * grow, height: 0.02 }),
|
|
55
|
+
at: () => ({ x: 0, y: FEET_Y + 0.02, z: 0 }),
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
case 'orbit': {
|
|
59
|
+
const n = 1 + Math.floor(rarity / 3);
|
|
60
|
+
const speed = 1.6 + rarity * 0.1;
|
|
61
|
+
return Array.from({ length: n }, (_, i) => ({
|
|
62
|
+
shape: shape('sphere', color, rarity, { radius: 0.07 * grow }),
|
|
63
|
+
at: (t) => {
|
|
64
|
+
const a = t * speed + (i * 2 * Math.PI) / n;
|
|
65
|
+
return { x: Math.cos(a) * ORBIT_RADIUS, y: MODEL_FEET_Y + top + Math.sin(a * 2) * 0.05, z: Math.sin(a) * ORBIT_RADIUS };
|
|
66
|
+
},
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
default:
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function makeWear() {
|
|
75
|
+
// playerId -> { json, ids, pieces }
|
|
76
|
+
const drawn = new Map();
|
|
77
|
+
|
|
78
|
+
function remove(scene, playerId) {
|
|
79
|
+
const entry = drawn.get(playerId);
|
|
80
|
+
drawn.delete(playerId);
|
|
81
|
+
for (const id of entry?.ids ?? []) {
|
|
82
|
+
if (scene.getActor(id)) {
|
|
83
|
+
scene.multiplayer?.avatars?.retired?.add(id);
|
|
84
|
+
scene.despawnActor(id);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
// Spawn, move and remove pieces to match `wearing` (playerId -> wearable).
|
|
91
|
+
// `topOf(playerId)` is how tall that player's avatar stands.
|
|
92
|
+
frame(scene, local, wearing, topOf = () => DEFAULT_TOP, now = performance.now()) {
|
|
93
|
+
const mp = scene.multiplayer;
|
|
94
|
+
const self = mp?.net?.selfId?.() ?? null;
|
|
95
|
+
const t = now / 1000;
|
|
96
|
+
for (const playerId of [...drawn.keys()]) {
|
|
97
|
+
if (!wearing.has(playerId)) {
|
|
98
|
+
remove(scene, playerId);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
for (const [playerId, wearable] of wearing) {
|
|
102
|
+
const actorId = playerId === self ? local?.id : mp?.avatars?.actors?.get(playerId);
|
|
103
|
+
const at = actorId ? scene.getActor(actorId)?.components.Transform : null;
|
|
104
|
+
const top = topOf(playerId);
|
|
105
|
+
const json = `${top}:${JSON.stringify(wearable)}`;
|
|
106
|
+
if (!at || drawn.get(playerId)?.json !== json) {
|
|
107
|
+
remove(scene, playerId);
|
|
108
|
+
}
|
|
109
|
+
if (!at) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
let entry = drawn.get(playerId);
|
|
113
|
+
if (!entry) {
|
|
114
|
+
const parts = pieces(wearable, top) ?? [];
|
|
115
|
+
entry = { json, pieces: parts, ids: parts.map((_, n) => `wear:${playerId}:${n}`) };
|
|
116
|
+
drawn.set(playerId, entry);
|
|
117
|
+
entry.pieces.forEach((piece, n) => {
|
|
118
|
+
const p = piece.at(t);
|
|
119
|
+
scene.spawnActor({
|
|
120
|
+
id: entry.ids[n],
|
|
121
|
+
components: { Transform: { x: at.x + p.x, y: at.y + p.y, z: at.z + p.z }, Shape: { ...piece.shape } },
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
entry.pieces.forEach((piece, n) => {
|
|
126
|
+
const pt = scene.getActor(entry.ids[n])?.components.Transform;
|
|
127
|
+
if (pt) {
|
|
128
|
+
const p = piece.at(t);
|
|
129
|
+
pt.x = at.x + p.x;
|
|
130
|
+
pt.y = at.y + p.y;
|
|
131
|
+
pt.z = at.z + p.z;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
// A scene load took every piece with it: forget them.
|
|
138
|
+
forget() {
|
|
139
|
+
drawn.clear();
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
// A session switch that kept the scene: take every piece down.
|
|
143
|
+
clear(scene) {
|
|
144
|
+
for (const playerId of [...drawn.keys()]) {
|
|
145
|
+
remove(scene, playerId);
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|