@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.js
CHANGED
|
@@ -1,3 +1,224 @@
|
|
|
1
|
+
// src/basin-drain.ts
|
|
2
|
+
var FLUSH_POUR_SECONDS = 3;
|
|
3
|
+
var CLOGGED = 0.5;
|
|
4
|
+
var REFILL_RATE = 0.12;
|
|
5
|
+
var BREAK_DEPTH = 0.035;
|
|
6
|
+
var WEIR_SHARE = 0.25;
|
|
7
|
+
var SEEP = 0.04;
|
|
8
|
+
var TURN_PER_LITRE = 2.4;
|
|
9
|
+
var TRAP_LITRES = 3.5;
|
|
10
|
+
var PLUNGE_PACKED = 0.34;
|
|
11
|
+
var PLUNGE_LODGED = 0.2;
|
|
12
|
+
var PLUNGER_WATER = 0.03;
|
|
13
|
+
var SOFT_SQUEEZE = 1.6;
|
|
14
|
+
var SWIRL_SETTLED = 1e-4;
|
|
15
|
+
var clamp01 = (v) => Math.min(1, Math.max(0, v));
|
|
16
|
+
var passingSize = (size) => [...size].sort((a, b) => b - a)[1] ?? 0;
|
|
17
|
+
function createBasinDrain(basin, drain) {
|
|
18
|
+
const width = basin.to[0] - basin.from[0];
|
|
19
|
+
const deep = basin.to[2] - basin.from[2];
|
|
20
|
+
const radius = Math.min(width, deep) / 2;
|
|
21
|
+
const area = basin.shape === "round" ? Math.PI * radius * radius : width * deep;
|
|
22
|
+
const litresAt = (level) => area * level * 1e3;
|
|
23
|
+
const levelOf = (litres) => litres / (area * 1e3);
|
|
24
|
+
const capacity = litresAt(basin.to[1] - basin.from[1]);
|
|
25
|
+
const still = litresAt(drain.weir);
|
|
26
|
+
const water = { litres: still, phase: "still", swirl: 0, turned: 0, clog: 0, cause: "none", cistern: 1, pouring: 0, pourRate: 0, carried: 0 };
|
|
27
|
+
let serial = 0;
|
|
28
|
+
let contents = [];
|
|
29
|
+
let shown = null;
|
|
30
|
+
const step = { spilled: 0, swallowed: [] };
|
|
31
|
+
const open = () => Math.max(SEEP, 1 - water.clog);
|
|
32
|
+
const lodge = (c, packed) => {
|
|
33
|
+
c.stage = "lodged";
|
|
34
|
+
c.depth = 1;
|
|
35
|
+
c.radius = 0;
|
|
36
|
+
water.clog = packed ? Math.max(water.clog, Math.min(0.95, water.clog + 0.55 + 0.3 * (c.kg / drain.carries))) : 0.97;
|
|
37
|
+
water.cause = water.cause === "object" || !packed ? "object" : "packed";
|
|
38
|
+
};
|
|
39
|
+
const reachTrap = (c, swallowed) => {
|
|
40
|
+
const hard = c.kind === "object";
|
|
41
|
+
if (passingSize(c.size) > drain.trap * (hard ? 1 : SOFT_SQUEEZE) || !hard && water.carried + c.kg > drain.carries) {
|
|
42
|
+
lodge(c, !hard);
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (!hard) water.carried += c.kg;
|
|
46
|
+
c.stage = "gone";
|
|
47
|
+
if (c.objectId) swallowed.push(c.objectId);
|
|
48
|
+
return true;
|
|
49
|
+
};
|
|
50
|
+
const stepContents = (moved, pulled, swallowed) => {
|
|
51
|
+
water.turned += moved * TURN_PER_LITRE;
|
|
52
|
+
const takesUrine = water.phase === "siphon" && water.swirl > 0.3;
|
|
53
|
+
let leaving = false;
|
|
54
|
+
for (const c of contents) {
|
|
55
|
+
if (c.kind === "urine" && takesUrine) leaving = true;
|
|
56
|
+
if (c.stage === "gone" || c.stage === "lodged") continue;
|
|
57
|
+
c.angle = c.start + water.turned;
|
|
58
|
+
if (water.phase !== "siphon" || c.kind === "urine") continue;
|
|
59
|
+
c.stage = "going";
|
|
60
|
+
c.travel = clamp01(c.travel + pulled / TRAP_LITRES);
|
|
61
|
+
c.depth = Math.max(c.depth, c.travel);
|
|
62
|
+
c.radius = c.startRadius * (1 - c.travel);
|
|
63
|
+
if (c.travel >= 1 && reachTrap(c, swallowed)) leaving = true;
|
|
64
|
+
}
|
|
65
|
+
if (leaving) contents = contents.filter((c) => c.stage !== "gone" && !(c.kind === "urine" && takesUrine));
|
|
66
|
+
};
|
|
67
|
+
const outflow = (dt) => {
|
|
68
|
+
const level = levelOf(water.litres);
|
|
69
|
+
if (water.phase === "siphon") return drain.siphon * open() * dt * Math.sqrt(clamp01(level / Math.max(1e-3, drain.weir)));
|
|
70
|
+
const head = level - drain.weir;
|
|
71
|
+
if (head <= 0) return 0;
|
|
72
|
+
return drain.siphon * WEIR_SHARE * open() * dt * Math.sqrt(clamp01(head / drain.prime));
|
|
73
|
+
};
|
|
74
|
+
const stepPhase = () => {
|
|
75
|
+
const head = levelOf(water.litres) - drain.weir;
|
|
76
|
+
if (water.phase !== "siphon" && head >= drain.prime && open() > CLOGGED) {
|
|
77
|
+
water.phase = "siphon";
|
|
78
|
+
water.carried = 0;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (water.phase === "siphon" && (head <= -BREAK_DEPTH || open() <= CLOGGED)) water.phase = "refill";
|
|
82
|
+
if (water.phase === "refill" && water.litres >= still - 1e-6 && water.pouring <= 0) water.phase = "still";
|
|
83
|
+
if (water.phase === "still" && water.pouring > 0) water.phase = "filling";
|
|
84
|
+
if (water.phase === "filling" && water.pouring <= 0 && head <= 1e-4) water.phase = "still";
|
|
85
|
+
};
|
|
86
|
+
const stepInflow = (dt) => {
|
|
87
|
+
const poured = water.pouring > 0 ? water.pourRate * Math.min(dt, water.pouring) : 0;
|
|
88
|
+
water.pouring = Math.max(0, water.pouring - dt);
|
|
89
|
+
water.litres += poured;
|
|
90
|
+
if ((water.phase === "refill" || water.phase === "still") && water.litres < still && water.clog < CLOGGED) water.litres = Math.min(still, water.litres + REFILL_RATE * dt);
|
|
91
|
+
return poured;
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
flush(asked) {
|
|
95
|
+
shown = null;
|
|
96
|
+
const litresIn = asked * water.cistern;
|
|
97
|
+
water.cistern = 0;
|
|
98
|
+
if (litresIn <= 0) return 0;
|
|
99
|
+
water.pouring = FLUSH_POUR_SECONDS;
|
|
100
|
+
water.pourRate = litresIn / FLUSH_POUR_SECONDS;
|
|
101
|
+
if (water.phase === "still") water.phase = "filling";
|
|
102
|
+
return litresIn;
|
|
103
|
+
},
|
|
104
|
+
add(content) {
|
|
105
|
+
shown = null;
|
|
106
|
+
water.litres += content.litres ?? 0;
|
|
107
|
+
const k = serial++;
|
|
108
|
+
const start = k * 2.39996;
|
|
109
|
+
const startRadius = 0.25 + k * 0.37 % 0.45;
|
|
110
|
+
contents.push({
|
|
111
|
+
start,
|
|
112
|
+
startRadius,
|
|
113
|
+
travel: 0,
|
|
114
|
+
id: `c${k}`,
|
|
115
|
+
kind: content.kind,
|
|
116
|
+
kg: content.kg,
|
|
117
|
+
size: content.size,
|
|
118
|
+
...content.objectId ? { objectId: content.objectId } : {},
|
|
119
|
+
stage: "afloat",
|
|
120
|
+
angle: start + water.turned,
|
|
121
|
+
radius: startRadius,
|
|
122
|
+
depth: content.kind === "object" ? 0.5 : 0
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
plunge() {
|
|
126
|
+
shown = null;
|
|
127
|
+
if (levelOf(water.litres) < PLUNGER_WATER) return false;
|
|
128
|
+
if (water.clog <= 0) return true;
|
|
129
|
+
const lodged = contents.filter((c) => c.stage === "lodged");
|
|
130
|
+
const hard = lodged.some((c) => c.kind === "object");
|
|
131
|
+
water.clog = Math.max(0, water.clog - (hard ? PLUNGE_LODGED : PLUNGE_PACKED));
|
|
132
|
+
if (water.clog > CLOGGED * 0.4) return true;
|
|
133
|
+
water.clog = 0;
|
|
134
|
+
water.cause = "none";
|
|
135
|
+
for (const c of lodged) {
|
|
136
|
+
if (c.kind === "object") Object.assign(c, { stage: "afloat", depth: 0.6, radius: 0.3, startRadius: 0.3, travel: 0 });
|
|
137
|
+
else c.stage = "gone";
|
|
138
|
+
}
|
|
139
|
+
contents = contents.filter((c) => c.stage !== "gone");
|
|
140
|
+
return true;
|
|
141
|
+
},
|
|
142
|
+
update(dt) {
|
|
143
|
+
step.spilled = 0;
|
|
144
|
+
step.swallowed.length = 0;
|
|
145
|
+
if (dt <= 0) return step;
|
|
146
|
+
const { litres, swirl, cistern, phase, clog } = water;
|
|
147
|
+
const count = contents.length;
|
|
148
|
+
water.cistern = clamp01(water.cistern + dt / drain.refill);
|
|
149
|
+
const poured = stepInflow(dt);
|
|
150
|
+
const out = Math.min(water.litres, outflow(dt));
|
|
151
|
+
water.litres -= out;
|
|
152
|
+
stepPhase();
|
|
153
|
+
const pull = water.phase === "siphon" ? clamp01(out / (drain.siphon * dt)) : 0;
|
|
154
|
+
const jets = poured > 0 ? 0.35 : 0;
|
|
155
|
+
const swirlTo = Math.max(pull, jets);
|
|
156
|
+
water.swirl = Math.abs(swirlTo - water.swirl) < SWIRL_SETTLED ? swirlTo : water.swirl + (swirlTo - water.swirl) * clamp01(dt * 6);
|
|
157
|
+
const moved = poured + out;
|
|
158
|
+
stepContents(moved, water.phase === "siphon" ? out : 0, step.swallowed);
|
|
159
|
+
step.spilled = Math.max(0, water.litres - capacity);
|
|
160
|
+
water.litres -= step.spilled;
|
|
161
|
+
const changed = moved > 0 || water.litres !== litres || water.swirl !== swirl || water.cistern !== cistern || water.phase !== phase || water.clog !== clog || contents.length !== count;
|
|
162
|
+
if (changed) shown = null;
|
|
163
|
+
return step;
|
|
164
|
+
},
|
|
165
|
+
state() {
|
|
166
|
+
shown ?? (shown = {
|
|
167
|
+
litres: water.litres,
|
|
168
|
+
level: levelOf(water.litres),
|
|
169
|
+
phase: water.phase,
|
|
170
|
+
swirl: water.swirl,
|
|
171
|
+
turned: water.turned,
|
|
172
|
+
clog: water.clog,
|
|
173
|
+
cause: water.cause,
|
|
174
|
+
cistern: water.cistern,
|
|
175
|
+
contents: contents.map(({ start: _start, startRadius: _startRadius, travel: _travel, ...c }) => c)
|
|
176
|
+
});
|
|
177
|
+
return shown;
|
|
178
|
+
},
|
|
179
|
+
litres: () => water.litres,
|
|
180
|
+
level: () => levelOf(water.litres),
|
|
181
|
+
clog: () => water.clog,
|
|
182
|
+
cause: () => water.cause,
|
|
183
|
+
dirty: () => contents.some((c) => c.kind !== "object"),
|
|
184
|
+
save: () => ({ water: { ...water }, serial, contents: contents.map((c) => ({ ...c })) }),
|
|
185
|
+
restore(saved) {
|
|
186
|
+
shown = null;
|
|
187
|
+
Object.assign(water, saved.water);
|
|
188
|
+
serial = saved.serial;
|
|
189
|
+
contents = saved.contents.map((c) => ({ ...c }));
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// src/gestures.ts
|
|
195
|
+
var GESTURE_OF_ACTION = {
|
|
196
|
+
toggle_part: null,
|
|
197
|
+
open_container: null,
|
|
198
|
+
take: null,
|
|
199
|
+
sit: null,
|
|
200
|
+
toggle_device: "press",
|
|
201
|
+
cycle_device: "press",
|
|
202
|
+
toggle_switch: "flip",
|
|
203
|
+
toggle_breaker: "flip",
|
|
204
|
+
toggle_main: "flip",
|
|
205
|
+
toggle_fixture: "turn",
|
|
206
|
+
toggle_burner: "turn",
|
|
207
|
+
ignite: "strike",
|
|
208
|
+
toggle_fuel: "turn",
|
|
209
|
+
read: "read"
|
|
210
|
+
};
|
|
211
|
+
var GESTURE_OF_USE = {
|
|
212
|
+
program: "press",
|
|
213
|
+
put_in: "put_in",
|
|
214
|
+
empty: "tip",
|
|
215
|
+
fill: "pour",
|
|
216
|
+
relieve: null,
|
|
217
|
+
plunge: null,
|
|
218
|
+
wash: null,
|
|
219
|
+
drink: null
|
|
220
|
+
};
|
|
221
|
+
|
|
1
222
|
// src/fixture-emitters.ts
|
|
2
223
|
var FLUSH_RUN_SECONDS = 2;
|
|
3
224
|
var START_OPENING = 0.05;
|
|
@@ -222,7 +443,17 @@ var locales = {
|
|
|
222
443
|
done_relieve_feces: "You pooed in {name}",
|
|
223
444
|
done_clean: "{name} flushed clean",
|
|
224
445
|
"use.wash_dishes": "Wash the dishes",
|
|
225
|
-
"use.drink_water": "Drink water",
|
|
446
|
+
"use.drink_water": "Drink water from the glass",
|
|
447
|
+
"use.drink_from_hands": "Drink water from your hands",
|
|
448
|
+
needs_in_hand: "Pick up {item} first",
|
|
449
|
+
needs_vessel: "You need a glass",
|
|
450
|
+
vessel_not_empty: "Empty {item} first",
|
|
451
|
+
hands_busy: "Your hands are busy",
|
|
452
|
+
no_animation: "Cannot be done here: the body has no movement for it",
|
|
453
|
+
needs_free_hand: "You need your hands free",
|
|
454
|
+
not_drunk: "No water was drunk",
|
|
455
|
+
drink_from_vessel: "You have a glass in your hand: drink from it",
|
|
456
|
+
done_drink_hands: "You drank {litres} l of water from your hands",
|
|
226
457
|
busy: "Already in use",
|
|
227
458
|
needs_running: "Turn the water on first",
|
|
228
459
|
needs_item: "You need {need}",
|
|
@@ -232,7 +463,21 @@ var locales = {
|
|
|
232
463
|
started_drink: "{label}\u2026",
|
|
233
464
|
done_wash: "Washed and rinsed",
|
|
234
465
|
done_wash_dishes: "Dishes washed: {n} on the rack",
|
|
235
|
-
done_drink: "You drank {litres} l of water"
|
|
466
|
+
done_drink: "You drank {litres} l of water",
|
|
467
|
+
"use.plunge": "Unclog {name} with the plunger",
|
|
468
|
+
needs_plunger: "Hold a plunger",
|
|
469
|
+
plunge_no_water: "No water over the trap for the plunger",
|
|
470
|
+
done_plunge: "You work the plunger in {name}",
|
|
471
|
+
plunge_cleared: "{name} unclogged: the water goes down",
|
|
472
|
+
plunge_object: "{name} unclogged: something came back up the trap",
|
|
473
|
+
plunge_still: "{name} is still clogged",
|
|
474
|
+
clogged: "{name} is clogged",
|
|
475
|
+
overflow: "{name} is overflowing",
|
|
476
|
+
needs_body: "There is no body here to use {name}",
|
|
477
|
+
host_lacks: "This place cannot run {name} (it lacks {capability})",
|
|
478
|
+
body_no_seat: "{name} has no seat to sit on",
|
|
479
|
+
body_object_gone: "{name} is not here",
|
|
480
|
+
body_busy: "You are busy with something else"
|
|
236
481
|
},
|
|
237
482
|
"pt-BR": {
|
|
238
483
|
"prompt.open": "Abrir {name}",
|
|
@@ -287,7 +532,17 @@ var locales = {
|
|
|
287
532
|
done_relieve_feces: "Voc\xEA fez coc\xF4 em {name}",
|
|
288
533
|
done_clean: "Descarga dada: {name} limpo",
|
|
289
534
|
"use.wash_dishes": "Lavar a lou\xE7a",
|
|
290
|
-
"use.drink_water": "Beber \xE1gua",
|
|
535
|
+
"use.drink_water": "Beber \xE1gua no copo",
|
|
536
|
+
"use.drink_from_hands": "Beber \xE1gua com a m\xE3o",
|
|
537
|
+
needs_in_hand: "Pegue {item} antes",
|
|
538
|
+
needs_vessel: "Precisa de um copo",
|
|
539
|
+
vessel_not_empty: "Esvazie {item} antes",
|
|
540
|
+
hands_busy: "As m\xE3os est\xE3o ocupadas",
|
|
541
|
+
no_animation: "N\xE3o d\xE1 para fazer isso aqui: o corpo n\xE3o tem o movimento",
|
|
542
|
+
needs_free_hand: "Precisa das m\xE3os livres",
|
|
543
|
+
not_drunk: "Nenhuma \xE1gua foi bebida",
|
|
544
|
+
drink_from_vessel: "Voc\xEA est\xE1 com um copo na m\xE3o: beba nele",
|
|
545
|
+
done_drink_hands: "Voc\xEA bebeu {litres} l de \xE1gua com a m\xE3o",
|
|
291
546
|
busy: "J\xE1 est\xE1 em uso",
|
|
292
547
|
needs_running: "Abra a \xE1gua primeiro",
|
|
293
548
|
needs_item: "Precisa de {need}",
|
|
@@ -297,7 +552,21 @@ var locales = {
|
|
|
297
552
|
started_drink: "{label}\u2026",
|
|
298
553
|
done_wash: "Lavado e enxaguado",
|
|
299
554
|
done_wash_dishes: "Lou\xE7a lavada: {n} no escorredor",
|
|
300
|
-
done_drink: "Voc\xEA bebeu {litres} l de \xE1gua"
|
|
555
|
+
done_drink: "Voc\xEA bebeu {litres} l de \xE1gua",
|
|
556
|
+
"use.plunge": "Desentupir {name} com o desentupidor",
|
|
557
|
+
needs_plunger: "Segure um desentupidor",
|
|
558
|
+
plunge_no_water: "Sem \xE1gua sobre o sif\xE3o para o desentupidor",
|
|
559
|
+
done_plunge: "Voc\xEA bombeia o desentupidor em {name}",
|
|
560
|
+
plunge_cleared: "{name} desentupido: a \xE1gua desce",
|
|
561
|
+
plunge_object: "{name} desentupido: uma coisa voltou do sif\xE3o",
|
|
562
|
+
plunge_still: "{name} ainda est\xE1 entupido",
|
|
563
|
+
clogged: "{name} entupiu",
|
|
564
|
+
overflow: "{name} est\xE1 transbordando",
|
|
565
|
+
needs_body: "N\xE3o h\xE1 corpo aqui para usar {name}",
|
|
566
|
+
host_lacks: "Este lugar n\xE3o sabe usar {name} (falta {capability})",
|
|
567
|
+
body_no_seat: "{name} n\xE3o tem assento para sentar",
|
|
568
|
+
body_object_gone: "{name} n\xE3o est\xE1 aqui",
|
|
569
|
+
body_busy: "Voc\xEA est\xE1 ocupado com outra coisa"
|
|
301
570
|
}
|
|
302
571
|
};
|
|
303
572
|
function pickLocale(locale) {
|
|
@@ -1326,6 +1595,7 @@ function createWorld(options = {}) {
|
|
|
1326
1595
|
id,
|
|
1327
1596
|
object: o.id,
|
|
1328
1597
|
kind: i.action.do,
|
|
1598
|
+
...GESTURE_OF_ACTION[i.action.do] ? { gesture: GESTURE_OF_ACTION[i.action.do] } : {},
|
|
1329
1599
|
pos: toWorld(o, i.pos),
|
|
1330
1600
|
radius: i.radius ?? DEFAULT_RADIUS,
|
|
1331
1601
|
label: p.label,
|
|
@@ -1703,6 +1973,7 @@ function createWorld(options = {}) {
|
|
|
1703
1973
|
burners: /* @__PURE__ */ new Map(),
|
|
1704
1974
|
tanks: /* @__PURE__ */ new Map(),
|
|
1705
1975
|
fixtures: /* @__PURE__ */ new Map(),
|
|
1976
|
+
drains: /* @__PURE__ */ new Map(),
|
|
1706
1977
|
soft: /* @__PURE__ */ new Map(),
|
|
1707
1978
|
hp: /* @__PURE__ */ new Map(),
|
|
1708
1979
|
interactions: spec.interactions ?? deriveInteractions(spec)
|
|
@@ -1735,6 +2006,7 @@ function createWorld(options = {}) {
|
|
|
1735
2006
|
for (const b of spec.burners ?? []) o.burners.set(b.id, { spec: b, on: false, lit: false, smoke: 0 });
|
|
1736
2007
|
for (const tk of spec.tanks ?? []) o.tanks.set(tk.id, { spec: tk, level: clamp(tk.level ?? tk.capacity, 0, tk.capacity) });
|
|
1737
2008
|
for (const f of spec.fixtures ?? []) o.fixtures.set(f.id, { spec: f, on: false, flowing: false, frac: 0, timer: 0 });
|
|
2009
|
+
for (const b of spec.basins ?? []) if (b.drain) o.drains.set(b.id, createBasinDrain(b, b.drain));
|
|
1738
2010
|
let n = 0;
|
|
1739
2011
|
for (const s of spec.soft ?? []) {
|
|
1740
2012
|
const driver = options.partPhysics?.attachSoft?.(id, s, pub.transform);
|
|
@@ -1767,7 +2039,8 @@ function createWorld(options = {}) {
|
|
|
1767
2039
|
burners: Object.fromEntries([...o.burners].map(([k, b]) => [k, { on: b.on, lit: b.lit }])),
|
|
1768
2040
|
tanks: Object.fromEntries([...o.tanks].map(([k, tk]) => [k, tk.level])),
|
|
1769
2041
|
fixtures: Object.fromEntries([...o.fixtures].map(([k, f]) => [k, f.on])),
|
|
1770
|
-
hp: Object.fromEntries([...o.hp].map(([k, h]) => [k, h.hp]))
|
|
2042
|
+
hp: Object.fromEntries([...o.hp].map(([k, h]) => [k, h.hp])),
|
|
2043
|
+
drains: Object.fromEntries([...o.drains].map(([k, d]) => [k, d.save()]))
|
|
1771
2044
|
};
|
|
1772
2045
|
}
|
|
1773
2046
|
return {
|
|
@@ -1833,6 +2106,7 @@ function createWorld(options = {}) {
|
|
|
1833
2106
|
const h = o.hp.get(k);
|
|
1834
2107
|
if (h) h.hp = v;
|
|
1835
2108
|
}
|
|
2109
|
+
for (const [k, v] of Object.entries(st.drains ?? {})) o.drains.get(k)?.restore(v);
|
|
1836
2110
|
}
|
|
1837
2111
|
grid = state.grid;
|
|
1838
2112
|
main = state.main ?? true;
|
|
@@ -1957,6 +2231,7 @@ function createWorld(options = {}) {
|
|
|
1957
2231
|
locale = l;
|
|
1958
2232
|
table = resolveStrings(locale, options.strings);
|
|
1959
2233
|
},
|
|
2234
|
+
drain: (objectId, basin) => objs.get(objectId)?.drains.get(basin),
|
|
1960
2235
|
serialize,
|
|
1961
2236
|
load
|
|
1962
2237
|
};
|
|
@@ -2481,6 +2756,178 @@ function castWithMember(member, other) {
|
|
|
2481
2756
|
return wrapsMember(member, other) || endsMember(member, other);
|
|
2482
2757
|
}
|
|
2483
2758
|
|
|
2759
|
+
// src/drain-uses.ts
|
|
2760
|
+
import { PLUNGE_STROKE_SECONDS } from "@adatechnology/game-contracts";
|
|
2761
|
+
var RELIEVE_SECONDS = 8;
|
|
2762
|
+
var LANDS_AT = 0.7;
|
|
2763
|
+
var FLUSH_LITRES = 6;
|
|
2764
|
+
var SWALLOW_SECONDS = 0.5;
|
|
2765
|
+
var SPILL_GATHER_SECONDS = 0.25;
|
|
2766
|
+
var URINE = { kind: "urine", kg: 0.3, litres: 0.3, size: [0.02, 0.02, 0.02] };
|
|
2767
|
+
var FECES = { kind: "feces", kg: 0.2, size: [0.12, 0.035, 0.035] };
|
|
2768
|
+
var PAPER = { kind: "paper", kg: 8e-3, size: [0.06, 0.03, 0.03] };
|
|
2769
|
+
var PEE = [URINE];
|
|
2770
|
+
var POO = [FECES, PAPER, PAPER];
|
|
2771
|
+
var HOST_NEEDS = ["setBasin", "spill", "looseInside", "swallow"];
|
|
2772
|
+
function createDrainUses(options) {
|
|
2773
|
+
const { spec, t, world, objectId } = options;
|
|
2774
|
+
const basins = /* @__PURE__ */ new Map();
|
|
2775
|
+
for (const b of spec.basins ?? []) {
|
|
2776
|
+
const drain = world.drain(objectId, b.id);
|
|
2777
|
+
if (!drain) continue;
|
|
2778
|
+
const centre = [(b.from[0] + b.to[0]) / 2, b.from[1], (b.from[2] + b.to[2]) / 2];
|
|
2779
|
+
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 });
|
|
2780
|
+
}
|
|
2781
|
+
const flushes = new Map(
|
|
2782
|
+
(spec.fixtures ?? []).flatMap((f) => f.cleans && basins.has(f.cleans) ? [[f.id, { basin: f.cleans, litres: f.volume ?? FLUSH_LITRES }]] : [])
|
|
2783
|
+
);
|
|
2784
|
+
const list = [...basins.values()];
|
|
2785
|
+
let states = {};
|
|
2786
|
+
const pending = [];
|
|
2787
|
+
const swallowing = [];
|
|
2788
|
+
let plunging = null;
|
|
2789
|
+
const typeKey = `type.${spec.type}`;
|
|
2790
|
+
const name = () => {
|
|
2791
|
+
const text = t(typeKey);
|
|
2792
|
+
return text === typeKey ? spec.type.replace(/_/g, " ") : text.charAt(0).toLowerCase() + text.slice(1);
|
|
2793
|
+
};
|
|
2794
|
+
const takeLoose = (b, host) => {
|
|
2795
|
+
const top = [b.spec.to[0], b.spec.to[1] + 0.08, b.spec.to[2]];
|
|
2796
|
+
const inWater = new Set(b.drain.state().contents.flatMap((c) => c.objectId ? [c.objectId] : []));
|
|
2797
|
+
for (const thing of host?.looseInside?.(b.spec.from, top) ?? []) {
|
|
2798
|
+
if (inWater.has(thing.id)) continue;
|
|
2799
|
+
b.drain.add({ kind: "object", kg: thing.kg, size: thing.size, objectId: thing.id });
|
|
2800
|
+
}
|
|
2801
|
+
};
|
|
2802
|
+
const report = (b, host) => {
|
|
2803
|
+
const clogged = b.drain.clog() >= CLOGGED;
|
|
2804
|
+
if (clogged && !b.clogged) host?.say(t("clogged", { name: name() }));
|
|
2805
|
+
b.clogged = clogged;
|
|
2806
|
+
};
|
|
2807
|
+
const stepPending = (dt) => {
|
|
2808
|
+
let kept = 0;
|
|
2809
|
+
for (const p of pending) {
|
|
2810
|
+
p.left -= dt;
|
|
2811
|
+
if (p.left > 0) {
|
|
2812
|
+
pending[kept++] = p;
|
|
2813
|
+
continue;
|
|
2814
|
+
}
|
|
2815
|
+
for (const content of p.lands) basins.get(p.basin)?.drain.add(content);
|
|
2816
|
+
}
|
|
2817
|
+
pending.length = kept;
|
|
2818
|
+
};
|
|
2819
|
+
const stepPlunge = (dt, host) => {
|
|
2820
|
+
if (!plunging) return;
|
|
2821
|
+
const b = basins.get(plunging.basin);
|
|
2822
|
+
plunging.left -= dt;
|
|
2823
|
+
plunging.stroke += dt;
|
|
2824
|
+
if (b && plunging.stroke >= PLUNGE_STROKE_SECONDS) {
|
|
2825
|
+
plunging.stroke -= PLUNGE_STROKE_SECONDS;
|
|
2826
|
+
const cause = b.drain.cause();
|
|
2827
|
+
b.drain.plunge();
|
|
2828
|
+
if (cause !== "none" && b.drain.cause() === "none") {
|
|
2829
|
+
host?.say(t(cause === "object" ? "plunge_object" : "plunge_cleared", { name: name() }));
|
|
2830
|
+
b.clogged = false;
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
if (plunging.left > 0) return;
|
|
2834
|
+
if (b && b.drain.clog() >= CLOGGED) host?.say(t("plunge_still", { name: name() }));
|
|
2835
|
+
plunging = null;
|
|
2836
|
+
};
|
|
2837
|
+
const stepSwallowing = (dt, host) => {
|
|
2838
|
+
let kept = 0;
|
|
2839
|
+
for (const s of swallowing) {
|
|
2840
|
+
s.time += dt;
|
|
2841
|
+
const progress = Math.min(1, s.time / SWALLOW_SECONDS);
|
|
2842
|
+
host?.swallow?.(s.id, s.point, progress);
|
|
2843
|
+
if (progress < 1) swallowing[kept++] = s;
|
|
2844
|
+
}
|
|
2845
|
+
swallowing.length = kept;
|
|
2846
|
+
};
|
|
2847
|
+
const stepSpill = (b, spilled, dt, host) => {
|
|
2848
|
+
if (spilled > 0 && !b.overflowing) host?.say(t("overflow", { name: name() }));
|
|
2849
|
+
b.overflowing = spilled > 0;
|
|
2850
|
+
b.spill += spilled;
|
|
2851
|
+
if (b.spill <= 0) return;
|
|
2852
|
+
b.spillTime += dt;
|
|
2853
|
+
if (b.spillTime < SPILL_GATHER_SECONDS) return;
|
|
2854
|
+
host?.spill?.(b.frontRim, b.spill, b.drain.dirty() ? "sewage" : "water");
|
|
2855
|
+
b.spill = 0;
|
|
2856
|
+
b.spillTime = 0;
|
|
2857
|
+
};
|
|
2858
|
+
const stepBasin = (b, dt, host) => {
|
|
2859
|
+
const step = b.drain.update(dt);
|
|
2860
|
+
for (const id of step.swallowed) swallowing.push({ id, point: b.centre, time: 0 });
|
|
2861
|
+
stepSpill(b, step.spilled, dt, host);
|
|
2862
|
+
host?.setBasin?.(b.spec.id, b.drain.litres());
|
|
2863
|
+
report(b, host);
|
|
2864
|
+
};
|
|
2865
|
+
return {
|
|
2866
|
+
has: (basin) => basins.has(basin),
|
|
2867
|
+
hostBlocked: (host) => HOST_NEEDS.find((need) => host[need] === void 0) ?? null,
|
|
2868
|
+
relieveBody(use, host) {
|
|
2869
|
+
const body = host.body?.();
|
|
2870
|
+
if (!body) return null;
|
|
2871
|
+
const seconds = use.seconds ?? RELIEVE_SECONDS;
|
|
2872
|
+
const b = basins.get(use.basin);
|
|
2873
|
+
if (use.kind === "urine" && use.stand && body.sex === "male") return { pose: "relieve_stand", seconds, at: use.stand, faces: b ? b.centre : [0, 0, 0] };
|
|
2874
|
+
return { pose: "relieve_sit", seconds, ...use.seat ? { seat: use.seat } : {} };
|
|
2875
|
+
},
|
|
2876
|
+
relieve(use, host, body) {
|
|
2877
|
+
if (use.cover) host.setPart(use.cover, true);
|
|
2878
|
+
if (use.ring) host.setPart(use.ring, body.pose === "relieve_stand");
|
|
2879
|
+
pending.push({ basin: use.basin, lands: use.kind === "urine" ? PEE : POO, left: body.seconds * LANDS_AT });
|
|
2880
|
+
return { ok: true, text: t(`done_relieve_${use.kind}`, { name: name() }), body };
|
|
2881
|
+
},
|
|
2882
|
+
plungeBlocked(use, host) {
|
|
2883
|
+
if (!host.hand()?.tools?.includes(use.tool)) return "needs_plunger";
|
|
2884
|
+
const b = basins.get(use.basin);
|
|
2885
|
+
return b && b.drain.level() < PLUNGER_WATER ? "plunge_no_water" : null;
|
|
2886
|
+
},
|
|
2887
|
+
plungeBody(use) {
|
|
2888
|
+
const b = basins.get(use.basin);
|
|
2889
|
+
return { pose: "plunge", seconds: use.seconds, at: use.stand, faces: b ? b.centre : [0, 0, 0] };
|
|
2890
|
+
},
|
|
2891
|
+
plunge(use, body) {
|
|
2892
|
+
plunging = { basin: use.basin, left: use.seconds, stroke: 0 };
|
|
2893
|
+
return { ok: true, text: t("done_plunge", { name: name() }), body };
|
|
2894
|
+
},
|
|
2895
|
+
flushed(fixture, host) {
|
|
2896
|
+
const flush = flushes.get(fixture);
|
|
2897
|
+
const b = flush ? basins.get(flush.basin) : void 0;
|
|
2898
|
+
if (!flush || !b) return false;
|
|
2899
|
+
takeLoose(b, host);
|
|
2900
|
+
b.drain.flush(flush.litres);
|
|
2901
|
+
return true;
|
|
2902
|
+
},
|
|
2903
|
+
update(dt, host) {
|
|
2904
|
+
stepPending(dt);
|
|
2905
|
+
stepPlunge(dt, host);
|
|
2906
|
+
stepSwallowing(dt, host);
|
|
2907
|
+
for (const b of list) stepBasin(b, dt, host);
|
|
2908
|
+
},
|
|
2909
|
+
dispose(host) {
|
|
2910
|
+
for (const s of swallowing) host?.swallow?.(s.id, s.point, 1);
|
|
2911
|
+
swallowing.length = 0;
|
|
2912
|
+
pending.length = 0;
|
|
2913
|
+
plunging = null;
|
|
2914
|
+
},
|
|
2915
|
+
soil(basin) {
|
|
2916
|
+
const contents = basins.get(basin)?.drain.state().contents ?? [];
|
|
2917
|
+
if (contents.some((c) => c.kind === "feces" || c.kind === "paper")) return "feces";
|
|
2918
|
+
return contents.some((c) => c.kind === "urine") ? "urine" : "clean";
|
|
2919
|
+
},
|
|
2920
|
+
state() {
|
|
2921
|
+
for (const b of list) {
|
|
2922
|
+
if (states[b.spec.id] === b.drain.state()) continue;
|
|
2923
|
+
states = Object.fromEntries(list.map((each) => [each.spec.id, each.drain.state()]));
|
|
2924
|
+
break;
|
|
2925
|
+
}
|
|
2926
|
+
return states;
|
|
2927
|
+
}
|
|
2928
|
+
};
|
|
2929
|
+
}
|
|
2930
|
+
|
|
2484
2931
|
// src/fits-volume.ts
|
|
2485
2932
|
function fitsInVolume(size, half) {
|
|
2486
2933
|
const thing = [...size].sort((a, b) => b - a);
|
|
@@ -2493,8 +2940,11 @@ var WASH_SCRUB_SECONDS = 3;
|
|
|
2493
2940
|
var DRINK_LITRES = 0.25;
|
|
2494
2941
|
var FILL_SHARE = 0.85;
|
|
2495
2942
|
var DRINK_LPS = 0.06;
|
|
2943
|
+
var DRINK_HANDS_LITRES = 0.12;
|
|
2944
|
+
var DRINK_HANDS_LPS = 0.03;
|
|
2496
2945
|
var REACH_SECONDS = 0.6;
|
|
2497
2946
|
var DRY_SECONDS = 0.5;
|
|
2947
|
+
var UNDER_STREAM = 0.14;
|
|
2498
2948
|
var SCRUBBED_DIRT = 0.15;
|
|
2499
2949
|
var YES = { available: true };
|
|
2500
2950
|
var idsOf = (need) => typeof need === "string" ? [need] : need;
|
|
@@ -2513,16 +2963,59 @@ function dirtyDishes(use, spec, host) {
|
|
|
2513
2963
|
if (!dishes || !basin) return [];
|
|
2514
2964
|
return (host.itemsInside?.(dishes.ids, basin.from, basin.to) ?? []).filter((item) => (item.dirt ?? 0) > 0);
|
|
2515
2965
|
}
|
|
2966
|
+
function washBody(use, host) {
|
|
2967
|
+
const { playUse, lather, rinse, itemsInside, placeItem, setDirt, takeDose } = host;
|
|
2968
|
+
if (!playUse || !lather || !rinse) return null;
|
|
2969
|
+
if (use.dishes && (!itemsInside || !placeItem || !setDirt)) return null;
|
|
2970
|
+
if (use.dose && !takeDose) return null;
|
|
2971
|
+
return { playUse, lather, rinse, itemsInside, placeItem, setDirt, takeDose };
|
|
2972
|
+
}
|
|
2973
|
+
function vesselBody(host) {
|
|
2974
|
+
const { playUse, vesselAt, fillItem, drinkItem } = host;
|
|
2975
|
+
return playUse && vesselAt && fillItem && drinkItem ? { playUse, vesselAt, fillItem, drinkItem } : null;
|
|
2976
|
+
}
|
|
2977
|
+
function handsBody(host) {
|
|
2978
|
+
const { playUse, handsFree, drinkFromHands } = host;
|
|
2979
|
+
return playUse && handsFree && drinkFromHands ? { playUse, handsFree, drinkFromHands } : null;
|
|
2980
|
+
}
|
|
2981
|
+
var NO_BODY = { available: false, reason: "no_animation" };
|
|
2982
|
+
var NEEDS_FREE_HAND = { available: false, reason: "needs_free_hand" };
|
|
2516
2983
|
function sinkVerdict(use, spec, host, flowing) {
|
|
2517
|
-
if (use.do === "
|
|
2984
|
+
if (use.do === "drink") return drinkVerdict(use, host);
|
|
2985
|
+
if (!washBody(use, host)) return NO_BODY;
|
|
2986
|
+
if (use.requiresFlowing && !flowing) return { available: false, reason: "needs_running" };
|
|
2518
2987
|
const found = findNeeds(use.needs ?? [], host);
|
|
2988
|
+
if (!handsFreeFor(use, found.items, host)) return NEEDS_FREE_HAND;
|
|
2519
2989
|
if (found.missing) return { available: false, reason: "needs_item", vars: { need: found.missing[0] ?? "" } };
|
|
2520
|
-
if (use.do === "drink") return YES;
|
|
2521
2990
|
const dosed = use.dose ? found.items[use.dose.need] : void 0;
|
|
2522
2991
|
if (dosed && (dosed.remaining ?? 1) <= 0) return { available: false, reason: "item_spent", vars: { item: dosed.name } };
|
|
2523
2992
|
if (use.dishes && dirtyDishes(use, spec, host).length === 0) return { available: false, reason: "no_dirty_dishes" };
|
|
2524
2993
|
return YES;
|
|
2525
2994
|
}
|
|
2995
|
+
function handsAreFree(host) {
|
|
2996
|
+
return host.handsFree?.() ?? host.hand() === null;
|
|
2997
|
+
}
|
|
2998
|
+
function handsFreeFor(use, needed, host) {
|
|
2999
|
+
if (handsAreFree(host)) return true;
|
|
3000
|
+
if (host.hand() === null) return false;
|
|
3001
|
+
if (needed.some((item) => item.where === "hand")) return true;
|
|
3002
|
+
return use.dishes !== void 0 && host.itemAt?.(use.dishes.ids)?.where === "hand";
|
|
3003
|
+
}
|
|
3004
|
+
function drinkVerdict(use, host) {
|
|
3005
|
+
if (use.from === "hands") {
|
|
3006
|
+
const body2 = handsBody(host);
|
|
3007
|
+
if (!body2) return NO_BODY;
|
|
3008
|
+
if (body2.handsFree()) return YES;
|
|
3009
|
+
return host.vesselAt?.()?.where === "hand" ? { available: false, reason: "drink_from_vessel" } : NEEDS_FREE_HAND;
|
|
3010
|
+
}
|
|
3011
|
+
const body = vesselBody(host);
|
|
3012
|
+
if (!body) return NO_BODY;
|
|
3013
|
+
const vessel = body.vesselAt();
|
|
3014
|
+
if (!vessel) return { available: false, reason: "needs_vessel" };
|
|
3015
|
+
if (vessel.where !== "hand") return { available: false, reason: "needs_in_hand", vars: { item: vessel.name } };
|
|
3016
|
+
const other = vessel.liquid?.kind !== void 0 && vessel.liquid.kind !== "water" && vessel.liquid.litres > 1e-3;
|
|
3017
|
+
return other ? { available: false, reason: "vessel_not_empty", vars: { item: vessel.name } } : YES;
|
|
3018
|
+
}
|
|
2526
3019
|
var fixtureFlowLps = (fixture) => fixture ? (fixture.flow ?? FLOW_DEFAULTS[fixture.kind] ?? 6) / 60 : 0;
|
|
2527
3020
|
function runPhases(phases) {
|
|
2528
3021
|
let index = 0;
|
|
@@ -2546,6 +3039,10 @@ function createSinkRoutines(options) {
|
|
|
2546
3039
|
const fixtureOf = (id) => (spec.fixtures ?? []).find((f) => f.id === id);
|
|
2547
3040
|
const flowing = (use) => world.water.isFlowing(objectId, use.fixture);
|
|
2548
3041
|
const water = (use) => flowing(use) ? fixtureFlowLps(fixtureOf(use.fixture)) : 0;
|
|
3042
|
+
const underStream = (use) => {
|
|
3043
|
+
const outlet = fixtureOf(use.fixture)?.outlet;
|
|
3044
|
+
return outlet ? [outlet[0], outlet[1] - UNDER_STREAM, outlet[2]] : void 0;
|
|
3045
|
+
};
|
|
2549
3046
|
const waterOf = (use) => {
|
|
2550
3047
|
let dry = 0;
|
|
2551
3048
|
return (dt) => {
|
|
@@ -2554,6 +3051,14 @@ function createSinkRoutines(options) {
|
|
|
2554
3051
|
return dry > DRY_SECONDS ? null : flow;
|
|
2555
3052
|
};
|
|
2556
3053
|
};
|
|
3054
|
+
const approachPhase = (use, host) => {
|
|
3055
|
+
let walked = 0;
|
|
3056
|
+
const at = underStream(use);
|
|
3057
|
+
return (dt) => {
|
|
3058
|
+
walked += dt;
|
|
3059
|
+
return !at || !host.approach || walked > REACH_SECONDS * 3 || host.approach(at, dt);
|
|
3060
|
+
};
|
|
3061
|
+
};
|
|
2557
3062
|
const tapPhases = (use) => {
|
|
2558
3063
|
let opened = false;
|
|
2559
3064
|
const reach = wait(REACH_SECONDS);
|
|
@@ -2570,7 +3075,7 @@ function createSinkRoutines(options) {
|
|
|
2570
3075
|
}
|
|
2571
3076
|
};
|
|
2572
3077
|
};
|
|
2573
|
-
const scrubAndRinse = (use,
|
|
3078
|
+
const scrubAndRinse = (use, body, target, fail) => {
|
|
2574
3079
|
const item = typeof target === "string" ? void 0 : target;
|
|
2575
3080
|
const id = item?.objectId ?? target;
|
|
2576
3081
|
const seconds = use.scrubSeconds ?? WASH_SCRUB_SECONDS;
|
|
@@ -2579,11 +3084,14 @@ function createSinkRoutines(options) {
|
|
|
2579
3084
|
const scrub = (dt) => {
|
|
2580
3085
|
if (scrubbed < 0) {
|
|
2581
3086
|
scrubbed = 0;
|
|
2582
|
-
|
|
3087
|
+
if (!body.playUse(use.clip, item?.objectId, underStream(use))) {
|
|
3088
|
+
fail({ key: "hands_busy", ok: false });
|
|
3089
|
+
return true;
|
|
3090
|
+
}
|
|
2583
3091
|
}
|
|
2584
3092
|
scrubbed = Math.min(seconds, scrubbed + dt);
|
|
2585
|
-
|
|
2586
|
-
if (dirt > 0)
|
|
3093
|
+
body.lather(id, dt / seconds);
|
|
3094
|
+
if (dirt > 0) body.setDirt?.(id, dirt - (dirt - Math.min(dirt, SCRUBBED_DIRT)) * (scrubbed / seconds));
|
|
2587
3095
|
return scrubbed >= seconds;
|
|
2588
3096
|
};
|
|
2589
3097
|
const running = waterOf(use);
|
|
@@ -2593,13 +3101,13 @@ function createSinkRoutines(options) {
|
|
|
2593
3101
|
fail({ key: "no_water", ok: false });
|
|
2594
3102
|
return true;
|
|
2595
3103
|
}
|
|
2596
|
-
if (flow <= 0 ||
|
|
2597
|
-
if (dirt > 0)
|
|
3104
|
+
if (flow <= 0 || body.rinse(id, flow, dt) > 0) return false;
|
|
3105
|
+
if (dirt > 0) body.setDirt?.(id, 0);
|
|
2598
3106
|
return true;
|
|
2599
3107
|
};
|
|
2600
3108
|
return [scrub, rinse];
|
|
2601
3109
|
};
|
|
2602
|
-
const startWash = (use, host) => {
|
|
3110
|
+
const startWash = (use, host, body) => {
|
|
2603
3111
|
const { items } = findNeeds(use.needs ?? [], host);
|
|
2604
3112
|
let end = null;
|
|
2605
3113
|
const fail = (reason) => {
|
|
@@ -2608,64 +3116,149 @@ function createSinkRoutines(options) {
|
|
|
2608
3116
|
const tap = tapPhases(use);
|
|
2609
3117
|
const dosed = use.dose ? items[use.dose.need] : void 0;
|
|
2610
3118
|
const dose = () => {
|
|
2611
|
-
if (dosed &&
|
|
3119
|
+
if (dosed && body.takeDose?.(dosed.objectId, use.dose?.amount).taken === 0) fail({ key: "item_spent", ok: false, vars: { item: dosed.name } });
|
|
2612
3120
|
return true;
|
|
2613
3121
|
};
|
|
2614
3122
|
const dishes = use.dishes ? dirtyDishes(use, spec, host) : [];
|
|
2615
3123
|
const rack = use.dishes?.rack ?? [];
|
|
2616
|
-
const work = use.dishes ? dishes.flatMap((dish, index) => [...scrubAndRinse(use,
|
|
3124
|
+
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);
|
|
2617
3125
|
const guarded = work.map((phase) => (dt) => end !== null || phase(dt));
|
|
2618
|
-
const run = runPhases([tap.open, dose, ...guarded, tap.close]);
|
|
3126
|
+
const run = runPhases([approachPhase(use, host), tap.open, dose, ...guarded, tap.close]);
|
|
2619
3127
|
const done = use.dishes ? { key: "done_wash_dishes", ok: true, vars: { n: String(dishes.length) } } : { key: "done_wash", ok: true, vars: { surface: use.surface } };
|
|
2620
3128
|
return { use: use.id, step: (dt) => run(dt) ? end ?? done : null };
|
|
2621
3129
|
};
|
|
2622
|
-
const startDrink = (use, host, vessel) => {
|
|
3130
|
+
const startDrink = (use, host, body, vessel) => {
|
|
2623
3131
|
const tap = tapPhases(use);
|
|
2624
3132
|
const want = Math.min(use.litres ?? DRINK_LITRES, (vessel.liquid?.capacity ?? DRINK_LITRES) * FILL_SHARE);
|
|
2625
3133
|
let filled = vessel.liquid?.kind === "water" ? vessel.liquid.litres : 0;
|
|
2626
3134
|
let drunk = 0;
|
|
2627
3135
|
let end = null;
|
|
2628
|
-
const take = () => {
|
|
2629
|
-
if (vessel.where !== "hand" && host.holdItem?.(vessel.objectId) === false) end = { key: "needs_item", ok: false, vars: { need: vessel.itemId } };
|
|
2630
|
-
else host.playUse?.(use.fillClip ?? "fill_cup", vessel.objectId);
|
|
2631
|
-
return true;
|
|
2632
|
-
};
|
|
2633
3136
|
const running = waterOf(use);
|
|
3137
|
+
const played = (clip, at) => {
|
|
3138
|
+
if (body.playUse(clip, vessel.objectId, at)) return true;
|
|
3139
|
+
end ?? (end = { key: "hands_busy", ok: false });
|
|
3140
|
+
return false;
|
|
3141
|
+
};
|
|
3142
|
+
let filling = false;
|
|
2634
3143
|
const fill = (dt) => {
|
|
2635
3144
|
if (end) return true;
|
|
3145
|
+
if (!filling && !(filling = played(use.fillClip ?? "fill_cup", underStream(use)))) return true;
|
|
2636
3146
|
const flow = running(dt);
|
|
2637
3147
|
if (flow === null) {
|
|
2638
3148
|
end = { key: "no_water", ok: false };
|
|
2639
3149
|
return true;
|
|
2640
3150
|
}
|
|
2641
3151
|
if (flow <= 0) return false;
|
|
2642
|
-
const took =
|
|
3152
|
+
const took = body.fillItem(vessel.objectId, "water", Math.min(flow * dt, want - filled));
|
|
2643
3153
|
filled += took;
|
|
2644
3154
|
return filled >= want - 1e-6 || took <= 0;
|
|
2645
3155
|
};
|
|
2646
3156
|
let sipping = false;
|
|
2647
3157
|
const drink = (dt) => {
|
|
2648
3158
|
if (end) return true;
|
|
2649
|
-
if (!sipping
|
|
2650
|
-
const sip =
|
|
3159
|
+
if (!sipping && !(sipping = played(use.clip))) return true;
|
|
3160
|
+
const sip = body.drinkItem(vessel.objectId, Math.min(DRINK_LPS * dt, filled - drunk));
|
|
2651
3161
|
drunk += sip;
|
|
2652
3162
|
return drunk >= filled - 1e-6 || sip <= 0;
|
|
2653
3163
|
};
|
|
2654
|
-
const
|
|
2655
|
-
const
|
|
2656
|
-
return { use: use.id, step: (dt) => run(dt) ? end ??
|
|
3164
|
+
const run = runPhases([approachPhase(use, host), tap.open, fill, tap.close, drink]);
|
|
3165
|
+
const done = () => drunk > 1e-3 ? { key: "done_drink", ok: true, vars: { litres: drunk.toFixed(2) } } : { key: "not_drunk", ok: false };
|
|
3166
|
+
return { use: use.id, step: (dt) => run(dt) ? end ?? done() : null };
|
|
2657
3167
|
};
|
|
3168
|
+
const startDrinkHands = (use, host, body) => {
|
|
3169
|
+
const tap = tapPhases(use);
|
|
3170
|
+
const want = use.litres ?? DRINK_HANDS_LITRES;
|
|
3171
|
+
let drunk = 0;
|
|
3172
|
+
let end = null;
|
|
3173
|
+
const running = waterOf(use);
|
|
3174
|
+
let bent = false;
|
|
3175
|
+
const drink = (dt) => {
|
|
3176
|
+
if (!bent) {
|
|
3177
|
+
bent = body.playUse(use.clip, void 0, underStream(use));
|
|
3178
|
+
if (!bent) {
|
|
3179
|
+
end = { key: "hands_busy", ok: false };
|
|
3180
|
+
return true;
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
const flow = running(dt);
|
|
3184
|
+
if (flow === null) {
|
|
3185
|
+
end = { key: "no_water", ok: false };
|
|
3186
|
+
return true;
|
|
3187
|
+
}
|
|
3188
|
+
if (flow <= 0) return false;
|
|
3189
|
+
const sip = body.drinkFromHands("water", Math.min(DRINK_HANDS_LPS * dt, flow * dt, want - drunk));
|
|
3190
|
+
drunk += sip;
|
|
3191
|
+
return drunk >= want - 1e-6 || sip <= 0;
|
|
3192
|
+
};
|
|
3193
|
+
const run = runPhases([approachPhase(use, host), tap.open, drink, tap.close]);
|
|
3194
|
+
const done = () => drunk > 1e-3 ? { key: "done_drink_hands", ok: true, vars: { litres: drunk.toFixed(2) } } : { key: "not_drunk", ok: false };
|
|
3195
|
+
return { use: use.id, step: (dt) => run(dt) ? end ?? done() : null };
|
|
3196
|
+
};
|
|
3197
|
+
const refused = (use, key) => ({ use: use.id, step: () => ({ key, ok: false }) });
|
|
2658
3198
|
return {
|
|
2659
3199
|
start(use, host) {
|
|
2660
|
-
if (use.do === "wash")
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
3200
|
+
if (use.do === "wash") {
|
|
3201
|
+
const body2 = washBody(use, host);
|
|
3202
|
+
return body2 ? startWash(use, host, body2) : refused(use, "no_animation");
|
|
3203
|
+
}
|
|
3204
|
+
if (use.from === "hands") {
|
|
3205
|
+
const body2 = handsBody(host);
|
|
3206
|
+
return body2 ? startDrinkHands(use, host, body2) : refused(use, "no_animation");
|
|
3207
|
+
}
|
|
3208
|
+
const body = vesselBody(host);
|
|
3209
|
+
const vessel = body?.vesselAt();
|
|
3210
|
+
if (!body) return refused(use, "no_animation");
|
|
3211
|
+
return vessel ? startDrink(use, host, body, vessel) : refused(use, "needs_vessel");
|
|
3212
|
+
}
|
|
3213
|
+
};
|
|
3214
|
+
}
|
|
3215
|
+
|
|
3216
|
+
// src/use-body.ts
|
|
3217
|
+
function createUseBody() {
|
|
3218
|
+
let running = null;
|
|
3219
|
+
const end = () => {
|
|
3220
|
+
const was = running;
|
|
3221
|
+
running = null;
|
|
3222
|
+
was?.body.end();
|
|
3223
|
+
};
|
|
3224
|
+
return {
|
|
3225
|
+
blocked(action, host) {
|
|
3226
|
+
const body = host.body?.();
|
|
3227
|
+
if (!body) return "needs_body";
|
|
3228
|
+
const why = body.blocked(action);
|
|
3229
|
+
return why ? `body_${why}` : null;
|
|
3230
|
+
},
|
|
3231
|
+
begin(action, host) {
|
|
3232
|
+
const body = host.body?.();
|
|
3233
|
+
if (!body) return false;
|
|
3234
|
+
end();
|
|
3235
|
+
if (!body.begin(action)) return false;
|
|
3236
|
+
running = { action, body, time: 0 };
|
|
3237
|
+
return true;
|
|
3238
|
+
},
|
|
3239
|
+
update(dt) {
|
|
3240
|
+
if (!running) return;
|
|
3241
|
+
running.time += dt;
|
|
3242
|
+
const { action, body, time } = running;
|
|
3243
|
+
if (!body.step(time, Math.min(1, time / action.seconds))) running = null;
|
|
3244
|
+
else if (time >= action.seconds) end();
|
|
3245
|
+
},
|
|
3246
|
+
end,
|
|
3247
|
+
get pose() {
|
|
3248
|
+
return running ? { pose: running.action.pose, time: running.time, progress: Math.min(1, running.time / running.action.seconds) } : null;
|
|
2664
3249
|
}
|
|
2665
3250
|
};
|
|
2666
3251
|
}
|
|
2667
3252
|
|
|
2668
3253
|
// src/object-uses.ts
|
|
3254
|
+
function devicePointOf(spec, device) {
|
|
3255
|
+
const own = (spec.interactions ?? []).find((i) => i.action.do === "toggle_device" && i.action.device === device);
|
|
3256
|
+
if (own) return own.pos;
|
|
3257
|
+
const def = (spec.devices ?? []).find((d) => d.id === device);
|
|
3258
|
+
if (!def) return void 0;
|
|
3259
|
+
const part = def.part ? spec.parts?.find((p) => p.id === def.part)?.pivot : void 0;
|
|
3260
|
+
return part ?? def.plug ?? [0, 1, 0];
|
|
3261
|
+
}
|
|
2669
3262
|
var OPEN = 0.5;
|
|
2670
3263
|
var PREFIX = "use.";
|
|
2671
3264
|
var SOIL_RANK = { clean: 0, urine: 1, feces: 2 };
|
|
@@ -2675,7 +3268,7 @@ var clock = (seconds) => {
|
|
|
2675
3268
|
};
|
|
2676
3269
|
var accepts = (bowl, hand) => (bowl.accepts ?? []).some((id) => hand.itemId === id || hand.itemId.endsWith(`_${id}`));
|
|
2677
3270
|
var YES2 = { available: true };
|
|
2678
|
-
var no = (reason) => ({ available: false, reason });
|
|
3271
|
+
var no = (reason, vars) => ({ available: false, reason, ...vars ? { vars } : {} });
|
|
2679
3272
|
function createUses(options) {
|
|
2680
3273
|
const { spec, world, objectId } = options;
|
|
2681
3274
|
const all = spec.uses ?? [];
|
|
@@ -2688,6 +3281,8 @@ function createUses(options) {
|
|
|
2688
3281
|
let lastHost = null;
|
|
2689
3282
|
const sinkRoutines = createSinkRoutines({ spec, world, objectId });
|
|
2690
3283
|
let routine = null;
|
|
3284
|
+
const drains = createDrainUses({ spec, world, objectId, t: (key, vars) => world.t(key, vars) });
|
|
3285
|
+
const useBody = createUseBody();
|
|
2691
3286
|
const typeKey = `type.${spec.type}`;
|
|
2692
3287
|
const name = () => {
|
|
2693
3288
|
const text = world.t(typeKey);
|
|
@@ -2718,12 +3313,28 @@ function createUses(options) {
|
|
|
2718
3313
|
return fits ? YES2 : no("not_accepted");
|
|
2719
3314
|
}
|
|
2720
3315
|
case "relieve":
|
|
2721
|
-
return YES2;
|
|
3316
|
+
return drains.has(use.basin) ? drainVerdict(host, () => handsAreFree(host) ? null : "needs_free_hand", () => drains.relieveBody(use, host)) : YES2;
|
|
2722
3317
|
case "wash":
|
|
2723
3318
|
case "drink":
|
|
2724
3319
|
return routine ? no("busy") : sinkVerdict(use, spec, host, world.water.isFlowing(objectId, use.fixture));
|
|
3320
|
+
case "plunge":
|
|
3321
|
+
return drainVerdict(host, () => drains.plungeBlocked(use, host), () => drains.plungeBody(use));
|
|
2725
3322
|
}
|
|
2726
3323
|
};
|
|
3324
|
+
const drainVerdict = (host, rule, body) => {
|
|
3325
|
+
const missing = drains.hostBlocked(host);
|
|
3326
|
+
if (missing) return no("host_lacks", { capability: missing });
|
|
3327
|
+
const broken = rule();
|
|
3328
|
+
if (broken) return no(broken);
|
|
3329
|
+
const action = body();
|
|
3330
|
+
if (!action) return no("needs_body");
|
|
3331
|
+
const why = useBody.blocked(action, host);
|
|
3332
|
+
return why ? no(why) : YES2;
|
|
3333
|
+
};
|
|
3334
|
+
const withBody = (action, host, vars, run) => {
|
|
3335
|
+
if (!action) return { ok: false, text: world.t("needs_body", vars) };
|
|
3336
|
+
return useBody.begin(action, host) ? run(action) : { ok: false, text: world.t("body_busy", vars) };
|
|
3337
|
+
};
|
|
2727
3338
|
const itemName = (id) => {
|
|
2728
3339
|
const text = world.t(`item.${id}`);
|
|
2729
3340
|
return text === `item.${id}` ? id.replace(/_/g, " ") : text;
|
|
@@ -2759,7 +3370,10 @@ function createUses(options) {
|
|
|
2759
3370
|
}
|
|
2760
3371
|
case "fill":
|
|
2761
3372
|
return fill(bowls.get(use.bowl), host, vars);
|
|
3373
|
+
case "plunge":
|
|
3374
|
+
return withBody(drains.plungeBody(use), host, vars, (action) => drains.plunge(use, action));
|
|
2762
3375
|
case "relieve": {
|
|
3376
|
+
if (drains.has(use.basin)) return withBody(drains.relieveBody(use, host), host, vars, (action) => drains.relieve(use, host, action));
|
|
2763
3377
|
const now = soil.get(use.basin) ?? "clean";
|
|
2764
3378
|
soil.set(use.basin, SOIL_RANK[use.kind] > SOIL_RANK[now] ? use.kind : now);
|
|
2765
3379
|
return { ok: true, text: world.t(`done_relieve_${use.kind}`, vars) };
|
|
@@ -2789,6 +3403,12 @@ function createUses(options) {
|
|
|
2789
3403
|
const words = end.vars?.need ? { ...end.vars, need: itemName(end.vars.need) } : end.vars;
|
|
2790
3404
|
lastHost?.say(world.t(end.key, { name: name(), ...words }));
|
|
2791
3405
|
};
|
|
3406
|
+
const gestureOf = (use) => {
|
|
3407
|
+
const gesture = GESTURE_OF_USE[use.do];
|
|
3408
|
+
if (!gesture) return null;
|
|
3409
|
+
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;
|
|
3410
|
+
return at ? { gesture, at: [at[0], at[1], at[2]] } : null;
|
|
3411
|
+
};
|
|
2792
3412
|
const visible = (use) => use.do !== "program" || program === null;
|
|
2793
3413
|
return {
|
|
2794
3414
|
has: (id) => id.startsWith(PREFIX),
|
|
@@ -2798,7 +3418,8 @@ function createUses(options) {
|
|
|
2798
3418
|
if (program) entries.push({ id: `${PREFIX}stop`, label: world.t("use.program.stop", { name: name(), left: clock(program.left) }), available: true });
|
|
2799
3419
|
for (const use of all.filter(visible)) {
|
|
2800
3420
|
const v = verdict(use, host);
|
|
2801
|
-
|
|
3421
|
+
const body = gestureOf(use);
|
|
3422
|
+
entries.push({ id: `${PREFIX}${use.id}`, label: labelOf(use, host), available: v.available, ...v.available ? {} : { reason: reasonOf(v, use, host) }, ...body ?? {} });
|
|
2802
3423
|
}
|
|
2803
3424
|
return entries;
|
|
2804
3425
|
},
|
|
@@ -2810,7 +3431,10 @@ function createUses(options) {
|
|
|
2810
3431
|
const v = verdict(use, host);
|
|
2811
3432
|
return v.available ? runUse(use, host) : { ok: false, text: reasonOf(v, use, host) };
|
|
2812
3433
|
},
|
|
2813
|
-
update(dt) {
|
|
3434
|
+
update(dt, host) {
|
|
3435
|
+
if (host) lastHost = host;
|
|
3436
|
+
drains.update(dt, lastHost);
|
|
3437
|
+
useBody.update(dt);
|
|
2814
3438
|
stepRoutine(dt);
|
|
2815
3439
|
if (!program) return;
|
|
2816
3440
|
program.left -= dt;
|
|
@@ -2820,17 +3444,25 @@ function createUses(options) {
|
|
|
2820
3444
|
program = null;
|
|
2821
3445
|
lastHost?.say(done);
|
|
2822
3446
|
},
|
|
2823
|
-
flushed(fixture) {
|
|
3447
|
+
flushed(fixture, host) {
|
|
3448
|
+
if (host) lastHost = host;
|
|
3449
|
+
if (drains.flushed(fixture, lastHost)) return;
|
|
2824
3450
|
const basin = cleans.get(fixture);
|
|
2825
3451
|
if (!basin || soil.get(basin) === "clean") return;
|
|
2826
3452
|
soil.set(basin, "clean");
|
|
2827
3453
|
lastHost?.say(world.t("done_clean", { name: name() }));
|
|
2828
3454
|
},
|
|
3455
|
+
dispose(host) {
|
|
3456
|
+
drains.dispose(host ?? lastHost);
|
|
3457
|
+
useBody.end();
|
|
3458
|
+
},
|
|
2829
3459
|
state: () => ({
|
|
2830
3460
|
bowls: Object.fromEntries(level),
|
|
2831
|
-
soil: Object.fromEntries(soil),
|
|
3461
|
+
soil: Object.fromEntries([...soil].map(([id, now]) => [id, drains.has(id) ? drains.soil(id) : now])),
|
|
3462
|
+
drains: drains.state(),
|
|
2832
3463
|
program: program ? { use: program.use.id, device: program.use.device, left: program.left } : null,
|
|
2833
|
-
routine: routine?.use ?? null
|
|
3464
|
+
routine: routine?.use ?? null,
|
|
3465
|
+
body: useBody.pose
|
|
2834
3466
|
})
|
|
2835
3467
|
};
|
|
2836
3468
|
}
|
|
@@ -2858,7 +3490,7 @@ function createObjectControls(options) {
|
|
|
2858
3490
|
onEvent: (event) => {
|
|
2859
3491
|
if (event.type === "message") said.push(event.text);
|
|
2860
3492
|
if (event.type === "part" && event.object === CONTROLLED_OBJECT) forwardPart(event.part, event.target >= 0.5);
|
|
2861
|
-
if (event.type === "fixture" && event.object === CONTROLLED_OBJECT && event.flowing) uses.flushed(event.fixture);
|
|
3493
|
+
if (event.type === "fixture" && event.object === CONTROLLED_OBJECT && event.flowing) uses.flushed(event.fixture, host ?? void 0);
|
|
2862
3494
|
}
|
|
2863
3495
|
});
|
|
2864
3496
|
const forwardPart = (part, open) => {
|
|
@@ -2885,7 +3517,10 @@ function createObjectControls(options) {
|
|
|
2885
3517
|
return {
|
|
2886
3518
|
list(lent) {
|
|
2887
3519
|
lend(lent);
|
|
2888
|
-
const fromWorld = interactions().map((i) =>
|
|
3520
|
+
const fromWorld = interactions().map((i) => {
|
|
3521
|
+
const gesture = i.gesture;
|
|
3522
|
+
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]] } : {} };
|
|
3523
|
+
});
|
|
2889
3524
|
return [...fromWorld, ...uses.list(lent)];
|
|
2890
3525
|
},
|
|
2891
3526
|
run(id, lent) {
|
|
@@ -2900,14 +3535,17 @@ function createObjectControls(options) {
|
|
|
2900
3535
|
update(dt, lent) {
|
|
2901
3536
|
lend(lent);
|
|
2902
3537
|
world.update(dt);
|
|
2903
|
-
uses.update(dt);
|
|
3538
|
+
uses.update(dt, lent);
|
|
2904
3539
|
},
|
|
2905
3540
|
state() {
|
|
2906
3541
|
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) }));
|
|
2907
3542
|
const emitters = world.emitters().filter((e) => e.object === CONTROLLED_OBJECT && e.kind !== "water");
|
|
2908
3543
|
return { ...uses.state(), screens, emitters };
|
|
2909
3544
|
},
|
|
3545
|
+
serialize: () => world.serialize(),
|
|
3546
|
+
load: (state) => world.load(state),
|
|
2910
3547
|
dispose() {
|
|
3548
|
+
uses.dispose(host ?? void 0);
|
|
2911
3549
|
host = null;
|
|
2912
3550
|
world.remove(CONTROLLED_OBJECT);
|
|
2913
3551
|
world.remove(MAINS);
|
|
@@ -2915,26 +3553,36 @@ function createObjectControls(options) {
|
|
|
2915
3553
|
};
|
|
2916
3554
|
}
|
|
2917
3555
|
export {
|
|
3556
|
+
CLOGGED,
|
|
2918
3557
|
COLLAR_REACH,
|
|
2919
3558
|
CONTROLLED_OBJECT,
|
|
3559
|
+
DRINK_HANDS_LITRES,
|
|
3560
|
+
DRINK_HANDS_LPS,
|
|
2920
3561
|
DRINK_LITRES,
|
|
2921
3562
|
DRINK_LPS,
|
|
2922
3563
|
DRY_SECONDS,
|
|
2923
3564
|
END_GAP,
|
|
2924
3565
|
FILL_SHARE,
|
|
2925
3566
|
FLOW_DEFAULTS,
|
|
3567
|
+
FLUSH_POUR_SECONDS,
|
|
2926
3568
|
FLUSH_RUN_SECONDS,
|
|
3569
|
+
GESTURE_OF_ACTION,
|
|
3570
|
+
GESTURE_OF_USE,
|
|
2927
3571
|
REACH_SECONDS,
|
|
2928
3572
|
WASH_SCRUB_SECONDS,
|
|
2929
3573
|
alignY,
|
|
2930
3574
|
buildChain,
|
|
2931
3575
|
castWithMember,
|
|
2932
3576
|
chainPoints,
|
|
3577
|
+
createBasinDrain,
|
|
3578
|
+
createDrainUses,
|
|
2933
3579
|
createEnginePartPhysics,
|
|
2934
3580
|
createFixtureEmitters,
|
|
2935
3581
|
createObjectControls,
|
|
2936
3582
|
createSinkRoutines,
|
|
3583
|
+
createUseBody,
|
|
2937
3584
|
createWorld,
|
|
3585
|
+
devicePointOf,
|
|
2938
3586
|
dirtyDishes,
|
|
2939
3587
|
disposeChain,
|
|
2940
3588
|
endsMember,
|