ttpg-darrell 1.0.22 → 1.0.24

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.
@@ -1,4 +1,5 @@
1
- import { Container, GameObject } from "@tabletop-playground/api";
1
+ import { Container, GameObject, Player } from "@tabletop-playground/api";
2
+ import { TriggerableMulticastDelegate } from "../triggerable-multicast-delegate/triggerable-multicast-delegate";
2
3
  export declare abstract class GarbageHandler {
3
4
  /**
4
5
  * Can recycle this object?
@@ -18,6 +19,7 @@ export declare abstract class GarbageHandler {
18
19
  * Attempt to recycle deposited objects, break up decks into individual cards.
19
20
  */
20
21
  export declare class GarbageContainer {
22
+ static onRecycled: TriggerableMulticastDelegate<(obj: GameObject, player: Player | undefined) => void>;
21
23
  private static _garbageHandlers;
22
24
  private readonly _container;
23
25
  /**
@@ -30,8 +32,9 @@ export declare class GarbageContainer {
30
32
  * Clear all recycle handlers (for tests).
31
33
  */
32
34
  static clearHandlers(): void;
35
+ static tryRecycle(obj: GameObject, player: Player | undefined): boolean;
33
36
  private static _tryRecycleObj;
34
37
  private static _tryRecycleDeck;
35
38
  constructor(container: Container);
36
- _recycle(): void;
39
+ _recycle(player: Player | undefined): void;
37
40
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GarbageContainer = exports.GarbageHandler = void 0;
4
4
  const api_1 = require("@tabletop-playground/api");
5
+ const triggerable_multicast_delegate_1 = require("../triggerable-multicast-delegate/triggerable-multicast-delegate");
5
6
  class GarbageHandler {
6
7
  }
7
8
  exports.GarbageHandler = GarbageHandler;
@@ -23,17 +24,26 @@ class GarbageContainer {
23
24
  static clearHandlers() {
24
25
  this._garbageHandlers = [];
25
26
  }
26
- static _tryRecycleObj(obj) {
27
+ static tryRecycle(obj, player) {
28
+ if (obj instanceof api_1.Card && obj.getStackSize() > 1) {
29
+ return GarbageContainer._tryRecycleDeck(obj, player);
30
+ }
31
+ else {
32
+ return GarbageContainer._tryRecycleObj(obj, player);
33
+ }
34
+ }
35
+ static _tryRecycleObj(obj, player) {
27
36
  for (const handler of this._garbageHandlers) {
28
37
  if (handler.canRecycle(obj)) {
29
38
  if (handler.recycle(obj)) {
39
+ GarbageContainer.onRecycled.trigger(obj, player);
30
40
  return true;
31
41
  }
32
42
  }
33
43
  }
34
44
  return false;
35
45
  }
36
- static _tryRecycleDeck(deck) {
46
+ static _tryRecycleDeck(deck, player) {
37
47
  let recycleCount = 0;
38
48
  const stackSize = deck.getStackSize();
39
49
  // Process one card at a time. Assume a handler will exist, cost to
@@ -54,7 +64,7 @@ class GarbageContainer {
54
64
  continue;
55
65
  }
56
66
  // Try to recycle, return card to same spot if fails.
57
- let success = GarbageContainer._tryRecycleObj(card);
67
+ let success = GarbageContainer._tryRecycleObj(card, player);
58
68
  if (success) {
59
69
  recycleCount += 1;
60
70
  }
@@ -74,12 +84,12 @@ class GarbageContainer {
74
84
  this._container = container;
75
85
  container.onInserted.add((container, insertedObjects, player) => {
76
86
  process.nextTick(() => {
77
- this._recycle();
87
+ this._recycle(player);
78
88
  });
79
89
  });
80
90
  }
81
91
  // Expose for testing.
82
- _recycle() {
92
+ _recycle(player) {
83
93
  const objs = this._container.getItems();
84
94
  for (const obj of objs) {
85
95
  // Verify object.
@@ -95,13 +105,7 @@ class GarbageContainer {
95
105
  .add([0, 0, obj.getSize().z + 3]);
96
106
  this._container.take(obj, above);
97
107
  // Attempt to recyle.
98
- let success;
99
- if (obj instanceof api_1.Card && obj.getStackSize() > 1) {
100
- success = GarbageContainer._tryRecycleDeck(obj);
101
- }
102
- else {
103
- success = GarbageContainer._tryRecycleObj(obj);
104
- }
108
+ const success = GarbageContainer.tryRecycle(obj, player);
105
109
  // If recycle fails, return to container.
106
110
  if (!success) {
107
111
  this._container.addObjects([obj]);
@@ -110,4 +114,5 @@ class GarbageContainer {
110
114
  }
111
115
  }
112
116
  exports.GarbageContainer = GarbageContainer;
117
+ GarbageContainer.onRecycled = new triggerable_multicast_delegate_1.TriggerableMulticastDelegate();
113
118
  GarbageContainer._garbageHandlers = [];
@@ -31,7 +31,9 @@ class SimpleToContainerHandler {
31
31
  if (!container) {
32
32
  return false;
33
33
  }
34
- container.addObjects([obj]);
34
+ const index = 0;
35
+ const showAnimation = true;
36
+ container.addObjects([obj], index, showAnimation);
35
37
  return true;
36
38
  }
37
39
  _getContainer(obj) {
@@ -38,7 +38,7 @@ class SimpleToSnapPointHandler {
38
38
  if (otherObj && otherObj.getSnappedToPoint() === snapPoint) {
39
39
  return false;
40
40
  }
41
- obj.setPosition(snapPoint.getGlobalPosition().add([0, 0, 10]));
41
+ obj.setPosition(snapPoint.getGlobalPosition().add([0, 0, 10]), 1);
42
42
  obj.snapToGround(); // get in range
43
43
  obj.snap();
44
44
  return true;
@@ -1,4 +1,5 @@
1
- import { Container, GameObject } from "@tabletop-playground/api";
1
+ import { Container, GameObject, Player } from "@tabletop-playground/api";
2
+ import { TriggerableMulticastDelegate } from "../triggerable-multicast-delegate/triggerable-multicast-delegate";
2
3
  export declare abstract class GarbageHandler {
3
4
  /**
4
5
  * Can recycle this object?
@@ -18,6 +19,7 @@ export declare abstract class GarbageHandler {
18
19
  * Attempt to recycle deposited objects, break up decks into individual cards.
19
20
  */
20
21
  export declare class GarbageContainer {
22
+ static onRecycled: TriggerableMulticastDelegate<(obj: GameObject, player: Player | undefined) => void>;
21
23
  private static _garbageHandlers;
22
24
  private readonly _container;
23
25
  /**
@@ -30,8 +32,9 @@ export declare class GarbageContainer {
30
32
  * Clear all recycle handlers (for tests).
31
33
  */
32
34
  static clearHandlers(): void;
35
+ static tryRecycle(obj: GameObject, player: Player | undefined): boolean;
33
36
  private static _tryRecycleObj;
34
37
  private static _tryRecycleDeck;
35
38
  constructor(container: Container);
36
- _recycle(): void;
39
+ _recycle(player: Player | undefined): void;
37
40
  }
@@ -1,4 +1,5 @@
1
1
  import { Card, } from "@tabletop-playground/api";
2
+ import { TriggerableMulticastDelegate } from "../triggerable-multicast-delegate/triggerable-multicast-delegate";
2
3
  export class GarbageHandler {
3
4
  }
4
5
  /**
@@ -19,17 +20,26 @@ export class GarbageContainer {
19
20
  static clearHandlers() {
20
21
  this._garbageHandlers = [];
21
22
  }
22
- static _tryRecycleObj(obj) {
23
+ static tryRecycle(obj, player) {
24
+ if (obj instanceof Card && obj.getStackSize() > 1) {
25
+ return GarbageContainer._tryRecycleDeck(obj, player);
26
+ }
27
+ else {
28
+ return GarbageContainer._tryRecycleObj(obj, player);
29
+ }
30
+ }
31
+ static _tryRecycleObj(obj, player) {
23
32
  for (const handler of this._garbageHandlers) {
24
33
  if (handler.canRecycle(obj)) {
25
34
  if (handler.recycle(obj)) {
35
+ GarbageContainer.onRecycled.trigger(obj, player);
26
36
  return true;
27
37
  }
28
38
  }
29
39
  }
30
40
  return false;
31
41
  }
32
- static _tryRecycleDeck(deck) {
42
+ static _tryRecycleDeck(deck, player) {
33
43
  let recycleCount = 0;
34
44
  const stackSize = deck.getStackSize();
35
45
  // Process one card at a time. Assume a handler will exist, cost to
@@ -50,7 +60,7 @@ export class GarbageContainer {
50
60
  continue;
51
61
  }
52
62
  // Try to recycle, return card to same spot if fails.
53
- let success = GarbageContainer._tryRecycleObj(card);
63
+ let success = GarbageContainer._tryRecycleObj(card, player);
54
64
  if (success) {
55
65
  recycleCount += 1;
56
66
  }
@@ -70,12 +80,12 @@ export class GarbageContainer {
70
80
  this._container = container;
71
81
  container.onInserted.add((container, insertedObjects, player) => {
72
82
  process.nextTick(() => {
73
- this._recycle();
83
+ this._recycle(player);
74
84
  });
75
85
  });
76
86
  }
77
87
  // Expose for testing.
78
- _recycle() {
88
+ _recycle(player) {
79
89
  const objs = this._container.getItems();
80
90
  for (const obj of objs) {
81
91
  // Verify object.
@@ -91,13 +101,7 @@ export class GarbageContainer {
91
101
  .add([0, 0, obj.getSize().z + 3]);
92
102
  this._container.take(obj, above);
93
103
  // Attempt to recyle.
94
- let success;
95
- if (obj instanceof Card && obj.getStackSize() > 1) {
96
- success = GarbageContainer._tryRecycleDeck(obj);
97
- }
98
- else {
99
- success = GarbageContainer._tryRecycleObj(obj);
100
- }
104
+ const success = GarbageContainer.tryRecycle(obj, player);
101
105
  // If recycle fails, return to container.
102
106
  if (!success) {
103
107
  this._container.addObjects([obj]);
@@ -105,4 +109,5 @@ export class GarbageContainer {
105
109
  }
106
110
  }
107
111
  }
112
+ GarbageContainer.onRecycled = new TriggerableMulticastDelegate();
108
113
  GarbageContainer._garbageHandlers = [];
@@ -28,7 +28,9 @@ export class SimpleToContainerHandler {
28
28
  if (!container) {
29
29
  return false;
30
30
  }
31
- container.addObjects([obj]);
31
+ const index = 0;
32
+ const showAnimation = true;
33
+ container.addObjects([obj], index, showAnimation);
32
34
  return true;
33
35
  }
34
36
  _getContainer(obj) {
@@ -35,7 +35,7 @@ export class SimpleToSnapPointHandler {
35
35
  if (otherObj && otherObj.getSnappedToPoint() === snapPoint) {
36
36
  return false;
37
37
  }
38
- obj.setPosition(snapPoint.getGlobalPosition().add([0, 0, 10]));
38
+ obj.setPosition(snapPoint.getGlobalPosition().add([0, 0, 10]), 1);
39
39
  obj.snapToGround(); // get in range
40
40
  obj.snap();
41
41
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ttpg-darrell",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "TTPG TypeScript library",
5
5
  "main": "./build/cjs/index.js",
6
6
  "module": "./build/esm/index.js",