@adatechnology/game-interactables 0.11.0 → 0.13.0
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/README.md +17 -0
- package/dist/index.d.ts +263 -10
- package/dist/index.global.js +783 -43
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +691 -43
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.global.js
CHANGED
|
@@ -21,26 +21,36 @@ var GameInteractables = (() => {
|
|
|
21
21
|
// src/index.ts
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
|
+
CLOGGED: () => CLOGGED,
|
|
24
25
|
COLLAR_REACH: () => COLLAR_REACH,
|
|
25
26
|
CONTROLLED_OBJECT: () => CONTROLLED_OBJECT,
|
|
27
|
+
DRINK_HANDS_LITRES: () => DRINK_HANDS_LITRES,
|
|
28
|
+
DRINK_HANDS_LPS: () => DRINK_HANDS_LPS,
|
|
26
29
|
DRINK_LITRES: () => DRINK_LITRES,
|
|
27
30
|
DRINK_LPS: () => DRINK_LPS,
|
|
28
31
|
DRY_SECONDS: () => DRY_SECONDS,
|
|
29
32
|
END_GAP: () => END_GAP,
|
|
30
33
|
FILL_SHARE: () => FILL_SHARE,
|
|
31
34
|
FLOW_DEFAULTS: () => FLOW_DEFAULTS,
|
|
35
|
+
FLUSH_POUR_SECONDS: () => FLUSH_POUR_SECONDS,
|
|
32
36
|
FLUSH_RUN_SECONDS: () => FLUSH_RUN_SECONDS,
|
|
37
|
+
GESTURE_OF_ACTION: () => GESTURE_OF_ACTION,
|
|
38
|
+
GESTURE_OF_USE: () => GESTURE_OF_USE,
|
|
33
39
|
REACH_SECONDS: () => REACH_SECONDS,
|
|
34
40
|
WASH_SCRUB_SECONDS: () => WASH_SCRUB_SECONDS,
|
|
35
41
|
alignY: () => alignY,
|
|
36
42
|
buildChain: () => buildChain,
|
|
37
43
|
castWithMember: () => castWithMember,
|
|
38
44
|
chainPoints: () => chainPoints,
|
|
45
|
+
createBasinDrain: () => createBasinDrain,
|
|
46
|
+
createDrainUses: () => createDrainUses,
|
|
39
47
|
createEnginePartPhysics: () => createEnginePartPhysics,
|
|
40
48
|
createFixtureEmitters: () => createFixtureEmitters,
|
|
41
49
|
createObjectControls: () => createObjectControls,
|
|
42
50
|
createSinkRoutines: () => createSinkRoutines,
|
|
51
|
+
createUseBody: () => createUseBody,
|
|
43
52
|
createWorld: () => createWorld,
|
|
53
|
+
devicePointOf: () => devicePointOf,
|
|
44
54
|
dirtyDishes: () => dirtyDishes,
|
|
45
55
|
disposeChain: () => disposeChain,
|
|
46
56
|
endsMember: () => endsMember,
|
|
@@ -71,6 +81,227 @@ var GameInteractables = (() => {
|
|
|
71
81
|
wrapsMember: () => wrapsMember
|
|
72
82
|
});
|
|
73
83
|
|
|
84
|
+
// src/basin-drain.ts
|
|
85
|
+
var FLUSH_POUR_SECONDS = 3;
|
|
86
|
+
var CLOGGED = 0.5;
|
|
87
|
+
var REFILL_RATE = 0.12;
|
|
88
|
+
var BREAK_DEPTH = 0.035;
|
|
89
|
+
var WEIR_SHARE = 0.25;
|
|
90
|
+
var SEEP = 0.04;
|
|
91
|
+
var TURN_PER_LITRE = 2.4;
|
|
92
|
+
var TRAP_LITRES = 3.5;
|
|
93
|
+
var PLUNGE_PACKED = 0.34;
|
|
94
|
+
var PLUNGE_LODGED = 0.2;
|
|
95
|
+
var PLUNGER_WATER = 0.03;
|
|
96
|
+
var SOFT_SQUEEZE = 1.6;
|
|
97
|
+
var SWIRL_SETTLED = 1e-4;
|
|
98
|
+
var clamp01 = (v) => Math.min(1, Math.max(0, v));
|
|
99
|
+
var passingSize = (size) => [...size].sort((a, b) => b - a)[1] ?? 0;
|
|
100
|
+
function createBasinDrain(basin, drain) {
|
|
101
|
+
const width = basin.to[0] - basin.from[0];
|
|
102
|
+
const deep = basin.to[2] - basin.from[2];
|
|
103
|
+
const radius = Math.min(width, deep) / 2;
|
|
104
|
+
const area = basin.shape === "round" ? Math.PI * radius * radius : width * deep;
|
|
105
|
+
const litresAt = (level) => area * level * 1e3;
|
|
106
|
+
const levelOf = (litres) => litres / (area * 1e3);
|
|
107
|
+
const capacity = litresAt(basin.to[1] - basin.from[1]);
|
|
108
|
+
const still = litresAt(drain.weir);
|
|
109
|
+
const water = { litres: still, phase: "still", swirl: 0, turned: 0, clog: 0, cause: "none", cistern: 1, pouring: 0, pourRate: 0, carried: 0 };
|
|
110
|
+
let serial = 0;
|
|
111
|
+
let contents = [];
|
|
112
|
+
let shown = null;
|
|
113
|
+
const step = { spilled: 0, swallowed: [] };
|
|
114
|
+
const open = () => Math.max(SEEP, 1 - water.clog);
|
|
115
|
+
const lodge = (c, packed) => {
|
|
116
|
+
c.stage = "lodged";
|
|
117
|
+
c.depth = 1;
|
|
118
|
+
c.radius = 0;
|
|
119
|
+
water.clog = packed ? Math.max(water.clog, Math.min(0.95, water.clog + 0.55 + 0.3 * (c.kg / drain.carries))) : 0.97;
|
|
120
|
+
water.cause = water.cause === "object" || !packed ? "object" : "packed";
|
|
121
|
+
};
|
|
122
|
+
const reachTrap = (c, swallowed) => {
|
|
123
|
+
const hard = c.kind === "object";
|
|
124
|
+
if (passingSize(c.size) > drain.trap * (hard ? 1 : SOFT_SQUEEZE) || !hard && water.carried + c.kg > drain.carries) {
|
|
125
|
+
lodge(c, !hard);
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
if (!hard) water.carried += c.kg;
|
|
129
|
+
c.stage = "gone";
|
|
130
|
+
if (c.objectId) swallowed.push(c.objectId);
|
|
131
|
+
return true;
|
|
132
|
+
};
|
|
133
|
+
const stepContents = (moved, pulled, swallowed) => {
|
|
134
|
+
water.turned += moved * TURN_PER_LITRE;
|
|
135
|
+
const takesUrine = water.phase === "siphon" && water.swirl > 0.3;
|
|
136
|
+
let leaving = false;
|
|
137
|
+
for (const c of contents) {
|
|
138
|
+
if (c.kind === "urine" && takesUrine) leaving = true;
|
|
139
|
+
if (c.stage === "gone" || c.stage === "lodged") continue;
|
|
140
|
+
c.angle = c.start + water.turned;
|
|
141
|
+
if (water.phase !== "siphon" || c.kind === "urine") continue;
|
|
142
|
+
c.stage = "going";
|
|
143
|
+
c.travel = clamp01(c.travel + pulled / TRAP_LITRES);
|
|
144
|
+
c.depth = Math.max(c.depth, c.travel);
|
|
145
|
+
c.radius = c.startRadius * (1 - c.travel);
|
|
146
|
+
if (c.travel >= 1 && reachTrap(c, swallowed)) leaving = true;
|
|
147
|
+
}
|
|
148
|
+
if (leaving) contents = contents.filter((c) => c.stage !== "gone" && !(c.kind === "urine" && takesUrine));
|
|
149
|
+
};
|
|
150
|
+
const outflow = (dt) => {
|
|
151
|
+
const level = levelOf(water.litres);
|
|
152
|
+
if (water.phase === "siphon") return drain.siphon * open() * dt * Math.sqrt(clamp01(level / Math.max(1e-3, drain.weir)));
|
|
153
|
+
const head = level - drain.weir;
|
|
154
|
+
if (head <= 0) return 0;
|
|
155
|
+
return drain.siphon * WEIR_SHARE * open() * dt * Math.sqrt(clamp01(head / drain.prime));
|
|
156
|
+
};
|
|
157
|
+
const stepPhase = () => {
|
|
158
|
+
const head = levelOf(water.litres) - drain.weir;
|
|
159
|
+
if (water.phase !== "siphon" && head >= drain.prime && open() > CLOGGED) {
|
|
160
|
+
water.phase = "siphon";
|
|
161
|
+
water.carried = 0;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (water.phase === "siphon" && (head <= -BREAK_DEPTH || open() <= CLOGGED)) water.phase = "refill";
|
|
165
|
+
if (water.phase === "refill" && water.litres >= still - 1e-6 && water.pouring <= 0) water.phase = "still";
|
|
166
|
+
if (water.phase === "still" && water.pouring > 0) water.phase = "filling";
|
|
167
|
+
if (water.phase === "filling" && water.pouring <= 0 && head <= 1e-4) water.phase = "still";
|
|
168
|
+
};
|
|
169
|
+
const stepInflow = (dt) => {
|
|
170
|
+
const poured = water.pouring > 0 ? water.pourRate * Math.min(dt, water.pouring) : 0;
|
|
171
|
+
water.pouring = Math.max(0, water.pouring - dt);
|
|
172
|
+
water.litres += poured;
|
|
173
|
+
if ((water.phase === "refill" || water.phase === "still") && water.litres < still && water.clog < CLOGGED) water.litres = Math.min(still, water.litres + REFILL_RATE * dt);
|
|
174
|
+
return poured;
|
|
175
|
+
};
|
|
176
|
+
return {
|
|
177
|
+
flush(asked) {
|
|
178
|
+
shown = null;
|
|
179
|
+
const litresIn = asked * water.cistern;
|
|
180
|
+
water.cistern = 0;
|
|
181
|
+
if (litresIn <= 0) return 0;
|
|
182
|
+
water.pouring = FLUSH_POUR_SECONDS;
|
|
183
|
+
water.pourRate = litresIn / FLUSH_POUR_SECONDS;
|
|
184
|
+
if (water.phase === "still") water.phase = "filling";
|
|
185
|
+
return litresIn;
|
|
186
|
+
},
|
|
187
|
+
add(content) {
|
|
188
|
+
shown = null;
|
|
189
|
+
water.litres += content.litres ?? 0;
|
|
190
|
+
const k = serial++;
|
|
191
|
+
const start = k * 2.39996;
|
|
192
|
+
const startRadius = 0.25 + k * 0.37 % 0.45;
|
|
193
|
+
contents.push({
|
|
194
|
+
start,
|
|
195
|
+
startRadius,
|
|
196
|
+
travel: 0,
|
|
197
|
+
id: `c${k}`,
|
|
198
|
+
kind: content.kind,
|
|
199
|
+
kg: content.kg,
|
|
200
|
+
size: content.size,
|
|
201
|
+
...content.objectId ? { objectId: content.objectId } : {},
|
|
202
|
+
stage: "afloat",
|
|
203
|
+
angle: start + water.turned,
|
|
204
|
+
radius: startRadius,
|
|
205
|
+
depth: content.kind === "object" ? 0.5 : 0
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
plunge() {
|
|
209
|
+
shown = null;
|
|
210
|
+
if (levelOf(water.litres) < PLUNGER_WATER) return false;
|
|
211
|
+
if (water.clog <= 0) return true;
|
|
212
|
+
const lodged = contents.filter((c) => c.stage === "lodged");
|
|
213
|
+
const hard = lodged.some((c) => c.kind === "object");
|
|
214
|
+
water.clog = Math.max(0, water.clog - (hard ? PLUNGE_LODGED : PLUNGE_PACKED));
|
|
215
|
+
if (water.clog > CLOGGED * 0.4) return true;
|
|
216
|
+
water.clog = 0;
|
|
217
|
+
water.cause = "none";
|
|
218
|
+
for (const c of lodged) {
|
|
219
|
+
if (c.kind === "object") Object.assign(c, { stage: "afloat", depth: 0.6, radius: 0.3, startRadius: 0.3, travel: 0 });
|
|
220
|
+
else c.stage = "gone";
|
|
221
|
+
}
|
|
222
|
+
contents = contents.filter((c) => c.stage !== "gone");
|
|
223
|
+
return true;
|
|
224
|
+
},
|
|
225
|
+
update(dt) {
|
|
226
|
+
step.spilled = 0;
|
|
227
|
+
step.swallowed.length = 0;
|
|
228
|
+
if (dt <= 0) return step;
|
|
229
|
+
const { litres, swirl, cistern, phase, clog } = water;
|
|
230
|
+
const count = contents.length;
|
|
231
|
+
water.cistern = clamp01(water.cistern + dt / drain.refill);
|
|
232
|
+
const poured = stepInflow(dt);
|
|
233
|
+
const out = Math.min(water.litres, outflow(dt));
|
|
234
|
+
water.litres -= out;
|
|
235
|
+
stepPhase();
|
|
236
|
+
const pull = water.phase === "siphon" ? clamp01(out / (drain.siphon * dt)) : 0;
|
|
237
|
+
const jets = poured > 0 ? 0.35 : 0;
|
|
238
|
+
const swirlTo = Math.max(pull, jets);
|
|
239
|
+
water.swirl = Math.abs(swirlTo - water.swirl) < SWIRL_SETTLED ? swirlTo : water.swirl + (swirlTo - water.swirl) * clamp01(dt * 6);
|
|
240
|
+
const moved = poured + out;
|
|
241
|
+
stepContents(moved, water.phase === "siphon" ? out : 0, step.swallowed);
|
|
242
|
+
step.spilled = Math.max(0, water.litres - capacity);
|
|
243
|
+
water.litres -= step.spilled;
|
|
244
|
+
const changed = moved > 0 || water.litres !== litres || water.swirl !== swirl || water.cistern !== cistern || water.phase !== phase || water.clog !== clog || contents.length !== count;
|
|
245
|
+
if (changed) shown = null;
|
|
246
|
+
return step;
|
|
247
|
+
},
|
|
248
|
+
state() {
|
|
249
|
+
shown ?? (shown = {
|
|
250
|
+
litres: water.litres,
|
|
251
|
+
level: levelOf(water.litres),
|
|
252
|
+
phase: water.phase,
|
|
253
|
+
swirl: water.swirl,
|
|
254
|
+
turned: water.turned,
|
|
255
|
+
clog: water.clog,
|
|
256
|
+
cause: water.cause,
|
|
257
|
+
cistern: water.cistern,
|
|
258
|
+
contents: contents.map(({ start: _start, startRadius: _startRadius, travel: _travel, ...c }) => c)
|
|
259
|
+
});
|
|
260
|
+
return shown;
|
|
261
|
+
},
|
|
262
|
+
litres: () => water.litres,
|
|
263
|
+
level: () => levelOf(water.litres),
|
|
264
|
+
clog: () => water.clog,
|
|
265
|
+
cause: () => water.cause,
|
|
266
|
+
dirty: () => contents.some((c) => c.kind !== "object"),
|
|
267
|
+
save: () => ({ water: { ...water }, serial, contents: contents.map((c) => ({ ...c })) }),
|
|
268
|
+
restore(saved) {
|
|
269
|
+
shown = null;
|
|
270
|
+
Object.assign(water, saved.water);
|
|
271
|
+
serial = saved.serial;
|
|
272
|
+
contents = saved.contents.map((c) => ({ ...c }));
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/gestures.ts
|
|
278
|
+
var GESTURE_OF_ACTION = {
|
|
279
|
+
toggle_part: null,
|
|
280
|
+
open_container: null,
|
|
281
|
+
take: null,
|
|
282
|
+
sit: null,
|
|
283
|
+
toggle_device: "press",
|
|
284
|
+
cycle_device: "press",
|
|
285
|
+
toggle_switch: "flip",
|
|
286
|
+
toggle_breaker: "flip",
|
|
287
|
+
toggle_main: "flip",
|
|
288
|
+
toggle_fixture: "turn",
|
|
289
|
+
toggle_burner: "turn",
|
|
290
|
+
ignite: "strike",
|
|
291
|
+
toggle_fuel: "turn",
|
|
292
|
+
read: "read"
|
|
293
|
+
};
|
|
294
|
+
var GESTURE_OF_USE = {
|
|
295
|
+
program: "press",
|
|
296
|
+
put_in: "put_in",
|
|
297
|
+
empty: "tip",
|
|
298
|
+
fill: "pour",
|
|
299
|
+
relieve: null,
|
|
300
|
+
plunge: null,
|
|
301
|
+
wash: null,
|
|
302
|
+
drink: null
|
|
303
|
+
};
|
|
304
|
+
|
|
74
305
|
// src/fixture-emitters.ts
|
|
75
306
|
var FLUSH_RUN_SECONDS = 2;
|
|
76
307
|
var START_OPENING = 0.05;
|
|
@@ -295,7 +526,17 @@ var GameInteractables = (() => {
|
|
|
295
526
|
done_relieve_feces: "You pooed in {name}",
|
|
296
527
|
done_clean: "{name} flushed clean",
|
|
297
528
|
"use.wash_dishes": "Wash the dishes",
|
|
298
|
-
"use.drink_water": "Drink water",
|
|
529
|
+
"use.drink_water": "Drink water from the glass",
|
|
530
|
+
"use.drink_from_hands": "Drink water from your hands",
|
|
531
|
+
needs_in_hand: "Pick up {item} first",
|
|
532
|
+
needs_vessel: "You need a glass",
|
|
533
|
+
vessel_not_empty: "Empty {item} first",
|
|
534
|
+
hands_busy: "Your hands are busy",
|
|
535
|
+
no_animation: "Cannot be done here: the body has no movement for it",
|
|
536
|
+
needs_free_hand: "You need your hands free",
|
|
537
|
+
not_drunk: "No water was drunk",
|
|
538
|
+
drink_from_vessel: "You have a glass in your hand: drink from it",
|
|
539
|
+
done_drink_hands: "You drank {litres} l of water from your hands",
|
|
299
540
|
busy: "Already in use",
|
|
300
541
|
needs_running: "Turn the water on first",
|
|
301
542
|
needs_item: "You need {need}",
|
|
@@ -305,7 +546,21 @@ var GameInteractables = (() => {
|
|
|
305
546
|
started_drink: "{label}\u2026",
|
|
306
547
|
done_wash: "Washed and rinsed",
|
|
307
548
|
done_wash_dishes: "Dishes washed: {n} on the rack",
|
|
308
|
-
done_drink: "You drank {litres} l of water"
|
|
549
|
+
done_drink: "You drank {litres} l of water",
|
|
550
|
+
"use.plunge": "Unclog {name} with the plunger",
|
|
551
|
+
needs_plunger: "Hold a plunger",
|
|
552
|
+
plunge_no_water: "No water over the trap for the plunger",
|
|
553
|
+
done_plunge: "You work the plunger in {name}",
|
|
554
|
+
plunge_cleared: "{name} unclogged: the water goes down",
|
|
555
|
+
plunge_object: "{name} unclogged: something came back up the trap",
|
|
556
|
+
plunge_still: "{name} is still clogged",
|
|
557
|
+
clogged: "{name} is clogged",
|
|
558
|
+
overflow: "{name} is overflowing",
|
|
559
|
+
needs_body: "There is no body here to use {name}",
|
|
560
|
+
host_lacks: "This place cannot run {name} (it lacks {capability})",
|
|
561
|
+
body_no_seat: "{name} has no seat to sit on",
|
|
562
|
+
body_object_gone: "{name} is not here",
|
|
563
|
+
body_busy: "You are busy with something else"
|
|
309
564
|
},
|
|
310
565
|
"pt-BR": {
|
|
311
566
|
"prompt.open": "Abrir {name}",
|
|
@@ -360,7 +615,17 @@ var GameInteractables = (() => {
|
|
|
360
615
|
done_relieve_feces: "Voc\xEA fez coc\xF4 em {name}",
|
|
361
616
|
done_clean: "Descarga dada: {name} limpo",
|
|
362
617
|
"use.wash_dishes": "Lavar a lou\xE7a",
|
|
363
|
-
"use.drink_water": "Beber \xE1gua",
|
|
618
|
+
"use.drink_water": "Beber \xE1gua no copo",
|
|
619
|
+
"use.drink_from_hands": "Beber \xE1gua com a m\xE3o",
|
|
620
|
+
needs_in_hand: "Pegue {item} antes",
|
|
621
|
+
needs_vessel: "Precisa de um copo",
|
|
622
|
+
vessel_not_empty: "Esvazie {item} antes",
|
|
623
|
+
hands_busy: "As m\xE3os est\xE3o ocupadas",
|
|
624
|
+
no_animation: "N\xE3o d\xE1 para fazer isso aqui: o corpo n\xE3o tem o movimento",
|
|
625
|
+
needs_free_hand: "Precisa das m\xE3os livres",
|
|
626
|
+
not_drunk: "Nenhuma \xE1gua foi bebida",
|
|
627
|
+
drink_from_vessel: "Voc\xEA est\xE1 com um copo na m\xE3o: beba nele",
|
|
628
|
+
done_drink_hands: "Voc\xEA bebeu {litres} l de \xE1gua com a m\xE3o",
|
|
364
629
|
busy: "J\xE1 est\xE1 em uso",
|
|
365
630
|
needs_running: "Abra a \xE1gua primeiro",
|
|
366
631
|
needs_item: "Precisa de {need}",
|
|
@@ -370,7 +635,21 @@ var GameInteractables = (() => {
|
|
|
370
635
|
started_drink: "{label}\u2026",
|
|
371
636
|
done_wash: "Lavado e enxaguado",
|
|
372
637
|
done_wash_dishes: "Lou\xE7a lavada: {n} no escorredor",
|
|
373
|
-
done_drink: "Voc\xEA bebeu {litres} l de \xE1gua"
|
|
638
|
+
done_drink: "Voc\xEA bebeu {litres} l de \xE1gua",
|
|
639
|
+
"use.plunge": "Desentupir {name} com o desentupidor",
|
|
640
|
+
needs_plunger: "Segure um desentupidor",
|
|
641
|
+
plunge_no_water: "Sem \xE1gua sobre o sif\xE3o para o desentupidor",
|
|
642
|
+
done_plunge: "Voc\xEA bombeia o desentupidor em {name}",
|
|
643
|
+
plunge_cleared: "{name} desentupido: a \xE1gua desce",
|
|
644
|
+
plunge_object: "{name} desentupido: uma coisa voltou do sif\xE3o",
|
|
645
|
+
plunge_still: "{name} ainda est\xE1 entupido",
|
|
646
|
+
clogged: "{name} entupiu",
|
|
647
|
+
overflow: "{name} est\xE1 transbordando",
|
|
648
|
+
needs_body: "N\xE3o h\xE1 corpo aqui para usar {name}",
|
|
649
|
+
host_lacks: "Este lugar n\xE3o sabe usar {name} (falta {capability})",
|
|
650
|
+
body_no_seat: "{name} n\xE3o tem assento para sentar",
|
|
651
|
+
body_object_gone: "{name} n\xE3o est\xE1 aqui",
|
|
652
|
+
body_busy: "Voc\xEA est\xE1 ocupado com outra coisa"
|
|
374
653
|
}
|
|
375
654
|
};
|
|
376
655
|
function pickLocale(locale) {
|
|
@@ -1399,6 +1678,7 @@ var GameInteractables = (() => {
|
|
|
1399
1678
|
id,
|
|
1400
1679
|
object: o.id,
|
|
1401
1680
|
kind: i.action.do,
|
|
1681
|
+
...GESTURE_OF_ACTION[i.action.do] ? { gesture: GESTURE_OF_ACTION[i.action.do] } : {},
|
|
1402
1682
|
pos: toWorld(o, i.pos),
|
|
1403
1683
|
radius: i.radius ?? DEFAULT_RADIUS,
|
|
1404
1684
|
label: p.label,
|
|
@@ -1776,6 +2056,7 @@ var GameInteractables = (() => {
|
|
|
1776
2056
|
burners: /* @__PURE__ */ new Map(),
|
|
1777
2057
|
tanks: /* @__PURE__ */ new Map(),
|
|
1778
2058
|
fixtures: /* @__PURE__ */ new Map(),
|
|
2059
|
+
drains: /* @__PURE__ */ new Map(),
|
|
1779
2060
|
soft: /* @__PURE__ */ new Map(),
|
|
1780
2061
|
hp: /* @__PURE__ */ new Map(),
|
|
1781
2062
|
interactions: spec.interactions ?? deriveInteractions(spec)
|
|
@@ -1808,6 +2089,7 @@ var GameInteractables = (() => {
|
|
|
1808
2089
|
for (const b of spec.burners ?? []) o.burners.set(b.id, { spec: b, on: false, lit: false, smoke: 0 });
|
|
1809
2090
|
for (const tk of spec.tanks ?? []) o.tanks.set(tk.id, { spec: tk, level: clamp(tk.level ?? tk.capacity, 0, tk.capacity) });
|
|
1810
2091
|
for (const f of spec.fixtures ?? []) o.fixtures.set(f.id, { spec: f, on: false, flowing: false, frac: 0, timer: 0 });
|
|
2092
|
+
for (const b of spec.basins ?? []) if (b.drain) o.drains.set(b.id, createBasinDrain(b, b.drain));
|
|
1811
2093
|
let n = 0;
|
|
1812
2094
|
for (const s of spec.soft ?? []) {
|
|
1813
2095
|
const driver = options.partPhysics?.attachSoft?.(id, s, pub.transform);
|
|
@@ -1840,7 +2122,8 @@ var GameInteractables = (() => {
|
|
|
1840
2122
|
burners: Object.fromEntries([...o.burners].map(([k, b]) => [k, { on: b.on, lit: b.lit }])),
|
|
1841
2123
|
tanks: Object.fromEntries([...o.tanks].map(([k, tk]) => [k, tk.level])),
|
|
1842
2124
|
fixtures: Object.fromEntries([...o.fixtures].map(([k, f]) => [k, f.on])),
|
|
1843
|
-
hp: Object.fromEntries([...o.hp].map(([k, h]) => [k, h.hp]))
|
|
2125
|
+
hp: Object.fromEntries([...o.hp].map(([k, h]) => [k, h.hp])),
|
|
2126
|
+
drains: Object.fromEntries([...o.drains].map(([k, d]) => [k, d.save()]))
|
|
1844
2127
|
};
|
|
1845
2128
|
}
|
|
1846
2129
|
return {
|
|
@@ -1906,6 +2189,7 @@ var GameInteractables = (() => {
|
|
|
1906
2189
|
const h = o.hp.get(k);
|
|
1907
2190
|
if (h) h.hp = v;
|
|
1908
2191
|
}
|
|
2192
|
+
for (const [k, v] of Object.entries(st.drains ?? {})) o.drains.get(k)?.restore(v);
|
|
1909
2193
|
}
|
|
1910
2194
|
grid = state.grid;
|
|
1911
2195
|
main = state.main ?? true;
|
|
@@ -2030,6 +2314,7 @@ var GameInteractables = (() => {
|
|
|
2030
2314
|
locale = l;
|
|
2031
2315
|
table = resolveStrings(locale, options.strings);
|
|
2032
2316
|
},
|
|
2317
|
+
drain: (objectId, basin) => objs.get(objectId)?.drains.get(basin),
|
|
2033
2318
|
serialize,
|
|
2034
2319
|
load
|
|
2035
2320
|
};
|
|
@@ -2554,6 +2839,270 @@ var GameInteractables = (() => {
|
|
|
2554
2839
|
return wrapsMember(member, other) || endsMember(member, other);
|
|
2555
2840
|
}
|
|
2556
2841
|
|
|
2842
|
+
// ../game-contracts/dist/index.js
|
|
2843
|
+
var DEFAULT_BLAST_IMPULSE = { bodyArea: 0.7, lift: 0.15, minSpeed: 0.3, tntPerJoule: 0.24 / 2e5 };
|
|
2844
|
+
var DEFAULT_COST_ALLOCATION_BYTES = 1024 * 1024;
|
|
2845
|
+
var DEFERRED_QUEUE_ID = {
|
|
2846
|
+
DESTRUCTION_EVENTS: "destruction.events",
|
|
2847
|
+
BREACH_PAINT: "floorplan.breach-paint",
|
|
2848
|
+
BREACH_CUT: "floorplan.breach-cut",
|
|
2849
|
+
AUDIO_VOICES: "audio.voices",
|
|
2850
|
+
VEHICLE_CREASE: "vehicles.crease",
|
|
2851
|
+
AUDIO_OCCLUSION: "audio.occlusion",
|
|
2852
|
+
FLUID_FILM: "fluids.film",
|
|
2853
|
+
VEHICLE_LOD_BATCH: "vehicles.lod-batch",
|
|
2854
|
+
SETTLED_BATCH: "destruction.settled-batch",
|
|
2855
|
+
STATIC_BATCH: "render.static-batch",
|
|
2856
|
+
ANIMALS_STATIC_BATCH: "animals.static-batch",
|
|
2857
|
+
CHARACTERS_STATIC_BATCH: "characters.static-batch",
|
|
2858
|
+
HOUSE_SHADOW_BATCH: "floorplan.shadow-batch",
|
|
2859
|
+
DESTRUCTION_PREFIT: "destruction.prefit"
|
|
2860
|
+
};
|
|
2861
|
+
var DEFERRED_PRIORITY = {
|
|
2862
|
+
[DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS]: { priority: 300, phase: "present" },
|
|
2863
|
+
// every frame: the walls cut since the last frame are painted once each, and a hole must show in the frame of the blast
|
|
2864
|
+
[DEFERRED_QUEUE_ID.BREACH_CUT]: { priority: 260, phase: "present", minEveryFrames: 1 },
|
|
2865
|
+
[DEFERRED_QUEUE_ID.BREACH_PAINT]: { priority: 250, phase: "present", minEveryFrames: 1 },
|
|
2866
|
+
[DEFERRED_QUEUE_ID.AUDIO_VOICES]: { priority: 200, phase: "idle", reserveMs: 1 },
|
|
2867
|
+
[DEFERRED_QUEUE_ID.AUDIO_OCCLUSION]: { priority: 190, phase: "idle", minEveryFrames: 8 },
|
|
2868
|
+
[DEFERRED_QUEUE_ID.FLUID_FILM]: { priority: 120, phase: "idle", minEveryFrames: 2 },
|
|
2869
|
+
[DEFERRED_QUEUE_ID.VEHICLE_CREASE]: { priority: 100, phase: "idle" },
|
|
2870
|
+
[DEFERRED_QUEUE_ID.VEHICLE_LOD_BATCH]: { priority: 90, phase: "idle", minEveryFrames: 4 },
|
|
2871
|
+
[DEFERRED_QUEUE_ID.SETTLED_BATCH]: { priority: 70, phase: "idle", minEveryFrames: 8 },
|
|
2872
|
+
[DEFERRED_QUEUE_ID.STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
|
|
2873
|
+
[DEFERRED_QUEUE_ID.ANIMALS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
|
|
2874
|
+
[DEFERRED_QUEUE_ID.CHARACTERS_STATIC_BATCH]: { priority: 60, phase: "idle", minEveryFrames: 8 },
|
|
2875
|
+
[DEFERRED_QUEUE_ID.HOUSE_SHADOW_BATCH]: { priority: 50, phase: "idle", minEveryFrames: 8 },
|
|
2876
|
+
[DEFERRED_QUEUE_ID.DESTRUCTION_PREFIT]: { priority: 40, phase: "idle", minEveryFrames: 30 }
|
|
2877
|
+
};
|
|
2878
|
+
var MUST_DRAIN_QUEUE_IDS = /* @__PURE__ */ new Set([DEFERRED_QUEUE_ID.DESTRUCTION_EVENTS, DEFERRED_QUEUE_ID.BREACH_CUT]);
|
|
2879
|
+
var PLUNGE_STROKE_SECONDS = 0.8;
|
|
2880
|
+
var SURFACE_IDS = ["concrete", "asphalt", "wood", "tile", "dirt", "grass", "gravel", "sand", "metal", "water", "glass", "carpet"];
|
|
2881
|
+
var GAIT_IDS = ["walk", "run"];
|
|
2882
|
+
var LANDING_IDS = ["light", "heavy"];
|
|
2883
|
+
var BODY_SOUND_IDS = [
|
|
2884
|
+
"jump",
|
|
2885
|
+
"cloth_rustle",
|
|
2886
|
+
"body_fall",
|
|
2887
|
+
"fall_damage",
|
|
2888
|
+
"player_hurt",
|
|
2889
|
+
"player_breath_run",
|
|
2890
|
+
"player_death",
|
|
2891
|
+
"bite",
|
|
2892
|
+
"grab",
|
|
2893
|
+
"punch_swing",
|
|
2894
|
+
"punch_hit_body",
|
|
2895
|
+
"punch_hit_face",
|
|
2896
|
+
"punch_hit_object",
|
|
2897
|
+
"kick_swing",
|
|
2898
|
+
"kick_hit",
|
|
2899
|
+
"kick_hit_object",
|
|
2900
|
+
"shove_two_hands",
|
|
2901
|
+
"knife_swing",
|
|
2902
|
+
"knife_stab",
|
|
2903
|
+
"knife_slash",
|
|
2904
|
+
"knife_hit_object",
|
|
2905
|
+
"blunt_swing",
|
|
2906
|
+
"blunt_hit",
|
|
2907
|
+
"blunt_hit_object",
|
|
2908
|
+
"axe_swing",
|
|
2909
|
+
"axe_chop",
|
|
2910
|
+
"axe_hit_object"
|
|
2911
|
+
];
|
|
2912
|
+
var footstepSoundId = (surface, gait) => `footstep_${surface}_${gait}`;
|
|
2913
|
+
var FOOTSTEP_SOUND_IDS = SURFACE_IDS.flatMap((surface) => GAIT_IDS.map((gait) => footstepSoundId(surface, gait)));
|
|
2914
|
+
var LAND_SOUND_IDS = SURFACE_IDS.flatMap((surface) => LANDING_IDS.map((landing) => `land_${surface}_${landing}`));
|
|
2915
|
+
var BODY_FOLEY_IDS = [...FOOTSTEP_SOUND_IDS, ...LAND_SOUND_IDS, ...BODY_SOUND_IDS];
|
|
2916
|
+
var WORKER_KIND_ID = {
|
|
2917
|
+
GROUND_TILES: "destruction.ground-tiles",
|
|
2918
|
+
CROWD_PHYSICS: "crowd.physics",
|
|
2919
|
+
PIECE_BOXES: "destruction.piece-boxes",
|
|
2920
|
+
STATIC_COLLIDERS: "destruction.static-colliders",
|
|
2921
|
+
SHAPES_GENERATE: "shapes.generate",
|
|
2922
|
+
WORLD_REGION: "world.region",
|
|
2923
|
+
VEHICLE_HULL_PLAN: "vehicles.hull-plan"
|
|
2924
|
+
};
|
|
2925
|
+
var WORKER_KIND_DEFAULTS = {
|
|
2926
|
+
[WORKER_KIND_ID.GROUND_TILES]: { lane: "sim", priority: 300, latencyFrames: 2, late: "sync" },
|
|
2927
|
+
[WORKER_KIND_ID.CROWD_PHYSICS]: { lane: "sim", priority: 250, latencyFrames: 1, late: "sync" },
|
|
2928
|
+
[WORKER_KIND_ID.PIECE_BOXES]: { lane: "sim", priority: 200, latencyFrames: 2, late: "sync" },
|
|
2929
|
+
[WORKER_KIND_ID.STATIC_COLLIDERS]: { lane: "build", priority: 150, late: "sync" },
|
|
2930
|
+
[WORKER_KIND_ID.SHAPES_GENERATE]: { lane: "build", priority: 100, late: "sync" },
|
|
2931
|
+
[WORKER_KIND_ID.WORLD_REGION]: { lane: "background", priority: 10, latencyFrames: 10, late: "drop" },
|
|
2932
|
+
[WORKER_KIND_ID.VEHICLE_HULL_PLAN]: { lane: "build", priority: 120, late: "keep-waiting" }
|
|
2933
|
+
};
|
|
2934
|
+
|
|
2935
|
+
// src/drain-uses.ts
|
|
2936
|
+
var RELIEVE_SECONDS = 8;
|
|
2937
|
+
var LANDS_AT = 0.7;
|
|
2938
|
+
var FLUSH_LITRES = 6;
|
|
2939
|
+
var SWALLOW_SECONDS = 0.5;
|
|
2940
|
+
var SPILL_GATHER_SECONDS = 0.25;
|
|
2941
|
+
var URINE = { kind: "urine", kg: 0.3, litres: 0.3, size: [0.02, 0.02, 0.02] };
|
|
2942
|
+
var FECES = { kind: "feces", kg: 0.2, size: [0.12, 0.035, 0.035] };
|
|
2943
|
+
var PAPER = { kind: "paper", kg: 8e-3, size: [0.06, 0.03, 0.03] };
|
|
2944
|
+
var PEE = [URINE];
|
|
2945
|
+
var POO = [FECES, PAPER, PAPER];
|
|
2946
|
+
var HOST_NEEDS = ["setBasin", "spill", "looseInside", "swallow"];
|
|
2947
|
+
function createDrainUses(options) {
|
|
2948
|
+
const { spec, t, world, objectId } = options;
|
|
2949
|
+
const basins = /* @__PURE__ */ new Map();
|
|
2950
|
+
for (const b of spec.basins ?? []) {
|
|
2951
|
+
const drain = world.drain(objectId, b.id);
|
|
2952
|
+
if (!drain) continue;
|
|
2953
|
+
const centre = [(b.from[0] + b.to[0]) / 2, b.from[1], (b.from[2] + b.to[2]) / 2];
|
|
2954
|
+
basins.set(b.id, { spec: b, drain, centre, frontRim: [centre[0], b.to[1], b.to[2]], clogged: false, overflowing: false, spill: 0, spillTime: 0 });
|
|
2955
|
+
}
|
|
2956
|
+
const flushes = new Map(
|
|
2957
|
+
(spec.fixtures ?? []).flatMap((f) => f.cleans && basins.has(f.cleans) ? [[f.id, { basin: f.cleans, litres: f.volume ?? FLUSH_LITRES }]] : [])
|
|
2958
|
+
);
|
|
2959
|
+
const list = [...basins.values()];
|
|
2960
|
+
let states = {};
|
|
2961
|
+
const pending = [];
|
|
2962
|
+
const swallowing = [];
|
|
2963
|
+
let plunging = null;
|
|
2964
|
+
const typeKey = `type.${spec.type}`;
|
|
2965
|
+
const name = () => {
|
|
2966
|
+
const text = t(typeKey);
|
|
2967
|
+
return text === typeKey ? spec.type.replace(/_/g, " ") : text.charAt(0).toLowerCase() + text.slice(1);
|
|
2968
|
+
};
|
|
2969
|
+
const takeLoose = (b, host) => {
|
|
2970
|
+
const top = [b.spec.to[0], b.spec.to[1] + 0.08, b.spec.to[2]];
|
|
2971
|
+
const inWater = new Set(b.drain.state().contents.flatMap((c) => c.objectId ? [c.objectId] : []));
|
|
2972
|
+
for (const thing of host?.looseInside?.(b.spec.from, top) ?? []) {
|
|
2973
|
+
if (inWater.has(thing.id)) continue;
|
|
2974
|
+
b.drain.add({ kind: "object", kg: thing.kg, size: thing.size, objectId: thing.id });
|
|
2975
|
+
}
|
|
2976
|
+
};
|
|
2977
|
+
const report = (b, host) => {
|
|
2978
|
+
const clogged = b.drain.clog() >= CLOGGED;
|
|
2979
|
+
if (clogged && !b.clogged) host?.say(t("clogged", { name: name() }));
|
|
2980
|
+
b.clogged = clogged;
|
|
2981
|
+
};
|
|
2982
|
+
const stepPending = (dt) => {
|
|
2983
|
+
let kept = 0;
|
|
2984
|
+
for (const p of pending) {
|
|
2985
|
+
p.left -= dt;
|
|
2986
|
+
if (p.left > 0) {
|
|
2987
|
+
pending[kept++] = p;
|
|
2988
|
+
continue;
|
|
2989
|
+
}
|
|
2990
|
+
for (const content of p.lands) basins.get(p.basin)?.drain.add(content);
|
|
2991
|
+
}
|
|
2992
|
+
pending.length = kept;
|
|
2993
|
+
};
|
|
2994
|
+
const stepPlunge = (dt, host) => {
|
|
2995
|
+
if (!plunging) return;
|
|
2996
|
+
const b = basins.get(plunging.basin);
|
|
2997
|
+
plunging.left -= dt;
|
|
2998
|
+
plunging.stroke += dt;
|
|
2999
|
+
if (b && plunging.stroke >= PLUNGE_STROKE_SECONDS) {
|
|
3000
|
+
plunging.stroke -= PLUNGE_STROKE_SECONDS;
|
|
3001
|
+
const cause = b.drain.cause();
|
|
3002
|
+
b.drain.plunge();
|
|
3003
|
+
if (cause !== "none" && b.drain.cause() === "none") {
|
|
3004
|
+
host?.say(t(cause === "object" ? "plunge_object" : "plunge_cleared", { name: name() }));
|
|
3005
|
+
b.clogged = false;
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
if (plunging.left > 0) return;
|
|
3009
|
+
if (b && b.drain.clog() >= CLOGGED) host?.say(t("plunge_still", { name: name() }));
|
|
3010
|
+
plunging = null;
|
|
3011
|
+
};
|
|
3012
|
+
const stepSwallowing = (dt, host) => {
|
|
3013
|
+
let kept = 0;
|
|
3014
|
+
for (const s of swallowing) {
|
|
3015
|
+
s.time += dt;
|
|
3016
|
+
const progress = Math.min(1, s.time / SWALLOW_SECONDS);
|
|
3017
|
+
host?.swallow?.(s.id, s.point, progress);
|
|
3018
|
+
if (progress < 1) swallowing[kept++] = s;
|
|
3019
|
+
}
|
|
3020
|
+
swallowing.length = kept;
|
|
3021
|
+
};
|
|
3022
|
+
const stepSpill = (b, spilled, dt, host) => {
|
|
3023
|
+
if (spilled > 0 && !b.overflowing) host?.say(t("overflow", { name: name() }));
|
|
3024
|
+
b.overflowing = spilled > 0;
|
|
3025
|
+
b.spill += spilled;
|
|
3026
|
+
if (b.spill <= 0) return;
|
|
3027
|
+
b.spillTime += dt;
|
|
3028
|
+
if (b.spillTime < SPILL_GATHER_SECONDS) return;
|
|
3029
|
+
host?.spill?.(b.frontRim, b.spill, b.drain.dirty() ? "sewage" : "water");
|
|
3030
|
+
b.spill = 0;
|
|
3031
|
+
b.spillTime = 0;
|
|
3032
|
+
};
|
|
3033
|
+
const stepBasin = (b, dt, host) => {
|
|
3034
|
+
const step = b.drain.update(dt);
|
|
3035
|
+
for (const id of step.swallowed) swallowing.push({ id, point: b.centre, time: 0 });
|
|
3036
|
+
stepSpill(b, step.spilled, dt, host);
|
|
3037
|
+
host?.setBasin?.(b.spec.id, b.drain.litres());
|
|
3038
|
+
report(b, host);
|
|
3039
|
+
};
|
|
3040
|
+
return {
|
|
3041
|
+
has: (basin) => basins.has(basin),
|
|
3042
|
+
hostBlocked: (host) => HOST_NEEDS.find((need) => host[need] === void 0) ?? null,
|
|
3043
|
+
relieveBody(use, host) {
|
|
3044
|
+
const body = host.body?.();
|
|
3045
|
+
if (!body) return null;
|
|
3046
|
+
const seconds = use.seconds ?? RELIEVE_SECONDS;
|
|
3047
|
+
const b = basins.get(use.basin);
|
|
3048
|
+
if (use.kind === "urine" && use.stand && body.sex === "male") return { pose: "relieve_stand", seconds, at: use.stand, faces: b ? b.centre : [0, 0, 0] };
|
|
3049
|
+
return { pose: "relieve_sit", seconds, ...use.seat ? { seat: use.seat } : {} };
|
|
3050
|
+
},
|
|
3051
|
+
relieve(use, host, body) {
|
|
3052
|
+
if (use.cover) host.setPart(use.cover, true);
|
|
3053
|
+
if (use.ring) host.setPart(use.ring, body.pose === "relieve_stand");
|
|
3054
|
+
pending.push({ basin: use.basin, lands: use.kind === "urine" ? PEE : POO, left: body.seconds * LANDS_AT });
|
|
3055
|
+
return { ok: true, text: t(`done_relieve_${use.kind}`, { name: name() }), body };
|
|
3056
|
+
},
|
|
3057
|
+
plungeBlocked(use, host) {
|
|
3058
|
+
if (!host.hand()?.tools?.includes(use.tool)) return "needs_plunger";
|
|
3059
|
+
const b = basins.get(use.basin);
|
|
3060
|
+
return b && b.drain.level() < PLUNGER_WATER ? "plunge_no_water" : null;
|
|
3061
|
+
},
|
|
3062
|
+
plungeBody(use) {
|
|
3063
|
+
const b = basins.get(use.basin);
|
|
3064
|
+
return { pose: "plunge", seconds: use.seconds, at: use.stand, faces: b ? b.centre : [0, 0, 0] };
|
|
3065
|
+
},
|
|
3066
|
+
plunge(use, body) {
|
|
3067
|
+
plunging = { basin: use.basin, left: use.seconds, stroke: 0 };
|
|
3068
|
+
return { ok: true, text: t("done_plunge", { name: name() }), body };
|
|
3069
|
+
},
|
|
3070
|
+
flushed(fixture, host) {
|
|
3071
|
+
const flush = flushes.get(fixture);
|
|
3072
|
+
const b = flush ? basins.get(flush.basin) : void 0;
|
|
3073
|
+
if (!flush || !b) return false;
|
|
3074
|
+
takeLoose(b, host);
|
|
3075
|
+
b.drain.flush(flush.litres);
|
|
3076
|
+
return true;
|
|
3077
|
+
},
|
|
3078
|
+
update(dt, host) {
|
|
3079
|
+
stepPending(dt);
|
|
3080
|
+
stepPlunge(dt, host);
|
|
3081
|
+
stepSwallowing(dt, host);
|
|
3082
|
+
for (const b of list) stepBasin(b, dt, host);
|
|
3083
|
+
},
|
|
3084
|
+
dispose(host) {
|
|
3085
|
+
for (const s of swallowing) host?.swallow?.(s.id, s.point, 1);
|
|
3086
|
+
swallowing.length = 0;
|
|
3087
|
+
pending.length = 0;
|
|
3088
|
+
plunging = null;
|
|
3089
|
+
},
|
|
3090
|
+
soil(basin) {
|
|
3091
|
+
const contents = basins.get(basin)?.drain.state().contents ?? [];
|
|
3092
|
+
if (contents.some((c) => c.kind === "feces" || c.kind === "paper")) return "feces";
|
|
3093
|
+
return contents.some((c) => c.kind === "urine") ? "urine" : "clean";
|
|
3094
|
+
},
|
|
3095
|
+
state() {
|
|
3096
|
+
for (const b of list) {
|
|
3097
|
+
if (states[b.spec.id] === b.drain.state()) continue;
|
|
3098
|
+
states = Object.fromEntries(list.map((each) => [each.spec.id, each.drain.state()]));
|
|
3099
|
+
break;
|
|
3100
|
+
}
|
|
3101
|
+
return states;
|
|
3102
|
+
}
|
|
3103
|
+
};
|
|
3104
|
+
}
|
|
3105
|
+
|
|
2557
3106
|
// src/fits-volume.ts
|
|
2558
3107
|
function fitsInVolume(size, half) {
|
|
2559
3108
|
const thing = [...size].sort((a, b) => b - a);
|
|
@@ -2566,8 +3115,11 @@ var GameInteractables = (() => {
|
|
|
2566
3115
|
var DRINK_LITRES = 0.25;
|
|
2567
3116
|
var FILL_SHARE = 0.85;
|
|
2568
3117
|
var DRINK_LPS = 0.06;
|
|
3118
|
+
var DRINK_HANDS_LITRES = 0.12;
|
|
3119
|
+
var DRINK_HANDS_LPS = 0.03;
|
|
2569
3120
|
var REACH_SECONDS = 0.6;
|
|
2570
3121
|
var DRY_SECONDS = 0.5;
|
|
3122
|
+
var UNDER_STREAM = 0.14;
|
|
2571
3123
|
var SCRUBBED_DIRT = 0.15;
|
|
2572
3124
|
var YES = { available: true };
|
|
2573
3125
|
var idsOf = (need) => typeof need === "string" ? [need] : need;
|
|
@@ -2586,16 +3138,59 @@ var GameInteractables = (() => {
|
|
|
2586
3138
|
if (!dishes || !basin) return [];
|
|
2587
3139
|
return (host.itemsInside?.(dishes.ids, basin.from, basin.to) ?? []).filter((item) => (item.dirt ?? 0) > 0);
|
|
2588
3140
|
}
|
|
3141
|
+
function washBody(use, host) {
|
|
3142
|
+
const { playUse, lather, rinse, itemsInside, placeItem, setDirt, takeDose } = host;
|
|
3143
|
+
if (!playUse || !lather || !rinse) return null;
|
|
3144
|
+
if (use.dishes && (!itemsInside || !placeItem || !setDirt)) return null;
|
|
3145
|
+
if (use.dose && !takeDose) return null;
|
|
3146
|
+
return { playUse, lather, rinse, itemsInside, placeItem, setDirt, takeDose };
|
|
3147
|
+
}
|
|
3148
|
+
function vesselBody(host) {
|
|
3149
|
+
const { playUse, vesselAt, fillItem, drinkItem } = host;
|
|
3150
|
+
return playUse && vesselAt && fillItem && drinkItem ? { playUse, vesselAt, fillItem, drinkItem } : null;
|
|
3151
|
+
}
|
|
3152
|
+
function handsBody(host) {
|
|
3153
|
+
const { playUse, handsFree, drinkFromHands } = host;
|
|
3154
|
+
return playUse && handsFree && drinkFromHands ? { playUse, handsFree, drinkFromHands } : null;
|
|
3155
|
+
}
|
|
3156
|
+
var NO_BODY = { available: false, reason: "no_animation" };
|
|
3157
|
+
var NEEDS_FREE_HAND = { available: false, reason: "needs_free_hand" };
|
|
2589
3158
|
function sinkVerdict(use, spec, host, flowing) {
|
|
2590
|
-
if (use.do === "
|
|
3159
|
+
if (use.do === "drink") return drinkVerdict(use, host);
|
|
3160
|
+
if (!washBody(use, host)) return NO_BODY;
|
|
3161
|
+
if (use.requiresFlowing && !flowing) return { available: false, reason: "needs_running" };
|
|
2591
3162
|
const found = findNeeds(use.needs ?? [], host);
|
|
3163
|
+
if (!handsFreeFor(use, found.items, host)) return NEEDS_FREE_HAND;
|
|
2592
3164
|
if (found.missing) return { available: false, reason: "needs_item", vars: { need: found.missing[0] ?? "" } };
|
|
2593
|
-
if (use.do === "drink") return YES;
|
|
2594
3165
|
const dosed = use.dose ? found.items[use.dose.need] : void 0;
|
|
2595
3166
|
if (dosed && (dosed.remaining ?? 1) <= 0) return { available: false, reason: "item_spent", vars: { item: dosed.name } };
|
|
2596
3167
|
if (use.dishes && dirtyDishes(use, spec, host).length === 0) return { available: false, reason: "no_dirty_dishes" };
|
|
2597
3168
|
return YES;
|
|
2598
3169
|
}
|
|
3170
|
+
function handsAreFree(host) {
|
|
3171
|
+
return host.handsFree?.() ?? host.hand() === null;
|
|
3172
|
+
}
|
|
3173
|
+
function handsFreeFor(use, needed, host) {
|
|
3174
|
+
if (handsAreFree(host)) return true;
|
|
3175
|
+
if (host.hand() === null) return false;
|
|
3176
|
+
if (needed.some((item) => item.where === "hand")) return true;
|
|
3177
|
+
return use.dishes !== void 0 && host.itemAt?.(use.dishes.ids)?.where === "hand";
|
|
3178
|
+
}
|
|
3179
|
+
function drinkVerdict(use, host) {
|
|
3180
|
+
if (use.from === "hands") {
|
|
3181
|
+
const body2 = handsBody(host);
|
|
3182
|
+
if (!body2) return NO_BODY;
|
|
3183
|
+
if (body2.handsFree()) return YES;
|
|
3184
|
+
return host.vesselAt?.()?.where === "hand" ? { available: false, reason: "drink_from_vessel" } : NEEDS_FREE_HAND;
|
|
3185
|
+
}
|
|
3186
|
+
const body = vesselBody(host);
|
|
3187
|
+
if (!body) return NO_BODY;
|
|
3188
|
+
const vessel = body.vesselAt();
|
|
3189
|
+
if (!vessel) return { available: false, reason: "needs_vessel" };
|
|
3190
|
+
if (vessel.where !== "hand") return { available: false, reason: "needs_in_hand", vars: { item: vessel.name } };
|
|
3191
|
+
const other = vessel.liquid?.kind !== void 0 && vessel.liquid.kind !== "water" && vessel.liquid.litres > 1e-3;
|
|
3192
|
+
return other ? { available: false, reason: "vessel_not_empty", vars: { item: vessel.name } } : YES;
|
|
3193
|
+
}
|
|
2599
3194
|
var fixtureFlowLps = (fixture) => fixture ? (fixture.flow ?? FLOW_DEFAULTS[fixture.kind] ?? 6) / 60 : 0;
|
|
2600
3195
|
function runPhases(phases) {
|
|
2601
3196
|
let index = 0;
|
|
@@ -2619,6 +3214,10 @@ var GameInteractables = (() => {
|
|
|
2619
3214
|
const fixtureOf = (id) => (spec.fixtures ?? []).find((f) => f.id === id);
|
|
2620
3215
|
const flowing = (use) => world.water.isFlowing(objectId, use.fixture);
|
|
2621
3216
|
const water = (use) => flowing(use) ? fixtureFlowLps(fixtureOf(use.fixture)) : 0;
|
|
3217
|
+
const underStream = (use) => {
|
|
3218
|
+
const outlet = fixtureOf(use.fixture)?.outlet;
|
|
3219
|
+
return outlet ? [outlet[0], outlet[1] - UNDER_STREAM, outlet[2]] : void 0;
|
|
3220
|
+
};
|
|
2622
3221
|
const waterOf = (use) => {
|
|
2623
3222
|
let dry = 0;
|
|
2624
3223
|
return (dt) => {
|
|
@@ -2627,6 +3226,14 @@ var GameInteractables = (() => {
|
|
|
2627
3226
|
return dry > DRY_SECONDS ? null : flow;
|
|
2628
3227
|
};
|
|
2629
3228
|
};
|
|
3229
|
+
const approachPhase = (use, host) => {
|
|
3230
|
+
let walked = 0;
|
|
3231
|
+
const at = underStream(use);
|
|
3232
|
+
return (dt) => {
|
|
3233
|
+
walked += dt;
|
|
3234
|
+
return !at || !host.approach || walked > REACH_SECONDS * 3 || host.approach(at, dt);
|
|
3235
|
+
};
|
|
3236
|
+
};
|
|
2630
3237
|
const tapPhases = (use) => {
|
|
2631
3238
|
let opened = false;
|
|
2632
3239
|
const reach = wait(REACH_SECONDS);
|
|
@@ -2643,7 +3250,7 @@ var GameInteractables = (() => {
|
|
|
2643
3250
|
}
|
|
2644
3251
|
};
|
|
2645
3252
|
};
|
|
2646
|
-
const scrubAndRinse = (use,
|
|
3253
|
+
const scrubAndRinse = (use, body, target, fail) => {
|
|
2647
3254
|
const item = typeof target === "string" ? void 0 : target;
|
|
2648
3255
|
const id = item?.objectId ?? target;
|
|
2649
3256
|
const seconds = use.scrubSeconds ?? WASH_SCRUB_SECONDS;
|
|
@@ -2652,11 +3259,14 @@ var GameInteractables = (() => {
|
|
|
2652
3259
|
const scrub = (dt) => {
|
|
2653
3260
|
if (scrubbed < 0) {
|
|
2654
3261
|
scrubbed = 0;
|
|
2655
|
-
|
|
3262
|
+
if (!body.playUse(use.clip, item?.objectId, underStream(use))) {
|
|
3263
|
+
fail({ key: "hands_busy", ok: false });
|
|
3264
|
+
return true;
|
|
3265
|
+
}
|
|
2656
3266
|
}
|
|
2657
3267
|
scrubbed = Math.min(seconds, scrubbed + dt);
|
|
2658
|
-
|
|
2659
|
-
if (dirt > 0)
|
|
3268
|
+
body.lather(id, dt / seconds);
|
|
3269
|
+
if (dirt > 0) body.setDirt?.(id, dirt - (dirt - Math.min(dirt, SCRUBBED_DIRT)) * (scrubbed / seconds));
|
|
2660
3270
|
return scrubbed >= seconds;
|
|
2661
3271
|
};
|
|
2662
3272
|
const running = waterOf(use);
|
|
@@ -2666,13 +3276,13 @@ var GameInteractables = (() => {
|
|
|
2666
3276
|
fail({ key: "no_water", ok: false });
|
|
2667
3277
|
return true;
|
|
2668
3278
|
}
|
|
2669
|
-
if (flow <= 0 ||
|
|
2670
|
-
if (dirt > 0)
|
|
3279
|
+
if (flow <= 0 || body.rinse(id, flow, dt) > 0) return false;
|
|
3280
|
+
if (dirt > 0) body.setDirt?.(id, 0);
|
|
2671
3281
|
return true;
|
|
2672
3282
|
};
|
|
2673
3283
|
return [scrub, rinse];
|
|
2674
3284
|
};
|
|
2675
|
-
const startWash = (use, host) => {
|
|
3285
|
+
const startWash = (use, host, body) => {
|
|
2676
3286
|
const { items } = findNeeds(use.needs ?? [], host);
|
|
2677
3287
|
let end = null;
|
|
2678
3288
|
const fail = (reason) => {
|
|
@@ -2681,64 +3291,149 @@ var GameInteractables = (() => {
|
|
|
2681
3291
|
const tap = tapPhases(use);
|
|
2682
3292
|
const dosed = use.dose ? items[use.dose.need] : void 0;
|
|
2683
3293
|
const dose = () => {
|
|
2684
|
-
if (dosed &&
|
|
3294
|
+
if (dosed && body.takeDose?.(dosed.objectId, use.dose?.amount).taken === 0) fail({ key: "item_spent", ok: false, vars: { item: dosed.name } });
|
|
2685
3295
|
return true;
|
|
2686
3296
|
};
|
|
2687
3297
|
const dishes = use.dishes ? dirtyDishes(use, spec, host) : [];
|
|
2688
3298
|
const rack = use.dishes?.rack ?? [];
|
|
2689
|
-
const work = use.dishes ? dishes.flatMap((dish, index) => [...scrubAndRinse(use,
|
|
3299
|
+
const work = use.dishes ? dishes.flatMap((dish, index) => [...scrubAndRinse(use, body, dish, fail), placePhase(host, dish, rack[Math.min(index, rack.length - 1)])]) : scrubAndRinse(use, body, use.surface, fail);
|
|
2690
3300
|
const guarded = work.map((phase) => (dt) => end !== null || phase(dt));
|
|
2691
|
-
const run = runPhases([tap.open, dose, ...guarded, tap.close]);
|
|
3301
|
+
const run = runPhases([approachPhase(use, host), tap.open, dose, ...guarded, tap.close]);
|
|
2692
3302
|
const done = use.dishes ? { key: "done_wash_dishes", ok: true, vars: { n: String(dishes.length) } } : { key: "done_wash", ok: true, vars: { surface: use.surface } };
|
|
2693
3303
|
return { use: use.id, step: (dt) => run(dt) ? end ?? done : null };
|
|
2694
3304
|
};
|
|
2695
|
-
const startDrink = (use, host, vessel) => {
|
|
3305
|
+
const startDrink = (use, host, body, vessel) => {
|
|
2696
3306
|
const tap = tapPhases(use);
|
|
2697
3307
|
const want = Math.min(use.litres ?? DRINK_LITRES, (vessel.liquid?.capacity ?? DRINK_LITRES) * FILL_SHARE);
|
|
2698
3308
|
let filled = vessel.liquid?.kind === "water" ? vessel.liquid.litres : 0;
|
|
2699
3309
|
let drunk = 0;
|
|
2700
3310
|
let end = null;
|
|
2701
|
-
const take = () => {
|
|
2702
|
-
if (vessel.where !== "hand" && host.holdItem?.(vessel.objectId) === false) end = { key: "needs_item", ok: false, vars: { need: vessel.itemId } };
|
|
2703
|
-
else host.playUse?.(use.fillClip ?? "fill_cup", vessel.objectId);
|
|
2704
|
-
return true;
|
|
2705
|
-
};
|
|
2706
3311
|
const running = waterOf(use);
|
|
3312
|
+
const played = (clip, at) => {
|
|
3313
|
+
if (body.playUse(clip, vessel.objectId, at)) return true;
|
|
3314
|
+
end ?? (end = { key: "hands_busy", ok: false });
|
|
3315
|
+
return false;
|
|
3316
|
+
};
|
|
3317
|
+
let filling = false;
|
|
2707
3318
|
const fill = (dt) => {
|
|
2708
3319
|
if (end) return true;
|
|
3320
|
+
if (!filling && !(filling = played(use.fillClip ?? "fill_cup", underStream(use)))) return true;
|
|
2709
3321
|
const flow = running(dt);
|
|
2710
3322
|
if (flow === null) {
|
|
2711
3323
|
end = { key: "no_water", ok: false };
|
|
2712
3324
|
return true;
|
|
2713
3325
|
}
|
|
2714
3326
|
if (flow <= 0) return false;
|
|
2715
|
-
const took =
|
|
3327
|
+
const took = body.fillItem(vessel.objectId, "water", Math.min(flow * dt, want - filled));
|
|
2716
3328
|
filled += took;
|
|
2717
3329
|
return filled >= want - 1e-6 || took <= 0;
|
|
2718
3330
|
};
|
|
2719
3331
|
let sipping = false;
|
|
2720
3332
|
const drink = (dt) => {
|
|
2721
3333
|
if (end) return true;
|
|
2722
|
-
if (!sipping
|
|
2723
|
-
const sip =
|
|
3334
|
+
if (!sipping && !(sipping = played(use.clip))) return true;
|
|
3335
|
+
const sip = body.drinkItem(vessel.objectId, Math.min(DRINK_LPS * dt, filled - drunk));
|
|
2724
3336
|
drunk += sip;
|
|
2725
3337
|
return drunk >= filled - 1e-6 || sip <= 0;
|
|
2726
3338
|
};
|
|
2727
|
-
const
|
|
2728
|
-
const
|
|
2729
|
-
return { use: use.id, step: (dt) => run(dt) ? end ??
|
|
3339
|
+
const run = runPhases([approachPhase(use, host), tap.open, fill, tap.close, drink]);
|
|
3340
|
+
const done = () => drunk > 1e-3 ? { key: "done_drink", ok: true, vars: { litres: drunk.toFixed(2) } } : { key: "not_drunk", ok: false };
|
|
3341
|
+
return { use: use.id, step: (dt) => run(dt) ? end ?? done() : null };
|
|
3342
|
+
};
|
|
3343
|
+
const startDrinkHands = (use, host, body) => {
|
|
3344
|
+
const tap = tapPhases(use);
|
|
3345
|
+
const want = use.litres ?? DRINK_HANDS_LITRES;
|
|
3346
|
+
let drunk = 0;
|
|
3347
|
+
let end = null;
|
|
3348
|
+
const running = waterOf(use);
|
|
3349
|
+
let bent = false;
|
|
3350
|
+
const drink = (dt) => {
|
|
3351
|
+
if (!bent) {
|
|
3352
|
+
bent = body.playUse(use.clip, void 0, underStream(use));
|
|
3353
|
+
if (!bent) {
|
|
3354
|
+
end = { key: "hands_busy", ok: false };
|
|
3355
|
+
return true;
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
const flow = running(dt);
|
|
3359
|
+
if (flow === null) {
|
|
3360
|
+
end = { key: "no_water", ok: false };
|
|
3361
|
+
return true;
|
|
3362
|
+
}
|
|
3363
|
+
if (flow <= 0) return false;
|
|
3364
|
+
const sip = body.drinkFromHands("water", Math.min(DRINK_HANDS_LPS * dt, flow * dt, want - drunk));
|
|
3365
|
+
drunk += sip;
|
|
3366
|
+
return drunk >= want - 1e-6 || sip <= 0;
|
|
3367
|
+
};
|
|
3368
|
+
const run = runPhases([approachPhase(use, host), tap.open, drink, tap.close]);
|
|
3369
|
+
const done = () => drunk > 1e-3 ? { key: "done_drink_hands", ok: true, vars: { litres: drunk.toFixed(2) } } : { key: "not_drunk", ok: false };
|
|
3370
|
+
return { use: use.id, step: (dt) => run(dt) ? end ?? done() : null };
|
|
2730
3371
|
};
|
|
3372
|
+
const refused = (use, key) => ({ use: use.id, step: () => ({ key, ok: false }) });
|
|
2731
3373
|
return {
|
|
2732
3374
|
start(use, host) {
|
|
2733
|
-
if (use.do === "wash")
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
3375
|
+
if (use.do === "wash") {
|
|
3376
|
+
const body2 = washBody(use, host);
|
|
3377
|
+
return body2 ? startWash(use, host, body2) : refused(use, "no_animation");
|
|
3378
|
+
}
|
|
3379
|
+
if (use.from === "hands") {
|
|
3380
|
+
const body2 = handsBody(host);
|
|
3381
|
+
return body2 ? startDrinkHands(use, host, body2) : refused(use, "no_animation");
|
|
3382
|
+
}
|
|
3383
|
+
const body = vesselBody(host);
|
|
3384
|
+
const vessel = body?.vesselAt();
|
|
3385
|
+
if (!body) return refused(use, "no_animation");
|
|
3386
|
+
return vessel ? startDrink(use, host, body, vessel) : refused(use, "needs_vessel");
|
|
3387
|
+
}
|
|
3388
|
+
};
|
|
3389
|
+
}
|
|
3390
|
+
|
|
3391
|
+
// src/use-body.ts
|
|
3392
|
+
function createUseBody() {
|
|
3393
|
+
let running = null;
|
|
3394
|
+
const end = () => {
|
|
3395
|
+
const was = running;
|
|
3396
|
+
running = null;
|
|
3397
|
+
was?.body.end();
|
|
3398
|
+
};
|
|
3399
|
+
return {
|
|
3400
|
+
blocked(action, host) {
|
|
3401
|
+
const body = host.body?.();
|
|
3402
|
+
if (!body) return "needs_body";
|
|
3403
|
+
const why = body.blocked(action);
|
|
3404
|
+
return why ? `body_${why}` : null;
|
|
3405
|
+
},
|
|
3406
|
+
begin(action, host) {
|
|
3407
|
+
const body = host.body?.();
|
|
3408
|
+
if (!body) return false;
|
|
3409
|
+
end();
|
|
3410
|
+
if (!body.begin(action)) return false;
|
|
3411
|
+
running = { action, body, time: 0 };
|
|
3412
|
+
return true;
|
|
3413
|
+
},
|
|
3414
|
+
update(dt) {
|
|
3415
|
+
if (!running) return;
|
|
3416
|
+
running.time += dt;
|
|
3417
|
+
const { action, body, time } = running;
|
|
3418
|
+
if (!body.step(time, Math.min(1, time / action.seconds))) running = null;
|
|
3419
|
+
else if (time >= action.seconds) end();
|
|
3420
|
+
},
|
|
3421
|
+
end,
|
|
3422
|
+
get pose() {
|
|
3423
|
+
return running ? { pose: running.action.pose, time: running.time, progress: Math.min(1, running.time / running.action.seconds) } : null;
|
|
2737
3424
|
}
|
|
2738
3425
|
};
|
|
2739
3426
|
}
|
|
2740
3427
|
|
|
2741
3428
|
// src/object-uses.ts
|
|
3429
|
+
function devicePointOf(spec, device) {
|
|
3430
|
+
const own = (spec.interactions ?? []).find((i) => i.action.do === "toggle_device" && i.action.device === device);
|
|
3431
|
+
if (own) return own.pos;
|
|
3432
|
+
const def = (spec.devices ?? []).find((d) => d.id === device);
|
|
3433
|
+
if (!def) return void 0;
|
|
3434
|
+
const part = def.part ? spec.parts?.find((p) => p.id === def.part)?.pivot : void 0;
|
|
3435
|
+
return part ?? def.plug ?? [0, 1, 0];
|
|
3436
|
+
}
|
|
2742
3437
|
var OPEN = 0.5;
|
|
2743
3438
|
var PREFIX = "use.";
|
|
2744
3439
|
var SOIL_RANK = { clean: 0, urine: 1, feces: 2 };
|
|
@@ -2748,7 +3443,7 @@ var GameInteractables = (() => {
|
|
|
2748
3443
|
};
|
|
2749
3444
|
var accepts = (bowl, hand) => (bowl.accepts ?? []).some((id) => hand.itemId === id || hand.itemId.endsWith(`_${id}`));
|
|
2750
3445
|
var YES2 = { available: true };
|
|
2751
|
-
var no = (reason) => ({ available: false, reason });
|
|
3446
|
+
var no = (reason, vars) => ({ available: false, reason, ...vars ? { vars } : {} });
|
|
2752
3447
|
function createUses(options) {
|
|
2753
3448
|
const { spec, world, objectId } = options;
|
|
2754
3449
|
const all = spec.uses ?? [];
|
|
@@ -2761,6 +3456,8 @@ var GameInteractables = (() => {
|
|
|
2761
3456
|
let lastHost = null;
|
|
2762
3457
|
const sinkRoutines = createSinkRoutines({ spec, world, objectId });
|
|
2763
3458
|
let routine = null;
|
|
3459
|
+
const drains = createDrainUses({ spec, world, objectId, t: (key, vars) => world.t(key, vars) });
|
|
3460
|
+
const useBody = createUseBody();
|
|
2764
3461
|
const typeKey = `type.${spec.type}`;
|
|
2765
3462
|
const name = () => {
|
|
2766
3463
|
const text = world.t(typeKey);
|
|
@@ -2791,12 +3488,28 @@ var GameInteractables = (() => {
|
|
|
2791
3488
|
return fits ? YES2 : no("not_accepted");
|
|
2792
3489
|
}
|
|
2793
3490
|
case "relieve":
|
|
2794
|
-
return YES2;
|
|
3491
|
+
return drains.has(use.basin) ? drainVerdict(host, () => handsAreFree(host) ? null : "needs_free_hand", () => drains.relieveBody(use, host)) : YES2;
|
|
2795
3492
|
case "wash":
|
|
2796
3493
|
case "drink":
|
|
2797
3494
|
return routine ? no("busy") : sinkVerdict(use, spec, host, world.water.isFlowing(objectId, use.fixture));
|
|
3495
|
+
case "plunge":
|
|
3496
|
+
return drainVerdict(host, () => drains.plungeBlocked(use, host), () => drains.plungeBody(use));
|
|
2798
3497
|
}
|
|
2799
3498
|
};
|
|
3499
|
+
const drainVerdict = (host, rule, body) => {
|
|
3500
|
+
const missing = drains.hostBlocked(host);
|
|
3501
|
+
if (missing) return no("host_lacks", { capability: missing });
|
|
3502
|
+
const broken = rule();
|
|
3503
|
+
if (broken) return no(broken);
|
|
3504
|
+
const action = body();
|
|
3505
|
+
if (!action) return no("needs_body");
|
|
3506
|
+
const why = useBody.blocked(action, host);
|
|
3507
|
+
return why ? no(why) : YES2;
|
|
3508
|
+
};
|
|
3509
|
+
const withBody = (action, host, vars, run) => {
|
|
3510
|
+
if (!action) return { ok: false, text: world.t("needs_body", vars) };
|
|
3511
|
+
return useBody.begin(action, host) ? run(action) : { ok: false, text: world.t("body_busy", vars) };
|
|
3512
|
+
};
|
|
2800
3513
|
const itemName = (id) => {
|
|
2801
3514
|
const text = world.t(`item.${id}`);
|
|
2802
3515
|
return text === `item.${id}` ? id.replace(/_/g, " ") : text;
|
|
@@ -2832,7 +3545,10 @@ var GameInteractables = (() => {
|
|
|
2832
3545
|
}
|
|
2833
3546
|
case "fill":
|
|
2834
3547
|
return fill(bowls.get(use.bowl), host, vars);
|
|
3548
|
+
case "plunge":
|
|
3549
|
+
return withBody(drains.plungeBody(use), host, vars, (action) => drains.plunge(use, action));
|
|
2835
3550
|
case "relieve": {
|
|
3551
|
+
if (drains.has(use.basin)) return withBody(drains.relieveBody(use, host), host, vars, (action) => drains.relieve(use, host, action));
|
|
2836
3552
|
const now = soil.get(use.basin) ?? "clean";
|
|
2837
3553
|
soil.set(use.basin, SOIL_RANK[use.kind] > SOIL_RANK[now] ? use.kind : now);
|
|
2838
3554
|
return { ok: true, text: world.t(`done_relieve_${use.kind}`, vars) };
|
|
@@ -2862,6 +3578,12 @@ var GameInteractables = (() => {
|
|
|
2862
3578
|
const words = end.vars?.need ? { ...end.vars, need: itemName(end.vars.need) } : end.vars;
|
|
2863
3579
|
lastHost?.say(world.t(end.key, { name: name(), ...words }));
|
|
2864
3580
|
};
|
|
3581
|
+
const gestureOf = (use) => {
|
|
3582
|
+
const gesture = GESTURE_OF_USE[use.do];
|
|
3583
|
+
if (!gesture) return null;
|
|
3584
|
+
const at = use.do === "program" ? devicePointOf(spec, use.device) : use.do === "put_in" || use.do === "empty" ? containers.get(use.container)?.volume.center : use.do === "fill" ? bowls.get(use.bowl)?.center : void 0;
|
|
3585
|
+
return at ? { gesture, at: [at[0], at[1], at[2]] } : null;
|
|
3586
|
+
};
|
|
2865
3587
|
const visible = (use) => use.do !== "program" || program === null;
|
|
2866
3588
|
return {
|
|
2867
3589
|
has: (id) => id.startsWith(PREFIX),
|
|
@@ -2871,7 +3593,8 @@ var GameInteractables = (() => {
|
|
|
2871
3593
|
if (program) entries.push({ id: `${PREFIX}stop`, label: world.t("use.program.stop", { name: name(), left: clock(program.left) }), available: true });
|
|
2872
3594
|
for (const use of all.filter(visible)) {
|
|
2873
3595
|
const v = verdict(use, host);
|
|
2874
|
-
|
|
3596
|
+
const body = gestureOf(use);
|
|
3597
|
+
entries.push({ id: `${PREFIX}${use.id}`, label: labelOf(use, host), available: v.available, ...v.available ? {} : { reason: reasonOf(v, use, host) }, ...body ?? {} });
|
|
2875
3598
|
}
|
|
2876
3599
|
return entries;
|
|
2877
3600
|
},
|
|
@@ -2883,7 +3606,10 @@ var GameInteractables = (() => {
|
|
|
2883
3606
|
const v = verdict(use, host);
|
|
2884
3607
|
return v.available ? runUse(use, host) : { ok: false, text: reasonOf(v, use, host) };
|
|
2885
3608
|
},
|
|
2886
|
-
update(dt) {
|
|
3609
|
+
update(dt, host) {
|
|
3610
|
+
if (host) lastHost = host;
|
|
3611
|
+
drains.update(dt, lastHost);
|
|
3612
|
+
useBody.update(dt);
|
|
2887
3613
|
stepRoutine(dt);
|
|
2888
3614
|
if (!program) return;
|
|
2889
3615
|
program.left -= dt;
|
|
@@ -2893,17 +3619,25 @@ var GameInteractables = (() => {
|
|
|
2893
3619
|
program = null;
|
|
2894
3620
|
lastHost?.say(done);
|
|
2895
3621
|
},
|
|
2896
|
-
flushed(fixture) {
|
|
3622
|
+
flushed(fixture, host) {
|
|
3623
|
+
if (host) lastHost = host;
|
|
3624
|
+
if (drains.flushed(fixture, lastHost)) return;
|
|
2897
3625
|
const basin = cleans.get(fixture);
|
|
2898
3626
|
if (!basin || soil.get(basin) === "clean") return;
|
|
2899
3627
|
soil.set(basin, "clean");
|
|
2900
3628
|
lastHost?.say(world.t("done_clean", { name: name() }));
|
|
2901
3629
|
},
|
|
3630
|
+
dispose(host) {
|
|
3631
|
+
drains.dispose(host ?? lastHost);
|
|
3632
|
+
useBody.end();
|
|
3633
|
+
},
|
|
2902
3634
|
state: () => ({
|
|
2903
3635
|
bowls: Object.fromEntries(level),
|
|
2904
|
-
soil: Object.fromEntries(soil),
|
|
3636
|
+
soil: Object.fromEntries([...soil].map(([id, now]) => [id, drains.has(id) ? drains.soil(id) : now])),
|
|
3637
|
+
drains: drains.state(),
|
|
2905
3638
|
program: program ? { use: program.use.id, device: program.use.device, left: program.left } : null,
|
|
2906
|
-
routine: routine?.use ?? null
|
|
3639
|
+
routine: routine?.use ?? null,
|
|
3640
|
+
body: useBody.pose
|
|
2907
3641
|
})
|
|
2908
3642
|
};
|
|
2909
3643
|
}
|
|
@@ -2931,7 +3665,7 @@ var GameInteractables = (() => {
|
|
|
2931
3665
|
onEvent: (event) => {
|
|
2932
3666
|
if (event.type === "message") said.push(event.text);
|
|
2933
3667
|
if (event.type === "part" && event.object === CONTROLLED_OBJECT) forwardPart(event.part, event.target >= 0.5);
|
|
2934
|
-
if (event.type === "fixture" && event.object === CONTROLLED_OBJECT && event.flowing) uses.flushed(event.fixture);
|
|
3668
|
+
if (event.type === "fixture" && event.object === CONTROLLED_OBJECT && event.flowing) uses.flushed(event.fixture, host ?? void 0);
|
|
2935
3669
|
}
|
|
2936
3670
|
});
|
|
2937
3671
|
const forwardPart = (part, open) => {
|
|
@@ -2958,7 +3692,10 @@ var GameInteractables = (() => {
|
|
|
2958
3692
|
return {
|
|
2959
3693
|
list(lent) {
|
|
2960
3694
|
lend(lent);
|
|
2961
|
-
const fromWorld = interactions().map((i) =>
|
|
3695
|
+
const fromWorld = interactions().map((i) => {
|
|
3696
|
+
const gesture = i.gesture;
|
|
3697
|
+
return { id: i.id, label: i.label, available: i.available, ...i.reason ? { reason: world.t(i.reason) } : {}, ...gesture ? { gesture, at: [i.pos[0], i.pos[1], i.pos[2]] } : {} };
|
|
3698
|
+
});
|
|
2962
3699
|
return [...fromWorld, ...uses.list(lent)];
|
|
2963
3700
|
},
|
|
2964
3701
|
run(id, lent) {
|
|
@@ -2973,14 +3710,17 @@ var GameInteractables = (() => {
|
|
|
2973
3710
|
update(dt, lent) {
|
|
2974
3711
|
lend(lent);
|
|
2975
3712
|
world.update(dt);
|
|
2976
|
-
uses.update(dt);
|
|
3713
|
+
uses.update(dt, lent);
|
|
2977
3714
|
},
|
|
2978
3715
|
state() {
|
|
2979
3716
|
const screens = (spec.devices ?? []).filter((d) => d.kind === "screen" && world.power.isOn(CONTROLLED_OBJECT, d.id) && world.power.isPowered(CONTROLLED_OBJECT, d.id)).map((d) => ({ device: d.id, channel: world.power.channel(CONTROLLED_OBJECT, d.id) }));
|
|
2980
3717
|
const emitters = world.emitters().filter((e) => e.object === CONTROLLED_OBJECT && e.kind !== "water");
|
|
2981
3718
|
return { ...uses.state(), screens, emitters };
|
|
2982
3719
|
},
|
|
3720
|
+
serialize: () => world.serialize(),
|
|
3721
|
+
load: (state) => world.load(state),
|
|
2983
3722
|
dispose() {
|
|
3723
|
+
uses.dispose(host ?? void 0);
|
|
2984
3724
|
host = null;
|
|
2985
3725
|
world.remove(CONTROLLED_OBJECT);
|
|
2986
3726
|
world.remove(MAINS);
|