@songsid/agend 2.4.0-beta.14 → 2.4.0-beta.16
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/accounts-profiles.d.ts +1 -1
- package/dist/accounts-view.d.ts +3 -0
- package/dist/accounts-view.js.map +1 -1
- package/dist/auth-api.js +5 -0
- package/dist/auth-api.js.map +1 -1
- package/dist/backend/claude-code.d.ts +6 -1
- package/dist/backend/claude-code.js +63 -8
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/kiro.js +6 -1
- package/dist/backend/kiro.js.map +1 -1
- package/dist/backend/types.d.ts +2 -0
- package/dist/backend/types.js.map +1 -1
- package/dist/backend-command.d.ts +4 -2
- package/dist/backend-command.js +3 -0
- package/dist/backend-command.js.map +1 -1
- package/dist/browser-backend-signins.d.ts +1 -0
- package/dist/browser-backend-signins.js +3 -1
- package/dist/browser-backend-signins.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/classic-channel-manager.d.ts +1 -0
- package/dist/classic-channel-manager.js +4 -1
- package/dist/classic-channel-manager.js.map +1 -1
- package/dist/claude-credential-change.d.ts +22 -0
- package/dist/claude-credential-change.js +47 -0
- package/dist/claude-credential-change.js.map +1 -0
- package/dist/claude-credential-launch.d.ts +62 -0
- package/dist/claude-credential-launch.js +304 -0
- package/dist/claude-credential-launch.js.map +1 -0
- package/dist/claude-credential-runner.d.ts +1 -0
- package/dist/claude-credential-runner.js +56 -0
- package/dist/claude-credential-runner.js.map +1 -0
- package/dist/claude-credential-vault.d.ts +51 -0
- package/dist/claude-credential-vault.js +252 -0
- package/dist/claude-credential-vault.js.map +1 -0
- package/dist/claude-setup-token-transport.d.ts +9 -0
- package/dist/claude-setup-token-transport.js +82 -0
- package/dist/claude-setup-token-transport.js.map +1 -0
- package/dist/claude-setup-token.d.ts +51 -0
- package/dist/claude-setup-token.js +83 -0
- package/dist/claude-setup-token.js.map +1 -0
- package/dist/cli-audited.js +7 -6
- package/dist/cli-audited.js.map +1 -1
- package/dist/command-report.d.ts +11 -0
- package/dist/command-report.js +2 -0
- package/dist/command-report.js.map +1 -0
- package/dist/config-validator.js +9 -0
- package/dist/config-validator.js.map +1 -1
- package/dist/config.js +4 -2
- package/dist/config.js.map +1 -1
- package/dist/contact-auth-api.d.ts +2 -1
- package/dist/contact-auth-api.js +15 -5
- package/dist/contact-auth-api.js.map +1 -1
- package/dist/contact-auth-policy.d.ts +5 -0
- package/dist/contact-auth-policy.js +2 -0
- package/dist/contact-auth-policy.js.map +1 -1
- package/dist/contact-auth-store.d.ts +12 -1
- package/dist/contact-auth-store.js +67 -5
- package/dist/contact-auth-store.js.map +1 -1
- package/dist/contact-auth-types.d.ts +27 -1
- package/dist/contact-auth-types.js.map +1 -1
- package/dist/daemon.d.ts +5 -0
- package/dist/daemon.js +59 -3
- package/dist/daemon.js.map +1 -1
- package/dist/fleet-level-config.d.ts +1 -1
- package/dist/fleet-level-config.js +1 -0
- package/dist/fleet-level-config.js.map +1 -1
- package/dist/fleet-manager.d.ts +48 -3
- package/dist/fleet-manager.js +446 -27
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +16 -6
- package/dist/general-knowledge/skills/web-appearance/SKILL.md +4 -1
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +23 -5
- package/dist/host-monitoring-config.d.ts +14 -0
- package/dist/host-monitoring-config.js +31 -0
- package/dist/host-monitoring-config.js.map +1 -0
- package/dist/hub/group-policy/resources.d.ts +1 -1
- package/dist/instance-config-impact.js +1 -1
- package/dist/instance-config-impact.js.map +1 -1
- package/dist/instructions.js +1 -0
- package/dist/instructions.js.map +1 -1
- package/dist/locale.d.ts +2 -0
- package/dist/locale.js +19 -1
- package/dist/locale.js.map +1 -1
- package/dist/needs-you-hub.js +3 -0
- package/dist/needs-you-hub.js.map +1 -1
- package/dist/needs-you.d.ts +2 -0
- package/dist/needs-you.js.map +1 -1
- package/dist/office-share-page.js +1 -1
- package/dist/office-share-page.js.map +1 -1
- package/dist/profile-signins.d.ts +1 -0
- package/dist/profile-signins.js +3 -1
- package/dist/profile-signins.js.map +1 -1
- package/dist/public-web-gateway.js +2 -0
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/public-web-link.d.ts +21 -2
- package/dist/public-web-link.js +22 -2
- package/dist/public-web-link.js.map +1 -1
- package/dist/settings-api.d.ts +12 -0
- package/dist/settings-api.js +146 -7
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-change.js +2 -0
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-effect.js +13 -1
- package/dist/settings-effect.js.map +1 -1
- package/dist/topic-commands.d.ts +7 -1
- package/dist/topic-commands.js +98 -88
- package/dist/topic-commands.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/ui/accounts-view.js +12 -6
- package/dist/ui/backend-signin.js +3 -1
- package/dist/ui/chat-commands.js +2 -0
- package/dist/ui/chat-popout-transport.js +49 -19
- package/dist/ui/chat-popout.js +15 -1
- package/dist/ui/chat-store.js +1 -1
- package/dist/ui/claude-credentials.js +112 -0
- package/dist/ui/claude-setup-token.js +36 -0
- package/dist/ui/contact-auth-client.js +9 -2
- package/dist/ui/contact-auth-strings.js +78 -16
- package/dist/ui/contact-authorizations.js +47 -26
- package/dist/ui/contact-needs.js +22 -6
- package/dist/ui/contact-permissions.js +55 -10
- package/dist/ui/contact-tool-groups.js +39 -0
- package/dist/ui/fleet-canvas.js +3 -2
- package/dist/ui/fleet-office-card.js +414 -41
- package/dist/ui/fleet-office-dialogue.js +3 -3
- package/dist/ui/fleet-office-pack.d.ts +67 -1
- package/dist/ui/fleet-office-pack.js +412 -18
- package/dist/ui/fleet-office-play.js +262 -3
- package/dist/ui/fleet-office-skin.js +67 -20
- package/dist/ui/fleet-office-zones.js +19 -1
- package/dist/ui/fleet-office.js +393 -47
- package/dist/ui/office-share-page.js +5 -1
- package/dist/ui/panel-chat.js +47 -3
- package/dist/ui/panel-fleet.js +1 -1
- package/dist/ui/panel-needs.js +7 -4
- package/dist/ui/panel-settings.js +2 -1
- package/dist/ui/preview-popout.js +134 -0
- package/dist/ui/reply-file-preview.js +1 -1
- package/dist/ui/settings-appearance.js +6 -1
- package/dist/ui/settings-host-monitoring.js +51 -0
- package/dist/ui/settings-registry.js +1 -1
- package/dist/ui/settings-shared.js +3 -2
- package/dist/ui/shared/app-i18n.js +4 -0
- package/dist/ui/shared/app-shell.js +16 -7
- package/dist/ui/shared/app.css +266 -27
- package/dist/ui/shared/app.js +7 -1
- package/dist/ui/shared/chat-strings.js +8 -2
- package/dist/ui/shared/info-tip.js +64 -0
- package/dist/ui/shared/office-dialogue.css +12 -0
- package/dist/ui/shared/preview-panel.js +44 -18
- package/dist/ui/shared/preview-popout.css +11 -0
- package/dist/ui/shared/theme-picker.js +46 -0
- package/dist/ui/shared/theme.js +47 -4
- package/dist/ui/shared/tokens.css +273 -0
- package/dist/ui/shared/ui-confirm.js +5 -2
- package/dist/ui/shared/usage-dialog.js +9 -34
- package/dist/ui/shared/view-strings.js +2 -0
- package/dist/usage/i18n-keys.d.ts +1 -1
- package/dist/usage/i18n-keys.js +1 -1
- package/dist/usage/i18n-keys.js.map +1 -1
- package/dist/usage/providers.d.ts +1 -0
- package/dist/usage/providers.js +14 -1
- package/dist/usage/providers.js.map +1 -1
- package/dist/usage/usage-api.js +5 -2
- package/dist/usage/usage-api.js.map +1 -1
- package/dist/web-api.d.ts +5 -1
- package/dist/web-api.js +29 -9
- package/dist/web-api.js.map +1 -1
- package/dist/web-claude-credentials.d.ts +31 -0
- package/dist/web-claude-credentials.js +138 -0
- package/dist/web-claude-credentials.js.map +1 -0
- package/dist/web-commands.d.ts +5 -2
- package/dist/web-commands.js +4 -2
- package/dist/web-commands.js.map +1 -1
- package/dist/web-office-skins.d.ts +7 -2
- package/dist/web-office-skins.js +42 -16
- package/dist/web-office-skins.js.map +1 -1
- package/dist/web-session.d.ts +20 -1
- package/dist/web-session.js +27 -0
- package/dist/web-session.js.map +1 -1
- package/dist/web-terminal.d.ts +4 -0
- package/dist/web-terminal.js +16 -1
- package/dist/web-terminal.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
// M-3293 (#4119, the light version): play in the Office — pick a person up and drop them anywhere (they walk back to their
|
|
2
|
-
// seat along the usual route), and pat or feed them (a few hearts rising over the head and a speech bubble).
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// seat along the usual route), and pat or feed them (a few hearts rising over the head and a speech bubble). M-3432
|
|
3
|
+
// (#4255): custom snacks from the active skin pack — drag onto a character to feed (plays optional `eat` strip), or drop
|
|
4
|
+
// on empty floor so nearby idle characters race to it (first eats, others scatter). The viewer's own: never stored on the
|
|
5
|
+
// host, never in a share link, never sent to an agent (unless Tell is ticked on their card). Pure — fleet-office.js wires
|
|
6
|
+
// it to the pointer, the walkers and the scene.
|
|
5
7
|
//
|
|
6
8
|
// Who may play: a single zones office on the dashboard itself (not All offices, not a share link's page, not while Edit
|
|
7
9
|
// layout is open), with the viewer's "Drag and pat" on (per device, on by default) — and never with reduced motion.
|
|
10
|
+
import { LOGICAL, SNACK_LIMITS, stripDurationMs } from "./fleet-office-pack.js";
|
|
11
|
+
import { nameHash } from "./fleet-office-model.js";
|
|
12
|
+
import { routeStaysInArea } from "./fleet-office-zones.js";
|
|
13
|
+
import { WALK } from "./fleet-office-zones.js";
|
|
8
14
|
|
|
9
15
|
/**
|
|
10
16
|
* LONG_MS: a touch held this long without moving picks a person up (a finger that moves first pans, as before); SLOP:
|
|
@@ -14,6 +20,20 @@
|
|
|
14
20
|
export const PLAY = { LONG_MS: 450, SLOP: 6, REACT_MS: 1800, HEARTS: 3, RISE: 26 };
|
|
15
21
|
export const PLAY_KINDS = ["pat", "feed"];
|
|
16
22
|
|
|
23
|
+
/** M-3432 (#4255): limits and timing for custom snacks, eating, and placed-snack races. */
|
|
24
|
+
export const SNACK = {
|
|
25
|
+
MAX_PLACED: 6,
|
|
26
|
+
MAX_RACERS: 4,
|
|
27
|
+
TTL_MS: 30_000,
|
|
28
|
+
CLAIM_DIST: 18,
|
|
29
|
+
RACE_SPEED_MULT: 1.25,
|
|
30
|
+
SPEED_VARIANCE: 0.08,
|
|
31
|
+
EAT_MIN_MS: 800,
|
|
32
|
+
EAT_MAX_MS: 10_000,
|
|
33
|
+
EAT_DEFAULT_MS: 1800,
|
|
34
|
+
SCATTER_MS: 1800,
|
|
35
|
+
};
|
|
36
|
+
|
|
17
37
|
/** Whether the viewer may play here: their toggle on, motion allowed, a single zones office of their own dashboard. */
|
|
18
38
|
export function playAllowed({ on, still, zones, overview, layout, shared }) {
|
|
19
39
|
return !!on && !still && !!zones && !overview && !layout && !shared;
|
|
@@ -82,3 +102,242 @@ export function pruneReactions(map, t) {
|
|
|
82
102
|
for (const [n, r] of [...map]) if (t - r.t0 >= PLAY.REACT_MS || t < r.t0) map.delete(n);
|
|
83
103
|
return map.size > 0;
|
|
84
104
|
}
|
|
105
|
+
|
|
106
|
+
const SCATTER_WORDS = { en: "Too slow!", "zh-TW": "被搶先了!" };
|
|
107
|
+
/** M-3432 (#4255): brief bubble for a losing snack racer heading back to their seat. */
|
|
108
|
+
export const scatterWords = (lang = "en") => SCATTER_WORDS[lang] || SCATTER_WORDS.en;
|
|
109
|
+
|
|
110
|
+
/** M-3432 (#4255): how long a character eats (ms) — clamped to [EAT_MIN_MS, EAT_MAX_MS], or EAT_DEFAULT_MS without an eat strip. */
|
|
111
|
+
export function eatDurationMs(charEatStrip = null, snackEatStrip = null) {
|
|
112
|
+
const ms = Math.max(stripDurationMs(charEatStrip), stripDurationMs(snackEatStrip));
|
|
113
|
+
return ms > 0 ? Math.max(SNACK.EAT_MIN_MS, Math.min(SNACK.EAT_MAX_MS, ms)) : SNACK.EAT_DEFAULT_MS;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** M-3432 (#4255): deterministic speed multiplier for a racer chasing a placed snack (1.25× ± 8%). */
|
|
117
|
+
export function racerSpeedMult(name, snackKey) {
|
|
118
|
+
const h = nameHash(`${name}\u0000${snackKey}`) % 1001;
|
|
119
|
+
const frac = h / 500 - 1;
|
|
120
|
+
return SNACK.RACE_SPEED_MULT * (1 + frac * SNACK.SPEED_VARIANCE);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function areaOfPoint(areas, pt) {
|
|
124
|
+
if (!areas || typeof areas !== "object") return null;
|
|
125
|
+
for (const [k, a] of Object.entries(areas)) {
|
|
126
|
+
const r = a && a.rect;
|
|
127
|
+
if (r && pt.x >= r.x && pt.x <= r.x + r.w && pt.y >= r.y && pt.y <= r.y + r.h) return k;
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* M-3432 (#4255): client-local snack manager for a single zones office.
|
|
134
|
+
* Handles direct feeds, placed snacks on the floor (max MAX_PLACED, TTL_MS expiry),
|
|
135
|
+
* nearby idle racers (max MAX_RACERS per snack, honoring stayInArea), claim → eat, and losing-racer scatter.
|
|
136
|
+
*/
|
|
137
|
+
export function createSnacks() {
|
|
138
|
+
let seq = 0;
|
|
139
|
+
let placed = [];
|
|
140
|
+
const eating = new Map();
|
|
141
|
+
const scatter = new Map();
|
|
142
|
+
|
|
143
|
+
const busySet = () => {
|
|
144
|
+
const busy = new Set(eating.keys());
|
|
145
|
+
for (const p of placed) for (const n of p.racers) busy.add(n);
|
|
146
|
+
return busy;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const pickRacers = (item, t, { desks = [], walkers = null, hidden = null, ownArea = false, graph = null } = {}, cap = SNACK.MAX_RACERS) => {
|
|
150
|
+
if (cap <= 0) return [];
|
|
151
|
+
const busy = busySet();
|
|
152
|
+
const candidates = [];
|
|
153
|
+
for (const d of desks) {
|
|
154
|
+
const name = d && d.node && d.node.name;
|
|
155
|
+
if (!name || d.node.state !== "idle" || d.night) continue;
|
|
156
|
+
if (busy.has(name) || (hidden && hidden.has(name))) continue;
|
|
157
|
+
if (ownArea && (item.area === null || d.area !== item.area)) continue;
|
|
158
|
+
const pos = (walkers && walkers.at(name, t)) || d.seat;
|
|
159
|
+
if (!pos) continue;
|
|
160
|
+
if (ownArea && graph && !routeStaysInArea(pos, { x: item.x, y: item.y }, graph, d.area, d.seat)) continue;
|
|
161
|
+
const dist = Math.hypot(pos.x - item.x, pos.y - item.y);
|
|
162
|
+
if (dist > item.radius) continue;
|
|
163
|
+
candidates.push({ name, dist, eta: dist / racerSpeedMult(name, item.id) });
|
|
164
|
+
}
|
|
165
|
+
candidates.sort((a, b) => (a.eta - b.eta) || (a.dist - b.dist) || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
166
|
+
return candidates.slice(0, cap).map((c) => c.name);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const feed = (name, snack, { x, y, t, charEatStrip = null }) => {
|
|
170
|
+
for (const p of placed) p.racers = p.racers.filter((n) => n !== name);
|
|
171
|
+
scatter.delete(name);
|
|
172
|
+
const durationMs = eatDurationMs(charEatStrip, snack && snack.eat);
|
|
173
|
+
eating.set(name, { snackId: snack ? snack.id : null, x, y, t0: t, until: t + durationMs });
|
|
174
|
+
return { durationMs };
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
feed,
|
|
179
|
+
place(snack, at, t, ctx = {}) {
|
|
180
|
+
if (!snack || !at) return null;
|
|
181
|
+
const x = Math.max(16, Math.min(LOGICAL.w - 16, Math.round(at.x)));
|
|
182
|
+
const y = Math.max(16, Math.min(LOGICAL.h - 16, Math.round(at.y)));
|
|
183
|
+
while (placed.length >= SNACK.MAX_PLACED) placed.shift();
|
|
184
|
+
const item = {
|
|
185
|
+
id: `sn-${++seq}`,
|
|
186
|
+
snackId: snack.id,
|
|
187
|
+
x,
|
|
188
|
+
y,
|
|
189
|
+
t0: t,
|
|
190
|
+
radius: snack.radius ?? SNACK_LIMITS.defaultRadius,
|
|
191
|
+
area: areaOfPoint(ctx.areas, { x, y }),
|
|
192
|
+
racers: [],
|
|
193
|
+
};
|
|
194
|
+
item.racers = pickRacers(item, t, ctx, SNACK.MAX_RACERS);
|
|
195
|
+
placed.push(item);
|
|
196
|
+
return item;
|
|
197
|
+
},
|
|
198
|
+
step(t, ctx = {}) {
|
|
199
|
+
const { desks = [], walkers = null, hidden = null, ownArea = false, graph = null, snacksById = null, charEatOf = null, onClaim = null } = ctx;
|
|
200
|
+
let changed = false;
|
|
201
|
+
for (const [n, e] of [...eating]) if (t >= e.until || t < e.t0) { eating.delete(n); changed = true; }
|
|
202
|
+
for (const [n, s] of [...scatter]) if (t >= s.until || t < s.t0) scatter.delete(n);
|
|
203
|
+
const deskByName = new Map(desks.filter((d) => d && d.node).map((d) => [d.node.name, d]));
|
|
204
|
+
const kept = [];
|
|
205
|
+
for (const p of placed) {
|
|
206
|
+
if (t - p.t0 >= SNACK.TTL_MS || t < p.t0) { changed = true; continue; }
|
|
207
|
+
const beforeLen = p.racers.length;
|
|
208
|
+
p.racers = p.racers.filter((n) => {
|
|
209
|
+
const d = deskByName.get(n);
|
|
210
|
+
if (!d || d.node.state !== "idle" || d.night || eating.has(n) || (hidden && hidden.has(n))) return false;
|
|
211
|
+
if (ownArea) {
|
|
212
|
+
if (p.area === null || d.area !== p.area) return false;
|
|
213
|
+
const pos = (walkers && walkers.at(n, t)) || d.seat;
|
|
214
|
+
if (graph && pos && !routeStaysInArea(pos, { x: p.x, y: p.y }, graph, d.area, d.seat)) return false;
|
|
215
|
+
}
|
|
216
|
+
return true;
|
|
217
|
+
});
|
|
218
|
+
if (p.racers.length !== beforeLen) changed = true;
|
|
219
|
+
// Check if any racer reached CLAIM_DIST.
|
|
220
|
+
const reached = [];
|
|
221
|
+
for (const n of p.racers) {
|
|
222
|
+
const d = deskByName.get(n);
|
|
223
|
+
const pos = (walkers && walkers.at(n, t)) || (d && d.seat);
|
|
224
|
+
if (!pos) continue;
|
|
225
|
+
const dist = Math.hypot(pos.x - p.x, pos.y - p.y);
|
|
226
|
+
if (dist <= SNACK.CLAIM_DIST) reached.push({ name: n, dist, speed: racerSpeedMult(n, p.id) });
|
|
227
|
+
}
|
|
228
|
+
if (reached.length) {
|
|
229
|
+
reached.sort((a, b) => (a.dist - b.dist) || (b.speed - a.speed) || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
230
|
+
const winner = reached[0].name;
|
|
231
|
+
const losers = p.racers.filter((n) => n !== winner);
|
|
232
|
+
const snack = snacksById ? snacksById.get(p.snackId) || null : null;
|
|
233
|
+
const charEat = typeof charEatOf === "function" ? charEatOf(winner) : null;
|
|
234
|
+
feed(winner, snack, { x: p.x, y: p.y, t, charEatStrip: charEat });
|
|
235
|
+
for (const loser of losers) scatter.set(loser, { t0: t, until: t + SNACK.SCATTER_MS });
|
|
236
|
+
if (typeof onClaim === "function") onClaim(winner, snack, p);
|
|
237
|
+
changed = true;
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (p.racers.length < SNACK.MAX_RACERS) {
|
|
241
|
+
const added = pickRacers(p, t, { desks, walkers, hidden, ownArea, graph }, SNACK.MAX_RACERS - p.racers.length);
|
|
242
|
+
if (added.length) { p.racers.push(...added); changed = true; }
|
|
243
|
+
}
|
|
244
|
+
kept.push(p);
|
|
245
|
+
}
|
|
246
|
+
placed = kept;
|
|
247
|
+
return changed;
|
|
248
|
+
},
|
|
249
|
+
targets(t) {
|
|
250
|
+
const out = new Map();
|
|
251
|
+
for (const [name, e] of eating) {
|
|
252
|
+
if (t >= e.t0 && t < e.until) out.set(name, { x: e.x, y: e.y });
|
|
253
|
+
}
|
|
254
|
+
for (const p of placed) {
|
|
255
|
+
for (const name of p.racers) {
|
|
256
|
+
if (!out.has(name)) out.set(name, { x: p.x, y: p.y, speed: WALK.SPEED * racerSpeedMult(name, p.id) });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return out;
|
|
260
|
+
},
|
|
261
|
+
placedList() { return [...placed]; },
|
|
262
|
+
eatingOf(name, t) {
|
|
263
|
+
const e = eating.get(name);
|
|
264
|
+
return e && t >= e.t0 && t < e.until ? e : null;
|
|
265
|
+
},
|
|
266
|
+
scatterOf(name, t) {
|
|
267
|
+
const s = scatter.get(name);
|
|
268
|
+
return s && t >= s.t0 && t < s.until ? s : null;
|
|
269
|
+
},
|
|
270
|
+
active(t) {
|
|
271
|
+
if (placed.length > 0) return true;
|
|
272
|
+
for (const e of eating.values()) if (t >= e.t0 && t < e.until) return true;
|
|
273
|
+
for (const s of scatter.values()) if (t >= s.t0 && t < s.until) return true;
|
|
274
|
+
return false;
|
|
275
|
+
},
|
|
276
|
+
clear() { placed = []; eating.clear(); scatter.clear(); },
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* M-3432 (#4255): owned snack-drag lifecycle controller.
|
|
282
|
+
* Manages the four global pointer/key listeners with a single cancellation handle and generation fence so
|
|
283
|
+
* drag replacement, play loss, Office/skin changes, and unmount immediately detach all listeners and block stale commits.
|
|
284
|
+
*/
|
|
285
|
+
export function createSnackDrag(win = globalThis) {
|
|
286
|
+
let gen = 0;
|
|
287
|
+
let cancelActive = null;
|
|
288
|
+
return {
|
|
289
|
+
active() { return cancelActive !== null; },
|
|
290
|
+
start({ pid, sx, sy, slop = PLAY.SLOP, onMove, onCommit, onCancel }) {
|
|
291
|
+
if (cancelActive) cancelActive();
|
|
292
|
+
const myGen = ++gen;
|
|
293
|
+
let dragging = false, lastDrop = null, live = true;
|
|
294
|
+
const detach = () => {
|
|
295
|
+
if (!live) return;
|
|
296
|
+
live = false;
|
|
297
|
+
win.removeEventListener?.("pointermove", onMoveEv, true);
|
|
298
|
+
win.removeEventListener?.("pointerup", onUpEv, true);
|
|
299
|
+
win.removeEventListener?.("pointercancel", onCancelEv, true);
|
|
300
|
+
win.removeEventListener?.("keydown", onKeyEv, true);
|
|
301
|
+
if (cancelActive === cancel) cancelActive = null;
|
|
302
|
+
};
|
|
303
|
+
const cancel = () => {
|
|
304
|
+
if (!live) return;
|
|
305
|
+
const wasDragging = dragging;
|
|
306
|
+
detach();
|
|
307
|
+
lastDrop = null;
|
|
308
|
+
if (typeof onCancel === "function") onCancel({ dragging: wasDragging });
|
|
309
|
+
};
|
|
310
|
+
const finish = (commit) => {
|
|
311
|
+
if (!live || myGen !== gen) return;
|
|
312
|
+
const drop = lastDrop, wasDragging = dragging;
|
|
313
|
+
detach();
|
|
314
|
+
lastDrop = null;
|
|
315
|
+
if (commit && wasDragging && drop) {
|
|
316
|
+
if (typeof onCommit === "function") onCommit(drop);
|
|
317
|
+
} else if (typeof onCancel === "function") {
|
|
318
|
+
onCancel({ dragging: wasDragging });
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
const onMoveEv = (ev) => {
|
|
322
|
+
if (!live || myGen !== gen || ev.pointerId !== pid) return;
|
|
323
|
+
const starting = !dragging && Math.hypot(ev.clientX - sx, ev.clientY - sy) > slop;
|
|
324
|
+
if (starting) dragging = true;
|
|
325
|
+
if (!dragging) return;
|
|
326
|
+
lastDrop = typeof onMove === "function" ? onMove(ev, { starting }) : null;
|
|
327
|
+
};
|
|
328
|
+
const onUpEv = (ev) => { if (ev.pointerId === pid) finish(true); };
|
|
329
|
+
const onCancelEv = (ev) => { if (ev.pointerId === pid) finish(false); };
|
|
330
|
+
const onKeyEv = (ev) => { if (ev.key === "Escape") { ev.preventDefault?.(); finish(false); } };
|
|
331
|
+
cancelActive = cancel;
|
|
332
|
+
win.addEventListener?.("pointermove", onMoveEv, true);
|
|
333
|
+
win.addEventListener?.("pointerup", onUpEv, true);
|
|
334
|
+
win.addEventListener?.("pointercancel", onCancelEv, true);
|
|
335
|
+
win.addEventListener?.("keydown", onKeyEv, true);
|
|
336
|
+
return cancel;
|
|
337
|
+
},
|
|
338
|
+
retire() {
|
|
339
|
+
gen++;
|
|
340
|
+
if (cancelActive) cancelActive();
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
}
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
// among them by base y), then the foreground, then the crowd counts, tags and bubbles.
|
|
46
46
|
import { t } from "/assets/app-i18n.js";
|
|
47
47
|
import { frameAt, nameHash } from "./fleet-office-model.js";
|
|
48
|
-
import { CHAR_DEPTH, LOGICAL, checkSkinPack, own, packPortraitImages, packSceneImages, poseStrip, stripBox, walkStrip } from "./fleet-office-pack.js";
|
|
48
|
+
import { CHAR_DEPTH, LOGICAL, checkSkinPack, own, packPortraitImages, packSceneImages, poseStrip, stripBox, stripCell, stripFrameAt, stripImages, walkStrip } from "./fleet-office-pack.js";
|
|
49
49
|
import { tierColours } from "./fleet-office-levels.js";
|
|
50
50
|
import { assetUrl } from "/assets/asset-url.js";
|
|
51
51
|
|
|
@@ -318,11 +318,12 @@ export function tagBox(ctx, x, y, label, compact = false) {
|
|
|
318
318
|
ctx.restore();
|
|
319
319
|
return { x: Math.round(x - w / 2), y: y + k.top, w, h: k.h, text: t };
|
|
320
320
|
}
|
|
321
|
-
/** #2860: what a tag covers with its level badge: on a full tag's top-left corner (
|
|
321
|
+
/** #2860: what a tag covers with its level badge: on a full tag's top-left corner (clear of the first letter); left of a compact one. */
|
|
322
322
|
export function tagFootprint(ctx, box, badge, compact = false) {
|
|
323
323
|
if (!badge) return box;
|
|
324
324
|
if (compact) { const w = badgeWidth(ctx, badge) + 1; return { x: box.x - w, y: box.y, w: box.w + w, h: box.h }; }
|
|
325
|
-
|
|
325
|
+
const left = badge.mark ? 6 : Math.max(10, badgeWidth(ctx, badge) - 3);
|
|
326
|
+
return { x: box.x - left, y: box.y - 7, w: box.w + left, h: box.h + 7 };
|
|
326
327
|
}
|
|
327
328
|
function badgeWidth(ctx, badge) {
|
|
328
329
|
if (badge.mark) return 8;
|
|
@@ -339,13 +340,12 @@ function badgeWidth(ctx, badge) {
|
|
|
339
340
|
*/
|
|
340
341
|
export function drawBadge(ctx, x, y, badge, pal, inline = false) {
|
|
341
342
|
if (!badge) return;
|
|
342
|
-
// #2860 inline (a compact tag): (x, y) is the tag's left edge and middle; the badge sits just left of it, whole.
|
|
343
|
-
if (inline) { const w = badgeWidth(ctx, badge); x = x - 1 - w + (badge.mark ? w / 2 : w / 2 - 3); y = y + (badge.mark ? 0 : 1); }
|
|
344
343
|
const c = tierColours(badge.tier, pal);
|
|
345
344
|
ctx.save();
|
|
346
345
|
ctx.globalAlpha = 1;
|
|
347
346
|
if (badge.mark) {
|
|
348
|
-
|
|
347
|
+
const mx = inline ? x - 1 - 4 : x;
|
|
348
|
+
ctx.translate(mx, y); ctx.rotate(Math.PI / 4);
|
|
349
349
|
ctx.fillStyle = pal.surface; ctx.fillRect(-4, -4, 8, 8);
|
|
350
350
|
ctx.fillStyle = c.bg; ctx.fillRect(-4, -4, 8, 8);
|
|
351
351
|
ctx.strokeStyle = c.line; ctx.lineWidth = 1; ctx.strokeRect(-3.5, -3.5, 7, 7);
|
|
@@ -354,7 +354,9 @@ export function drawBadge(ctx, x, y, badge, pal, inline = false) {
|
|
|
354
354
|
}
|
|
355
355
|
ctx.font = BADGE_FONT;
|
|
356
356
|
const w = Math.max(12, Math.ceil((ctx.measureText ? ctx.measureText(badge.text).width : badge.text.length * 5) + 6)), h = 11;
|
|
357
|
-
|
|
357
|
+
// Normal tag: badge overlaps only the left border corner (right edge at x + 3), leaving the first letter at x + 5 unobstructed.
|
|
358
|
+
const bx = inline ? Math.round(x - 1 - w) : Math.round(x - w + 3);
|
|
359
|
+
const by = inline ? Math.round(y - h / 2) : Math.round(y - h / 2 - 1);
|
|
358
360
|
// An opaque surface first, so a tint reads the same over any picture.
|
|
359
361
|
ctx.fillStyle = pal.surface; ctx.fillRect(bx, by, w, h);
|
|
360
362
|
ctx.fillStyle = c.bg; ctx.fillRect(bx, by, w, h);
|
|
@@ -526,23 +528,37 @@ export const studioSkin = { ...pixelSkin, id: "studio", pack: STUDIO_PACK, drawB
|
|
|
526
528
|
*/
|
|
527
529
|
export function spriteSkin(pack, images, base = pixelSkin) {
|
|
528
530
|
const img = (src) => (src && images.get(src)) || null;
|
|
531
|
+
const ready = (st) => !!st && (Array.isArray(st.sheets) ? stripImages(st).every((s) => !!img(s)) : !!img(st.src));
|
|
532
|
+
const clipMs = (env, key, st, ms) => (ms > 0 && env && typeof env.clock === "function" ? env.clock(key, st, ms) : ms);
|
|
529
533
|
// A strip's frame at its displayed size (dw × dh, unsmoothed), its anchor on (x, y); mirrored about the anchor.
|
|
530
534
|
const strip = (ctx, st, ms, x, y, frame = null, mirror = false) => {
|
|
531
|
-
|
|
535
|
+
if (!ready(st)) return false;
|
|
536
|
+
const f = frame ?? stripFrameAt(st, ms), cell = stripCell(st, f), im = img(cell.src);
|
|
532
537
|
if (!im) return false;
|
|
533
|
-
const
|
|
538
|
+
const b = stripBox(st, x, y, mirror);
|
|
534
539
|
ctx.save();
|
|
535
540
|
ctx.imageSmoothingEnabled = false;
|
|
536
|
-
if (mirror) { ctx.translate(b.x + b.w, b.y); ctx.scale(-1, 1); ctx.drawImage(im,
|
|
537
|
-
else ctx.drawImage(im,
|
|
541
|
+
if (mirror) { ctx.translate(b.x + b.w, b.y); ctx.scale(-1, 1); ctx.drawImage(im, cell.col * st.w, 0, st.w, st.h, 0, 0, b.w, b.h); }
|
|
542
|
+
else ctx.drawImage(im, cell.col * st.w, 0, st.w, st.h, b.x, b.y, b.w, b.h);
|
|
538
543
|
ctx.restore();
|
|
539
544
|
return true;
|
|
540
545
|
};
|
|
541
546
|
const setOf = (look) => own(pack.characters, own(pack.byInstance, look.name)) || own(pack.characters, "default");
|
|
542
|
-
/**
|
|
547
|
+
/** M-3432 (#4255): eating strip for `name` (their set's `eat`, else `default.eat`, else null). */
|
|
548
|
+
const eatStripOf = (name) => {
|
|
549
|
+
const st = own(setOf({ name }) || {}, "eat") || own(own(pack.characters, "default") || {}, "eat") || null;
|
|
550
|
+
return st && ready(st) ? st : null;
|
|
551
|
+
};
|
|
552
|
+
/** The strip a look shows (its pose; walking, by its heading), when all its pictures are loaded. */
|
|
543
553
|
const shown = (look, walking = look.pose === "walk") => {
|
|
554
|
+
if (!walking && look.pose === "eat") {
|
|
555
|
+
const eatSt = eatStripOf(look.name);
|
|
556
|
+
if (eatSt) return { strip: eatSt, mirror: false };
|
|
557
|
+
const fallback = poseStrip(setOf(look), look.basePose || "idle", look.heading);
|
|
558
|
+
return fallback && ready(fallback.strip) ? fallback : null;
|
|
559
|
+
}
|
|
544
560
|
const ps = poseStrip(setOf(look), walking ? "walk" : look.pose, look.heading);
|
|
545
|
-
return ps &&
|
|
561
|
+
return ps && ready(ps.strip) ? ps : null;
|
|
546
562
|
};
|
|
547
563
|
return {
|
|
548
564
|
...base,
|
|
@@ -586,10 +602,10 @@ export function spriteSkin(pack, images, base = pixelSkin) {
|
|
|
586
602
|
if (f.shape) { drawFurniture(ctx, f, active, ms, env); return; }
|
|
587
603
|
// An NPC walking (#2596): its walk strip for its heading (walkSide mirrored going left), when its picture is loaded.
|
|
588
604
|
const ws = walkStrip(f);
|
|
589
|
-
if (ws && strip(ctx, ws.strip, ms, f.x, f.y, null, ws.mirror)) return;
|
|
605
|
+
if (ws && ready(ws.strip) && strip(ctx, ws.strip, clipMs(env, `fw:${f.id}`, ws.strip, ms), f.x, f.y, null, ws.mirror)) return;
|
|
590
606
|
// Active: its activeSprite (or its strip) plays; otherwise its strip loops ("loop", #2570) or its first frame holds.
|
|
591
|
-
if (active)
|
|
592
|
-
else if (f.loop) strip(ctx, f.sprite, ms, f.x, f.y);
|
|
607
|
+
if (active) { const st = f.activeSprite || f.sprite; strip(ctx, st, clipMs(env, `fa:${f.id}`, st, ms), f.x, f.y); }
|
|
608
|
+
else if (f.loop) strip(ctx, f.sprite, clipMs(env, `fl:${f.id}`, f.sprite, ms), f.x, f.y);
|
|
593
609
|
else strip(ctx, f.sprite, 0, f.x, f.y, 0);
|
|
594
610
|
},
|
|
595
611
|
drawCharacter(ctx, d, look, ms, env) {
|
|
@@ -597,9 +613,33 @@ export function spriteSkin(pack, images, base = pixelSkin) {
|
|
|
597
613
|
const ps = shown(look);
|
|
598
614
|
ctx.save();
|
|
599
615
|
if (look.dim) ctx.globalAlpha = 0.35;
|
|
600
|
-
const
|
|
616
|
+
const cms = ps ? clipMs(env, `c:${look.name || (d && d.key) || ""}`, ps.strip, ms) : ms;
|
|
617
|
+
const done = !!ps && strip(ctx, ps.strip, cms, d.seat.x, d.seat.y, null, ps.mirror);
|
|
618
|
+
ctx.restore();
|
|
619
|
+
if (!done) base.drawCharacter(ctx, d, look.pose === "eat" ? { ...look, pose: look.basePose || "idle" } : look, ms, env);
|
|
620
|
+
},
|
|
621
|
+
/** M-3432 (#4255): character's eating strip (set.eat → default.eat → null) when loaded. */
|
|
622
|
+
eatStrip: eatStripOf,
|
|
623
|
+
/** M-3432 (#4255): draw a snack strip (placed on floor or eat overlay) at logical (x, y). */
|
|
624
|
+
drawSnack(ctx, st, ms, x, y, env, clipKey = null) {
|
|
625
|
+
if (!st || !ready(st)) return false;
|
|
626
|
+
const sms = clipKey ? clipMs(env, clipKey, st, ms) : ms;
|
|
627
|
+
return strip(ctx, st, sms, x, y);
|
|
628
|
+
},
|
|
629
|
+
/** M-3432 (#4255): draw frame 0 of a snack strip fitted cleanly inside a square tray/ghost icon canvas. */
|
|
630
|
+
drawSnackIcon(ctx, st, size) {
|
|
631
|
+
if (!st || !ready(st)) return false;
|
|
632
|
+
const cell = stripCell(st, 0), im = img(cell.src);
|
|
633
|
+
if (!im) return false;
|
|
634
|
+
const pad = 2, avail = Math.max(1, size - pad * 2);
|
|
635
|
+
const scale = Math.min(avail / st.w, avail / st.h);
|
|
636
|
+
const dw = Math.max(1, Math.round(st.w * scale)), dh = Math.max(1, Math.round(st.h * scale));
|
|
637
|
+
const dx = Math.round((size - dw) / 2), dy = Math.round((size - dh) / 2);
|
|
638
|
+
ctx.save();
|
|
639
|
+
ctx.imageSmoothingEnabled = false;
|
|
640
|
+
ctx.drawImage(im, cell.col * st.w, 0, st.w, st.h, dx, dy, dw, dh);
|
|
601
641
|
ctx.restore();
|
|
602
|
-
|
|
642
|
+
return true;
|
|
603
643
|
},
|
|
604
644
|
charBox(look, at) {
|
|
605
645
|
const ps = shown({ ...look, heading: at.heading }, !!at.walking);
|
|
@@ -608,7 +648,9 @@ export function spriteSkin(pack, images, base = pixelSkin) {
|
|
|
608
648
|
// An item in the air: its sender's own (their set's "prop", #2562), else the pack's for its kind, else the built-in one.
|
|
609
649
|
drawProp(ctx, it, ms, env) {
|
|
610
650
|
const mine = it.from ? own(setOf({ name: it.from }) || {}, "prop") : null;
|
|
611
|
-
|
|
651
|
+
const st = mine || own(pack.props, it.hue);
|
|
652
|
+
const pms = st && it.id ? clipMs(env, `p:${it.id}`, st, ms) : ms;
|
|
653
|
+
if (!strip(ctx, st, pms, it.x, it.y)) base.drawProp(ctx, it, ms, env);
|
|
612
654
|
},
|
|
613
655
|
};
|
|
614
656
|
}
|
|
@@ -770,7 +812,12 @@ const MAX_LOADED = 24;
|
|
|
770
812
|
const defaultImage = (url) => new Promise((resolve) => {
|
|
771
813
|
if (typeof Image !== "function") { resolve(null); return; }
|
|
772
814
|
const im = new Image();
|
|
773
|
-
im.onload = () =>
|
|
815
|
+
im.onload = () => {
|
|
816
|
+
// M-3394 (#4231): pre-decode each sheet before handing the skin to the renderer so multi-sheet
|
|
817
|
+
// boundaries never trigger a synchronous decode hitch on desktop or phone.
|
|
818
|
+
if (typeof im.decode === "function") im.decode().then(() => resolve(im), () => resolve(im));
|
|
819
|
+
else resolve(im);
|
|
820
|
+
};
|
|
774
821
|
im.onerror = () => resolve(null);
|
|
775
822
|
im.src = url;
|
|
776
823
|
});
|
|
@@ -216,6 +216,23 @@ function withinArea(near, seat, graph, home) {
|
|
|
216
216
|
const others = Object.keys(areas).filter((k) => k !== home && areas[k].rect).map((k) => areas[k].rect);
|
|
217
217
|
return inside.filter((w) => legs(w).every((pts) => pts.every((p, i) => !i || !others.some((r) => crosses(r, pts[i - 1], p)))));
|
|
218
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* M-3286 / M-3432: whether walking from `from` to `to` (and returning to `returnTo`) keeps a person in area `home`:
|
|
221
|
+
* `to` is inside `home`'s rect, and both outbound and return walks (including straightened legs on `graph.straight`)
|
|
222
|
+
* either stay inside `home`'s rect or pass through no other area's interior.
|
|
223
|
+
*/
|
|
224
|
+
export function routeStaysInArea(from, to, graph, home, returnTo = from) {
|
|
225
|
+
if (!graph || typeof graph !== "object") return true;
|
|
226
|
+
const areas = graph.areas || {}, a = own(areas, home);
|
|
227
|
+
if (!a || !a.rect) return false;
|
|
228
|
+
if (!inRect(a.rect, to)) return false;
|
|
229
|
+
const legs = [walkPts(graph, from, to)];
|
|
230
|
+
if (returnTo) legs.push(walkPts(graph, to, returnTo));
|
|
231
|
+
if (legs.every((pts) => pts.every((p) => inRect(a.rect, p)))) return true;
|
|
232
|
+
const others = Object.keys(areas).filter((k) => k !== home && areas[k].rect).map((k) => areas[k].rect);
|
|
233
|
+
const strictIn = (r, p) => p.x > r.x && p.x < r.x + r.w && p.y > r.y && p.y < r.y + r.h;
|
|
234
|
+
return legs.every((pts) => pts.every((p, i) => !others.some((r) => strictIn(r, p) || (i > 0 && crosses(r, pts[i - 1], p)))));
|
|
235
|
+
}
|
|
219
236
|
/**
|
|
220
237
|
* Where `name`, seated at `seat`, should be at `t` (ms) while idle: a spot near the seat, or the seat. `area` (M-3286:
|
|
221
238
|
* the office keeps idle people in their own area): the id of the area they are seated in — only spots inside it, and
|
|
@@ -487,7 +504,8 @@ export function createWalkers() {
|
|
|
487
504
|
if (w.to.x === to.x && w.to.y === to.y) continue;
|
|
488
505
|
const here = posAt(w, now), via = routeVia(graph, { x: here.x, y: here.y }, { x: to.x, y: to.y });
|
|
489
506
|
const pts = graph.straight ? straighten(via) : via; // #2634: timed along the longer way
|
|
490
|
-
|
|
507
|
+
const speed = to.speed > 0 ? to.speed : WALK.SPEED;
|
|
508
|
+
by.set(name, { pts, start: now, ms: Math.max(1, pathLength(pts) / speed), to });
|
|
491
509
|
}
|
|
492
510
|
},
|
|
493
511
|
at(name, now) { const w = by.get(name); return w ? posAt(w, now) : null; },
|