ttpg-darrell 1.0.19 → 1.0.21
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/build/cjs/garbage/simple-card-garbage-handler.d.ts +4 -0
- package/build/cjs/garbage/simple-card-garbage-handler.js +4 -0
- package/build/cjs/garbage/simple-to-container-handler.d.ts +14 -0
- package/build/cjs/garbage/simple-to-container-handler.js +75 -0
- package/build/cjs/garbage/simple-to-snap-point-handler.d.ts +17 -0
- package/build/cjs/garbage/simple-to-snap-point-handler.js +70 -0
- package/build/cjs/setup/layout/layout-objects.d.ts +1 -1
- package/build/esm/garbage/simple-card-garbage-handler.d.ts +4 -0
- package/build/esm/garbage/simple-card-garbage-handler.js +4 -0
- package/build/esm/garbage/simple-to-container-handler.d.ts +14 -0
- package/build/esm/garbage/simple-to-container-handler.js +71 -0
- package/build/esm/garbage/simple-to-snap-point-handler.d.ts +17 -0
- package/build/esm/garbage/simple-to-snap-point-handler.js +66 -0
- package/build/esm/setup/layout/layout-objects.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { GameObject } from "@tabletop-playground/api";
|
|
2
2
|
import { GarbageHandler } from "./garbage-container";
|
|
3
|
+
/**
|
|
4
|
+
* Recycle cards to a specific snap point on a mat.
|
|
5
|
+
* Optionally shuffle any existing deck after discard.
|
|
6
|
+
*/
|
|
3
7
|
export declare class SimpleCardGarbageHandler implements GarbageHandler {
|
|
4
8
|
private _matNsid;
|
|
5
9
|
private _matSnapPointTag;
|
|
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SimpleCardGarbageHandler = void 0;
|
|
4
4
|
const api_1 = require("@tabletop-playground/api");
|
|
5
5
|
const nsid_1 = require("../nsid/nsid");
|
|
6
|
+
/**
|
|
7
|
+
* Recycle cards to a specific snap point on a mat.
|
|
8
|
+
* Optionally shuffle any existing deck after discard.
|
|
9
|
+
*/
|
|
6
10
|
class SimpleCardGarbageHandler {
|
|
7
11
|
constructor() {
|
|
8
12
|
this._matNsid = "";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Container, GameObject } from "@tabletop-playground/api";
|
|
2
|
+
import { GarbageHandler } from "./garbage-container";
|
|
3
|
+
export declare class SimpleToContainerHandler implements GarbageHandler {
|
|
4
|
+
private readonly _playerSlotToContainer;
|
|
5
|
+
private readonly _recycleObjectNsids;
|
|
6
|
+
private _requirePlayerSlot;
|
|
7
|
+
private _containerNsid;
|
|
8
|
+
addRecycleObjectNsid(nsid: string): this;
|
|
9
|
+
setContainerNsid(nsid: string): this;
|
|
10
|
+
setRequireOwningPlayerSlot(value: boolean): this;
|
|
11
|
+
canRecycle(obj: GameObject): boolean;
|
|
12
|
+
recycle(obj: GameObject): boolean;
|
|
13
|
+
_getContainer(obj: GameObject): Container | undefined;
|
|
14
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleToContainerHandler = void 0;
|
|
4
|
+
const api_1 = require("@tabletop-playground/api");
|
|
5
|
+
const nsid_1 = require("../nsid/nsid");
|
|
6
|
+
class SimpleToContainerHandler {
|
|
7
|
+
constructor() {
|
|
8
|
+
this._playerSlotToContainer = {};
|
|
9
|
+
this._recycleObjectNsids = new Set();
|
|
10
|
+
this._requirePlayerSlot = false;
|
|
11
|
+
this._containerNsid = "";
|
|
12
|
+
}
|
|
13
|
+
addRecycleObjectNsid(nsid) {
|
|
14
|
+
this._recycleObjectNsids.add(nsid);
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
setContainerNsid(nsid) {
|
|
18
|
+
this._containerNsid = nsid;
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
setRequireOwningPlayerSlot(value) {
|
|
22
|
+
this._requirePlayerSlot = value;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
canRecycle(obj) {
|
|
26
|
+
const nsid = nsid_1.NSID.get(obj);
|
|
27
|
+
return this._recycleObjectNsids.has(nsid);
|
|
28
|
+
}
|
|
29
|
+
recycle(obj) {
|
|
30
|
+
const container = this._getContainer(obj);
|
|
31
|
+
if (!container) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
container.addObjects([obj]);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
_getContainer(obj) {
|
|
38
|
+
const isMatch = (container) => {
|
|
39
|
+
if (!container.isValid()) {
|
|
40
|
+
return false; // deleted!
|
|
41
|
+
}
|
|
42
|
+
const containerNsid = nsid_1.NSID.get(container);
|
|
43
|
+
if (containerNsid !== this._containerNsid) {
|
|
44
|
+
return false; // wrong container type
|
|
45
|
+
}
|
|
46
|
+
if (this._requirePlayerSlot) {
|
|
47
|
+
const objSlot = obj.getOwningPlayerSlot();
|
|
48
|
+
const containerSlot = container.getOwningPlayerSlot();
|
|
49
|
+
if (objSlot !== containerSlot) {
|
|
50
|
+
return false; // wrong owning player slot
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
};
|
|
55
|
+
// Use cache if valid.
|
|
56
|
+
const cacheKey = this._requirePlayerSlot ? obj.getOwningPlayerSlot() : -1;
|
|
57
|
+
const cached = this._playerSlotToContainer[cacheKey];
|
|
58
|
+
if (cached && isMatch(cached)) {
|
|
59
|
+
return cached;
|
|
60
|
+
}
|
|
61
|
+
// Search for container.
|
|
62
|
+
const skipContained = true;
|
|
63
|
+
for (const obj of api_1.world.getAllObjects(skipContained)) {
|
|
64
|
+
if (!(obj instanceof api_1.Container)) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (isMatch(obj)) {
|
|
68
|
+
this._playerSlotToContainer[cacheKey] = obj;
|
|
69
|
+
return obj;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.SimpleToContainerHandler = SimpleToContainerHandler;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GameObject, SnapPoint } from "@tabletop-playground/api";
|
|
2
|
+
import { GarbageHandler } from "./garbage-container";
|
|
3
|
+
/**
|
|
4
|
+
* Recycle an object to a specific snap point with the matching tag.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SimpleToSnapPointHandler implements GarbageHandler {
|
|
7
|
+
private readonly _recycleObjectNsids;
|
|
8
|
+
private _matNsid;
|
|
9
|
+
private _snapPointTag;
|
|
10
|
+
private _cachedSnapPoint;
|
|
11
|
+
addRecycleObjectNsid(nsid: string): this;
|
|
12
|
+
setMatNsid(nsid: string): this;
|
|
13
|
+
setSnapPointTag(tag: string): this;
|
|
14
|
+
canRecycle(obj: GameObject): boolean;
|
|
15
|
+
recycle(obj: GameObject): boolean;
|
|
16
|
+
_getSnapPoint(): SnapPoint | undefined;
|
|
17
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SimpleToSnapPointHandler = void 0;
|
|
4
|
+
const api_1 = require("@tabletop-playground/api");
|
|
5
|
+
const nsid_1 = require("../nsid/nsid");
|
|
6
|
+
/**
|
|
7
|
+
* Recycle an object to a specific snap point with the matching tag.
|
|
8
|
+
*/
|
|
9
|
+
class SimpleToSnapPointHandler {
|
|
10
|
+
constructor() {
|
|
11
|
+
this._recycleObjectNsids = new Set();
|
|
12
|
+
this._matNsid = "";
|
|
13
|
+
this._snapPointTag = "";
|
|
14
|
+
}
|
|
15
|
+
addRecycleObjectNsid(nsid) {
|
|
16
|
+
this._recycleObjectNsids.add(nsid);
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
setMatNsid(nsid) {
|
|
20
|
+
this._matNsid = nsid;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
setSnapPointTag(tag) {
|
|
24
|
+
this._snapPointTag = tag;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
canRecycle(obj) {
|
|
28
|
+
const nsid = nsid_1.NSID.get(obj);
|
|
29
|
+
return this._recycleObjectNsids.has(nsid);
|
|
30
|
+
}
|
|
31
|
+
recycle(obj) {
|
|
32
|
+
const snapPoint = this._getSnapPoint();
|
|
33
|
+
if (!snapPoint) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
// Reject if something already snapped there.
|
|
37
|
+
const otherObj = snapPoint.getSnappedObject();
|
|
38
|
+
if (otherObj && otherObj.getSnappedToPoint() === snapPoint) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
obj.setPosition(snapPoint.getGlobalPosition().add([0, 0, 10]));
|
|
42
|
+
obj.snapToGround(); // get in range
|
|
43
|
+
obj.snap();
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
_getSnapPoint() {
|
|
47
|
+
var _a;
|
|
48
|
+
// Use cache if valid.
|
|
49
|
+
if (this._cachedSnapPoint &&
|
|
50
|
+
((_a = this._cachedSnapPoint.getParentObject()) === null || _a === void 0 ? void 0 : _a.isValid())) {
|
|
51
|
+
return this._cachedSnapPoint;
|
|
52
|
+
}
|
|
53
|
+
// Search for mat.
|
|
54
|
+
const skipContained = true;
|
|
55
|
+
for (const obj of api_1.world.getAllObjects(skipContained)) {
|
|
56
|
+
const nsid = nsid_1.NSID.get(obj);
|
|
57
|
+
if (nsid !== this._matNsid) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
for (const snapPoint of obj.getAllSnapPoints()) {
|
|
61
|
+
if (snapPoint.getTags().includes(this._snapPointTag)) {
|
|
62
|
+
this._cachedSnapPoint = snapPoint;
|
|
63
|
+
return snapPoint;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.SimpleToSnapPointHandler = SimpleToSnapPointHandler;
|
|
@@ -25,7 +25,7 @@ export declare class LayoutObjects {
|
|
|
25
25
|
setOverrideHeight(value: number): this;
|
|
26
26
|
setOverrideWidth(value: number): this;
|
|
27
27
|
add(item: GameObject | LayoutObjects): this;
|
|
28
|
-
addAfterLayout(f: () =>
|
|
28
|
+
addAfterLayout(f: () => void): this;
|
|
29
29
|
flip(flipH: boolean, flipV: boolean): this;
|
|
30
30
|
/**
|
|
31
31
|
* Get size of self, applying any overrides.
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { GameObject } from "@tabletop-playground/api";
|
|
2
2
|
import { GarbageHandler } from "./garbage-container";
|
|
3
|
+
/**
|
|
4
|
+
* Recycle cards to a specific snap point on a mat.
|
|
5
|
+
* Optionally shuffle any existing deck after discard.
|
|
6
|
+
*/
|
|
3
7
|
export declare class SimpleCardGarbageHandler implements GarbageHandler {
|
|
4
8
|
private _matNsid;
|
|
5
9
|
private _matSnapPointTag;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Card, world } from "@tabletop-playground/api";
|
|
2
2
|
import { NSID } from "../nsid/nsid";
|
|
3
|
+
/**
|
|
4
|
+
* Recycle cards to a specific snap point on a mat.
|
|
5
|
+
* Optionally shuffle any existing deck after discard.
|
|
6
|
+
*/
|
|
3
7
|
export class SimpleCardGarbageHandler {
|
|
4
8
|
constructor() {
|
|
5
9
|
this._matNsid = "";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Container, GameObject } from "@tabletop-playground/api";
|
|
2
|
+
import { GarbageHandler } from "./garbage-container";
|
|
3
|
+
export declare class SimpleToContainerHandler implements GarbageHandler {
|
|
4
|
+
private readonly _playerSlotToContainer;
|
|
5
|
+
private readonly _recycleObjectNsids;
|
|
6
|
+
private _requirePlayerSlot;
|
|
7
|
+
private _containerNsid;
|
|
8
|
+
addRecycleObjectNsid(nsid: string): this;
|
|
9
|
+
setContainerNsid(nsid: string): this;
|
|
10
|
+
setRequireOwningPlayerSlot(value: boolean): this;
|
|
11
|
+
canRecycle(obj: GameObject): boolean;
|
|
12
|
+
recycle(obj: GameObject): boolean;
|
|
13
|
+
_getContainer(obj: GameObject): Container | undefined;
|
|
14
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Container, world } from "@tabletop-playground/api";
|
|
2
|
+
import { NSID } from "../nsid/nsid";
|
|
3
|
+
export class SimpleToContainerHandler {
|
|
4
|
+
constructor() {
|
|
5
|
+
this._playerSlotToContainer = {};
|
|
6
|
+
this._recycleObjectNsids = new Set();
|
|
7
|
+
this._requirePlayerSlot = false;
|
|
8
|
+
this._containerNsid = "";
|
|
9
|
+
}
|
|
10
|
+
addRecycleObjectNsid(nsid) {
|
|
11
|
+
this._recycleObjectNsids.add(nsid);
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
setContainerNsid(nsid) {
|
|
15
|
+
this._containerNsid = nsid;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
setRequireOwningPlayerSlot(value) {
|
|
19
|
+
this._requirePlayerSlot = value;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
canRecycle(obj) {
|
|
23
|
+
const nsid = NSID.get(obj);
|
|
24
|
+
return this._recycleObjectNsids.has(nsid);
|
|
25
|
+
}
|
|
26
|
+
recycle(obj) {
|
|
27
|
+
const container = this._getContainer(obj);
|
|
28
|
+
if (!container) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
container.addObjects([obj]);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
_getContainer(obj) {
|
|
35
|
+
const isMatch = (container) => {
|
|
36
|
+
if (!container.isValid()) {
|
|
37
|
+
return false; // deleted!
|
|
38
|
+
}
|
|
39
|
+
const containerNsid = NSID.get(container);
|
|
40
|
+
if (containerNsid !== this._containerNsid) {
|
|
41
|
+
return false; // wrong container type
|
|
42
|
+
}
|
|
43
|
+
if (this._requirePlayerSlot) {
|
|
44
|
+
const objSlot = obj.getOwningPlayerSlot();
|
|
45
|
+
const containerSlot = container.getOwningPlayerSlot();
|
|
46
|
+
if (objSlot !== containerSlot) {
|
|
47
|
+
return false; // wrong owning player slot
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
};
|
|
52
|
+
// Use cache if valid.
|
|
53
|
+
const cacheKey = this._requirePlayerSlot ? obj.getOwningPlayerSlot() : -1;
|
|
54
|
+
const cached = this._playerSlotToContainer[cacheKey];
|
|
55
|
+
if (cached && isMatch(cached)) {
|
|
56
|
+
return cached;
|
|
57
|
+
}
|
|
58
|
+
// Search for container.
|
|
59
|
+
const skipContained = true;
|
|
60
|
+
for (const obj of world.getAllObjects(skipContained)) {
|
|
61
|
+
if (!(obj instanceof Container)) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (isMatch(obj)) {
|
|
65
|
+
this._playerSlotToContainer[cacheKey] = obj;
|
|
66
|
+
return obj;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GameObject, SnapPoint } from "@tabletop-playground/api";
|
|
2
|
+
import { GarbageHandler } from "./garbage-container";
|
|
3
|
+
/**
|
|
4
|
+
* Recycle an object to a specific snap point with the matching tag.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SimpleToSnapPointHandler implements GarbageHandler {
|
|
7
|
+
private readonly _recycleObjectNsids;
|
|
8
|
+
private _matNsid;
|
|
9
|
+
private _snapPointTag;
|
|
10
|
+
private _cachedSnapPoint;
|
|
11
|
+
addRecycleObjectNsid(nsid: string): this;
|
|
12
|
+
setMatNsid(nsid: string): this;
|
|
13
|
+
setSnapPointTag(tag: string): this;
|
|
14
|
+
canRecycle(obj: GameObject): boolean;
|
|
15
|
+
recycle(obj: GameObject): boolean;
|
|
16
|
+
_getSnapPoint(): SnapPoint | undefined;
|
|
17
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { world } from "@tabletop-playground/api";
|
|
2
|
+
import { NSID } from "../nsid/nsid";
|
|
3
|
+
/**
|
|
4
|
+
* Recycle an object to a specific snap point with the matching tag.
|
|
5
|
+
*/
|
|
6
|
+
export class SimpleToSnapPointHandler {
|
|
7
|
+
constructor() {
|
|
8
|
+
this._recycleObjectNsids = new Set();
|
|
9
|
+
this._matNsid = "";
|
|
10
|
+
this._snapPointTag = "";
|
|
11
|
+
}
|
|
12
|
+
addRecycleObjectNsid(nsid) {
|
|
13
|
+
this._recycleObjectNsids.add(nsid);
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
setMatNsid(nsid) {
|
|
17
|
+
this._matNsid = nsid;
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
setSnapPointTag(tag) {
|
|
21
|
+
this._snapPointTag = tag;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
canRecycle(obj) {
|
|
25
|
+
const nsid = NSID.get(obj);
|
|
26
|
+
return this._recycleObjectNsids.has(nsid);
|
|
27
|
+
}
|
|
28
|
+
recycle(obj) {
|
|
29
|
+
const snapPoint = this._getSnapPoint();
|
|
30
|
+
if (!snapPoint) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
// Reject if something already snapped there.
|
|
34
|
+
const otherObj = snapPoint.getSnappedObject();
|
|
35
|
+
if (otherObj && otherObj.getSnappedToPoint() === snapPoint) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
obj.setPosition(snapPoint.getGlobalPosition().add([0, 0, 10]));
|
|
39
|
+
obj.snapToGround(); // get in range
|
|
40
|
+
obj.snap();
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
_getSnapPoint() {
|
|
44
|
+
var _a;
|
|
45
|
+
// Use cache if valid.
|
|
46
|
+
if (this._cachedSnapPoint &&
|
|
47
|
+
((_a = this._cachedSnapPoint.getParentObject()) === null || _a === void 0 ? void 0 : _a.isValid())) {
|
|
48
|
+
return this._cachedSnapPoint;
|
|
49
|
+
}
|
|
50
|
+
// Search for mat.
|
|
51
|
+
const skipContained = true;
|
|
52
|
+
for (const obj of world.getAllObjects(skipContained)) {
|
|
53
|
+
const nsid = NSID.get(obj);
|
|
54
|
+
if (nsid !== this._matNsid) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
for (const snapPoint of obj.getAllSnapPoints()) {
|
|
58
|
+
if (snapPoint.getTags().includes(this._snapPointTag)) {
|
|
59
|
+
this._cachedSnapPoint = snapPoint;
|
|
60
|
+
return snapPoint;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -25,7 +25,7 @@ export declare class LayoutObjects {
|
|
|
25
25
|
setOverrideHeight(value: number): this;
|
|
26
26
|
setOverrideWidth(value: number): this;
|
|
27
27
|
add(item: GameObject | LayoutObjects): this;
|
|
28
|
-
addAfterLayout(f: () =>
|
|
28
|
+
addAfterLayout(f: () => void): this;
|
|
29
29
|
flip(flipH: boolean, flipV: boolean): this;
|
|
30
30
|
/**
|
|
31
31
|
* Get size of self, applying any overrides.
|