ttpg-darrell 1.0.3 → 1.0.4

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
1
  import { StaticObject, Vector } from "@tabletop-playground/api";
2
+ import { TriggerableMulticastDelegate } from "../triggerable-multicast-delegate/triggerable-multicast-delegate";
2
3
  export type LayoutObjectsSize = {
3
4
  w: number;
4
5
  h: number;
@@ -12,6 +13,7 @@ export declare class LayoutObjects {
12
13
  private _overrideHeight;
13
14
  private _overrideWidth;
14
15
  private _layoutCenter;
16
+ readonly afterLayout: TriggerableMulticastDelegate<unknown>;
15
17
  constructor();
16
18
  setChildDistanace(value: number): this;
17
19
  setHorizontalAlignment(value: number): this;
@@ -20,6 +22,7 @@ export declare class LayoutObjects {
20
22
  setOverrideHeight(value: number): this;
21
23
  setOverrideWidth(value: number): this;
22
24
  add(item: StaticObject | LayoutObjects): this;
25
+ flip(flipH: boolean, flipV: boolean): this;
23
26
  /**
24
27
  * Get size of self, applying any overrides.
25
28
  *
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LayoutObjects = 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 LayoutObjects {
6
7
  constructor() {
7
8
  this._children = [];
@@ -12,6 +13,7 @@ class LayoutObjects {
12
13
  this._overrideHeight = 0;
13
14
  this._overrideWidth = 0;
14
15
  this._layoutCenter = new api_1.Vector(0, 0, 0);
16
+ this.afterLayout = new triggerable_multicast_delegate_1.TriggerableMulticastDelegate();
15
17
  }
16
18
  setChildDistanace(value) {
17
19
  this._childDistance = value;
@@ -42,6 +44,36 @@ class LayoutObjects {
42
44
  this._children.push(item);
43
45
  return this;
44
46
  }
47
+ flip(flipH, flipV) {
48
+ // Children.
49
+ if ((flipH && !this._isVertical) || (flipV && this._isVertical)) {
50
+ this._children.reverse();
51
+ }
52
+ // Layout.
53
+ if (flipH) {
54
+ if (this._horizontalAlignment === api_1.HorizontalAlignment.Left) {
55
+ this._horizontalAlignment = api_1.HorizontalAlignment.Right;
56
+ }
57
+ else if (this._horizontalAlignment === api_1.HorizontalAlignment.Right) {
58
+ this._horizontalAlignment = api_1.HorizontalAlignment.Left;
59
+ }
60
+ }
61
+ if (flipV) {
62
+ if (this._verticalAlignment === api_1.VerticalAlignment.Top) {
63
+ this._verticalAlignment = api_1.VerticalAlignment.Bottom;
64
+ }
65
+ else if (this._verticalAlignment === api_1.VerticalAlignment.Bottom) {
66
+ this._verticalAlignment = api_1.VerticalAlignment.Top;
67
+ }
68
+ }
69
+ // Recurse.
70
+ for (const child of this._children) {
71
+ if (child instanceof LayoutObjects) {
72
+ child.flip(flipH, flipV);
73
+ }
74
+ }
75
+ return this;
76
+ }
45
77
  /**
46
78
  * Get size of self, applying any overrides.
47
79
  *
@@ -101,34 +133,60 @@ class LayoutObjects {
101
133
  }
102
134
  doLayoutAtPoint(center, yaw) {
103
135
  this._layoutCenter = center;
104
- const size = this.calculateSize();
136
+ const overrideSize = this.calculateSize();
105
137
  const childrenSize = this.calculateChildrenSize();
138
+ // Position accounting for override size.
106
139
  let padLeft;
140
+ let padTop;
107
141
  if (this._horizontalAlignment === api_1.HorizontalAlignment.Left) {
108
142
  padLeft = 0;
109
143
  }
110
144
  else if (this._horizontalAlignment === api_1.HorizontalAlignment.Right) {
111
- padLeft = size.w - childrenSize.w;
145
+ padLeft = overrideSize.w - childrenSize.w;
112
146
  }
113
147
  else {
114
- padLeft = (size.w - childrenSize.w) / 2; // center (even if "Fill")
148
+ padLeft = (overrideSize.w - childrenSize.w) / 2; // center (even if "Fill")
115
149
  }
116
- let padTop;
117
150
  if (this._verticalAlignment === api_1.VerticalAlignment.Top) {
118
151
  padTop = 0;
119
152
  }
120
153
  else if (this._verticalAlignment === api_1.VerticalAlignment.Bottom) {
121
- padTop = size.w - childrenSize.w;
154
+ padTop = overrideSize.h - childrenSize.h;
122
155
  }
123
156
  else {
124
- padTop = (size.w - childrenSize.w) / 2; // center (even if "Fill")
157
+ padTop = (overrideSize.h - childrenSize.h) / 2; // center (even if "Fill")
125
158
  }
126
- let left = -size.w / 2 + padLeft;
127
- let top = -size.h / 2 + padTop;
159
+ let left = -overrideSize.w / 2 + padLeft;
160
+ let top = overrideSize.h / 2 - padTop;
128
161
  for (const child of this._children) {
129
162
  const childSize = LayoutObjects._calculateChildSize(child);
163
+ // Apply layout in row/col.
164
+ padLeft = 0;
165
+ padTop = 0;
166
+ if (this._isVertical) {
167
+ if (this._horizontalAlignment === api_1.HorizontalAlignment.Left) {
168
+ padLeft = 0;
169
+ }
170
+ else if (this._horizontalAlignment === api_1.HorizontalAlignment.Right) {
171
+ padLeft = childrenSize.w - childSize.w;
172
+ }
173
+ else {
174
+ padLeft = (childrenSize.w - childSize.w) / 2; // center (even if "Fill")
175
+ }
176
+ }
177
+ else {
178
+ if (this._verticalAlignment === api_1.VerticalAlignment.Top) {
179
+ padTop = 0;
180
+ }
181
+ else if (this._verticalAlignment === api_1.VerticalAlignment.Bottom) {
182
+ padTop = childrenSize.h - childSize.h;
183
+ }
184
+ else {
185
+ padTop = (childrenSize.h - childSize.h) / 2; // center (even if "Fill")
186
+ }
187
+ }
130
188
  // Calculate child center (world).
131
- const childCenter = new api_1.Vector(top + childSize.h / 2, left + childSize.w / 2, 0)
189
+ const childCenter = new api_1.Vector(top - childSize.h / 2 - padTop, left + childSize.w / 2 + padLeft, 0)
132
190
  .rotateAngleAxis(yaw, [0, 0, 1])
133
191
  .add(center);
134
192
  // Position child.
@@ -141,12 +199,13 @@ class LayoutObjects {
141
199
  }
142
200
  // Move "cursor" to next open spot top-left.
143
201
  if (this._isVertical) {
144
- top += childSize.h + this._childDistance;
202
+ top -= childSize.h + this._childDistance;
145
203
  }
146
204
  else {
147
205
  left += childSize.w + this._childDistance;
148
206
  }
149
207
  }
208
+ this.afterLayout.trigger();
150
209
  return this;
151
210
  }
152
211
  getCenter() {
@@ -1,4 +1,5 @@
1
1
  import { StaticObject, Vector } from "@tabletop-playground/api";
2
+ import { TriggerableMulticastDelegate } from "../triggerable-multicast-delegate/triggerable-multicast-delegate";
2
3
  export type LayoutObjectsSize = {
3
4
  w: number;
4
5
  h: number;
@@ -12,6 +13,7 @@ export declare class LayoutObjects {
12
13
  private _overrideHeight;
13
14
  private _overrideWidth;
14
15
  private _layoutCenter;
16
+ readonly afterLayout: TriggerableMulticastDelegate<unknown>;
15
17
  constructor();
16
18
  setChildDistanace(value: number): this;
17
19
  setHorizontalAlignment(value: number): this;
@@ -20,6 +22,7 @@ export declare class LayoutObjects {
20
22
  setOverrideHeight(value: number): this;
21
23
  setOverrideWidth(value: number): this;
22
24
  add(item: StaticObject | LayoutObjects): this;
25
+ flip(flipH: boolean, flipV: boolean): this;
23
26
  /**
24
27
  * Get size of self, applying any overrides.
25
28
  *
@@ -1,4 +1,5 @@
1
1
  import { HorizontalAlignment, StaticObject, Vector, VerticalAlignment, } from "@tabletop-playground/api";
2
+ import { TriggerableMulticastDelegate } from "../triggerable-multicast-delegate/triggerable-multicast-delegate";
2
3
  export class LayoutObjects {
3
4
  constructor() {
4
5
  this._children = [];
@@ -9,6 +10,7 @@ export class LayoutObjects {
9
10
  this._overrideHeight = 0;
10
11
  this._overrideWidth = 0;
11
12
  this._layoutCenter = new Vector(0, 0, 0);
13
+ this.afterLayout = new TriggerableMulticastDelegate();
12
14
  }
13
15
  setChildDistanace(value) {
14
16
  this._childDistance = value;
@@ -39,6 +41,36 @@ export class LayoutObjects {
39
41
  this._children.push(item);
40
42
  return this;
41
43
  }
44
+ flip(flipH, flipV) {
45
+ // Children.
46
+ if ((flipH && !this._isVertical) || (flipV && this._isVertical)) {
47
+ this._children.reverse();
48
+ }
49
+ // Layout.
50
+ if (flipH) {
51
+ if (this._horizontalAlignment === HorizontalAlignment.Left) {
52
+ this._horizontalAlignment = HorizontalAlignment.Right;
53
+ }
54
+ else if (this._horizontalAlignment === HorizontalAlignment.Right) {
55
+ this._horizontalAlignment = HorizontalAlignment.Left;
56
+ }
57
+ }
58
+ if (flipV) {
59
+ if (this._verticalAlignment === VerticalAlignment.Top) {
60
+ this._verticalAlignment = VerticalAlignment.Bottom;
61
+ }
62
+ else if (this._verticalAlignment === VerticalAlignment.Bottom) {
63
+ this._verticalAlignment = VerticalAlignment.Top;
64
+ }
65
+ }
66
+ // Recurse.
67
+ for (const child of this._children) {
68
+ if (child instanceof LayoutObjects) {
69
+ child.flip(flipH, flipV);
70
+ }
71
+ }
72
+ return this;
73
+ }
42
74
  /**
43
75
  * Get size of self, applying any overrides.
44
76
  *
@@ -98,34 +130,60 @@ export class LayoutObjects {
98
130
  }
99
131
  doLayoutAtPoint(center, yaw) {
100
132
  this._layoutCenter = center;
101
- const size = this.calculateSize();
133
+ const overrideSize = this.calculateSize();
102
134
  const childrenSize = this.calculateChildrenSize();
135
+ // Position accounting for override size.
103
136
  let padLeft;
137
+ let padTop;
104
138
  if (this._horizontalAlignment === HorizontalAlignment.Left) {
105
139
  padLeft = 0;
106
140
  }
107
141
  else if (this._horizontalAlignment === HorizontalAlignment.Right) {
108
- padLeft = size.w - childrenSize.w;
142
+ padLeft = overrideSize.w - childrenSize.w;
109
143
  }
110
144
  else {
111
- padLeft = (size.w - childrenSize.w) / 2; // center (even if "Fill")
145
+ padLeft = (overrideSize.w - childrenSize.w) / 2; // center (even if "Fill")
112
146
  }
113
- let padTop;
114
147
  if (this._verticalAlignment === VerticalAlignment.Top) {
115
148
  padTop = 0;
116
149
  }
117
150
  else if (this._verticalAlignment === VerticalAlignment.Bottom) {
118
- padTop = size.w - childrenSize.w;
151
+ padTop = overrideSize.h - childrenSize.h;
119
152
  }
120
153
  else {
121
- padTop = (size.w - childrenSize.w) / 2; // center (even if "Fill")
154
+ padTop = (overrideSize.h - childrenSize.h) / 2; // center (even if "Fill")
122
155
  }
123
- let left = -size.w / 2 + padLeft;
124
- let top = -size.h / 2 + padTop;
156
+ let left = -overrideSize.w / 2 + padLeft;
157
+ let top = overrideSize.h / 2 - padTop;
125
158
  for (const child of this._children) {
126
159
  const childSize = LayoutObjects._calculateChildSize(child);
160
+ // Apply layout in row/col.
161
+ padLeft = 0;
162
+ padTop = 0;
163
+ if (this._isVertical) {
164
+ if (this._horizontalAlignment === HorizontalAlignment.Left) {
165
+ padLeft = 0;
166
+ }
167
+ else if (this._horizontalAlignment === HorizontalAlignment.Right) {
168
+ padLeft = childrenSize.w - childSize.w;
169
+ }
170
+ else {
171
+ padLeft = (childrenSize.w - childSize.w) / 2; // center (even if "Fill")
172
+ }
173
+ }
174
+ else {
175
+ if (this._verticalAlignment === VerticalAlignment.Top) {
176
+ padTop = 0;
177
+ }
178
+ else if (this._verticalAlignment === VerticalAlignment.Bottom) {
179
+ padTop = childrenSize.h - childSize.h;
180
+ }
181
+ else {
182
+ padTop = (childrenSize.h - childSize.h) / 2; // center (even if "Fill")
183
+ }
184
+ }
127
185
  // Calculate child center (world).
128
- const childCenter = new Vector(top + childSize.h / 2, left + childSize.w / 2, 0)
186
+ const childCenter = new Vector(top - childSize.h / 2 - padTop, left + childSize.w / 2 + padLeft, 0)
129
187
  .rotateAngleAxis(yaw, [0, 0, 1])
130
188
  .add(center);
131
189
  // Position child.
@@ -138,12 +196,13 @@ export class LayoutObjects {
138
196
  }
139
197
  // Move "cursor" to next open spot top-left.
140
198
  if (this._isVertical) {
141
- top += childSize.h + this._childDistance;
199
+ top -= childSize.h + this._childDistance;
142
200
  }
143
201
  else {
144
202
  left += childSize.w + this._childDistance;
145
203
  }
146
204
  }
205
+ this.afterLayout.trigger();
147
206
  return this;
148
207
  }
149
208
  getCenter() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ttpg-darrell",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "TTPG TypeScript library",
5
5
  "main": "./build/cjs/index.js",
6
6
  "module": "./build/esm/index.js",