@adatechnology/game-interactables 0.10.0 → 0.12.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/dist/index.d.ts +150 -3
- package/dist/index.global.js +334 -17
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +334 -17
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.global.js
CHANGED
|
@@ -21,19 +21,37 @@ 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
|
+
GESTURE_OF_ACTION: () => GESTURE_OF_ACTION,
|
|
34
|
+
GESTURE_OF_USE: () => GESTURE_OF_USE,
|
|
35
|
+
REACH_SECONDS: () => REACH_SECONDS,
|
|
36
|
+
WASH_SCRUB_SECONDS: () => WASH_SCRUB_SECONDS,
|
|
26
37
|
alignY: () => alignY,
|
|
27
38
|
buildChain: () => buildChain,
|
|
39
|
+
castWithMember: () => castWithMember,
|
|
28
40
|
chainPoints: () => chainPoints,
|
|
29
41
|
createEnginePartPhysics: () => createEnginePartPhysics,
|
|
30
42
|
createFixtureEmitters: () => createFixtureEmitters,
|
|
31
43
|
createObjectControls: () => createObjectControls,
|
|
44
|
+
createSinkRoutines: () => createSinkRoutines,
|
|
32
45
|
createWorld: () => createWorld,
|
|
46
|
+
devicePointOf: () => devicePointOf,
|
|
47
|
+
dirtyDishes: () => dirtyDishes,
|
|
33
48
|
disposeChain: () => disposeChain,
|
|
49
|
+
endsMember: () => endsMember,
|
|
50
|
+
findNeeds: () => findNeeds,
|
|
34
51
|
fitsInVolume: () => fitsInVolume,
|
|
35
52
|
fitsSize: () => fitsSize,
|
|
36
53
|
fitsSlot: () => fitsSlot,
|
|
54
|
+
fixtureFlowLps: () => fixtureFlowLps,
|
|
37
55
|
format: () => format,
|
|
38
56
|
generateLoot: () => generateLoot,
|
|
39
57
|
hangTail: () => hangTail,
|
|
@@ -48,12 +66,41 @@ var GameInteractables = (() => {
|
|
|
48
66
|
rng: () => rng,
|
|
49
67
|
rotY: () => rotY,
|
|
50
68
|
rotateAxis: () => rotateAxis,
|
|
69
|
+
sinkVerdict: () => sinkVerdict,
|
|
51
70
|
solveSpan: () => solveSpan,
|
|
52
71
|
spanStrength: () => spanStrength,
|
|
53
72
|
wireRuns: () => wireRuns,
|
|
54
|
-
worldToLocal: () => worldToLocal
|
|
73
|
+
worldToLocal: () => worldToLocal,
|
|
74
|
+
wrapsMember: () => wrapsMember
|
|
55
75
|
});
|
|
56
76
|
|
|
77
|
+
// src/gestures.ts
|
|
78
|
+
var GESTURE_OF_ACTION = {
|
|
79
|
+
toggle_part: null,
|
|
80
|
+
open_container: null,
|
|
81
|
+
take: null,
|
|
82
|
+
sit: null,
|
|
83
|
+
toggle_device: "press",
|
|
84
|
+
cycle_device: "press",
|
|
85
|
+
toggle_switch: "flip",
|
|
86
|
+
toggle_breaker: "flip",
|
|
87
|
+
toggle_main: "flip",
|
|
88
|
+
toggle_fixture: "turn",
|
|
89
|
+
toggle_burner: "turn",
|
|
90
|
+
ignite: "strike",
|
|
91
|
+
toggle_fuel: "turn",
|
|
92
|
+
read: "read"
|
|
93
|
+
};
|
|
94
|
+
var GESTURE_OF_USE = {
|
|
95
|
+
program: "press",
|
|
96
|
+
put_in: "put_in",
|
|
97
|
+
empty: "tip",
|
|
98
|
+
fill: "pour",
|
|
99
|
+
relieve: null,
|
|
100
|
+
wash: null,
|
|
101
|
+
drink: null
|
|
102
|
+
};
|
|
103
|
+
|
|
57
104
|
// src/fixture-emitters.ts
|
|
58
105
|
var FLUSH_RUN_SECONDS = 2;
|
|
59
106
|
var START_OPENING = 0.05;
|
|
@@ -276,7 +323,19 @@ var GameInteractables = (() => {
|
|
|
276
323
|
done_program_stop: "{name} stopped",
|
|
277
324
|
done_relieve_urine: "You peed in {name}",
|
|
278
325
|
done_relieve_feces: "You pooed in {name}",
|
|
279
|
-
done_clean: "{name} flushed clean"
|
|
326
|
+
done_clean: "{name} flushed clean",
|
|
327
|
+
"use.wash_dishes": "Wash the dishes",
|
|
328
|
+
"use.drink_water": "Drink water",
|
|
329
|
+
busy: "Already in use",
|
|
330
|
+
needs_running: "Turn the water on first",
|
|
331
|
+
needs_item: "You need {need}",
|
|
332
|
+
item_spent: "{item} is empty",
|
|
333
|
+
no_dirty_dishes: "No dirty dishes in the sink",
|
|
334
|
+
started_wash: "{label}\u2026",
|
|
335
|
+
started_drink: "{label}\u2026",
|
|
336
|
+
done_wash: "Washed and rinsed",
|
|
337
|
+
done_wash_dishes: "Dishes washed: {n} on the rack",
|
|
338
|
+
done_drink: "You drank {litres} l of water"
|
|
280
339
|
},
|
|
281
340
|
"pt-BR": {
|
|
282
341
|
"prompt.open": "Abrir {name}",
|
|
@@ -329,7 +388,19 @@ var GameInteractables = (() => {
|
|
|
329
388
|
done_program_stop: "{name} parou",
|
|
330
389
|
done_relieve_urine: "Voc\xEA fez xixi em {name}",
|
|
331
390
|
done_relieve_feces: "Voc\xEA fez coc\xF4 em {name}",
|
|
332
|
-
done_clean: "Descarga dada: {name} limpo"
|
|
391
|
+
done_clean: "Descarga dada: {name} limpo",
|
|
392
|
+
"use.wash_dishes": "Lavar a lou\xE7a",
|
|
393
|
+
"use.drink_water": "Beber \xE1gua",
|
|
394
|
+
busy: "J\xE1 est\xE1 em uso",
|
|
395
|
+
needs_running: "Abra a \xE1gua primeiro",
|
|
396
|
+
needs_item: "Precisa de {need}",
|
|
397
|
+
item_spent: "{item} acabou",
|
|
398
|
+
no_dirty_dishes: "N\xE3o h\xE1 lou\xE7a suja na pia",
|
|
399
|
+
started_wash: "{label}\u2026",
|
|
400
|
+
started_drink: "{label}\u2026",
|
|
401
|
+
done_wash: "Lavado e enxaguado",
|
|
402
|
+
done_wash_dishes: "Lou\xE7a lavada: {n} no escorredor",
|
|
403
|
+
done_drink: "Voc\xEA bebeu {litres} l de \xE1gua"
|
|
333
404
|
}
|
|
334
405
|
};
|
|
335
406
|
function pickLocale(locale) {
|
|
@@ -1358,6 +1429,7 @@ var GameInteractables = (() => {
|
|
|
1358
1429
|
id,
|
|
1359
1430
|
object: o.id,
|
|
1360
1431
|
kind: i.action.do,
|
|
1432
|
+
...GESTURE_OF_ACTION[i.action.do] ? { gesture: GESTURE_OF_ACTION[i.action.do] } : {},
|
|
1361
1433
|
pos: toWorld(o, i.pos),
|
|
1362
1434
|
radius: i.radius ?? DEFAULT_RADIUS,
|
|
1363
1435
|
label: p.label,
|
|
@@ -2490,6 +2562,29 @@ var GameInteractables = (() => {
|
|
|
2490
2562
|
return runs;
|
|
2491
2563
|
}
|
|
2492
2564
|
|
|
2565
|
+
// src/cast-with-member.ts
|
|
2566
|
+
var COLLAR_REACH = 0.03;
|
|
2567
|
+
var END_GAP = 5e-3;
|
|
2568
|
+
function centredOn(member, other) {
|
|
2569
|
+
for (const k of [0, 2]) {
|
|
2570
|
+
if (other[k] < member[k] - COLLAR_REACH || other[k + 3] > member[k + 3] + COLLAR_REACH) return false;
|
|
2571
|
+
if (Math.abs((other[k] + other[k + 3]) / 2 - (member[k] + member[k + 3]) / 2) > COLLAR_REACH) return false;
|
|
2572
|
+
}
|
|
2573
|
+
return true;
|
|
2574
|
+
}
|
|
2575
|
+
function wrapsMember(member, collar) {
|
|
2576
|
+
const overlap2 = Math.min(collar[4], member[4]) - Math.max(collar[1], member[1]);
|
|
2577
|
+
return overlap2 >= (collar[4] - collar[1]) / 2 && centredOn(member, collar);
|
|
2578
|
+
}
|
|
2579
|
+
function endsMember(member, end) {
|
|
2580
|
+
const under = Math.abs(end[4] - member[1]) <= END_GAP;
|
|
2581
|
+
const over = Math.abs(end[1] - member[4]) <= END_GAP;
|
|
2582
|
+
return (under || over) && end[4] - end[1] <= member[4] - member[1] && centredOn(member, end);
|
|
2583
|
+
}
|
|
2584
|
+
function castWithMember(member, other) {
|
|
2585
|
+
return wrapsMember(member, other) || endsMember(member, other);
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2493
2588
|
// src/fits-volume.ts
|
|
2494
2589
|
function fitsInVolume(size, half) {
|
|
2495
2590
|
const thing = [...size].sort((a, b) => b - a);
|
|
@@ -2497,7 +2592,192 @@ var GameInteractables = (() => {
|
|
|
2497
2592
|
return thing.every((side, i) => side <= (room[i] ?? 0));
|
|
2498
2593
|
}
|
|
2499
2594
|
|
|
2595
|
+
// src/sink-uses.ts
|
|
2596
|
+
var WASH_SCRUB_SECONDS = 3;
|
|
2597
|
+
var DRINK_LITRES = 0.25;
|
|
2598
|
+
var FILL_SHARE = 0.85;
|
|
2599
|
+
var DRINK_LPS = 0.06;
|
|
2600
|
+
var REACH_SECONDS = 0.6;
|
|
2601
|
+
var DRY_SECONDS = 0.5;
|
|
2602
|
+
var SCRUBBED_DIRT = 0.15;
|
|
2603
|
+
var YES = { available: true };
|
|
2604
|
+
var idsOf = (need) => typeof need === "string" ? [need] : need;
|
|
2605
|
+
function findNeeds(needs, host) {
|
|
2606
|
+
const items = [];
|
|
2607
|
+
for (const need of needs) {
|
|
2608
|
+
const item = host.itemAt?.(idsOf(need)) ?? null;
|
|
2609
|
+
if (!item) return { items, missing: idsOf(need) };
|
|
2610
|
+
items.push(item);
|
|
2611
|
+
}
|
|
2612
|
+
return { items };
|
|
2613
|
+
}
|
|
2614
|
+
function dirtyDishes(use, spec, host) {
|
|
2615
|
+
const dishes = use.dishes;
|
|
2616
|
+
const basin = dishes ? (spec.basins ?? []).find((b) => b.id === dishes.basin) : void 0;
|
|
2617
|
+
if (!dishes || !basin) return [];
|
|
2618
|
+
return (host.itemsInside?.(dishes.ids, basin.from, basin.to) ?? []).filter((item) => (item.dirt ?? 0) > 0);
|
|
2619
|
+
}
|
|
2620
|
+
function sinkVerdict(use, spec, host, flowing) {
|
|
2621
|
+
if (use.do === "wash" && use.requiresFlowing && !flowing) return { available: false, reason: "needs_running" };
|
|
2622
|
+
const found = findNeeds(use.needs ?? [], host);
|
|
2623
|
+
if (found.missing) return { available: false, reason: "needs_item", vars: { need: found.missing[0] ?? "" } };
|
|
2624
|
+
if (use.do === "drink") return YES;
|
|
2625
|
+
const dosed = use.dose ? found.items[use.dose.need] : void 0;
|
|
2626
|
+
if (dosed && (dosed.remaining ?? 1) <= 0) return { available: false, reason: "item_spent", vars: { item: dosed.name } };
|
|
2627
|
+
if (use.dishes && dirtyDishes(use, spec, host).length === 0) return { available: false, reason: "no_dirty_dishes" };
|
|
2628
|
+
return YES;
|
|
2629
|
+
}
|
|
2630
|
+
var fixtureFlowLps = (fixture) => fixture ? (fixture.flow ?? FLOW_DEFAULTS[fixture.kind] ?? 6) / 60 : 0;
|
|
2631
|
+
function runPhases(phases) {
|
|
2632
|
+
let index = 0;
|
|
2633
|
+
return (dt) => {
|
|
2634
|
+
if (index < phases.length && phases[index]?.(dt)) index++;
|
|
2635
|
+
return index >= phases.length;
|
|
2636
|
+
};
|
|
2637
|
+
}
|
|
2638
|
+
function wait(seconds) {
|
|
2639
|
+
let left = seconds;
|
|
2640
|
+
return (dt) => (left -= dt) <= 0;
|
|
2641
|
+
}
|
|
2642
|
+
function placePhase(host, item, spot) {
|
|
2643
|
+
return () => {
|
|
2644
|
+
if (spot) host.placeItem?.(item.objectId, [spot[0], spot[1], spot[2]]);
|
|
2645
|
+
return true;
|
|
2646
|
+
};
|
|
2647
|
+
}
|
|
2648
|
+
function createSinkRoutines(options) {
|
|
2649
|
+
const { spec, world, objectId } = options;
|
|
2650
|
+
const fixtureOf = (id) => (spec.fixtures ?? []).find((f) => f.id === id);
|
|
2651
|
+
const flowing = (use) => world.water.isFlowing(objectId, use.fixture);
|
|
2652
|
+
const water = (use) => flowing(use) ? fixtureFlowLps(fixtureOf(use.fixture)) : 0;
|
|
2653
|
+
const waterOf = (use) => {
|
|
2654
|
+
let dry = 0;
|
|
2655
|
+
return (dt) => {
|
|
2656
|
+
const flow = water(use);
|
|
2657
|
+
dry = flow > 0 ? 0 : dry + dt;
|
|
2658
|
+
return dry > DRY_SECONDS ? null : flow;
|
|
2659
|
+
};
|
|
2660
|
+
};
|
|
2661
|
+
const tapPhases = (use) => {
|
|
2662
|
+
let opened = false;
|
|
2663
|
+
const reach = wait(REACH_SECONDS);
|
|
2664
|
+
return {
|
|
2665
|
+
open: (dt) => {
|
|
2666
|
+
if (opened || use.opensFixture === false || flowing(use)) return true;
|
|
2667
|
+
if (!reach(dt)) return false;
|
|
2668
|
+
opened = world.setFixture(objectId, use.fixture, true);
|
|
2669
|
+
return true;
|
|
2670
|
+
},
|
|
2671
|
+
close: () => {
|
|
2672
|
+
if (opened) world.setFixture(objectId, use.fixture, false);
|
|
2673
|
+
return true;
|
|
2674
|
+
}
|
|
2675
|
+
};
|
|
2676
|
+
};
|
|
2677
|
+
const scrubAndRinse = (use, host, target, fail) => {
|
|
2678
|
+
const item = typeof target === "string" ? void 0 : target;
|
|
2679
|
+
const id = item?.objectId ?? target;
|
|
2680
|
+
const seconds = use.scrubSeconds ?? WASH_SCRUB_SECONDS;
|
|
2681
|
+
const dirt = item?.dirt ?? 0;
|
|
2682
|
+
let scrubbed = -1;
|
|
2683
|
+
const scrub = (dt) => {
|
|
2684
|
+
if (scrubbed < 0) {
|
|
2685
|
+
scrubbed = 0;
|
|
2686
|
+
host.playUse?.(use.clip, item?.objectId);
|
|
2687
|
+
}
|
|
2688
|
+
scrubbed = Math.min(seconds, scrubbed + dt);
|
|
2689
|
+
host.lather?.(id, dt / seconds);
|
|
2690
|
+
if (dirt > 0) host.setDirt?.(id, dirt - (dirt - Math.min(dirt, SCRUBBED_DIRT)) * (scrubbed / seconds));
|
|
2691
|
+
return scrubbed >= seconds;
|
|
2692
|
+
};
|
|
2693
|
+
const running = waterOf(use);
|
|
2694
|
+
const rinse = (dt) => {
|
|
2695
|
+
const flow = running(dt);
|
|
2696
|
+
if (flow === null) {
|
|
2697
|
+
fail({ key: "no_water", ok: false });
|
|
2698
|
+
return true;
|
|
2699
|
+
}
|
|
2700
|
+
if (flow <= 0 || (host.rinse?.(id, flow, dt) ?? 0) > 0) return false;
|
|
2701
|
+
if (dirt > 0) host.setDirt?.(id, 0);
|
|
2702
|
+
return true;
|
|
2703
|
+
};
|
|
2704
|
+
return [scrub, rinse];
|
|
2705
|
+
};
|
|
2706
|
+
const startWash = (use, host) => {
|
|
2707
|
+
const { items } = findNeeds(use.needs ?? [], host);
|
|
2708
|
+
let end = null;
|
|
2709
|
+
const fail = (reason) => {
|
|
2710
|
+
end ?? (end = reason);
|
|
2711
|
+
};
|
|
2712
|
+
const tap = tapPhases(use);
|
|
2713
|
+
const dosed = use.dose ? items[use.dose.need] : void 0;
|
|
2714
|
+
const dose = () => {
|
|
2715
|
+
if (dosed && host.takeDose?.(dosed.objectId, use.dose?.amount).taken === 0) fail({ key: "item_spent", ok: false, vars: { item: dosed.name } });
|
|
2716
|
+
return true;
|
|
2717
|
+
};
|
|
2718
|
+
const dishes = use.dishes ? dirtyDishes(use, spec, host) : [];
|
|
2719
|
+
const rack = use.dishes?.rack ?? [];
|
|
2720
|
+
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);
|
|
2721
|
+
const guarded = work.map((phase) => (dt) => end !== null || phase(dt));
|
|
2722
|
+
const run = runPhases([tap.open, dose, ...guarded, tap.close]);
|
|
2723
|
+
const done = use.dishes ? { key: "done_wash_dishes", ok: true, vars: { n: String(dishes.length) } } : { key: "done_wash", ok: true, vars: { surface: use.surface } };
|
|
2724
|
+
return { use: use.id, step: (dt) => run(dt) ? end ?? done : null };
|
|
2725
|
+
};
|
|
2726
|
+
const startDrink = (use, host, vessel) => {
|
|
2727
|
+
const tap = tapPhases(use);
|
|
2728
|
+
const want = Math.min(use.litres ?? DRINK_LITRES, (vessel.liquid?.capacity ?? DRINK_LITRES) * FILL_SHARE);
|
|
2729
|
+
let filled = vessel.liquid?.kind === "water" ? vessel.liquid.litres : 0;
|
|
2730
|
+
let drunk = 0;
|
|
2731
|
+
let end = null;
|
|
2732
|
+
const take = () => {
|
|
2733
|
+
if (vessel.where !== "hand" && host.holdItem?.(vessel.objectId) === false) end = { key: "needs_item", ok: false, vars: { need: vessel.itemId } };
|
|
2734
|
+
else host.playUse?.(use.fillClip ?? "fill_cup", vessel.objectId);
|
|
2735
|
+
return true;
|
|
2736
|
+
};
|
|
2737
|
+
const running = waterOf(use);
|
|
2738
|
+
const fill = (dt) => {
|
|
2739
|
+
if (end) return true;
|
|
2740
|
+
const flow = running(dt);
|
|
2741
|
+
if (flow === null) {
|
|
2742
|
+
end = { key: "no_water", ok: false };
|
|
2743
|
+
return true;
|
|
2744
|
+
}
|
|
2745
|
+
if (flow <= 0) return false;
|
|
2746
|
+
const took = host.fillItem?.(vessel.objectId, "water", Math.min(flow * dt, want - filled)) ?? 0;
|
|
2747
|
+
filled += took;
|
|
2748
|
+
return filled >= want - 1e-6 || took <= 0;
|
|
2749
|
+
};
|
|
2750
|
+
let sipping = false;
|
|
2751
|
+
const drink = (dt) => {
|
|
2752
|
+
if (end) return true;
|
|
2753
|
+
if (!sipping) sipping = host.playUse?.(use.clip, vessel.objectId) ?? true;
|
|
2754
|
+
const sip = host.drinkItem?.(vessel.objectId, Math.min(DRINK_LPS * dt, filled - drunk)) ?? 0;
|
|
2755
|
+
drunk += sip;
|
|
2756
|
+
return drunk >= filled - 1e-6 || sip <= 0;
|
|
2757
|
+
};
|
|
2758
|
+
const giveBack = vessel.where === "reach" ? placePhase(host, vessel, vessel.at) : () => true;
|
|
2759
|
+
const run = runPhases([take, tap.open, fill, tap.close, drink, wait(REACH_SECONDS), giveBack]);
|
|
2760
|
+
return { use: use.id, step: (dt) => run(dt) ? end ?? { key: "done_drink", ok: true, vars: { litres: drunk.toFixed(2) } } : null };
|
|
2761
|
+
};
|
|
2762
|
+
return {
|
|
2763
|
+
start(use, host) {
|
|
2764
|
+
if (use.do === "wash") return startWash(use, host);
|
|
2765
|
+
const vessel = findNeeds(use.needs, host).items[0];
|
|
2766
|
+
if (!vessel) return { use: use.id, step: () => ({ key: "needs_item", ok: false, vars: { need: idsOf(use.needs[0] ?? "")[0] ?? "" } }) };
|
|
2767
|
+
return startDrink(use, host, vessel);
|
|
2768
|
+
}
|
|
2769
|
+
};
|
|
2770
|
+
}
|
|
2771
|
+
|
|
2500
2772
|
// src/object-uses.ts
|
|
2773
|
+
function devicePointOf(spec, device) {
|
|
2774
|
+
const own = (spec.interactions ?? []).find((i) => i.action.do === "toggle_device" && i.action.device === device);
|
|
2775
|
+
if (own) return own.pos;
|
|
2776
|
+
const def = (spec.devices ?? []).find((d) => d.id === device);
|
|
2777
|
+
if (!def) return void 0;
|
|
2778
|
+
const part = def.part ? spec.parts?.find((p) => p.id === def.part)?.pivot : void 0;
|
|
2779
|
+
return part ?? def.plug ?? [0, 1, 0];
|
|
2780
|
+
}
|
|
2501
2781
|
var OPEN = 0.5;
|
|
2502
2782
|
var PREFIX = "use.";
|
|
2503
2783
|
var SOIL_RANK = { clean: 0, urine: 1, feces: 2 };
|
|
@@ -2506,7 +2786,7 @@ var GameInteractables = (() => {
|
|
|
2506
2786
|
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
|
|
2507
2787
|
};
|
|
2508
2788
|
var accepts = (bowl, hand) => (bowl.accepts ?? []).some((id) => hand.itemId === id || hand.itemId.endsWith(`_${id}`));
|
|
2509
|
-
var
|
|
2789
|
+
var YES2 = { available: true };
|
|
2510
2790
|
var no = (reason) => ({ available: false, reason });
|
|
2511
2791
|
function createUses(options) {
|
|
2512
2792
|
const { spec, world, objectId } = options;
|
|
@@ -2518,6 +2798,8 @@ var GameInteractables = (() => {
|
|
|
2518
2798
|
const cleans = new Map((spec.fixtures ?? []).flatMap((f) => f.cleans ? [[f.id, f.cleans]] : []));
|
|
2519
2799
|
let program = null;
|
|
2520
2800
|
let lastHost = null;
|
|
2801
|
+
const sinkRoutines = createSinkRoutines({ spec, world, objectId });
|
|
2802
|
+
let routine = null;
|
|
2521
2803
|
const typeKey = `type.${spec.type}`;
|
|
2522
2804
|
const name = () => {
|
|
2523
2805
|
const text = world.t(typeKey);
|
|
@@ -2529,15 +2811,15 @@ var GameInteractables = (() => {
|
|
|
2529
2811
|
switch (use.do) {
|
|
2530
2812
|
case "program":
|
|
2531
2813
|
if (!world.power.isPowered(objectId, use.device)) return no("no_power");
|
|
2532
|
-
return use.access && host.partOpening(use.access) >= OPEN ? no("needs_closed") :
|
|
2814
|
+
return use.access && host.partOpening(use.access) >= OPEN ? no("needs_closed") : YES2;
|
|
2533
2815
|
case "put_in": {
|
|
2534
2816
|
const c = containers.get(use.container);
|
|
2535
2817
|
if (!hand) return no("hand_empty");
|
|
2536
2818
|
if (!c || !accessOpen(host, c.access)) return no("requires_open");
|
|
2537
|
-
return fitsInVolume(hand.size, c.volume.half) ?
|
|
2819
|
+
return fitsInVolume(hand.size, c.volume.half) ? YES2 : no("not_fit");
|
|
2538
2820
|
}
|
|
2539
2821
|
case "empty":
|
|
2540
|
-
return accessOpen(host, containers.get(use.container)?.access) ?
|
|
2822
|
+
return accessOpen(host, containers.get(use.container)?.access) ? YES2 : no("requires_open");
|
|
2541
2823
|
case "fill": {
|
|
2542
2824
|
const bowl = bowls.get(use.bowl);
|
|
2543
2825
|
if (!bowl) return no("empty");
|
|
@@ -2545,12 +2827,23 @@ var GameInteractables = (() => {
|
|
|
2545
2827
|
if (!hand) return no("hand_empty");
|
|
2546
2828
|
if (bowl.holds === "water" && hand.liquid?.kind === "water" && hand.liquid.closed) return no("requires_open");
|
|
2547
2829
|
const fits = bowl.holds === "water" ? hand.liquid?.kind === "water" && hand.liquid.litres > 0 : accepts(bowl, hand);
|
|
2548
|
-
return fits ?
|
|
2830
|
+
return fits ? YES2 : no("not_accepted");
|
|
2549
2831
|
}
|
|
2550
2832
|
case "relieve":
|
|
2551
|
-
return
|
|
2833
|
+
return YES2;
|
|
2834
|
+
case "wash":
|
|
2835
|
+
case "drink":
|
|
2836
|
+
return routine ? no("busy") : sinkVerdict(use, spec, host, world.water.isFlowing(objectId, use.fixture));
|
|
2552
2837
|
}
|
|
2553
2838
|
};
|
|
2839
|
+
const itemName = (id) => {
|
|
2840
|
+
const text = world.t(`item.${id}`);
|
|
2841
|
+
return text === `item.${id}` ? id.replace(/_/g, " ") : text;
|
|
2842
|
+
};
|
|
2843
|
+
const reasonOf = (v, use, host) => {
|
|
2844
|
+
const words = { ...textVars(use, host), ...v.vars };
|
|
2845
|
+
return world.t(v.reason, words.need ? { ...words, need: itemName(words.need) } : words);
|
|
2846
|
+
};
|
|
2554
2847
|
const textVars = (use, host) => ({
|
|
2555
2848
|
name: name(),
|
|
2556
2849
|
item: host.hand()?.name ?? "",
|
|
@@ -2583,6 +2876,10 @@ var GameInteractables = (() => {
|
|
|
2583
2876
|
soil.set(use.basin, SOIL_RANK[use.kind] > SOIL_RANK[now] ? use.kind : now);
|
|
2584
2877
|
return { ok: true, text: world.t(`done_relieve_${use.kind}`, vars) };
|
|
2585
2878
|
}
|
|
2879
|
+
case "wash":
|
|
2880
|
+
case "drink":
|
|
2881
|
+
routine = sinkRoutines.start(use, host);
|
|
2882
|
+
return { ok: true, text: world.t(`started_${use.do}`, { ...vars, label: world.t(use.label, vars) }) };
|
|
2586
2883
|
}
|
|
2587
2884
|
};
|
|
2588
2885
|
const fill = (bowl, host, vars) => {
|
|
@@ -2597,6 +2894,19 @@ var GameInteractables = (() => {
|
|
|
2597
2894
|
program = null;
|
|
2598
2895
|
return world.t("done_program_stop", { name: name() });
|
|
2599
2896
|
};
|
|
2897
|
+
const stepRoutine = (dt) => {
|
|
2898
|
+
const end = routine?.step(dt);
|
|
2899
|
+
if (!end) return;
|
|
2900
|
+
routine = null;
|
|
2901
|
+
const words = end.vars?.need ? { ...end.vars, need: itemName(end.vars.need) } : end.vars;
|
|
2902
|
+
lastHost?.say(world.t(end.key, { name: name(), ...words }));
|
|
2903
|
+
};
|
|
2904
|
+
const gestureOf = (use) => {
|
|
2905
|
+
const gesture = GESTURE_OF_USE[use.do];
|
|
2906
|
+
if (!gesture) return null;
|
|
2907
|
+
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;
|
|
2908
|
+
return at ? { gesture, at: [at[0], at[1], at[2]] } : null;
|
|
2909
|
+
};
|
|
2600
2910
|
const visible = (use) => use.do !== "program" || program === null;
|
|
2601
2911
|
return {
|
|
2602
2912
|
has: (id) => id.startsWith(PREFIX),
|
|
@@ -2606,7 +2916,8 @@ var GameInteractables = (() => {
|
|
|
2606
2916
|
if (program) entries.push({ id: `${PREFIX}stop`, label: world.t("use.program.stop", { name: name(), left: clock(program.left) }), available: true });
|
|
2607
2917
|
for (const use of all.filter(visible)) {
|
|
2608
2918
|
const v = verdict(use, host);
|
|
2609
|
-
|
|
2919
|
+
const body = gestureOf(use);
|
|
2920
|
+
entries.push({ id: `${PREFIX}${use.id}`, label: labelOf(use, host), available: v.available, ...v.available ? {} : { reason: reasonOf(v, use, host) }, ...body ?? {} });
|
|
2610
2921
|
}
|
|
2611
2922
|
return entries;
|
|
2612
2923
|
},
|
|
@@ -2616,9 +2927,10 @@ var GameInteractables = (() => {
|
|
|
2616
2927
|
const use = all.find((u) => `${PREFIX}${u.id}` === id);
|
|
2617
2928
|
if (!use || !visible(use)) return { ok: false, text: "" };
|
|
2618
2929
|
const v = verdict(use, host);
|
|
2619
|
-
return v.available ? runUse(use, host) : { ok: false, text:
|
|
2930
|
+
return v.available ? runUse(use, host) : { ok: false, text: reasonOf(v, use, host) };
|
|
2620
2931
|
},
|
|
2621
2932
|
update(dt) {
|
|
2933
|
+
stepRoutine(dt);
|
|
2622
2934
|
if (!program) return;
|
|
2623
2935
|
program.left -= dt;
|
|
2624
2936
|
if (program.left > 0) return;
|
|
@@ -2636,7 +2948,8 @@ var GameInteractables = (() => {
|
|
|
2636
2948
|
state: () => ({
|
|
2637
2949
|
bowls: Object.fromEntries(level),
|
|
2638
2950
|
soil: Object.fromEntries(soil),
|
|
2639
|
-
program: program ? { use: program.use.id, device: program.use.device, left: program.left } : null
|
|
2951
|
+
program: program ? { use: program.use.id, device: program.use.device, left: program.left } : null,
|
|
2952
|
+
routine: routine?.use ?? null
|
|
2640
2953
|
})
|
|
2641
2954
|
};
|
|
2642
2955
|
}
|
|
@@ -2647,9 +2960,9 @@ var GameInteractables = (() => {
|
|
|
2647
2960
|
var MAINS_TANK = "water";
|
|
2648
2961
|
var HOST_KINDS = /* @__PURE__ */ new Set(["toggle_part", "open_container", "take", "read", "sit", "toggle_breaker"]);
|
|
2649
2962
|
var PLUG_FALLBACK = [0, 0.3, 0];
|
|
2650
|
-
function mainsSpec(spec) {
|
|
2963
|
+
function mainsSpec(spec, water) {
|
|
2651
2964
|
const plugged = (spec.devices ?? []).filter((d) => d.socket !== void 0 && !d.circuit);
|
|
2652
|
-
return { type: MAINS, sockets: plugged.map((d, i) => ({ id: `socket_${i}`, pos: d.plug ?? PLUG_FALLBACK })), tanks: [{ id: MAINS_TANK, capacity: 1e9 }] };
|
|
2965
|
+
return { type: MAINS, sockets: plugged.map((d, i) => ({ id: `socket_${i}`, pos: d.plug ?? PLUG_FALLBACK })), tanks: water ? [{ id: MAINS_TANK, capacity: 1e9 }] : [] };
|
|
2653
2966
|
}
|
|
2654
2967
|
function createObjectControls(options) {
|
|
2655
2968
|
const { spec } = options;
|
|
@@ -2672,8 +2985,9 @@ var GameInteractables = (() => {
|
|
|
2672
2985
|
forwarded.set(part, open);
|
|
2673
2986
|
host?.setPart(part, open);
|
|
2674
2987
|
};
|
|
2675
|
-
|
|
2676
|
-
|
|
2988
|
+
const piped = options.mains?.water ?? true;
|
|
2989
|
+
world.add(MAINS, mainsSpec(spec, piped), { x: 0, y: 0, z: 0, ry: 0 });
|
|
2990
|
+
if (piped) world.water.setDefaultTank(`${MAINS}:${MAINS_TANK}`);
|
|
2677
2991
|
world.add(CONTROLLED_OBJECT, spec, { x: 0, y: 0, z: 0, ry: 0 });
|
|
2678
2992
|
const uses = createUses({ spec, world, objectId: CONTROLLED_OBJECT });
|
|
2679
2993
|
const programmedDevices = new Set((spec.uses ?? []).flatMap((u) => u.do === "program" ? [u.device] : []));
|
|
@@ -2690,7 +3004,10 @@ var GameInteractables = (() => {
|
|
|
2690
3004
|
return {
|
|
2691
3005
|
list(lent) {
|
|
2692
3006
|
lend(lent);
|
|
2693
|
-
const fromWorld = interactions().map((i) =>
|
|
3007
|
+
const fromWorld = interactions().map((i) => {
|
|
3008
|
+
const gesture = i.gesture;
|
|
3009
|
+
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]] } : {} };
|
|
3010
|
+
});
|
|
2694
3011
|
return [...fromWorld, ...uses.list(lent)];
|
|
2695
3012
|
},
|
|
2696
3013
|
run(id, lent) {
|