castle-web-cli 0.4.229 → 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 +2 -0
- package/dist/agent-prompts.js +16 -8
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +21 -21
- package/dist/api.d.ts +28 -2
- package/dist/api.js +74 -16
- package/dist/castle-host/host.d.ts +91 -0
- package/dist/castle-host/host.js +779 -3
- package/dist/castleJson.d.ts +44 -0
- package/dist/castleJson.js +131 -0
- package/dist/check.js +27 -1
- 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 +141 -31
- package/dist/index.js +3 -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 +142 -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/webSourceSync.d.ts +2 -0
- package/dist/webSourceSync.js +2 -0
- package/kits/base/CLAUDE.md +2 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +258 -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 +5 -0
- 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 +45 -1
- package/kits/base/sdk/multiplayer.js +106 -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 +42 -1
- package/kits/base/sdk/server/storage.d.ts +55 -2
- package/kits/base/sdk/server/wrapper.d.ts +32 -2
- package/kits/base/sdk/server/wrapper.js +90 -11
- 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,288 @@
|
|
|
1
|
+
// The platform avatar seam (contract §11). A hub game never draws a player:
|
|
2
|
+
// the kit draws everyone, the local player included, from one of its avatar
|
|
3
|
+
// blueprints. Which one is this module's one question, `current`: the
|
|
4
|
+
// account's platform avatar, which ghost keeps and the host serves
|
|
5
|
+
// (`Avatar.get` / `Avatar.set` in the SDK), so it is the same in every place.
|
|
6
|
+
// Where there is none -- a signed-out visitor, a host or SDK from before
|
|
7
|
+
// avatars, a deck that is not a curated hub place (the dev serve) -- the pick kept in
|
|
8
|
+
// `scene.persistent` stands in, as it did before ghost had avatars. Nothing
|
|
9
|
+
// else in the kit or any game reads where it comes from.
|
|
10
|
+
|
|
11
|
+
import * as castleSdk from 'castle-web-sdk';
|
|
12
|
+
|
|
13
|
+
export const AVATARS = 4;
|
|
14
|
+
|
|
15
|
+
// The avatar sets. Each draws the same four avatar indexes in its own look:
|
|
16
|
+
// `toon` is the kit's first set and the default (`blueprints/avatar-<n>.scene`),
|
|
17
|
+
// the others live a directory down (`blueprints/<style>/avatar-<n>.scene`).
|
|
18
|
+
// Which set is drawn is the viewer's own question (`style`), never the
|
|
19
|
+
// place's: nothing about it goes over the wire.
|
|
20
|
+
export const STYLES = ['toon', 'blocky', 'bean', 'pixel'];
|
|
21
|
+
const DEFAULT_STYLE = 'toon';
|
|
22
|
+
const STYLE_EXPERIMENT = 'hub_avatar_style';
|
|
23
|
+
const STYLE_PARAM = 'hubStyle';
|
|
24
|
+
|
|
25
|
+
// How tall each avatar stands, feet to the top of its head or whatever is on
|
|
26
|
+
// it, in metres (`models/avatar-<n>.pxmodel`, `models/<style>/avatar-<n>.pxmodel`):
|
|
27
|
+
// what a player wears over one (`wear.js`) sits by it.
|
|
28
|
+
const TOPS = {
|
|
29
|
+
toon: [1.38, 1.5, 1.42, 1.56],
|
|
30
|
+
blocky: [1.45, 1.66, 1.6, 1.51],
|
|
31
|
+
bean: [1.37, 1.41, 1.7, 1.31],
|
|
32
|
+
pixel: [1.37, 1.44, 1.35, 1.54],
|
|
33
|
+
};
|
|
34
|
+
const DEFAULT_TOP = 1.65;
|
|
35
|
+
|
|
36
|
+
// Where the kit's blueprints are: inside the import in a deck, at the root
|
|
37
|
+
// while this kit is served as itself.
|
|
38
|
+
const ROOTS = ['imports/castle.hub-game/', ''];
|
|
39
|
+
|
|
40
|
+
// One per runtime: the iframe and engine stay up across every door, so this
|
|
41
|
+
// is read once and outlives every scene swap.
|
|
42
|
+
const platform = {
|
|
43
|
+
// 'idle' | 'loading' | 'ready' | 'none'
|
|
44
|
+
state: 'idle',
|
|
45
|
+
// The avatar ghost last confirmed.
|
|
46
|
+
confirmed: null,
|
|
47
|
+
// The player's latest pick, until ghost has it or refused it; worn meanwhile.
|
|
48
|
+
desired: null,
|
|
49
|
+
// The pick being written; one write at a time, so answers cannot cross.
|
|
50
|
+
writing: null,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// The SDK's Avatar, or null on an SDK from before it. Tests swap it.
|
|
54
|
+
let apiOverride;
|
|
55
|
+
function api() {
|
|
56
|
+
return apiOverride !== undefined ? apiOverride : (castleSdk.Avatar ?? null);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function usable(avatar) {
|
|
60
|
+
return Number.isInteger(avatar) && avatar >= 0 && avatar < AVATARS;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// There is no platform avatar here after all: a pick still waiting becomes
|
|
64
|
+
// the stand-in.
|
|
65
|
+
function standIn(scene) {
|
|
66
|
+
platform.state = 'none';
|
|
67
|
+
if (platform.desired !== null && scene) {
|
|
68
|
+
(scene.persistent ??= {}).hubAvatar = platform.desired;
|
|
69
|
+
}
|
|
70
|
+
platform.desired = null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Starts reading the platform avatar, once per runtime.
|
|
74
|
+
export function load(scene) {
|
|
75
|
+
if (platform.state !== 'idle') {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const Avatar = api();
|
|
79
|
+
if (!Avatar) {
|
|
80
|
+
standIn(scene);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
platform.state = 'loading';
|
|
84
|
+
Avatar.get().then(
|
|
85
|
+
(result) => {
|
|
86
|
+
if (result?.status === 'ok' && usable(result.avatar)) {
|
|
87
|
+
platform.state = 'ready';
|
|
88
|
+
platform.confirmed = result.avatar;
|
|
89
|
+
write(scene);
|
|
90
|
+
} else {
|
|
91
|
+
standIn(scene);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
(error) => {
|
|
95
|
+
console.warn('[hub] platform avatar unavailable:', error?.code ?? error);
|
|
96
|
+
standIn(scene);
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function current(scene) {
|
|
102
|
+
if (usable(platform.desired)) {
|
|
103
|
+
return platform.desired;
|
|
104
|
+
}
|
|
105
|
+
if (platform.state === 'ready' && usable(platform.confirmed)) {
|
|
106
|
+
return platform.confirmed;
|
|
107
|
+
}
|
|
108
|
+
const per = (scene.persistent ??= {});
|
|
109
|
+
if (!usable(per.hubAvatar)) {
|
|
110
|
+
per.hubAvatar = Math.floor(Math.random() * AVATARS);
|
|
111
|
+
}
|
|
112
|
+
return per.hubAvatar;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// The player picked an avatar. With a platform avatar it becomes the
|
|
116
|
+
// account's, everywhere: worn at once, written once the platform avatar is
|
|
117
|
+
// known, and undone if ghost refuses it. Without one it is this runtime's
|
|
118
|
+
// stand-in.
|
|
119
|
+
export function choose(scene, index) {
|
|
120
|
+
if (!usable(index)) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (platform.state === 'none' || !api()) {
|
|
124
|
+
(scene.persistent ??= {}).hubAvatar = index;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
platform.desired = index;
|
|
128
|
+
write(scene);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function write(scene) {
|
|
132
|
+
const Avatar = api();
|
|
133
|
+
if (
|
|
134
|
+
platform.state !== 'ready' ||
|
|
135
|
+
platform.writing !== null ||
|
|
136
|
+
platform.desired === null ||
|
|
137
|
+
!Avatar
|
|
138
|
+
) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const want = platform.desired;
|
|
142
|
+
platform.writing = want;
|
|
143
|
+
const done = (result) => {
|
|
144
|
+
platform.writing = null;
|
|
145
|
+
if (result?.status === 'ok' && usable(result.avatar)) {
|
|
146
|
+
platform.confirmed = result.avatar;
|
|
147
|
+
} else if (result?.status === 'unavailable') {
|
|
148
|
+
// This place may not change it (or the account is gone): the pick stays
|
|
149
|
+
// this runtime's own.
|
|
150
|
+
standIn(scene);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (platform.desired === want) {
|
|
154
|
+
platform.desired = null;
|
|
155
|
+
}
|
|
156
|
+
write(scene);
|
|
157
|
+
};
|
|
158
|
+
Avatar.set(want).then(done, (error) => {
|
|
159
|
+
console.warn('[hub] avatar not saved:', error?.code ?? error);
|
|
160
|
+
done(null);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Tests only.
|
|
165
|
+
export function resetPlatformForTests(api) {
|
|
166
|
+
apiOverride = api;
|
|
167
|
+
Object.assign(platform, { state: 'idle', confirmed: null, desired: null, writing: null });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Tests only: `{ location, experiment, experimentsReady }` in place of the
|
|
171
|
+
// page's location and the SDK's exports; nothing (or undefined) puts the real
|
|
172
|
+
// ones back.
|
|
173
|
+
let styleEnv;
|
|
174
|
+
export function resetStyleForTests(env) {
|
|
175
|
+
styleEnv = env;
|
|
176
|
+
experimentsAsked = false;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// The SDK is told once, before the first read, that this kit reads
|
|
180
|
+
// experiments: a read before the host has answered is then expected (it is
|
|
181
|
+
// null, and toon is drawn meanwhile) rather than warned about. Nothing waits
|
|
182
|
+
// on it.
|
|
183
|
+
let experimentsAsked = false;
|
|
184
|
+
function askExperiments() {
|
|
185
|
+
if (experimentsAsked) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
experimentsAsked = true;
|
|
189
|
+
try {
|
|
190
|
+
const ready = styleEnv ? styleEnv.experimentsReady : castleSdk.experimentsReady;
|
|
191
|
+
if (typeof ready === 'function') {
|
|
192
|
+
Promise.resolve(ready()).catch(() => {});
|
|
193
|
+
}
|
|
194
|
+
} catch {
|
|
195
|
+
// An SDK that cannot say when has no experiments to wait for.
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const LOCAL_HOSTS = new Set(['localhost', '127.0.0.1']);
|
|
200
|
+
|
|
201
|
+
// The set this viewer sees every player in, themselves included. A dev
|
|
202
|
+
// override first, `?hubStyle=<style>` on a page served from this machine;
|
|
203
|
+
// then the platform's experiment, on an SDK that has one (it answers at once:
|
|
204
|
+
// a string, or null until the host has answered); then toon. Anything that is not
|
|
205
|
+
// a set this kit has is toon too, so nothing changes until an experiment says
|
|
206
|
+
// so. Asked again every frame, so an answer that arrives late is followed.
|
|
207
|
+
export function style() {
|
|
208
|
+
const location = styleEnv ? styleEnv.location : globalThis.location;
|
|
209
|
+
try {
|
|
210
|
+
if (location && LOCAL_HOSTS.has(location.hostname)) {
|
|
211
|
+
const override = new URLSearchParams(location.search ?? '').get(STYLE_PARAM);
|
|
212
|
+
if (STYLES.includes(override)) {
|
|
213
|
+
return override;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
} catch {
|
|
217
|
+
// A location that cannot be read has no override.
|
|
218
|
+
}
|
|
219
|
+
askExperiments();
|
|
220
|
+
try {
|
|
221
|
+
const experiment = styleEnv ? styleEnv.experiment : castleSdk.experiment;
|
|
222
|
+
const variant = typeof experiment === 'function' ? experiment(STYLE_EXPERIMENT) : null;
|
|
223
|
+
if (STYLES.includes(variant)) {
|
|
224
|
+
return variant;
|
|
225
|
+
}
|
|
226
|
+
} catch {
|
|
227
|
+
// An SDK or host that cannot say leaves the default.
|
|
228
|
+
}
|
|
229
|
+
return DEFAULT_STYLE;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function directory(which) {
|
|
233
|
+
return which === DEFAULT_STYLE || !STYLES.includes(which) ? '' : `${which}/`;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function find(files, index, which) {
|
|
237
|
+
for (const root of ROOTS) {
|
|
238
|
+
const path = `${root}blueprints/${directory(which)}avatar-${index}.scene`;
|
|
239
|
+
if (typeof files?.[path] === 'string') {
|
|
240
|
+
return path;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// The set this avatar is really drawn from here: the one asked for where
|
|
247
|
+
// these files have its blueprint, else toon (an engine or a pack from before
|
|
248
|
+
// the set). Without files, the one asked for.
|
|
249
|
+
export function drawn(files, index, which = style()) {
|
|
250
|
+
const known = STYLES.includes(which) ? which : DEFAULT_STYLE;
|
|
251
|
+
return !files || find(files, index, known) ? known : DEFAULT_STYLE;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// How tall the avatar stands in a set, or a usual height for one this kit
|
|
255
|
+
// does not have.
|
|
256
|
+
export function top(index, which = style()) {
|
|
257
|
+
return usable(index) ? TOPS[STYLES.includes(which) ? which : DEFAULT_STYLE][index] : DEFAULT_TOP;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// The blueprint other players are drawn from, as a path the live files map
|
|
261
|
+
// has, or null before the files are known. A set these files do not have is
|
|
262
|
+
// drawn from toon's.
|
|
263
|
+
export function blueprint(files, index, which = style()) {
|
|
264
|
+
return find(files, index, which) ?? find(files, index, DEFAULT_STYLE);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// The model the local player wears: the one the avatar's blueprint draws.
|
|
268
|
+
export function model(files, index, which = style()) {
|
|
269
|
+
const path = blueprint(files, index, which);
|
|
270
|
+
if (!path) {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
const file = JSON.parse(files[path]).actors?.[0]?.components?.Model?.file ?? null;
|
|
275
|
+
if (typeof file !== 'string') {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
// A blueprint may name an import's file as `@imports/...`; the live files
|
|
279
|
+
// map keys it without the `@`. Any other path is the blueprint's own
|
|
280
|
+
// deck's: this kit's, wherever it is.
|
|
281
|
+
if (file.startsWith('@')) {
|
|
282
|
+
return file.slice(1);
|
|
283
|
+
}
|
|
284
|
+
return file.startsWith('imports/') ? file : path.slice(0, path.indexOf('blueprints/')) + file;
|
|
285
|
+
} catch {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Arcade cabinets on the client (contract v1.7): the place's server sends this
|
|
2
|
+
// player a cabinet's card when they come near it (`hub-cabinet`, one card a
|
|
3
|
+
// message, its pictures data URIs; server `cabinets.js` says why), kept here
|
|
4
|
+
// in `state.js`; the hub chrome draws the card of the cabinet this player
|
|
5
|
+
// stands nearest, over it: a chip with the best score, and the whole board
|
|
6
|
+
// when the player taps it (`chrome.js`).
|
|
7
|
+
|
|
8
|
+
import { hub } from './state.js';
|
|
9
|
+
|
|
10
|
+
// A card is drawn within this many metres of its cabinet, fading in over the
|
|
11
|
+
// last one and a half: three cabinets side by side never show three cards,
|
|
12
|
+
// and a player crossing the square past the arcade sees none.
|
|
13
|
+
export const NEAR_M = 5;
|
|
14
|
+
const FADE_M = 1.5;
|
|
15
|
+
// How far above its door actor (the screen) a card is anchored.
|
|
16
|
+
const CARD_LIFT_M = 0.95;
|
|
17
|
+
const IMAGE = /^data:image\//i;
|
|
18
|
+
|
|
19
|
+
// A `hub-cabinet` card, or its withdrawal (`card: null`).
|
|
20
|
+
export function receive(msg) {
|
|
21
|
+
if (typeof msg.actor !== 'string') {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
hub.cabinetsRev += 1;
|
|
25
|
+
if (!msg.card || typeof msg.card !== 'object') {
|
|
26
|
+
delete hub.cabinets[msg.actor];
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
hub.cabinets[msg.actor] = { door: msg.door ?? null, card: msg.card, rev: hub.cabinetsRev };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// A picture of a card as an image's `src`, or null: only ever a data URI of
|
|
33
|
+
// an image.
|
|
34
|
+
export function imageOf(value) {
|
|
35
|
+
return typeof value === 'string' && IMAGE.test(value) ? value : null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// The card to draw this frame: the nearest cabinet within NEAR_M of the
|
|
39
|
+
// player, where it is on screen, or null. `project` is the hub system's.
|
|
40
|
+
export function nearest(scene, at, cam, view, project) {
|
|
41
|
+
let best = null;
|
|
42
|
+
for (const [actorId, entry] of Object.entries(hub.cabinets)) {
|
|
43
|
+
const t = scene.getActor(actorId)?.components.Transform;
|
|
44
|
+
if (!t) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const d = Math.hypot(t.x - at.x, t.z - at.z);
|
|
48
|
+
if (d <= NEAR_M && (!best || d < best.d)) {
|
|
49
|
+
best = { actorId, entry, t, d };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (!best) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const screen = project(cam, best.t.x, (best.t.y ?? 0) + CARD_LIFT_M, best.t.z, view);
|
|
56
|
+
if (!screen) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
id: best.actorId,
|
|
61
|
+
rev: best.entry.rev,
|
|
62
|
+
card: best.entry.card,
|
|
63
|
+
x: screen.x,
|
|
64
|
+
y: screen.y,
|
|
65
|
+
opacity: Math.max(0, Math.min(1, (NEAR_M - best.d) / FADE_M)),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Which of a cabinet's two drawings the chrome shows. `view` is
|
|
70
|
+
// `{ open, shown }`: the cabinet whose board the player opened and the one
|
|
71
|
+
// whose card is up this frame, each a door actor's id or null.
|
|
72
|
+
export function makeCardView() {
|
|
73
|
+
return { open: null, shown: null };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// A tap on the card: the chip opens its board, the board closes.
|
|
77
|
+
export function tapCard(view) {
|
|
78
|
+
view.open = view.open === null ? view.shown : null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// The card up this frame is `shownId`'s (null for none): 'board' when the
|
|
82
|
+
// player opened that cabinet's, else 'chip'. A board is its cabinet's alone,
|
|
83
|
+
// so it closes when the player leaves it for another or walks away.
|
|
84
|
+
export function cardMode(view, shownId) {
|
|
85
|
+
view.shown = shownId ?? null;
|
|
86
|
+
if (view.open !== null && view.open !== view.shown) {
|
|
87
|
+
view.open = null;
|
|
88
|
+
}
|
|
89
|
+
return view.shown !== null && view.open === view.shown ? 'board' : 'chip';
|
|
90
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Free-text chat between players who may chat (contract §6, v1.12). Who may
|
|
2
|
+
// is ghost's rule alone -- two players who follow each other, both over 13 --
|
|
3
|
+
// and ghost enforces it: this client asks the host (`Hub.chat`) what it may
|
|
4
|
+
// read and whom its words would reach, and sends through the host
|
|
5
|
+
// (`Hub.say`). The place's server carries none of it, and a host or SDK
|
|
6
|
+
// without the commands leaves the kit as it was: reactions and phrases only.
|
|
7
|
+
|
|
8
|
+
import * as castleSdk from 'castle-web-sdk';
|
|
9
|
+
|
|
10
|
+
// How often the host is asked: while someone here can be chatted with, and
|
|
11
|
+
// while nobody can (a friend may arrive).
|
|
12
|
+
const POLL_MS = 2500;
|
|
13
|
+
const IDLE_POLL_MS = 15000;
|
|
14
|
+
// A chat line stays over its speaker this long.
|
|
15
|
+
export const CHAT_BUBBLE_MS = 6000;
|
|
16
|
+
|
|
17
|
+
export function makeChat() {
|
|
18
|
+
let off = false;
|
|
19
|
+
let asking = false;
|
|
20
|
+
let askedAt = -Infinity;
|
|
21
|
+
let cursor = null;
|
|
22
|
+
let sending = false;
|
|
23
|
+
// Counts sessions: an answer that lands after a reset belongs to the last
|
|
24
|
+
// session and is dropped.
|
|
25
|
+
let generation = 0;
|
|
26
|
+
const c = {
|
|
27
|
+
// Whether this player may chat at all, and the user ids here they may
|
|
28
|
+
// chat with; null until the host has answered.
|
|
29
|
+
canChat: false,
|
|
30
|
+
peers: null,
|
|
31
|
+
// Messages not yet shown: [{ id, fromUserId, fromUsername, text, mine }].
|
|
32
|
+
incoming: [],
|
|
33
|
+
|
|
34
|
+
available: () => !off && typeof castleSdk.Hub?.chat === 'function' && typeof castleSdk.Hub?.say === 'function',
|
|
35
|
+
|
|
36
|
+
// Asks the host what there is to read, on its cadence. `active` is false
|
|
37
|
+
// during a trip or away from any place.
|
|
38
|
+
frame(active, now) {
|
|
39
|
+
if (!active || asking || !c.available()) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (now - askedAt < (c.peers?.length ? POLL_MS : IDLE_POLL_MS)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
askedAt = now;
|
|
46
|
+
asking = true;
|
|
47
|
+
const asked = generation;
|
|
48
|
+
Promise.resolve(castleSdk.Hub.chat(cursor ?? undefined))
|
|
49
|
+
.then((answer) => {
|
|
50
|
+
if (asked !== generation) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (answer?.status !== 'ok') {
|
|
54
|
+
off = true;
|
|
55
|
+
c.reset();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
// The first answer only sets the cursor: what was said before this
|
|
59
|
+
// player arrived is not replayed.
|
|
60
|
+
const first = cursor === null && c.peers === null;
|
|
61
|
+
c.canChat = answer.canChat === true;
|
|
62
|
+
c.peers = Array.isArray(answer.peers) ? answer.peers.map(String) : [];
|
|
63
|
+
if (!first) {
|
|
64
|
+
for (const m of answer.messages ?? []) {
|
|
65
|
+
c.incoming.push({ ...m, mine: false });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
cursor = answer.cursor ?? cursor;
|
|
69
|
+
})
|
|
70
|
+
.catch((err) => {
|
|
71
|
+
if (asked !== generation) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
// A host from before chat refuses the command for good.
|
|
75
|
+
if (err?.code === 'UNKNOWN_COMMAND' || err?.code === 'CASTLE_HOST_UNAVAILABLE') {
|
|
76
|
+
off = true;
|
|
77
|
+
c.reset();
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
.finally(() => {
|
|
81
|
+
if (asked === generation) {
|
|
82
|
+
asking = false;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
// Sends `text`; `done(status)` hears ghost's answer: "sent", "none"
|
|
88
|
+
// (nobody here may read it), "limited", "refused" or "unavailable".
|
|
89
|
+
send(text, done = () => {}) {
|
|
90
|
+
const words = String(text ?? '').trim().slice(0, 200);
|
|
91
|
+
if (!words || sending || !c.available()) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
sending = true;
|
|
95
|
+
const asked = generation;
|
|
96
|
+
Promise.resolve(castleSdk.Hub.say(words))
|
|
97
|
+
.then((answer) => {
|
|
98
|
+
if (asked !== generation) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (answer?.status === 'sent') {
|
|
102
|
+
c.incoming.push({ id: answer.id ?? null, fromUserId: null, fromUsername: null, text: words, mine: true });
|
|
103
|
+
}
|
|
104
|
+
done(answer?.status ?? 'unavailable');
|
|
105
|
+
})
|
|
106
|
+
.catch(() => asked === generation && done('unavailable'))
|
|
107
|
+
.finally(() => {
|
|
108
|
+
sending = false;
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
report(messageId, done = () => {}) {
|
|
113
|
+
if (typeof castleSdk.Hub?.reportChat !== 'function' || !messageId) {
|
|
114
|
+
done(false);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
Promise.resolve(castleSdk.Hub.reportChat(messageId))
|
|
118
|
+
.then((answer) => done(answer?.status === 'ok'))
|
|
119
|
+
.catch(() => done(false));
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
// Another session: the cursor and what was read belong to the last one.
|
|
123
|
+
reset() {
|
|
124
|
+
generation += 1;
|
|
125
|
+
// A read still in flight is the last session's: the next one asks anew.
|
|
126
|
+
asking = false;
|
|
127
|
+
cursor = null;
|
|
128
|
+
askedAt = -Infinity;
|
|
129
|
+
c.canChat = false;
|
|
130
|
+
c.peers = null;
|
|
131
|
+
c.incoming.length = 0;
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
return c;
|
|
135
|
+
}
|