@adatechnology/game-interactables 0.14.0 → 0.14.1

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 CHANGED
@@ -628,6 +628,14 @@ interface WashUseSpec {
628
628
  readonly dishes?: WashDishesSpec;
629
629
  /** Seconds of scrubbing per thing washed. Default `WASH_SCRUB_SECONDS`. */
630
630
  readonly scrubSeconds?: number;
631
+ /**
632
+ * The hand use the rinse plays while the water takes the foam off a thing held in the hands (a dish under the tap), and its length in seconds: played as the rinse
633
+ * starts and again each time it ends, until the thing is clean. Left out, the rinse has no hold of its own (the scrubbing clip already rinses, as washing the hands).
634
+ */
635
+ readonly rinse?: {
636
+ readonly clip: string;
637
+ readonly seconds: number;
638
+ };
631
639
  }
632
640
  /**
633
641
  * Drinking at a fixture (`do: 'drink'`), one of two ways:
@@ -3266,7 +3266,7 @@ var GameInteractables = (() => {
3266
3266
  }
3267
3267
  };
3268
3268
  };
3269
- const scrubAndRinse = (use, body, target, fail) => {
3269
+ const scrubAndRinse = (use, body, target, fail, tool) => {
3270
3270
  const item = typeof target === "string" ? void 0 : target;
3271
3271
  const id = item?.objectId ?? target;
3272
3272
  const seconds = use.scrubSeconds ?? WASH_SCRUB_SECONDS;
@@ -3275,7 +3275,7 @@ var GameInteractables = (() => {
3275
3275
  const scrub = (dt) => {
3276
3276
  if (scrubbed < 0) {
3277
3277
  scrubbed = 0;
3278
- if (!body.playUse(use.clip, item?.objectId, underStream(use))) {
3278
+ if (!body.playUse(use.clip, (item ?? tool)?.objectId, underStream(use))) {
3279
3279
  fail({ key: "hands_busy", ok: false });
3280
3280
  return true;
3281
3281
  }
@@ -3286,15 +3286,28 @@ var GameInteractables = (() => {
3286
3286
  return scrubbed >= seconds;
3287
3287
  };
3288
3288
  const running = waterOf(use);
3289
+ let sinceRinsePlay = Infinity;
3290
+ let clean = false;
3289
3291
  const rinse = (dt) => {
3290
3292
  const flow = running(dt);
3291
3293
  if (flow === null) {
3292
3294
  fail({ key: "no_water", ok: false });
3293
3295
  return true;
3294
3296
  }
3295
- if (flow <= 0 || body.rinse(id, flow, dt) > 0) return false;
3296
- if (dirt > 0) body.setDirt?.(id, 0);
3297
- return true;
3297
+ if (use.rinse && !clean && sinceRinsePlay >= use.rinse.seconds) {
3298
+ if (!body.playUse(use.rinse.clip, item?.objectId, underStream(use))) {
3299
+ fail({ key: "hands_busy", ok: false });
3300
+ return true;
3301
+ }
3302
+ sinceRinsePlay = 0;
3303
+ }
3304
+ sinceRinsePlay += dt;
3305
+ if (!clean) {
3306
+ if (flow <= 0 || body.rinse(id, flow, dt) > 0) return false;
3307
+ clean = true;
3308
+ if (dirt > 0) body.setDirt?.(id, 0);
3309
+ }
3310
+ return !use.rinse || sinceRinsePlay >= use.rinse.seconds;
3298
3311
  };
3299
3312
  return [scrub, rinse];
3300
3313
  };
@@ -3317,11 +3330,13 @@ var GameInteractables = (() => {
3317
3330
  if (dosed && body.takeDose?.(dosed.objectId, use.dose?.amount).taken === 0) fail({ key: "item_spent", ok: false, vars: { item: dosed.name } });
3318
3331
  return true;
3319
3332
  };
3333
+ const tool = use.dishes ? void 0 : items[0];
3320
3334
  const dishes = use.dishes ? dirtyDishes(use, spec, host) : [];
3321
3335
  const rack = use.dishes?.rack ?? [];
3322
- 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);
3336
+ 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, tool);
3323
3337
  const guarded = work.map((phase) => (dt) => end !== null || phase(dt));
3324
- const run = runPhases([approachPhase(use, host), tap.open, dose, ...guarded, tap.close]);
3338
+ const giveBack = tool?.where === "reach" ? placePhase(host, tool, tool.at) : () => true;
3339
+ const run = runPhases([approachPhase(use, host), tap.open, dose, ...guarded, tap.close, giveBack]);
3325
3340
  const done = use.dishes ? { key: "done_wash_dishes", ok: true, vars: { n: String(dishes.length) } } : { key: "done_wash", ok: true, vars: { surface: use.surface } };
3326
3341
  return { use: use.id, step: (dt) => run(dt) ? end ?? done : null };
3327
3342
  };