@newkrok/nape-js 3.21.5 → 3.21.6

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.cts CHANGED
@@ -1561,6 +1561,100 @@ declare class CharacterController {
1561
1561
  private _getCharacterRadius;
1562
1562
  }
1563
1563
 
1564
+ /** Handler called when an interactor enters, stays in, or exits the zone. */
1565
+ type TriggerHandler = (interactor: Interactor) => void;
1566
+ /** Configuration options for {@link TriggerZone}. */
1567
+ interface TriggerZoneOptions {
1568
+ /**
1569
+ * Filter for which interactors trigger the zone.
1570
+ * When `null`, any interactor triggers the zone.
1571
+ * @default null
1572
+ */
1573
+ filter?: CbType | OptionType | null;
1574
+ /**
1575
+ * The interaction type to listen for.
1576
+ * @default InteractionType.SENSOR
1577
+ */
1578
+ interactionType?: InteractionType;
1579
+ /** Called once when an interactor enters the zone. */
1580
+ onEnter?: TriggerHandler | null;
1581
+ /** Called every simulation step while an interactor remains in the zone. */
1582
+ onStay?: TriggerHandler | null;
1583
+ /** Called once when an interactor exits the zone. */
1584
+ onExit?: TriggerHandler | null;
1585
+ }
1586
+ /**
1587
+ * High-level trigger zone — Unity-style `onEnter`/`onStay`/`onExit` wrapper
1588
+ * over the nape callback system.
1589
+ *
1590
+ * Automatically creates sensor-based {@link InteractionListener}s and manages
1591
+ * their lifecycle. Assign handlers directly or via the constructor options.
1592
+ *
1593
+ * @example
1594
+ * ```ts
1595
+ * const zone = new TriggerZone(space, sensorBody, {
1596
+ * onEnter: (other) => console.log("entered!", other),
1597
+ * onStay: (other) => console.log("inside", other),
1598
+ * onExit: (other) => console.log("left!", other),
1599
+ * });
1600
+ *
1601
+ * // Later: clean up all listeners
1602
+ * zone.dispose();
1603
+ * ```
1604
+ */
1605
+ declare class TriggerZone {
1606
+ /** The CbType automatically created for this zone. */
1607
+ readonly cbType: CbType;
1608
+ private _space;
1609
+ private _body;
1610
+ private _enabled;
1611
+ private _onEnter;
1612
+ private _onStay;
1613
+ private _onExit;
1614
+ private _enterListener;
1615
+ private _stayListener;
1616
+ private _exitListener;
1617
+ private _filter;
1618
+ private _interactionType;
1619
+ /**
1620
+ * @param space - The physics space to register listeners on.
1621
+ * @param body - The body acting as the trigger zone. Its shapes should have
1622
+ * `sensorEnabled = true` (the constructor enables it automatically
1623
+ * for all shapes that don't already have it set).
1624
+ * @param options - Optional configuration and initial handlers.
1625
+ */
1626
+ constructor(space: Space, body: Body, options?: TriggerZoneOptions);
1627
+ /** Called once when an interactor enters the zone. */
1628
+ get onEnter(): TriggerHandler | null;
1629
+ set onEnter(handler: TriggerHandler | null);
1630
+ /** Called every simulation step while an interactor remains in the zone. */
1631
+ get onStay(): TriggerHandler | null;
1632
+ set onStay(handler: TriggerHandler | null);
1633
+ /** Called once when an interactor exits the zone. */
1634
+ get onExit(): TriggerHandler | null;
1635
+ set onExit(handler: TriggerHandler | null);
1636
+ /** Whether the zone is active. When disabled, no callbacks fire. */
1637
+ get enabled(): boolean;
1638
+ set enabled(value: boolean);
1639
+ /** The body acting as the trigger zone. */
1640
+ get body(): Body;
1641
+ /** The space the zone is registered on. */
1642
+ get space(): Space;
1643
+ /**
1644
+ * Remove all listeners from the space and untag the body.
1645
+ * After disposal, the TriggerZone should not be reused.
1646
+ */
1647
+ dispose(): void;
1648
+ /**
1649
+ * Resolve which interactor is "the other" (not the zone body) from
1650
+ * the callback's int1/int2 pair.
1651
+ */
1652
+ private _resolveOther;
1653
+ private _syncListeners;
1654
+ private _createListener;
1655
+ private _removeListener;
1656
+ }
1657
+
1564
1658
  declare const VERSION: string;
1565
1659
 
1566
- export { AABB, AngleJoint, Arbiter, Body, BodyCallback, BodyListener, BodyType, Callback, Capsule, CbEvent, CbType, CharacterController, type CharacterControllerOptions, Circle, CollisionArbiter, type ConcaveBodyOptions, Constraint, ConstraintCallback, ConstraintListener, Contact, DebugDrawFlags, DistanceJoint, Geom, GeomPoly, InteractionCallback, InteractionFilter, InteractionListener, InteractionType, Interactor, LineJoint, Listener, MarchingSquares, MatMN, Material, MotorJoint, type MoveResult, OptionType, PivotJoint, PreCallback, PreFlag, PreListener, PulleyJoint, Shape, ShapeType, Space, UserConstraint, VERSION, ValidationResult, Vec2, Vec3, WeldJoint, Winding, createConcaveBody };
1660
+ export { AABB, AngleJoint, Arbiter, Body, BodyCallback, BodyListener, BodyType, Callback, Capsule, CbEvent, CbType, CharacterController, type CharacterControllerOptions, Circle, CollisionArbiter, type ConcaveBodyOptions, Constraint, ConstraintCallback, ConstraintListener, Contact, DebugDrawFlags, DistanceJoint, Geom, GeomPoly, InteractionCallback, InteractionFilter, InteractionListener, InteractionType, Interactor, LineJoint, Listener, MarchingSquares, MatMN, Material, MotorJoint, type MoveResult, OptionType, PivotJoint, PreCallback, PreFlag, PreListener, PulleyJoint, Shape, ShapeType, Space, type TriggerHandler, TriggerZone, type TriggerZoneOptions, UserConstraint, VERSION, ValidationResult, Vec2, Vec3, WeldJoint, Winding, createConcaveBody };
package/dist/index.d.ts CHANGED
@@ -1561,6 +1561,100 @@ declare class CharacterController {
1561
1561
  private _getCharacterRadius;
1562
1562
  }
1563
1563
 
1564
+ /** Handler called when an interactor enters, stays in, or exits the zone. */
1565
+ type TriggerHandler = (interactor: Interactor) => void;
1566
+ /** Configuration options for {@link TriggerZone}. */
1567
+ interface TriggerZoneOptions {
1568
+ /**
1569
+ * Filter for which interactors trigger the zone.
1570
+ * When `null`, any interactor triggers the zone.
1571
+ * @default null
1572
+ */
1573
+ filter?: CbType | OptionType | null;
1574
+ /**
1575
+ * The interaction type to listen for.
1576
+ * @default InteractionType.SENSOR
1577
+ */
1578
+ interactionType?: InteractionType;
1579
+ /** Called once when an interactor enters the zone. */
1580
+ onEnter?: TriggerHandler | null;
1581
+ /** Called every simulation step while an interactor remains in the zone. */
1582
+ onStay?: TriggerHandler | null;
1583
+ /** Called once when an interactor exits the zone. */
1584
+ onExit?: TriggerHandler | null;
1585
+ }
1586
+ /**
1587
+ * High-level trigger zone — Unity-style `onEnter`/`onStay`/`onExit` wrapper
1588
+ * over the nape callback system.
1589
+ *
1590
+ * Automatically creates sensor-based {@link InteractionListener}s and manages
1591
+ * their lifecycle. Assign handlers directly or via the constructor options.
1592
+ *
1593
+ * @example
1594
+ * ```ts
1595
+ * const zone = new TriggerZone(space, sensorBody, {
1596
+ * onEnter: (other) => console.log("entered!", other),
1597
+ * onStay: (other) => console.log("inside", other),
1598
+ * onExit: (other) => console.log("left!", other),
1599
+ * });
1600
+ *
1601
+ * // Later: clean up all listeners
1602
+ * zone.dispose();
1603
+ * ```
1604
+ */
1605
+ declare class TriggerZone {
1606
+ /** The CbType automatically created for this zone. */
1607
+ readonly cbType: CbType;
1608
+ private _space;
1609
+ private _body;
1610
+ private _enabled;
1611
+ private _onEnter;
1612
+ private _onStay;
1613
+ private _onExit;
1614
+ private _enterListener;
1615
+ private _stayListener;
1616
+ private _exitListener;
1617
+ private _filter;
1618
+ private _interactionType;
1619
+ /**
1620
+ * @param space - The physics space to register listeners on.
1621
+ * @param body - The body acting as the trigger zone. Its shapes should have
1622
+ * `sensorEnabled = true` (the constructor enables it automatically
1623
+ * for all shapes that don't already have it set).
1624
+ * @param options - Optional configuration and initial handlers.
1625
+ */
1626
+ constructor(space: Space, body: Body, options?: TriggerZoneOptions);
1627
+ /** Called once when an interactor enters the zone. */
1628
+ get onEnter(): TriggerHandler | null;
1629
+ set onEnter(handler: TriggerHandler | null);
1630
+ /** Called every simulation step while an interactor remains in the zone. */
1631
+ get onStay(): TriggerHandler | null;
1632
+ set onStay(handler: TriggerHandler | null);
1633
+ /** Called once when an interactor exits the zone. */
1634
+ get onExit(): TriggerHandler | null;
1635
+ set onExit(handler: TriggerHandler | null);
1636
+ /** Whether the zone is active. When disabled, no callbacks fire. */
1637
+ get enabled(): boolean;
1638
+ set enabled(value: boolean);
1639
+ /** The body acting as the trigger zone. */
1640
+ get body(): Body;
1641
+ /** The space the zone is registered on. */
1642
+ get space(): Space;
1643
+ /**
1644
+ * Remove all listeners from the space and untag the body.
1645
+ * After disposal, the TriggerZone should not be reused.
1646
+ */
1647
+ dispose(): void;
1648
+ /**
1649
+ * Resolve which interactor is "the other" (not the zone body) from
1650
+ * the callback's int1/int2 pair.
1651
+ */
1652
+ private _resolveOther;
1653
+ private _syncListeners;
1654
+ private _createListener;
1655
+ private _removeListener;
1656
+ }
1657
+
1564
1658
  declare const VERSION: string;
1565
1659
 
1566
- export { AABB, AngleJoint, Arbiter, Body, BodyCallback, BodyListener, BodyType, Callback, Capsule, CbEvent, CbType, CharacterController, type CharacterControllerOptions, Circle, CollisionArbiter, type ConcaveBodyOptions, Constraint, ConstraintCallback, ConstraintListener, Contact, DebugDrawFlags, DistanceJoint, Geom, GeomPoly, InteractionCallback, InteractionFilter, InteractionListener, InteractionType, Interactor, LineJoint, Listener, MarchingSquares, MatMN, Material, MotorJoint, type MoveResult, OptionType, PivotJoint, PreCallback, PreFlag, PreListener, PulleyJoint, Shape, ShapeType, Space, UserConstraint, VERSION, ValidationResult, Vec2, Vec3, WeldJoint, Winding, createConcaveBody };
1660
+ export { AABB, AngleJoint, Arbiter, Body, BodyCallback, BodyListener, BodyType, Callback, Capsule, CbEvent, CbType, CharacterController, type CharacterControllerOptions, Circle, CollisionArbiter, type ConcaveBodyOptions, Constraint, ConstraintCallback, ConstraintListener, Contact, DebugDrawFlags, DistanceJoint, Geom, GeomPoly, InteractionCallback, InteractionFilter, InteractionListener, InteractionType, Interactor, LineJoint, Listener, MarchingSquares, MatMN, Material, MotorJoint, type MoveResult, OptionType, PivotJoint, PreCallback, PreFlag, PreListener, PulleyJoint, Shape, ShapeType, Space, type TriggerHandler, TriggerZone, type TriggerZoneOptions, UserConstraint, VERSION, ValidationResult, Vec2, Vec3, WeldJoint, Winding, createConcaveBody };