ttpg-darrell 1.0.2 → 1.0.3

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.
@@ -11,6 +11,7 @@ export declare class LayoutObjects {
11
11
  private _isVertical;
12
12
  private _overrideHeight;
13
13
  private _overrideWidth;
14
+ private _layoutCenter;
14
15
  constructor();
15
16
  setChildDistanace(value: number): this;
16
17
  setHorizontalAlignment(value: number): this;
@@ -33,6 +34,7 @@ export declare class LayoutObjects {
33
34
  calculateChildrenSize(): LayoutObjectsSize;
34
35
  static _calculateChildSize(child: StaticObject | LayoutObjects): LayoutObjectsSize;
35
36
  doLayoutAtPoint(center: Vector, yaw: number): this;
37
+ getCenter(): Vector;
36
38
  layoutLeftOf(peer: StaticObject, gap: number): this;
37
39
  layoutRightOf(peer: StaticObject, gap: number): this;
38
40
  layoutAbove(peer: StaticObject, gap: number): this;
@@ -11,6 +11,7 @@ class LayoutObjects {
11
11
  this._isVertical = false;
12
12
  this._overrideHeight = 0;
13
13
  this._overrideWidth = 0;
14
+ this._layoutCenter = new api_1.Vector(0, 0, 0);
14
15
  }
15
16
  setChildDistanace(value) {
16
17
  this._childDistance = value;
@@ -99,6 +100,7 @@ class LayoutObjects {
99
100
  return childSize;
100
101
  }
101
102
  doLayoutAtPoint(center, yaw) {
103
+ this._layoutCenter = center;
102
104
  const size = this.calculateSize();
103
105
  const childrenSize = this.calculateChildrenSize();
104
106
  let padLeft;
@@ -147,6 +149,9 @@ class LayoutObjects {
147
149
  }
148
150
  return this;
149
151
  }
152
+ getCenter() {
153
+ return this._layoutCenter;
154
+ }
150
155
  layoutLeftOf(peer, gap) {
151
156
  const peerSize = LayoutObjects._calculateChildSize(peer);
152
157
  const size = this.calculateSize();
@@ -5,6 +5,7 @@ import { GameObject, Vector } from "@tabletop-playground/api";
5
5
  export declare abstract class Spawn {
6
6
  private static _nsidToTemplateId;
7
7
  static spawn(nsid: string, position: Vector | [x: number, y: number, z: number]): GameObject | undefined;
8
+ static spawnOrThrow(nsid: string, position: Vector | [x: number, y: number, z: number]): GameObject;
8
9
  static inject(dict: {
9
10
  [key: string]: string;
10
11
  }): void;
@@ -9,11 +9,18 @@ class Spawn {
9
9
  static spawn(nsid, position) {
10
10
  const templateId = Spawn._nsidToTemplateId[nsid];
11
11
  if (!templateId) {
12
- throw new Error(`spawn nsid "${nsid}" has no templateId`);
12
+ return undefined;
13
13
  }
14
14
  const obj = api_1.world.createObjectFromTemplate(templateId, position);
15
15
  return obj;
16
16
  }
17
+ static spawnOrThrow(nsid, position) {
18
+ const obj = Spawn.spawn(nsid, position);
19
+ if (!obj) {
20
+ throw new Error(`spawnOrThrow failed for "${nsid}"`);
21
+ }
22
+ return obj;
23
+ }
17
24
  static inject(dict) {
18
25
  for (const [k, v] of Object.entries(dict)) {
19
26
  Spawn._nsidToTemplateId[k] = v;
@@ -11,6 +11,7 @@ export declare class LayoutObjects {
11
11
  private _isVertical;
12
12
  private _overrideHeight;
13
13
  private _overrideWidth;
14
+ private _layoutCenter;
14
15
  constructor();
15
16
  setChildDistanace(value: number): this;
16
17
  setHorizontalAlignment(value: number): this;
@@ -33,6 +34,7 @@ export declare class LayoutObjects {
33
34
  calculateChildrenSize(): LayoutObjectsSize;
34
35
  static _calculateChildSize(child: StaticObject | LayoutObjects): LayoutObjectsSize;
35
36
  doLayoutAtPoint(center: Vector, yaw: number): this;
37
+ getCenter(): Vector;
36
38
  layoutLeftOf(peer: StaticObject, gap: number): this;
37
39
  layoutRightOf(peer: StaticObject, gap: number): this;
38
40
  layoutAbove(peer: StaticObject, gap: number): this;
@@ -8,6 +8,7 @@ export class LayoutObjects {
8
8
  this._isVertical = false;
9
9
  this._overrideHeight = 0;
10
10
  this._overrideWidth = 0;
11
+ this._layoutCenter = new Vector(0, 0, 0);
11
12
  }
12
13
  setChildDistanace(value) {
13
14
  this._childDistance = value;
@@ -96,6 +97,7 @@ export class LayoutObjects {
96
97
  return childSize;
97
98
  }
98
99
  doLayoutAtPoint(center, yaw) {
100
+ this._layoutCenter = center;
99
101
  const size = this.calculateSize();
100
102
  const childrenSize = this.calculateChildrenSize();
101
103
  let padLeft;
@@ -144,6 +146,9 @@ export class LayoutObjects {
144
146
  }
145
147
  return this;
146
148
  }
149
+ getCenter() {
150
+ return this._layoutCenter;
151
+ }
147
152
  layoutLeftOf(peer, gap) {
148
153
  const peerSize = LayoutObjects._calculateChildSize(peer);
149
154
  const size = this.calculateSize();
@@ -5,6 +5,7 @@ import { GameObject, Vector } from "@tabletop-playground/api";
5
5
  export declare abstract class Spawn {
6
6
  private static _nsidToTemplateId;
7
7
  static spawn(nsid: string, position: Vector | [x: number, y: number, z: number]): GameObject | undefined;
8
+ static spawnOrThrow(nsid: string, position: Vector | [x: number, y: number, z: number]): GameObject;
8
9
  static inject(dict: {
9
10
  [key: string]: string;
10
11
  }): void;
@@ -6,11 +6,18 @@ export class Spawn {
6
6
  static spawn(nsid, position) {
7
7
  const templateId = Spawn._nsidToTemplateId[nsid];
8
8
  if (!templateId) {
9
- throw new Error(`spawn nsid "${nsid}" has no templateId`);
9
+ return undefined;
10
10
  }
11
11
  const obj = world.createObjectFromTemplate(templateId, position);
12
12
  return obj;
13
13
  }
14
+ static spawnOrThrow(nsid, position) {
15
+ const obj = Spawn.spawn(nsid, position);
16
+ if (!obj) {
17
+ throw new Error(`spawnOrThrow failed for "${nsid}"`);
18
+ }
19
+ return obj;
20
+ }
14
21
  static inject(dict) {
15
22
  for (const [k, v] of Object.entries(dict)) {
16
23
  Spawn._nsidToTemplateId[k] = v;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ttpg-darrell",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "TTPG TypeScript library",
5
5
  "main": "./build/cjs/index.js",
6
6
  "module": "./build/esm/index.js",