@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.js
CHANGED
|
@@ -220,7 +220,19 @@ var locales = {
|
|
|
220
220
|
done_program_stop: "{name} stopped",
|
|
221
221
|
done_relieve_urine: "You peed in {name}",
|
|
222
222
|
done_relieve_feces: "You pooed in {name}",
|
|
223
|
-
done_clean: "{name} flushed clean"
|
|
223
|
+
done_clean: "{name} flushed clean",
|
|
224
|
+
"use.wash_dishes": "Wash the dishes",
|
|
225
|
+
"use.drink_water": "Drink water",
|
|
226
|
+
busy: "Already in use",
|
|
227
|
+
needs_running: "Turn the water on first",
|
|
228
|
+
needs_item: "You need {need}",
|
|
229
|
+
item_spent: "{item} is empty",
|
|
230
|
+
no_dirty_dishes: "No dirty dishes in the sink",
|
|
231
|
+
started_wash: "{label}\u2026",
|
|
232
|
+
started_drink: "{label}\u2026",
|
|
233
|
+
done_wash: "Washed and rinsed",
|
|
234
|
+
done_wash_dishes: "Dishes washed: {n} on the rack",
|
|
235
|
+
done_drink: "You drank {litres} l of water"
|
|
224
236
|
},
|
|
225
237
|
"pt-BR": {
|
|
226
238
|
"prompt.open": "Abrir {name}",
|
|
@@ -273,7 +285,19 @@ var locales = {
|
|
|
273
285
|
done_program_stop: "{name} parou",
|
|
274
286
|
done_relieve_urine: "Voc\xEA fez xixi em {name}",
|
|
275
287
|
done_relieve_feces: "Voc\xEA fez coc\xF4 em {name}",
|
|
276
|
-
done_clean: "Descarga dada: {name} limpo"
|
|
288
|
+
done_clean: "Descarga dada: {name} limpo",
|
|
289
|
+
"use.wash_dishes": "Lavar a lou\xE7a",
|
|
290
|
+
"use.drink_water": "Beber \xE1gua",
|
|
291
|
+
busy: "J\xE1 est\xE1 em uso",
|
|
292
|
+
needs_running: "Abra a \xE1gua primeiro",
|
|
293
|
+
needs_item: "Precisa de {need}",
|
|
294
|
+
item_spent: "{item} acabou",
|
|
295
|
+
no_dirty_dishes: "N\xE3o h\xE1 lou\xE7a suja na pia",
|
|
296
|
+
started_wash: "{label}\u2026",
|
|
297
|
+
started_drink: "{label}\u2026",
|
|
298
|
+
done_wash: "Lavado e enxaguado",
|
|
299
|
+
done_wash_dishes: "Lou\xE7a lavada: {n} no escorredor",
|
|
300
|
+
done_drink: "Voc\xEA bebeu {litres} l de \xE1gua"
|
|
277
301
|
}
|
|
278
302
|
};
|
|
279
303
|
function pickLocale(locale) {
|
|
@@ -2402,6 +2426,61 @@ function hangTail(params) {
|
|
|
2402
2426
|
});
|
|
2403
2427
|
}
|
|
2404
2428
|
|
|
2429
|
+
// src/wire-runs.ts
|
|
2430
|
+
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];
|
|
2431
|
+
function along(points, step) {
|
|
2432
|
+
const out = points.length ? [[...points[0]]] : [];
|
|
2433
|
+
for (let i = 1; i < points.length; i++) {
|
|
2434
|
+
const a = points[i - 1];
|
|
2435
|
+
const b = points[i];
|
|
2436
|
+
const steps = Math.max(1, Math.ceil(Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]) / step));
|
|
2437
|
+
for (let k = 1; k <= steps; k++) out.push(lerp(a, b, k / steps));
|
|
2438
|
+
}
|
|
2439
|
+
return out;
|
|
2440
|
+
}
|
|
2441
|
+
function wireRuns(params) {
|
|
2442
|
+
const points = along(params.points, Math.max(1e-3, params.step));
|
|
2443
|
+
if (points.length < 2) return [];
|
|
2444
|
+
const holders = points.map((p) => params.holderOf(p));
|
|
2445
|
+
const runs = [];
|
|
2446
|
+
let current = { holder: holders[0], points: [points[0]] };
|
|
2447
|
+
for (let i = 1; i < points.length; i++) {
|
|
2448
|
+
if (holders[i] === current.holder) {
|
|
2449
|
+
current.points.push(points[i]);
|
|
2450
|
+
continue;
|
|
2451
|
+
}
|
|
2452
|
+
const seam = lerp(points[i - 1], points[i], 0.5);
|
|
2453
|
+
current.points.push(seam);
|
|
2454
|
+
runs.push(current);
|
|
2455
|
+
current = { holder: holders[i], points: [[...seam], points[i]] };
|
|
2456
|
+
}
|
|
2457
|
+
runs.push(current);
|
|
2458
|
+
return runs;
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
// src/cast-with-member.ts
|
|
2462
|
+
var COLLAR_REACH = 0.03;
|
|
2463
|
+
var END_GAP = 5e-3;
|
|
2464
|
+
function centredOn(member, other) {
|
|
2465
|
+
for (const k of [0, 2]) {
|
|
2466
|
+
if (other[k] < member[k] - COLLAR_REACH || other[k + 3] > member[k + 3] + COLLAR_REACH) return false;
|
|
2467
|
+
if (Math.abs((other[k] + other[k + 3]) / 2 - (member[k] + member[k + 3]) / 2) > COLLAR_REACH) return false;
|
|
2468
|
+
}
|
|
2469
|
+
return true;
|
|
2470
|
+
}
|
|
2471
|
+
function wrapsMember(member, collar) {
|
|
2472
|
+
const overlap2 = Math.min(collar[4], member[4]) - Math.max(collar[1], member[1]);
|
|
2473
|
+
return overlap2 >= (collar[4] - collar[1]) / 2 && centredOn(member, collar);
|
|
2474
|
+
}
|
|
2475
|
+
function endsMember(member, end) {
|
|
2476
|
+
const under = Math.abs(end[4] - member[1]) <= END_GAP;
|
|
2477
|
+
const over = Math.abs(end[1] - member[4]) <= END_GAP;
|
|
2478
|
+
return (under || over) && end[4] - end[1] <= member[4] - member[1] && centredOn(member, end);
|
|
2479
|
+
}
|
|
2480
|
+
function castWithMember(member, other) {
|
|
2481
|
+
return wrapsMember(member, other) || endsMember(member, other);
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2405
2484
|
// src/fits-volume.ts
|
|
2406
2485
|
function fitsInVolume(size, half) {
|
|
2407
2486
|
const thing = [...size].sort((a, b) => b - a);
|
|
@@ -2409,6 +2488,183 @@ function fitsInVolume(size, half) {
|
|
|
2409
2488
|
return thing.every((side, i) => side <= (room[i] ?? 0));
|
|
2410
2489
|
}
|
|
2411
2490
|
|
|
2491
|
+
// src/sink-uses.ts
|
|
2492
|
+
var WASH_SCRUB_SECONDS = 3;
|
|
2493
|
+
var DRINK_LITRES = 0.25;
|
|
2494
|
+
var FILL_SHARE = 0.85;
|
|
2495
|
+
var DRINK_LPS = 0.06;
|
|
2496
|
+
var REACH_SECONDS = 0.6;
|
|
2497
|
+
var DRY_SECONDS = 0.5;
|
|
2498
|
+
var SCRUBBED_DIRT = 0.15;
|
|
2499
|
+
var YES = { available: true };
|
|
2500
|
+
var idsOf = (need) => typeof need === "string" ? [need] : need;
|
|
2501
|
+
function findNeeds(needs, host) {
|
|
2502
|
+
const items = [];
|
|
2503
|
+
for (const need of needs) {
|
|
2504
|
+
const item = host.itemAt?.(idsOf(need)) ?? null;
|
|
2505
|
+
if (!item) return { items, missing: idsOf(need) };
|
|
2506
|
+
items.push(item);
|
|
2507
|
+
}
|
|
2508
|
+
return { items };
|
|
2509
|
+
}
|
|
2510
|
+
function dirtyDishes(use, spec, host) {
|
|
2511
|
+
const dishes = use.dishes;
|
|
2512
|
+
const basin = dishes ? (spec.basins ?? []).find((b) => b.id === dishes.basin) : void 0;
|
|
2513
|
+
if (!dishes || !basin) return [];
|
|
2514
|
+
return (host.itemsInside?.(dishes.ids, basin.from, basin.to) ?? []).filter((item) => (item.dirt ?? 0) > 0);
|
|
2515
|
+
}
|
|
2516
|
+
function sinkVerdict(use, spec, host, flowing) {
|
|
2517
|
+
if (use.do === "wash" && use.requiresFlowing && !flowing) return { available: false, reason: "needs_running" };
|
|
2518
|
+
const found = findNeeds(use.needs ?? [], host);
|
|
2519
|
+
if (found.missing) return { available: false, reason: "needs_item", vars: { need: found.missing[0] ?? "" } };
|
|
2520
|
+
if (use.do === "drink") return YES;
|
|
2521
|
+
const dosed = use.dose ? found.items[use.dose.need] : void 0;
|
|
2522
|
+
if (dosed && (dosed.remaining ?? 1) <= 0) return { available: false, reason: "item_spent", vars: { item: dosed.name } };
|
|
2523
|
+
if (use.dishes && dirtyDishes(use, spec, host).length === 0) return { available: false, reason: "no_dirty_dishes" };
|
|
2524
|
+
return YES;
|
|
2525
|
+
}
|
|
2526
|
+
var fixtureFlowLps = (fixture) => fixture ? (fixture.flow ?? FLOW_DEFAULTS[fixture.kind] ?? 6) / 60 : 0;
|
|
2527
|
+
function runPhases(phases) {
|
|
2528
|
+
let index = 0;
|
|
2529
|
+
return (dt) => {
|
|
2530
|
+
if (index < phases.length && phases[index]?.(dt)) index++;
|
|
2531
|
+
return index >= phases.length;
|
|
2532
|
+
};
|
|
2533
|
+
}
|
|
2534
|
+
function wait(seconds) {
|
|
2535
|
+
let left = seconds;
|
|
2536
|
+
return (dt) => (left -= dt) <= 0;
|
|
2537
|
+
}
|
|
2538
|
+
function placePhase(host, item, spot) {
|
|
2539
|
+
return () => {
|
|
2540
|
+
if (spot) host.placeItem?.(item.objectId, [spot[0], spot[1], spot[2]]);
|
|
2541
|
+
return true;
|
|
2542
|
+
};
|
|
2543
|
+
}
|
|
2544
|
+
function createSinkRoutines(options) {
|
|
2545
|
+
const { spec, world, objectId } = options;
|
|
2546
|
+
const fixtureOf = (id) => (spec.fixtures ?? []).find((f) => f.id === id);
|
|
2547
|
+
const flowing = (use) => world.water.isFlowing(objectId, use.fixture);
|
|
2548
|
+
const water = (use) => flowing(use) ? fixtureFlowLps(fixtureOf(use.fixture)) : 0;
|
|
2549
|
+
const waterOf = (use) => {
|
|
2550
|
+
let dry = 0;
|
|
2551
|
+
return (dt) => {
|
|
2552
|
+
const flow = water(use);
|
|
2553
|
+
dry = flow > 0 ? 0 : dry + dt;
|
|
2554
|
+
return dry > DRY_SECONDS ? null : flow;
|
|
2555
|
+
};
|
|
2556
|
+
};
|
|
2557
|
+
const tapPhases = (use) => {
|
|
2558
|
+
let opened = false;
|
|
2559
|
+
const reach = wait(REACH_SECONDS);
|
|
2560
|
+
return {
|
|
2561
|
+
open: (dt) => {
|
|
2562
|
+
if (opened || use.opensFixture === false || flowing(use)) return true;
|
|
2563
|
+
if (!reach(dt)) return false;
|
|
2564
|
+
opened = world.setFixture(objectId, use.fixture, true);
|
|
2565
|
+
return true;
|
|
2566
|
+
},
|
|
2567
|
+
close: () => {
|
|
2568
|
+
if (opened) world.setFixture(objectId, use.fixture, false);
|
|
2569
|
+
return true;
|
|
2570
|
+
}
|
|
2571
|
+
};
|
|
2572
|
+
};
|
|
2573
|
+
const scrubAndRinse = (use, host, target, fail) => {
|
|
2574
|
+
const item = typeof target === "string" ? void 0 : target;
|
|
2575
|
+
const id = item?.objectId ?? target;
|
|
2576
|
+
const seconds = use.scrubSeconds ?? WASH_SCRUB_SECONDS;
|
|
2577
|
+
const dirt = item?.dirt ?? 0;
|
|
2578
|
+
let scrubbed = -1;
|
|
2579
|
+
const scrub = (dt) => {
|
|
2580
|
+
if (scrubbed < 0) {
|
|
2581
|
+
scrubbed = 0;
|
|
2582
|
+
host.playUse?.(use.clip, item?.objectId);
|
|
2583
|
+
}
|
|
2584
|
+
scrubbed = Math.min(seconds, scrubbed + dt);
|
|
2585
|
+
host.lather?.(id, dt / seconds);
|
|
2586
|
+
if (dirt > 0) host.setDirt?.(id, dirt - (dirt - Math.min(dirt, SCRUBBED_DIRT)) * (scrubbed / seconds));
|
|
2587
|
+
return scrubbed >= seconds;
|
|
2588
|
+
};
|
|
2589
|
+
const running = waterOf(use);
|
|
2590
|
+
const rinse = (dt) => {
|
|
2591
|
+
const flow = running(dt);
|
|
2592
|
+
if (flow === null) {
|
|
2593
|
+
fail({ key: "no_water", ok: false });
|
|
2594
|
+
return true;
|
|
2595
|
+
}
|
|
2596
|
+
if (flow <= 0 || (host.rinse?.(id, flow, dt) ?? 0) > 0) return false;
|
|
2597
|
+
if (dirt > 0) host.setDirt?.(id, 0);
|
|
2598
|
+
return true;
|
|
2599
|
+
};
|
|
2600
|
+
return [scrub, rinse];
|
|
2601
|
+
};
|
|
2602
|
+
const startWash = (use, host) => {
|
|
2603
|
+
const { items } = findNeeds(use.needs ?? [], host);
|
|
2604
|
+
let end = null;
|
|
2605
|
+
const fail = (reason) => {
|
|
2606
|
+
end ?? (end = reason);
|
|
2607
|
+
};
|
|
2608
|
+
const tap = tapPhases(use);
|
|
2609
|
+
const dosed = use.dose ? items[use.dose.need] : void 0;
|
|
2610
|
+
const dose = () => {
|
|
2611
|
+
if (dosed && host.takeDose?.(dosed.objectId, use.dose?.amount).taken === 0) fail({ key: "item_spent", ok: false, vars: { item: dosed.name } });
|
|
2612
|
+
return true;
|
|
2613
|
+
};
|
|
2614
|
+
const dishes = use.dishes ? dirtyDishes(use, spec, host) : [];
|
|
2615
|
+
const rack = use.dishes?.rack ?? [];
|
|
2616
|
+
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);
|
|
2617
|
+
const guarded = work.map((phase) => (dt) => end !== null || phase(dt));
|
|
2618
|
+
const run = runPhases([tap.open, dose, ...guarded, tap.close]);
|
|
2619
|
+
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
|
+
return { use: use.id, step: (dt) => run(dt) ? end ?? done : null };
|
|
2621
|
+
};
|
|
2622
|
+
const startDrink = (use, host, vessel) => {
|
|
2623
|
+
const tap = tapPhases(use);
|
|
2624
|
+
const want = Math.min(use.litres ?? DRINK_LITRES, (vessel.liquid?.capacity ?? DRINK_LITRES) * FILL_SHARE);
|
|
2625
|
+
let filled = vessel.liquid?.kind === "water" ? vessel.liquid.litres : 0;
|
|
2626
|
+
let drunk = 0;
|
|
2627
|
+
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
|
+
const running = waterOf(use);
|
|
2634
|
+
const fill = (dt) => {
|
|
2635
|
+
if (end) return true;
|
|
2636
|
+
const flow = running(dt);
|
|
2637
|
+
if (flow === null) {
|
|
2638
|
+
end = { key: "no_water", ok: false };
|
|
2639
|
+
return true;
|
|
2640
|
+
}
|
|
2641
|
+
if (flow <= 0) return false;
|
|
2642
|
+
const took = host.fillItem?.(vessel.objectId, "water", Math.min(flow * dt, want - filled)) ?? 0;
|
|
2643
|
+
filled += took;
|
|
2644
|
+
return filled >= want - 1e-6 || took <= 0;
|
|
2645
|
+
};
|
|
2646
|
+
let sipping = false;
|
|
2647
|
+
const drink = (dt) => {
|
|
2648
|
+
if (end) return true;
|
|
2649
|
+
if (!sipping) sipping = host.playUse?.(use.clip, vessel.objectId) ?? true;
|
|
2650
|
+
const sip = host.drinkItem?.(vessel.objectId, Math.min(DRINK_LPS * dt, filled - drunk)) ?? 0;
|
|
2651
|
+
drunk += sip;
|
|
2652
|
+
return drunk >= filled - 1e-6 || sip <= 0;
|
|
2653
|
+
};
|
|
2654
|
+
const giveBack = vessel.where === "reach" ? placePhase(host, vessel, vessel.at) : () => true;
|
|
2655
|
+
const run = runPhases([take, tap.open, fill, tap.close, drink, wait(REACH_SECONDS), giveBack]);
|
|
2656
|
+
return { use: use.id, step: (dt) => run(dt) ? end ?? { key: "done_drink", ok: true, vars: { litres: drunk.toFixed(2) } } : null };
|
|
2657
|
+
};
|
|
2658
|
+
return {
|
|
2659
|
+
start(use, host) {
|
|
2660
|
+
if (use.do === "wash") return startWash(use, host);
|
|
2661
|
+
const vessel = findNeeds(use.needs, host).items[0];
|
|
2662
|
+
if (!vessel) return { use: use.id, step: () => ({ key: "needs_item", ok: false, vars: { need: idsOf(use.needs[0] ?? "")[0] ?? "" } }) };
|
|
2663
|
+
return startDrink(use, host, vessel);
|
|
2664
|
+
}
|
|
2665
|
+
};
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2412
2668
|
// src/object-uses.ts
|
|
2413
2669
|
var OPEN = 0.5;
|
|
2414
2670
|
var PREFIX = "use.";
|
|
@@ -2418,7 +2674,7 @@ var clock = (seconds) => {
|
|
|
2418
2674
|
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
|
|
2419
2675
|
};
|
|
2420
2676
|
var accepts = (bowl, hand) => (bowl.accepts ?? []).some((id) => hand.itemId === id || hand.itemId.endsWith(`_${id}`));
|
|
2421
|
-
var
|
|
2677
|
+
var YES2 = { available: true };
|
|
2422
2678
|
var no = (reason) => ({ available: false, reason });
|
|
2423
2679
|
function createUses(options) {
|
|
2424
2680
|
const { spec, world, objectId } = options;
|
|
@@ -2430,6 +2686,8 @@ function createUses(options) {
|
|
|
2430
2686
|
const cleans = new Map((spec.fixtures ?? []).flatMap((f) => f.cleans ? [[f.id, f.cleans]] : []));
|
|
2431
2687
|
let program = null;
|
|
2432
2688
|
let lastHost = null;
|
|
2689
|
+
const sinkRoutines = createSinkRoutines({ spec, world, objectId });
|
|
2690
|
+
let routine = null;
|
|
2433
2691
|
const typeKey = `type.${spec.type}`;
|
|
2434
2692
|
const name = () => {
|
|
2435
2693
|
const text = world.t(typeKey);
|
|
@@ -2441,15 +2699,15 @@ function createUses(options) {
|
|
|
2441
2699
|
switch (use.do) {
|
|
2442
2700
|
case "program":
|
|
2443
2701
|
if (!world.power.isPowered(objectId, use.device)) return no("no_power");
|
|
2444
|
-
return use.access && host.partOpening(use.access) >= OPEN ? no("needs_closed") :
|
|
2702
|
+
return use.access && host.partOpening(use.access) >= OPEN ? no("needs_closed") : YES2;
|
|
2445
2703
|
case "put_in": {
|
|
2446
2704
|
const c = containers.get(use.container);
|
|
2447
2705
|
if (!hand) return no("hand_empty");
|
|
2448
2706
|
if (!c || !accessOpen(host, c.access)) return no("requires_open");
|
|
2449
|
-
return fitsInVolume(hand.size, c.volume.half) ?
|
|
2707
|
+
return fitsInVolume(hand.size, c.volume.half) ? YES2 : no("not_fit");
|
|
2450
2708
|
}
|
|
2451
2709
|
case "empty":
|
|
2452
|
-
return accessOpen(host, containers.get(use.container)?.access) ?
|
|
2710
|
+
return accessOpen(host, containers.get(use.container)?.access) ? YES2 : no("requires_open");
|
|
2453
2711
|
case "fill": {
|
|
2454
2712
|
const bowl = bowls.get(use.bowl);
|
|
2455
2713
|
if (!bowl) return no("empty");
|
|
@@ -2457,12 +2715,23 @@ function createUses(options) {
|
|
|
2457
2715
|
if (!hand) return no("hand_empty");
|
|
2458
2716
|
if (bowl.holds === "water" && hand.liquid?.kind === "water" && hand.liquid.closed) return no("requires_open");
|
|
2459
2717
|
const fits = bowl.holds === "water" ? hand.liquid?.kind === "water" && hand.liquid.litres > 0 : accepts(bowl, hand);
|
|
2460
|
-
return fits ?
|
|
2718
|
+
return fits ? YES2 : no("not_accepted");
|
|
2461
2719
|
}
|
|
2462
2720
|
case "relieve":
|
|
2463
|
-
return
|
|
2721
|
+
return YES2;
|
|
2722
|
+
case "wash":
|
|
2723
|
+
case "drink":
|
|
2724
|
+
return routine ? no("busy") : sinkVerdict(use, spec, host, world.water.isFlowing(objectId, use.fixture));
|
|
2464
2725
|
}
|
|
2465
2726
|
};
|
|
2727
|
+
const itemName = (id) => {
|
|
2728
|
+
const text = world.t(`item.${id}`);
|
|
2729
|
+
return text === `item.${id}` ? id.replace(/_/g, " ") : text;
|
|
2730
|
+
};
|
|
2731
|
+
const reasonOf = (v, use, host) => {
|
|
2732
|
+
const words = { ...textVars(use, host), ...v.vars };
|
|
2733
|
+
return world.t(v.reason, words.need ? { ...words, need: itemName(words.need) } : words);
|
|
2734
|
+
};
|
|
2466
2735
|
const textVars = (use, host) => ({
|
|
2467
2736
|
name: name(),
|
|
2468
2737
|
item: host.hand()?.name ?? "",
|
|
@@ -2495,6 +2764,10 @@ function createUses(options) {
|
|
|
2495
2764
|
soil.set(use.basin, SOIL_RANK[use.kind] > SOIL_RANK[now] ? use.kind : now);
|
|
2496
2765
|
return { ok: true, text: world.t(`done_relieve_${use.kind}`, vars) };
|
|
2497
2766
|
}
|
|
2767
|
+
case "wash":
|
|
2768
|
+
case "drink":
|
|
2769
|
+
routine = sinkRoutines.start(use, host);
|
|
2770
|
+
return { ok: true, text: world.t(`started_${use.do}`, { ...vars, label: world.t(use.label, vars) }) };
|
|
2498
2771
|
}
|
|
2499
2772
|
};
|
|
2500
2773
|
const fill = (bowl, host, vars) => {
|
|
@@ -2509,6 +2782,13 @@ function createUses(options) {
|
|
|
2509
2782
|
program = null;
|
|
2510
2783
|
return world.t("done_program_stop", { name: name() });
|
|
2511
2784
|
};
|
|
2785
|
+
const stepRoutine = (dt) => {
|
|
2786
|
+
const end = routine?.step(dt);
|
|
2787
|
+
if (!end) return;
|
|
2788
|
+
routine = null;
|
|
2789
|
+
const words = end.vars?.need ? { ...end.vars, need: itemName(end.vars.need) } : end.vars;
|
|
2790
|
+
lastHost?.say(world.t(end.key, { name: name(), ...words }));
|
|
2791
|
+
};
|
|
2512
2792
|
const visible = (use) => use.do !== "program" || program === null;
|
|
2513
2793
|
return {
|
|
2514
2794
|
has: (id) => id.startsWith(PREFIX),
|
|
@@ -2518,7 +2798,7 @@ function createUses(options) {
|
|
|
2518
2798
|
if (program) entries.push({ id: `${PREFIX}stop`, label: world.t("use.program.stop", { name: name(), left: clock(program.left) }), available: true });
|
|
2519
2799
|
for (const use of all.filter(visible)) {
|
|
2520
2800
|
const v = verdict(use, host);
|
|
2521
|
-
entries.push({ id: `${PREFIX}${use.id}`, label: labelOf(use, host), available: v.available, ...v.available ? {} : { reason:
|
|
2801
|
+
entries.push({ id: `${PREFIX}${use.id}`, label: labelOf(use, host), available: v.available, ...v.available ? {} : { reason: reasonOf(v, use, host) } });
|
|
2522
2802
|
}
|
|
2523
2803
|
return entries;
|
|
2524
2804
|
},
|
|
@@ -2528,9 +2808,10 @@ function createUses(options) {
|
|
|
2528
2808
|
const use = all.find((u) => `${PREFIX}${u.id}` === id);
|
|
2529
2809
|
if (!use || !visible(use)) return { ok: false, text: "" };
|
|
2530
2810
|
const v = verdict(use, host);
|
|
2531
|
-
return v.available ? runUse(use, host) : { ok: false, text:
|
|
2811
|
+
return v.available ? runUse(use, host) : { ok: false, text: reasonOf(v, use, host) };
|
|
2532
2812
|
},
|
|
2533
2813
|
update(dt) {
|
|
2814
|
+
stepRoutine(dt);
|
|
2534
2815
|
if (!program) return;
|
|
2535
2816
|
program.left -= dt;
|
|
2536
2817
|
if (program.left > 0) return;
|
|
@@ -2548,7 +2829,8 @@ function createUses(options) {
|
|
|
2548
2829
|
state: () => ({
|
|
2549
2830
|
bowls: Object.fromEntries(level),
|
|
2550
2831
|
soil: Object.fromEntries(soil),
|
|
2551
|
-
program: program ? { use: program.use.id, device: program.use.device, left: program.left } : null
|
|
2832
|
+
program: program ? { use: program.use.id, device: program.use.device, left: program.left } : null,
|
|
2833
|
+
routine: routine?.use ?? null
|
|
2552
2834
|
})
|
|
2553
2835
|
};
|
|
2554
2836
|
}
|
|
@@ -2559,9 +2841,9 @@ var MAINS = "mains";
|
|
|
2559
2841
|
var MAINS_TANK = "water";
|
|
2560
2842
|
var HOST_KINDS = /* @__PURE__ */ new Set(["toggle_part", "open_container", "take", "read", "sit", "toggle_breaker"]);
|
|
2561
2843
|
var PLUG_FALLBACK = [0, 0.3, 0];
|
|
2562
|
-
function mainsSpec(spec) {
|
|
2844
|
+
function mainsSpec(spec, water) {
|
|
2563
2845
|
const plugged = (spec.devices ?? []).filter((d) => d.socket !== void 0 && !d.circuit);
|
|
2564
|
-
return { type: MAINS, sockets: plugged.map((d, i) => ({ id: `socket_${i}`, pos: d.plug ?? PLUG_FALLBACK })), tanks: [{ id: MAINS_TANK, capacity: 1e9 }] };
|
|
2846
|
+
return { type: MAINS, sockets: plugged.map((d, i) => ({ id: `socket_${i}`, pos: d.plug ?? PLUG_FALLBACK })), tanks: water ? [{ id: MAINS_TANK, capacity: 1e9 }] : [] };
|
|
2565
2847
|
}
|
|
2566
2848
|
function createObjectControls(options) {
|
|
2567
2849
|
const { spec } = options;
|
|
@@ -2584,8 +2866,9 @@ function createObjectControls(options) {
|
|
|
2584
2866
|
forwarded.set(part, open);
|
|
2585
2867
|
host?.setPart(part, open);
|
|
2586
2868
|
};
|
|
2587
|
-
|
|
2588
|
-
|
|
2869
|
+
const piped = options.mains?.water ?? true;
|
|
2870
|
+
world.add(MAINS, mainsSpec(spec, piped), { x: 0, y: 0, z: 0, ry: 0 });
|
|
2871
|
+
if (piped) world.water.setDefaultTank(`${MAINS}:${MAINS_TANK}`);
|
|
2589
2872
|
world.add(CONTROLLED_OBJECT, spec, { x: 0, y: 0, z: 0, ry: 0 });
|
|
2590
2873
|
const uses = createUses({ spec, world, objectId: CONTROLLED_OBJECT });
|
|
2591
2874
|
const programmedDevices = new Set((spec.uses ?? []).flatMap((u) => u.do === "program" ? [u.device] : []));
|
|
@@ -2632,19 +2915,34 @@ function createObjectControls(options) {
|
|
|
2632
2915
|
};
|
|
2633
2916
|
}
|
|
2634
2917
|
export {
|
|
2918
|
+
COLLAR_REACH,
|
|
2635
2919
|
CONTROLLED_OBJECT,
|
|
2920
|
+
DRINK_LITRES,
|
|
2921
|
+
DRINK_LPS,
|
|
2922
|
+
DRY_SECONDS,
|
|
2923
|
+
END_GAP,
|
|
2924
|
+
FILL_SHARE,
|
|
2925
|
+
FLOW_DEFAULTS,
|
|
2636
2926
|
FLUSH_RUN_SECONDS,
|
|
2927
|
+
REACH_SECONDS,
|
|
2928
|
+
WASH_SCRUB_SECONDS,
|
|
2637
2929
|
alignY,
|
|
2638
2930
|
buildChain,
|
|
2931
|
+
castWithMember,
|
|
2639
2932
|
chainPoints,
|
|
2640
2933
|
createEnginePartPhysics,
|
|
2641
2934
|
createFixtureEmitters,
|
|
2642
2935
|
createObjectControls,
|
|
2936
|
+
createSinkRoutines,
|
|
2643
2937
|
createWorld,
|
|
2938
|
+
dirtyDishes,
|
|
2644
2939
|
disposeChain,
|
|
2940
|
+
endsMember,
|
|
2941
|
+
findNeeds,
|
|
2645
2942
|
fitsInVolume,
|
|
2646
2943
|
fitsSize,
|
|
2647
2944
|
fitsSlot,
|
|
2945
|
+
fixtureFlowLps,
|
|
2648
2946
|
format,
|
|
2649
2947
|
generateLoot,
|
|
2650
2948
|
hangTail,
|
|
@@ -2659,8 +2957,11 @@ export {
|
|
|
2659
2957
|
rng,
|
|
2660
2958
|
rotY,
|
|
2661
2959
|
rotateAxis,
|
|
2960
|
+
sinkVerdict,
|
|
2662
2961
|
solveSpan,
|
|
2663
2962
|
spanStrength,
|
|
2664
|
-
|
|
2963
|
+
wireRuns,
|
|
2964
|
+
worldToLocal,
|
|
2965
|
+
wrapsMember
|
|
2665
2966
|
};
|
|
2666
2967
|
//# sourceMappingURL=index.js.map
|