@adatechnology/game-interactables 0.9.0 → 0.11.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 +4 -0
- package/dist/index.d.ts +149 -3
- package/dist/index.global.js +317 -16
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +317 -16
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.global.js
CHANGED
|
@@ -21,19 +21,34 @@ var GameInteractables = (() => {
|
|
|
21
21
|
// src/index.ts
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
|
+
COLLAR_REACH: () => COLLAR_REACH,
|
|
24
25
|
CONTROLLED_OBJECT: () => CONTROLLED_OBJECT,
|
|
26
|
+
DRINK_LITRES: () => DRINK_LITRES,
|
|
27
|
+
DRINK_LPS: () => DRINK_LPS,
|
|
28
|
+
DRY_SECONDS: () => DRY_SECONDS,
|
|
29
|
+
END_GAP: () => END_GAP,
|
|
30
|
+
FILL_SHARE: () => FILL_SHARE,
|
|
31
|
+
FLOW_DEFAULTS: () => FLOW_DEFAULTS,
|
|
25
32
|
FLUSH_RUN_SECONDS: () => FLUSH_RUN_SECONDS,
|
|
33
|
+
REACH_SECONDS: () => REACH_SECONDS,
|
|
34
|
+
WASH_SCRUB_SECONDS: () => WASH_SCRUB_SECONDS,
|
|
26
35
|
alignY: () => alignY,
|
|
27
36
|
buildChain: () => buildChain,
|
|
37
|
+
castWithMember: () => castWithMember,
|
|
28
38
|
chainPoints: () => chainPoints,
|
|
29
39
|
createEnginePartPhysics: () => createEnginePartPhysics,
|
|
30
40
|
createFixtureEmitters: () => createFixtureEmitters,
|
|
31
41
|
createObjectControls: () => createObjectControls,
|
|
42
|
+
createSinkRoutines: () => createSinkRoutines,
|
|
32
43
|
createWorld: () => createWorld,
|
|
44
|
+
dirtyDishes: () => dirtyDishes,
|
|
33
45
|
disposeChain: () => disposeChain,
|
|
46
|
+
endsMember: () => endsMember,
|
|
47
|
+
findNeeds: () => findNeeds,
|
|
34
48
|
fitsInVolume: () => fitsInVolume,
|
|
35
49
|
fitsSize: () => fitsSize,
|
|
36
50
|
fitsSlot: () => fitsSlot,
|
|
51
|
+
fixtureFlowLps: () => fixtureFlowLps,
|
|
37
52
|
format: () => format,
|
|
38
53
|
generateLoot: () => generateLoot,
|
|
39
54
|
hangTail: () => hangTail,
|
|
@@ -48,9 +63,12 @@ var GameInteractables = (() => {
|
|
|
48
63
|
rng: () => rng,
|
|
49
64
|
rotY: () => rotY,
|
|
50
65
|
rotateAxis: () => rotateAxis,
|
|
66
|
+
sinkVerdict: () => sinkVerdict,
|
|
51
67
|
solveSpan: () => solveSpan,
|
|
52
68
|
spanStrength: () => spanStrength,
|
|
53
|
-
|
|
69
|
+
wireRuns: () => wireRuns,
|
|
70
|
+
worldToLocal: () => worldToLocal,
|
|
71
|
+
wrapsMember: () => wrapsMember
|
|
54
72
|
});
|
|
55
73
|
|
|
56
74
|
// src/fixture-emitters.ts
|
|
@@ -275,7 +293,19 @@ var GameInteractables = (() => {
|
|
|
275
293
|
done_program_stop: "{name} stopped",
|
|
276
294
|
done_relieve_urine: "You peed in {name}",
|
|
277
295
|
done_relieve_feces: "You pooed in {name}",
|
|
278
|
-
done_clean: "{name} flushed clean"
|
|
296
|
+
done_clean: "{name} flushed clean",
|
|
297
|
+
"use.wash_dishes": "Wash the dishes",
|
|
298
|
+
"use.drink_water": "Drink water",
|
|
299
|
+
busy: "Already in use",
|
|
300
|
+
needs_running: "Turn the water on first",
|
|
301
|
+
needs_item: "You need {need}",
|
|
302
|
+
item_spent: "{item} is empty",
|
|
303
|
+
no_dirty_dishes: "No dirty dishes in the sink",
|
|
304
|
+
started_wash: "{label}\u2026",
|
|
305
|
+
started_drink: "{label}\u2026",
|
|
306
|
+
done_wash: "Washed and rinsed",
|
|
307
|
+
done_wash_dishes: "Dishes washed: {n} on the rack",
|
|
308
|
+
done_drink: "You drank {litres} l of water"
|
|
279
309
|
},
|
|
280
310
|
"pt-BR": {
|
|
281
311
|
"prompt.open": "Abrir {name}",
|
|
@@ -328,7 +358,19 @@ var GameInteractables = (() => {
|
|
|
328
358
|
done_program_stop: "{name} parou",
|
|
329
359
|
done_relieve_urine: "Voc\xEA fez xixi em {name}",
|
|
330
360
|
done_relieve_feces: "Voc\xEA fez coc\xF4 em {name}",
|
|
331
|
-
done_clean: "Descarga dada: {name} limpo"
|
|
361
|
+
done_clean: "Descarga dada: {name} limpo",
|
|
362
|
+
"use.wash_dishes": "Lavar a lou\xE7a",
|
|
363
|
+
"use.drink_water": "Beber \xE1gua",
|
|
364
|
+
busy: "J\xE1 est\xE1 em uso",
|
|
365
|
+
needs_running: "Abra a \xE1gua primeiro",
|
|
366
|
+
needs_item: "Precisa de {need}",
|
|
367
|
+
item_spent: "{item} acabou",
|
|
368
|
+
no_dirty_dishes: "N\xE3o h\xE1 lou\xE7a suja na pia",
|
|
369
|
+
started_wash: "{label}\u2026",
|
|
370
|
+
started_drink: "{label}\u2026",
|
|
371
|
+
done_wash: "Lavado e enxaguado",
|
|
372
|
+
done_wash_dishes: "Lou\xE7a lavada: {n} no escorredor",
|
|
373
|
+
done_drink: "Voc\xEA bebeu {litres} l de \xE1gua"
|
|
332
374
|
}
|
|
333
375
|
};
|
|
334
376
|
function pickLocale(locale) {
|
|
@@ -2457,6 +2499,61 @@ var GameInteractables = (() => {
|
|
|
2457
2499
|
});
|
|
2458
2500
|
}
|
|
2459
2501
|
|
|
2502
|
+
// src/wire-runs.ts
|
|
2503
|
+
var lerp = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
|
|
2504
|
+
function along(points, step) {
|
|
2505
|
+
const out = points.length ? [[...points[0]]] : [];
|
|
2506
|
+
for (let i = 1; i < points.length; i++) {
|
|
2507
|
+
const a = points[i - 1];
|
|
2508
|
+
const b = points[i];
|
|
2509
|
+
const steps = Math.max(1, Math.ceil(Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]) / step));
|
|
2510
|
+
for (let k = 1; k <= steps; k++) out.push(lerp(a, b, k / steps));
|
|
2511
|
+
}
|
|
2512
|
+
return out;
|
|
2513
|
+
}
|
|
2514
|
+
function wireRuns(params) {
|
|
2515
|
+
const points = along(params.points, Math.max(1e-3, params.step));
|
|
2516
|
+
if (points.length < 2) return [];
|
|
2517
|
+
const holders = points.map((p) => params.holderOf(p));
|
|
2518
|
+
const runs = [];
|
|
2519
|
+
let current = { holder: holders[0], points: [points[0]] };
|
|
2520
|
+
for (let i = 1; i < points.length; i++) {
|
|
2521
|
+
if (holders[i] === current.holder) {
|
|
2522
|
+
current.points.push(points[i]);
|
|
2523
|
+
continue;
|
|
2524
|
+
}
|
|
2525
|
+
const seam = lerp(points[i - 1], points[i], 0.5);
|
|
2526
|
+
current.points.push(seam);
|
|
2527
|
+
runs.push(current);
|
|
2528
|
+
current = { holder: holders[i], points: [[...seam], points[i]] };
|
|
2529
|
+
}
|
|
2530
|
+
runs.push(current);
|
|
2531
|
+
return runs;
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
// src/cast-with-member.ts
|
|
2535
|
+
var COLLAR_REACH = 0.03;
|
|
2536
|
+
var END_GAP = 5e-3;
|
|
2537
|
+
function centredOn(member, other) {
|
|
2538
|
+
for (const k of [0, 2]) {
|
|
2539
|
+
if (other[k] < member[k] - COLLAR_REACH || other[k + 3] > member[k + 3] + COLLAR_REACH) return false;
|
|
2540
|
+
if (Math.abs((other[k] + other[k + 3]) / 2 - (member[k] + member[k + 3]) / 2) > COLLAR_REACH) return false;
|
|
2541
|
+
}
|
|
2542
|
+
return true;
|
|
2543
|
+
}
|
|
2544
|
+
function wrapsMember(member, collar) {
|
|
2545
|
+
const overlap2 = Math.min(collar[4], member[4]) - Math.max(collar[1], member[1]);
|
|
2546
|
+
return overlap2 >= (collar[4] - collar[1]) / 2 && centredOn(member, collar);
|
|
2547
|
+
}
|
|
2548
|
+
function endsMember(member, end) {
|
|
2549
|
+
const under = Math.abs(end[4] - member[1]) <= END_GAP;
|
|
2550
|
+
const over = Math.abs(end[1] - member[4]) <= END_GAP;
|
|
2551
|
+
return (under || over) && end[4] - end[1] <= member[4] - member[1] && centredOn(member, end);
|
|
2552
|
+
}
|
|
2553
|
+
function castWithMember(member, other) {
|
|
2554
|
+
return wrapsMember(member, other) || endsMember(member, other);
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2460
2557
|
// src/fits-volume.ts
|
|
2461
2558
|
function fitsInVolume(size, half) {
|
|
2462
2559
|
const thing = [...size].sort((a, b) => b - a);
|
|
@@ -2464,6 +2561,183 @@ var GameInteractables = (() => {
|
|
|
2464
2561
|
return thing.every((side, i) => side <= (room[i] ?? 0));
|
|
2465
2562
|
}
|
|
2466
2563
|
|
|
2564
|
+
// src/sink-uses.ts
|
|
2565
|
+
var WASH_SCRUB_SECONDS = 3;
|
|
2566
|
+
var DRINK_LITRES = 0.25;
|
|
2567
|
+
var FILL_SHARE = 0.85;
|
|
2568
|
+
var DRINK_LPS = 0.06;
|
|
2569
|
+
var REACH_SECONDS = 0.6;
|
|
2570
|
+
var DRY_SECONDS = 0.5;
|
|
2571
|
+
var SCRUBBED_DIRT = 0.15;
|
|
2572
|
+
var YES = { available: true };
|
|
2573
|
+
var idsOf = (need) => typeof need === "string" ? [need] : need;
|
|
2574
|
+
function findNeeds(needs, host) {
|
|
2575
|
+
const items = [];
|
|
2576
|
+
for (const need of needs) {
|
|
2577
|
+
const item = host.itemAt?.(idsOf(need)) ?? null;
|
|
2578
|
+
if (!item) return { items, missing: idsOf(need) };
|
|
2579
|
+
items.push(item);
|
|
2580
|
+
}
|
|
2581
|
+
return { items };
|
|
2582
|
+
}
|
|
2583
|
+
function dirtyDishes(use, spec, host) {
|
|
2584
|
+
const dishes = use.dishes;
|
|
2585
|
+
const basin = dishes ? (spec.basins ?? []).find((b) => b.id === dishes.basin) : void 0;
|
|
2586
|
+
if (!dishes || !basin) return [];
|
|
2587
|
+
return (host.itemsInside?.(dishes.ids, basin.from, basin.to) ?? []).filter((item) => (item.dirt ?? 0) > 0);
|
|
2588
|
+
}
|
|
2589
|
+
function sinkVerdict(use, spec, host, flowing) {
|
|
2590
|
+
if (use.do === "wash" && use.requiresFlowing && !flowing) return { available: false, reason: "needs_running" };
|
|
2591
|
+
const found = findNeeds(use.needs ?? [], host);
|
|
2592
|
+
if (found.missing) return { available: false, reason: "needs_item", vars: { need: found.missing[0] ?? "" } };
|
|
2593
|
+
if (use.do === "drink") return YES;
|
|
2594
|
+
const dosed = use.dose ? found.items[use.dose.need] : void 0;
|
|
2595
|
+
if (dosed && (dosed.remaining ?? 1) <= 0) return { available: false, reason: "item_spent", vars: { item: dosed.name } };
|
|
2596
|
+
if (use.dishes && dirtyDishes(use, spec, host).length === 0) return { available: false, reason: "no_dirty_dishes" };
|
|
2597
|
+
return YES;
|
|
2598
|
+
}
|
|
2599
|
+
var fixtureFlowLps = (fixture) => fixture ? (fixture.flow ?? FLOW_DEFAULTS[fixture.kind] ?? 6) / 60 : 0;
|
|
2600
|
+
function runPhases(phases) {
|
|
2601
|
+
let index = 0;
|
|
2602
|
+
return (dt) => {
|
|
2603
|
+
if (index < phases.length && phases[index]?.(dt)) index++;
|
|
2604
|
+
return index >= phases.length;
|
|
2605
|
+
};
|
|
2606
|
+
}
|
|
2607
|
+
function wait(seconds) {
|
|
2608
|
+
let left = seconds;
|
|
2609
|
+
return (dt) => (left -= dt) <= 0;
|
|
2610
|
+
}
|
|
2611
|
+
function placePhase(host, item, spot) {
|
|
2612
|
+
return () => {
|
|
2613
|
+
if (spot) host.placeItem?.(item.objectId, [spot[0], spot[1], spot[2]]);
|
|
2614
|
+
return true;
|
|
2615
|
+
};
|
|
2616
|
+
}
|
|
2617
|
+
function createSinkRoutines(options) {
|
|
2618
|
+
const { spec, world, objectId } = options;
|
|
2619
|
+
const fixtureOf = (id) => (spec.fixtures ?? []).find((f) => f.id === id);
|
|
2620
|
+
const flowing = (use) => world.water.isFlowing(objectId, use.fixture);
|
|
2621
|
+
const water = (use) => flowing(use) ? fixtureFlowLps(fixtureOf(use.fixture)) : 0;
|
|
2622
|
+
const waterOf = (use) => {
|
|
2623
|
+
let dry = 0;
|
|
2624
|
+
return (dt) => {
|
|
2625
|
+
const flow = water(use);
|
|
2626
|
+
dry = flow > 0 ? 0 : dry + dt;
|
|
2627
|
+
return dry > DRY_SECONDS ? null : flow;
|
|
2628
|
+
};
|
|
2629
|
+
};
|
|
2630
|
+
const tapPhases = (use) => {
|
|
2631
|
+
let opened = false;
|
|
2632
|
+
const reach = wait(REACH_SECONDS);
|
|
2633
|
+
return {
|
|
2634
|
+
open: (dt) => {
|
|
2635
|
+
if (opened || use.opensFixture === false || flowing(use)) return true;
|
|
2636
|
+
if (!reach(dt)) return false;
|
|
2637
|
+
opened = world.setFixture(objectId, use.fixture, true);
|
|
2638
|
+
return true;
|
|
2639
|
+
},
|
|
2640
|
+
close: () => {
|
|
2641
|
+
if (opened) world.setFixture(objectId, use.fixture, false);
|
|
2642
|
+
return true;
|
|
2643
|
+
}
|
|
2644
|
+
};
|
|
2645
|
+
};
|
|
2646
|
+
const scrubAndRinse = (use, host, target, fail) => {
|
|
2647
|
+
const item = typeof target === "string" ? void 0 : target;
|
|
2648
|
+
const id = item?.objectId ?? target;
|
|
2649
|
+
const seconds = use.scrubSeconds ?? WASH_SCRUB_SECONDS;
|
|
2650
|
+
const dirt = item?.dirt ?? 0;
|
|
2651
|
+
let scrubbed = -1;
|
|
2652
|
+
const scrub = (dt) => {
|
|
2653
|
+
if (scrubbed < 0) {
|
|
2654
|
+
scrubbed = 0;
|
|
2655
|
+
host.playUse?.(use.clip, item?.objectId);
|
|
2656
|
+
}
|
|
2657
|
+
scrubbed = Math.min(seconds, scrubbed + dt);
|
|
2658
|
+
host.lather?.(id, dt / seconds);
|
|
2659
|
+
if (dirt > 0) host.setDirt?.(id, dirt - (dirt - Math.min(dirt, SCRUBBED_DIRT)) * (scrubbed / seconds));
|
|
2660
|
+
return scrubbed >= seconds;
|
|
2661
|
+
};
|
|
2662
|
+
const running = waterOf(use);
|
|
2663
|
+
const rinse = (dt) => {
|
|
2664
|
+
const flow = running(dt);
|
|
2665
|
+
if (flow === null) {
|
|
2666
|
+
fail({ key: "no_water", ok: false });
|
|
2667
|
+
return true;
|
|
2668
|
+
}
|
|
2669
|
+
if (flow <= 0 || (host.rinse?.(id, flow, dt) ?? 0) > 0) return false;
|
|
2670
|
+
if (dirt > 0) host.setDirt?.(id, 0);
|
|
2671
|
+
return true;
|
|
2672
|
+
};
|
|
2673
|
+
return [scrub, rinse];
|
|
2674
|
+
};
|
|
2675
|
+
const startWash = (use, host) => {
|
|
2676
|
+
const { items } = findNeeds(use.needs ?? [], host);
|
|
2677
|
+
let end = null;
|
|
2678
|
+
const fail = (reason) => {
|
|
2679
|
+
end ?? (end = reason);
|
|
2680
|
+
};
|
|
2681
|
+
const tap = tapPhases(use);
|
|
2682
|
+
const dosed = use.dose ? items[use.dose.need] : void 0;
|
|
2683
|
+
const dose = () => {
|
|
2684
|
+
if (dosed && host.takeDose?.(dosed.objectId, use.dose?.amount).taken === 0) fail({ key: "item_spent", ok: false, vars: { item: dosed.name } });
|
|
2685
|
+
return true;
|
|
2686
|
+
};
|
|
2687
|
+
const dishes = use.dishes ? dirtyDishes(use, spec, host) : [];
|
|
2688
|
+
const rack = use.dishes?.rack ?? [];
|
|
2689
|
+
const work = use.dishes ? dishes.flatMap((dish, index) => [...scrubAndRinse(use, host, dish, fail), placePhase(host, dish, rack[Math.min(index, rack.length - 1)])]) : scrubAndRinse(use, host, use.surface, fail);
|
|
2690
|
+
const guarded = work.map((phase) => (dt) => end !== null || phase(dt));
|
|
2691
|
+
const run = runPhases([tap.open, dose, ...guarded, tap.close]);
|
|
2692
|
+
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
|
+
return { use: use.id, step: (dt) => run(dt) ? end ?? done : null };
|
|
2694
|
+
};
|
|
2695
|
+
const startDrink = (use, host, vessel) => {
|
|
2696
|
+
const tap = tapPhases(use);
|
|
2697
|
+
const want = Math.min(use.litres ?? DRINK_LITRES, (vessel.liquid?.capacity ?? DRINK_LITRES) * FILL_SHARE);
|
|
2698
|
+
let filled = vessel.liquid?.kind === "water" ? vessel.liquid.litres : 0;
|
|
2699
|
+
let drunk = 0;
|
|
2700
|
+
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
|
+
const running = waterOf(use);
|
|
2707
|
+
const fill = (dt) => {
|
|
2708
|
+
if (end) return true;
|
|
2709
|
+
const flow = running(dt);
|
|
2710
|
+
if (flow === null) {
|
|
2711
|
+
end = { key: "no_water", ok: false };
|
|
2712
|
+
return true;
|
|
2713
|
+
}
|
|
2714
|
+
if (flow <= 0) return false;
|
|
2715
|
+
const took = host.fillItem?.(vessel.objectId, "water", Math.min(flow * dt, want - filled)) ?? 0;
|
|
2716
|
+
filled += took;
|
|
2717
|
+
return filled >= want - 1e-6 || took <= 0;
|
|
2718
|
+
};
|
|
2719
|
+
let sipping = false;
|
|
2720
|
+
const drink = (dt) => {
|
|
2721
|
+
if (end) return true;
|
|
2722
|
+
if (!sipping) sipping = host.playUse?.(use.clip, vessel.objectId) ?? true;
|
|
2723
|
+
const sip = host.drinkItem?.(vessel.objectId, Math.min(DRINK_LPS * dt, filled - drunk)) ?? 0;
|
|
2724
|
+
drunk += sip;
|
|
2725
|
+
return drunk >= filled - 1e-6 || sip <= 0;
|
|
2726
|
+
};
|
|
2727
|
+
const giveBack = vessel.where === "reach" ? placePhase(host, vessel, vessel.at) : () => true;
|
|
2728
|
+
const run = runPhases([take, tap.open, fill, tap.close, drink, wait(REACH_SECONDS), giveBack]);
|
|
2729
|
+
return { use: use.id, step: (dt) => run(dt) ? end ?? { key: "done_drink", ok: true, vars: { litres: drunk.toFixed(2) } } : null };
|
|
2730
|
+
};
|
|
2731
|
+
return {
|
|
2732
|
+
start(use, host) {
|
|
2733
|
+
if (use.do === "wash") return startWash(use, host);
|
|
2734
|
+
const vessel = findNeeds(use.needs, host).items[0];
|
|
2735
|
+
if (!vessel) return { use: use.id, step: () => ({ key: "needs_item", ok: false, vars: { need: idsOf(use.needs[0] ?? "")[0] ?? "" } }) };
|
|
2736
|
+
return startDrink(use, host, vessel);
|
|
2737
|
+
}
|
|
2738
|
+
};
|
|
2739
|
+
}
|
|
2740
|
+
|
|
2467
2741
|
// src/object-uses.ts
|
|
2468
2742
|
var OPEN = 0.5;
|
|
2469
2743
|
var PREFIX = "use.";
|
|
@@ -2473,7 +2747,7 @@ var GameInteractables = (() => {
|
|
|
2473
2747
|
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
|
|
2474
2748
|
};
|
|
2475
2749
|
var accepts = (bowl, hand) => (bowl.accepts ?? []).some((id) => hand.itemId === id || hand.itemId.endsWith(`_${id}`));
|
|
2476
|
-
var
|
|
2750
|
+
var YES2 = { available: true };
|
|
2477
2751
|
var no = (reason) => ({ available: false, reason });
|
|
2478
2752
|
function createUses(options) {
|
|
2479
2753
|
const { spec, world, objectId } = options;
|
|
@@ -2485,6 +2759,8 @@ var GameInteractables = (() => {
|
|
|
2485
2759
|
const cleans = new Map((spec.fixtures ?? []).flatMap((f) => f.cleans ? [[f.id, f.cleans]] : []));
|
|
2486
2760
|
let program = null;
|
|
2487
2761
|
let lastHost = null;
|
|
2762
|
+
const sinkRoutines = createSinkRoutines({ spec, world, objectId });
|
|
2763
|
+
let routine = null;
|
|
2488
2764
|
const typeKey = `type.${spec.type}`;
|
|
2489
2765
|
const name = () => {
|
|
2490
2766
|
const text = world.t(typeKey);
|
|
@@ -2496,15 +2772,15 @@ var GameInteractables = (() => {
|
|
|
2496
2772
|
switch (use.do) {
|
|
2497
2773
|
case "program":
|
|
2498
2774
|
if (!world.power.isPowered(objectId, use.device)) return no("no_power");
|
|
2499
|
-
return use.access && host.partOpening(use.access) >= OPEN ? no("needs_closed") :
|
|
2775
|
+
return use.access && host.partOpening(use.access) >= OPEN ? no("needs_closed") : YES2;
|
|
2500
2776
|
case "put_in": {
|
|
2501
2777
|
const c = containers.get(use.container);
|
|
2502
2778
|
if (!hand) return no("hand_empty");
|
|
2503
2779
|
if (!c || !accessOpen(host, c.access)) return no("requires_open");
|
|
2504
|
-
return fitsInVolume(hand.size, c.volume.half) ?
|
|
2780
|
+
return fitsInVolume(hand.size, c.volume.half) ? YES2 : no("not_fit");
|
|
2505
2781
|
}
|
|
2506
2782
|
case "empty":
|
|
2507
|
-
return accessOpen(host, containers.get(use.container)?.access) ?
|
|
2783
|
+
return accessOpen(host, containers.get(use.container)?.access) ? YES2 : no("requires_open");
|
|
2508
2784
|
case "fill": {
|
|
2509
2785
|
const bowl = bowls.get(use.bowl);
|
|
2510
2786
|
if (!bowl) return no("empty");
|
|
@@ -2512,12 +2788,23 @@ var GameInteractables = (() => {
|
|
|
2512
2788
|
if (!hand) return no("hand_empty");
|
|
2513
2789
|
if (bowl.holds === "water" && hand.liquid?.kind === "water" && hand.liquid.closed) return no("requires_open");
|
|
2514
2790
|
const fits = bowl.holds === "water" ? hand.liquid?.kind === "water" && hand.liquid.litres > 0 : accepts(bowl, hand);
|
|
2515
|
-
return fits ?
|
|
2791
|
+
return fits ? YES2 : no("not_accepted");
|
|
2516
2792
|
}
|
|
2517
2793
|
case "relieve":
|
|
2518
|
-
return
|
|
2794
|
+
return YES2;
|
|
2795
|
+
case "wash":
|
|
2796
|
+
case "drink":
|
|
2797
|
+
return routine ? no("busy") : sinkVerdict(use, spec, host, world.water.isFlowing(objectId, use.fixture));
|
|
2519
2798
|
}
|
|
2520
2799
|
};
|
|
2800
|
+
const itemName = (id) => {
|
|
2801
|
+
const text = world.t(`item.${id}`);
|
|
2802
|
+
return text === `item.${id}` ? id.replace(/_/g, " ") : text;
|
|
2803
|
+
};
|
|
2804
|
+
const reasonOf = (v, use, host) => {
|
|
2805
|
+
const words = { ...textVars(use, host), ...v.vars };
|
|
2806
|
+
return world.t(v.reason, words.need ? { ...words, need: itemName(words.need) } : words);
|
|
2807
|
+
};
|
|
2521
2808
|
const textVars = (use, host) => ({
|
|
2522
2809
|
name: name(),
|
|
2523
2810
|
item: host.hand()?.name ?? "",
|
|
@@ -2550,6 +2837,10 @@ var GameInteractables = (() => {
|
|
|
2550
2837
|
soil.set(use.basin, SOIL_RANK[use.kind] > SOIL_RANK[now] ? use.kind : now);
|
|
2551
2838
|
return { ok: true, text: world.t(`done_relieve_${use.kind}`, vars) };
|
|
2552
2839
|
}
|
|
2840
|
+
case "wash":
|
|
2841
|
+
case "drink":
|
|
2842
|
+
routine = sinkRoutines.start(use, host);
|
|
2843
|
+
return { ok: true, text: world.t(`started_${use.do}`, { ...vars, label: world.t(use.label, vars) }) };
|
|
2553
2844
|
}
|
|
2554
2845
|
};
|
|
2555
2846
|
const fill = (bowl, host, vars) => {
|
|
@@ -2564,6 +2855,13 @@ var GameInteractables = (() => {
|
|
|
2564
2855
|
program = null;
|
|
2565
2856
|
return world.t("done_program_stop", { name: name() });
|
|
2566
2857
|
};
|
|
2858
|
+
const stepRoutine = (dt) => {
|
|
2859
|
+
const end = routine?.step(dt);
|
|
2860
|
+
if (!end) return;
|
|
2861
|
+
routine = null;
|
|
2862
|
+
const words = end.vars?.need ? { ...end.vars, need: itemName(end.vars.need) } : end.vars;
|
|
2863
|
+
lastHost?.say(world.t(end.key, { name: name(), ...words }));
|
|
2864
|
+
};
|
|
2567
2865
|
const visible = (use) => use.do !== "program" || program === null;
|
|
2568
2866
|
return {
|
|
2569
2867
|
has: (id) => id.startsWith(PREFIX),
|
|
@@ -2573,7 +2871,7 @@ var GameInteractables = (() => {
|
|
|
2573
2871
|
if (program) entries.push({ id: `${PREFIX}stop`, label: world.t("use.program.stop", { name: name(), left: clock(program.left) }), available: true });
|
|
2574
2872
|
for (const use of all.filter(visible)) {
|
|
2575
2873
|
const v = verdict(use, host);
|
|
2576
|
-
entries.push({ id: `${PREFIX}${use.id}`, label: labelOf(use, host), available: v.available, ...v.available ? {} : { reason:
|
|
2874
|
+
entries.push({ id: `${PREFIX}${use.id}`, label: labelOf(use, host), available: v.available, ...v.available ? {} : { reason: reasonOf(v, use, host) } });
|
|
2577
2875
|
}
|
|
2578
2876
|
return entries;
|
|
2579
2877
|
},
|
|
@@ -2583,9 +2881,10 @@ var GameInteractables = (() => {
|
|
|
2583
2881
|
const use = all.find((u) => `${PREFIX}${u.id}` === id);
|
|
2584
2882
|
if (!use || !visible(use)) return { ok: false, text: "" };
|
|
2585
2883
|
const v = verdict(use, host);
|
|
2586
|
-
return v.available ? runUse(use, host) : { ok: false, text:
|
|
2884
|
+
return v.available ? runUse(use, host) : { ok: false, text: reasonOf(v, use, host) };
|
|
2587
2885
|
},
|
|
2588
2886
|
update(dt) {
|
|
2887
|
+
stepRoutine(dt);
|
|
2589
2888
|
if (!program) return;
|
|
2590
2889
|
program.left -= dt;
|
|
2591
2890
|
if (program.left > 0) return;
|
|
@@ -2603,7 +2902,8 @@ var GameInteractables = (() => {
|
|
|
2603
2902
|
state: () => ({
|
|
2604
2903
|
bowls: Object.fromEntries(level),
|
|
2605
2904
|
soil: Object.fromEntries(soil),
|
|
2606
|
-
program: program ? { use: program.use.id, device: program.use.device, left: program.left } : null
|
|
2905
|
+
program: program ? { use: program.use.id, device: program.use.device, left: program.left } : null,
|
|
2906
|
+
routine: routine?.use ?? null
|
|
2607
2907
|
})
|
|
2608
2908
|
};
|
|
2609
2909
|
}
|
|
@@ -2614,9 +2914,9 @@ var GameInteractables = (() => {
|
|
|
2614
2914
|
var MAINS_TANK = "water";
|
|
2615
2915
|
var HOST_KINDS = /* @__PURE__ */ new Set(["toggle_part", "open_container", "take", "read", "sit", "toggle_breaker"]);
|
|
2616
2916
|
var PLUG_FALLBACK = [0, 0.3, 0];
|
|
2617
|
-
function mainsSpec(spec) {
|
|
2917
|
+
function mainsSpec(spec, water) {
|
|
2618
2918
|
const plugged = (spec.devices ?? []).filter((d) => d.socket !== void 0 && !d.circuit);
|
|
2619
|
-
return { type: MAINS, sockets: plugged.map((d, i) => ({ id: `socket_${i}`, pos: d.plug ?? PLUG_FALLBACK })), tanks: [{ id: MAINS_TANK, capacity: 1e9 }] };
|
|
2919
|
+
return { type: MAINS, sockets: plugged.map((d, i) => ({ id: `socket_${i}`, pos: d.plug ?? PLUG_FALLBACK })), tanks: water ? [{ id: MAINS_TANK, capacity: 1e9 }] : [] };
|
|
2620
2920
|
}
|
|
2621
2921
|
function createObjectControls(options) {
|
|
2622
2922
|
const { spec } = options;
|
|
@@ -2639,8 +2939,9 @@ var GameInteractables = (() => {
|
|
|
2639
2939
|
forwarded.set(part, open);
|
|
2640
2940
|
host?.setPart(part, open);
|
|
2641
2941
|
};
|
|
2642
|
-
|
|
2643
|
-
|
|
2942
|
+
const piped = options.mains?.water ?? true;
|
|
2943
|
+
world.add(MAINS, mainsSpec(spec, piped), { x: 0, y: 0, z: 0, ry: 0 });
|
|
2944
|
+
if (piped) world.water.setDefaultTank(`${MAINS}:${MAINS_TANK}`);
|
|
2644
2945
|
world.add(CONTROLLED_OBJECT, spec, { x: 0, y: 0, z: 0, ry: 0 });
|
|
2645
2946
|
const uses = createUses({ spec, world, objectId: CONTROLLED_OBJECT });
|
|
2646
2947
|
const programmedDevices = new Set((spec.uses ?? []).flatMap((u) => u.do === "program" ? [u.device] : []));
|