@woosh/meep-engine 2.120.1 → 2.120.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.
Files changed (98) hide show
  1. package/README.md +1 -1
  2. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +2 -1
  3. package/editor/view/ecs/EntityEditor.js +2 -1
  4. package/editor/view/makeEntityDecorators.js +5 -5
  5. package/package.json +1 -1
  6. package/src/core/binary/BitSet.d.ts +59 -38
  7. package/src/core/binary/BitSet.d.ts.map +1 -1
  8. package/src/core/binary/BitSet.js +76 -55
  9. package/src/core/function/noop.d.ts +4 -1
  10. package/src/core/function/noop.d.ts.map +1 -1
  11. package/src/core/function/noop.js +4 -1
  12. package/src/core/geom/2d/circle/Circle.d.ts +7 -5
  13. package/src/core/geom/2d/circle/Circle.d.ts.map +1 -1
  14. package/src/core/geom/2d/circle/Circle.js +7 -5
  15. package/src/core/geom/2d/circle/circle_area.d.ts +7 -0
  16. package/src/core/geom/2d/circle/circle_area.d.ts.map +1 -0
  17. package/src/core/geom/2d/circle/circle_area.js +8 -0
  18. package/src/core/geom/Quaternion.d.ts.map +1 -1
  19. package/src/core/geom/Quaternion.js +57 -23
  20. package/src/core/geom/Vector4.d.ts.map +1 -1
  21. package/src/core/geom/Vector4.js +27 -5
  22. package/src/core/math/gaussian.d.ts +5 -4
  23. package/src/core/math/gaussian.d.ts.map +1 -1
  24. package/src/core/math/gaussian.js +5 -4
  25. package/src/core/math/matrix/SquareMatrix.d.ts +55 -32
  26. package/src/core/math/matrix/SquareMatrix.d.ts.map +1 -1
  27. package/src/core/math/matrix/SquareMatrix.js +59 -33
  28. package/src/core/math/spline/spline_hermite3_to_bezier.d.ts +6 -5
  29. package/src/core/math/spline/spline_hermite3_to_bezier.d.ts.map +1 -1
  30. package/src/core/math/spline/spline_hermite3_to_bezier.js +15 -11
  31. package/src/core/model/ModuleRegistry.d.ts.map +1 -1
  32. package/src/core/model/ModuleRegistry.js +2 -2
  33. package/src/engine/EngineConfiguration.js +1 -1
  34. package/src/engine/ecs/Entity.d.ts.map +1 -1
  35. package/src/engine/ecs/Entity.js +44 -4
  36. package/src/engine/ecs/EntityBuilderUtils.js +1 -1
  37. package/src/engine/ecs/EntityComponentDataset.d.ts +1 -1
  38. package/src/engine/ecs/EntityComponentDataset.d.ts.map +1 -1
  39. package/src/engine/ecs/EntityComponentDataset.js +56 -17
  40. package/src/engine/ecs/EntityManager.d.ts.map +1 -1
  41. package/src/engine/ecs/EntityManager.js +16 -13
  42. package/src/engine/ecs/EntityObserver.d.ts.map +1 -1
  43. package/src/engine/ecs/EntityObserver.js +2 -10
  44. package/src/engine/ecs/EntityReference.d.ts +24 -2
  45. package/src/engine/ecs/EntityReference.d.ts.map +1 -1
  46. package/src/engine/ecs/EntityReference.js +42 -6
  47. package/src/engine/ecs/EventType.d.ts +10 -0
  48. package/src/engine/ecs/EventType.d.ts.map +1 -0
  49. package/src/engine/ecs/EventType.js +10 -0
  50. package/src/engine/ecs/System.d.ts.map +1 -1
  51. package/src/engine/ecs/System.js +1 -12
  52. package/src/engine/ecs/computeSystemName.d.ts +8 -0
  53. package/src/engine/ecs/computeSystemName.d.ts.map +1 -0
  54. package/src/engine/ecs/computeSystemName.js +10 -0
  55. package/src/engine/ecs/parent/ParentEntitySystem.js +1 -1
  56. package/src/engine/ecs/terrain/TerrainClouds.d.ts +43 -10
  57. package/src/engine/ecs/terrain/TerrainClouds.d.ts.map +1 -1
  58. package/src/engine/ecs/terrain/TerrainClouds.js +38 -2
  59. package/src/engine/ecs/terrain/ecs/Terrain.d.ts.map +1 -1
  60. package/src/engine/ecs/terrain/ecs/Terrain.js +6 -0
  61. package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.d.ts.map +1 -1
  62. package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +3 -1
  63. package/src/engine/graphics/ecs/path/ribbon/RibbonPathBuilder.d.ts.map +1 -1
  64. package/src/engine/graphics/ecs/path/ribbon/RibbonPathBuilder.js +7 -7
  65. package/src/engine/graphics/texture/sampler/Sampler2D.d.ts +349 -50
  66. package/src/engine/input/devices/InputDeviceSwitch.d.ts +4 -0
  67. package/src/engine/input/devices/InputDeviceSwitch.d.ts.map +1 -1
  68. package/src/engine/input/devices/InputDeviceSwitch.js +4 -2
  69. package/src/engine/input/devices/KeyCodes.d.ts.map +1 -1
  70. package/src/engine/input/devices/KeyCodes.js +1 -0
  71. package/src/engine/input/devices/KeyboardDevice.d.ts.map +1 -1
  72. package/src/engine/input/devices/KeyboardDevice.js +28 -3
  73. package/src/engine/intelligence/behavior/ecs/DieBehavior.d.ts +3 -0
  74. package/src/engine/intelligence/behavior/ecs/DieBehavior.d.ts.map +1 -1
  75. package/src/engine/intelligence/behavior/ecs/DieBehavior.js +4 -0
  76. package/src/engine/intelligence/behavior/ecs/KillBehavior.d.ts +17 -0
  77. package/src/engine/intelligence/behavior/ecs/KillBehavior.d.ts.map +1 -0
  78. package/src/engine/intelligence/behavior/ecs/KillBehavior.js +47 -0
  79. package/src/engine/knowledge/database/StaticKnowledgeDataTable.d.ts.map +1 -1
  80. package/src/engine/knowledge/database/StaticKnowledgeDataTable.js +3 -0
  81. package/src/engine/ui/notification/NotificationManager.d.ts.map +1 -1
  82. package/src/engine/ui/notification/NotificationManager.js +2 -1
  83. package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.d.ts +7 -6
  84. package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.d.ts.map +1 -1
  85. package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.js +51 -43
  86. package/editor/actions/concrete/ModifyPatchSampler2DAction.d.ts +0 -48
  87. package/editor/actions/concrete/ModifyPatchTextureArray2DAction.d.ts.map +0 -1
  88. package/editor/actions/concrete/PaintTerrainOverlayAction.d.ts.map +0 -1
  89. package/editor/actions/concrete/PatchTerrainHeightAction.d.ts.map +0 -1
  90. package/editor/actions/concrete/SelectionAddAction.d.ts.map +0 -1
  91. package/editor/actions/concrete/SelectionClearAction.d.ts.map +0 -1
  92. package/editor/actions/concrete/SelectionRemoveAction.d.ts.map +0 -1
  93. package/editor/actions/concrete/TransformModifyAction.d.ts.map +0 -1
  94. package/editor/actions/concrete/WriteGridValueAction.d.ts.map +0 -1
  95. package/src/engine/ecs/read_entity_reference.d.ts +0 -9
  96. package/src/engine/ecs/read_entity_reference.d.ts.map +0 -1
  97. package/src/engine/ecs/read_entity_reference.js +0 -15
  98. package/src/engine/ecs/transform/Transform.editor.schema.json +0 -16
@@ -2,11 +2,16 @@ import { assert } from "../../assert.js";
2
2
  import { DataType2TypedArrayConstructorMapping } from "../../binary/type/DataType2TypedArrayConstructorMapping.js";
3
3
  import { array_copy } from "../../collection/array/array_copy.js";
4
4
 
5
+ /**
6
+ * Represents a square matrix (number of rows equals number of columns).
7
+ * Data is stored in a typed array.
8
+ */
5
9
  export class SquareMatrix {
10
+
6
11
  /**
7
- *
8
- * @param {number} size
9
- * @param {BinaryDataType|string} type
12
+ * @param {number} size Side length of the matrix (e.g. '3' for a 3x3 matrix).
13
+ * @param {BinaryDataType|string} type Data type of the elements. Must be a valid BinaryDataType (e.g., "uint8", "float32").
14
+ * @throws {Error} If the provided type is not supported.
10
15
  */
11
16
  constructor(size, type) {
12
17
  assert.isNonNegativeInteger(size, 'size');
@@ -18,51 +23,68 @@ export class SquareMatrix {
18
23
  }
19
24
 
20
25
  /**
21
- *
26
+ * Side length of the matrix.
22
27
  * @type {number}
23
28
  */
24
29
  this.size = size;
25
30
 
26
31
  /**
27
- *
32
+ * Data type of matrix elements.
28
33
  * @type {BinaryDataType}
29
34
  */
30
35
  this.type = type;
31
36
 
32
37
  /**
38
+ * Matrix data, stored as a typed array. Column-major order.
33
39
  * @type {number[]}
34
40
  */
35
41
  this.data = new TypedArray(size * size);
36
42
  }
37
43
 
44
+ /**
45
+ * @returns {number} Side length of the matrix.
46
+ */
38
47
  get n() {
39
48
  return this.size;
40
49
  }
41
50
 
51
+ /**
52
+ * @returns {number} Total number of elements in the matrix (size * size).
53
+ */
42
54
  get length() {
43
55
  return this.size * this.size;
44
56
  }
45
57
 
58
+ /**
59
+ * Returns direct reference to underlying data, modifying it WILL affect the matrix.
60
+ * @returns {number[]}
61
+ */
46
62
  get val() {
47
63
  return this.data;
48
64
  }
49
65
 
66
+ /**
67
+ * Fills the entire matrix with the given value.
68
+ * @param {number} v Value to fill the matrix with.
69
+ * @returns {void}
70
+ */
50
71
  fill(v) {
51
72
  this.data.fill(v);
52
73
  }
53
74
 
54
75
  /**
55
- *
56
- * @param {SquareMatrix} other
76
+ * Subtracts another matrix from this matrix (this = this - other).
77
+ * @param {SquareMatrix} other The matrix to subtract. Must be of the same size.
57
78
  */
58
79
  subtract(other) {
59
80
  this.subtractMatrices(this, other);
60
81
  }
61
82
 
62
83
  /**
63
- * Component-size subtraction
64
- * @param {SquareMatrix} a
65
- * @param {SquareMatrix} b
84
+ * Subtracts matrix 'b' from matrix 'a', storing the result in this matrix (this = a - b).
85
+ * Component-wise operation.
86
+ * @param {SquareMatrix} a The first matrix.
87
+ * @param {SquareMatrix} b The second matrix.
66
88
  */
67
89
  subtractMatrices(a, b) {
68
90
  const size = this.size;
@@ -82,7 +104,7 @@ export class SquareMatrix {
82
104
  }
83
105
 
84
106
  /**
85
- * Individually negate each value in the matrix
107
+ * Negates all elements of the matrix (multiplies each element by -1).
86
108
  */
87
109
  negate() {
88
110
  const data = this.data;
@@ -93,7 +115,7 @@ export class SquareMatrix {
93
115
  }
94
116
 
95
117
  /**
96
- * Set all cells to 0
118
+ * Sets all elements of the matrix to 0.
97
119
  */
98
120
  clear() {
99
121
  this.data.fill(0);
@@ -101,6 +123,7 @@ export class SquareMatrix {
101
123
 
102
124
  /**
103
125
  * Set diagonal to 1
126
+ * NOTE: if the other cells are 0s - it will produce identity matrix, but those cells will not be written explicitly
104
127
  */
105
128
  eye() {
106
129
  const size = this.size;
@@ -111,8 +134,8 @@ export class SquareMatrix {
111
134
  }
112
135
 
113
136
  /**
114
- *
115
- * @param {SquareMatrix} other
137
+ * Copies the elements of another matrix into this matrix.
138
+ * @param {SquareMatrix} other The matrix to copy from. Must be the same size.
116
139
  */
117
140
  copy(other) {
118
141
  assert.equal(this.size, other.size, 'difference sizes');
@@ -121,8 +144,8 @@ export class SquareMatrix {
121
144
  }
122
145
 
123
146
  /**
124
- *
125
- * @return {SquareMatrix}
147
+ * Creates a new matrix that is a copy of this matrix.
148
+ * @returns {SquareMatrix} A new matrix with the same elements.
126
149
  */
127
150
  clone() {
128
151
  const r = new SquareMatrix(this.size, this.type);
@@ -133,7 +156,7 @@ export class SquareMatrix {
133
156
  }
134
157
 
135
158
  /**
136
- * Transpose matrix
159
+ * Transposes the matrix in-place (swaps rows and columns).
137
160
  */
138
161
  transpose() {
139
162
  const size = this.size;
@@ -152,29 +175,33 @@ export class SquareMatrix {
152
175
  }
153
176
 
154
177
  /**
155
- *
156
- * @param {number[]} arr
178
+ * Populates matrix from a 1D array.
179
+ * @param {number[]} arr Source array. Must have at least size*size elements.
157
180
  */
158
181
  fromArray(arr) {
159
182
  this.data.set(arr);
160
183
  }
161
184
 
162
185
  /**
163
- *
164
- * @param {number[]} [destination]
165
- * @param {number} [offset]
186
+ * Copies matrix elements into a 1D array.
187
+ * @param {number[]} [destination] Array to store matrix into. Creates a new array if not provided.
188
+ * @param {number} [offset=0] Starting index in the destination array.
189
+ * @returns {number[]} The array containing the matrix data.
166
190
  */
167
- toArray(destination = new Array(this.length), offset = 0) {
191
+ toArray(
192
+ destination = new Array(this.length),
193
+ offset = 0
194
+ ) {
168
195
  array_copy(this.data, 0, destination, offset, this.length);
169
196
 
170
197
  return destination;
171
198
  }
172
199
 
173
200
  /**
174
- *
175
- * @param {number} row_index
176
- * @param {number} column_index
177
- * @param {number} value
201
+ * Sets the value of a cell in the matrix.
202
+ * @param {number} row_index Row index (0-based).
203
+ * @param {number} column_index Column index (0-based).
204
+ * @param {number} value The value to set.
178
205
  */
179
206
  setCellValue(row_index, column_index, value) {
180
207
  assert.isNonNegativeInteger(row_index, 'row_index');
@@ -189,10 +216,10 @@ export class SquareMatrix {
189
216
  }
190
217
 
191
218
  /**
192
- *
193
- * @param {number} row_index
194
- * @param {number} column_index
195
- * @return {number}
219
+ * Retrieves the value of a cell in the matrix.
220
+ * @param {number} row_index Row index (0-based).
221
+ * @param {number} column_index Column index (0-based).
222
+ * @returns {number} The value of the cell.
196
223
  */
197
224
  getCellValue(row_index, column_index) {
198
225
  assert.isNonNegativeInteger(row_index, 'row_index');
@@ -201,13 +228,12 @@ export class SquareMatrix {
201
228
  assert.lessThan(row_index, this.size, 'row overflow');
202
229
  assert.lessThan(column_index, this.size, 'column overflow');
203
230
 
204
-
205
231
  return this.data[this.size * column_index + row_index];
206
232
  }
207
233
 
208
234
  /**
209
235
  * Read values at the diagonal, from left to right, top to bottom
210
- * @param {number[]|Float32Array|Float64Array} result
236
+ * @param {number[]|Float32Array|Float64Array} result Array to store the diagonal.
211
237
  */
212
238
  readDiagonal(result) {
213
239
  const n = this.size;
@@ -1,12 +1,13 @@
1
1
  /**
2
+ * One-dimensional curve conversion from cubic Hermite to bezier
2
3
  * TODO: not tested
3
- * @param {Float32Array|number[]} result
4
- * @param {number} result_offset
5
- * @param {number} result_stride
4
+ * @param {Float32Array|number[]} result where to put results
5
+ * @param {number} result_offset offset to start writing at in result array
6
+ * @param {number} result_stride how far to step between each written value. Necessary for N-dimensional curves where we want to interleave multiple curves together, such as for color or quaternions
6
7
  * @param {number} p0
7
8
  * @param {number} p1
8
- * @param {number} m0
9
- * @param {number} m1
9
+ * @param {number} m0 tangent at p0
10
+ * @param {number} m1 tangent at p1
10
11
  */
11
12
  export function spline_hermite3_to_bezier(result: Float32Array | number[], result_offset: number, result_stride: number, p0: number, p1: number, m0: number, m1: number): void;
12
13
  //# sourceMappingURL=spline_hermite3_to_bezier.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"spline_hermite3_to_bezier.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/spline/spline_hermite3_to_bezier.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,kDARW,YAAY,GAAC,MAAM,EAAE,iBACrB,MAAM,iBACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QAehB"}
1
+ {"version":3,"file":"spline_hermite3_to_bezier.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/spline/spline_hermite3_to_bezier.js"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,kDARW,YAAY,GAAC,MAAM,EAAE,iBACrB,MAAM,iBACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QAkBhB"}
@@ -1,24 +1,28 @@
1
1
  /**
2
+ * One-dimensional curve conversion from cubic Hermite to bezier
2
3
  * TODO: not tested
3
- * @param {Float32Array|number[]} result
4
- * @param {number} result_offset
5
- * @param {number} result_stride
4
+ * @param {Float32Array|number[]} result where to put results
5
+ * @param {number} result_offset offset to start writing at in result array
6
+ * @param {number} result_stride how far to step between each written value. Necessary for N-dimensional curves where we want to interleave multiple curves together, such as for color or quaternions
6
7
  * @param {number} p0
7
8
  * @param {number} p1
8
- * @param {number} m0
9
- * @param {number} m1
9
+ * @param {number} m0 tangent at p0
10
+ * @param {number} m1 tangent at p1
10
11
  */
11
- export function spline_hermite3_to_bezier(result, result_offset, result_stride, p0, p1, m0, m1) {
12
+ export function spline_hermite3_to_bezier(
13
+ result,
14
+ result_offset,
15
+ result_stride,
16
+ p0, p1,
17
+ m0, m1
18
+ ) {
12
19
 
13
20
  // see https://stackoverflow.com/questions/42574940/draw-hermite-curve-on-browser-canvas-javascript
14
21
  // see https://pomax.github.io/bezierinfo/#catmullconv
15
22
 
16
- const tension = 1;
17
- const tension_factor = 2 * tension;
18
-
19
23
  result[result_offset + 0 * result_stride] = p0;
20
- result[result_offset + 1 * result_stride] = p0 + m0 / tension_factor;
21
- result[result_offset + 2 * result_stride] = p1 - m1 / tension_factor;
24
+ result[result_offset + 1 * result_stride] = p0 + m0 / 3;
25
+ result[result_offset + 2 * result_stride] = p1 - m1 / 3;
22
26
  result[result_offset + 3 * result_stride] = p1;
23
27
 
24
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ModuleRegistry.d.ts","sourceRoot":"","sources":["../../../../src/core/model/ModuleRegistry.js"],"names":[],"mappings":"AAEA;;GAEG;AACH,4BAFa,CAAC;IAeV;;;OAGG;IACH,oCAiBG;IAEH;;;OAGG;IACH,6BAEC;IAGD;;;;OAIG;IACH,IAJiB,CAAC,SAAJ,CAAE,iBAEH,CAAC,CAIb;IAED;;;;OAIG;IACH,UAHW,MAAM,GACJ,OAAO,CAInB;IAED;;;;;OAKG;IACH,IALiB,CAAC,SAAJ,CAAE,QACL,MAAM,UACN,CAAC,GACC,OAAO,CA0BnB;IAED;;;;;;OAMG;IACH,kBALiB,CAAC,SAAJ,CAAE,UACL,CAAC,GACC,MAAM,EAAE,CAYpB;IAED,mBAEC;;CACJ"}
1
+ {"version":3,"file":"ModuleRegistry.d.ts","sourceRoot":"","sources":["../../../../src/core/model/ModuleRegistry.js"],"names":[],"mappings":"AAEA;;GAEG;AACH,4BAFa,CAAC;IAeV;;;OAGG;IACH,oCAiBG;IAEH;;;OAGG;IACH,6BAEC;IAGD;;;;OAIG;IACH,IAJiB,CAAC,SAAJ,CAAE,iBAEH,CAAC,CAIb;IAED;;;;OAIG;IACH,UAHW,MAAM,GACJ,OAAO,CAInB;IAED;;;;;OAKG;IACH,IALiB,CAAC,SAAJ,CAAE,QACL,MAAM,UACN,CAAC,GACC,OAAO,CA0BnB;IAED;;;;;;OAMG;IACH,kBALa,CAAC,UACH,CAAC,GACC,MAAM,EAAE,CAYpB;IAED,mBAEC;;CACJ"}
@@ -100,10 +100,10 @@ export class ModuleRegistry {
100
100
 
101
101
  /**
102
102
  * Find all names associated with the given module
103
- * @template {T} M
103
+ * @template M
104
104
  * @param {M} module
105
105
  * @returns {string[]}
106
- * @throws if module is not registered
106
+ * @throws {Error} if module is not registered
107
107
  */
108
108
  findNamesByModule(module) {
109
109
 
@@ -1,5 +1,5 @@
1
1
  import { assert } from "../core/assert.js";
2
- import { computeSystemName } from "./ecs/System.js";
2
+ import { computeSystemName } from "./ecs/computeSystemName.js";
3
3
 
4
4
  export class EngineConfiguration {
5
5
 
@@ -1 +1 @@
1
- {"version":3,"file":"Entity.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/Entity.js"],"names":[],"mappings":";AAgBA;;;GAGG;AACH;IAgaI;;;;;OAKG;IACH,+BAJW,MAAM,WACN,sBAAsB,GACpB,MAAM,CAgBlB;IAlbD;;;OAGG;IACH,oBAFU,eAAe,CAES;IAWlC;;;OAGG;IACH,UAFW,MAAM,EAIhB;IAdD;;;OAGG;IACH,UAFa,MAAM,CAIlB;IAmBD;;;OAGG;IACH,kBAFW,MAAM,EAIhB;IAfD;;;OAGG;IACH,kBAFa,MAAM,CAIlB;IAWD;;;;OAIG;IACH,2BAAgB;IAQhB;;;OAGG;IACH,SAFU,sBAAsB,CAEjB;IAEf;;;OAGG;IACH,OAFU,WAAW,GAAC,MAAM,CAEN;IAEtB;;;OAGG;IACH,gBAAgB;IAEhB;;OAEG;IACH;;MAEE;IAUF;;;OAGG;IACH,eAFW,MAAM,GAAC,WAAW,QAI5B;IAED;;;;OAIG;IACH,cAHW,MAAM,GAAC,WAAW,GAChB,OAAO,CAMnB;IAED;;;OAGG;IACH,gBAFW,MAAM,GAAC,WAAW,QAI5B;IAED;;;OAGG;IACH,eAFa,OAAO,CAInB;IAED;;OAEG;IACH,4BAQC;IAED;;;OAGG;IACH,aAFY,MAAM,CAIjB;IAED;;;;OAIG;IACH,IAJa,CAAC,qBACH,CAAC,GACC,MAAM,CAiBlB;IAED;;;;OAIG;IACH,aAJa,CAAC,SACH,CAAC,GACC,OAAO,CAInB;IAED;;;;OAIG;IACH,aAJa,CAAC,SACH,KAAK,CAAC,CAAC,CAAC,GACN,CAAC,GAAC,IAAI,CAclB;IAED;;;;;OAKG;IACH,iBAJa,CAAC,SACH,KAAK,CAAC,CAAC,CAAC,GACN,CAAC,CAUb;IAED;;;;OAIG;IACH,kCAFa,GAAC,GAAC,IAAI,CA0BlB;IAED;;;;OAIG;IACH,qBAHW,MAAM,UACN,GAAC,QAQX;IAED;;;OAGG;IACH,wBAFW,MAAM,gBAiBhB;IAED;;;;;;OAMG;IACH,4BALW,MAAM,gCAEN,GAAC,GACC,MAAM,CAalB;IAED;;;;;;OAMG;IACH,+BALW,MAAM,gCAEN,GAAC,GACC,MAAM,CAyBlB;IAED;;;OAGG;IACH,WAFa,OAAO,CAwBnB;IAED;;;;OAIG;IACH,eAFW,sBAAsB,GADpB,MAAM,CAyDlB;IAyBL;;;;OAIG;IACH,mBAFU,OAAO,CAEQ;;CAPxB;gCApc+B,sBAAsB;4BAF1B,kBAAkB;mBAF3B,oCAAoC"}
1
+ {"version":3,"file":"Entity.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/Entity.js"],"names":[],"mappings":";AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH;IAgaI;;;;;OAKG;IACH,+BAJW,MAAM,WACN,sBAAsB,GACpB,MAAM,CAgBlB;IAlbD;;;OAGG;IACH,oBAFU,eAAe,CAES;IAWlC;;;OAGG;IACH,UAFW,MAAM,EAIhB;IAdD;;;OAGG;IACH,UAFa,MAAM,CAIlB;IAmBD;;;OAGG;IACH,kBAFW,MAAM,EAIhB;IAfD;;;OAGG;IACH,kBAFa,MAAM,CAIlB;IAWD;;;;OAIG;IACH,2BAAgB;IAQhB;;;OAGG;IACH,SAFU,sBAAsB,CAEjB;IAEf;;;OAGG;IACH,OAFU,WAAW,GAAC,MAAM,CAEN;IAEtB;;;OAGG;IACH,gBAAgB;IAEhB;;OAEG;IACH;;MAEE;IAUF;;;OAGG;IACH,eAFW,MAAM,GAAC,WAAW,QAI5B;IAED;;;;OAIG;IACH,cAHW,MAAM,GAAC,WAAW,GAChB,OAAO,CAMnB;IAED;;;OAGG;IACH,gBAFW,MAAM,GAAC,WAAW,QAI5B;IAED;;;OAGG;IACH,eAFa,OAAO,CAInB;IAED;;OAEG;IACH,4BAQC;IAED;;;OAGG;IACH,aAFY,MAAM,CAIjB;IAED;;;;OAIG;IACH,IAJa,CAAC,qBACH,CAAC,GACC,MAAM,CAiBlB;IAED;;;;OAIG;IACH,aAJa,CAAC,SACH,CAAC,GACC,OAAO,CAInB;IAED;;;;OAIG;IACH,aAJa,CAAC,SACH,KAAK,CAAC,CAAC,CAAC,GACN,CAAC,GAAC,IAAI,CAclB;IAED;;;;;OAKG;IACH,iBAJa,CAAC,SACH,KAAK,CAAC,CAAC,CAAC,GACN,CAAC,CAUb;IAED;;;;OAIG;IACH,kCAFa,GAAC,GAAC,IAAI,CA0BlB;IAED;;;;OAIG;IACH,qBAHW,MAAM,UACN,GAAC,QAQX;IAED;;;OAGG;IACH,wBAFW,MAAM,gBAiBhB;IAED;;;;;;OAMG;IACH,4BALW,MAAM,gCAEN,GAAC,GACC,MAAM,CAalB;IAED;;;;;;OAMG;IACH,+BALW,MAAM,gCAEN,GAAC,GACC,MAAM,CAyBlB;IAED;;;OAGG;IACH,WAFa,OAAO,CAwBnB;IAED;;;;OAIG;IACH,eAFW,sBAAsB,GADpB,MAAM,CAyDlB;IAyBL;;;;OAIG;IACH,mBAFU,OAAO,CAEQ;;CAPxB;gCA7e+B,sBAAsB;4BAD1B,kBAAkB;mBAF3B,oCAAoC"}
@@ -2,8 +2,8 @@ import { assert } from "../../core/assert.js";
2
2
  import Signal from "../../core/events/signal/Signal.js";
3
3
  import { isDefined } from "../../core/process/matcher/isDefined.js";
4
4
  import { EntityFlags } from "./EntityFlags.js";
5
- import { EventType } from "./EntityManager.js";
6
5
  import { EntityReference } from "./EntityReference.js";
6
+ import { EventType } from "./EventType.js";
7
7
 
8
8
  /**
9
9
  * Set of default flags
@@ -16,7 +16,47 @@ const DEFAULT_FLAGS =
16
16
 
17
17
  /**
18
18
  * Representation of an entity, helps build entities and keep track of them without having to access {@link EntityComponentDataset} directly
19
- * @class
19
+ *
20
+ *
21
+ * @example
22
+ * // Create a new entity (initially has no components).
23
+ * const entity = new Entity();
24
+ *
25
+ * // Define some components (simple data containers).
26
+ * class PositionComponent {
27
+ * constructor(x, y) {
28
+ * this.x = x;
29
+ * this.y = y;
30
+ * }
31
+ * }
32
+ *
33
+ * class VelocityComponent {
34
+ * constructor(x, y) {
35
+ * this.x = x;
36
+ * this.y = y;
37
+ * }
38
+ * }
39
+ *
40
+ * // Add components to the entity.
41
+ * entity.add(new PositionComponent(10, 20));
42
+ * entity.add(new VelocityComponent(1, 2));
43
+
44
+ *
45
+ * // Get a component (would return null if the entity doesn't have it).
46
+ * const position = entity.getComponent(PositionComponent); // { x:10, y:20 }
47
+ *
48
+ * // Remove a component.
49
+ * entity.removeComponent(VelocityComponent);
50
+ *
51
+ * // To actually use the entity in a game, you need to build it using an EntityComponentDataset.
52
+ * const dataset = new EntityComponentDataset(); // You would typically have one already
53
+ *
54
+ * entity.build(dataset);
55
+ * // Now the entity and its components are managed by the ECS.
56
+ *
57
+ * // later, you can destroy the entity:
58
+ * entity.destroy();
59
+ *
20
60
  */
21
61
  class Entity {
22
62
 
@@ -68,7 +108,7 @@ class Entity {
68
108
  components = [];
69
109
 
70
110
  /**
71
- *
111
+ * Listeners added before the entity is build live here
72
112
  * @type {{name:string,listener:(function|Function), context:*}[]}
73
113
  */
74
114
  #deferredListeners = [];
@@ -451,7 +491,7 @@ class Entity {
451
491
 
452
492
  r.dataset = dataset;
453
493
 
454
- r.reference.bind(dataset,entity);
494
+ r.reference.bind(dataset, entity);
455
495
 
456
496
  return r;
457
497
  }
@@ -1,4 +1,4 @@
1
- import { EventType } from "./EntityManager.js";
1
+ import { EventType } from "./EventType.js";
2
2
 
3
3
  /**
4
4
  *
@@ -23,7 +23,7 @@ export class EntityComponentDataset {
23
23
 
24
24
  public createEntitySpecific(entityId: number): void
25
25
 
26
- public removeEntity(entityIndex: number): void
26
+ public removeEntity(entityIndex: number): boolean
27
27
 
28
28
  public removeEntities(entityIndices: number[]): void
29
29
 
@@ -1 +1 @@
1
- {"version":3,"file":"EntityComponentDataset.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityComponentDataset.js"],"names":[],"mappings":"AA2GA;;;;;GAKG;AACH;IAEI;;;OAGG;IACH,wBAA+B;IAE/B;;;;;OAKG;IACH,yBAAsC;IAEtC;;;OAGG;IACH,2BAAkC;IAElC;;;OAGG;IACH,yBAAsB;IAEtB;;;;OAIG;IACH,4BAAgC;IAEhC;;;;OAIG;IACH,2BAAuB;IAEvB;;;OAGG;IACH,mBAAgB;IAEhB;;;;OAIG;IACH,oBAAgB;IAEhB;;;;;;;OAOG;IACH,mBAAe;IAEf;;;OAGG;IACH,0BAFU,MAAM,CAAC,MAAM,CAAC,CAEO;IAE/B;;;OAGG;IACH,0BAFU,MAAM,CAEe;IAG/B;;;;OAIG;IACH,+BAA4B;IAE5B;;;;OAIG;IACH,kCAA+B;IAE/B;;;OAGG;IACH,kBAAe;IAGf;;;;;;OAMG;IACH,iBALa,CAAC,EAAE,CAAC,UACN,GAAG,iBACH,CAAC,GACC,OAAO,CAAC,CAAC,CAAC,CAoCtB;IAED;;;;;OAKG;IACH,sBAJW,cAAc,cACd,OAAO,GACL,OAAO,CAqDnB;IAED;;;;;OAKG;IACH,yBAJW,cAAc,cACd,OAAO,GACL,OAAO,CAuDnB;IAED;;;OAGG;IACH,kBAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,yBAFa,MAAM,CAIlB;IAED;;;;;OAKG;IACH,sBAJW,MAAM,kCAoChB;IAED;;;;OAIG;IACH,8BAFW,MAAM,SAkBhB;IAED;;;;OAIG;IACH,yBAHW,KAAK,EAAE,QAwLjB;IAED;;;;OAIG;IACH,mCAHW,KAAK,EAAE,GACL,OAAO,CAYnB;IAED;;;OAGG;IACH,gCAHW,KAAK,WAAS,GACb,OAAO,CAMlB;IAED;;;OAGG;IACH,uBAFa,KAAK,EAA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;;OAIG;IACH,mBAFW,sBAAsB,iCA6DhC;IAED;;;;OAIG;IACH,+EAiDC;IAED;;;OAGG;IACH,WAFa,OAAO,CAInB;IAED;;;OAGG;IACH,0CAQC;IAGL;;;OAGG;IACH,mCAFU,OAAO,CAEwC;CANxD;mBA1zDkB,oCAAoC"}
1
+ {"version":3,"file":"EntityComponentDataset.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityComponentDataset.js"],"names":[],"mappings":"AA4GA;;;;;;;;;;;;;;;;;GAiBG;AACH;IAEI;;;OAGG;IACH,wBAA+B;IAE/B;;;;;OAKG;IACH,yBAAsC;IAEtC;;;OAGG;IACH,2BAAkC;IAElC;;;OAGG;IACH,yBAAsB;IAEtB;;;;OAIG;IACH,4BAAgC;IAEhC;;;;OAIG;IACH,2BAAuB;IAEvB;;;OAGG;IACH,mBAAgB;IAEhB;;;;OAIG;IACH,oBAAgB;IAEhB;;;;;;;OAOG;IACH,mBAAe;IAEf;;;OAGG;IACH,0BAFU,MAAM,CAAC,MAAM,CAAC,CAEO;IAE/B;;;OAGG;IACH,0BAFU,MAAM,CAEe;IAG/B;;;;OAIG;IACH,+BAA4B;IAE5B;;;;OAIG;IACH,kCAA+B;IAE/B;;;OAGG;IACH,kBAAe;IAGf;;;;;;OAMG;IACH,iBALa,CAAC,EAAE,CAAC,UACN,GAAG,iBACH,CAAC,GACC,OAAO,CAAC,CAAC,CAAC,CAoCtB;IAED;;;;;OAKG;IACH,sBAJW,cAAc,cACd,OAAO,GACL,OAAO,CAqDnB;IAED;;;;;OAKG;IACH,yBAJW,cAAc,cACd,OAAO,GACL,OAAO,CAuDnB;IAED;;;OAGG;IACH,kBAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,yBAFa,MAAM,CAIlB;IAED;;;;;OAKG;IACH,sBAJW,MAAM,kCAoChB;IAED;;;;OAIG;IACH,4BAHW,MAAM,GACJ,EAAE,CAyBd;IAED;;;;OAIG;IACH,yBAHW,KAAK,EAAE,QAwLjB;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GACJ,OAAO,CAenB;IAED;;OAEG;IACH,cAMC;IAED;;;OAGG;IACH,iBAYC;IAED;;;;OAIG;IACH,wBAJa,CAAC,aACH,MAAM,GACJ,IAAI,cAAU,KAAK,CAAC,CAAC,CAAC,CAYlC;IAED;;;;OAIG;IACH,mBAFW,sBAAsB,iCA6DhC;IAED;;;;OAIG;IACH,+EAiDC;IAED;;;OAGG;IACH,WAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,8CAFW,GAAC,QAgBX;IAGL;;;OAGG;IACH,mCAFU,OAAO,CAEwC;CANxD;mBAj2DkB,oCAAoC"}
@@ -9,7 +9,8 @@ import {
9
9
  import Signal from "../../core/events/signal/Signal.js";
10
10
  import { SignalHandler } from "../../core/events/signal/SignalHandler.js";
11
11
  import { max3 } from "../../core/math/max3.js";
12
- import { EventType } from "./EntityManager.js";
12
+
13
+ import { EventType } from "./EventType.js";
13
14
 
14
15
  /**
15
16
  *
@@ -110,6 +111,18 @@ const scratch_array_1 = [];
110
111
  * Entities are just integer IDs and components are stored in a virtual table, where each component type has a separate column and each entity is a row in that table
111
112
  * It is valid for entities to have no components or to have every possible component
112
113
  * Generally the entity IDs are compacted, meaning that when an entity is removed - it's ID will be later reused
114
+ * Typically you would use {@link Entity} helper class instead of working directly with the dataset as it offers a higher-level API
115
+ *
116
+ * @example
117
+ * const ecd = new EntityComponentDataset();
118
+ * // create an entity
119
+ * const entityId = ecd.createEntity();
120
+ *
121
+ * // add a component to your entity
122
+ * ecd.addComponentToEntity(entityId, myComponentInstance);
123
+ *
124
+ * // destroy the entity
125
+ * ecd.removeEntity(entityId);
113
126
  */
114
127
  export class EntityComponentDataset {
115
128
 
@@ -431,22 +444,29 @@ export class EntityComponentDataset {
431
444
 
432
445
  /**
433
446
  * Get all components associated with a given entity
434
- * @returns {Array}
435
- * @param {number} entityIndex
447
+ * @param {number} entity_id
448
+ * @returns {[]} all components attached to the entity, array is not compacted
436
449
  */
437
- getAllComponents(entityIndex) {
438
- assert.ok(this.entityExists(entityIndex), `Entity ${entityIndex} doesn't exist`);
450
+ getAllComponents(entity_id) {
451
+ assert.isNonNegativeInteger(entity_id, 'entity_id');
452
+ assert.ok(this.entityExists(entity_id), `Entity ${entity_id} doesn't exist`);
439
453
 
440
454
  const ret = [];
441
455
 
442
456
  const componentTypeCount = this.componentTypeCount;
443
- const occupancyStart = componentTypeCount * entityIndex;
444
- const occupancyEnd = occupancyStart + componentTypeCount;
457
+ const occupancy_start = componentTypeCount * entity_id;
458
+ const occupancy_end = occupancy_start + componentTypeCount;
445
459
 
446
- for (let i = this.componentOccupancy.nextSetBit(occupancyStart); i < occupancyEnd && i !== -1; i = this.componentOccupancy.nextSetBit(i + 1)) {
460
+ const occupancy = this.componentOccupancy;
461
+
462
+ for (
463
+ let i = occupancy.nextSetBit(occupancy_start);
464
+ i < occupancy_end && i !== -1;
465
+ i = occupancy.nextSetBit(i + 1)
466
+ ) {
447
467
  const componentIndex = i % componentTypeCount;
448
468
 
449
- ret[componentIndex] = this.components[componentIndex][entityIndex];
469
+ ret[componentIndex] = this.components[componentIndex][entity_id];
450
470
  }
451
471
 
452
472
  return ret;
@@ -762,6 +782,8 @@ export class EntityComponentDataset {
762
782
  * @returns {number}
763
783
  */
764
784
  getEntityGeneration(entity_id) {
785
+ assert.isNonNegativeInteger(entity_id, 'entity_id');
786
+
765
787
  return this.entityGeneration[entity_id];
766
788
  }
767
789
 
@@ -836,9 +858,9 @@ export class EntityComponentDataset {
836
858
  }
837
859
 
838
860
  /**
839
- *
861
+ * Remove entity from the dataset, effectively destroying it from the world
840
862
  * @param {number} entity_id
841
- * @returns {boolean}
863
+ * @returns {boolean} true if entity was removed, false if it doesn't exist
842
864
  */
843
865
  removeEntity(entity_id) {
844
866
  if (!this.entityExists(entity_id)) {
@@ -968,7 +990,7 @@ export class EntityComponentDataset {
968
990
  }
969
991
 
970
992
  /**
971
- * @template {T}
993
+ * @template T
972
994
  * @param {T} klass
973
995
  * @returns {number}
974
996
  */
@@ -1017,6 +1039,10 @@ export class EntityComponentDataset {
1017
1039
 
1018
1040
  assert.defined(componentInstance, "componentInstance");
1019
1041
 
1042
+ /**
1043
+ *
1044
+ * @type {Class<C>}
1045
+ */
1020
1046
  const klass = componentInstance.constructor;
1021
1047
 
1022
1048
  const componentTypeIndex = this.__type_to_index_map.get(klass);
@@ -1155,7 +1181,13 @@ export class EntityComponentDataset {
1155
1181
 
1156
1182
  /**
1157
1183
  * Performs traversal on a subset of entities which have specified components.
1158
- * @example traverseEntities([Transform,Renderable,Tag],function(transform, renderable, tag, entity){ ... }, this);
1184
+ * @example
1185
+ * ecd.traverseEntities(
1186
+ * [Transform, Renderable, Tag], // Component classes to match
1187
+ * (transform, renderable, tag, entity ) => { // actual component instances along with entity ID
1188
+ * // do something
1189
+ * }
1190
+ * );
1159
1191
  * @param {Array} classes
1160
1192
  * @param {function(...args):boolean} visitor Visitor can return optional "false" to terminate traversal earlier
1161
1193
  * @param {object} [thisArg] specifies context object on which callbacks are to be called, optional
@@ -1836,7 +1868,7 @@ export class EntityComponentDataset {
1836
1868
  }
1837
1869
 
1838
1870
  /**
1839
- * Tells whether or not dataset has any entities
1871
+ * Tells if dataset has any entities
1840
1872
  * @returns {boolean}
1841
1873
  */
1842
1874
  isEmpty() {
@@ -1846,14 +1878,21 @@ export class EntityComponentDataset {
1846
1878
  /**
1847
1879
  *
1848
1880
  * @param {function(entityIndex:number)} visitor
1881
+ * @param {*} [thisArg]
1849
1882
  */
1850
- traverseEntityIndices(visitor) {
1883
+ traverseEntityIndices(visitor, thisArg) {
1851
1884
  let entityIndex;
1852
1885
 
1853
1886
  const occupancy = this.entityOccupancy;
1854
1887
 
1855
- for (entityIndex = occupancy.nextSetBit(0); entityIndex !== -1; entityIndex = occupancy.nextSetBit(entityIndex + 1)) {
1856
- visitor(entityIndex);
1888
+ for (
1889
+ entityIndex = occupancy.nextSetBit(0);
1890
+ entityIndex !== -1;
1891
+ entityIndex = occupancy.nextSetBit(entityIndex + 1)
1892
+ ) {
1893
+
1894
+ visitor.call(thisArg, entityIndex);
1895
+
1857
1896
  }
1858
1897
  }
1859
1898
  }
@@ -1 +1 @@
1
- {"version":3,"file":"EntityManager.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityManager.js"],"names":[],"mappings":";;;wBAcU,MAAM;;;;;;iCAWN,MAAM;;;;;;;;;AAWhB;IAEI;;;OAGG;IACH,kBAFU,iCAAQ,CAEL;IAEb;;;OAGG;IACH,gCAFU,iCAAQ,CAES;IAE3B;;;OAGG;IACH,0BAFU,cAAc,EAAE,CAEL;IAErB;;OAEG;IACH;;;QAGI;;WAEG;qBADO,MAAM,iCAAQ;;MAI1B;IAEF;;;OAGG;IACH,OAFU,kBAAkB,CAEO;IAEnC;;;;OAIG;IACH,gDAA2C;IAE3C;;;;OAIG;IACH,qBAFU,MAAM,CAEY;IAE5B;;;;;OAKG;IACH,wCAFU,MAAM,CAE4B;IAE5C;;;OAGG;IACH,SAFU,sBAAsB,CAEjB;IAEf;;;;OAIG;IACH,uCAAsC;IAEtC;;;OAGG;IACH,6BA8EC;IAED,sBAcC;IAED;;;OAGG;IACH,uBAFa,KAAK,EAAE,CAuBnB;IAED;;;;;OAKG;IACH,uBAJW,sBAAsB,QA0BhC;IAED;;;;OAIG;IACH,UAJa,CAAC,eACH,KAAK,CAAC,CAAC,CAAC,GACN,OAAO,CAInB;IAED;;;;OAIG;IACH,UAJa,CAAC,eACH,KAAK,CAAC,CAAC,CAAC,GACN,CAAC,GAAC,IAAI,CAgBlB;IAED;;;;;OAKG;IACH,wBAJa,CAAC,aACH,MAAM,GACJ,IAAI,GAAC,KAAK,CAAC,CAAC,CAAC,CAezB;IAGD;;;OAGG;IACH,oBAFW,MAAM,QAkEhB;IAED;;;;;OAKG;IACH,iEA0EC;IAED;;;;OAIG;IACH,uDAFa,OAAO,CAAC,OAAO,CAAC,CAyC5B;IAED;;;;;OAKG;IACH,mBA6BC;IAED;;;;;OAKG;IACH,oBAwCC;IAED;;;;OAIG;IACH,gEAwEC;IAED;;;;OAIG;IACH,2BAHW,KAAK,GACH,OAAO,iCAAS,CA0B5B;IAED;;;;;OAKG;IACH,kCAJW,KAAK,SACL,WAAW,GACT,OAAO,iCAAS,CAsB5B;IAED;;;;OAIG;IACH,iEAkEC;CACJ;uBApyBsD,aAAa;+BADrC,qBAAqB;mBALjC,oCAAoC"}
1
+ {"version":3,"file":"EntityManager.d.ts","sourceRoot":"","sources":["../../../../src/engine/ecs/EntityManager.js"],"names":[],"mappings":"iCAeU,MAAM;;;;;;;;;AAWhB;;;GAGG;AACH;IAEI;;;OAGG;IACH,kBAFU,iCAAQ,CAEL;IAEb;;;;OAIG;IACH,uCAA2B;IAE3B;;;;OAIG;IACH,iCAAqB;IAErB;;OAEG;IACH;;;QAGI;;WAEG;qBADO,MAAM,iCAAQ;;MAI1B;IAEF;;;OAGG;IACH,OAFU,kBAAkB,CAEO;IAEnC;;;;;;OAMG;IACH,gDAA2C;IAE3C;;;;OAIG;IACH,qBAFU,MAAM,CAEY;IAE5B;;;;;OAKG;IACH,wCAFU,MAAM,CAE4B;IAE5C;;;OAGG;IACH,SAFU,sBAAsB,CAEjB;IAEf;;;;;OAKG;IACH,uCAAsC;IAEtC;;;OAGG;IACH,6BA8EC;IAED,sBAcC;IAED;;;OAGG;IACH,uBAFa,KAAK,EAAE,CAuBnB;IAED;;;;;OAKG;IACH,uBAJW,sBAAsB,QA0BhC;IAED;;;;OAIG;IACH,UAJa,CAAC,eACH,KAAK,CAAC,CAAC,CAAC,GACN,OAAO,CAInB;IAED;;;;OAIG;IACH,UAJa,CAAC,eACH,KAAK,CAAC,CAAC,CAAC,GACN,CAAC,GAAC,IAAI,CAgBlB;IAED;;;;;OAKG;IACH,wBAJa,CAAC,aACH,MAAM,GACJ,IAAI,GAAC,KAAK,CAAC,CAAC,CAAC,CAezB;IAGD;;;OAGG;IACH,oBAFW,MAAM,QAkEhB;IAED;;;;;OAKG;IACH,iEA0EC;IAED;;;;OAIG;IACH,uDA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