@adatechnology/game-interactables 0.5.2 → 0.6.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/README.md CHANGED
@@ -198,6 +198,13 @@ alvo?.act()
198
198
  O pacote não desenha nada: você informa o `ObjectSpec` (dados), chama `update(dt)` a cada quadro e desenha o que o mundo reportar. Os textos do
199
199
  motor (`Abrir`, `Ligar`, `Sem energia`, `Sem gás`, `Sem água`...) vêm em `pt-BR`; os pacotes de conteúdo acrescentam as suas chaves em `strings`.
200
200
 
201
+ ## Physics engine for the parts (spec 008, T4.4)
202
+
203
+ `createWorld({ partPhysics: createEnginePartPhysics(physicsWorld) })` (a `SeamWorld` of `@adatechnology/game-physics`) moves the parts that have `bounds` by joints: a door or lid is a leaf on a
204
+ hinge limited to the motion's `angle`, a drawer a leaf on a slider limited to its `distance`; `t` is read from the joint, a push or a blow moves it, it stays where it is left, and the next
205
+ `act` toggles from there. `EnginePartOptions.breakImpulse` makes a part whose joint breaks over that impulse emit `{ type: 'broke' }`, keep its last `t` and fly as a loose body (`leafOf(object, part)`
206
+ gives the body to draw). Soft volumes `curtain`, `cloth` and `strip` hang as swing-twist chains from a rail and `world.sway` reads them; `buildChain` and `chainPoints` make a cable. Without
207
+ `partPhysics`, or for a part with no `bounds`, `t` steps at `Motion.speed` as before.
201
208
  ## Destruction delegate
202
209
 
203
210
  Pass `destruction: { hitPart }` (the shape of `DestructionWorld.hitPart` from `@adatechnology/game-destruction`, no dependency on it) to `createWorld` and `world.damage` forwards to it as a `blunt` (`explosive` for `gas`, `slash` for `fabric`) hit with `energy: amount`; the world stops its own hp bookkeeping and `world.hp` returns `null`. Without it the deprecated `DamageSpec` behaviour is unchanged.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,38 @@
1
1
  import { CarryHands, Thumbnail } from '@adatechnology/game-contracts';
2
+ import { BodyId, SeamWorld, JointId, Vec3 as Vec3$1, Quat } from '@adatechnology/game-physics';
3
+
4
+ /** A movable part (door, drawer, lid) moved by a physics engine instead of by `t` stepping at `Motion.speed`. */
5
+ interface PartDriver {
6
+ /** Starts going to `target` (t, 0..1) at the part's speed, from wherever the part is (the world calls it when the target changed). */
7
+ aim(target: number): void;
8
+ /** Puts the part at `t` at once (a load, an instant set), at rest. */
9
+ snap(t: number): void;
10
+ /** Called every `World.update(dt)` before `read`. */
11
+ update(dt: number): void;
12
+ /** Where the part is now, as t. */
13
+ read(): number;
14
+ /** The part has reached its target (or was let go) and is free: a push moves it, a joint holds it. */
15
+ readonly settled: boolean;
16
+ /** The joint broke (an impact over its limit): the part is a loose body now and `read` stays where it was. */
17
+ readonly broken: boolean;
18
+ dispose(): void;
19
+ }
20
+ /** A soft volume (curtain, strip, cloth) swung by a physics engine instead of the spring of the world. */
21
+ interface SoftDriver {
22
+ /** Rotation around the anchor line now, radians, as `World.sway` reports it: x (front/back) and z (sideways). */
23
+ swing(out: [number, number]): void;
24
+ /** An actor pushes through it with this velocity, object-local. */
25
+ push(velocity: Vec3): void;
26
+ dispose(): void;
27
+ }
28
+ /**
29
+ * The world's port to a physics engine (`WorldOptions.partPhysics`), duck-typed so this package does not depend on one: `createEnginePartPhysics`
30
+ * implements it over `@adatechnology/game-physics`. An `attach` that returns undefined leaves that part or soft volume to the world, as without an engine.
31
+ */
32
+ interface PartPhysics {
33
+ attachPart(object: string, part: PartSpec, transform: Transform): PartDriver | undefined;
34
+ attachSoft?(object: string, soft: SoftSpec, transform: Transform): SoftDriver | undefined;
35
+ }
2
36
 
3
37
  /**
4
38
  * Contract of @adatechnology/game-interactables.
@@ -471,6 +505,11 @@ interface WorldOptions {
471
505
  * `blunt` otherwise. Without it the deprecated behaviour is unchanged.
472
506
  */
473
507
  destruction?: DestructionDelegate;
508
+ /**
509
+ * A physics engine for the movable parts and soft volumes (`createEnginePartPhysics`): the parts it takes move by joints (limits, friction, a push moves them, an impact
510
+ * can break them) and `t` is read back from them. Without it, or for a part it declines, `t` steps at `Motion.speed` as before.
511
+ */
512
+ partPhysics?: PartPhysics;
474
513
  /** Called for every event. */
475
514
  onEvent?: (event: WorldEvent) => void;
476
515
  /** Return false to cancel an interaction (locked, needs a tool, tutorial...). */
@@ -484,6 +523,12 @@ type WorldEvent = {
484
523
  part: string;
485
524
  t: number;
486
525
  target: number;
526
+ }
527
+ /** The joint of a part broke (an impact over its limit, with a physics engine): it is a loose body of the engine now, and `t` stays where it was. */
528
+ | {
529
+ type: 'broke';
530
+ object: string;
531
+ part: string;
487
532
  } | {
488
533
  type: 'pickup';
489
534
  object: string;
@@ -834,4 +879,63 @@ declare function format(text: string, vars?: Record<string, string | number>): s
834
879
  */
835
880
  declare function mergeColliders(list: WorldCollider[], options?: Pick<ColliderOptions, 'gap' | 'slack'>): WorldCollider[];
836
881
 
837
- export { type Action, type ActiveEmitter, type BurnerSpec, type ColliderOptions, type ColliderSpec, type ContainerSpec, type DamageKind, type DamageSpec, type DestructionDelegate, type DestructionJoint, type DeviceKind, type DeviceSpec, type EmitterKind, type EmitterSpec, 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 PartSpec, type Pose, type Rect, type SeatPose, type SeatResult, type SeatSpec, type SlotSpec, type SocketSpec, 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, createWorld, fitsSize, fitsSlot, format, generateLoot, hashString, localToWorld, locales, mergeColliders, pickLocale, poseOf, resolveStrings, rng, rotY, rotateAxis, worldToLocal };
882
+ /** What a host tells the engine about its objects. */
883
+ interface EnginePartOptions {
884
+ /** 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. */
885
+ readonly frameOf?: (object: string) => BodyId | undefined;
886
+ /** The impulse (N s) over which a part's joint breaks, or undefined for a part that never breaks. */
887
+ readonly breakImpulse?: (object: string, part: PartSpec) => number | undefined;
888
+ /** Mass of a leaf (kg); default its volume at the density of a hollow door. */
889
+ readonly leafMass?: (object: string, part: PartSpec) => number;
890
+ }
891
+ interface EnginePartPhysics extends PartPhysics {
892
+ /** The leaf body of a part the engine took (also after it broke: then it is a loose body the host draws where it is), or undefined. */
893
+ leafOf(object: string, part: string): BodyId | undefined;
894
+ dispose(): void;
895
+ }
896
+ /** The engine under the movable parts and soft volumes of an interactables world (`WorldOptions.partPhysics`), made of the contract's bodies and joints only. */
897
+ declare function createEnginePartPhysics(world: SeamWorld, options?: EnginePartOptions): EnginePartPhysics;
898
+
899
+ /** A part driver whose leaf is a body of the engine: the host draws the part where the body is, and after a break the body is all that is left. */
900
+ interface EnginePartDriver extends PartDriver {
901
+ readonly leaf: BodyId;
902
+ }
903
+
904
+ /** A chain of boxes along a polyline, each joined to the one before by a swing-twist joint: a cord, a cable, a strip of a curtain. */
905
+ interface ChainSpec {
906
+ /** From the start to the end of the chain; one link between each two points. */
907
+ readonly points: readonly Vec3$1[];
908
+ /** Half the width and the depth of a link (m); its length is the segment's. */
909
+ readonly halfWidth: number;
910
+ readonly halfDepth: number;
911
+ readonly totalMass: number;
912
+ /** What the first link hangs from (a static body, or a kinematic one a host moves). */
913
+ readonly startBody: BodyId;
914
+ /** What the last link is tied to; undefined: it hangs free. */
915
+ readonly endBody?: BodyId;
916
+ /** Half cone of every joint (radians) and the most it twists either way. */
917
+ readonly halfCone: number;
918
+ readonly twist: number;
919
+ /** Torque (N m) that holds a joint still against the swing: the chain's stiffness at rest. */
920
+ readonly jointFriction: number;
921
+ /** Share of velocity lost per second by every link (the air, the cloth). */
922
+ readonly damping: number;
923
+ }
924
+ interface Chain {
925
+ readonly bodies: readonly BodyId[];
926
+ readonly joints: readonly JointId[];
927
+ /** Half the length of each link, for reading its ends. */
928
+ readonly halfLengths: readonly number[];
929
+ /** The collision group the links share (released with the chain). */
930
+ readonly group: number;
931
+ }
932
+ /** The turn that takes +y (a link's length) onto `direction` (unit). */
933
+ declare function alignY(direction: Vec3$1): Quat;
934
+ /** Builds the links and joints of a chain in the world, in the pose its points give (so a cord starts already sagging). */
935
+ declare function buildChain(world: SeamWorld, spec: ChainSpec): Chain;
936
+ /** Takes a chain out of the world: its joints, its links, then the group the links shared. */
937
+ declare function disposeChain(world: SeamWorld, chain: Chain): void;
938
+ /** 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
+ declare function chainPoints(world: SeamWorld, chain: Chain, out: Float64Array): void;
940
+
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 };