@m2c2kit/addons 0.3.8 → 0.3.9

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.ts CHANGED
@@ -30,7 +30,7 @@ declare class Grid extends Composite {
30
30
  cellWidth: number;
31
31
  cellHeight: number;
32
32
  gridChildren: GridChild[];
33
- private gridBackground?;
33
+ private _gridBackground?;
34
34
  /**
35
35
  * A rectangular grid that supports placement of entities within the grid's
36
36
  * cells.
@@ -43,6 +43,8 @@ declare class Grid extends Composite {
43
43
  */
44
44
  constructor(options: GridOptions);
45
45
  initialize(): void;
46
+ private get gridBackground();
47
+ private set gridBackground(value);
46
48
  dispose(): void;
47
49
  /**
48
50
  * Duplicates an entity using deep copy.
@@ -60,7 +62,6 @@ declare class Grid extends Composite {
60
62
  warmup(canvas: Canvas): void;
61
63
  /**
62
64
  * Removes all children from the grid, but retains grid lines.
63
- *
64
65
  */
65
66
  removeAllChildren(): void;
66
67
  /**
package/dist/index.js CHANGED
@@ -48,7 +48,7 @@ class Grid extends Composite {
48
48
  __publicField$3(this, "cellWidth");
49
49
  __publicField$3(this, "cellHeight");
50
50
  __publicField$3(this, "gridChildren", new Array());
51
- __publicField$3(this, "gridBackground");
51
+ __publicField$3(this, "_gridBackground");
52
52
  if (options.size) {
53
53
  this.size = options.size;
54
54
  } else {
@@ -137,6 +137,15 @@ class Grid extends Composite {
137
137
  }
138
138
  this.needsInitialization = false;
139
139
  }
140
+ get gridBackground() {
141
+ if (!this._gridBackground) {
142
+ throw new Error("gridBackground is null or undefined");
143
+ }
144
+ return this._gridBackground;
145
+ }
146
+ set gridBackground(gridBackground) {
147
+ this._gridBackground = gridBackground;
148
+ }
140
149
  // all entities that make up grid are added as children, so they
141
150
  // have their own dispose methods
142
151
  // eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -185,17 +194,18 @@ class Grid extends Composite {
185
194
  }
186
195
  // override Entity.RemoveAllChildren() so that when RemoveAllChildren() is called on a Grid,
187
196
  // it removes only entities added to the grid cells (what we call grid children), not the grid lines!
188
- // note: when we upgrade to typescript 4.3+, we can mark this with override keyword to make intention explicit
189
197
  /**
190
198
  * Removes all children from the grid, but retains grid lines.
191
- *
192
199
  */
193
200
  removeAllChildren() {
194
201
  if (this.gridChildren.length === 0) {
195
202
  return;
196
203
  }
197
204
  while (this.gridChildren.length) {
198
- this.gridChildren.pop();
205
+ const gridChild = this.gridChildren.pop();
206
+ if (gridChild) {
207
+ this.gridBackground.removeChild(gridChild.entity);
208
+ }
199
209
  }
200
210
  this.needsInitialization = true;
201
211
  }
@@ -222,8 +232,17 @@ class Grid extends Composite {
222
232
  * @param column - column position within grid at which to remove children; zero-based indexing
223
233
  */
224
234
  removeAllAtCell(row, column) {
235
+ const gridChildrenToRemove = this.gridChildren.filter(
236
+ (gridChild) => gridChild.row === row && gridChild.column === column
237
+ );
238
+ if (gridChildrenToRemove.length === 0) {
239
+ return;
240
+ }
241
+ this.gridBackground.removeChildren(
242
+ gridChildrenToRemove.map((gridChild) => gridChild.entity)
243
+ );
225
244
  this.gridChildren = this.gridChildren.filter(
226
- (gridChild) => gridChild.row != row && gridChild.column != column
245
+ (gridChild) => gridChild.row !== row && gridChild.column !== column
227
246
  );
228
247
  this.needsInitialization = true;
229
248
  }
@@ -235,9 +254,6 @@ class Grid extends Composite {
235
254
  * @param entity - entity to remove
236
255
  */
237
256
  removeChild(entity) {
238
- if (!this.gridBackground) {
239
- throw new Error("gridBackground is null or undefined");
240
- }
241
257
  this.gridBackground.removeChild(entity);
242
258
  this.gridChildren = this.gridChildren.filter(
243
259
  (gridChild) => gridChild.entity != entity
@@ -1311,7 +1327,7 @@ class Instructions extends Story {
1311
1327
  }
1312
1328
  }
1313
1329
 
1314
- console.log("\u26AA @m2c2kit/addons version 0.3.8 (25099410)");
1330
+ console.log("\u26AA @m2c2kit/addons version 0.3.9 (03abb9e7)");
1315
1331
 
1316
1332
  export { Button, Dialog, DialogResult, Grid, Instructions, VirtualKeyboard };
1317
1333
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m2c2kit/addons",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "Additions to m2c2kit core functionality, such as button, grid, and instructions",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",