@m2c2kit/core 0.3.12 → 0.3.14
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 +205 -46
- package/dist/index.js +1325 -1061
- package/package.json +19 -17
package/dist/index.js
CHANGED
|
@@ -5,15 +5,11 @@ var ActionType = /* @__PURE__ */ ((ActionType2) => {
|
|
|
5
5
|
ActionType2["Custom"] = "Custom";
|
|
6
6
|
ActionType2["Move"] = "Move";
|
|
7
7
|
ActionType2["Scale"] = "Scale";
|
|
8
|
+
ActionType2["FadeAlpha"] = "FadeAlpha";
|
|
9
|
+
ActionType2["Rotate"] = "Rotate";
|
|
8
10
|
return ActionType2;
|
|
9
11
|
})(ActionType || {});
|
|
10
12
|
|
|
11
|
-
var __defProp$k = Object.defineProperty;
|
|
12
|
-
var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __publicField$k = (obj, key, value) => {
|
|
14
|
-
__defNormalProp$k(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
15
|
-
return value;
|
|
16
|
-
};
|
|
17
13
|
class Easings {
|
|
18
14
|
}
|
|
19
15
|
// These easing functions are adapted from work by Robert Penner
|
|
@@ -32,134 +28,369 @@ class Easings {
|
|
|
32
28
|
// Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
33
29
|
// Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
34
30
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
35
|
-
|
|
31
|
+
Easings.none = (t, b, c, d) => {
|
|
36
32
|
return c + b;
|
|
37
|
-
}
|
|
38
|
-
|
|
33
|
+
};
|
|
34
|
+
Easings.linear = (t, b, c, d) => {
|
|
39
35
|
return c * t / d + b;
|
|
40
|
-
}
|
|
41
|
-
|
|
36
|
+
};
|
|
37
|
+
Easings.quadraticIn = (t, b, c, d) => {
|
|
42
38
|
t /= d;
|
|
43
39
|
return c * t * t + b;
|
|
44
|
-
}
|
|
45
|
-
|
|
40
|
+
};
|
|
41
|
+
Easings.quadraticOut = (t, b, c, d) => {
|
|
46
42
|
t /= d;
|
|
47
43
|
return -c * t * (t - 2) + b;
|
|
48
|
-
}
|
|
49
|
-
|
|
44
|
+
};
|
|
45
|
+
Easings.quadraticInOut = (t, b, c, d) => {
|
|
50
46
|
t /= d / 2;
|
|
51
47
|
if (t < 1)
|
|
52
48
|
return c / 2 * t * t + b;
|
|
53
49
|
t--;
|
|
54
50
|
return -c / 2 * (t * (t - 2) - 1) + b;
|
|
55
|
-
}
|
|
56
|
-
|
|
51
|
+
};
|
|
52
|
+
Easings.cubicIn = (t, b, c, d) => {
|
|
57
53
|
t /= d;
|
|
58
54
|
return c * t * t * t + b;
|
|
59
|
-
}
|
|
60
|
-
|
|
55
|
+
};
|
|
56
|
+
Easings.cubicOut = (t, b, c, d) => {
|
|
61
57
|
t /= d;
|
|
62
58
|
t--;
|
|
63
59
|
return c * (t * t * t + 1) + b;
|
|
64
|
-
}
|
|
65
|
-
|
|
60
|
+
};
|
|
61
|
+
Easings.cubicInOut = (t, b, c, d) => {
|
|
66
62
|
t /= d / 2;
|
|
67
63
|
if (t < 1)
|
|
68
64
|
return c / 2 * t * t * t + b;
|
|
69
65
|
t -= 2;
|
|
70
66
|
return c / 2 * (t * t * t + 2) + b;
|
|
71
|
-
}
|
|
72
|
-
|
|
67
|
+
};
|
|
68
|
+
Easings.quarticIn = (t, b, c, d) => {
|
|
73
69
|
t /= d;
|
|
74
70
|
return c * t * t * t * t + b;
|
|
75
|
-
}
|
|
76
|
-
|
|
71
|
+
};
|
|
72
|
+
Easings.quarticOut = (t, b, c, d) => {
|
|
77
73
|
t /= d;
|
|
78
74
|
t--;
|
|
79
75
|
return -c * (t * t * t * t - 1) + b;
|
|
80
|
-
}
|
|
81
|
-
|
|
76
|
+
};
|
|
77
|
+
Easings.quarticInOut = (t, b, c, d) => {
|
|
82
78
|
t /= d / 2;
|
|
83
79
|
if (t < 1)
|
|
84
80
|
return c / 2 * t * t * t * t + b;
|
|
85
81
|
t -= 2;
|
|
86
82
|
return -c / 2 * (t * t * t * t - 2) + b;
|
|
87
|
-
}
|
|
88
|
-
|
|
83
|
+
};
|
|
84
|
+
Easings.quinticIn = (t, b, c, d) => {
|
|
89
85
|
t /= d;
|
|
90
86
|
return c * t * t * t * t * t + b;
|
|
91
|
-
}
|
|
92
|
-
|
|
87
|
+
};
|
|
88
|
+
Easings.quinticOut = (t, b, c, d) => {
|
|
93
89
|
t /= d;
|
|
94
90
|
t--;
|
|
95
91
|
return c * (t * t * t * t * t + 1) + b;
|
|
96
|
-
}
|
|
97
|
-
|
|
92
|
+
};
|
|
93
|
+
Easings.quinticInOut = (t, b, c, d) => {
|
|
98
94
|
t /= d / 2;
|
|
99
95
|
if (t < 1)
|
|
100
96
|
return c / 2 * t * t * t * t * t + b;
|
|
101
97
|
t -= 2;
|
|
102
98
|
return c / 2 * (t * t * t * t * t + 2) + b;
|
|
103
|
-
}
|
|
104
|
-
|
|
99
|
+
};
|
|
100
|
+
Easings.sinusoidalIn = (t, b, c, d) => {
|
|
105
101
|
return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
|
|
106
|
-
}
|
|
107
|
-
|
|
102
|
+
};
|
|
103
|
+
Easings.sinusoidalOut = (t, b, c, d) => {
|
|
108
104
|
return c * Math.sin(t / d * (Math.PI / 2)) + b;
|
|
109
|
-
}
|
|
110
|
-
|
|
105
|
+
};
|
|
106
|
+
Easings.sinusoidalInOut = (t, b, c, d) => {
|
|
111
107
|
return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
|
|
112
|
-
}
|
|
113
|
-
|
|
108
|
+
};
|
|
109
|
+
Easings.exponentialIn = (t, b, c, d) => {
|
|
114
110
|
return c * Math.pow(2, 10 * (t / d - 1)) + b;
|
|
115
|
-
}
|
|
116
|
-
|
|
111
|
+
};
|
|
112
|
+
Easings.exponentialOut = (t, b, c, d) => {
|
|
117
113
|
return c * (-Math.pow(2, -10 * t / d) + 1) + b;
|
|
118
|
-
}
|
|
119
|
-
|
|
114
|
+
};
|
|
115
|
+
Easings.exponentialInOut = (t, b, c, d) => {
|
|
120
116
|
t /= d / 2;
|
|
121
117
|
if (t < 1)
|
|
122
118
|
return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
|
|
123
119
|
t--;
|
|
124
120
|
return c / 2 * (-Math.pow(2, -10 * t) + 2) + b;
|
|
125
|
-
}
|
|
126
|
-
|
|
121
|
+
};
|
|
122
|
+
Easings.circularIn = (t, b, c, d) => {
|
|
127
123
|
t /= d;
|
|
128
124
|
return -c * (Math.sqrt(1 - t * t) - 1) + b;
|
|
129
|
-
}
|
|
130
|
-
|
|
125
|
+
};
|
|
126
|
+
Easings.circularOut = (t, b, c, d) => {
|
|
131
127
|
t /= d;
|
|
132
128
|
t--;
|
|
133
129
|
return c * Math.sqrt(1 - t * t) + b;
|
|
134
|
-
}
|
|
135
|
-
|
|
130
|
+
};
|
|
131
|
+
Easings.circularInOut = (t, b, c, d) => {
|
|
136
132
|
t /= d / 2;
|
|
137
133
|
if (t < 1)
|
|
138
134
|
return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
|
|
139
135
|
t -= 2;
|
|
140
136
|
return c / 2 * (Math.sqrt(1 - t * t) + 1) + b;
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
var __defProp$j = Object.defineProperty;
|
|
144
|
-
var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
145
|
-
var __publicField$j = (obj, key, value) => {
|
|
146
|
-
__defNormalProp$j(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
147
|
-
return value;
|
|
148
137
|
};
|
|
138
|
+
|
|
139
|
+
var EntityType = /* @__PURE__ */ ((EntityType2) => {
|
|
140
|
+
EntityType2["Entity"] = "Entity";
|
|
141
|
+
EntityType2["Scene"] = "Scene";
|
|
142
|
+
EntityType2["Sprite"] = "Sprite";
|
|
143
|
+
EntityType2["Label"] = "Label";
|
|
144
|
+
EntityType2["TextLine"] = "TextLine";
|
|
145
|
+
EntityType2["Shape"] = "Shape";
|
|
146
|
+
EntityType2["Composite"] = "Composite";
|
|
147
|
+
return EntityType2;
|
|
148
|
+
})(EntityType || {});
|
|
149
|
+
|
|
150
|
+
var ShapeType = /* @__PURE__ */ ((ShapeType2) => {
|
|
151
|
+
ShapeType2["Undefined"] = "Undefined";
|
|
152
|
+
ShapeType2["Rectangle"] = "Rectangle";
|
|
153
|
+
ShapeType2["Circle"] = "Circle";
|
|
154
|
+
ShapeType2["Path"] = "Path";
|
|
155
|
+
return ShapeType2;
|
|
156
|
+
})(ShapeType || {});
|
|
157
|
+
|
|
158
|
+
class M2c2KitHelpers {
|
|
159
|
+
/**
|
|
160
|
+
* Calculates the four points of the bounding box of the entity, taking
|
|
161
|
+
* into account the entity's rotation (as well as the rotation of its
|
|
162
|
+
* ancestors).
|
|
163
|
+
*
|
|
164
|
+
* @remarks This method is used to calculate the rotated bounding box of an
|
|
165
|
+
* entity when in order to determine if a point is inside the entity in
|
|
166
|
+
* response to DOM pointer events. This method is NOT used to prepare the
|
|
167
|
+
* CanvasKit canvas for drawing the entity.
|
|
168
|
+
*
|
|
169
|
+
* @param drawableEntity
|
|
170
|
+
* @returns array of points representing the rotated entity
|
|
171
|
+
*/
|
|
172
|
+
static calculateRotatedPoints(drawableEntity) {
|
|
173
|
+
const entities = drawableEntity.ancestors;
|
|
174
|
+
entities.reverse();
|
|
175
|
+
entities.push(drawableEntity);
|
|
176
|
+
const entityPointsArray = entities.map((entity) => {
|
|
177
|
+
const boundingBox = M2c2KitHelpers.calculateEntityAbsoluteBoundingBox(entity);
|
|
178
|
+
return boundingBoxToPoints(boundingBox);
|
|
179
|
+
});
|
|
180
|
+
for (let i = 0; i < entityPointsArray.length; i++) {
|
|
181
|
+
if (!entityNeedsRotation(entities[i])) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
const entityPoints = entityPointsArray[i];
|
|
185
|
+
const radians = entities[i].zRotation;
|
|
186
|
+
const center = findCentroid(entityPoints);
|
|
187
|
+
for (let j = i; j < entities.length; j++) {
|
|
188
|
+
entityPointsArray[j] = rotateRectangle(
|
|
189
|
+
entityPointsArray[j],
|
|
190
|
+
radians,
|
|
191
|
+
center
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return entityPointsArray[entityPointsArray.length - 1];
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Rotates the canvas so the entity appears rotated when drawn.
|
|
199
|
+
*
|
|
200
|
+
* @remarks Entities inherit rotations from their ancestors. Each ancestor,
|
|
201
|
+
* however, rotates around its own anchor point. Thus, we must rotate the
|
|
202
|
+
* canvas around the anchor point of each ancestor as well as the entity's
|
|
203
|
+
* anchor point.
|
|
204
|
+
*
|
|
205
|
+
* @param canvas - CanvasKit canvas to rotate
|
|
206
|
+
* @param drawableEntity - Entity to rotate the canvas for
|
|
207
|
+
*/
|
|
208
|
+
static rotateCanvasForDrawableEntity(canvas, drawableEntity) {
|
|
209
|
+
const rotationTransforms = calculateRotationTransforms(drawableEntity);
|
|
210
|
+
if (rotationTransforms.length === 0) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const drawScale = Globals.canvasScale / drawableEntity.absoluteScale;
|
|
214
|
+
applyRotationTransformsToCanvas(rotationTransforms, drawScale, canvas);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Calculates the absolute bounding box of the entity before any rotation
|
|
218
|
+
* is applied.
|
|
219
|
+
*
|
|
220
|
+
* @remarks The absolute bounding box is the bounding box of the entity
|
|
221
|
+
* relative to the scene's origin (0, 0).
|
|
222
|
+
*
|
|
223
|
+
* @param entity
|
|
224
|
+
* @returns the bounding box of the entity
|
|
225
|
+
*/
|
|
226
|
+
static calculateEntityAbsoluteBoundingBox(entity) {
|
|
227
|
+
const anchorPoint = entity.anchorPoint;
|
|
228
|
+
const scale = entity.absoluteScale;
|
|
229
|
+
let width = entity.size.width;
|
|
230
|
+
let height = entity.size.height;
|
|
231
|
+
if (entity.type === EntityType.Shape && entity.shapeType === ShapeType.Circle) {
|
|
232
|
+
const radius = entity.circleOfRadius;
|
|
233
|
+
if (!radius) {
|
|
234
|
+
throw "circleOfRadius is undefined";
|
|
235
|
+
}
|
|
236
|
+
width = radius * 2;
|
|
237
|
+
height = radius * 2;
|
|
238
|
+
}
|
|
239
|
+
const xMin = entity.absolutePosition.x - width * anchorPoint.x * scale;
|
|
240
|
+
const xMax = entity.absolutePosition.x + width * (1 - anchorPoint.x) * scale;
|
|
241
|
+
const yMin = entity.absolutePosition.y - height * anchorPoint.y * scale;
|
|
242
|
+
const yMax = entity.absolutePosition.y + height * (1 - anchorPoint.y) * scale;
|
|
243
|
+
return { xMin, xMax, yMin, yMax };
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Converts an angle from radians to degrees.
|
|
247
|
+
*
|
|
248
|
+
* @remarks In m2c2kit, radians are counter clockwise from the positive
|
|
249
|
+
* x-axis, but the rotate method in CanvasKit uses degrees clockwise. Thus
|
|
250
|
+
* we negate after conversion from radians to degrees.
|
|
251
|
+
*
|
|
252
|
+
* @param radians - The angle in radians
|
|
253
|
+
* @returns The angle in degrees
|
|
254
|
+
*/
|
|
255
|
+
static radiansToDegrees(radians) {
|
|
256
|
+
return -M2c2KitHelpers.normalizeAngleRadians(radians) * (180 / Math.PI);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Normalizes an angle in radians to the range [0, 2*Math.PI)
|
|
260
|
+
*
|
|
261
|
+
* @param radians - angle in radians
|
|
262
|
+
* @returns normalized angle in radians
|
|
263
|
+
*/
|
|
264
|
+
static normalizeAngleRadians(radians) {
|
|
265
|
+
const quotient = Math.floor(radians / (2 * Math.PI));
|
|
266
|
+
let normalized = radians - quotient * (2 * Math.PI);
|
|
267
|
+
if (normalized < 0) {
|
|
268
|
+
normalized += 2 * Math.PI;
|
|
269
|
+
}
|
|
270
|
+
return normalized;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Checks if a point is inside a rectangle.
|
|
274
|
+
*
|
|
275
|
+
* @param point - The Point to check
|
|
276
|
+
* @param rect - An array of four Points representing the vertices of the
|
|
277
|
+
* rectangle in clockwise order
|
|
278
|
+
* @returns true if the Point is inside the rectangle
|
|
279
|
+
*/
|
|
280
|
+
static isPointInsideRectangle(point, rect) {
|
|
281
|
+
for (let i = 0; i < 4; i++) {
|
|
282
|
+
const p1 = rect[i];
|
|
283
|
+
const p2 = rect[(i + 1) % 4];
|
|
284
|
+
const cross = (p2.x - p1.x) * (point.y - p1.y) - (p2.y - p1.y) * (point.x - p1.x);
|
|
285
|
+
if (cross > 0) {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function applyRotationTransformsToCanvas(rotationTransforms, scale, canvas) {
|
|
293
|
+
rotationTransforms.forEach((transform) => {
|
|
294
|
+
canvas.rotate(
|
|
295
|
+
M2c2KitHelpers.radiansToDegrees(transform.radians),
|
|
296
|
+
transform.center.x * scale,
|
|
297
|
+
transform.center.y * scale
|
|
298
|
+
);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
function calculateRotationTransforms(drawableEntity) {
|
|
302
|
+
const rotationTransforms = [];
|
|
303
|
+
const entities = drawableEntity.ancestors;
|
|
304
|
+
entities.reverse();
|
|
305
|
+
entities.push(drawableEntity);
|
|
306
|
+
entities.forEach((entity) => {
|
|
307
|
+
if (entityNeedsRotation(entity)) {
|
|
308
|
+
const drawable = entity;
|
|
309
|
+
if (drawable.type === EntityType.Scene) {
|
|
310
|
+
const center2 = {
|
|
311
|
+
x: drawable.absolutePosition.x + drawable.size.width * 0.5,
|
|
312
|
+
y: drawable.absolutePosition.y + drawable.size.height * 0.5
|
|
313
|
+
};
|
|
314
|
+
rotationTransforms.push({
|
|
315
|
+
radians: drawable.zRotation,
|
|
316
|
+
center: center2
|
|
317
|
+
});
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
const boundingBox = M2c2KitHelpers.calculateEntityAbsoluteBoundingBox(drawable);
|
|
321
|
+
const points = boundingBoxToPoints(boundingBox);
|
|
322
|
+
const center = findCentroid(points);
|
|
323
|
+
rotationTransforms.push({
|
|
324
|
+
radians: drawable.zRotation,
|
|
325
|
+
center
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
return rotationTransforms;
|
|
330
|
+
}
|
|
331
|
+
function entityNeedsRotation(entity) {
|
|
332
|
+
return M2c2KitHelpers.normalizeAngleRadians(entity.zRotation) !== 0 && entity.isDrawable;
|
|
333
|
+
}
|
|
334
|
+
function boundingBoxToPoints(boundingBox) {
|
|
335
|
+
const { xMin, xMax, yMin, yMax } = boundingBox;
|
|
336
|
+
const points = [
|
|
337
|
+
{ x: xMin, y: yMin },
|
|
338
|
+
// Top left
|
|
339
|
+
{ x: xMin, y: yMax },
|
|
340
|
+
// Bottom left
|
|
341
|
+
{ x: xMax, y: yMax },
|
|
342
|
+
// Bottom right
|
|
343
|
+
{ x: xMax, y: yMin }
|
|
344
|
+
// Top right
|
|
345
|
+
];
|
|
346
|
+
return points;
|
|
347
|
+
}
|
|
348
|
+
function findCentroid(points) {
|
|
349
|
+
if (points.length !== 4) {
|
|
350
|
+
throw new Error("Invalid input: expected an array of four points");
|
|
351
|
+
}
|
|
352
|
+
let xSum = 0;
|
|
353
|
+
let ySum = 0;
|
|
354
|
+
for (const point of points) {
|
|
355
|
+
xSum += point.x;
|
|
356
|
+
ySum += point.y;
|
|
357
|
+
}
|
|
358
|
+
const xAvg = xSum / 4;
|
|
359
|
+
const yAvg = ySum / 4;
|
|
360
|
+
return { x: xAvg, y: yAvg };
|
|
361
|
+
}
|
|
362
|
+
function rotatePoint(point, radians, center) {
|
|
363
|
+
const dx = point.x - center.x;
|
|
364
|
+
const dy = point.y - center.y;
|
|
365
|
+
const x = dx * Math.cos(-radians) - dy * Math.sin(-radians);
|
|
366
|
+
const y = dx * Math.sin(-radians) + dy * Math.cos(-radians);
|
|
367
|
+
return {
|
|
368
|
+
x: x + center.x,
|
|
369
|
+
y: y + center.y
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
function rotateRectangle(rect, radians, center) {
|
|
373
|
+
if (rect.length !== 4) {
|
|
374
|
+
throw new Error("Invalid input: expected an array of four points");
|
|
375
|
+
}
|
|
376
|
+
const rotated = [];
|
|
377
|
+
for (const p of rect) {
|
|
378
|
+
rotated.push(rotatePoint(p, radians, center));
|
|
379
|
+
}
|
|
380
|
+
return rotated;
|
|
381
|
+
}
|
|
382
|
+
|
|
149
383
|
class Action {
|
|
150
384
|
constructor(runDuringTransition = false) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
__publicField$j(this, "isParent", false);
|
|
161
|
-
__publicField$j(this, "isChild", false);
|
|
162
|
-
__publicField$j(this, "key");
|
|
385
|
+
this.startOffset = -1;
|
|
386
|
+
this.endOffset = -1;
|
|
387
|
+
this.started = false;
|
|
388
|
+
this.running = false;
|
|
389
|
+
this.completed = false;
|
|
390
|
+
this.runStartTime = -1;
|
|
391
|
+
this.duration = 0;
|
|
392
|
+
this.isParent = false;
|
|
393
|
+
this.isChild = false;
|
|
163
394
|
this.runDuringTransition = runDuringTransition;
|
|
164
395
|
}
|
|
165
396
|
/**
|
|
@@ -169,12 +400,11 @@ class Action {
|
|
|
169
400
|
* @returns The move action
|
|
170
401
|
*/
|
|
171
402
|
static move(options) {
|
|
172
|
-
var _a, _b;
|
|
173
403
|
return new MoveAction(
|
|
174
404
|
options.point,
|
|
175
405
|
options.duration,
|
|
176
|
-
|
|
177
|
-
|
|
406
|
+
options.easing ?? Easings.linear,
|
|
407
|
+
options.runDuringTransition ?? false
|
|
178
408
|
);
|
|
179
409
|
}
|
|
180
410
|
/**
|
|
@@ -184,10 +414,9 @@ class Action {
|
|
|
184
414
|
* @returns The wait action
|
|
185
415
|
*/
|
|
186
416
|
static wait(options) {
|
|
187
|
-
var _a;
|
|
188
417
|
return new WaitAction(
|
|
189
418
|
options.duration,
|
|
190
|
-
|
|
419
|
+
options.runDuringTransition ?? false
|
|
191
420
|
);
|
|
192
421
|
}
|
|
193
422
|
/**
|
|
@@ -197,10 +426,9 @@ class Action {
|
|
|
197
426
|
* @returns The custom action
|
|
198
427
|
*/
|
|
199
428
|
static custom(options) {
|
|
200
|
-
var _a;
|
|
201
429
|
return new CustomAction(
|
|
202
430
|
options.callback,
|
|
203
|
-
|
|
431
|
+
options.runDuringTransition ?? false
|
|
204
432
|
);
|
|
205
433
|
}
|
|
206
434
|
/**
|
|
@@ -218,6 +446,52 @@ class Action {
|
|
|
218
446
|
options.runDuringTransition
|
|
219
447
|
);
|
|
220
448
|
}
|
|
449
|
+
/**
|
|
450
|
+
* Creates an action that will change the entity's alpha (opacity).
|
|
451
|
+
*
|
|
452
|
+
* @remarks Alpha has multiplicative inheritance. For example, if the entity's parent is alpha .5 and this entity's action fades alpha to .4, then the entity will appear with alpha .2.
|
|
453
|
+
*
|
|
454
|
+
* @param options - {@link FadeAlphaActionOptions}
|
|
455
|
+
* @returns The fadeAlpha action
|
|
456
|
+
*/
|
|
457
|
+
static fadeAlpha(options) {
|
|
458
|
+
return new FadeAlphaAction(
|
|
459
|
+
options.alpha,
|
|
460
|
+
options.duration,
|
|
461
|
+
options.runDuringTransition
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Creates an action that will rotate the entity.
|
|
466
|
+
*
|
|
467
|
+
* @remarks Rotate actions are applied to their children. In addition to this entity's rotate action, all ancestors' rotate actions will also be applied.
|
|
468
|
+
*
|
|
469
|
+
* @param options - {@link RotateActionOptions}
|
|
470
|
+
* @returns The rotate action
|
|
471
|
+
*/
|
|
472
|
+
static rotate(options) {
|
|
473
|
+
if (options.byAngle !== void 0 && options.toAngle !== void 0) {
|
|
474
|
+
throw new Error("rotate Action: cannot specify both byAngle and toAngle");
|
|
475
|
+
}
|
|
476
|
+
if (options.byAngle === void 0 && options.toAngle === void 0) {
|
|
477
|
+
throw new Error("rotate Action: must specify either byAngle or toAngle");
|
|
478
|
+
}
|
|
479
|
+
if (options.toAngle === void 0 && options.shortestUnitArc !== void 0) {
|
|
480
|
+
throw new Error(
|
|
481
|
+
"rotate Action: shortestUnitArc can only be specified when toAngle is provided"
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
if (options.toAngle !== void 0 && options.shortestUnitArc === void 0) {
|
|
485
|
+
options.shortestUnitArc = true;
|
|
486
|
+
}
|
|
487
|
+
return new RotateAction(
|
|
488
|
+
options.byAngle,
|
|
489
|
+
options.toAngle,
|
|
490
|
+
options.shortestUnitArc,
|
|
491
|
+
options.duration,
|
|
492
|
+
options.runDuringTransition
|
|
493
|
+
);
|
|
494
|
+
}
|
|
221
495
|
/**
|
|
222
496
|
* Creates an array of actions that will be run in order.
|
|
223
497
|
*
|
|
@@ -304,6 +578,26 @@ class Action {
|
|
|
304
578
|
});
|
|
305
579
|
break;
|
|
306
580
|
}
|
|
581
|
+
case ActionType.FadeAlpha: {
|
|
582
|
+
const fadeAlpha = action;
|
|
583
|
+
cloned = Action.fadeAlpha({
|
|
584
|
+
alpha: fadeAlpha.alpha,
|
|
585
|
+
duration: fadeAlpha.duration,
|
|
586
|
+
runDuringTransition: fadeAlpha.runDuringTransition
|
|
587
|
+
});
|
|
588
|
+
break;
|
|
589
|
+
}
|
|
590
|
+
case ActionType.Rotate: {
|
|
591
|
+
const rotate = action;
|
|
592
|
+
cloned = Action.rotate({
|
|
593
|
+
byAngle: rotate.byAngle,
|
|
594
|
+
toAngle: rotate.toAngle,
|
|
595
|
+
shortestUnitArc: rotate.shortestUnitArc,
|
|
596
|
+
duration: rotate.duration,
|
|
597
|
+
runDuringTransition: rotate.runDuringTransition
|
|
598
|
+
});
|
|
599
|
+
break;
|
|
600
|
+
}
|
|
307
601
|
case ActionType.Wait: {
|
|
308
602
|
const wait = action;
|
|
309
603
|
cloned = Action.wait({
|
|
@@ -391,6 +685,55 @@ class Action {
|
|
|
391
685
|
scaleAction.completed = true;
|
|
392
686
|
}
|
|
393
687
|
}
|
|
688
|
+
if (action.type === ActionType.FadeAlpha) {
|
|
689
|
+
const fadeAlphaAction = action;
|
|
690
|
+
if (!fadeAlphaAction.started) {
|
|
691
|
+
fadeAlphaAction.delta = fadeAlphaAction.alpha - entity.alpha;
|
|
692
|
+
fadeAlphaAction.started = true;
|
|
693
|
+
}
|
|
694
|
+
if (elapsed < fadeAlphaAction.duration) {
|
|
695
|
+
entity.alpha = entity.alpha + fadeAlphaAction.delta * (dt / fadeAlphaAction.duration);
|
|
696
|
+
} else {
|
|
697
|
+
entity.alpha = fadeAlphaAction.alpha;
|
|
698
|
+
fadeAlphaAction.running = false;
|
|
699
|
+
fadeAlphaAction.completed = true;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
if (action.type === ActionType.Rotate) {
|
|
703
|
+
const rotateAction = action;
|
|
704
|
+
if (!rotateAction.started) {
|
|
705
|
+
if (rotateAction.byAngle !== void 0) {
|
|
706
|
+
rotateAction.delta = rotateAction.byAngle;
|
|
707
|
+
}
|
|
708
|
+
if (rotateAction.toAngle !== void 0) {
|
|
709
|
+
rotateAction.toAngle = M2c2KitHelpers.normalizeAngleRadians(
|
|
710
|
+
rotateAction.toAngle
|
|
711
|
+
);
|
|
712
|
+
entity.zRotation = M2c2KitHelpers.normalizeAngleRadians(
|
|
713
|
+
entity.zRotation
|
|
714
|
+
);
|
|
715
|
+
rotateAction.delta = rotateAction.toAngle - entity.zRotation;
|
|
716
|
+
if (rotateAction.shortestUnitArc === true && Math.abs(rotateAction.delta) > Math.PI) {
|
|
717
|
+
rotateAction.delta = 2 * Math.PI - Math.abs(rotateAction.delta);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
rotateAction.started = true;
|
|
721
|
+
rotateAction.finalValue = entity.zRotation + rotateAction.delta;
|
|
722
|
+
}
|
|
723
|
+
if (elapsed < rotateAction.duration) {
|
|
724
|
+
entity.zRotation = entity.zRotation + rotateAction.delta * (dt / rotateAction.duration);
|
|
725
|
+
if (rotateAction.delta <= 0 && entity.zRotation < rotateAction.finalValue) {
|
|
726
|
+
entity.zRotation = rotateAction.finalValue;
|
|
727
|
+
}
|
|
728
|
+
if (rotateAction.delta > 0 && entity.zRotation > rotateAction.finalValue) {
|
|
729
|
+
entity.zRotation = rotateAction.finalValue;
|
|
730
|
+
}
|
|
731
|
+
} else {
|
|
732
|
+
entity.zRotation = rotateAction.finalValue;
|
|
733
|
+
rotateAction.running = false;
|
|
734
|
+
rotateAction.completed = true;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
394
737
|
}
|
|
395
738
|
/**
|
|
396
739
|
* Calculates the duration of an action, including any children actions
|
|
@@ -428,17 +771,16 @@ class Action {
|
|
|
428
771
|
* @param action that needs assigning start and end offsets
|
|
429
772
|
*/
|
|
430
773
|
calculateStartEndOffsets(action) {
|
|
431
|
-
var _a, _b, _c;
|
|
432
774
|
let parentStartOffset;
|
|
433
775
|
if (action.parent === void 0) {
|
|
434
776
|
parentStartOffset = 0;
|
|
435
777
|
} else {
|
|
436
778
|
parentStartOffset = action.parent.startOffset;
|
|
437
779
|
}
|
|
438
|
-
if (
|
|
780
|
+
if (action.parent?.type === ActionType.Group) {
|
|
439
781
|
action.startOffset = parentStartOffset;
|
|
440
782
|
action.endOffset = action.startOffset + action.duration;
|
|
441
|
-
} else if (
|
|
783
|
+
} else if (action.parent?.type === ActionType.Sequence) {
|
|
442
784
|
const parent = action.parent;
|
|
443
785
|
let dur = 0;
|
|
444
786
|
for (const a of parent.children) {
|
|
@@ -454,7 +796,7 @@ class Action {
|
|
|
454
796
|
action.endOffset = action.startOffset + action.duration;
|
|
455
797
|
}
|
|
456
798
|
if (action.isParent) {
|
|
457
|
-
|
|
799
|
+
action.children?.forEach(
|
|
458
800
|
(child) => this.calculateStartEndOffsets(child)
|
|
459
801
|
);
|
|
460
802
|
}
|
|
@@ -512,8 +854,7 @@ class Action {
|
|
|
512
854
|
class SequenceAction extends Action {
|
|
513
855
|
constructor(actions) {
|
|
514
856
|
super();
|
|
515
|
-
|
|
516
|
-
__publicField$j(this, "children");
|
|
857
|
+
this.type = ActionType.Sequence;
|
|
517
858
|
this.children = actions;
|
|
518
859
|
this.isParent = true;
|
|
519
860
|
}
|
|
@@ -521,8 +862,8 @@ class SequenceAction extends Action {
|
|
|
521
862
|
class GroupAction extends Action {
|
|
522
863
|
constructor(actions) {
|
|
523
864
|
super();
|
|
524
|
-
|
|
525
|
-
|
|
865
|
+
this.type = ActionType.Group;
|
|
866
|
+
this.children = new Array();
|
|
526
867
|
this.children = actions;
|
|
527
868
|
this.isParent = true;
|
|
528
869
|
}
|
|
@@ -530,8 +871,7 @@ class GroupAction extends Action {
|
|
|
530
871
|
class CustomAction extends Action {
|
|
531
872
|
constructor(callback, runDuringTransition = false) {
|
|
532
873
|
super(runDuringTransition);
|
|
533
|
-
|
|
534
|
-
__publicField$j(this, "callback");
|
|
874
|
+
this.type = ActionType.Custom;
|
|
535
875
|
this.callback = callback;
|
|
536
876
|
this.isParent = false;
|
|
537
877
|
this.duration = 0;
|
|
@@ -540,7 +880,7 @@ class CustomAction extends Action {
|
|
|
540
880
|
class WaitAction extends Action {
|
|
541
881
|
constructor(duration, runDuringTransition) {
|
|
542
882
|
super(runDuringTransition);
|
|
543
|
-
|
|
883
|
+
this.type = ActionType.Wait;
|
|
544
884
|
this.duration = duration;
|
|
545
885
|
this.isParent = false;
|
|
546
886
|
}
|
|
@@ -548,12 +888,9 @@ class WaitAction extends Action {
|
|
|
548
888
|
class MoveAction extends Action {
|
|
549
889
|
constructor(point, duration, easing, runDuringTransition) {
|
|
550
890
|
super(runDuringTransition);
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
__publicField$j(this, "dx", 0);
|
|
555
|
-
__publicField$j(this, "dy", 0);
|
|
556
|
-
__publicField$j(this, "easing");
|
|
891
|
+
this.type = ActionType.Move;
|
|
892
|
+
this.dx = 0;
|
|
893
|
+
this.dy = 0;
|
|
557
894
|
this.duration = duration;
|
|
558
895
|
this.point = point;
|
|
559
896
|
this.isParent = false;
|
|
@@ -564,14 +901,36 @@ class MoveAction extends Action {
|
|
|
564
901
|
class ScaleAction extends Action {
|
|
565
902
|
constructor(scale, duration, runDuringTransition = false) {
|
|
566
903
|
super(runDuringTransition);
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
__publicField$j(this, "delta", 0);
|
|
904
|
+
this.type = ActionType.Scale;
|
|
905
|
+
this.delta = 0;
|
|
570
906
|
this.duration = duration;
|
|
571
907
|
this.scale = scale;
|
|
572
908
|
this.isParent = false;
|
|
573
909
|
}
|
|
574
910
|
}
|
|
911
|
+
class FadeAlphaAction extends Action {
|
|
912
|
+
constructor(alpha, duration, runDuringTransition = false) {
|
|
913
|
+
super(runDuringTransition);
|
|
914
|
+
this.type = ActionType.FadeAlpha;
|
|
915
|
+
this.delta = 0;
|
|
916
|
+
this.duration = duration;
|
|
917
|
+
this.alpha = alpha;
|
|
918
|
+
this.isParent = false;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
class RotateAction extends Action {
|
|
922
|
+
constructor(byAngle, toAngle, shortestUnitArc, duration, runDuringTransition = false) {
|
|
923
|
+
super(runDuringTransition);
|
|
924
|
+
this.type = ActionType.Rotate;
|
|
925
|
+
this.delta = 0;
|
|
926
|
+
this.finalValue = NaN;
|
|
927
|
+
this.duration = duration;
|
|
928
|
+
this.byAngle = byAngle;
|
|
929
|
+
this.toAngle = toAngle;
|
|
930
|
+
this.shortestUnitArc = shortestUnitArc;
|
|
931
|
+
this.isParent = false;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
575
934
|
|
|
576
935
|
var ActivityType = /* @__PURE__ */ ((ActivityType2) => {
|
|
577
936
|
ActivityType2["Game"] = "Game";
|
|
@@ -588,7 +947,7 @@ class CanvasKitHelpers {
|
|
|
588
947
|
* free these wasm objects.
|
|
589
948
|
*/
|
|
590
949
|
static Dispose(objects) {
|
|
591
|
-
objects.filter((o) => !
|
|
950
|
+
objects.filter((o) => !o?.isDeleted()).forEach((o) => o?.delete());
|
|
592
951
|
}
|
|
593
952
|
static makePaint(canvasKit, color, style, isAntialiased) {
|
|
594
953
|
const paint = new canvasKit.Paint();
|
|
@@ -599,23 +958,316 @@ class CanvasKitHelpers {
|
|
|
599
958
|
}
|
|
600
959
|
}
|
|
601
960
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
961
|
+
class MutablePath {
|
|
962
|
+
constructor() {
|
|
963
|
+
this._subpaths = new Array();
|
|
964
|
+
this.currentPath = new Array();
|
|
965
|
+
}
|
|
966
|
+
get subpaths() {
|
|
967
|
+
if (this.currentPath.length > 0) {
|
|
968
|
+
return [...this._subpaths, this.currentPath];
|
|
969
|
+
} else {
|
|
970
|
+
return this._subpaths;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* Starts a new subpath at a given point.
|
|
975
|
+
*
|
|
976
|
+
* @param point - location at which to start the new subpath
|
|
977
|
+
*/
|
|
978
|
+
move(point) {
|
|
979
|
+
if (this.currentPath.length > 0) {
|
|
980
|
+
this._subpaths.push(this.currentPath);
|
|
981
|
+
}
|
|
982
|
+
this.currentPath = new Array();
|
|
983
|
+
this.currentPath.push(point);
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Adds a straight line to the current subpath.
|
|
987
|
+
*
|
|
988
|
+
* @remarks The line is added from the last point in the current subpath to
|
|
989
|
+
* the given point.
|
|
990
|
+
*
|
|
991
|
+
* @param point - location where the line will end
|
|
992
|
+
*/
|
|
993
|
+
addLine(point) {
|
|
994
|
+
this.currentPath.push(point);
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* Removes all subpaths from the shape.
|
|
998
|
+
*/
|
|
999
|
+
clear() {
|
|
1000
|
+
this._subpaths = new Array();
|
|
1001
|
+
this.currentPath = new Array();
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* Makes a deep copy.
|
|
1005
|
+
*
|
|
1006
|
+
* @returns a deep copy
|
|
1007
|
+
*/
|
|
1008
|
+
duplicate() {
|
|
1009
|
+
const newPath = new MutablePath();
|
|
1010
|
+
newPath._subpaths = JSON.parse(JSON.stringify(this._subpaths));
|
|
1011
|
+
newPath.currentPath = JSON.parse(JSON.stringify(this.currentPath));
|
|
1012
|
+
return newPath;
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
class WebColors {
|
|
1017
|
+
}
|
|
1018
|
+
WebColors.Transparent = [0, 0, 0, 0];
|
|
1019
|
+
WebColors.MediumVioletRed = [199, 21, 133, 1];
|
|
1020
|
+
WebColors.DeepPink = [255, 20, 147, 1];
|
|
1021
|
+
WebColors.PaleVioletRed = [219, 112, 147, 1];
|
|
1022
|
+
WebColors.HotPink = [255, 105, 180, 1];
|
|
1023
|
+
WebColors.LightPink = [255, 182, 193, 1];
|
|
1024
|
+
WebColors.Pink = [255, 192, 203, 1];
|
|
1025
|
+
WebColors.DarkRed = [139, 0, 0, 1];
|
|
1026
|
+
WebColors.Red = [255, 0, 0, 1];
|
|
1027
|
+
WebColors.Firebrick = [178, 34, 34, 1];
|
|
1028
|
+
WebColors.Crimson = [220, 20, 60, 1];
|
|
1029
|
+
WebColors.IndianRed = [205, 92, 92, 1];
|
|
1030
|
+
WebColors.LightCoral = [240, 128, 128, 1];
|
|
1031
|
+
WebColors.Salmon = [250, 128, 114, 1];
|
|
1032
|
+
WebColors.DarkSalmon = [233, 150, 122, 1];
|
|
1033
|
+
WebColors.LightSalmon = [255, 160, 122, 1];
|
|
1034
|
+
WebColors.OrangeRed = [255, 69, 0, 1];
|
|
1035
|
+
WebColors.Tomato = [255, 99, 71, 1];
|
|
1036
|
+
WebColors.DarkOrange = [255, 140, 0, 1];
|
|
1037
|
+
WebColors.Coral = [255, 127, 80, 1];
|
|
1038
|
+
WebColors.Orange = [255, 165, 0, 1];
|
|
1039
|
+
WebColors.DarkKhaki = [189, 183, 107, 1];
|
|
1040
|
+
WebColors.Gold = [255, 215, 0, 1];
|
|
1041
|
+
WebColors.Khaki = [240, 230, 140, 1];
|
|
1042
|
+
WebColors.PeachPuff = [255, 218, 185, 1];
|
|
1043
|
+
WebColors.Yellow = [255, 255, 0, 1];
|
|
1044
|
+
WebColors.PaleGoldenrod = [238, 232, 170, 1];
|
|
1045
|
+
WebColors.Moccasin = [255, 228, 181, 1];
|
|
1046
|
+
WebColors.PapayaWhip = [255, 239, 213, 1];
|
|
1047
|
+
WebColors.LightGoldenrodYellow = [250, 250, 210, 1];
|
|
1048
|
+
WebColors.LemonChiffon = [255, 250, 205, 1];
|
|
1049
|
+
WebColors.LightYellow = [255, 255, 224, 1];
|
|
1050
|
+
WebColors.Maroon = [128, 0, 0, 1];
|
|
1051
|
+
WebColors.Brown = [165, 42, 42, 1];
|
|
1052
|
+
WebColors.SaddleBrown = [139, 69, 19, 1];
|
|
1053
|
+
WebColors.Sienna = [160, 82, 45, 1];
|
|
1054
|
+
WebColors.Chocolate = [210, 105, 30, 1];
|
|
1055
|
+
WebColors.DarkGoldenrod = [184, 134, 11, 1];
|
|
1056
|
+
WebColors.Peru = [205, 133, 63, 1];
|
|
1057
|
+
WebColors.RosyBrown = [188, 143, 143, 1];
|
|
1058
|
+
WebColors.Goldenrod = [218, 165, 32, 1];
|
|
1059
|
+
WebColors.SandyBrown = [244, 164, 96, 1];
|
|
1060
|
+
WebColors.Tan = [210, 180, 140, 1];
|
|
1061
|
+
WebColors.Burlywood = [222, 184, 135, 1];
|
|
1062
|
+
WebColors.Wheat = [245, 222, 179, 1];
|
|
1063
|
+
WebColors.NavajoWhite = [255, 222, 173, 1];
|
|
1064
|
+
WebColors.Bisque = [255, 228, 196, 1];
|
|
1065
|
+
WebColors.BlanchedAlmond = [255, 235, 205, 1];
|
|
1066
|
+
WebColors.Cornsilk = [255, 248, 220, 1];
|
|
1067
|
+
WebColors.DarkGreen = [0, 100, 0, 1];
|
|
1068
|
+
WebColors.Green = [0, 128, 0, 1];
|
|
1069
|
+
WebColors.DarkOliveGreen = [85, 107, 47, 1];
|
|
1070
|
+
WebColors.ForestGreen = [34, 139, 34, 1];
|
|
1071
|
+
WebColors.SeaGreen = [46, 139, 87, 1];
|
|
1072
|
+
WebColors.Olive = [128, 128, 0, 1];
|
|
1073
|
+
WebColors.OliveDrab = [107, 142, 35, 1];
|
|
1074
|
+
WebColors.MediumSeaGreen = [60, 179, 113, 1];
|
|
1075
|
+
WebColors.LimeGreen = [50, 205, 50, 1];
|
|
1076
|
+
WebColors.Lime = [0, 255, 0, 1];
|
|
1077
|
+
WebColors.SpringGreen = [0, 255, 127, 1];
|
|
1078
|
+
WebColors.MediumSpringGreen = [0, 250, 154, 1];
|
|
1079
|
+
WebColors.DarkSeaGreen = [143, 188, 143, 1];
|
|
1080
|
+
WebColors.MediumAquamarine = [102, 205, 170, 1];
|
|
1081
|
+
WebColors.YellowGreen = [154, 205, 50, 1];
|
|
1082
|
+
WebColors.LawnGreen = [124, 252, 0, 1];
|
|
1083
|
+
WebColors.Chartreuse = [127, 255, 0, 1];
|
|
1084
|
+
WebColors.LightGreen = [144, 238, 144, 1];
|
|
1085
|
+
WebColors.GreenYellow = [173, 255, 47, 1];
|
|
1086
|
+
WebColors.PaleGreen = [152, 251, 152, 1];
|
|
1087
|
+
WebColors.Teal = [0, 128, 128, 1];
|
|
1088
|
+
WebColors.DarkCyan = [0, 139, 139, 1];
|
|
1089
|
+
WebColors.LightSeaGreen = [32, 178, 170, 1];
|
|
1090
|
+
WebColors.CadetBlue = [95, 158, 160, 1];
|
|
1091
|
+
WebColors.DarkTurquoise = [0, 206, 209, 1];
|
|
1092
|
+
WebColors.MediumTurquoise = [72, 209, 204, 1];
|
|
1093
|
+
WebColors.Turquoise = [64, 224, 208, 1];
|
|
1094
|
+
WebColors.Aqua = [0, 255, 255, 1];
|
|
1095
|
+
WebColors.Cyan = [0, 255, 255, 1];
|
|
1096
|
+
WebColors.Aquamarine = [127, 255, 212, 1];
|
|
1097
|
+
WebColors.PaleTurquoise = [175, 238, 238, 1];
|
|
1098
|
+
WebColors.LightCyan = [224, 255, 255, 1];
|
|
1099
|
+
WebColors.Navy = [0, 0, 128, 1];
|
|
1100
|
+
WebColors.DarkBlue = [0, 0, 139, 1];
|
|
1101
|
+
WebColors.MediumBlue = [0, 0, 205, 1];
|
|
1102
|
+
WebColors.Blue = [0, 0, 255, 1];
|
|
1103
|
+
WebColors.MidnightBlue = [25, 25, 112, 1];
|
|
1104
|
+
WebColors.RoyalBlue = [65, 105, 225, 1];
|
|
1105
|
+
WebColors.SteelBlue = [70, 130, 180, 1];
|
|
1106
|
+
WebColors.DodgerBlue = [30, 144, 255, 1];
|
|
1107
|
+
WebColors.DeepSkyBlue = [0, 191, 255, 1];
|
|
1108
|
+
WebColors.CornflowerBlue = [100, 149, 237, 1];
|
|
1109
|
+
WebColors.SkyBlue = [135, 206, 235, 1];
|
|
1110
|
+
WebColors.LightSkyBlue = [135, 206, 250, 1];
|
|
1111
|
+
WebColors.LightSteelBlue = [176, 196, 222, 1];
|
|
1112
|
+
WebColors.LightBlue = [173, 216, 230, 1];
|
|
1113
|
+
WebColors.PowderBlue = [176, 224, 230, 1];
|
|
1114
|
+
WebColors.Indigo = [75, 0, 130, 1];
|
|
1115
|
+
WebColors.Purple = [128, 0, 128, 1];
|
|
1116
|
+
WebColors.DarkMagenta = [139, 0, 139, 1];
|
|
1117
|
+
WebColors.DarkViolet = [148, 0, 211, 1];
|
|
1118
|
+
WebColors.DarkSlateBlue = [72, 61, 139, 1];
|
|
1119
|
+
WebColors.BlueViolet = [138, 43, 226, 1];
|
|
1120
|
+
WebColors.DarkOrchid = [153, 50, 204, 1];
|
|
1121
|
+
WebColors.Fuchsia = [255, 0, 255, 1];
|
|
1122
|
+
WebColors.Magenta = [255, 0, 255, 1];
|
|
1123
|
+
WebColors.SlateBlue = [106, 90, 205, 1];
|
|
1124
|
+
WebColors.MediumSlateBlue = [123, 104, 238, 1];
|
|
1125
|
+
WebColors.MediumOrchid = [186, 85, 211, 1];
|
|
1126
|
+
WebColors.MediumPurple = [147, 112, 219, 1];
|
|
1127
|
+
WebColors.Orchid = [218, 112, 214, 1];
|
|
1128
|
+
WebColors.Violet = [238, 130, 238, 1];
|
|
1129
|
+
WebColors.Plum = [221, 160, 221, 1];
|
|
1130
|
+
WebColors.Thistle = [216, 191, 216, 1];
|
|
1131
|
+
WebColors.Lavender = [230, 230, 250, 1];
|
|
1132
|
+
WebColors.MistyRose = [255, 228, 225, 1];
|
|
1133
|
+
WebColors.AntiqueWhite = [250, 235, 215, 1];
|
|
1134
|
+
WebColors.Linen = [250, 240, 230, 1];
|
|
1135
|
+
WebColors.Beige = [245, 245, 220, 1];
|
|
1136
|
+
WebColors.WhiteSmoke = [245, 245, 245, 1];
|
|
1137
|
+
WebColors.LavenderBlush = [255, 240, 245, 1];
|
|
1138
|
+
WebColors.OldLace = [253, 245, 230, 1];
|
|
1139
|
+
WebColors.AliceBlue = [240, 248, 255, 1];
|
|
1140
|
+
WebColors.Seashell = [255, 245, 238, 1];
|
|
1141
|
+
WebColors.GhostWhite = [248, 248, 255, 1];
|
|
1142
|
+
WebColors.Honeydew = [240, 255, 240, 1];
|
|
1143
|
+
WebColors.FloralWhite = [255, 250, 240, 1];
|
|
1144
|
+
WebColors.Azure = [240, 255, 255, 1];
|
|
1145
|
+
WebColors.MintCream = [245, 255, 250, 1];
|
|
1146
|
+
WebColors.Snow = [255, 250, 250, 1];
|
|
1147
|
+
WebColors.Ivory = [255, 255, 240, 1];
|
|
1148
|
+
WebColors.White = [255, 255, 255, 1];
|
|
1149
|
+
WebColors.Black = [0, 0, 0, 1];
|
|
1150
|
+
WebColors.DarkSlateGray = [47, 79, 79, 1];
|
|
1151
|
+
WebColors.DimGray = [105, 105, 105, 1];
|
|
1152
|
+
WebColors.SlateGray = [112, 128, 144, 1];
|
|
1153
|
+
WebColors.Gray = [128, 128, 128, 1];
|
|
1154
|
+
WebColors.LightSlateGray = [119, 136, 153, 1];
|
|
1155
|
+
WebColors.DarkGray = [169, 169, 169, 1];
|
|
1156
|
+
WebColors.Silver = [192, 192, 192, 1];
|
|
1157
|
+
WebColors.LightGray = [211, 211, 211, 1];
|
|
1158
|
+
WebColors.Gainsboro = [220, 220, 220, 1];
|
|
1159
|
+
WebColors.RebeccaPurple = [102, 51, 153, 1];
|
|
1160
|
+
|
|
1161
|
+
class Constants {
|
|
1162
|
+
}
|
|
1163
|
+
/** Size of the font showing frames per second */
|
|
1164
|
+
Constants.FPS_DISPLAY_TEXT_FONT_SIZE = 12;
|
|
1165
|
+
/** Color of the font showing frames per second */
|
|
1166
|
+
Constants.FPS_DISPLAY_TEXT_COLOR = [0, 0, 0, 0.5];
|
|
1167
|
+
/** Frequency, in milliseconds, at which to update frames per second metric shown on the screen */
|
|
1168
|
+
Constants.FPS_DISPLAY_UPDATE_INTERVAL = 1e3;
|
|
1169
|
+
/** Maximum number of activity metrics to log. */
|
|
1170
|
+
Constants.MAXIMUM_RECORDED_ACTIVITY_METRICS = 32;
|
|
1171
|
+
/** The frames per second will be logged in game metrics if the FPS is lower than this value */
|
|
1172
|
+
Constants.FPS_METRIC_REPORT_THRESHOLD = 59;
|
|
1173
|
+
/** Scene color, if none is specified. */
|
|
1174
|
+
Constants.DEFAULT_SCENE_BACKGROUND_COLOR = WebColors.White;
|
|
1175
|
+
/** Shape fill color, if none is specified. */
|
|
1176
|
+
Constants.DEFAULT_SHAPE_FILL_COLOR = WebColors.Red;
|
|
1177
|
+
/** Color of paths in a shape, if none is specified. */
|
|
1178
|
+
Constants.DEFAULT_PATH_STROKE_COLOR = WebColors.Red;
|
|
1179
|
+
/** Line width of paths in a shape, if none is specified. */
|
|
1180
|
+
Constants.DEFAULT_PATH_LINE_WIDTH = 2;
|
|
1181
|
+
/** Color of text in Label and TextLine, if none is specified. */
|
|
1182
|
+
Constants.DEFAULT_FONT_COLOR = WebColors.Black;
|
|
1183
|
+
/** Font size in Label and TextLine, if none is specified. */
|
|
1184
|
+
Constants.DEFAULT_FONT_SIZE = 16;
|
|
1185
|
+
Constants.LIMITED_FPS_RATE = 5;
|
|
1186
|
+
Constants.FREE_ENTITIES_SCENE_NAME = "__freeEntitiesScene";
|
|
1187
|
+
Constants.OUTGOING_SCENE_NAME = "__outgoingScene";
|
|
1188
|
+
Constants.OUTGOING_SCENE_SPRITE_NAME = "__outgoingSceneSprite";
|
|
1189
|
+
Constants.OUTGOING_SCENE_IMAGE_NAME = "__outgoingSceneSnapshot";
|
|
1190
|
+
Constants.SESSION_INITIALIZATION_POLLING_INTERVAL_MS = 50;
|
|
1191
|
+
|
|
1192
|
+
class ColorfulMutablePath extends MutablePath {
|
|
1193
|
+
constructor() {
|
|
1194
|
+
super(...arguments);
|
|
1195
|
+
/** Stroke color to be applied to subsequent lines. */
|
|
1196
|
+
this.strokeColor = Constants.DEFAULT_PATH_STROKE_COLOR;
|
|
1197
|
+
/** Line width to be applied to subsequent lines. */
|
|
1198
|
+
this.lineWidth = Constants.DEFAULT_PATH_LINE_WIDTH;
|
|
1199
|
+
/** Colors and widths of lines in the path. */
|
|
1200
|
+
this.linePresentations = [];
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Adds a straight line to the current subpath
|
|
1204
|
+
*
|
|
1205
|
+
* @remarks The line is added from the last point in the current subpath to
|
|
1206
|
+
* the given point, with the current stroke color and line width.
|
|
1207
|
+
*
|
|
1208
|
+
* @param point - location where the line will end
|
|
1209
|
+
*/
|
|
1210
|
+
addLine(point) {
|
|
1211
|
+
if (this.isNewLinePresentation()) {
|
|
1212
|
+
this.linePresentations.push({
|
|
1213
|
+
strokeColor: this.strokeColor,
|
|
1214
|
+
lineWidth: this.lineWidth,
|
|
1215
|
+
subpathIndex: this._subpaths.length,
|
|
1216
|
+
pointIndex: this.currentPath.length - 1
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
this.currentPath.push(point);
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Checks if the current line presentation (stroke color and line width) is
|
|
1223
|
+
* different from the last line presentation.
|
|
1224
|
+
*
|
|
1225
|
+
* @returns true if the current line presentation is different from the last
|
|
1226
|
+
*/
|
|
1227
|
+
isNewLinePresentation() {
|
|
1228
|
+
if (this.linePresentations.length === 0) {
|
|
1229
|
+
return true;
|
|
1230
|
+
}
|
|
1231
|
+
const currentLinePresentation = this.linePresentations[this.linePresentations.length - 1];
|
|
1232
|
+
return currentLinePresentation.strokeColor !== this.strokeColor || currentLinePresentation.lineWidth !== this.lineWidth;
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Removes all subpaths from the shape and resets the stroke color and line
|
|
1236
|
+
* width to their default values.
|
|
1237
|
+
*/
|
|
1238
|
+
clear() {
|
|
1239
|
+
super.clear();
|
|
1240
|
+
this.linePresentations = [];
|
|
1241
|
+
this.strokeColor = Constants.DEFAULT_PATH_STROKE_COLOR;
|
|
1242
|
+
this.lineWidth = Constants.DEFAULT_PATH_LINE_WIDTH;
|
|
1243
|
+
}
|
|
1244
|
+
/**
|
|
1245
|
+
* Makes a deep copy.
|
|
1246
|
+
*
|
|
1247
|
+
* @returns a deep copy
|
|
1248
|
+
*/
|
|
1249
|
+
duplicate() {
|
|
1250
|
+
const newPath = super.duplicate();
|
|
1251
|
+
newPath.strokeColor = JSON.parse(JSON.stringify(this.strokeColor));
|
|
1252
|
+
newPath.lineWidth = this.lineWidth;
|
|
1253
|
+
newPath.linePresentations = JSON.parse(
|
|
1254
|
+
JSON.stringify(this.linePresentations)
|
|
1255
|
+
);
|
|
1256
|
+
return newPath;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
|
|
608
1260
|
class GlobalVariables {
|
|
609
1261
|
constructor() {
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
1262
|
+
this.now = NaN;
|
|
1263
|
+
this.deltaTime = NaN;
|
|
1264
|
+
this.canvasScale = NaN;
|
|
613
1265
|
// _rootScale is the scaling factor to be applied to scenes to scale up or
|
|
614
1266
|
// down to fit the device's window while preserving the aspect ratio the
|
|
615
1267
|
// game was designed for
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
1268
|
+
this.rootScale = 1;
|
|
1269
|
+
this.canvasCssWidth = NaN;
|
|
1270
|
+
this.canvasCssHeight = NaN;
|
|
619
1271
|
}
|
|
620
1272
|
}
|
|
621
1273
|
|
|
@@ -637,20 +1289,8 @@ var ConstraintType = /* @__PURE__ */ ((ConstraintType2) => {
|
|
|
637
1289
|
return ConstraintType2;
|
|
638
1290
|
})(ConstraintType || {});
|
|
639
1291
|
|
|
640
|
-
var __defProp$h = Object.defineProperty;
|
|
641
|
-
var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
642
|
-
var __publicField$h = (obj, key, value) => {
|
|
643
|
-
__defNormalProp$h(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
644
|
-
return value;
|
|
645
|
-
};
|
|
646
1292
|
class LayoutConstraint {
|
|
647
1293
|
constructor(type, alterEntity) {
|
|
648
|
-
// the constraint, e.g., bottomToTopOf
|
|
649
|
-
__publicField$h(this, "type");
|
|
650
|
-
// alter is the other entity that the focal entity is constrained to.
|
|
651
|
-
// in the example above, A is the focal entity, B is the alter
|
|
652
|
-
// thus the alter entity property is B
|
|
653
|
-
__publicField$h(this, "alterEntity");
|
|
654
1294
|
// the below 3 properties are calculated from the constraint type
|
|
655
1295
|
// (we set them to false by default to avoid undefined warnings, but
|
|
656
1296
|
// they will be definitely assigned in the constructor logic)
|
|
@@ -658,37 +1298,37 @@ class LayoutConstraint {
|
|
|
658
1298
|
//
|
|
659
1299
|
// does the constraint affect the Y or X axis? If not, then it's
|
|
660
1300
|
// a horizontal constraint
|
|
661
|
-
|
|
1301
|
+
this.verticalConstraint = false;
|
|
662
1302
|
// does the constraint apply to the focal entity's "minimum" position
|
|
663
1303
|
// along its axis? That is, does the constraint reference the focal
|
|
664
1304
|
// entity's "top" or "start"? Top and start are considered minimums because
|
|
665
1305
|
// our origin (0, 0) in the upper left.
|
|
666
1306
|
// If not, then the constraint applies to the focal entity's "maximum"
|
|
667
1307
|
// position, e.g., its "bottom" or "end".
|
|
668
|
-
|
|
1308
|
+
this.focalEntityMinimum = false;
|
|
669
1309
|
// does the constraint apply to the alter entity's "minimum" position
|
|
670
1310
|
// along its axis?
|
|
671
|
-
|
|
672
|
-
|
|
1311
|
+
this.alterEntityMinimum = false;
|
|
1312
|
+
this.verticalTypes = [
|
|
673
1313
|
ConstraintType.topToTopOf,
|
|
674
1314
|
ConstraintType.topToBottomOf,
|
|
675
1315
|
ConstraintType.bottomToTopOf,
|
|
676
1316
|
ConstraintType.bottomToBottomOf
|
|
677
|
-
]
|
|
1317
|
+
];
|
|
678
1318
|
// e.g., entity A
|
|
679
|
-
|
|
1319
|
+
this.focalEntityMinimumTypes = [
|
|
680
1320
|
ConstraintType.topToTopOf,
|
|
681
1321
|
ConstraintType.topToBottomOf,
|
|
682
1322
|
ConstraintType.startToStartOf,
|
|
683
1323
|
ConstraintType.startToEndOf
|
|
684
|
-
]
|
|
1324
|
+
];
|
|
685
1325
|
// e.g., entity B
|
|
686
|
-
|
|
1326
|
+
this.alterEntityMinimumTypes = [
|
|
687
1327
|
ConstraintType.topToTopOf,
|
|
688
1328
|
ConstraintType.bottomToTopOf,
|
|
689
1329
|
ConstraintType.startToStartOf,
|
|
690
1330
|
ConstraintType.endToStartOf
|
|
691
|
-
]
|
|
1331
|
+
];
|
|
692
1332
|
this.type = type;
|
|
693
1333
|
this.alterEntity = alterEntity;
|
|
694
1334
|
if (this.verticalTypes.includes(type)) {
|
|
@@ -716,29 +1356,18 @@ class LayoutConstraint {
|
|
|
716
1356
|
this.alterEntityMinimum = false;
|
|
717
1357
|
}
|
|
718
1358
|
}
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
var EntityType = /* @__PURE__ */ ((EntityType2) => {
|
|
723
|
-
EntityType2["Entity"] = "Entity";
|
|
724
|
-
EntityType2["Scene"] = "Scene";
|
|
725
|
-
EntityType2["Sprite"] = "Sprite";
|
|
726
|
-
EntityType2["Label"] = "Label";
|
|
727
|
-
EntityType2["TextLine"] = "TextLine";
|
|
728
|
-
EntityType2["Shape"] = "Shape";
|
|
729
|
-
EntityType2["Composite"] = "Composite";
|
|
730
|
-
return EntityType2;
|
|
731
|
-
})(EntityType || {});
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
732
1361
|
|
|
733
1362
|
class Uuid {
|
|
734
1363
|
static generate() {
|
|
735
1364
|
try {
|
|
736
1365
|
return crypto.randomUUID();
|
|
737
|
-
} catch
|
|
1366
|
+
} catch {
|
|
738
1367
|
let randomValue;
|
|
739
1368
|
try {
|
|
740
1369
|
randomValue = () => crypto.getRandomValues(new Uint8Array(1))[0];
|
|
741
|
-
} catch
|
|
1370
|
+
} catch {
|
|
742
1371
|
randomValue = () => Math.floor(Math.random() * 256);
|
|
743
1372
|
}
|
|
744
1373
|
return (1e7.toString() + -1e3 + -4e3 + -8e3 + -1e11).replace(
|
|
@@ -772,31 +1401,25 @@ const EventType = {
|
|
|
772
1401
|
FrameDidSimulatePhysics: "FrameDidSimulatePhysics"
|
|
773
1402
|
};
|
|
774
1403
|
|
|
775
|
-
var __defProp$g = Object.defineProperty;
|
|
776
|
-
var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
777
|
-
var __publicField$g = (obj, key, value) => {
|
|
778
|
-
__defNormalProp$g(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
779
|
-
return value;
|
|
780
|
-
};
|
|
781
1404
|
function handleDrawableOptions(drawable, options) {
|
|
782
1405
|
if (options.anchorPoint) {
|
|
783
1406
|
drawable.anchorPoint = options.anchorPoint;
|
|
784
1407
|
}
|
|
785
|
-
if (options.zPosition) {
|
|
1408
|
+
if (options.zPosition !== void 0) {
|
|
786
1409
|
drawable.zPosition = options.zPosition;
|
|
787
1410
|
}
|
|
788
1411
|
}
|
|
789
1412
|
function handleTextOptions(text, options) {
|
|
790
|
-
if (options.text) {
|
|
1413
|
+
if (options.text !== void 0) {
|
|
791
1414
|
text.text = options.text;
|
|
792
1415
|
}
|
|
793
|
-
if (options.fontName) {
|
|
1416
|
+
if (options.fontName !== void 0) {
|
|
794
1417
|
text.fontName = options.fontName;
|
|
795
1418
|
}
|
|
796
1419
|
if (options.fontColor) {
|
|
797
1420
|
text.fontColor = options.fontColor;
|
|
798
1421
|
}
|
|
799
|
-
if (options.fontSize) {
|
|
1422
|
+
if (options.fontSize !== void 0) {
|
|
800
1423
|
text.fontSize = options.fontSize;
|
|
801
1424
|
}
|
|
802
1425
|
}
|
|
@@ -813,60 +1436,59 @@ function handleInterfaceOptions(entity, options) {
|
|
|
813
1436
|
}
|
|
814
1437
|
class Entity {
|
|
815
1438
|
constructor(options = {}) {
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
__publicField$g(this, "name");
|
|
822
|
-
__publicField$g(this, "position", { x: 0, y: 0 });
|
|
1439
|
+
this.type = EntityType.Entity;
|
|
1440
|
+
this.isDrawable = false;
|
|
1441
|
+
this.isShape = false;
|
|
1442
|
+
this.isText = false;
|
|
1443
|
+
this.position = { x: 0, y: 0 };
|
|
823
1444
|
// position of the entity in the parent coordinate system
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
1445
|
+
this.scale = 1;
|
|
1446
|
+
this.alpha = 1;
|
|
1447
|
+
this.zRotation = 0;
|
|
1448
|
+
this.isUserInteractionEnabled = false;
|
|
1449
|
+
this.draggable = false;
|
|
1450
|
+
this.hidden = false;
|
|
1451
|
+
this.layout = {};
|
|
1452
|
+
this.children = new Array();
|
|
1453
|
+
this.absolutePosition = { x: 0, y: 0 };
|
|
833
1454
|
// position within the root coordinate system
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
1455
|
+
this.size = { width: 0, height: 0 };
|
|
1456
|
+
this.absoluteScale = 1;
|
|
1457
|
+
this.absoluteAlpha = 1;
|
|
1458
|
+
this.absoluteAlphaChange = 0;
|
|
1459
|
+
this.actions = new Array();
|
|
1460
|
+
this.originalActions = new Array();
|
|
1461
|
+
this.eventListeners = new Array();
|
|
1462
|
+
this.uuid = Uuid.generate();
|
|
1463
|
+
this.needsInitialization = true;
|
|
842
1464
|
// library users might put anything in userData property
|
|
843
1465
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
844
|
-
|
|
845
|
-
|
|
1466
|
+
this.userData = {};
|
|
1467
|
+
this.loopMessages = /* @__PURE__ */ new Set();
|
|
846
1468
|
/** Is the entity in a pressed state? E.g., did the user put the pointer
|
|
847
1469
|
* down on the entity and not yet release it? */
|
|
848
|
-
|
|
849
|
-
|
|
1470
|
+
this.pressed = false;
|
|
1471
|
+
this.withinHitArea = false;
|
|
850
1472
|
/** Is the entity in a pressed state AND is the pointer within the entity's
|
|
851
1473
|
* hit area? For example, a user may put the pointer down on the entity, but
|
|
852
1474
|
* then move the pointer, while still down, beyond the entity's hit area. In
|
|
853
1475
|
* this case, pressed = true, but pressedAndWithinHitArea = false. */
|
|
854
|
-
|
|
1476
|
+
this.pressedAndWithinHitArea = false;
|
|
855
1477
|
/** When the entity initially enters the pressed state, what is the pointer
|
|
856
1478
|
* offset? (offset from the canvas's origin to the pointer position). We
|
|
857
1479
|
* save this because it will be needed if this press then led to a drag. */
|
|
858
|
-
|
|
1480
|
+
this.pressedInitialPointerOffset = { x: NaN, y: NaN };
|
|
859
1481
|
/** What was the previous pointer offset when the entity was in a dragging
|
|
860
1482
|
* state? */
|
|
861
|
-
|
|
1483
|
+
this.draggingLastPointerOffset = { x: NaN, y: NaN };
|
|
862
1484
|
/** Is the entity in a dragging state? */
|
|
863
|
-
|
|
1485
|
+
this.dragging = false;
|
|
864
1486
|
/**
|
|
865
1487
|
* Overrides toString() and returns a human-friendly description of the entity.
|
|
866
1488
|
*
|
|
867
1489
|
* @remarks Inspiration from https://stackoverflow.com/a/35361695
|
|
868
1490
|
*/
|
|
869
|
-
|
|
1491
|
+
this.toString = () => {
|
|
870
1492
|
let type = this.type.toString();
|
|
871
1493
|
if (this.type == EntityType.Composite) {
|
|
872
1494
|
type = this.compositeType;
|
|
@@ -876,28 +1498,34 @@ class Entity {
|
|
|
876
1498
|
} else {
|
|
877
1499
|
return `${type} (${this.uuid})`;
|
|
878
1500
|
}
|
|
879
|
-
}
|
|
1501
|
+
};
|
|
880
1502
|
if (options.name === void 0) {
|
|
881
1503
|
this.name = this.uuid;
|
|
882
1504
|
} else {
|
|
883
1505
|
this.name = options.name;
|
|
884
1506
|
}
|
|
885
|
-
if (options.position) {
|
|
1507
|
+
if (options.position !== void 0) {
|
|
886
1508
|
this.position = options.position;
|
|
887
1509
|
}
|
|
888
|
-
if (options.scale) {
|
|
1510
|
+
if (options.scale !== void 0) {
|
|
889
1511
|
this.scale = options.scale;
|
|
890
1512
|
}
|
|
891
|
-
if (options.
|
|
1513
|
+
if (options.alpha !== void 0) {
|
|
1514
|
+
this.alpha = options.alpha;
|
|
1515
|
+
}
|
|
1516
|
+
if (options.zRotation !== void 0) {
|
|
1517
|
+
this.zRotation = options.zRotation;
|
|
1518
|
+
}
|
|
1519
|
+
if (options.isUserInteractionEnabled !== void 0) {
|
|
892
1520
|
this.isUserInteractionEnabled = options.isUserInteractionEnabled;
|
|
893
1521
|
}
|
|
894
|
-
if (options.draggable) {
|
|
1522
|
+
if (options.draggable !== void 0) {
|
|
895
1523
|
this.draggable = options.draggable;
|
|
896
1524
|
}
|
|
897
|
-
if (options.hidden) {
|
|
1525
|
+
if (options.hidden !== void 0) {
|
|
898
1526
|
this.hidden = options.hidden;
|
|
899
1527
|
}
|
|
900
|
-
if (options.layout) {
|
|
1528
|
+
if (options.layout !== void 0) {
|
|
901
1529
|
this.layout = options.layout;
|
|
902
1530
|
}
|
|
903
1531
|
}
|
|
@@ -928,7 +1556,6 @@ class Entity {
|
|
|
928
1556
|
* @returns true if entity has been added
|
|
929
1557
|
*/
|
|
930
1558
|
isPartOfGame() {
|
|
931
|
-
var _a;
|
|
932
1559
|
if (this.type === EntityType.Scene && this._game === void 0) {
|
|
933
1560
|
return false;
|
|
934
1561
|
}
|
|
@@ -944,7 +1571,7 @@ class Entity {
|
|
|
944
1571
|
return findParentScene(entity.parent);
|
|
945
1572
|
}
|
|
946
1573
|
};
|
|
947
|
-
return
|
|
1574
|
+
return findParentScene(this)?._game !== void 0;
|
|
948
1575
|
}
|
|
949
1576
|
/**
|
|
950
1577
|
* Adds a child to this parent entity. Throws exception if the child's name
|
|
@@ -977,10 +1604,7 @@ class Entity {
|
|
|
977
1604
|
} else {
|
|
978
1605
|
const descendants = this.descendants;
|
|
979
1606
|
if (descendants.includes(child)) {
|
|
980
|
-
otherParents = descendants.filter((d) => d.children.includes(child)).map((d) =>
|
|
981
|
-
var _a;
|
|
982
|
-
return (_a = d.parent) != null ? _a : void 0;
|
|
983
|
-
});
|
|
1607
|
+
otherParents = descendants.filter((d) => d.children.includes(child)).map((d) => d.parent ?? void 0);
|
|
984
1608
|
}
|
|
985
1609
|
}
|
|
986
1610
|
if (otherParents.length === 0) {
|
|
@@ -995,7 +1619,7 @@ class Entity {
|
|
|
995
1619
|
);
|
|
996
1620
|
}
|
|
997
1621
|
throw new Error(
|
|
998
|
-
`Cannot add child entity ${child.toString()} to parent entity ${this.toString()}. This child already exists on other parent entity: ${firstOtherParent
|
|
1622
|
+
`Cannot add child entity ${child.toString()} to parent entity ${this.toString()}. This child already exists on other parent entity: ${firstOtherParent?.toString()}}. Remove the child from the other parent first.`
|
|
999
1623
|
);
|
|
1000
1624
|
}
|
|
1001
1625
|
/**
|
|
@@ -1302,7 +1926,7 @@ class Entity {
|
|
|
1302
1926
|
entityUuid: this.uuid,
|
|
1303
1927
|
callback
|
|
1304
1928
|
};
|
|
1305
|
-
if (callbackOptions
|
|
1929
|
+
if (callbackOptions?.replaceExisting) {
|
|
1306
1930
|
this.eventListeners = this.eventListeners.filter(
|
|
1307
1931
|
(listener) => !(listener.entityUuid === eventListener.entityUuid && listener.type === eventListener.type)
|
|
1308
1932
|
);
|
|
@@ -1383,30 +2007,47 @@ class Entity {
|
|
|
1383
2007
|
}
|
|
1384
2008
|
return x;
|
|
1385
2009
|
}
|
|
2010
|
+
/**
|
|
2011
|
+
* Calculates the absolute alpha of the entity, taking into account the
|
|
2012
|
+
* alpha of all ancestor parent entities.
|
|
2013
|
+
*
|
|
2014
|
+
* @remarks Alpha has multiplicative inheritance from all ancestors.
|
|
2015
|
+
*
|
|
2016
|
+
* @param alpha - Opacity of the entity
|
|
2017
|
+
* @param ancestors - Array of ancestor parent entities
|
|
2018
|
+
* @returns
|
|
2019
|
+
*/
|
|
2020
|
+
calculateAbsoluteAlpha(alpha, ancestors) {
|
|
2021
|
+
const inheritedAlpha = ancestors.reduce((acc, ancestor) => {
|
|
2022
|
+
return acc * ancestor.alpha;
|
|
2023
|
+
}, 1);
|
|
2024
|
+
return alpha * inheritedAlpha;
|
|
2025
|
+
}
|
|
1386
2026
|
update() {
|
|
1387
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
1388
2027
|
if (this.needsInitialization) {
|
|
1389
2028
|
this.initialize();
|
|
1390
2029
|
this.needsInitialization = false;
|
|
1391
2030
|
}
|
|
2031
|
+
this.absoluteAlphaChange = this.calculateAbsoluteAlpha(this.alpha, this.ancestors) - this.absoluteAlpha;
|
|
2032
|
+
this.absoluteAlpha += this.absoluteAlphaChange;
|
|
1392
2033
|
if (this.parent === void 0) {
|
|
1393
2034
|
this.absolutePosition.x = this.position.x * this.scale;
|
|
1394
2035
|
this.absolutePosition.y = this.position.y * this.scale;
|
|
1395
2036
|
this.absoluteScale = this.scale;
|
|
1396
2037
|
} else {
|
|
1397
2038
|
this.absoluteScale = this.parent.absoluteScale * this.scale;
|
|
1398
|
-
if (
|
|
2039
|
+
if (this.layout?.constraints === void 0) {
|
|
1399
2040
|
this.absolutePosition.x = this.parent.absolutePosition.x + this.position.x * this.parent.absoluteScale;
|
|
1400
2041
|
this.absolutePosition.y = this.parent.absolutePosition.y + this.position.y * this.parent.absoluteScale;
|
|
1401
2042
|
} else {
|
|
1402
|
-
const horizontalBias =
|
|
1403
|
-
const verticalBias =
|
|
1404
|
-
const marginTop =
|
|
1405
|
-
const marginBottom =
|
|
1406
|
-
const marginStart =
|
|
1407
|
-
const marginEnd =
|
|
2043
|
+
const horizontalBias = this.layout?.constraints?.horizontalBias ?? 0.5;
|
|
2044
|
+
const verticalBias = this.layout?.constraints?.verticalBias ?? 0.5;
|
|
2045
|
+
const marginTop = this.layout?.marginTop ?? 0;
|
|
2046
|
+
const marginBottom = this.layout?.marginBottom ?? 0;
|
|
2047
|
+
const marginStart = this.layout?.marginStart ?? 0;
|
|
2048
|
+
const marginEnd = this.layout?.marginEnd ?? 0;
|
|
1408
2049
|
const layoutConstraints = this.parseLayoutConstraints(
|
|
1409
|
-
|
|
2050
|
+
this.layout?.constraints,
|
|
1410
2051
|
//this.parentScene.game.entities
|
|
1411
2052
|
this.parentSceneAsEntity.descendants
|
|
1412
2053
|
);
|
|
@@ -1504,10 +2145,9 @@ class Entity {
|
|
|
1504
2145
|
}
|
|
1505
2146
|
const adjList = /* @__PURE__ */ new Map();
|
|
1506
2147
|
this.children.forEach((child) => {
|
|
1507
|
-
var _a2;
|
|
1508
2148
|
adjList.set(
|
|
1509
2149
|
child.uuid,
|
|
1510
|
-
getSiblingConstraintUuids(this,
|
|
2150
|
+
getSiblingConstraintUuids(this, child.layout?.constraints)
|
|
1511
2151
|
);
|
|
1512
2152
|
});
|
|
1513
2153
|
const sortedUuids = this.findTopologicalSort(adjList);
|
|
@@ -1643,7 +2283,6 @@ class Entity {
|
|
|
1643
2283
|
* @param adjList Adjacency List that represent a graph with vertices and edges
|
|
1644
2284
|
*/
|
|
1645
2285
|
findTopologicalSort(adjList) {
|
|
1646
|
-
var _a;
|
|
1647
2286
|
const tSort = [];
|
|
1648
2287
|
const inDegree = /* @__PURE__ */ new Map();
|
|
1649
2288
|
adjList.forEach((edges, vertex) => {
|
|
@@ -1671,7 +2310,7 @@ class Entity {
|
|
|
1671
2310
|
}
|
|
1672
2311
|
tSort.push(current);
|
|
1673
2312
|
if (adjList.has(current)) {
|
|
1674
|
-
|
|
2313
|
+
adjList.get(current)?.forEach((edge) => {
|
|
1675
2314
|
if (inDegree.has(edge) && inDegree.get(edge) > 0) {
|
|
1676
2315
|
const newDegree = inDegree.get(edge) - 1;
|
|
1677
2316
|
inDegree.set(edge, newDegree);
|
|
@@ -1686,12 +2325,6 @@ class Entity {
|
|
|
1686
2325
|
}
|
|
1687
2326
|
}
|
|
1688
2327
|
|
|
1689
|
-
var __defProp$f = Object.defineProperty;
|
|
1690
|
-
var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1691
|
-
var __publicField$f = (obj, key, value) => {
|
|
1692
|
-
__defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1693
|
-
return value;
|
|
1694
|
-
};
|
|
1695
2328
|
class Composite extends Entity {
|
|
1696
2329
|
/**
|
|
1697
2330
|
* Base Drawable object for creating custom entities ("composites") composed of primitive entities.
|
|
@@ -1700,12 +2333,12 @@ class Composite extends Entity {
|
|
|
1700
2333
|
*/
|
|
1701
2334
|
constructor(options = {}) {
|
|
1702
2335
|
super(options);
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
2336
|
+
this.type = EntityType.Composite;
|
|
2337
|
+
this.compositeType = "<compositeType>";
|
|
2338
|
+
this.isDrawable = true;
|
|
1706
2339
|
// Drawable options
|
|
1707
|
-
|
|
1708
|
-
|
|
2340
|
+
this.anchorPoint = { x: 0.5, y: 0.5 };
|
|
2341
|
+
this.zPosition = 0;
|
|
1709
2342
|
handleInterfaceOptions(this, options);
|
|
1710
2343
|
}
|
|
1711
2344
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
@@ -1722,194 +2355,6 @@ class Composite extends Entity {
|
|
|
1722
2355
|
}
|
|
1723
2356
|
}
|
|
1724
2357
|
|
|
1725
|
-
var __defProp$e = Object.defineProperty;
|
|
1726
|
-
var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1727
|
-
var __publicField$e = (obj, key, value) => {
|
|
1728
|
-
__defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1729
|
-
return value;
|
|
1730
|
-
};
|
|
1731
|
-
class WebColors {
|
|
1732
|
-
}
|
|
1733
|
-
__publicField$e(WebColors, "Transparent", [0, 0, 0, 0]);
|
|
1734
|
-
__publicField$e(WebColors, "MediumVioletRed", [199, 21, 133, 1]);
|
|
1735
|
-
__publicField$e(WebColors, "DeepPink", [255, 20, 147, 1]);
|
|
1736
|
-
__publicField$e(WebColors, "PaleVioletRed", [219, 112, 147, 1]);
|
|
1737
|
-
__publicField$e(WebColors, "HotPink", [255, 105, 180, 1]);
|
|
1738
|
-
__publicField$e(WebColors, "LightPink", [255, 182, 193, 1]);
|
|
1739
|
-
__publicField$e(WebColors, "Pink", [255, 192, 203, 1]);
|
|
1740
|
-
__publicField$e(WebColors, "DarkRed", [139, 0, 0, 1]);
|
|
1741
|
-
__publicField$e(WebColors, "Red", [255, 0, 0, 1]);
|
|
1742
|
-
__publicField$e(WebColors, "Firebrick", [178, 34, 34, 1]);
|
|
1743
|
-
__publicField$e(WebColors, "Crimson", [220, 20, 60, 1]);
|
|
1744
|
-
__publicField$e(WebColors, "IndianRed", [205, 92, 92, 1]);
|
|
1745
|
-
__publicField$e(WebColors, "LightCoral", [240, 128, 128, 1]);
|
|
1746
|
-
__publicField$e(WebColors, "Salmon", [250, 128, 114, 1]);
|
|
1747
|
-
__publicField$e(WebColors, "DarkSalmon", [233, 150, 122, 1]);
|
|
1748
|
-
__publicField$e(WebColors, "LightSalmon", [255, 160, 122, 1]);
|
|
1749
|
-
__publicField$e(WebColors, "OrangeRed", [255, 69, 0, 1]);
|
|
1750
|
-
__publicField$e(WebColors, "Tomato", [255, 99, 71, 1]);
|
|
1751
|
-
__publicField$e(WebColors, "DarkOrange", [255, 140, 0, 1]);
|
|
1752
|
-
__publicField$e(WebColors, "Coral", [255, 127, 80, 1]);
|
|
1753
|
-
__publicField$e(WebColors, "Orange", [255, 165, 0, 1]);
|
|
1754
|
-
__publicField$e(WebColors, "DarkKhaki", [189, 183, 107, 1]);
|
|
1755
|
-
__publicField$e(WebColors, "Gold", [255, 215, 0, 1]);
|
|
1756
|
-
__publicField$e(WebColors, "Khaki", [240, 230, 140, 1]);
|
|
1757
|
-
__publicField$e(WebColors, "PeachPuff", [255, 218, 185, 1]);
|
|
1758
|
-
__publicField$e(WebColors, "Yellow", [255, 255, 0, 1]);
|
|
1759
|
-
__publicField$e(WebColors, "PaleGoldenrod", [238, 232, 170, 1]);
|
|
1760
|
-
__publicField$e(WebColors, "Moccasin", [255, 228, 181, 1]);
|
|
1761
|
-
__publicField$e(WebColors, "PapayaWhip", [255, 239, 213, 1]);
|
|
1762
|
-
__publicField$e(WebColors, "LightGoldenrodYellow", [250, 250, 210, 1]);
|
|
1763
|
-
__publicField$e(WebColors, "LemonChiffon", [255, 250, 205, 1]);
|
|
1764
|
-
__publicField$e(WebColors, "LightYellow", [255, 255, 224, 1]);
|
|
1765
|
-
__publicField$e(WebColors, "Maroon", [128, 0, 0, 1]);
|
|
1766
|
-
__publicField$e(WebColors, "Brown", [165, 42, 42, 1]);
|
|
1767
|
-
__publicField$e(WebColors, "SaddleBrown", [139, 69, 19, 1]);
|
|
1768
|
-
__publicField$e(WebColors, "Sienna", [160, 82, 45, 1]);
|
|
1769
|
-
__publicField$e(WebColors, "Chocolate", [210, 105, 30, 1]);
|
|
1770
|
-
__publicField$e(WebColors, "DarkGoldenrod", [184, 134, 11, 1]);
|
|
1771
|
-
__publicField$e(WebColors, "Peru", [205, 133, 63, 1]);
|
|
1772
|
-
__publicField$e(WebColors, "RosyBrown", [188, 143, 143, 1]);
|
|
1773
|
-
__publicField$e(WebColors, "Goldenrod", [218, 165, 32, 1]);
|
|
1774
|
-
__publicField$e(WebColors, "SandyBrown", [244, 164, 96, 1]);
|
|
1775
|
-
__publicField$e(WebColors, "Tan", [210, 180, 140, 1]);
|
|
1776
|
-
__publicField$e(WebColors, "Burlywood", [222, 184, 135, 1]);
|
|
1777
|
-
__publicField$e(WebColors, "Wheat", [245, 222, 179, 1]);
|
|
1778
|
-
__publicField$e(WebColors, "NavajoWhite", [255, 222, 173, 1]);
|
|
1779
|
-
__publicField$e(WebColors, "Bisque", [255, 228, 196, 1]);
|
|
1780
|
-
__publicField$e(WebColors, "BlanchedAlmond", [255, 235, 205, 1]);
|
|
1781
|
-
__publicField$e(WebColors, "Cornsilk", [255, 248, 220, 1]);
|
|
1782
|
-
__publicField$e(WebColors, "DarkGreen", [0, 100, 0, 1]);
|
|
1783
|
-
__publicField$e(WebColors, "Green", [0, 128, 0, 1]);
|
|
1784
|
-
__publicField$e(WebColors, "DarkOliveGreen", [85, 107, 47, 1]);
|
|
1785
|
-
__publicField$e(WebColors, "ForestGreen", [34, 139, 34, 1]);
|
|
1786
|
-
__publicField$e(WebColors, "SeaGreen", [46, 139, 87, 1]);
|
|
1787
|
-
__publicField$e(WebColors, "Olive", [128, 128, 0, 1]);
|
|
1788
|
-
__publicField$e(WebColors, "OliveDrab", [107, 142, 35, 1]);
|
|
1789
|
-
__publicField$e(WebColors, "MediumSeaGreen", [60, 179, 113, 1]);
|
|
1790
|
-
__publicField$e(WebColors, "LimeGreen", [50, 205, 50, 1]);
|
|
1791
|
-
__publicField$e(WebColors, "Lime", [0, 255, 0, 1]);
|
|
1792
|
-
__publicField$e(WebColors, "SpringGreen", [0, 255, 127, 1]);
|
|
1793
|
-
__publicField$e(WebColors, "MediumSpringGreen", [0, 250, 154, 1]);
|
|
1794
|
-
__publicField$e(WebColors, "DarkSeaGreen", [143, 188, 143, 1]);
|
|
1795
|
-
__publicField$e(WebColors, "MediumAquamarine", [102, 205, 170, 1]);
|
|
1796
|
-
__publicField$e(WebColors, "YellowGreen", [154, 205, 50, 1]);
|
|
1797
|
-
__publicField$e(WebColors, "LawnGreen", [124, 252, 0, 1]);
|
|
1798
|
-
__publicField$e(WebColors, "Chartreuse", [127, 255, 0, 1]);
|
|
1799
|
-
__publicField$e(WebColors, "LightGreen", [144, 238, 144, 1]);
|
|
1800
|
-
__publicField$e(WebColors, "GreenYellow", [173, 255, 47, 1]);
|
|
1801
|
-
__publicField$e(WebColors, "PaleGreen", [152, 251, 152, 1]);
|
|
1802
|
-
__publicField$e(WebColors, "Teal", [0, 128, 128, 1]);
|
|
1803
|
-
__publicField$e(WebColors, "DarkCyan", [0, 139, 139, 1]);
|
|
1804
|
-
__publicField$e(WebColors, "LightSeaGreen", [32, 178, 170, 1]);
|
|
1805
|
-
__publicField$e(WebColors, "CadetBlue", [95, 158, 160, 1]);
|
|
1806
|
-
__publicField$e(WebColors, "DarkTurquoise", [0, 206, 209, 1]);
|
|
1807
|
-
__publicField$e(WebColors, "MediumTurquoise", [72, 209, 204, 1]);
|
|
1808
|
-
__publicField$e(WebColors, "Turquoise", [64, 224, 208, 1]);
|
|
1809
|
-
__publicField$e(WebColors, "Aqua", [0, 255, 255, 1]);
|
|
1810
|
-
__publicField$e(WebColors, "Cyan", [0, 255, 255, 1]);
|
|
1811
|
-
__publicField$e(WebColors, "Aquamarine", [127, 255, 212, 1]);
|
|
1812
|
-
__publicField$e(WebColors, "PaleTurquoise", [175, 238, 238, 1]);
|
|
1813
|
-
__publicField$e(WebColors, "LightCyan", [224, 255, 255, 1]);
|
|
1814
|
-
__publicField$e(WebColors, "Navy", [0, 0, 128, 1]);
|
|
1815
|
-
__publicField$e(WebColors, "DarkBlue", [0, 0, 139, 1]);
|
|
1816
|
-
__publicField$e(WebColors, "MediumBlue", [0, 0, 205, 1]);
|
|
1817
|
-
__publicField$e(WebColors, "Blue", [0, 0, 255, 1]);
|
|
1818
|
-
__publicField$e(WebColors, "MidnightBlue", [25, 25, 112, 1]);
|
|
1819
|
-
__publicField$e(WebColors, "RoyalBlue", [65, 105, 225, 1]);
|
|
1820
|
-
__publicField$e(WebColors, "SteelBlue", [70, 130, 180, 1]);
|
|
1821
|
-
__publicField$e(WebColors, "DodgerBlue", [30, 144, 255, 1]);
|
|
1822
|
-
__publicField$e(WebColors, "DeepSkyBlue", [0, 191, 255, 1]);
|
|
1823
|
-
__publicField$e(WebColors, "CornflowerBlue", [100, 149, 237, 1]);
|
|
1824
|
-
__publicField$e(WebColors, "SkyBlue", [135, 206, 235, 1]);
|
|
1825
|
-
__publicField$e(WebColors, "LightSkyBlue", [135, 206, 250, 1]);
|
|
1826
|
-
__publicField$e(WebColors, "LightSteelBlue", [176, 196, 222, 1]);
|
|
1827
|
-
__publicField$e(WebColors, "LightBlue", [173, 216, 230, 1]);
|
|
1828
|
-
__publicField$e(WebColors, "PowderBlue", [176, 224, 230, 1]);
|
|
1829
|
-
__publicField$e(WebColors, "Indigo", [75, 0, 130, 1]);
|
|
1830
|
-
__publicField$e(WebColors, "Purple", [128, 0, 128, 1]);
|
|
1831
|
-
__publicField$e(WebColors, "DarkMagenta", [139, 0, 139, 1]);
|
|
1832
|
-
__publicField$e(WebColors, "DarkViolet", [148, 0, 211, 1]);
|
|
1833
|
-
__publicField$e(WebColors, "DarkSlateBlue", [72, 61, 139, 1]);
|
|
1834
|
-
__publicField$e(WebColors, "BlueViolet", [138, 43, 226, 1]);
|
|
1835
|
-
__publicField$e(WebColors, "DarkOrchid", [153, 50, 204, 1]);
|
|
1836
|
-
__publicField$e(WebColors, "Fuchsia", [255, 0, 255, 1]);
|
|
1837
|
-
__publicField$e(WebColors, "Magenta", [255, 0, 255, 1]);
|
|
1838
|
-
__publicField$e(WebColors, "SlateBlue", [106, 90, 205, 1]);
|
|
1839
|
-
__publicField$e(WebColors, "MediumSlateBlue", [123, 104, 238, 1]);
|
|
1840
|
-
__publicField$e(WebColors, "MediumOrchid", [186, 85, 211, 1]);
|
|
1841
|
-
__publicField$e(WebColors, "MediumPurple", [147, 112, 219, 1]);
|
|
1842
|
-
__publicField$e(WebColors, "Orchid", [218, 112, 214, 1]);
|
|
1843
|
-
__publicField$e(WebColors, "Violet", [238, 130, 238, 1]);
|
|
1844
|
-
__publicField$e(WebColors, "Plum", [221, 160, 221, 1]);
|
|
1845
|
-
__publicField$e(WebColors, "Thistle", [216, 191, 216, 1]);
|
|
1846
|
-
__publicField$e(WebColors, "Lavender", [230, 230, 250, 1]);
|
|
1847
|
-
__publicField$e(WebColors, "MistyRose", [255, 228, 225, 1]);
|
|
1848
|
-
__publicField$e(WebColors, "AntiqueWhite", [250, 235, 215, 1]);
|
|
1849
|
-
__publicField$e(WebColors, "Linen", [250, 240, 230, 1]);
|
|
1850
|
-
__publicField$e(WebColors, "Beige", [245, 245, 220, 1]);
|
|
1851
|
-
__publicField$e(WebColors, "WhiteSmoke", [245, 245, 245, 1]);
|
|
1852
|
-
__publicField$e(WebColors, "LavenderBlush", [255, 240, 245, 1]);
|
|
1853
|
-
__publicField$e(WebColors, "OldLace", [253, 245, 230, 1]);
|
|
1854
|
-
__publicField$e(WebColors, "AliceBlue", [240, 248, 255, 1]);
|
|
1855
|
-
__publicField$e(WebColors, "Seashell", [255, 245, 238, 1]);
|
|
1856
|
-
__publicField$e(WebColors, "GhostWhite", [248, 248, 255, 1]);
|
|
1857
|
-
__publicField$e(WebColors, "Honeydew", [240, 255, 240, 1]);
|
|
1858
|
-
__publicField$e(WebColors, "FloralWhite", [255, 250, 240, 1]);
|
|
1859
|
-
__publicField$e(WebColors, "Azure", [240, 255, 255, 1]);
|
|
1860
|
-
__publicField$e(WebColors, "MintCream", [245, 255, 250, 1]);
|
|
1861
|
-
__publicField$e(WebColors, "Snow", [255, 250, 250, 1]);
|
|
1862
|
-
__publicField$e(WebColors, "Ivory", [255, 255, 240, 1]);
|
|
1863
|
-
__publicField$e(WebColors, "White", [255, 255, 255, 1]);
|
|
1864
|
-
__publicField$e(WebColors, "Black", [0, 0, 0, 1]);
|
|
1865
|
-
__publicField$e(WebColors, "DarkSlateGray", [47, 79, 79, 1]);
|
|
1866
|
-
__publicField$e(WebColors, "DimGray", [105, 105, 105, 1]);
|
|
1867
|
-
__publicField$e(WebColors, "SlateGray", [112, 128, 144, 1]);
|
|
1868
|
-
__publicField$e(WebColors, "Gray", [128, 128, 128, 1]);
|
|
1869
|
-
__publicField$e(WebColors, "LightSlateGray", [119, 136, 153, 1]);
|
|
1870
|
-
__publicField$e(WebColors, "DarkGray", [169, 169, 169, 1]);
|
|
1871
|
-
__publicField$e(WebColors, "Silver", [192, 192, 192, 1]);
|
|
1872
|
-
__publicField$e(WebColors, "LightGray", [211, 211, 211, 1]);
|
|
1873
|
-
__publicField$e(WebColors, "Gainsboro", [220, 220, 220, 1]);
|
|
1874
|
-
__publicField$e(WebColors, "RebeccaPurple", [102, 51, 153, 1]);
|
|
1875
|
-
|
|
1876
|
-
var __defProp$d = Object.defineProperty;
|
|
1877
|
-
var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1878
|
-
var __publicField$d = (obj, key, value) => {
|
|
1879
|
-
__defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1880
|
-
return value;
|
|
1881
|
-
};
|
|
1882
|
-
class Constants {
|
|
1883
|
-
}
|
|
1884
|
-
/** Size of the font showing frames per second */
|
|
1885
|
-
__publicField$d(Constants, "FPS_DISPLAY_TEXT_FONT_SIZE", 12);
|
|
1886
|
-
/** Color of the font showing frames per second */
|
|
1887
|
-
__publicField$d(Constants, "FPS_DISPLAY_TEXT_COLOR", [0, 0, 0, 0.5]);
|
|
1888
|
-
/** Frequency, in milliseconds, at which to update frames per second metric shown on the screen */
|
|
1889
|
-
__publicField$d(Constants, "FPS_DISPLAY_UPDATE_INTERVAL", 1e3);
|
|
1890
|
-
/** Maximum number of activity metrics to log. */
|
|
1891
|
-
__publicField$d(Constants, "MAXIMUM_RECORDED_ACTIVITY_METRICS", 32);
|
|
1892
|
-
/** The frames per second will be logged in game metrics if the FPS is lower than this value */
|
|
1893
|
-
__publicField$d(Constants, "FPS_METRIC_REPORT_THRESHOLD", 59);
|
|
1894
|
-
/** Scene color, if none is specified. */
|
|
1895
|
-
__publicField$d(Constants, "DEFAULT_SCENE_BACKGROUND_COLOR", WebColors.White);
|
|
1896
|
-
/** Shape fill color, if none is specified. */
|
|
1897
|
-
__publicField$d(Constants, "DEFAULT_SHAPE_FILL_COLOR", WebColors.Red);
|
|
1898
|
-
/** Color of paths in a shape, if none is specified. */
|
|
1899
|
-
__publicField$d(Constants, "DEFAULT_PATH_STROKE_COLOR", WebColors.Red);
|
|
1900
|
-
/** Line width of paths in a shape, if none is specified. */
|
|
1901
|
-
__publicField$d(Constants, "DEFAULT_PATH_LINE_WIDTH", 2);
|
|
1902
|
-
/** Color of text in Label and TextLine, if none is specified. */
|
|
1903
|
-
__publicField$d(Constants, "DEFAULT_FONT_COLOR", WebColors.Black);
|
|
1904
|
-
/** Font size in Label and TextLine, if none is specified. */
|
|
1905
|
-
__publicField$d(Constants, "DEFAULT_FONT_SIZE", 16);
|
|
1906
|
-
__publicField$d(Constants, "LIMITED_FPS_RATE", 5);
|
|
1907
|
-
__publicField$d(Constants, "FREE_ENTITIES_SCENE_NAME", "__freeEntitiesScene");
|
|
1908
|
-
__publicField$d(Constants, "OUTGOING_SCENE_NAME", "__outgoingScene");
|
|
1909
|
-
__publicField$d(Constants, "OUTGOING_SCENE_SPRITE_NAME", "__outgoingSceneSprite");
|
|
1910
|
-
__publicField$d(Constants, "OUTGOING_SCENE_IMAGE_NAME", "__outgoingSceneSnapshot");
|
|
1911
|
-
__publicField$d(Constants, "SESSION_INITIALIZATION_POLLING_INTERVAL_MS", 50);
|
|
1912
|
-
|
|
1913
2358
|
var Dimensions = /* @__PURE__ */ ((Dimensions2) => {
|
|
1914
2359
|
Dimensions2[Dimensions2["MatchConstraint"] = 0] = "MatchConstraint";
|
|
1915
2360
|
return Dimensions2;
|
|
@@ -2154,22 +2599,12 @@ function property(e) {
|
|
|
2154
2599
|
return meta;
|
|
2155
2600
|
}
|
|
2156
2601
|
|
|
2157
|
-
var __defProp$c = Object.defineProperty;
|
|
2158
|
-
var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2159
|
-
var __publicField$c = (obj, key, value) => {
|
|
2160
|
-
__defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2161
|
-
return value;
|
|
2162
|
-
};
|
|
2163
2602
|
class GameTypefaces {
|
|
2164
2603
|
}
|
|
2165
2604
|
class FontManager {
|
|
2166
2605
|
constructor(session) {
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
__publicField$c(this, "gameTypefaces", new GameTypefaces());
|
|
2170
|
-
__publicField$c(this, "fontData", new Array());
|
|
2171
|
-
__publicField$c(this, "session");
|
|
2172
|
-
__publicField$c(this, "games");
|
|
2606
|
+
this.gameTypefaces = new GameTypefaces();
|
|
2607
|
+
this.fontData = new Array();
|
|
2173
2608
|
this.session = session;
|
|
2174
2609
|
}
|
|
2175
2610
|
/**
|
|
@@ -2203,20 +2638,17 @@ class FontManager {
|
|
|
2203
2638
|
fetchFonts(games) {
|
|
2204
2639
|
this.games = games;
|
|
2205
2640
|
const fontsToFetch = games.flatMap(
|
|
2206
|
-
(game) =>
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
})
|
|
2218
|
-
);
|
|
2219
|
-
}
|
|
2641
|
+
(game) => (
|
|
2642
|
+
// no fonts in game if game.options.fonts is undefined
|
|
2643
|
+
game.options.fonts?.map((font, i) => {
|
|
2644
|
+
return {
|
|
2645
|
+
gameUuid: game.uuid,
|
|
2646
|
+
fontUrl: font.url,
|
|
2647
|
+
fontName: font.fontName,
|
|
2648
|
+
isDefault: i === 0
|
|
2649
|
+
};
|
|
2650
|
+
})
|
|
2651
|
+
)
|
|
2220
2652
|
).filter((f) => f !== void 0);
|
|
2221
2653
|
if (fontsToFetch.length === 0) {
|
|
2222
2654
|
return Promise.all([Promise.resolve()]);
|
|
@@ -2249,23 +2681,21 @@ class FontManager {
|
|
|
2249
2681
|
* to our engine by creating canvaskit Typefaces.
|
|
2250
2682
|
*/
|
|
2251
2683
|
loadAllGamesFontData() {
|
|
2252
|
-
var _a;
|
|
2253
2684
|
if (this.fontData.length === 0) {
|
|
2254
2685
|
return;
|
|
2255
2686
|
}
|
|
2256
2687
|
if (!this.canvasKit) {
|
|
2257
2688
|
throw new Error("canvasKit undefined");
|
|
2258
2689
|
}
|
|
2259
|
-
this.fontMgr =
|
|
2690
|
+
this.fontMgr = this.canvasKit.FontMgr.FromData(
|
|
2260
2691
|
...this.fontData.map((f) => f.fontArrayBuffer)
|
|
2261
|
-
)
|
|
2692
|
+
) ?? void 0;
|
|
2262
2693
|
if (!this.fontMgr) {
|
|
2263
2694
|
throw new Error("error creating FontMgr while loading fonts");
|
|
2264
2695
|
}
|
|
2265
2696
|
this.fontData.forEach((font) => {
|
|
2266
|
-
var _a2, _b, _c;
|
|
2267
2697
|
const result = ttfInfo(new DataView(font.fontArrayBuffer));
|
|
2268
|
-
const fontFamilyUtf16Be =
|
|
2698
|
+
const fontFamilyUtf16Be = result.meta.property.filter((p) => p.name === "font-family").find(Boolean)?.text;
|
|
2269
2699
|
if (fontFamilyUtf16Be === void 0) {
|
|
2270
2700
|
throw new Error(
|
|
2271
2701
|
`error loading fonts. could not get font-family name from font at ${font.fontUrl}`
|
|
@@ -2285,7 +2715,7 @@ class FontManager {
|
|
|
2285
2715
|
if (!typeface) {
|
|
2286
2716
|
throw new Error("cannot make typeface from font array buffer");
|
|
2287
2717
|
}
|
|
2288
|
-
const gameId =
|
|
2718
|
+
const gameId = this.games?.find((g) => g.uuid === font.gameUuid)?.id;
|
|
2289
2719
|
console.log(
|
|
2290
2720
|
`\u26AA typeface ${font.fontName} ${font.isDefault ? "(default) " : ""}created from font-family ${fontFamily} for game ${gameId}`
|
|
2291
2721
|
);
|
|
@@ -2301,29 +2731,6 @@ class FontManager {
|
|
|
2301
2731
|
}
|
|
2302
2732
|
}
|
|
2303
2733
|
|
|
2304
|
-
var __defProp$b = Object.defineProperty;
|
|
2305
|
-
var __defProps$5 = Object.defineProperties;
|
|
2306
|
-
var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
|
|
2307
|
-
var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
|
|
2308
|
-
var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
|
|
2309
|
-
var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
|
|
2310
|
-
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2311
|
-
var __spreadValues$7 = (a, b) => {
|
|
2312
|
-
for (var prop in b || (b = {}))
|
|
2313
|
-
if (__hasOwnProp$7.call(b, prop))
|
|
2314
|
-
__defNormalProp$b(a, prop, b[prop]);
|
|
2315
|
-
if (__getOwnPropSymbols$7)
|
|
2316
|
-
for (var prop of __getOwnPropSymbols$7(b)) {
|
|
2317
|
-
if (__propIsEnum$7.call(b, prop))
|
|
2318
|
-
__defNormalProp$b(a, prop, b[prop]);
|
|
2319
|
-
}
|
|
2320
|
-
return a;
|
|
2321
|
-
};
|
|
2322
|
-
var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
2323
|
-
var __publicField$b = (obj, key, value) => {
|
|
2324
|
-
__defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2325
|
-
return value;
|
|
2326
|
-
};
|
|
2327
2734
|
class Sprite extends Entity {
|
|
2328
2735
|
/**
|
|
2329
2736
|
* Visual image displayed on the screen.
|
|
@@ -2334,17 +2741,15 @@ class Sprite extends Entity {
|
|
|
2334
2741
|
*/
|
|
2335
2742
|
constructor(options = {}) {
|
|
2336
2743
|
super(options);
|
|
2337
|
-
|
|
2338
|
-
|
|
2744
|
+
this.type = EntityType.Sprite;
|
|
2745
|
+
this.isDrawable = true;
|
|
2339
2746
|
// Drawable options
|
|
2340
|
-
|
|
2341
|
-
|
|
2747
|
+
this.anchorPoint = { x: 0.5, y: 0.5 };
|
|
2748
|
+
this.zPosition = 0;
|
|
2342
2749
|
// Sprite options
|
|
2343
|
-
|
|
2344
|
-
// public getter/setter is below
|
|
2345
|
-
__publicField$b(this, "loadedImage");
|
|
2750
|
+
this._imageName = "";
|
|
2346
2751
|
handleInterfaceOptions(this, options);
|
|
2347
|
-
if (options.imageName) {
|
|
2752
|
+
if (options.imageName !== void 0) {
|
|
2348
2753
|
this.imageName = options.imageName;
|
|
2349
2754
|
}
|
|
2350
2755
|
}
|
|
@@ -2363,11 +2768,13 @@ class Sprite extends Entity {
|
|
|
2363
2768
|
}
|
|
2364
2769
|
this.size.width = this.loadedImage.width;
|
|
2365
2770
|
this.size.height = this.loadedImage.height;
|
|
2771
|
+
if (!this._paint) {
|
|
2772
|
+
this.paint = new this.canvasKit.Paint();
|
|
2773
|
+
}
|
|
2366
2774
|
this.needsInitialization = false;
|
|
2367
2775
|
}
|
|
2368
2776
|
dispose() {
|
|
2369
|
-
|
|
2370
|
-
CanvasKitHelpers.Dispose([(_a = this.loadedImage) == null ? void 0 : _a.image]);
|
|
2777
|
+
CanvasKitHelpers.Dispose([this.loadedImage?.image, this._paint]);
|
|
2371
2778
|
}
|
|
2372
2779
|
set imageName(imageName) {
|
|
2373
2780
|
this._imageName = imageName;
|
|
@@ -2376,6 +2783,17 @@ class Sprite extends Entity {
|
|
|
2376
2783
|
get imageName() {
|
|
2377
2784
|
return this._imageName;
|
|
2378
2785
|
}
|
|
2786
|
+
set paint(paint) {
|
|
2787
|
+
this._paint = paint;
|
|
2788
|
+
}
|
|
2789
|
+
get paint() {
|
|
2790
|
+
if (!this._paint) {
|
|
2791
|
+
throw new Error(
|
|
2792
|
+
`in paint getter: Sprite entity ${this.toString()} paint is undefined.`
|
|
2793
|
+
);
|
|
2794
|
+
}
|
|
2795
|
+
return this._paint;
|
|
2796
|
+
}
|
|
2379
2797
|
/**
|
|
2380
2798
|
* Duplicates an entity using deep copy.
|
|
2381
2799
|
*
|
|
@@ -2387,10 +2805,12 @@ class Sprite extends Entity {
|
|
|
2387
2805
|
* provided, name will be the new uuid
|
|
2388
2806
|
*/
|
|
2389
2807
|
duplicate(newName) {
|
|
2390
|
-
const dest = new Sprite(
|
|
2808
|
+
const dest = new Sprite({
|
|
2809
|
+
...this.getEntityOptions(),
|
|
2810
|
+
...this.getDrawableOptions(),
|
|
2391
2811
|
imageName: this.imageName,
|
|
2392
2812
|
name: newName
|
|
2393
|
-
})
|
|
2813
|
+
});
|
|
2394
2814
|
if (this.children.length > 0) {
|
|
2395
2815
|
dest.children = this.children.map((child) => {
|
|
2396
2816
|
const clonedChild = child.duplicate();
|
|
@@ -2409,9 +2829,13 @@ class Sprite extends Entity {
|
|
|
2409
2829
|
canvas.save();
|
|
2410
2830
|
const drawScale = Globals.canvasScale / this.absoluteScale;
|
|
2411
2831
|
canvas.scale(1 / drawScale, 1 / drawScale);
|
|
2832
|
+
M2c2KitHelpers.rotateCanvasForDrawableEntity(canvas, this);
|
|
2412
2833
|
const x = (this.absolutePosition.x - this.size.width * this.anchorPoint.x * this.absoluteScale) * drawScale;
|
|
2413
2834
|
const y = (this.absolutePosition.y - this.size.height * this.anchorPoint.y * this.absoluteScale) * drawScale;
|
|
2414
|
-
|
|
2835
|
+
if (this.absoluteAlphaChange !== 0) {
|
|
2836
|
+
this.paint.setAlphaf(this.absoluteAlpha);
|
|
2837
|
+
}
|
|
2838
|
+
canvas.drawImage(this.loadedImage.image, x, y, this.paint);
|
|
2415
2839
|
canvas.restore();
|
|
2416
2840
|
}
|
|
2417
2841
|
super.drawChildren(canvas);
|
|
@@ -2442,29 +2866,6 @@ class LoadedImage {
|
|
|
2442
2866
|
}
|
|
2443
2867
|
}
|
|
2444
2868
|
|
|
2445
|
-
var __defProp$a = Object.defineProperty;
|
|
2446
|
-
var __defProps$4 = Object.defineProperties;
|
|
2447
|
-
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
|
|
2448
|
-
var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
|
|
2449
|
-
var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
|
|
2450
|
-
var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
|
|
2451
|
-
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2452
|
-
var __spreadValues$6 = (a, b) => {
|
|
2453
|
-
for (var prop in b || (b = {}))
|
|
2454
|
-
if (__hasOwnProp$6.call(b, prop))
|
|
2455
|
-
__defNormalProp$a(a, prop, b[prop]);
|
|
2456
|
-
if (__getOwnPropSymbols$6)
|
|
2457
|
-
for (var prop of __getOwnPropSymbols$6(b)) {
|
|
2458
|
-
if (__propIsEnum$6.call(b, prop))
|
|
2459
|
-
__defNormalProp$a(a, prop, b[prop]);
|
|
2460
|
-
}
|
|
2461
|
-
return a;
|
|
2462
|
-
};
|
|
2463
|
-
var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
2464
|
-
var __publicField$a = (obj, key, value) => {
|
|
2465
|
-
__defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2466
|
-
return value;
|
|
2467
|
-
};
|
|
2468
2869
|
class Scene extends Entity {
|
|
2469
2870
|
/**
|
|
2470
2871
|
* Top-level entity that holds all other entities, such as sprites, rectangles, or labels, that will be displayed on the screen
|
|
@@ -2475,18 +2876,15 @@ class Scene extends Entity {
|
|
|
2475
2876
|
*/
|
|
2476
2877
|
constructor(options = {}) {
|
|
2477
2878
|
super(options);
|
|
2478
|
-
|
|
2479
|
-
|
|
2879
|
+
this.type = EntityType.Scene;
|
|
2880
|
+
this.isDrawable = true;
|
|
2480
2881
|
// Drawable options
|
|
2481
|
-
|
|
2482
|
-
|
|
2882
|
+
this.anchorPoint = { x: 0, y: 0 };
|
|
2883
|
+
this.zPosition = 0;
|
|
2483
2884
|
// Scene options
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
__publicField$a(this, "_setupCallback");
|
|
2488
|
-
__publicField$a(this, "_appearCallback");
|
|
2489
|
-
__publicField$a(this, "backgroundPaint");
|
|
2885
|
+
this._backgroundColor = Constants.DEFAULT_SCENE_BACKGROUND_COLOR;
|
|
2886
|
+
this._active = false;
|
|
2887
|
+
this._transitioning = false;
|
|
2490
2888
|
handleInterfaceOptions(this, options);
|
|
2491
2889
|
if (options.backgroundColor) {
|
|
2492
2890
|
this.backgroundColor = options.backgroundColor;
|
|
@@ -2496,16 +2894,15 @@ class Scene extends Entity {
|
|
|
2496
2894
|
this.scale = Globals.rootScale;
|
|
2497
2895
|
this.size.width = this.game.canvasCssWidth;
|
|
2498
2896
|
this.size.height = this.game.canvasCssHeight;
|
|
2499
|
-
this.backgroundPaint
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2897
|
+
if (this.backgroundPaint) {
|
|
2898
|
+
this.backgroundPaint.delete();
|
|
2899
|
+
}
|
|
2900
|
+
this.backgroundPaint = CanvasKitHelpers.makePaint(
|
|
2901
|
+
this.canvasKit,
|
|
2902
|
+
this.backgroundColor,
|
|
2903
|
+
this.canvasKit.PaintStyle.Fill,
|
|
2904
|
+
false
|
|
2507
2905
|
);
|
|
2508
|
-
this.backgroundPaint.setStyle(this.canvasKit.PaintStyle.Fill);
|
|
2509
2906
|
this.needsInitialization = false;
|
|
2510
2907
|
}
|
|
2511
2908
|
dispose() {
|
|
@@ -2543,10 +2940,12 @@ class Scene extends Entity {
|
|
|
2543
2940
|
* provided, name will be the new uuid
|
|
2544
2941
|
*/
|
|
2545
2942
|
duplicate(newName) {
|
|
2546
|
-
const dest = new Scene(
|
|
2943
|
+
const dest = new Scene({
|
|
2944
|
+
...this.getEntityOptions(),
|
|
2945
|
+
...this.getDrawableOptions(),
|
|
2547
2946
|
backgroundColor: this.backgroundColor,
|
|
2548
2947
|
name: newName
|
|
2549
|
-
})
|
|
2948
|
+
});
|
|
2550
2949
|
dest.game = this.game;
|
|
2551
2950
|
if (this.children.length > 0) {
|
|
2552
2951
|
dest.children = this.children.map((child) => {
|
|
@@ -2582,13 +2981,20 @@ class Scene extends Entity {
|
|
|
2582
2981
|
onAppear(callback) {
|
|
2583
2982
|
this._appearCallback = callback;
|
|
2584
2983
|
}
|
|
2984
|
+
update() {
|
|
2985
|
+
super.update();
|
|
2986
|
+
}
|
|
2585
2987
|
draw(canvas) {
|
|
2586
2988
|
canvas.save();
|
|
2587
2989
|
const drawScale = Globals.canvasScale / this.absoluteScale;
|
|
2588
2990
|
canvas.scale(1 / drawScale, 1 / drawScale);
|
|
2991
|
+
M2c2KitHelpers.rotateCanvasForDrawableEntity(canvas, this);
|
|
2589
2992
|
if (!this.backgroundPaint) {
|
|
2590
2993
|
throw new Error(`in Scene ${this}, background paint is undefined.`);
|
|
2591
2994
|
}
|
|
2995
|
+
if (this.absoluteAlphaChange !== 0) {
|
|
2996
|
+
this.backgroundPaint.setAlphaf(this.absoluteAlpha);
|
|
2997
|
+
}
|
|
2592
2998
|
canvas.drawRect(
|
|
2593
2999
|
[
|
|
2594
3000
|
this.position.x * drawScale * Globals.rootScale,
|
|
@@ -2627,12 +3033,6 @@ class Scene extends Entity {
|
|
|
2627
3033
|
}
|
|
2628
3034
|
}
|
|
2629
3035
|
|
|
2630
|
-
var __defProp$9 = Object.defineProperty;
|
|
2631
|
-
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2632
|
-
var __publicField$9 = (obj, key, value) => {
|
|
2633
|
-
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2634
|
-
return value;
|
|
2635
|
-
};
|
|
2636
3036
|
class Transition {
|
|
2637
3037
|
/**
|
|
2638
3038
|
* Creates a scene transition in which the outgoing scene slides out and the incoming scene slides in, as if the incoming scene pushes it.
|
|
@@ -2641,11 +3041,10 @@ class Transition {
|
|
|
2641
3041
|
* @returns
|
|
2642
3042
|
*/
|
|
2643
3043
|
static slide(options) {
|
|
2644
|
-
var _a;
|
|
2645
3044
|
return new SlideTransition(
|
|
2646
3045
|
options.direction,
|
|
2647
3046
|
options.duration,
|
|
2648
|
-
|
|
3047
|
+
options.easing ?? Easings.linear
|
|
2649
3048
|
);
|
|
2650
3049
|
}
|
|
2651
3050
|
/**
|
|
@@ -2658,9 +3057,7 @@ class Transition {
|
|
|
2658
3057
|
class NoneTransition extends Transition {
|
|
2659
3058
|
constructor() {
|
|
2660
3059
|
super();
|
|
2661
|
-
|
|
2662
|
-
__publicField$9(this, "easing");
|
|
2663
|
-
__publicField$9(this, "duration");
|
|
3060
|
+
this.type = "None" /* None */;
|
|
2664
3061
|
this.duration = NaN;
|
|
2665
3062
|
this.easing = Easings.none;
|
|
2666
3063
|
}
|
|
@@ -2668,10 +3065,7 @@ class NoneTransition extends Transition {
|
|
|
2668
3065
|
class SlideTransition extends Transition {
|
|
2669
3066
|
constructor(direction, duration, easing) {
|
|
2670
3067
|
super();
|
|
2671
|
-
|
|
2672
|
-
__publicField$9(this, "easing");
|
|
2673
|
-
__publicField$9(this, "duration");
|
|
2674
|
-
__publicField$9(this, "direction");
|
|
3068
|
+
this.type = "Slide" /* Slide */;
|
|
2675
3069
|
this.direction = direction;
|
|
2676
3070
|
this.duration = duration;
|
|
2677
3071
|
this.easing = easing;
|
|
@@ -2696,25 +3090,18 @@ class SceneTransition {
|
|
|
2696
3090
|
}
|
|
2697
3091
|
}
|
|
2698
3092
|
|
|
2699
|
-
var __defProp$8 = Object.defineProperty;
|
|
2700
|
-
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2701
|
-
var __publicField$8 = (obj, key, value) => {
|
|
2702
|
-
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2703
|
-
return value;
|
|
2704
|
-
};
|
|
2705
3093
|
const _Timer = class _Timer {
|
|
2706
3094
|
constructor(name) {
|
|
2707
3095
|
// startTime is the timestamp of the current active run
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
3096
|
+
this.startTime = NaN;
|
|
3097
|
+
this.stopTime = NaN;
|
|
3098
|
+
this.stopped = true;
|
|
2711
3099
|
/**
|
|
2712
3100
|
* cumulativeElapsed is a cumulative total of elapsed time while the timer
|
|
2713
3101
|
* was in previous started (running) states, NOT INCLUDING the possibly
|
|
2714
3102
|
* active run's duration
|
|
2715
3103
|
*/
|
|
2716
|
-
|
|
2717
|
-
__publicField$8(this, "name");
|
|
3104
|
+
this.cumulativeElapsed = NaN;
|
|
2718
3105
|
this.name = name;
|
|
2719
3106
|
}
|
|
2720
3107
|
/**
|
|
@@ -2866,7 +3253,7 @@ const _Timer = class _Timer {
|
|
|
2866
3253
|
return this._timers.some((t) => t.name === name);
|
|
2867
3254
|
}
|
|
2868
3255
|
};
|
|
2869
|
-
|
|
3256
|
+
_Timer._timers = new Array();
|
|
2870
3257
|
let Timer = _Timer;
|
|
2871
3258
|
|
|
2872
3259
|
const deviceMetadataSchema = {
|
|
@@ -2976,39 +3363,16 @@ class WebGlInfo {
|
|
|
2976
3363
|
}
|
|
2977
3364
|
}
|
|
2978
3365
|
|
|
2979
|
-
var __defProp$7 = Object.defineProperty;
|
|
2980
|
-
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
|
|
2981
|
-
var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
|
|
2982
|
-
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
|
|
2983
|
-
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2984
|
-
var __spreadValues$5 = (a, b) => {
|
|
2985
|
-
for (var prop in b || (b = {}))
|
|
2986
|
-
if (__hasOwnProp$5.call(b, prop))
|
|
2987
|
-
__defNormalProp$7(a, prop, b[prop]);
|
|
2988
|
-
if (__getOwnPropSymbols$5)
|
|
2989
|
-
for (var prop of __getOwnPropSymbols$5(b)) {
|
|
2990
|
-
if (__propIsEnum$5.call(b, prop))
|
|
2991
|
-
__defNormalProp$7(a, prop, b[prop]);
|
|
2992
|
-
}
|
|
2993
|
-
return a;
|
|
2994
|
-
};
|
|
2995
|
-
var __publicField$7 = (obj, key, value) => {
|
|
2996
|
-
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2997
|
-
return value;
|
|
2998
|
-
};
|
|
2999
3366
|
class I18n {
|
|
3000
3367
|
constructor(options) {
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
__publicField$7(this, "environmentLocale", this.getEnvironmentLocale());
|
|
3005
|
-
__publicField$7(this, "options");
|
|
3006
|
-
var _a;
|
|
3368
|
+
this.locale = "";
|
|
3369
|
+
this.fallbackLocale = "en";
|
|
3370
|
+
this.environmentLocale = this.getEnvironmentLocale();
|
|
3007
3371
|
this.options = options;
|
|
3008
|
-
this._translations =
|
|
3372
|
+
this._translations = this.mergeAdditionalTranslations(
|
|
3009
3373
|
options.translations,
|
|
3010
3374
|
options.additionalTranslations
|
|
3011
|
-
)
|
|
3375
|
+
) ?? {};
|
|
3012
3376
|
if (options.locale.toLowerCase() === "auto") {
|
|
3013
3377
|
this.locale = this.environmentLocale;
|
|
3014
3378
|
if (!this.locale) {
|
|
@@ -3061,11 +3425,10 @@ class I18n {
|
|
|
3061
3425
|
return localizationParameters;
|
|
3062
3426
|
}
|
|
3063
3427
|
t(key, useFallback = false) {
|
|
3064
|
-
var _a, _b;
|
|
3065
3428
|
if (useFallback) {
|
|
3066
|
-
return
|
|
3429
|
+
return this._translations[this.fallbackLocale]?.[key];
|
|
3067
3430
|
}
|
|
3068
|
-
return
|
|
3431
|
+
return this._translations[this.locale]?.[key];
|
|
3069
3432
|
}
|
|
3070
3433
|
get translations() {
|
|
3071
3434
|
return this._translations;
|
|
@@ -3090,7 +3453,10 @@ class I18n {
|
|
|
3090
3453
|
const processedLocales = new Array();
|
|
3091
3454
|
for (const locale in baseTranslations) {
|
|
3092
3455
|
processedLocales.push(locale);
|
|
3093
|
-
result[locale] =
|
|
3456
|
+
result[locale] = {
|
|
3457
|
+
...baseTranslations[locale],
|
|
3458
|
+
...additionalTranslations[locale]
|
|
3459
|
+
};
|
|
3094
3460
|
}
|
|
3095
3461
|
for (const locale in additionalTranslations) {
|
|
3096
3462
|
if (processedLocales.includes(locale)) {
|
|
@@ -3212,49 +3578,6 @@ class DomHelpers {
|
|
|
3212
3578
|
}
|
|
3213
3579
|
}
|
|
3214
3580
|
|
|
3215
|
-
var ShapeType = /* @__PURE__ */ ((ShapeType2) => {
|
|
3216
|
-
ShapeType2["Undefined"] = "Undefined";
|
|
3217
|
-
ShapeType2["Rectangle"] = "Rectangle";
|
|
3218
|
-
ShapeType2["Circle"] = "Circle";
|
|
3219
|
-
ShapeType2["Path"] = "Path";
|
|
3220
|
-
return ShapeType2;
|
|
3221
|
-
})(ShapeType || {});
|
|
3222
|
-
|
|
3223
|
-
var __defProp$6 = Object.defineProperty;
|
|
3224
|
-
var __defProps$3 = Object.defineProperties;
|
|
3225
|
-
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
|
|
3226
|
-
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
3227
|
-
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
3228
|
-
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
3229
|
-
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3230
|
-
var __spreadValues$4 = (a, b) => {
|
|
3231
|
-
for (var prop in b || (b = {}))
|
|
3232
|
-
if (__hasOwnProp$4.call(b, prop))
|
|
3233
|
-
__defNormalProp$6(a, prop, b[prop]);
|
|
3234
|
-
if (__getOwnPropSymbols$4)
|
|
3235
|
-
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
3236
|
-
if (__propIsEnum$4.call(b, prop))
|
|
3237
|
-
__defNormalProp$6(a, prop, b[prop]);
|
|
3238
|
-
}
|
|
3239
|
-
return a;
|
|
3240
|
-
};
|
|
3241
|
-
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
3242
|
-
var __objRest = (source, exclude) => {
|
|
3243
|
-
var target = {};
|
|
3244
|
-
for (var prop in source)
|
|
3245
|
-
if (__hasOwnProp$4.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
3246
|
-
target[prop] = source[prop];
|
|
3247
|
-
if (source != null && __getOwnPropSymbols$4)
|
|
3248
|
-
for (var prop of __getOwnPropSymbols$4(source)) {
|
|
3249
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$4.call(source, prop))
|
|
3250
|
-
target[prop] = source[prop];
|
|
3251
|
-
}
|
|
3252
|
-
return target;
|
|
3253
|
-
};
|
|
3254
|
-
var __publicField$6 = (obj, key, value) => {
|
|
3255
|
-
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3256
|
-
return value;
|
|
3257
|
-
};
|
|
3258
3581
|
class Game {
|
|
3259
3582
|
/**
|
|
3260
3583
|
* The base class for all games. New games should extend this class.
|
|
@@ -3262,66 +3585,44 @@ class Game {
|
|
|
3262
3585
|
* @param options - {@link GameOptions}
|
|
3263
3586
|
*/
|
|
3264
3587
|
constructor(options) {
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
__publicField$6(this, "maximumRecordedActivityMetrics");
|
|
3278
|
-
__publicField$6(this, "stepCount", 0);
|
|
3279
|
-
__publicField$6(this, "steppingNow", 0);
|
|
3280
|
-
__publicField$6(this, "i18n");
|
|
3281
|
-
__publicField$6(this, "warmupFunctionQueue", new Array());
|
|
3282
|
-
__publicField$6(this, "loaderElementsRemoved", false);
|
|
3283
|
-
__publicField$6(this, "_dataStores");
|
|
3284
|
-
__publicField$6(this, "additionalParameters");
|
|
3285
|
-
__publicField$6(this, "staticTrialSchema", {});
|
|
3286
|
-
/** The scene, or its name as a string, to be presented when the game is started. If this is undefined, the game will start with the first scene that has been added */
|
|
3287
|
-
__publicField$6(this, "entryScene");
|
|
3288
|
-
__publicField$6(this, "data", {
|
|
3588
|
+
this.type = ActivityType.Game;
|
|
3589
|
+
this.uuid = Uuid.generate();
|
|
3590
|
+
this.beginTimestamp = NaN;
|
|
3591
|
+
this.beginIso8601Timestamp = "";
|
|
3592
|
+
this.eventListeners = new Array();
|
|
3593
|
+
this.gameMetrics = new Array();
|
|
3594
|
+
this.stepCount = 0;
|
|
3595
|
+
this.steppingNow = 0;
|
|
3596
|
+
this.warmupFunctionQueue = new Array();
|
|
3597
|
+
this.loaderElementsRemoved = false;
|
|
3598
|
+
this.staticTrialSchema = {};
|
|
3599
|
+
this.data = {
|
|
3289
3600
|
trials: new Array()
|
|
3290
|
-
}
|
|
3601
|
+
};
|
|
3291
3602
|
/** The 0-based index of the current trial */
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
__publicField$6(this, "limitFps", false);
|
|
3307
|
-
__publicField$6(this, "unitTesting", false);
|
|
3308
|
-
__publicField$6(this, "gameStopRequested", false);
|
|
3309
|
-
__publicField$6(this, "webGlRendererInfo", "");
|
|
3310
|
-
__publicField$6(this, "canvasCssWidth", 0);
|
|
3311
|
-
__publicField$6(this, "canvasCssHeight", 0);
|
|
3312
|
-
__publicField$6(this, "scenes", new Array());
|
|
3313
|
-
__publicField$6(this, "freeEntitiesScene", new Scene({
|
|
3603
|
+
this.trialIndex = 0;
|
|
3604
|
+
this.drawnFrames = 0;
|
|
3605
|
+
this.lastFpsUpdate = 0;
|
|
3606
|
+
this.nextFpsUpdate = 0;
|
|
3607
|
+
this.fpsRate = 0;
|
|
3608
|
+
this.animationFramesRequested = 0;
|
|
3609
|
+
this.limitFps = false;
|
|
3610
|
+
this.unitTesting = false;
|
|
3611
|
+
this.gameStopRequested = false;
|
|
3612
|
+
this.webGlRendererInfo = "";
|
|
3613
|
+
this.canvasCssWidth = 0;
|
|
3614
|
+
this.canvasCssHeight = 0;
|
|
3615
|
+
this.scenes = new Array();
|
|
3616
|
+
this.freeEntitiesScene = new Scene({
|
|
3314
3617
|
name: Constants.FREE_ENTITIES_SCENE_NAME,
|
|
3315
3618
|
backgroundColor: [255, 255, 255, 0]
|
|
3316
|
-
})
|
|
3317
|
-
|
|
3318
|
-
__publicField$6(this, "currentSceneSnapshot");
|
|
3319
|
-
__publicField$6(this, "pendingScreenshot");
|
|
3619
|
+
});
|
|
3620
|
+
this.incomingSceneTransitions = new Array();
|
|
3320
3621
|
/**
|
|
3321
3622
|
* The m2c2kit engine will automatically include these schema and their
|
|
3322
3623
|
* values in the trial data.
|
|
3323
3624
|
*/
|
|
3324
|
-
|
|
3625
|
+
this.automaticTrialSchema = {
|
|
3325
3626
|
document_uuid: {
|
|
3326
3627
|
type: "string",
|
|
3327
3628
|
format: "uuid",
|
|
@@ -3353,9 +3654,8 @@ class Game {
|
|
|
3353
3654
|
type: "integer",
|
|
3354
3655
|
description: "Difference in minutes between UTC and device timezone. Calculated from Date.getTimezoneOffset()."
|
|
3355
3656
|
}
|
|
3356
|
-
}
|
|
3357
|
-
|
|
3358
|
-
var _a, _b;
|
|
3657
|
+
};
|
|
3658
|
+
this.snapshots = new Array();
|
|
3359
3659
|
if (!options.id || options.id.trim() === "") {
|
|
3360
3660
|
throw new Error("id is required in GameOptions");
|
|
3361
3661
|
}
|
|
@@ -3364,31 +3664,33 @@ class Game {
|
|
|
3364
3664
|
this.id = options.id;
|
|
3365
3665
|
this.freeEntitiesScene.game = this;
|
|
3366
3666
|
this.freeEntitiesScene.needsInitialization = true;
|
|
3367
|
-
this.fpsMetricReportThreshold =
|
|
3368
|
-
this.maximumRecordedActivityMetrics =
|
|
3667
|
+
this.fpsMetricReportThreshold = options.fpsMetricReportThreshold ?? Constants.FPS_METRIC_REPORT_THRESHOLD;
|
|
3668
|
+
this.maximumRecordedActivityMetrics = options.maximumRecordedActivityMetrics ?? Constants.MAXIMUM_RECORDED_ACTIVITY_METRICS;
|
|
3369
3669
|
this.addLocalizationParametersToGameParameters();
|
|
3370
3670
|
if (!this.options.trialSchema) {
|
|
3371
3671
|
this.options.trialSchema = {};
|
|
3372
3672
|
}
|
|
3373
3673
|
}
|
|
3374
3674
|
addLocalizationParametersToGameParameters() {
|
|
3375
|
-
this.options.parameters =
|
|
3675
|
+
this.options.parameters = {
|
|
3676
|
+
...this.options.parameters,
|
|
3677
|
+
...I18n.makeLocalizationParameters()
|
|
3678
|
+
};
|
|
3376
3679
|
}
|
|
3377
3680
|
async init() {
|
|
3378
3681
|
return this.initialize();
|
|
3379
3682
|
}
|
|
3380
3683
|
async initialize() {
|
|
3381
|
-
var _a, _b;
|
|
3382
3684
|
if (this.isLocalizationRequested()) {
|
|
3383
3685
|
const options = this.getLocalizationOptionsFromGameParameters();
|
|
3384
3686
|
this.i18n = new I18n(options);
|
|
3385
3687
|
}
|
|
3386
|
-
if (
|
|
3688
|
+
if (this.session.options.activityCallbacks?.onActivityLifecycle) {
|
|
3387
3689
|
this.onStart(this.session.options.activityCallbacks.onActivityLifecycle);
|
|
3388
3690
|
this.onCancel(this.session.options.activityCallbacks.onActivityLifecycle);
|
|
3389
3691
|
this.onEnd(this.session.options.activityCallbacks.onActivityLifecycle);
|
|
3390
3692
|
}
|
|
3391
|
-
if (
|
|
3693
|
+
if (this.session.options.activityCallbacks?.onActivityResults) {
|
|
3392
3694
|
this.onData(this.session.options.activityCallbacks.onActivityResults);
|
|
3393
3695
|
}
|
|
3394
3696
|
}
|
|
@@ -3777,16 +4079,15 @@ class Game {
|
|
|
3777
4079
|
* @param entryScene - The scene (Scene object or its string name) to display when the game starts
|
|
3778
4080
|
*/
|
|
3779
4081
|
async start(entryScene) {
|
|
3780
|
-
var _a, _b;
|
|
3781
4082
|
const gameInitOptions = this.options;
|
|
3782
|
-
this.unitTesting =
|
|
4083
|
+
this.unitTesting = gameInitOptions._unitTesting ?? false;
|
|
3783
4084
|
this.setupHtmlCanvases(
|
|
3784
4085
|
gameInitOptions.canvasId,
|
|
3785
4086
|
gameInitOptions.width,
|
|
3786
4087
|
gameInitOptions.height,
|
|
3787
4088
|
gameInitOptions.stretch
|
|
3788
4089
|
);
|
|
3789
|
-
this.showFps =
|
|
4090
|
+
this.showFps = gameInitOptions.showFps ?? false;
|
|
3790
4091
|
this.bodyBackgroundColor = gameInitOptions.bodyBackgroundColor;
|
|
3791
4092
|
this.initData();
|
|
3792
4093
|
this.setupCanvasKitSurface();
|
|
@@ -3898,11 +4199,10 @@ class Game {
|
|
|
3898
4199
|
}
|
|
3899
4200
|
}
|
|
3900
4201
|
advanceStepsHandler(mouseEvent) {
|
|
3901
|
-
|
|
3902
|
-
if (((_a = mouseEvent == null ? void 0 : mouseEvent.target) == null ? void 0 : _a.id) === "1-step-advance") {
|
|
4202
|
+
if (mouseEvent?.target?.id === "1-step-advance") {
|
|
3903
4203
|
this.steppingNow = this.steppingNow + 16.66666666666667;
|
|
3904
4204
|
this.stepCount = this.stepCount + 1;
|
|
3905
|
-
} else if (
|
|
4205
|
+
} else if (mouseEvent?.target?.id === "55-step-advance") {
|
|
3906
4206
|
this.steppingNow = this.steppingNow + 16.66666666666667 * 55;
|
|
3907
4207
|
this.stepCount = this.stepCount + 55;
|
|
3908
4208
|
}
|
|
@@ -4072,12 +4372,11 @@ class Game {
|
|
|
4072
4372
|
this.entities.filter((e) => e.isDrawable).forEach((e) => e.dispose());
|
|
4073
4373
|
}
|
|
4074
4374
|
initData() {
|
|
4075
|
-
var _a;
|
|
4076
4375
|
this.trialIndex = 0;
|
|
4077
4376
|
this.data = {
|
|
4078
4377
|
trials: new Array()
|
|
4079
4378
|
};
|
|
4080
|
-
const trialSchema =
|
|
4379
|
+
const trialSchema = this.options.trialSchema ?? {};
|
|
4081
4380
|
const variables = Object.entries(trialSchema);
|
|
4082
4381
|
for (const [variableName, propertySchema] of variables) {
|
|
4083
4382
|
if (propertySchema.type !== void 0 && !this.propertySchemaDataTypeIsValid(propertySchema.type)) {
|
|
@@ -4159,7 +4458,6 @@ class Game {
|
|
|
4159
4458
|
* @param value - value of the variable to set
|
|
4160
4459
|
*/
|
|
4161
4460
|
addTrialData(variableName, value) {
|
|
4162
|
-
var _a, _b, _c;
|
|
4163
4461
|
if (!this.options.trialSchema) {
|
|
4164
4462
|
throw new Error(
|
|
4165
4463
|
"no trial schema were provided in GameOptions. cannot add trial data"
|
|
@@ -4171,17 +4469,17 @@ class Game {
|
|
|
4171
4469
|
for (const [variableName2] of variables) {
|
|
4172
4470
|
emptyTrial[variableName2] = null;
|
|
4173
4471
|
}
|
|
4174
|
-
this.data.trials.push(
|
|
4472
|
+
this.data.trials.push({
|
|
4175
4473
|
document_uuid: Uuid.generate(),
|
|
4176
4474
|
session_uuid: this.session.uuid,
|
|
4177
4475
|
activity_uuid: this.uuid,
|
|
4178
4476
|
activity_id: this.options.id,
|
|
4179
4477
|
activity_version: this.options.version,
|
|
4180
|
-
device_timezone:
|
|
4181
|
-
device_timezone_offset_minutes: (/* @__PURE__ */ new Date()).getTimezoneOffset()
|
|
4182
|
-
|
|
4478
|
+
device_timezone: Intl?.DateTimeFormat()?.resolvedOptions()?.timeZone ?? "",
|
|
4479
|
+
device_timezone_offset_minutes: (/* @__PURE__ */ new Date()).getTimezoneOffset(),
|
|
4480
|
+
...emptyTrial,
|
|
4183
4481
|
device_metadata: this.getDeviceMetadata()
|
|
4184
|
-
})
|
|
4482
|
+
});
|
|
4185
4483
|
}
|
|
4186
4484
|
if (!(variableName in this.options.trialSchema)) {
|
|
4187
4485
|
throw new Error(`trial variable ${variableName} not defined in schema`);
|
|
@@ -4240,12 +4538,12 @@ class Game {
|
|
|
4240
4538
|
* Rather than modify the source code for the game, you can do the following
|
|
4241
4539
|
* to ensure that the participant ID is saved for each trial:
|
|
4242
4540
|
*
|
|
4243
|
-
* game.addTrialSchema(
|
|
4244
|
-
* participant_id:
|
|
4541
|
+
* game.addTrialSchema({
|
|
4542
|
+
* participant_id: {
|
|
4245
4543
|
* type: "string",
|
|
4246
4544
|
* description: "ID of the participant",
|
|
4247
|
-
*
|
|
4248
|
-
*
|
|
4545
|
+
* }
|
|
4546
|
+
* });
|
|
4249
4547
|
* game.addStaticTrialData("participant_id", "12345");
|
|
4250
4548
|
*
|
|
4251
4549
|
* When Game.trialComplete() is called, the participant_id variable will
|
|
@@ -4274,9 +4572,11 @@ class Game {
|
|
|
4274
4572
|
* the appropriate time. It is not triggered automatically.
|
|
4275
4573
|
*/
|
|
4276
4574
|
trialComplete() {
|
|
4277
|
-
var _a, _b;
|
|
4278
4575
|
if (Object.keys(this.staticTrialSchema).length > 0) {
|
|
4279
|
-
this.data.trials[this.trialIndex] =
|
|
4576
|
+
this.data.trials[this.trialIndex] = {
|
|
4577
|
+
...this.data.trials[this.trialIndex],
|
|
4578
|
+
...this.staticTrialSchema
|
|
4579
|
+
};
|
|
4280
4580
|
}
|
|
4281
4581
|
this.trialIndex++;
|
|
4282
4582
|
const resultsEvent = {
|
|
@@ -4290,10 +4590,10 @@ class Game {
|
|
|
4290
4590
|
data: this.data,
|
|
4291
4591
|
dataSchema: this.makeGameDataSchema(),
|
|
4292
4592
|
activityConfiguration: this.makeGameActivityConfiguration(
|
|
4293
|
-
|
|
4593
|
+
this.options.parameters ?? {}
|
|
4294
4594
|
),
|
|
4295
4595
|
activityConfigurationSchema: this.makeGameActivityConfigurationSchema(
|
|
4296
|
-
|
|
4596
|
+
this.options.parameters ?? {}
|
|
4297
4597
|
),
|
|
4298
4598
|
activityMetrics: this.gameMetrics
|
|
4299
4599
|
};
|
|
@@ -4305,9 +4605,11 @@ class Game {
|
|
|
4305
4605
|
$comment: `Activity identifier: ${this.options.id}, version: ${this.options.version}.`,
|
|
4306
4606
|
$schema: "https://json-schema.org/draft/2019-09/schema",
|
|
4307
4607
|
type: "object",
|
|
4308
|
-
properties:
|
|
4608
|
+
properties: {
|
|
4609
|
+
...this.automaticTrialSchema,
|
|
4610
|
+
...this.options.trialSchema,
|
|
4309
4611
|
device_metadata: deviceMetadataSchema
|
|
4310
|
-
}
|
|
4612
|
+
}
|
|
4311
4613
|
};
|
|
4312
4614
|
return newDataSchema;
|
|
4313
4615
|
}
|
|
@@ -4328,9 +4630,11 @@ class Game {
|
|
|
4328
4630
|
$defs: {
|
|
4329
4631
|
trial: {
|
|
4330
4632
|
type: "object",
|
|
4331
|
-
properties:
|
|
4633
|
+
properties: {
|
|
4634
|
+
...this.automaticTrialSchema,
|
|
4635
|
+
...this.options.trialSchema,
|
|
4332
4636
|
device_metadata: deviceMetadataSchema
|
|
4333
|
-
}
|
|
4637
|
+
}
|
|
4334
4638
|
}
|
|
4335
4639
|
}
|
|
4336
4640
|
};
|
|
@@ -4345,15 +4649,17 @@ class Game {
|
|
|
4345
4649
|
*/
|
|
4346
4650
|
makeGameActivityConfiguration(parameters) {
|
|
4347
4651
|
const gameParams = JSON.parse(JSON.stringify(parameters));
|
|
4348
|
-
const
|
|
4349
|
-
|
|
4652
|
+
const {
|
|
4653
|
+
locale,
|
|
4350
4654
|
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
4351
|
-
|
|
4655
|
+
fallback_locale,
|
|
4352
4656
|
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
4353
|
-
|
|
4657
|
+
missing_translation_font_color,
|
|
4354
4658
|
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
4355
|
-
|
|
4356
|
-
|
|
4659
|
+
translations,
|
|
4660
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
4661
|
+
...result
|
|
4662
|
+
} = gameParams;
|
|
4357
4663
|
for (const prop in result) {
|
|
4358
4664
|
for (const subProp in result[prop]) {
|
|
4359
4665
|
if (subProp == "default") {
|
|
@@ -4365,15 +4671,17 @@ class Game {
|
|
|
4365
4671
|
}
|
|
4366
4672
|
makeGameActivityConfigurationSchema(parameters) {
|
|
4367
4673
|
const gameParams = JSON.parse(JSON.stringify(parameters));
|
|
4368
|
-
const
|
|
4369
|
-
|
|
4674
|
+
const {
|
|
4675
|
+
locale,
|
|
4370
4676
|
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
4371
|
-
|
|
4677
|
+
fallback_locale,
|
|
4372
4678
|
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
4373
|
-
|
|
4679
|
+
missing_translation_font_color,
|
|
4374
4680
|
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
4375
|
-
|
|
4376
|
-
|
|
4681
|
+
translations,
|
|
4682
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
4683
|
+
...result
|
|
4684
|
+
} = gameParams;
|
|
4377
4685
|
for (const prop in result) {
|
|
4378
4686
|
if (!("type" in result[prop]) && "value" in result[prop]) {
|
|
4379
4687
|
const valueType = typeof result[prop]["default"];
|
|
@@ -4404,7 +4712,6 @@ class Game {
|
|
|
4404
4712
|
* appropriate time. It is not triggered automatically.
|
|
4405
4713
|
*/
|
|
4406
4714
|
end() {
|
|
4407
|
-
var _a, _b;
|
|
4408
4715
|
const activityEndEvent = {
|
|
4409
4716
|
target: this,
|
|
4410
4717
|
type: EventType.ActivityEnd
|
|
@@ -4413,10 +4720,10 @@ class Game {
|
|
|
4413
4720
|
data: this.data,
|
|
4414
4721
|
dataSchema: this.makeGameDataSchema(),
|
|
4415
4722
|
activityConfiguration: this.makeGameActivityConfiguration(
|
|
4416
|
-
|
|
4723
|
+
this.options.parameters ?? {}
|
|
4417
4724
|
),
|
|
4418
4725
|
activityConfigurationSchema: this.makeGameActivityConfigurationSchema(
|
|
4419
|
-
|
|
4726
|
+
this.options.parameters ?? {}
|
|
4420
4727
|
),
|
|
4421
4728
|
activityMetrics: this.gameMetrics
|
|
4422
4729
|
};
|
|
@@ -4433,7 +4740,6 @@ class Game {
|
|
|
4433
4740
|
* appropriate time. It is not triggered automatically.
|
|
4434
4741
|
*/
|
|
4435
4742
|
cancel() {
|
|
4436
|
-
var _a, _b;
|
|
4437
4743
|
const activityCancelEvent = {
|
|
4438
4744
|
target: this,
|
|
4439
4745
|
type: EventType.ActivityCancel
|
|
@@ -4442,10 +4748,10 @@ class Game {
|
|
|
4442
4748
|
data: this.data,
|
|
4443
4749
|
dataSchema: this.makeGameDataSchema(),
|
|
4444
4750
|
activityConfiguration: this.makeGameActivityConfiguration(
|
|
4445
|
-
|
|
4751
|
+
this.options.parameters ?? {}
|
|
4446
4752
|
),
|
|
4447
4753
|
activityConfigurationSchema: this.makeGameActivityConfigurationSchema(
|
|
4448
|
-
|
|
4754
|
+
this.options.parameters ?? {}
|
|
4449
4755
|
),
|
|
4450
4756
|
activityMetrics: this.gameMetrics
|
|
4451
4757
|
};
|
|
@@ -4517,7 +4823,7 @@ class Game {
|
|
|
4517
4823
|
this.interceptWebGlCalls();
|
|
4518
4824
|
try {
|
|
4519
4825
|
this.webGlRendererInfo = WebGlInfo.getRendererString();
|
|
4520
|
-
} catch
|
|
4826
|
+
} catch {
|
|
4521
4827
|
this.webGlRendererInfo = "err";
|
|
4522
4828
|
WebGlInfo.dispose();
|
|
4523
4829
|
}
|
|
@@ -4604,13 +4910,12 @@ class Game {
|
|
|
4604
4910
|
);
|
|
4605
4911
|
}
|
|
4606
4912
|
loop(canvas) {
|
|
4607
|
-
var _a;
|
|
4608
4913
|
if (!this.surface) {
|
|
4609
4914
|
throw new Error("surface is undefined");
|
|
4610
4915
|
}
|
|
4611
4916
|
if (this.warmupFunctionQueue.length > 0) {
|
|
4612
4917
|
const warmup = this.warmupFunctionQueue.shift();
|
|
4613
|
-
warmup
|
|
4918
|
+
warmup?.warmupFunction.call(this, canvas, warmup.positionOffset);
|
|
4614
4919
|
this.surface.requestAnimationFrame(this.loop.bind(this));
|
|
4615
4920
|
return;
|
|
4616
4921
|
}
|
|
@@ -4635,7 +4940,7 @@ class Game {
|
|
|
4635
4940
|
this.update();
|
|
4636
4941
|
this.draw(canvas);
|
|
4637
4942
|
while (this.snapshots.length > 0) {
|
|
4638
|
-
|
|
4943
|
+
this.snapshots.shift()?.delete();
|
|
4639
4944
|
}
|
|
4640
4945
|
this.snapshots.push(this.takeCurrentSceneSnapshot());
|
|
4641
4946
|
this.freeEntitiesScene.draw(canvas);
|
|
@@ -5445,7 +5750,7 @@ class Game {
|
|
|
5445
5750
|
}
|
|
5446
5751
|
const x = domPointerEvent.offsetX;
|
|
5447
5752
|
const y = domPointerEvent.offsetY;
|
|
5448
|
-
const bb =
|
|
5753
|
+
const bb = M2c2KitHelpers.calculateEntityAbsoluteBoundingBox(entity);
|
|
5449
5754
|
const relativeX = (x - bb.xMin) / (bb.xMax - bb.xMin) * width;
|
|
5450
5755
|
const relativeY = (y - bb.yMin) / (bb.yMax - bb.yMin) * height;
|
|
5451
5756
|
return { x: relativeX, y: relativeY };
|
|
@@ -5496,7 +5801,7 @@ class Game {
|
|
|
5496
5801
|
activityUuid: this.uuid,
|
|
5497
5802
|
callback
|
|
5498
5803
|
};
|
|
5499
|
-
if (options
|
|
5804
|
+
if (options?.replaceExisting) {
|
|
5500
5805
|
this.eventListeners = this.eventListeners.filter(
|
|
5501
5806
|
(listener) => !(listener.activityUuid === eventListener.activityUuid && listener.type === eventListener.type)
|
|
5502
5807
|
);
|
|
@@ -5505,7 +5810,11 @@ class Game {
|
|
|
5505
5810
|
}
|
|
5506
5811
|
raiseActivityEventOnListeners(activityEvent, extra) {
|
|
5507
5812
|
if (extra) {
|
|
5508
|
-
activityEvent =
|
|
5813
|
+
activityEvent = {
|
|
5814
|
+
...activityEvent,
|
|
5815
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5816
|
+
...extra
|
|
5817
|
+
};
|
|
5509
5818
|
}
|
|
5510
5819
|
this.eventListeners.filter((listener) => listener.type === activityEvent.type).forEach((listener) => {
|
|
5511
5820
|
listener.callback(activityEvent);
|
|
@@ -5553,8 +5862,7 @@ class Game {
|
|
|
5553
5862
|
});
|
|
5554
5863
|
}
|
|
5555
5864
|
sceneCanReceiveUserInteraction(scene) {
|
|
5556
|
-
|
|
5557
|
-
if (scene.game === ((_a = scene.game.session) == null ? void 0 : _a.currentActivity) && scene._transitioning === false) {
|
|
5865
|
+
if (scene.game === scene.game.session?.currentActivity && scene._transitioning === false) {
|
|
5558
5866
|
return true;
|
|
5559
5867
|
}
|
|
5560
5868
|
return false;
|
|
@@ -5573,14 +5881,14 @@ class Game {
|
|
|
5573
5881
|
throw "only drawable entities can receive pointer events";
|
|
5574
5882
|
}
|
|
5575
5883
|
if (entity.type === EntityType.Shape && entity.shapeType === ShapeType.Circle) {
|
|
5576
|
-
const
|
|
5884
|
+
const bb = M2c2KitHelpers.calculateEntityAbsoluteBoundingBox(entity);
|
|
5577
5885
|
const radius = entity.circleOfRadius;
|
|
5578
5886
|
if (!radius) {
|
|
5579
5887
|
throw "circleOfRadius is undefined";
|
|
5580
5888
|
}
|
|
5581
5889
|
const center = {
|
|
5582
|
-
x:
|
|
5583
|
-
y:
|
|
5890
|
+
x: bb.xMin + radius * entity.absoluteScale,
|
|
5891
|
+
y: bb.yMin + radius * entity.absoluteScale
|
|
5584
5892
|
};
|
|
5585
5893
|
const distance = Math.sqrt(
|
|
5586
5894
|
Math.pow(x - center.x, 2) + Math.pow(y - center.y, 2)
|
|
@@ -5593,30 +5901,10 @@ class Game {
|
|
|
5593
5901
|
if (entity.type === EntityType.TextLine && isNaN(entity.size.width)) {
|
|
5594
5902
|
return false;
|
|
5595
5903
|
}
|
|
5596
|
-
const
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
}
|
|
5600
|
-
return false;
|
|
5601
|
-
}
|
|
5602
|
-
calculateEntityAbsoluteBoundingBox(entity) {
|
|
5603
|
-
const anchorPoint = entity.anchorPoint;
|
|
5604
|
-
const scale = entity.absoluteScale;
|
|
5605
|
-
let width = entity.size.width;
|
|
5606
|
-
let height = entity.size.height;
|
|
5607
|
-
if (entity.type === EntityType.Shape && entity.shapeType === ShapeType.Circle) {
|
|
5608
|
-
const radius = entity.circleOfRadius;
|
|
5609
|
-
if (!radius) {
|
|
5610
|
-
throw "circleOfRadius is undefined";
|
|
5611
|
-
}
|
|
5612
|
-
width = radius * 2;
|
|
5613
|
-
height = radius * 2;
|
|
5614
|
-
}
|
|
5615
|
-
const xMin = entity.absolutePosition.x - width * anchorPoint.x * scale;
|
|
5616
|
-
const xMax = entity.absolutePosition.x + width * (1 - anchorPoint.x) * scale;
|
|
5617
|
-
const yMin = entity.absolutePosition.y - height * anchorPoint.y * scale;
|
|
5618
|
-
const yMax = entity.absolutePosition.y + height * (1 - anchorPoint.y) * scale;
|
|
5619
|
-
return { xMin, xMax, yMin, yMax };
|
|
5904
|
+
const points = M2c2KitHelpers.calculateRotatedPoints(
|
|
5905
|
+
entity
|
|
5906
|
+
);
|
|
5907
|
+
return entity.isUserInteractionEnabled && M2c2KitHelpers.isPointInsideRectangle({ x, y }, points);
|
|
5620
5908
|
}
|
|
5621
5909
|
prependAssetsGameIdUrl(url) {
|
|
5622
5910
|
function hasUrlScheme(str) {
|
|
@@ -5641,25 +5929,14 @@ class RenderedDataUrlImage {
|
|
|
5641
5929
|
}
|
|
5642
5930
|
}
|
|
5643
5931
|
|
|
5644
|
-
var __defProp$5 = Object.defineProperty;
|
|
5645
|
-
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5646
|
-
var __publicField$5 = (obj, key, value) => {
|
|
5647
|
-
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5648
|
-
return value;
|
|
5649
|
-
};
|
|
5650
5932
|
class RenderedImages {
|
|
5651
5933
|
}
|
|
5652
5934
|
class LoadedImages {
|
|
5653
5935
|
}
|
|
5654
5936
|
class ImageManager {
|
|
5655
5937
|
constructor(session) {
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
__publicField$5(this, "loadedImages", new LoadedImages());
|
|
5659
|
-
__publicField$5(this, "_scratchCanvas");
|
|
5660
|
-
__publicField$5(this, "ctx");
|
|
5661
|
-
__publicField$5(this, "scale");
|
|
5662
|
-
__publicField$5(this, "session");
|
|
5938
|
+
this.renderedImages = new RenderedImages();
|
|
5939
|
+
this.loadedImages = new LoadedImages();
|
|
5663
5940
|
this.session = session;
|
|
5664
5941
|
}
|
|
5665
5942
|
/**
|
|
@@ -5933,10 +6210,9 @@ class ImageManager {
|
|
|
5933
6210
|
return window.btoa(binary);
|
|
5934
6211
|
}
|
|
5935
6212
|
inferImageSubtypeFromUrl(url) {
|
|
5936
|
-
var _a, _b;
|
|
5937
6213
|
let subtype = "jpeg";
|
|
5938
|
-
if (url
|
|
5939
|
-
subtype =
|
|
6214
|
+
if (url?.includes(".")) {
|
|
6215
|
+
subtype = url.split(".").pop()?.toLowerCase() ?? "jpeg";
|
|
5940
6216
|
if (subtype === "") {
|
|
5941
6217
|
subtype = "jpeg";
|
|
5942
6218
|
}
|
|
@@ -5955,7 +6231,7 @@ class ImageManager {
|
|
|
5955
6231
|
img = this.canvasKit.MakeImageFromEncoded(
|
|
5956
6232
|
this.dataURLtoArrayBuffer(loadedDataUrlImage.dataUrlImage)
|
|
5957
6233
|
);
|
|
5958
|
-
} catch
|
|
6234
|
+
} catch {
|
|
5959
6235
|
throw new Error(
|
|
5960
6236
|
`could not create image with name "${loadedDataUrlImage.name}."`
|
|
5961
6237
|
);
|
|
@@ -6007,9 +6283,8 @@ class ImageManager {
|
|
|
6007
6283
|
return u8arr.buffer;
|
|
6008
6284
|
}
|
|
6009
6285
|
removeScratchCanvas() {
|
|
6010
|
-
var _a;
|
|
6011
6286
|
this.ctx = void 0;
|
|
6012
|
-
|
|
6287
|
+
this._scratchCanvas?.remove();
|
|
6013
6288
|
}
|
|
6014
6289
|
}
|
|
6015
6290
|
|
|
@@ -6020,29 +6295,6 @@ var LabelHorizontalAlignmentMode = /* @__PURE__ */ ((LabelHorizontalAlignmentMod
|
|
|
6020
6295
|
return LabelHorizontalAlignmentMode2;
|
|
6021
6296
|
})(LabelHorizontalAlignmentMode || {});
|
|
6022
6297
|
|
|
6023
|
-
var __defProp$4 = Object.defineProperty;
|
|
6024
|
-
var __defProps$2 = Object.defineProperties;
|
|
6025
|
-
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
6026
|
-
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
6027
|
-
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
6028
|
-
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
6029
|
-
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6030
|
-
var __spreadValues$3 = (a, b) => {
|
|
6031
|
-
for (var prop in b || (b = {}))
|
|
6032
|
-
if (__hasOwnProp$3.call(b, prop))
|
|
6033
|
-
__defNormalProp$4(a, prop, b[prop]);
|
|
6034
|
-
if (__getOwnPropSymbols$3)
|
|
6035
|
-
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
6036
|
-
if (__propIsEnum$3.call(b, prop))
|
|
6037
|
-
__defNormalProp$4(a, prop, b[prop]);
|
|
6038
|
-
}
|
|
6039
|
-
return a;
|
|
6040
|
-
};
|
|
6041
|
-
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
6042
|
-
var __publicField$4 = (obj, key, value) => {
|
|
6043
|
-
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6044
|
-
return value;
|
|
6045
|
-
};
|
|
6046
6298
|
class Label extends Entity {
|
|
6047
6299
|
/**
|
|
6048
6300
|
* Single or multi-line text formatted and rendered on the screen.
|
|
@@ -6053,34 +6305,22 @@ class Label extends Entity {
|
|
|
6053
6305
|
*/
|
|
6054
6306
|
constructor(options = {}) {
|
|
6055
6307
|
super(options);
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6308
|
+
this.type = EntityType.Label;
|
|
6309
|
+
this.isDrawable = true;
|
|
6310
|
+
this.isText = true;
|
|
6059
6311
|
// Drawable options
|
|
6060
|
-
|
|
6061
|
-
|
|
6312
|
+
this.anchorPoint = { x: 0.5, y: 0.5 };
|
|
6313
|
+
this.zPosition = 0;
|
|
6062
6314
|
// Text options
|
|
6063
|
-
|
|
6315
|
+
this._text = "";
|
|
6064
6316
|
// public getter/setter is below
|
|
6065
|
-
|
|
6317
|
+
this._fontColor = Constants.DEFAULT_FONT_COLOR;
|
|
6066
6318
|
// public getter/setter is below
|
|
6067
|
-
|
|
6068
|
-
// public getter/setter is below
|
|
6069
|
-
__publicField$4(this, "_fontColor", Constants.DEFAULT_FONT_COLOR);
|
|
6070
|
-
// public getter/setter is below
|
|
6071
|
-
__publicField$4(this, "_fontSize", Constants.DEFAULT_FONT_SIZE);
|
|
6319
|
+
this._fontSize = Constants.DEFAULT_FONT_SIZE;
|
|
6072
6320
|
// public getter/setter is below
|
|
6073
6321
|
// Label options
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
__publicField$4(this, "_preferredMaxLayoutWidth");
|
|
6077
|
-
// public getter/setter is below
|
|
6078
|
-
__publicField$4(this, "_backgroundColor");
|
|
6079
|
-
// public getter/setter is below
|
|
6080
|
-
__publicField$4(this, "paragraph");
|
|
6081
|
-
__publicField$4(this, "paraStyle");
|
|
6082
|
-
__publicField$4(this, "builder");
|
|
6083
|
-
__publicField$4(this, "_translatedText", "");
|
|
6322
|
+
this._horizontalAlignmentMode = LabelHorizontalAlignmentMode.Center;
|
|
6323
|
+
this._translatedText = "";
|
|
6084
6324
|
handleInterfaceOptions(this, options);
|
|
6085
6325
|
if (options.horizontalAlignmentMode) {
|
|
6086
6326
|
this.horizontalAlignmentMode = options.horizontalAlignmentMode;
|
|
@@ -6096,7 +6336,6 @@ class Label extends Entity {
|
|
|
6096
6336
|
}
|
|
6097
6337
|
}
|
|
6098
6338
|
initialize() {
|
|
6099
|
-
var _a, _b, _c;
|
|
6100
6339
|
let ckTextAlign = this.canvasKit.TextAlign.Center;
|
|
6101
6340
|
switch (this.horizontalAlignmentMode) {
|
|
6102
6341
|
case LabelHorizontalAlignmentMode.Center:
|
|
@@ -6188,28 +6427,67 @@ class Label extends Entity {
|
|
|
6188
6427
|
fontFamilies.push(defaultTypeface.fontFamily);
|
|
6189
6428
|
}
|
|
6190
6429
|
this.paraStyle = new this.canvasKit.ParagraphStyle({
|
|
6191
|
-
textStyle: {
|
|
6192
|
-
color: textColor,
|
|
6193
|
-
backgroundColor: this.backgroundColor ? this.canvasKit.Color(
|
|
6194
|
-
this.backgroundColor[0],
|
|
6195
|
-
this.backgroundColor[1],
|
|
6196
|
-
this.backgroundColor[2],
|
|
6197
|
-
this.backgroundColor[3]
|
|
6198
|
-
) : void 0,
|
|
6199
|
-
fontFamilies,
|
|
6200
|
-
fontSize: this.fontSize * Globals.canvasScale
|
|
6201
|
-
},
|
|
6430
|
+
textStyle: {},
|
|
6202
6431
|
textAlign: ckTextAlign
|
|
6203
6432
|
});
|
|
6433
|
+
if (this.builder) {
|
|
6434
|
+
this.builder.delete();
|
|
6435
|
+
}
|
|
6204
6436
|
this.builder = this.canvasKit.ParagraphBuilder.Make(
|
|
6205
6437
|
this.paraStyle,
|
|
6206
6438
|
fontManager.fontMgr
|
|
6207
6439
|
);
|
|
6440
|
+
if (!this._backgroundPaint) {
|
|
6441
|
+
this._backgroundPaint = new this.canvasKit.Paint();
|
|
6442
|
+
}
|
|
6443
|
+
if (!this._fontPaint) {
|
|
6444
|
+
this._fontPaint = new this.canvasKit.Paint();
|
|
6445
|
+
}
|
|
6446
|
+
this.fontPaint.setColor(textColor);
|
|
6447
|
+
this.fontPaint.setAlphaf(this.absoluteAlpha);
|
|
6448
|
+
if (this.backgroundColor) {
|
|
6449
|
+
this.backgroundPaint.setColor(this.backgroundColor);
|
|
6450
|
+
this.backgroundPaint.setAlphaf(this.absoluteAlpha);
|
|
6451
|
+
} else {
|
|
6452
|
+
this.backgroundPaint.setColor(this.canvasKit.Color(0, 0, 0, 0));
|
|
6453
|
+
}
|
|
6454
|
+
this.builder.pushPaintStyle(
|
|
6455
|
+
{
|
|
6456
|
+
fontFamilies,
|
|
6457
|
+
fontSize: this.fontSize * Globals.canvasScale,
|
|
6458
|
+
// set default values for below properties as well.
|
|
6459
|
+
fontStyle: {
|
|
6460
|
+
weight: this.canvasKit.FontWeight.Normal,
|
|
6461
|
+
width: this.canvasKit.FontWidth.Normal,
|
|
6462
|
+
slant: this.canvasKit.FontSlant.Oblique
|
|
6463
|
+
},
|
|
6464
|
+
// Normal font style
|
|
6465
|
+
decoration: 0,
|
|
6466
|
+
// No decoration
|
|
6467
|
+
decorationThickness: 1,
|
|
6468
|
+
// Default decoration thickness
|
|
6469
|
+
decorationStyle: this.canvasKit.DecorationStyle.Solid,
|
|
6470
|
+
// Solid decoration style
|
|
6471
|
+
heightMultiplier: -1,
|
|
6472
|
+
// Providing -1, rather than 1.0, gives default height multiplier
|
|
6473
|
+
halfLeading: false,
|
|
6474
|
+
// Default half leading
|
|
6475
|
+
letterSpacing: 0,
|
|
6476
|
+
// Default letter spacing
|
|
6477
|
+
wordSpacing: 0
|
|
6478
|
+
// Default word spacing
|
|
6479
|
+
},
|
|
6480
|
+
this.fontPaint,
|
|
6481
|
+
this.backgroundPaint
|
|
6482
|
+
);
|
|
6208
6483
|
this.builder.addText(textForParagraph);
|
|
6484
|
+
if (this.paragraph) {
|
|
6485
|
+
this.paragraph.delete();
|
|
6486
|
+
}
|
|
6209
6487
|
this.paragraph = this.builder.build();
|
|
6210
6488
|
const preferredWidth = (
|
|
6211
6489
|
//this.preferredMaxLayoutWidth ?? this.parentScene.game.canvasCssWidth;
|
|
6212
|
-
|
|
6490
|
+
this.preferredMaxLayoutWidth ?? Globals.canvasCssWidth
|
|
6213
6491
|
);
|
|
6214
6492
|
let calculatedWidth = preferredWidth;
|
|
6215
6493
|
if (preferredWidth === 0 || this.layout.width === 0) {
|
|
@@ -6218,8 +6496,8 @@ class Label extends Entity {
|
|
|
6218
6496
|
"width is set to match parent, but entity has no parent"
|
|
6219
6497
|
);
|
|
6220
6498
|
}
|
|
6221
|
-
const marginStart =
|
|
6222
|
-
const marginEnd =
|
|
6499
|
+
const marginStart = this.layout.marginStart ?? 0;
|
|
6500
|
+
const marginEnd = this.layout.marginEnd ?? 0;
|
|
6223
6501
|
calculatedWidth = this.parent.size.width - (marginStart + marginEnd);
|
|
6224
6502
|
}
|
|
6225
6503
|
this.paragraph.layout(calculatedWidth * Globals.canvasScale);
|
|
@@ -6233,7 +6511,14 @@ class Label extends Entity {
|
|
|
6233
6511
|
this.needsInitialization = false;
|
|
6234
6512
|
}
|
|
6235
6513
|
dispose() {
|
|
6236
|
-
CanvasKitHelpers.Dispose([
|
|
6514
|
+
CanvasKitHelpers.Dispose([
|
|
6515
|
+
this.paragraph,
|
|
6516
|
+
this.builder,
|
|
6517
|
+
this._fontPaint,
|
|
6518
|
+
// use backing field since it may be undefined
|
|
6519
|
+
this._backgroundPaint
|
|
6520
|
+
// use backing field since it may be undefined
|
|
6521
|
+
]);
|
|
6237
6522
|
}
|
|
6238
6523
|
get text() {
|
|
6239
6524
|
return this._text;
|
|
@@ -6294,6 +6579,24 @@ class Label extends Entity {
|
|
|
6294
6579
|
this._backgroundColor = backgroundColor;
|
|
6295
6580
|
this.needsInitialization = true;
|
|
6296
6581
|
}
|
|
6582
|
+
get backgroundPaint() {
|
|
6583
|
+
if (!this._backgroundPaint) {
|
|
6584
|
+
throw new Error("backgroundPaint cannot be undefined");
|
|
6585
|
+
}
|
|
6586
|
+
return this._backgroundPaint;
|
|
6587
|
+
}
|
|
6588
|
+
set backgroundPaint(backgroundPaint) {
|
|
6589
|
+
this._backgroundPaint = backgroundPaint;
|
|
6590
|
+
}
|
|
6591
|
+
get fontPaint() {
|
|
6592
|
+
if (!this._fontPaint) {
|
|
6593
|
+
throw new Error("fontPaint cannot be undefined");
|
|
6594
|
+
}
|
|
6595
|
+
return this._fontPaint;
|
|
6596
|
+
}
|
|
6597
|
+
set fontPaint(fontPaint) {
|
|
6598
|
+
this._fontPaint = fontPaint;
|
|
6599
|
+
}
|
|
6297
6600
|
/**
|
|
6298
6601
|
* Duplicates an entity using deep copy.
|
|
6299
6602
|
*
|
|
@@ -6305,12 +6608,15 @@ class Label extends Entity {
|
|
|
6305
6608
|
* provided, name will be the new uuid
|
|
6306
6609
|
*/
|
|
6307
6610
|
duplicate(newName) {
|
|
6308
|
-
const dest = new Label(
|
|
6611
|
+
const dest = new Label({
|
|
6612
|
+
...this.getEntityOptions(),
|
|
6613
|
+
...this.getDrawableOptions(),
|
|
6614
|
+
...this.getTextOptions(),
|
|
6309
6615
|
horizontalAlignmentMode: this.horizontalAlignmentMode,
|
|
6310
6616
|
preferredMaxLayoutWidth: this.preferredMaxLayoutWidth,
|
|
6311
6617
|
backgroundColor: this.backgroundColor,
|
|
6312
6618
|
name: newName
|
|
6313
|
-
})
|
|
6619
|
+
});
|
|
6314
6620
|
if (this.children.length > 0) {
|
|
6315
6621
|
dest.children = this.children.map((child) => {
|
|
6316
6622
|
const clonedChild = child.duplicate();
|
|
@@ -6322,12 +6628,16 @@ class Label extends Entity {
|
|
|
6322
6628
|
}
|
|
6323
6629
|
update() {
|
|
6324
6630
|
super.update();
|
|
6631
|
+
if (this.absoluteAlphaChange !== 0) {
|
|
6632
|
+
this.initialize();
|
|
6633
|
+
}
|
|
6325
6634
|
}
|
|
6326
6635
|
draw(canvas) {
|
|
6327
6636
|
if (this.parent && this.text !== "") {
|
|
6328
6637
|
canvas.save();
|
|
6329
6638
|
const drawScale = Globals.canvasScale / this.absoluteScale;
|
|
6330
6639
|
canvas.scale(1 / drawScale, 1 / drawScale);
|
|
6640
|
+
M2c2KitHelpers.rotateCanvasForDrawableEntity(canvas, this);
|
|
6331
6641
|
const x = (this.absolutePosition.x - this.size.width * this.anchorPoint.x * this.absoluteScale) * drawScale;
|
|
6332
6642
|
const y = (this.absolutePosition.y - this.size.height * this.anchorPoint.y * this.absoluteScale) * drawScale;
|
|
6333
6643
|
if (this.paragraph === void 0) {
|
|
@@ -6351,57 +6661,6 @@ class Label extends Entity {
|
|
|
6351
6661
|
}
|
|
6352
6662
|
}
|
|
6353
6663
|
|
|
6354
|
-
var __defProp$3 = Object.defineProperty;
|
|
6355
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6356
|
-
var __publicField$3 = (obj, key, value) => {
|
|
6357
|
-
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6358
|
-
return value;
|
|
6359
|
-
};
|
|
6360
|
-
class MutablePath {
|
|
6361
|
-
constructor() {
|
|
6362
|
-
__publicField$3(this, "size", { width: 0, height: 0 });
|
|
6363
|
-
__publicField$3(this, "_subpaths", new Array());
|
|
6364
|
-
__publicField$3(this, "currentPath", new Array());
|
|
6365
|
-
}
|
|
6366
|
-
get subpaths() {
|
|
6367
|
-
if (this.currentPath.length > 0) {
|
|
6368
|
-
return [...this._subpaths, this.currentPath];
|
|
6369
|
-
} else {
|
|
6370
|
-
return this._subpaths;
|
|
6371
|
-
}
|
|
6372
|
-
}
|
|
6373
|
-
/**
|
|
6374
|
-
* Starts a new subpath at a given point.
|
|
6375
|
-
*
|
|
6376
|
-
* @param point - location at which to start the new subpath
|
|
6377
|
-
*/
|
|
6378
|
-
move(point) {
|
|
6379
|
-
if (this.currentPath.length > 0) {
|
|
6380
|
-
this._subpaths.push(this.currentPath);
|
|
6381
|
-
}
|
|
6382
|
-
this.currentPath = new Array();
|
|
6383
|
-
this.currentPath.push(point);
|
|
6384
|
-
}
|
|
6385
|
-
/**
|
|
6386
|
-
* Adds a straight line to the current subpath.
|
|
6387
|
-
*
|
|
6388
|
-
* @remarks The line is added from the last point in the current subpath to
|
|
6389
|
-
* the given point.
|
|
6390
|
-
*
|
|
6391
|
-
* @param point - location where the line will end
|
|
6392
|
-
*/
|
|
6393
|
-
addLine(point) {
|
|
6394
|
-
this.currentPath.push(point);
|
|
6395
|
-
}
|
|
6396
|
-
clear() {
|
|
6397
|
-
this._subpaths = new Array();
|
|
6398
|
-
this.currentPath = new Array();
|
|
6399
|
-
}
|
|
6400
|
-
duplicate(newName) {
|
|
6401
|
-
throw new Error("Method not implemented.");
|
|
6402
|
-
}
|
|
6403
|
-
}
|
|
6404
|
-
|
|
6405
6664
|
class RandomDraws {
|
|
6406
6665
|
/**
|
|
6407
6666
|
* Draws a single random integer from a uniform distribution of integers in
|
|
@@ -6454,7 +6713,7 @@ class RandomDraws {
|
|
|
6454
6713
|
* grid location to be along the diagonal, the predicate would be:
|
|
6455
6714
|
* (row, column) => row === column
|
|
6456
6715
|
* @returns Array of grid cells. Each cell is object in form of:
|
|
6457
|
-
*
|
|
6716
|
+
* { row: number, column: number }. Grid cell locations are zero-based
|
|
6458
6717
|
*/
|
|
6459
6718
|
static FromGridWithoutReplacement(n, rows, columns, predicate) {
|
|
6460
6719
|
const result = new Array();
|
|
@@ -6495,10 +6754,7 @@ function getAugmentedNamespace(n) {
|
|
|
6495
6754
|
if (typeof f == "function") {
|
|
6496
6755
|
var a = function a () {
|
|
6497
6756
|
if (this instanceof a) {
|
|
6498
|
-
|
|
6499
|
-
args.push.apply(args, arguments);
|
|
6500
|
-
var Ctor = Function.bind.apply(f, args);
|
|
6501
|
-
return new Ctor();
|
|
6757
|
+
return Reflect.construct(f, arguments, this.constructor);
|
|
6502
6758
|
}
|
|
6503
6759
|
return f.apply(this, arguments);
|
|
6504
6760
|
};
|
|
@@ -7065,26 +7321,6 @@ var w;w||(w=typeof CanvasKitInit !== 'undefined' ? CanvasKitInit : {});var da,ea
|
|
|
7065
7321
|
var canvaskitExports = canvaskit.exports;
|
|
7066
7322
|
var CanvasKitInit = /*@__PURE__*/getDefaultExportFromCjs(canvaskitExports);
|
|
7067
7323
|
|
|
7068
|
-
var __defProp$2 = Object.defineProperty;
|
|
7069
|
-
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
7070
|
-
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
7071
|
-
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
7072
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7073
|
-
var __spreadValues$2 = (a, b) => {
|
|
7074
|
-
for (var prop in b || (b = {}))
|
|
7075
|
-
if (__hasOwnProp$2.call(b, prop))
|
|
7076
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
7077
|
-
if (__getOwnPropSymbols$2)
|
|
7078
|
-
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
7079
|
-
if (__propIsEnum$2.call(b, prop))
|
|
7080
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
7081
|
-
}
|
|
7082
|
-
return a;
|
|
7083
|
-
};
|
|
7084
|
-
var __publicField$2 = (obj, key, value) => {
|
|
7085
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7086
|
-
return value;
|
|
7087
|
-
};
|
|
7088
7324
|
class Session {
|
|
7089
7325
|
/**
|
|
7090
7326
|
* A Session contains one or more activities. The session manages the start
|
|
@@ -7093,17 +7329,10 @@ class Session {
|
|
|
7093
7329
|
* @param options
|
|
7094
7330
|
*/
|
|
7095
7331
|
constructor(options) {
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
__publicField$2(this, "uuid");
|
|
7101
|
-
__publicField$2(this, "dataStores");
|
|
7102
|
-
__publicField$2(this, "eventListeners", new Array());
|
|
7103
|
-
__publicField$2(this, "sessionDictionary", /* @__PURE__ */ new Map());
|
|
7104
|
-
__publicField$2(this, "canvasKit");
|
|
7105
|
-
__publicField$2(this, "initialized", false);
|
|
7106
|
-
__publicField$2(this, "version", "0.3.12 (291d0cee)");
|
|
7332
|
+
this.eventListeners = new Array();
|
|
7333
|
+
this.sessionDictionary = /* @__PURE__ */ new Map();
|
|
7334
|
+
this.initialized = false;
|
|
7335
|
+
this.version = "0.3.14 (60325bea)";
|
|
7107
7336
|
this.options = options;
|
|
7108
7337
|
for (const activity of this.options.activities) {
|
|
7109
7338
|
if (this.options.activities.filter((a) => a === activity).length > 1) {
|
|
@@ -7177,9 +7406,9 @@ class Session {
|
|
|
7177
7406
|
const eventListener = {
|
|
7178
7407
|
type,
|
|
7179
7408
|
callback,
|
|
7180
|
-
key: options
|
|
7409
|
+
key: options?.key
|
|
7181
7410
|
};
|
|
7182
|
-
if (options
|
|
7411
|
+
if (options?.replaceExisting) {
|
|
7183
7412
|
this.eventListeners = this.eventListeners.filter(
|
|
7184
7413
|
(listener) => !(listener.type === eventListener.type)
|
|
7185
7414
|
);
|
|
@@ -7188,7 +7417,11 @@ class Session {
|
|
|
7188
7417
|
}
|
|
7189
7418
|
raiseEventOnListeners(event, extra) {
|
|
7190
7419
|
if (extra) {
|
|
7191
|
-
event =
|
|
7420
|
+
event = {
|
|
7421
|
+
...event,
|
|
7422
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7423
|
+
...extra
|
|
7424
|
+
};
|
|
7192
7425
|
}
|
|
7193
7426
|
this.eventListeners.filter((listener) => listener.type === event.type).forEach((listener) => {
|
|
7194
7427
|
listener.callback(event);
|
|
@@ -7264,13 +7497,12 @@ class Session {
|
|
|
7264
7497
|
}
|
|
7265
7498
|
const activityPrototype = Object.getPrototypeOf(activity);
|
|
7266
7499
|
const gamePrototype = Object.getPrototypeOf(activityPrototype);
|
|
7267
|
-
return
|
|
7500
|
+
return activityPrototype?.init !== gamePrototype?.init;
|
|
7268
7501
|
}
|
|
7269
7502
|
/**
|
|
7270
7503
|
* Asynchronously initializes the m2c2kit engine and loads assets
|
|
7271
7504
|
*/
|
|
7272
7505
|
async initialize() {
|
|
7273
|
-
var _a;
|
|
7274
7506
|
console.log(`\u26AA @m2c2kit/core version ${this.version}`);
|
|
7275
7507
|
Timer.start("sessionInitialize");
|
|
7276
7508
|
const sessionInitializeEvent = {
|
|
@@ -7282,7 +7514,7 @@ class Session {
|
|
|
7282
7514
|
DomHelpers.setSpinnerVisibility(true);
|
|
7283
7515
|
DomHelpers.setCanvasOverlayVisibility(true);
|
|
7284
7516
|
this.dataStores = this.options.dataStores;
|
|
7285
|
-
if (
|
|
7517
|
+
if (this.dataStores?.length === 0) {
|
|
7286
7518
|
throw new Error(
|
|
7287
7519
|
"Session.initialize(): dataStores must be undefined or a non-zero array of datastores."
|
|
7288
7520
|
);
|
|
@@ -7571,9 +7803,8 @@ class Session {
|
|
|
7571
7803
|
}
|
|
7572
7804
|
getImagesConfigurationFromGames() {
|
|
7573
7805
|
return this.options.activities.filter((activity) => activity.type == ActivityType.Game).map((activity) => {
|
|
7574
|
-
var _a;
|
|
7575
7806
|
const game = activity;
|
|
7576
|
-
return { uuid: game.uuid, images:
|
|
7807
|
+
return { uuid: game.uuid, images: game.options.images ?? [] };
|
|
7577
7808
|
});
|
|
7578
7809
|
}
|
|
7579
7810
|
prependAssetsUrl(url) {
|
|
@@ -7590,29 +7821,6 @@ class Session {
|
|
|
7590
7821
|
}
|
|
7591
7822
|
}
|
|
7592
7823
|
|
|
7593
|
-
var __defProp$1 = Object.defineProperty;
|
|
7594
|
-
var __defProps$1 = Object.defineProperties;
|
|
7595
|
-
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
7596
|
-
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
7597
|
-
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
7598
|
-
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
7599
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7600
|
-
var __spreadValues$1 = (a, b) => {
|
|
7601
|
-
for (var prop in b || (b = {}))
|
|
7602
|
-
if (__hasOwnProp$1.call(b, prop))
|
|
7603
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
7604
|
-
if (__getOwnPropSymbols$1)
|
|
7605
|
-
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
7606
|
-
if (__propIsEnum$1.call(b, prop))
|
|
7607
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
7608
|
-
}
|
|
7609
|
-
return a;
|
|
7610
|
-
};
|
|
7611
|
-
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
7612
|
-
var __publicField$1 = (obj, key, value) => {
|
|
7613
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7614
|
-
return value;
|
|
7615
|
-
};
|
|
7616
7824
|
class Shape extends Entity {
|
|
7617
7825
|
/**
|
|
7618
7826
|
* Rectangular, circular, or path-based shape
|
|
@@ -7621,45 +7829,41 @@ class Shape extends Entity {
|
|
|
7621
7829
|
*/
|
|
7622
7830
|
constructor(options = {}) {
|
|
7623
7831
|
super(options);
|
|
7624
|
-
|
|
7625
|
-
|
|
7626
|
-
|
|
7832
|
+
this.type = EntityType.Shape;
|
|
7833
|
+
this.isDrawable = true;
|
|
7834
|
+
this.isShape = true;
|
|
7627
7835
|
// Drawable options
|
|
7628
|
-
|
|
7629
|
-
|
|
7836
|
+
this.anchorPoint = { x: 0.5, y: 0.5 };
|
|
7837
|
+
this.zPosition = 0;
|
|
7630
7838
|
// Shape options
|
|
7631
7839
|
// TODO: fix the Size issue; should be readonly (calculated value) in all entities, but Rectangle
|
|
7632
|
-
|
|
7633
|
-
|
|
7634
|
-
|
|
7635
|
-
|
|
7636
|
-
|
|
7637
|
-
|
|
7638
|
-
|
|
7639
|
-
|
|
7640
|
-
|
|
7641
|
-
|
|
7642
|
-
|
|
7643
|
-
|
|
7644
|
-
__publicField$1(this, "_fillColorPaintAntialiased");
|
|
7645
|
-
__publicField$1(this, "_strokeColorPaintAntialiased");
|
|
7646
|
-
__publicField$1(this, "_fillColorPaintNotAntialiased");
|
|
7647
|
-
__publicField$1(this, "_strokeColorPaintNotAntialiased");
|
|
7648
|
-
__publicField$1(this, "svgPathRequestedWidth");
|
|
7649
|
-
__publicField$1(this, "svgPathRequestedHeight");
|
|
7650
|
-
__publicField$1(this, "svgPathScaleForResizing", 1);
|
|
7651
|
-
__publicField$1(this, "svgPathWidth", 0);
|
|
7652
|
-
__publicField$1(this, "svgPathHeight", 0);
|
|
7653
|
-
__publicField$1(this, "svgPreviousAbsoluteX", NaN);
|
|
7654
|
-
__publicField$1(this, "svgPreviousAbsoluteY", NaN);
|
|
7655
|
-
__publicField$1(this, "svgFirstPathDraw", true);
|
|
7840
|
+
this.shapeType = ShapeType.Undefined;
|
|
7841
|
+
this.ckPath = null;
|
|
7842
|
+
this.cornerRadius = 0;
|
|
7843
|
+
this._fillColor = Constants.DEFAULT_SHAPE_FILL_COLOR;
|
|
7844
|
+
this._isAntialiased = true;
|
|
7845
|
+
this.svgPathScaleForResizing = 1;
|
|
7846
|
+
this.svgPathWidth = 0;
|
|
7847
|
+
this.svgPathHeight = 0;
|
|
7848
|
+
this.svgPreviousAbsoluteX = NaN;
|
|
7849
|
+
this.svgPreviousAbsoluteY = NaN;
|
|
7850
|
+
this.svgFirstPathDraw = true;
|
|
7851
|
+
this.colorfulPathPaints = /* @__PURE__ */ new Map();
|
|
7656
7852
|
handleInterfaceOptions(this, options);
|
|
7657
7853
|
if (options.path !== void 0) {
|
|
7658
7854
|
this.path = options.path;
|
|
7659
7855
|
this.shapeType = ShapeType.Path;
|
|
7660
|
-
if (this.
|
|
7661
|
-
|
|
7662
|
-
|
|
7856
|
+
if (this.shapeIsM2Path()) {
|
|
7857
|
+
if (options.size !== void 0) {
|
|
7858
|
+
this.size = options.size;
|
|
7859
|
+
}
|
|
7860
|
+
}
|
|
7861
|
+
if (this.shapeIsSvgStringPath()) {
|
|
7862
|
+
if (options.size !== void 0) {
|
|
7863
|
+
throw new Error(
|
|
7864
|
+
"Size cannot be specified when path is SVG string path"
|
|
7865
|
+
);
|
|
7866
|
+
}
|
|
7663
7867
|
}
|
|
7664
7868
|
this.svgPathRequestedWidth = options.path.width;
|
|
7665
7869
|
this.svgPathRequestedHeight = options.path.height;
|
|
@@ -7711,7 +7915,7 @@ class Shape extends Entity {
|
|
|
7711
7915
|
throw new Error("Size cannot be specified for rectangle shape");
|
|
7712
7916
|
}
|
|
7713
7917
|
}
|
|
7714
|
-
if (options.cornerRadius) {
|
|
7918
|
+
if (options.cornerRadius !== void 0) {
|
|
7715
7919
|
this.cornerRadius = options.cornerRadius;
|
|
7716
7920
|
}
|
|
7717
7921
|
if (options.fillColor) {
|
|
@@ -7726,9 +7930,9 @@ class Shape extends Entity {
|
|
|
7726
7930
|
if (options.isAntialiased !== void 0) {
|
|
7727
7931
|
this.isAntialiased = options.isAntialiased;
|
|
7728
7932
|
}
|
|
7729
|
-
if (options.strokeColor && options.lineWidth
|
|
7933
|
+
if (options.strokeColor && !options.lineWidth) {
|
|
7730
7934
|
console.warn(
|
|
7731
|
-
`warning: for entity ${this}, strokeColor = ${options.strokeColor} but lineWidth is
|
|
7935
|
+
`warning: for entity ${this}, strokeColor = ${options.strokeColor} but lineWidth is non-zero. In normal usage, both would be set or both would be undefined.`
|
|
7732
7936
|
);
|
|
7733
7937
|
}
|
|
7734
7938
|
if (options.strokeColor === void 0 && options.lineWidth) {
|
|
@@ -7740,11 +7944,16 @@ class Shape extends Entity {
|
|
|
7740
7944
|
initialize() {
|
|
7741
7945
|
if (this.shapeType === ShapeType.Path) {
|
|
7742
7946
|
if (this.shapeIsSvgStringPath()) {
|
|
7743
|
-
const
|
|
7744
|
-
if (!
|
|
7947
|
+
const pathString = this.path.pathString ?? this.path.svgPathString;
|
|
7948
|
+
if (!pathString) {
|
|
7745
7949
|
throw new Error("SVG Path string is null/undefined");
|
|
7746
7950
|
}
|
|
7747
|
-
this.
|
|
7951
|
+
if (this.path.svgPathString !== void 0) {
|
|
7952
|
+
console.warn(
|
|
7953
|
+
`warning: svgPathString is deprecated. Use pathString instead.`
|
|
7954
|
+
);
|
|
7955
|
+
}
|
|
7956
|
+
this.ckPath = this.canvasKit.Path.MakeFromSVGString(pathString);
|
|
7748
7957
|
if (!this.ckPath) {
|
|
7749
7958
|
throw new Error("could not make CanvasKit Path from SVG string");
|
|
7750
7959
|
}
|
|
@@ -7762,6 +7971,13 @@ class Shape extends Entity {
|
|
|
7762
7971
|
this.svgPreviousAbsoluteY = 0;
|
|
7763
7972
|
}
|
|
7764
7973
|
}
|
|
7974
|
+
if (this.shapeIsM2Path()) {
|
|
7975
|
+
if (this.size.width === 0 || this.size.height === 0 || this.size.width === void 0 || this.size.height === void 0) {
|
|
7976
|
+
throw new Error(
|
|
7977
|
+
"Size of shape must have non-zero height and width when path is M2Path"
|
|
7978
|
+
);
|
|
7979
|
+
}
|
|
7980
|
+
}
|
|
7765
7981
|
if (this.fillColor) {
|
|
7766
7982
|
this.fillColorPaintAntialiased = CanvasKitHelpers.makePaint(
|
|
7767
7983
|
this.canvasKit,
|
|
@@ -7795,11 +8011,13 @@ class Shape extends Entity {
|
|
|
7795
8011
|
}
|
|
7796
8012
|
dispose() {
|
|
7797
8013
|
CanvasKitHelpers.Dispose([
|
|
8014
|
+
// use backing fields, since paints may be undefined
|
|
7798
8015
|
this._strokeColorPaintAntialiased,
|
|
7799
8016
|
this._strokeColorPaintNotAntialiased,
|
|
7800
8017
|
this._fillColorPaintAntialiased,
|
|
7801
8018
|
this._fillColorPaintNotAntialiased,
|
|
7802
|
-
this.ckPath
|
|
8019
|
+
this.ckPath,
|
|
8020
|
+
...Array.from(this.colorfulPathPaints.values())
|
|
7803
8021
|
]);
|
|
7804
8022
|
}
|
|
7805
8023
|
/**
|
|
@@ -7813,7 +8031,9 @@ class Shape extends Entity {
|
|
|
7813
8031
|
* provided, name will be the new uuid
|
|
7814
8032
|
*/
|
|
7815
8033
|
duplicate(newName) {
|
|
7816
|
-
const dest = new Shape(
|
|
8034
|
+
const dest = new Shape({
|
|
8035
|
+
...this.getEntityOptions(),
|
|
8036
|
+
...this.getDrawableOptions(),
|
|
7817
8037
|
shapeType: this.shapeType,
|
|
7818
8038
|
circleOfRadius: this.circleOfRadius,
|
|
7819
8039
|
rect: this.rect,
|
|
@@ -7822,7 +8042,7 @@ class Shape extends Entity {
|
|
|
7822
8042
|
strokeColor: this.strokeColor,
|
|
7823
8043
|
lineWidth: this.lineWidth,
|
|
7824
8044
|
name: newName
|
|
7825
|
-
})
|
|
8045
|
+
});
|
|
7826
8046
|
if (this.children.length > 0) {
|
|
7827
8047
|
dest.children = this.children.map((child) => {
|
|
7828
8048
|
const clonedChild = child.duplicate();
|
|
@@ -7839,6 +8059,15 @@ class Shape extends Entity {
|
|
|
7839
8059
|
canvas.save();
|
|
7840
8060
|
const drawScale = Globals.canvasScale / this.absoluteScale;
|
|
7841
8061
|
canvas.scale(1 / drawScale, 1 / drawScale);
|
|
8062
|
+
M2c2KitHelpers.rotateCanvasForDrawableEntity(canvas, this);
|
|
8063
|
+
if (this.absoluteAlphaChange !== 0) {
|
|
8064
|
+
this.applyAlphaToPaints(this.absoluteAlpha, [
|
|
8065
|
+
this._fillColorPaintAntialiased,
|
|
8066
|
+
this._fillColorPaintNotAntialiased,
|
|
8067
|
+
this._strokeColorPaintAntialiased,
|
|
8068
|
+
this._strokeColorPaintNotAntialiased
|
|
8069
|
+
]);
|
|
8070
|
+
}
|
|
7842
8071
|
if (this.shapeIsM2Path()) {
|
|
7843
8072
|
this.drawPathFromM2Path(canvas);
|
|
7844
8073
|
}
|
|
@@ -7854,12 +8083,63 @@ class Shape extends Entity {
|
|
|
7854
8083
|
canvas.restore();
|
|
7855
8084
|
super.drawChildren(canvas);
|
|
7856
8085
|
}
|
|
8086
|
+
applyAlphaToPaints(alpha, paints) {
|
|
8087
|
+
paints.forEach((paint) => {
|
|
8088
|
+
if (paint) {
|
|
8089
|
+
paint.setAlphaf(alpha);
|
|
8090
|
+
}
|
|
8091
|
+
});
|
|
8092
|
+
}
|
|
7857
8093
|
drawPathFromM2Path(canvas) {
|
|
7858
8094
|
const drawScale = Globals.canvasScale / this.absoluteScale;
|
|
7859
8095
|
const pathOriginX = (this.absolutePosition.x - this.anchorPoint.x * this.size.width * this.absoluteScale) * drawScale;
|
|
7860
8096
|
const pathOriginY = (this.absolutePosition.y - this.anchorPoint.y * this.size.height * this.absoluteScale) * drawScale;
|
|
8097
|
+
if (this.pathIsM2ColorfulPath(this.path)) {
|
|
8098
|
+
const linePresentations = this.path.linePresentations;
|
|
8099
|
+
let lp = 0;
|
|
8100
|
+
const subpaths = this.path.subpaths;
|
|
8101
|
+
let paint;
|
|
8102
|
+
for (let s = 0; s < subpaths.length; s++) {
|
|
8103
|
+
const subpath = subpaths[s];
|
|
8104
|
+
const points = subpath.flat();
|
|
8105
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
8106
|
+
if (linePresentations[lp].subpathIndex === s && linePresentations[lp].pointIndex === i) {
|
|
8107
|
+
const strokeColor = linePresentations[lp].strokeColor;
|
|
8108
|
+
const lineWidth = linePresentations[lp].lineWidth;
|
|
8109
|
+
const paintKey = [...strokeColor, lineWidth].toString();
|
|
8110
|
+
paint = this.colorfulPathPaints.get(paintKey);
|
|
8111
|
+
if (paint === void 0) {
|
|
8112
|
+
paint = CanvasKitHelpers.makePaint(
|
|
8113
|
+
this.canvasKit,
|
|
8114
|
+
strokeColor,
|
|
8115
|
+
this.canvasKit.PaintStyle.Stroke,
|
|
8116
|
+
true
|
|
8117
|
+
);
|
|
8118
|
+
paint.setStrokeWidth(lineWidth * Globals.canvasScale);
|
|
8119
|
+
this.colorfulPathPaints.set(paintKey, paint);
|
|
8120
|
+
}
|
|
8121
|
+
if (lp < linePresentations.length - 1) {
|
|
8122
|
+
lp++;
|
|
8123
|
+
}
|
|
8124
|
+
}
|
|
8125
|
+
if (paint === void 0) {
|
|
8126
|
+
throw new Error("paint is undefined");
|
|
8127
|
+
}
|
|
8128
|
+
canvas.drawLine(
|
|
8129
|
+
pathOriginX + points[i].x * Globals.canvasScale,
|
|
8130
|
+
pathOriginY + points[i].y * Globals.canvasScale,
|
|
8131
|
+
pathOriginX + points[i + 1].x * Globals.canvasScale,
|
|
8132
|
+
pathOriginY + points[i + 1].y * Globals.canvasScale,
|
|
8133
|
+
paint
|
|
8134
|
+
);
|
|
8135
|
+
}
|
|
8136
|
+
}
|
|
8137
|
+
return;
|
|
8138
|
+
}
|
|
7861
8139
|
if (this.strokeColor && this.strokeColorPaintAntialiased && this.lineWidth) {
|
|
7862
|
-
this.strokeColorPaintAntialiased.setStrokeWidth(
|
|
8140
|
+
this.strokeColorPaintAntialiased.setStrokeWidth(
|
|
8141
|
+
this.lineWidth * Globals.canvasScale
|
|
8142
|
+
);
|
|
7863
8143
|
const subpaths = this.path.subpaths;
|
|
7864
8144
|
for (const subpath of subpaths) {
|
|
7865
8145
|
const points = subpath.flat();
|
|
@@ -7925,12 +8205,13 @@ class Shape extends Entity {
|
|
|
7925
8205
|
return this.svgFirstPathDraw === true || x !== this.svgPreviousAbsoluteX || y !== this.svgPreviousAbsoluteY;
|
|
7926
8206
|
}
|
|
7927
8207
|
shapeIsSvgStringPath() {
|
|
7928
|
-
|
|
7929
|
-
return ((_a = this.path) == null ? void 0 : _a.svgPathString) !== void 0;
|
|
8208
|
+
return this.path?.pathString !== void 0 || this.path?.svgPathString !== void 0;
|
|
7930
8209
|
}
|
|
7931
8210
|
shapeIsM2Path() {
|
|
7932
|
-
|
|
7933
|
-
|
|
8211
|
+
return this.path?.subpaths !== void 0;
|
|
8212
|
+
}
|
|
8213
|
+
pathIsM2ColorfulPath(path) {
|
|
8214
|
+
return path !== void 0 && "linePresentations" in path;
|
|
7934
8215
|
}
|
|
7935
8216
|
drawCircle(canvas) {
|
|
7936
8217
|
if (!this.circleOfRadius) {
|
|
@@ -8132,29 +8413,6 @@ class Story {
|
|
|
8132
8413
|
}
|
|
8133
8414
|
}
|
|
8134
8415
|
|
|
8135
|
-
var __defProp = Object.defineProperty;
|
|
8136
|
-
var __defProps = Object.defineProperties;
|
|
8137
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
8138
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8139
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8140
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8141
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8142
|
-
var __spreadValues = (a, b) => {
|
|
8143
|
-
for (var prop in b || (b = {}))
|
|
8144
|
-
if (__hasOwnProp.call(b, prop))
|
|
8145
|
-
__defNormalProp(a, prop, b[prop]);
|
|
8146
|
-
if (__getOwnPropSymbols)
|
|
8147
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
8148
|
-
if (__propIsEnum.call(b, prop))
|
|
8149
|
-
__defNormalProp(a, prop, b[prop]);
|
|
8150
|
-
}
|
|
8151
|
-
return a;
|
|
8152
|
-
};
|
|
8153
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
8154
|
-
var __publicField = (obj, key, value) => {
|
|
8155
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8156
|
-
return value;
|
|
8157
|
-
};
|
|
8158
8416
|
class TextLine extends Entity {
|
|
8159
8417
|
/**
|
|
8160
8418
|
* Single-line text rendered on the screen.
|
|
@@ -8164,33 +8422,26 @@ class TextLine extends Entity {
|
|
|
8164
8422
|
* @param options - {@link TextLineOptions}
|
|
8165
8423
|
*/
|
|
8166
8424
|
constructor(options = {}) {
|
|
8167
|
-
var _a;
|
|
8168
8425
|
super(options);
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
|
|
8426
|
+
this.type = EntityType.TextLine;
|
|
8427
|
+
this.isDrawable = true;
|
|
8428
|
+
this.isText = true;
|
|
8172
8429
|
// Drawable options
|
|
8173
|
-
|
|
8430
|
+
this.zPosition = 0;
|
|
8174
8431
|
// We don't know TextLine width in advance, so we must text align left,
|
|
8175
8432
|
// and so anchorPoint is (0, .5). (we do know height, which is fontSize)
|
|
8176
|
-
|
|
8433
|
+
this.anchorPoint = { x: 0, y: 0.5 };
|
|
8177
8434
|
// Text options
|
|
8178
|
-
|
|
8179
|
-
// public getter/setter is below
|
|
8180
|
-
__publicField(this, "_fontName");
|
|
8181
|
-
// public getter/setter is below
|
|
8182
|
-
__publicField(this, "_fontColor", Constants.DEFAULT_FONT_COLOR);
|
|
8435
|
+
this._text = "";
|
|
8183
8436
|
// public getter/setter is below
|
|
8184
|
-
|
|
8437
|
+
this._fontColor = Constants.DEFAULT_FONT_COLOR;
|
|
8185
8438
|
// public getter/setter is below
|
|
8186
|
-
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
__publicField(this, "_translatedText", "");
|
|
8190
|
-
__publicField(this, "missingTranslationPaint");
|
|
8439
|
+
this._fontSize = Constants.DEFAULT_FONT_SIZE;
|
|
8440
|
+
this.typeface = null;
|
|
8441
|
+
this._translatedText = "";
|
|
8191
8442
|
handleInterfaceOptions(this, options);
|
|
8192
8443
|
this.size.height = this.fontSize;
|
|
8193
|
-
this.size.width =
|
|
8444
|
+
this.size.width = options.width ?? NaN;
|
|
8194
8445
|
}
|
|
8195
8446
|
get text() {
|
|
8196
8447
|
return this._text;
|
|
@@ -8227,6 +8478,9 @@ class TextLine extends Entity {
|
|
|
8227
8478
|
super.update();
|
|
8228
8479
|
}
|
|
8229
8480
|
initialize() {
|
|
8481
|
+
if (this.paint) {
|
|
8482
|
+
this.paint.delete();
|
|
8483
|
+
}
|
|
8230
8484
|
this.paint = new this.canvasKit.Paint();
|
|
8231
8485
|
this.paint.setColor(
|
|
8232
8486
|
this.canvasKit.Color(
|
|
@@ -8266,6 +8520,9 @@ class TextLine extends Entity {
|
|
|
8266
8520
|
this.typeface = fontManager.getTypeface(gameUuid, fontNames[0]);
|
|
8267
8521
|
}
|
|
8268
8522
|
}
|
|
8523
|
+
if (this.font) {
|
|
8524
|
+
this.font.delete();
|
|
8525
|
+
}
|
|
8269
8526
|
this.font = new this.canvasKit.Font(
|
|
8270
8527
|
this.typeface,
|
|
8271
8528
|
this.fontSize * Globals.canvasScale
|
|
@@ -8286,10 +8543,13 @@ class TextLine extends Entity {
|
|
|
8286
8543
|
* provided, name will be the new uuid
|
|
8287
8544
|
*/
|
|
8288
8545
|
duplicate(newName) {
|
|
8289
|
-
const dest = new TextLine(
|
|
8546
|
+
const dest = new TextLine({
|
|
8547
|
+
...this.getEntityOptions(),
|
|
8548
|
+
...this.getDrawableOptions(),
|
|
8549
|
+
...this.getTextOptions(),
|
|
8290
8550
|
width: this.size.width,
|
|
8291
8551
|
name: newName
|
|
8292
|
-
})
|
|
8552
|
+
});
|
|
8293
8553
|
if (this.children.length > 0) {
|
|
8294
8554
|
dest.children = this.children.map((child) => {
|
|
8295
8555
|
const clonedChild = child.duplicate();
|
|
@@ -8304,6 +8564,7 @@ class TextLine extends Entity {
|
|
|
8304
8564
|
canvas.save();
|
|
8305
8565
|
const drawScale = Globals.canvasScale / this.absoluteScale;
|
|
8306
8566
|
canvas.scale(1 / drawScale, 1 / drawScale);
|
|
8567
|
+
M2c2KitHelpers.rotateCanvasForDrawableEntity(canvas, this);
|
|
8307
8568
|
const x = this.absolutePosition.x * drawScale;
|
|
8308
8569
|
const y = (this.absolutePosition.y + this.size.height * this.anchorPoint.y * this.absoluteScale) * drawScale;
|
|
8309
8570
|
let textForDraw;
|
|
@@ -8341,6 +8602,9 @@ class TextLine extends Entity {
|
|
|
8341
8602
|
`in TextLine entity ${this}, Paint or Font is undefined.`
|
|
8342
8603
|
);
|
|
8343
8604
|
}
|
|
8605
|
+
if (this.absoluteAlphaChange !== 0) {
|
|
8606
|
+
paintForDraw.setAlphaf(this.absoluteAlpha);
|
|
8607
|
+
}
|
|
8344
8608
|
canvas.drawText(textForDraw, x, y, paintForDraw, this.font);
|
|
8345
8609
|
canvas.restore();
|
|
8346
8610
|
}
|
|
@@ -8357,5 +8621,5 @@ class TextLine extends Entity {
|
|
|
8357
8621
|
}
|
|
8358
8622
|
}
|
|
8359
8623
|
|
|
8360
|
-
export { Action, ActivityType, CanvasKitHelpers, Composite, Constants, ConstraintType, CustomAction, Dimensions, Easings, Entity, EntityType, Equals, EventType, FontManager, Game, GlobalVariables, GroupAction, I18n, ImageManager, Label, LabelHorizontalAlignmentMode, LayoutConstraint, LoadedImage, MoveAction, MutablePath, NoneTransition, RandomDraws, ScaleAction, Scene, SceneTransition, SequenceAction, Session, Shape, ShapeType, SlideTransition, Sprite, Story, TextLine, Timer, Transition, TransitionDirection, TransitionType, Uuid, WaitAction, WebColors, WebGlInfo, handleInterfaceOptions };
|
|
8624
|
+
export { Action, ActivityType, CanvasKitHelpers, ColorfulMutablePath, Composite, Constants, ConstraintType, CustomAction, Dimensions, Easings, Entity, EntityType, Equals, EventType, FadeAlphaAction, FontManager, Game, GlobalVariables, GroupAction, I18n, ImageManager, Label, LabelHorizontalAlignmentMode, LayoutConstraint, LoadedImage, MoveAction, MutablePath, NoneTransition, RandomDraws, RotateAction, ScaleAction, Scene, SceneTransition, SequenceAction, Session, Shape, ShapeType, SlideTransition, Sprite, Story, TextLine, Timer, Transition, TransitionDirection, TransitionType, Uuid, WaitAction, WebColors, WebGlInfo, handleInterfaceOptions };
|
|
8361
8625
|
//# sourceMappingURL=index.js.map
|