@adatechnology/game-interactables 0.6.8 → 0.6.10

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
@@ -115,7 +115,7 @@ interface PartSpec {
115
115
  destruction?: PartDestruction;
116
116
  }
117
117
  /** Joint kinds of the destruction SDK (`JointKind`). */
118
- type DestructionJoint = 'screw' | 'bolt' | 'nail' | 'weld' | 'glue' | 'hinge' | 'slide' | 'clip' | 'tie' | 'mortar' | 'fused' | 'stem';
118
+ type DestructionJoint = 'screw' | 'bolt' | 'nail' | 'weld' | 'glue' | 'hinge' | 'slide' | 'clip' | 'tie' | 'mortar' | 'fused' | 'stem' | 'rebar';
119
119
  /** What a part is made of and how it is attached. Field names and shapes mirror the SDK's `PartSpec`. */
120
120
  interface PartDestruction {
121
121
  /** SDK material id (`steel`, `wood_soft`, `mdf`, `glass`, `ceramic`, `plastic`, `fabric`...). */
@@ -136,6 +136,15 @@ interface PartDestruction {
136
136
  liters: number;
137
137
  pressurized?: boolean;
138
138
  };
139
+ /**
140
+ * Steel cast inside a concrete body (a concrete pole, a precast post): the SDK material of the bars, metres between them and their diameter. A host gives the
141
+ * concrete its cage (`PartSpec.reinforcement` of the destruction SDK), so a hit chips the concrete off where it lands, the bars show there and bend under the load.
142
+ */
143
+ reinforcement?: {
144
+ material: string;
145
+ spacing: number;
146
+ diameter: number;
147
+ };
139
148
  }
140
149
  /** One stack of items. `type` is an id from the content pack's item catalog. */
141
150
  interface ItemStack {
@@ -333,6 +342,27 @@ interface EmitterSpec {
333
342
  size?: number;
334
343
  /** How far (m) a water stream falls before it hits something (a basin, a bowl). Default: until the floor. */
335
344
  reach?: number;
345
+ /**
346
+ * The bowl the stream lands in (a sink's basin, a toilet bowl): its walls rise `depth` metres above where the stream lands and stand `radius` metres from it. What
347
+ * splashes stays in it, as the walls catch it. Default: open floor.
348
+ */
349
+ bowl?: EmitterBowl;
350
+ }
351
+ /** The walls round where a water stream lands (`EmitterSpec.bowl`). */
352
+ interface EmitterBowl {
353
+ radius: number;
354
+ depth: number;
355
+ }
356
+ /**
357
+ * The inside of a bowl that holds water (a sink's basin, a laundry tub, a toilet bowl), object-local: the box from the middle of its floor's corner (`from`, the
358
+ * lowest corner) to the rim (`to`). The host lays the liquid of the piece in it and lets the streams of its taps land on its floor.
359
+ */
360
+ interface BasinSpec {
361
+ id: string;
362
+ from: Vec3;
363
+ to: Vec3;
364
+ /** `'round'` for a round bowl (a toilet's): the liquid is the upright cylinder inside the box, as wide as its narrower side. Default `'box'`. */
365
+ shape?: 'box' | 'round';
336
366
  }
337
367
  interface MirrorSpec {
338
368
  id: string;
@@ -445,6 +475,8 @@ interface ObjectSpec {
445
475
  seats?: SeatSpec[];
446
476
  soft?: SoftSpec[];
447
477
  emitters?: EmitterSpec[];
478
+ /** What holds water in it (a sink's basin, a toilet bowl). */
479
+ basins?: BasinSpec[];
448
480
  mirrors?: MirrorSpec[];
449
481
  colliders?: ColliderSpec[];
450
482
  /** @deprecated Use the destruction SDK; see `DamageSpec`. */
@@ -664,6 +696,8 @@ interface ActiveEmitter {
664
696
  size: number;
665
697
  /** Meters a water stream falls before it hits something; omitted = until the floor. */
666
698
  reach?: number;
699
+ /** The bowl it lands in (`EmitterSpec.bowl`); omitted = open floor. */
700
+ bowl?: EmitterBowl;
667
701
  /** 0..1. */
668
702
  intensity: number;
669
703
  }
@@ -879,6 +913,22 @@ declare function format(text: string, vars?: Record<string, string | number>): s
879
913
  */
880
914
  declare function mergeColliders(list: WorldCollider[], options?: Pick<ColliderOptions, 'gap' | 'slack'>): WorldCollider[];
881
915
 
916
+ /** Seconds a flush runs once its button goes down (the interactables world's own flush time). */
917
+ declare const FLUSH_RUN_SECONDS = 2;
918
+ /** One emitter running now, object-local, with its strength 0..1. */
919
+ interface RunningEmitter {
920
+ readonly emitter: EmitterSpec;
921
+ readonly intensity: number;
922
+ }
923
+ interface FixtureEmitters {
924
+ /** The water emitters of the piece that run now: `opening(part)` is how open that part is, 0 closed to 1 open. Advances the flushes by `dt` seconds. */
925
+ update(dt: number, opening: (part: string) => number): RunningEmitter[];
926
+ /** Whether the piece has any emitter a handle runs (a sink, a shower, a toilet): a host can skip the others. */
927
+ readonly runs: boolean;
928
+ }
929
+ /** The driver of one piece's water emitters by its handles. */
930
+ declare function createFixtureEmitters(spec: Pick<ObjectSpec, 'emitters' | 'fixtures'>): FixtureEmitters;
931
+
882
932
  /** What a host tells the engine about its objects. */
883
933
  interface EnginePartOptions {
884
934
  /** The object's own static body when the host has one: a leaf does not collide with it. Without it each part gets a hidden anchor at its pivot. */
@@ -938,4 +988,4 @@ declare function disposeChain(world: SeamWorld, chain: Chain): void;
938
988
  /** The two ends of every link now, as a polyline (x, y, z per point) for a host that draws the cord: the points a chain was built from, moved. */
939
989
  declare function chainPoints(world: SeamWorld, chain: Chain, out: Float64Array): void;
940
990
 
941
- export { type Action, type ActiveEmitter, type BurnerSpec, type Chain, type ChainSpec, type ColliderOptions, type ColliderSpec, type ContainerSpec, type DamageKind, type DamageSpec, type DestructionDelegate, type DestructionJoint, type DeviceKind, type DeviceSpec, type EmitterKind, type EmitterSpec, type EnginePartDriver, type EnginePartOptions, type EnginePartPhysics, type FixtureKind, type FixtureSpec, type FuelSourceSpec, type Interactable, type InteractablesLocale, type InteractionSpec, type ItemCatalog, type ItemDef, type ItemStack, type LootEntry, type LootTable, type LootTables, type MirrorSpec, type Motion, type MotionKind, type ObjectSpec, type PartDestruction, type PartDriver, type PartPhysics, type PartSpec, type Pose, type Rect, type SeatPose, type SeatResult, type SeatSpec, type SlotSpec, type SocketSpec, type SoftDriver, type SoftSpec, type Strings, type SwitchSpec, type TankSpec, type TargetOptions, type Transform, type Vec3, type World, type WorldCollider, type WorldEvent, type WorldObject, type WorldOptions, type WorldState, alignY, buildChain, chainPoints, createEnginePartPhysics, createWorld, disposeChain, fitsSize, fitsSlot, format, generateLoot, hashString, localToWorld, locales, mergeColliders, pickLocale, poseOf, resolveStrings, rng, rotY, rotateAxis, worldToLocal };
991
+ export { type Action, type ActiveEmitter, type BasinSpec, type BurnerSpec, type Chain, type ChainSpec, type ColliderOptions, type ColliderSpec, type ContainerSpec, type DamageKind, type DamageSpec, type DestructionDelegate, type DestructionJoint, type DeviceKind, type DeviceSpec, type EmitterBowl, type EmitterKind, type EmitterSpec, type EnginePartDriver, type EnginePartOptions, type EnginePartPhysics, FLUSH_RUN_SECONDS, type FixtureEmitters, type FixtureKind, type FixtureSpec, type FuelSourceSpec, type Interactable, type InteractablesLocale, type InteractionSpec, type ItemCatalog, type ItemDef, type ItemStack, type LootEntry, type LootTable, type LootTables, type MirrorSpec, type Motion, type MotionKind, type ObjectSpec, type PartDestruction, type PartDriver, type PartPhysics, type PartSpec, type Pose, type Rect, type RunningEmitter, type SeatPose, type SeatResult, type SeatSpec, type SlotSpec, type SocketSpec, type SoftDriver, type SoftSpec, type Strings, type SwitchSpec, type TankSpec, type TargetOptions, type Transform, type Vec3, type World, type WorldCollider, type WorldEvent, type WorldObject, type WorldOptions, type WorldState, alignY, buildChain, chainPoints, createEnginePartPhysics, createFixtureEmitters, createWorld, disposeChain, fitsSize, fitsSlot, format, generateLoot, hashString, localToWorld, locales, mergeColliders, pickLocale, poseOf, resolveStrings, rng, rotY, rotateAxis, worldToLocal };
@@ -21,10 +21,12 @@ var GameInteractables = (() => {
21
21
  // src/index.ts
22
22
  var index_exports = {};
23
23
  __export(index_exports, {
24
+ FLUSH_RUN_SECONDS: () => FLUSH_RUN_SECONDS,
24
25
  alignY: () => alignY,
25
26
  buildChain: () => buildChain,
26
27
  chainPoints: () => chainPoints,
27
28
  createEnginePartPhysics: () => createEnginePartPhysics,
29
+ createFixtureEmitters: () => createFixtureEmitters,
28
30
  createWorld: () => createWorld,
29
31
  disposeChain: () => disposeChain,
30
32
  fitsSize: () => fitsSize,
@@ -44,6 +46,42 @@ var GameInteractables = (() => {
44
46
  worldToLocal: () => worldToLocal
45
47
  });
46
48
 
49
+ // src/fixture-emitters.ts
50
+ var FLUSH_RUN_SECONDS = 2;
51
+ var START_OPENING = 0.05;
52
+ var PRESSED = 0.5;
53
+ var FLUSH_FADE = 0.4;
54
+ function createFixtureEmitters(spec) {
55
+ const fixtures = new Map((spec.fixtures ?? []).map((fixture) => [fixture.id, fixture]));
56
+ const driven = [];
57
+ for (const emitter of spec.emitters ?? []) {
58
+ if (emitter.kind !== "water") continue;
59
+ const fixture = fixtures.get(emitter.source);
60
+ if (!fixture?.part) continue;
61
+ driven.push({ emitter, fixture: { ...fixture, part: fixture.part }, left: 0, down: false });
62
+ }
63
+ return {
64
+ runs: driven.length > 0,
65
+ update(dt, opening) {
66
+ const out = [];
67
+ for (const d of driven) {
68
+ const open = Math.min(1, Math.max(0, opening(d.fixture.part)));
69
+ if (d.fixture.kind === "flush") {
70
+ const down = open >= PRESSED;
71
+ if (down && !d.down) d.left = FLUSH_RUN_SECONDS;
72
+ d.down = down;
73
+ if (d.left <= 0) continue;
74
+ d.left = Math.max(0, d.left - dt);
75
+ out.push({ emitter: d.emitter, intensity: Math.min(1, (d.left + 1e-6) / FLUSH_FADE) });
76
+ continue;
77
+ }
78
+ if (open > START_OPENING) out.push({ emitter: d.emitter, intensity: open });
79
+ }
80
+ return out;
81
+ }
82
+ };
83
+ }
84
+
47
85
  // src/colliders.ts
48
86
  var volume = (b) => (b.u1 - b.u0) * (b.v1 - b.v0) * (b.y1 - b.y0);
49
87
  var overlap = (a0, a1, b0, b1) => Math.max(0, Math.min(a1, b1) - Math.max(a0, b0));
@@ -310,7 +348,7 @@ var GameInteractables = (() => {
310
348
  var AUTO_RANGE = 2;
311
349
  var SOCKET_BEHIND = 0.05;
312
350
  var SMOKE_TAIL = 20;
313
- var FLUSH_SECONDS = 2;
351
+ var FLUSH_SECONDS = FLUSH_RUN_SECONDS;
314
352
  var ACTOR_HEIGHT = 1.7;
315
353
  var PUSH_GAIN = 1.2;
316
354
  var SWEEP_STEPS = 24;
@@ -1468,7 +1506,7 @@ var GameInteractables = (() => {
1468
1506
  }
1469
1507
  if (intensity <= 0) continue;
1470
1508
  const dir = rotY(e.dir ?? [0, 1, 0], o.public.transform.ry);
1471
- out.push({ id: gid(o, e.id), object: o.id, kind: e.kind, pos: toWorld(o, e.pos), dir, size: e.size ?? 0.3, ...e.reach !== void 0 ? { reach: e.reach } : {}, intensity: clamp(intensity, 0, 1) });
1509
+ out.push({ id: gid(o, e.id), object: o.id, kind: e.kind, pos: toWorld(o, e.pos), dir, size: e.size ?? 0.3, ...e.reach !== void 0 ? { reach: e.reach } : {}, ...e.bowl ? { bowl: e.bowl } : {}, intensity: clamp(intensity, 0, 1) });
1472
1510
  }
1473
1511
  }
1474
1512
  return out;