microboard-temp 0.4.24 → 0.4.26
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/cjs/browser.js +76 -25
- package/dist/cjs/index.js +76 -25
- package/dist/cjs/node.js +76 -25
- package/dist/esm/browser.js +76 -25
- package/dist/esm/index.js +76 -25
- package/dist/esm/node.js +76 -25
- package/dist/types/Items/Examples/CardGame/Dice/Dice.d.ts +10 -11
- package/dist/types/Items/Examples/CardGame/Dice/DiceOperation.d.ts +7 -8
- package/package.json +1 -1
package/dist/cjs/browser.js
CHANGED
|
@@ -46227,27 +46227,37 @@ class AddDice extends ShapeTool {
|
|
|
46227
46227
|
var TIMEOUT = 2000;
|
|
46228
46228
|
var defaultDiceData = {
|
|
46229
46229
|
itemType: "Dice",
|
|
46230
|
+
type: "common",
|
|
46230
46231
|
backgroundColor: "#FFFFFF",
|
|
46231
46232
|
backgroundOpacity: 1,
|
|
46232
46233
|
borderColor: "#000207",
|
|
46233
46234
|
borderOpacity: 1,
|
|
46234
46235
|
borderStyle: "solid",
|
|
46235
46236
|
borderWidth: 1,
|
|
46236
|
-
|
|
46237
|
-
|
|
46237
|
+
valueIndex: 0,
|
|
46238
|
+
values: [1, 2, 3, 4, 5, 6]
|
|
46238
46239
|
};
|
|
46239
46240
|
|
|
46240
46241
|
class Dice extends BaseItem {
|
|
46241
46242
|
itemType = "Dice";
|
|
46243
|
+
type = "common";
|
|
46242
46244
|
path;
|
|
46243
46245
|
subject = new Subject;
|
|
46244
46246
|
borderWidth = 1;
|
|
46245
|
-
|
|
46246
|
-
|
|
46247
|
+
valueIndex = 0;
|
|
46248
|
+
values = [];
|
|
46249
|
+
renderValues = {};
|
|
46247
46250
|
animationFrameId;
|
|
46248
46251
|
drawingContext = null;
|
|
46249
|
-
constructor(board, id = "") {
|
|
46252
|
+
constructor(board, id = "", type, values2) {
|
|
46250
46253
|
super(board, id, defaultDiceData);
|
|
46254
|
+
if (type) {
|
|
46255
|
+
this.type = type;
|
|
46256
|
+
}
|
|
46257
|
+
if (values2) {
|
|
46258
|
+
this.values = values2;
|
|
46259
|
+
}
|
|
46260
|
+
this.createRenderValues();
|
|
46251
46261
|
this.transformPath();
|
|
46252
46262
|
this.transformation.subject.subscribe(() => {
|
|
46253
46263
|
this.transformPath();
|
|
@@ -46263,6 +46273,24 @@ class Dice extends BaseItem {
|
|
|
46263
46273
|
this.path.setBorderColor(this.borderColor);
|
|
46264
46274
|
this.path.setBorderWidth(this.borderWidth);
|
|
46265
46275
|
}
|
|
46276
|
+
createRenderValues() {
|
|
46277
|
+
this.values.forEach((value, index2) => {
|
|
46278
|
+
if (typeof value === "number") {
|
|
46279
|
+
this.renderValues[index2] = value;
|
|
46280
|
+
} else {
|
|
46281
|
+
const image2 = conf.documentFactory.createElement("img");
|
|
46282
|
+
image2.src = value;
|
|
46283
|
+
this.renderValues[index2] = image2;
|
|
46284
|
+
image2.onload = () => {
|
|
46285
|
+
this.subject.publish(this);
|
|
46286
|
+
};
|
|
46287
|
+
image2.onerror = () => {
|
|
46288
|
+
this.renderValues[index2] = 1;
|
|
46289
|
+
this.subject.publish(this);
|
|
46290
|
+
};
|
|
46291
|
+
}
|
|
46292
|
+
});
|
|
46293
|
+
}
|
|
46266
46294
|
render(context) {
|
|
46267
46295
|
this.drawingContext = context;
|
|
46268
46296
|
if (this.transformationRenderBlock) {
|
|
@@ -46283,11 +46311,25 @@ class Dice extends BaseItem {
|
|
|
46283
46311
|
const mbr = this.getMbr();
|
|
46284
46312
|
const centerX = (mbr.left + mbr.right) / 2;
|
|
46285
46313
|
const centerY = (mbr.top + mbr.bottom) / 2;
|
|
46286
|
-
|
|
46287
|
-
|
|
46288
|
-
|
|
46289
|
-
|
|
46290
|
-
|
|
46314
|
+
const valueToRender = this.renderValues[this.valueIndex];
|
|
46315
|
+
if (typeof valueToRender === "number") {
|
|
46316
|
+
context.ctx.fillStyle = "black";
|
|
46317
|
+
context.ctx.font = `bold ${this.getHeight() / 3}px sans-serif`;
|
|
46318
|
+
context.ctx.textAlign = "center";
|
|
46319
|
+
context.ctx.textBaseline = "middle";
|
|
46320
|
+
context.ctx.fillText(String(valueToRender), centerX, centerY);
|
|
46321
|
+
} else if (valueToRender instanceof HTMLImageElement) {
|
|
46322
|
+
const size = this.getHeight() / 3;
|
|
46323
|
+
if (valueToRender.complete && valueToRender.naturalWidth > 0) {
|
|
46324
|
+
context.ctx.drawImage(valueToRender, centerX - size / 2, centerY - size / 2, size, size);
|
|
46325
|
+
} else {
|
|
46326
|
+
context.ctx.fillStyle = "black";
|
|
46327
|
+
context.ctx.font = `bold ${size}px sans-serif`;
|
|
46328
|
+
context.ctx.textAlign = "center";
|
|
46329
|
+
context.ctx.textBaseline = "middle";
|
|
46330
|
+
context.ctx.fillText("?", centerX, centerY);
|
|
46331
|
+
}
|
|
46332
|
+
}
|
|
46291
46333
|
context.ctx.restore();
|
|
46292
46334
|
}
|
|
46293
46335
|
updateMbr() {
|
|
@@ -46313,8 +46355,14 @@ class Dice extends BaseItem {
|
|
|
46313
46355
|
getIsRotating() {
|
|
46314
46356
|
return !!this.animationFrameId;
|
|
46315
46357
|
}
|
|
46358
|
+
getType() {
|
|
46359
|
+
return this.type;
|
|
46360
|
+
}
|
|
46316
46361
|
getRange() {
|
|
46317
|
-
|
|
46362
|
+
if (this.type === "custom") {
|
|
46363
|
+
return { min: 1, max: this.values.length };
|
|
46364
|
+
}
|
|
46365
|
+
return { min: this.values[0], max: this.values[this.values.length - 1] };
|
|
46318
46366
|
}
|
|
46319
46367
|
applyBackgroundColor(backgroundColor) {
|
|
46320
46368
|
this.backgroundColor = backgroundColor;
|
|
@@ -46355,26 +46403,26 @@ class Dice extends BaseItem {
|
|
|
46355
46403
|
prevData: { borderColor: this.borderColor }
|
|
46356
46404
|
});
|
|
46357
46405
|
}
|
|
46358
|
-
|
|
46406
|
+
setValues(values2) {
|
|
46359
46407
|
this.emit({
|
|
46360
46408
|
class: "Dice",
|
|
46361
|
-
method: "
|
|
46409
|
+
method: "changeValues",
|
|
46362
46410
|
item: [this.getId()],
|
|
46363
|
-
newData:
|
|
46364
|
-
prevData: this.
|
|
46411
|
+
newData: { values: values2 },
|
|
46412
|
+
prevData: { values: this.values }
|
|
46365
46413
|
});
|
|
46366
46414
|
}
|
|
46367
|
-
|
|
46415
|
+
setValueIndex(valueIndex) {
|
|
46368
46416
|
this.emit({
|
|
46369
46417
|
class: "Dice",
|
|
46370
|
-
method: "
|
|
46418
|
+
method: "changeValueIndex",
|
|
46371
46419
|
item: [this.getId()],
|
|
46372
|
-
newData: {
|
|
46373
|
-
prevData: { value: this.
|
|
46420
|
+
newData: { valueIndex, shouldRotate: true, timeStamp: Date.now() },
|
|
46421
|
+
prevData: { value: this.valueIndex, shouldRotate: false }
|
|
46374
46422
|
});
|
|
46375
46423
|
}
|
|
46376
46424
|
throwDice() {
|
|
46377
|
-
this.
|
|
46425
|
+
this.setValueIndex(Math.floor(Math.random() * this.values.length));
|
|
46378
46426
|
}
|
|
46379
46427
|
apply(op) {
|
|
46380
46428
|
super.apply(op);
|
|
@@ -46390,19 +46438,22 @@ class Dice extends BaseItem {
|
|
|
46390
46438
|
case "setBorderColor":
|
|
46391
46439
|
this.applyBorderColor(op.newData.borderColor);
|
|
46392
46440
|
break;
|
|
46393
|
-
case "
|
|
46441
|
+
case "changeValueIndex":
|
|
46394
46442
|
if (op.newData.shouldRotate && op.newData.timeStamp && Date.now() - op.newData.timeStamp < 1e4) {
|
|
46395
46443
|
this.startRotation();
|
|
46396
46444
|
setTimeout(() => {
|
|
46397
46445
|
this.stopRotation();
|
|
46398
|
-
this.
|
|
46446
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46399
46447
|
}, TIMEOUT);
|
|
46400
46448
|
} else {
|
|
46401
|
-
this.
|
|
46449
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46402
46450
|
}
|
|
46403
46451
|
break;
|
|
46404
|
-
case "
|
|
46405
|
-
|
|
46452
|
+
case "changeValues":
|
|
46453
|
+
if (!op.newData.values[this.valueIndex]) {
|
|
46454
|
+
this.valueIndex = 0;
|
|
46455
|
+
}
|
|
46456
|
+
this.values = op.newData.values;
|
|
46406
46457
|
break;
|
|
46407
46458
|
}
|
|
46408
46459
|
break;
|
package/dist/cjs/index.js
CHANGED
|
@@ -46227,27 +46227,37 @@ class AddDice extends ShapeTool {
|
|
|
46227
46227
|
var TIMEOUT = 2000;
|
|
46228
46228
|
var defaultDiceData = {
|
|
46229
46229
|
itemType: "Dice",
|
|
46230
|
+
type: "common",
|
|
46230
46231
|
backgroundColor: "#FFFFFF",
|
|
46231
46232
|
backgroundOpacity: 1,
|
|
46232
46233
|
borderColor: "#000207",
|
|
46233
46234
|
borderOpacity: 1,
|
|
46234
46235
|
borderStyle: "solid",
|
|
46235
46236
|
borderWidth: 1,
|
|
46236
|
-
|
|
46237
|
-
|
|
46237
|
+
valueIndex: 0,
|
|
46238
|
+
values: [1, 2, 3, 4, 5, 6]
|
|
46238
46239
|
};
|
|
46239
46240
|
|
|
46240
46241
|
class Dice extends BaseItem {
|
|
46241
46242
|
itemType = "Dice";
|
|
46243
|
+
type = "common";
|
|
46242
46244
|
path;
|
|
46243
46245
|
subject = new Subject;
|
|
46244
46246
|
borderWidth = 1;
|
|
46245
|
-
|
|
46246
|
-
|
|
46247
|
+
valueIndex = 0;
|
|
46248
|
+
values = [];
|
|
46249
|
+
renderValues = {};
|
|
46247
46250
|
animationFrameId;
|
|
46248
46251
|
drawingContext = null;
|
|
46249
|
-
constructor(board, id = "") {
|
|
46252
|
+
constructor(board, id = "", type, values2) {
|
|
46250
46253
|
super(board, id, defaultDiceData);
|
|
46254
|
+
if (type) {
|
|
46255
|
+
this.type = type;
|
|
46256
|
+
}
|
|
46257
|
+
if (values2) {
|
|
46258
|
+
this.values = values2;
|
|
46259
|
+
}
|
|
46260
|
+
this.createRenderValues();
|
|
46251
46261
|
this.transformPath();
|
|
46252
46262
|
this.transformation.subject.subscribe(() => {
|
|
46253
46263
|
this.transformPath();
|
|
@@ -46263,6 +46273,24 @@ class Dice extends BaseItem {
|
|
|
46263
46273
|
this.path.setBorderColor(this.borderColor);
|
|
46264
46274
|
this.path.setBorderWidth(this.borderWidth);
|
|
46265
46275
|
}
|
|
46276
|
+
createRenderValues() {
|
|
46277
|
+
this.values.forEach((value, index2) => {
|
|
46278
|
+
if (typeof value === "number") {
|
|
46279
|
+
this.renderValues[index2] = value;
|
|
46280
|
+
} else {
|
|
46281
|
+
const image2 = conf.documentFactory.createElement("img");
|
|
46282
|
+
image2.src = value;
|
|
46283
|
+
this.renderValues[index2] = image2;
|
|
46284
|
+
image2.onload = () => {
|
|
46285
|
+
this.subject.publish(this);
|
|
46286
|
+
};
|
|
46287
|
+
image2.onerror = () => {
|
|
46288
|
+
this.renderValues[index2] = 1;
|
|
46289
|
+
this.subject.publish(this);
|
|
46290
|
+
};
|
|
46291
|
+
}
|
|
46292
|
+
});
|
|
46293
|
+
}
|
|
46266
46294
|
render(context) {
|
|
46267
46295
|
this.drawingContext = context;
|
|
46268
46296
|
if (this.transformationRenderBlock) {
|
|
@@ -46283,11 +46311,25 @@ class Dice extends BaseItem {
|
|
|
46283
46311
|
const mbr = this.getMbr();
|
|
46284
46312
|
const centerX = (mbr.left + mbr.right) / 2;
|
|
46285
46313
|
const centerY = (mbr.top + mbr.bottom) / 2;
|
|
46286
|
-
|
|
46287
|
-
|
|
46288
|
-
|
|
46289
|
-
|
|
46290
|
-
|
|
46314
|
+
const valueToRender = this.renderValues[this.valueIndex];
|
|
46315
|
+
if (typeof valueToRender === "number") {
|
|
46316
|
+
context.ctx.fillStyle = "black";
|
|
46317
|
+
context.ctx.font = `bold ${this.getHeight() / 3}px sans-serif`;
|
|
46318
|
+
context.ctx.textAlign = "center";
|
|
46319
|
+
context.ctx.textBaseline = "middle";
|
|
46320
|
+
context.ctx.fillText(String(valueToRender), centerX, centerY);
|
|
46321
|
+
} else if (valueToRender instanceof HTMLImageElement) {
|
|
46322
|
+
const size = this.getHeight() / 3;
|
|
46323
|
+
if (valueToRender.complete && valueToRender.naturalWidth > 0) {
|
|
46324
|
+
context.ctx.drawImage(valueToRender, centerX - size / 2, centerY - size / 2, size, size);
|
|
46325
|
+
} else {
|
|
46326
|
+
context.ctx.fillStyle = "black";
|
|
46327
|
+
context.ctx.font = `bold ${size}px sans-serif`;
|
|
46328
|
+
context.ctx.textAlign = "center";
|
|
46329
|
+
context.ctx.textBaseline = "middle";
|
|
46330
|
+
context.ctx.fillText("?", centerX, centerY);
|
|
46331
|
+
}
|
|
46332
|
+
}
|
|
46291
46333
|
context.ctx.restore();
|
|
46292
46334
|
}
|
|
46293
46335
|
updateMbr() {
|
|
@@ -46313,8 +46355,14 @@ class Dice extends BaseItem {
|
|
|
46313
46355
|
getIsRotating() {
|
|
46314
46356
|
return !!this.animationFrameId;
|
|
46315
46357
|
}
|
|
46358
|
+
getType() {
|
|
46359
|
+
return this.type;
|
|
46360
|
+
}
|
|
46316
46361
|
getRange() {
|
|
46317
|
-
|
|
46362
|
+
if (this.type === "custom") {
|
|
46363
|
+
return { min: 1, max: this.values.length };
|
|
46364
|
+
}
|
|
46365
|
+
return { min: this.values[0], max: this.values[this.values.length - 1] };
|
|
46318
46366
|
}
|
|
46319
46367
|
applyBackgroundColor(backgroundColor) {
|
|
46320
46368
|
this.backgroundColor = backgroundColor;
|
|
@@ -46355,26 +46403,26 @@ class Dice extends BaseItem {
|
|
|
46355
46403
|
prevData: { borderColor: this.borderColor }
|
|
46356
46404
|
});
|
|
46357
46405
|
}
|
|
46358
|
-
|
|
46406
|
+
setValues(values2) {
|
|
46359
46407
|
this.emit({
|
|
46360
46408
|
class: "Dice",
|
|
46361
|
-
method: "
|
|
46409
|
+
method: "changeValues",
|
|
46362
46410
|
item: [this.getId()],
|
|
46363
|
-
newData:
|
|
46364
|
-
prevData: this.
|
|
46411
|
+
newData: { values: values2 },
|
|
46412
|
+
prevData: { values: this.values }
|
|
46365
46413
|
});
|
|
46366
46414
|
}
|
|
46367
|
-
|
|
46415
|
+
setValueIndex(valueIndex) {
|
|
46368
46416
|
this.emit({
|
|
46369
46417
|
class: "Dice",
|
|
46370
|
-
method: "
|
|
46418
|
+
method: "changeValueIndex",
|
|
46371
46419
|
item: [this.getId()],
|
|
46372
|
-
newData: {
|
|
46373
|
-
prevData: { value: this.
|
|
46420
|
+
newData: { valueIndex, shouldRotate: true, timeStamp: Date.now() },
|
|
46421
|
+
prevData: { value: this.valueIndex, shouldRotate: false }
|
|
46374
46422
|
});
|
|
46375
46423
|
}
|
|
46376
46424
|
throwDice() {
|
|
46377
|
-
this.
|
|
46425
|
+
this.setValueIndex(Math.floor(Math.random() * this.values.length));
|
|
46378
46426
|
}
|
|
46379
46427
|
apply(op) {
|
|
46380
46428
|
super.apply(op);
|
|
@@ -46390,19 +46438,22 @@ class Dice extends BaseItem {
|
|
|
46390
46438
|
case "setBorderColor":
|
|
46391
46439
|
this.applyBorderColor(op.newData.borderColor);
|
|
46392
46440
|
break;
|
|
46393
|
-
case "
|
|
46441
|
+
case "changeValueIndex":
|
|
46394
46442
|
if (op.newData.shouldRotate && op.newData.timeStamp && Date.now() - op.newData.timeStamp < 1e4) {
|
|
46395
46443
|
this.startRotation();
|
|
46396
46444
|
setTimeout(() => {
|
|
46397
46445
|
this.stopRotation();
|
|
46398
|
-
this.
|
|
46446
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46399
46447
|
}, TIMEOUT);
|
|
46400
46448
|
} else {
|
|
46401
|
-
this.
|
|
46449
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46402
46450
|
}
|
|
46403
46451
|
break;
|
|
46404
|
-
case "
|
|
46405
|
-
|
|
46452
|
+
case "changeValues":
|
|
46453
|
+
if (!op.newData.values[this.valueIndex]) {
|
|
46454
|
+
this.valueIndex = 0;
|
|
46455
|
+
}
|
|
46456
|
+
this.values = op.newData.values;
|
|
46406
46457
|
break;
|
|
46407
46458
|
}
|
|
46408
46459
|
break;
|
package/dist/cjs/node.js
CHANGED
|
@@ -48767,27 +48767,37 @@ class AddDice extends ShapeTool {
|
|
|
48767
48767
|
var TIMEOUT = 2000;
|
|
48768
48768
|
var defaultDiceData = {
|
|
48769
48769
|
itemType: "Dice",
|
|
48770
|
+
type: "common",
|
|
48770
48771
|
backgroundColor: "#FFFFFF",
|
|
48771
48772
|
backgroundOpacity: 1,
|
|
48772
48773
|
borderColor: "#000207",
|
|
48773
48774
|
borderOpacity: 1,
|
|
48774
48775
|
borderStyle: "solid",
|
|
48775
48776
|
borderWidth: 1,
|
|
48776
|
-
|
|
48777
|
-
|
|
48777
|
+
valueIndex: 0,
|
|
48778
|
+
values: [1, 2, 3, 4, 5, 6]
|
|
48778
48779
|
};
|
|
48779
48780
|
|
|
48780
48781
|
class Dice extends BaseItem {
|
|
48781
48782
|
itemType = "Dice";
|
|
48783
|
+
type = "common";
|
|
48782
48784
|
path;
|
|
48783
48785
|
subject = new Subject;
|
|
48784
48786
|
borderWidth = 1;
|
|
48785
|
-
|
|
48786
|
-
|
|
48787
|
+
valueIndex = 0;
|
|
48788
|
+
values = [];
|
|
48789
|
+
renderValues = {};
|
|
48787
48790
|
animationFrameId;
|
|
48788
48791
|
drawingContext = null;
|
|
48789
|
-
constructor(board, id = "") {
|
|
48792
|
+
constructor(board, id = "", type, values2) {
|
|
48790
48793
|
super(board, id, defaultDiceData);
|
|
48794
|
+
if (type) {
|
|
48795
|
+
this.type = type;
|
|
48796
|
+
}
|
|
48797
|
+
if (values2) {
|
|
48798
|
+
this.values = values2;
|
|
48799
|
+
}
|
|
48800
|
+
this.createRenderValues();
|
|
48791
48801
|
this.transformPath();
|
|
48792
48802
|
this.transformation.subject.subscribe(() => {
|
|
48793
48803
|
this.transformPath();
|
|
@@ -48803,6 +48813,24 @@ class Dice extends BaseItem {
|
|
|
48803
48813
|
this.path.setBorderColor(this.borderColor);
|
|
48804
48814
|
this.path.setBorderWidth(this.borderWidth);
|
|
48805
48815
|
}
|
|
48816
|
+
createRenderValues() {
|
|
48817
|
+
this.values.forEach((value, index2) => {
|
|
48818
|
+
if (typeof value === "number") {
|
|
48819
|
+
this.renderValues[index2] = value;
|
|
48820
|
+
} else {
|
|
48821
|
+
const image2 = conf.documentFactory.createElement("img");
|
|
48822
|
+
image2.src = value;
|
|
48823
|
+
this.renderValues[index2] = image2;
|
|
48824
|
+
image2.onload = () => {
|
|
48825
|
+
this.subject.publish(this);
|
|
48826
|
+
};
|
|
48827
|
+
image2.onerror = () => {
|
|
48828
|
+
this.renderValues[index2] = 1;
|
|
48829
|
+
this.subject.publish(this);
|
|
48830
|
+
};
|
|
48831
|
+
}
|
|
48832
|
+
});
|
|
48833
|
+
}
|
|
48806
48834
|
render(context) {
|
|
48807
48835
|
this.drawingContext = context;
|
|
48808
48836
|
if (this.transformationRenderBlock) {
|
|
@@ -48823,11 +48851,25 @@ class Dice extends BaseItem {
|
|
|
48823
48851
|
const mbr = this.getMbr();
|
|
48824
48852
|
const centerX = (mbr.left + mbr.right) / 2;
|
|
48825
48853
|
const centerY = (mbr.top + mbr.bottom) / 2;
|
|
48826
|
-
|
|
48827
|
-
|
|
48828
|
-
|
|
48829
|
-
|
|
48830
|
-
|
|
48854
|
+
const valueToRender = this.renderValues[this.valueIndex];
|
|
48855
|
+
if (typeof valueToRender === "number") {
|
|
48856
|
+
context.ctx.fillStyle = "black";
|
|
48857
|
+
context.ctx.font = `bold ${this.getHeight() / 3}px sans-serif`;
|
|
48858
|
+
context.ctx.textAlign = "center";
|
|
48859
|
+
context.ctx.textBaseline = "middle";
|
|
48860
|
+
context.ctx.fillText(String(valueToRender), centerX, centerY);
|
|
48861
|
+
} else if (valueToRender instanceof HTMLImageElement) {
|
|
48862
|
+
const size = this.getHeight() / 3;
|
|
48863
|
+
if (valueToRender.complete && valueToRender.naturalWidth > 0) {
|
|
48864
|
+
context.ctx.drawImage(valueToRender, centerX - size / 2, centerY - size / 2, size, size);
|
|
48865
|
+
} else {
|
|
48866
|
+
context.ctx.fillStyle = "black";
|
|
48867
|
+
context.ctx.font = `bold ${size}px sans-serif`;
|
|
48868
|
+
context.ctx.textAlign = "center";
|
|
48869
|
+
context.ctx.textBaseline = "middle";
|
|
48870
|
+
context.ctx.fillText("?", centerX, centerY);
|
|
48871
|
+
}
|
|
48872
|
+
}
|
|
48831
48873
|
context.ctx.restore();
|
|
48832
48874
|
}
|
|
48833
48875
|
updateMbr() {
|
|
@@ -48853,8 +48895,14 @@ class Dice extends BaseItem {
|
|
|
48853
48895
|
getIsRotating() {
|
|
48854
48896
|
return !!this.animationFrameId;
|
|
48855
48897
|
}
|
|
48898
|
+
getType() {
|
|
48899
|
+
return this.type;
|
|
48900
|
+
}
|
|
48856
48901
|
getRange() {
|
|
48857
|
-
|
|
48902
|
+
if (this.type === "custom") {
|
|
48903
|
+
return { min: 1, max: this.values.length };
|
|
48904
|
+
}
|
|
48905
|
+
return { min: this.values[0], max: this.values[this.values.length - 1] };
|
|
48858
48906
|
}
|
|
48859
48907
|
applyBackgroundColor(backgroundColor) {
|
|
48860
48908
|
this.backgroundColor = backgroundColor;
|
|
@@ -48895,26 +48943,26 @@ class Dice extends BaseItem {
|
|
|
48895
48943
|
prevData: { borderColor: this.borderColor }
|
|
48896
48944
|
});
|
|
48897
48945
|
}
|
|
48898
|
-
|
|
48946
|
+
setValues(values2) {
|
|
48899
48947
|
this.emit({
|
|
48900
48948
|
class: "Dice",
|
|
48901
|
-
method: "
|
|
48949
|
+
method: "changeValues",
|
|
48902
48950
|
item: [this.getId()],
|
|
48903
|
-
newData:
|
|
48904
|
-
prevData: this.
|
|
48951
|
+
newData: { values: values2 },
|
|
48952
|
+
prevData: { values: this.values }
|
|
48905
48953
|
});
|
|
48906
48954
|
}
|
|
48907
|
-
|
|
48955
|
+
setValueIndex(valueIndex) {
|
|
48908
48956
|
this.emit({
|
|
48909
48957
|
class: "Dice",
|
|
48910
|
-
method: "
|
|
48958
|
+
method: "changeValueIndex",
|
|
48911
48959
|
item: [this.getId()],
|
|
48912
|
-
newData: {
|
|
48913
|
-
prevData: { value: this.
|
|
48960
|
+
newData: { valueIndex, shouldRotate: true, timeStamp: Date.now() },
|
|
48961
|
+
prevData: { value: this.valueIndex, shouldRotate: false }
|
|
48914
48962
|
});
|
|
48915
48963
|
}
|
|
48916
48964
|
throwDice() {
|
|
48917
|
-
this.
|
|
48965
|
+
this.setValueIndex(Math.floor(Math.random() * this.values.length));
|
|
48918
48966
|
}
|
|
48919
48967
|
apply(op) {
|
|
48920
48968
|
super.apply(op);
|
|
@@ -48930,19 +48978,22 @@ class Dice extends BaseItem {
|
|
|
48930
48978
|
case "setBorderColor":
|
|
48931
48979
|
this.applyBorderColor(op.newData.borderColor);
|
|
48932
48980
|
break;
|
|
48933
|
-
case "
|
|
48981
|
+
case "changeValueIndex":
|
|
48934
48982
|
if (op.newData.shouldRotate && op.newData.timeStamp && Date.now() - op.newData.timeStamp < 1e4) {
|
|
48935
48983
|
this.startRotation();
|
|
48936
48984
|
setTimeout(() => {
|
|
48937
48985
|
this.stopRotation();
|
|
48938
|
-
this.
|
|
48986
|
+
this.valueIndex = op.newData.valueIndex;
|
|
48939
48987
|
}, TIMEOUT);
|
|
48940
48988
|
} else {
|
|
48941
|
-
this.
|
|
48989
|
+
this.valueIndex = op.newData.valueIndex;
|
|
48942
48990
|
}
|
|
48943
48991
|
break;
|
|
48944
|
-
case "
|
|
48945
|
-
|
|
48992
|
+
case "changeValues":
|
|
48993
|
+
if (!op.newData.values[this.valueIndex]) {
|
|
48994
|
+
this.valueIndex = 0;
|
|
48995
|
+
}
|
|
48996
|
+
this.values = op.newData.values;
|
|
48946
48997
|
break;
|
|
48947
48998
|
}
|
|
48948
48999
|
break;
|
package/dist/esm/browser.js
CHANGED
|
@@ -46077,27 +46077,37 @@ class AddDice extends ShapeTool {
|
|
|
46077
46077
|
var TIMEOUT = 2000;
|
|
46078
46078
|
var defaultDiceData = {
|
|
46079
46079
|
itemType: "Dice",
|
|
46080
|
+
type: "common",
|
|
46080
46081
|
backgroundColor: "#FFFFFF",
|
|
46081
46082
|
backgroundOpacity: 1,
|
|
46082
46083
|
borderColor: "#000207",
|
|
46083
46084
|
borderOpacity: 1,
|
|
46084
46085
|
borderStyle: "solid",
|
|
46085
46086
|
borderWidth: 1,
|
|
46086
|
-
|
|
46087
|
-
|
|
46087
|
+
valueIndex: 0,
|
|
46088
|
+
values: [1, 2, 3, 4, 5, 6]
|
|
46088
46089
|
};
|
|
46089
46090
|
|
|
46090
46091
|
class Dice extends BaseItem {
|
|
46091
46092
|
itemType = "Dice";
|
|
46093
|
+
type = "common";
|
|
46092
46094
|
path;
|
|
46093
46095
|
subject = new Subject;
|
|
46094
46096
|
borderWidth = 1;
|
|
46095
|
-
|
|
46096
|
-
|
|
46097
|
+
valueIndex = 0;
|
|
46098
|
+
values = [];
|
|
46099
|
+
renderValues = {};
|
|
46097
46100
|
animationFrameId;
|
|
46098
46101
|
drawingContext = null;
|
|
46099
|
-
constructor(board, id = "") {
|
|
46102
|
+
constructor(board, id = "", type, values2) {
|
|
46100
46103
|
super(board, id, defaultDiceData);
|
|
46104
|
+
if (type) {
|
|
46105
|
+
this.type = type;
|
|
46106
|
+
}
|
|
46107
|
+
if (values2) {
|
|
46108
|
+
this.values = values2;
|
|
46109
|
+
}
|
|
46110
|
+
this.createRenderValues();
|
|
46101
46111
|
this.transformPath();
|
|
46102
46112
|
this.transformation.subject.subscribe(() => {
|
|
46103
46113
|
this.transformPath();
|
|
@@ -46113,6 +46123,24 @@ class Dice extends BaseItem {
|
|
|
46113
46123
|
this.path.setBorderColor(this.borderColor);
|
|
46114
46124
|
this.path.setBorderWidth(this.borderWidth);
|
|
46115
46125
|
}
|
|
46126
|
+
createRenderValues() {
|
|
46127
|
+
this.values.forEach((value, index2) => {
|
|
46128
|
+
if (typeof value === "number") {
|
|
46129
|
+
this.renderValues[index2] = value;
|
|
46130
|
+
} else {
|
|
46131
|
+
const image2 = conf.documentFactory.createElement("img");
|
|
46132
|
+
image2.src = value;
|
|
46133
|
+
this.renderValues[index2] = image2;
|
|
46134
|
+
image2.onload = () => {
|
|
46135
|
+
this.subject.publish(this);
|
|
46136
|
+
};
|
|
46137
|
+
image2.onerror = () => {
|
|
46138
|
+
this.renderValues[index2] = 1;
|
|
46139
|
+
this.subject.publish(this);
|
|
46140
|
+
};
|
|
46141
|
+
}
|
|
46142
|
+
});
|
|
46143
|
+
}
|
|
46116
46144
|
render(context) {
|
|
46117
46145
|
this.drawingContext = context;
|
|
46118
46146
|
if (this.transformationRenderBlock) {
|
|
@@ -46133,11 +46161,25 @@ class Dice extends BaseItem {
|
|
|
46133
46161
|
const mbr = this.getMbr();
|
|
46134
46162
|
const centerX = (mbr.left + mbr.right) / 2;
|
|
46135
46163
|
const centerY = (mbr.top + mbr.bottom) / 2;
|
|
46136
|
-
|
|
46137
|
-
|
|
46138
|
-
|
|
46139
|
-
|
|
46140
|
-
|
|
46164
|
+
const valueToRender = this.renderValues[this.valueIndex];
|
|
46165
|
+
if (typeof valueToRender === "number") {
|
|
46166
|
+
context.ctx.fillStyle = "black";
|
|
46167
|
+
context.ctx.font = `bold ${this.getHeight() / 3}px sans-serif`;
|
|
46168
|
+
context.ctx.textAlign = "center";
|
|
46169
|
+
context.ctx.textBaseline = "middle";
|
|
46170
|
+
context.ctx.fillText(String(valueToRender), centerX, centerY);
|
|
46171
|
+
} else if (valueToRender instanceof HTMLImageElement) {
|
|
46172
|
+
const size = this.getHeight() / 3;
|
|
46173
|
+
if (valueToRender.complete && valueToRender.naturalWidth > 0) {
|
|
46174
|
+
context.ctx.drawImage(valueToRender, centerX - size / 2, centerY - size / 2, size, size);
|
|
46175
|
+
} else {
|
|
46176
|
+
context.ctx.fillStyle = "black";
|
|
46177
|
+
context.ctx.font = `bold ${size}px sans-serif`;
|
|
46178
|
+
context.ctx.textAlign = "center";
|
|
46179
|
+
context.ctx.textBaseline = "middle";
|
|
46180
|
+
context.ctx.fillText("?", centerX, centerY);
|
|
46181
|
+
}
|
|
46182
|
+
}
|
|
46141
46183
|
context.ctx.restore();
|
|
46142
46184
|
}
|
|
46143
46185
|
updateMbr() {
|
|
@@ -46163,8 +46205,14 @@ class Dice extends BaseItem {
|
|
|
46163
46205
|
getIsRotating() {
|
|
46164
46206
|
return !!this.animationFrameId;
|
|
46165
46207
|
}
|
|
46208
|
+
getType() {
|
|
46209
|
+
return this.type;
|
|
46210
|
+
}
|
|
46166
46211
|
getRange() {
|
|
46167
|
-
|
|
46212
|
+
if (this.type === "custom") {
|
|
46213
|
+
return { min: 1, max: this.values.length };
|
|
46214
|
+
}
|
|
46215
|
+
return { min: this.values[0], max: this.values[this.values.length - 1] };
|
|
46168
46216
|
}
|
|
46169
46217
|
applyBackgroundColor(backgroundColor) {
|
|
46170
46218
|
this.backgroundColor = backgroundColor;
|
|
@@ -46205,26 +46253,26 @@ class Dice extends BaseItem {
|
|
|
46205
46253
|
prevData: { borderColor: this.borderColor }
|
|
46206
46254
|
});
|
|
46207
46255
|
}
|
|
46208
|
-
|
|
46256
|
+
setValues(values2) {
|
|
46209
46257
|
this.emit({
|
|
46210
46258
|
class: "Dice",
|
|
46211
|
-
method: "
|
|
46259
|
+
method: "changeValues",
|
|
46212
46260
|
item: [this.getId()],
|
|
46213
|
-
newData:
|
|
46214
|
-
prevData: this.
|
|
46261
|
+
newData: { values: values2 },
|
|
46262
|
+
prevData: { values: this.values }
|
|
46215
46263
|
});
|
|
46216
46264
|
}
|
|
46217
|
-
|
|
46265
|
+
setValueIndex(valueIndex) {
|
|
46218
46266
|
this.emit({
|
|
46219
46267
|
class: "Dice",
|
|
46220
|
-
method: "
|
|
46268
|
+
method: "changeValueIndex",
|
|
46221
46269
|
item: [this.getId()],
|
|
46222
|
-
newData: {
|
|
46223
|
-
prevData: { value: this.
|
|
46270
|
+
newData: { valueIndex, shouldRotate: true, timeStamp: Date.now() },
|
|
46271
|
+
prevData: { value: this.valueIndex, shouldRotate: false }
|
|
46224
46272
|
});
|
|
46225
46273
|
}
|
|
46226
46274
|
throwDice() {
|
|
46227
|
-
this.
|
|
46275
|
+
this.setValueIndex(Math.floor(Math.random() * this.values.length));
|
|
46228
46276
|
}
|
|
46229
46277
|
apply(op) {
|
|
46230
46278
|
super.apply(op);
|
|
@@ -46240,19 +46288,22 @@ class Dice extends BaseItem {
|
|
|
46240
46288
|
case "setBorderColor":
|
|
46241
46289
|
this.applyBorderColor(op.newData.borderColor);
|
|
46242
46290
|
break;
|
|
46243
|
-
case "
|
|
46291
|
+
case "changeValueIndex":
|
|
46244
46292
|
if (op.newData.shouldRotate && op.newData.timeStamp && Date.now() - op.newData.timeStamp < 1e4) {
|
|
46245
46293
|
this.startRotation();
|
|
46246
46294
|
setTimeout(() => {
|
|
46247
46295
|
this.stopRotation();
|
|
46248
|
-
this.
|
|
46296
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46249
46297
|
}, TIMEOUT);
|
|
46250
46298
|
} else {
|
|
46251
|
-
this.
|
|
46299
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46252
46300
|
}
|
|
46253
46301
|
break;
|
|
46254
|
-
case "
|
|
46255
|
-
|
|
46302
|
+
case "changeValues":
|
|
46303
|
+
if (!op.newData.values[this.valueIndex]) {
|
|
46304
|
+
this.valueIndex = 0;
|
|
46305
|
+
}
|
|
46306
|
+
this.values = op.newData.values;
|
|
46256
46307
|
break;
|
|
46257
46308
|
}
|
|
46258
46309
|
break;
|
package/dist/esm/index.js
CHANGED
|
@@ -46070,27 +46070,37 @@ class AddDice extends ShapeTool {
|
|
|
46070
46070
|
var TIMEOUT = 2000;
|
|
46071
46071
|
var defaultDiceData = {
|
|
46072
46072
|
itemType: "Dice",
|
|
46073
|
+
type: "common",
|
|
46073
46074
|
backgroundColor: "#FFFFFF",
|
|
46074
46075
|
backgroundOpacity: 1,
|
|
46075
46076
|
borderColor: "#000207",
|
|
46076
46077
|
borderOpacity: 1,
|
|
46077
46078
|
borderStyle: "solid",
|
|
46078
46079
|
borderWidth: 1,
|
|
46079
|
-
|
|
46080
|
-
|
|
46080
|
+
valueIndex: 0,
|
|
46081
|
+
values: [1, 2, 3, 4, 5, 6]
|
|
46081
46082
|
};
|
|
46082
46083
|
|
|
46083
46084
|
class Dice extends BaseItem {
|
|
46084
46085
|
itemType = "Dice";
|
|
46086
|
+
type = "common";
|
|
46085
46087
|
path;
|
|
46086
46088
|
subject = new Subject;
|
|
46087
46089
|
borderWidth = 1;
|
|
46088
|
-
|
|
46089
|
-
|
|
46090
|
+
valueIndex = 0;
|
|
46091
|
+
values = [];
|
|
46092
|
+
renderValues = {};
|
|
46090
46093
|
animationFrameId;
|
|
46091
46094
|
drawingContext = null;
|
|
46092
|
-
constructor(board, id = "") {
|
|
46095
|
+
constructor(board, id = "", type, values2) {
|
|
46093
46096
|
super(board, id, defaultDiceData);
|
|
46097
|
+
if (type) {
|
|
46098
|
+
this.type = type;
|
|
46099
|
+
}
|
|
46100
|
+
if (values2) {
|
|
46101
|
+
this.values = values2;
|
|
46102
|
+
}
|
|
46103
|
+
this.createRenderValues();
|
|
46094
46104
|
this.transformPath();
|
|
46095
46105
|
this.transformation.subject.subscribe(() => {
|
|
46096
46106
|
this.transformPath();
|
|
@@ -46106,6 +46116,24 @@ class Dice extends BaseItem {
|
|
|
46106
46116
|
this.path.setBorderColor(this.borderColor);
|
|
46107
46117
|
this.path.setBorderWidth(this.borderWidth);
|
|
46108
46118
|
}
|
|
46119
|
+
createRenderValues() {
|
|
46120
|
+
this.values.forEach((value, index2) => {
|
|
46121
|
+
if (typeof value === "number") {
|
|
46122
|
+
this.renderValues[index2] = value;
|
|
46123
|
+
} else {
|
|
46124
|
+
const image2 = conf.documentFactory.createElement("img");
|
|
46125
|
+
image2.src = value;
|
|
46126
|
+
this.renderValues[index2] = image2;
|
|
46127
|
+
image2.onload = () => {
|
|
46128
|
+
this.subject.publish(this);
|
|
46129
|
+
};
|
|
46130
|
+
image2.onerror = () => {
|
|
46131
|
+
this.renderValues[index2] = 1;
|
|
46132
|
+
this.subject.publish(this);
|
|
46133
|
+
};
|
|
46134
|
+
}
|
|
46135
|
+
});
|
|
46136
|
+
}
|
|
46109
46137
|
render(context) {
|
|
46110
46138
|
this.drawingContext = context;
|
|
46111
46139
|
if (this.transformationRenderBlock) {
|
|
@@ -46126,11 +46154,25 @@ class Dice extends BaseItem {
|
|
|
46126
46154
|
const mbr = this.getMbr();
|
|
46127
46155
|
const centerX = (mbr.left + mbr.right) / 2;
|
|
46128
46156
|
const centerY = (mbr.top + mbr.bottom) / 2;
|
|
46129
|
-
|
|
46130
|
-
|
|
46131
|
-
|
|
46132
|
-
|
|
46133
|
-
|
|
46157
|
+
const valueToRender = this.renderValues[this.valueIndex];
|
|
46158
|
+
if (typeof valueToRender === "number") {
|
|
46159
|
+
context.ctx.fillStyle = "black";
|
|
46160
|
+
context.ctx.font = `bold ${this.getHeight() / 3}px sans-serif`;
|
|
46161
|
+
context.ctx.textAlign = "center";
|
|
46162
|
+
context.ctx.textBaseline = "middle";
|
|
46163
|
+
context.ctx.fillText(String(valueToRender), centerX, centerY);
|
|
46164
|
+
} else if (valueToRender instanceof HTMLImageElement) {
|
|
46165
|
+
const size = this.getHeight() / 3;
|
|
46166
|
+
if (valueToRender.complete && valueToRender.naturalWidth > 0) {
|
|
46167
|
+
context.ctx.drawImage(valueToRender, centerX - size / 2, centerY - size / 2, size, size);
|
|
46168
|
+
} else {
|
|
46169
|
+
context.ctx.fillStyle = "black";
|
|
46170
|
+
context.ctx.font = `bold ${size}px sans-serif`;
|
|
46171
|
+
context.ctx.textAlign = "center";
|
|
46172
|
+
context.ctx.textBaseline = "middle";
|
|
46173
|
+
context.ctx.fillText("?", centerX, centerY);
|
|
46174
|
+
}
|
|
46175
|
+
}
|
|
46134
46176
|
context.ctx.restore();
|
|
46135
46177
|
}
|
|
46136
46178
|
updateMbr() {
|
|
@@ -46156,8 +46198,14 @@ class Dice extends BaseItem {
|
|
|
46156
46198
|
getIsRotating() {
|
|
46157
46199
|
return !!this.animationFrameId;
|
|
46158
46200
|
}
|
|
46201
|
+
getType() {
|
|
46202
|
+
return this.type;
|
|
46203
|
+
}
|
|
46159
46204
|
getRange() {
|
|
46160
|
-
|
|
46205
|
+
if (this.type === "custom") {
|
|
46206
|
+
return { min: 1, max: this.values.length };
|
|
46207
|
+
}
|
|
46208
|
+
return { min: this.values[0], max: this.values[this.values.length - 1] };
|
|
46161
46209
|
}
|
|
46162
46210
|
applyBackgroundColor(backgroundColor) {
|
|
46163
46211
|
this.backgroundColor = backgroundColor;
|
|
@@ -46198,26 +46246,26 @@ class Dice extends BaseItem {
|
|
|
46198
46246
|
prevData: { borderColor: this.borderColor }
|
|
46199
46247
|
});
|
|
46200
46248
|
}
|
|
46201
|
-
|
|
46249
|
+
setValues(values2) {
|
|
46202
46250
|
this.emit({
|
|
46203
46251
|
class: "Dice",
|
|
46204
|
-
method: "
|
|
46252
|
+
method: "changeValues",
|
|
46205
46253
|
item: [this.getId()],
|
|
46206
|
-
newData:
|
|
46207
|
-
prevData: this.
|
|
46254
|
+
newData: { values: values2 },
|
|
46255
|
+
prevData: { values: this.values }
|
|
46208
46256
|
});
|
|
46209
46257
|
}
|
|
46210
|
-
|
|
46258
|
+
setValueIndex(valueIndex) {
|
|
46211
46259
|
this.emit({
|
|
46212
46260
|
class: "Dice",
|
|
46213
|
-
method: "
|
|
46261
|
+
method: "changeValueIndex",
|
|
46214
46262
|
item: [this.getId()],
|
|
46215
|
-
newData: {
|
|
46216
|
-
prevData: { value: this.
|
|
46263
|
+
newData: { valueIndex, shouldRotate: true, timeStamp: Date.now() },
|
|
46264
|
+
prevData: { value: this.valueIndex, shouldRotate: false }
|
|
46217
46265
|
});
|
|
46218
46266
|
}
|
|
46219
46267
|
throwDice() {
|
|
46220
|
-
this.
|
|
46268
|
+
this.setValueIndex(Math.floor(Math.random() * this.values.length));
|
|
46221
46269
|
}
|
|
46222
46270
|
apply(op) {
|
|
46223
46271
|
super.apply(op);
|
|
@@ -46233,19 +46281,22 @@ class Dice extends BaseItem {
|
|
|
46233
46281
|
case "setBorderColor":
|
|
46234
46282
|
this.applyBorderColor(op.newData.borderColor);
|
|
46235
46283
|
break;
|
|
46236
|
-
case "
|
|
46284
|
+
case "changeValueIndex":
|
|
46237
46285
|
if (op.newData.shouldRotate && op.newData.timeStamp && Date.now() - op.newData.timeStamp < 1e4) {
|
|
46238
46286
|
this.startRotation();
|
|
46239
46287
|
setTimeout(() => {
|
|
46240
46288
|
this.stopRotation();
|
|
46241
|
-
this.
|
|
46289
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46242
46290
|
}, TIMEOUT);
|
|
46243
46291
|
} else {
|
|
46244
|
-
this.
|
|
46292
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46245
46293
|
}
|
|
46246
46294
|
break;
|
|
46247
|
-
case "
|
|
46248
|
-
|
|
46295
|
+
case "changeValues":
|
|
46296
|
+
if (!op.newData.values[this.valueIndex]) {
|
|
46297
|
+
this.valueIndex = 0;
|
|
46298
|
+
}
|
|
46299
|
+
this.values = op.newData.values;
|
|
46249
46300
|
break;
|
|
46250
46301
|
}
|
|
46251
46302
|
break;
|
package/dist/esm/node.js
CHANGED
|
@@ -48605,27 +48605,37 @@ class AddDice extends ShapeTool {
|
|
|
48605
48605
|
var TIMEOUT = 2000;
|
|
48606
48606
|
var defaultDiceData = {
|
|
48607
48607
|
itemType: "Dice",
|
|
48608
|
+
type: "common",
|
|
48608
48609
|
backgroundColor: "#FFFFFF",
|
|
48609
48610
|
backgroundOpacity: 1,
|
|
48610
48611
|
borderColor: "#000207",
|
|
48611
48612
|
borderOpacity: 1,
|
|
48612
48613
|
borderStyle: "solid",
|
|
48613
48614
|
borderWidth: 1,
|
|
48614
|
-
|
|
48615
|
-
|
|
48615
|
+
valueIndex: 0,
|
|
48616
|
+
values: [1, 2, 3, 4, 5, 6]
|
|
48616
48617
|
};
|
|
48617
48618
|
|
|
48618
48619
|
class Dice extends BaseItem {
|
|
48619
48620
|
itemType = "Dice";
|
|
48621
|
+
type = "common";
|
|
48620
48622
|
path;
|
|
48621
48623
|
subject = new Subject;
|
|
48622
48624
|
borderWidth = 1;
|
|
48623
|
-
|
|
48624
|
-
|
|
48625
|
+
valueIndex = 0;
|
|
48626
|
+
values = [];
|
|
48627
|
+
renderValues = {};
|
|
48625
48628
|
animationFrameId;
|
|
48626
48629
|
drawingContext = null;
|
|
48627
|
-
constructor(board, id = "") {
|
|
48630
|
+
constructor(board, id = "", type, values2) {
|
|
48628
48631
|
super(board, id, defaultDiceData);
|
|
48632
|
+
if (type) {
|
|
48633
|
+
this.type = type;
|
|
48634
|
+
}
|
|
48635
|
+
if (values2) {
|
|
48636
|
+
this.values = values2;
|
|
48637
|
+
}
|
|
48638
|
+
this.createRenderValues();
|
|
48629
48639
|
this.transformPath();
|
|
48630
48640
|
this.transformation.subject.subscribe(() => {
|
|
48631
48641
|
this.transformPath();
|
|
@@ -48641,6 +48651,24 @@ class Dice extends BaseItem {
|
|
|
48641
48651
|
this.path.setBorderColor(this.borderColor);
|
|
48642
48652
|
this.path.setBorderWidth(this.borderWidth);
|
|
48643
48653
|
}
|
|
48654
|
+
createRenderValues() {
|
|
48655
|
+
this.values.forEach((value, index2) => {
|
|
48656
|
+
if (typeof value === "number") {
|
|
48657
|
+
this.renderValues[index2] = value;
|
|
48658
|
+
} else {
|
|
48659
|
+
const image2 = conf.documentFactory.createElement("img");
|
|
48660
|
+
image2.src = value;
|
|
48661
|
+
this.renderValues[index2] = image2;
|
|
48662
|
+
image2.onload = () => {
|
|
48663
|
+
this.subject.publish(this);
|
|
48664
|
+
};
|
|
48665
|
+
image2.onerror = () => {
|
|
48666
|
+
this.renderValues[index2] = 1;
|
|
48667
|
+
this.subject.publish(this);
|
|
48668
|
+
};
|
|
48669
|
+
}
|
|
48670
|
+
});
|
|
48671
|
+
}
|
|
48644
48672
|
render(context) {
|
|
48645
48673
|
this.drawingContext = context;
|
|
48646
48674
|
if (this.transformationRenderBlock) {
|
|
@@ -48661,11 +48689,25 @@ class Dice extends BaseItem {
|
|
|
48661
48689
|
const mbr = this.getMbr();
|
|
48662
48690
|
const centerX = (mbr.left + mbr.right) / 2;
|
|
48663
48691
|
const centerY = (mbr.top + mbr.bottom) / 2;
|
|
48664
|
-
|
|
48665
|
-
|
|
48666
|
-
|
|
48667
|
-
|
|
48668
|
-
|
|
48692
|
+
const valueToRender = this.renderValues[this.valueIndex];
|
|
48693
|
+
if (typeof valueToRender === "number") {
|
|
48694
|
+
context.ctx.fillStyle = "black";
|
|
48695
|
+
context.ctx.font = `bold ${this.getHeight() / 3}px sans-serif`;
|
|
48696
|
+
context.ctx.textAlign = "center";
|
|
48697
|
+
context.ctx.textBaseline = "middle";
|
|
48698
|
+
context.ctx.fillText(String(valueToRender), centerX, centerY);
|
|
48699
|
+
} else if (valueToRender instanceof HTMLImageElement) {
|
|
48700
|
+
const size = this.getHeight() / 3;
|
|
48701
|
+
if (valueToRender.complete && valueToRender.naturalWidth > 0) {
|
|
48702
|
+
context.ctx.drawImage(valueToRender, centerX - size / 2, centerY - size / 2, size, size);
|
|
48703
|
+
} else {
|
|
48704
|
+
context.ctx.fillStyle = "black";
|
|
48705
|
+
context.ctx.font = `bold ${size}px sans-serif`;
|
|
48706
|
+
context.ctx.textAlign = "center";
|
|
48707
|
+
context.ctx.textBaseline = "middle";
|
|
48708
|
+
context.ctx.fillText("?", centerX, centerY);
|
|
48709
|
+
}
|
|
48710
|
+
}
|
|
48669
48711
|
context.ctx.restore();
|
|
48670
48712
|
}
|
|
48671
48713
|
updateMbr() {
|
|
@@ -48691,8 +48733,14 @@ class Dice extends BaseItem {
|
|
|
48691
48733
|
getIsRotating() {
|
|
48692
48734
|
return !!this.animationFrameId;
|
|
48693
48735
|
}
|
|
48736
|
+
getType() {
|
|
48737
|
+
return this.type;
|
|
48738
|
+
}
|
|
48694
48739
|
getRange() {
|
|
48695
|
-
|
|
48740
|
+
if (this.type === "custom") {
|
|
48741
|
+
return { min: 1, max: this.values.length };
|
|
48742
|
+
}
|
|
48743
|
+
return { min: this.values[0], max: this.values[this.values.length - 1] };
|
|
48696
48744
|
}
|
|
48697
48745
|
applyBackgroundColor(backgroundColor) {
|
|
48698
48746
|
this.backgroundColor = backgroundColor;
|
|
@@ -48733,26 +48781,26 @@ class Dice extends BaseItem {
|
|
|
48733
48781
|
prevData: { borderColor: this.borderColor }
|
|
48734
48782
|
});
|
|
48735
48783
|
}
|
|
48736
|
-
|
|
48784
|
+
setValues(values2) {
|
|
48737
48785
|
this.emit({
|
|
48738
48786
|
class: "Dice",
|
|
48739
|
-
method: "
|
|
48787
|
+
method: "changeValues",
|
|
48740
48788
|
item: [this.getId()],
|
|
48741
|
-
newData:
|
|
48742
|
-
prevData: this.
|
|
48789
|
+
newData: { values: values2 },
|
|
48790
|
+
prevData: { values: this.values }
|
|
48743
48791
|
});
|
|
48744
48792
|
}
|
|
48745
|
-
|
|
48793
|
+
setValueIndex(valueIndex) {
|
|
48746
48794
|
this.emit({
|
|
48747
48795
|
class: "Dice",
|
|
48748
|
-
method: "
|
|
48796
|
+
method: "changeValueIndex",
|
|
48749
48797
|
item: [this.getId()],
|
|
48750
|
-
newData: {
|
|
48751
|
-
prevData: { value: this.
|
|
48798
|
+
newData: { valueIndex, shouldRotate: true, timeStamp: Date.now() },
|
|
48799
|
+
prevData: { value: this.valueIndex, shouldRotate: false }
|
|
48752
48800
|
});
|
|
48753
48801
|
}
|
|
48754
48802
|
throwDice() {
|
|
48755
|
-
this.
|
|
48803
|
+
this.setValueIndex(Math.floor(Math.random() * this.values.length));
|
|
48756
48804
|
}
|
|
48757
48805
|
apply(op) {
|
|
48758
48806
|
super.apply(op);
|
|
@@ -48768,19 +48816,22 @@ class Dice extends BaseItem {
|
|
|
48768
48816
|
case "setBorderColor":
|
|
48769
48817
|
this.applyBorderColor(op.newData.borderColor);
|
|
48770
48818
|
break;
|
|
48771
|
-
case "
|
|
48819
|
+
case "changeValueIndex":
|
|
48772
48820
|
if (op.newData.shouldRotate && op.newData.timeStamp && Date.now() - op.newData.timeStamp < 1e4) {
|
|
48773
48821
|
this.startRotation();
|
|
48774
48822
|
setTimeout(() => {
|
|
48775
48823
|
this.stopRotation();
|
|
48776
|
-
this.
|
|
48824
|
+
this.valueIndex = op.newData.valueIndex;
|
|
48777
48825
|
}, TIMEOUT);
|
|
48778
48826
|
} else {
|
|
48779
|
-
this.
|
|
48827
|
+
this.valueIndex = op.newData.valueIndex;
|
|
48780
48828
|
}
|
|
48781
48829
|
break;
|
|
48782
|
-
case "
|
|
48783
|
-
|
|
48830
|
+
case "changeValues":
|
|
48831
|
+
if (!op.newData.values[this.valueIndex]) {
|
|
48832
|
+
this.valueIndex = 0;
|
|
48833
|
+
}
|
|
48834
|
+
this.values = op.newData.values;
|
|
48784
48835
|
break;
|
|
48785
48836
|
}
|
|
48786
48837
|
break;
|
|
@@ -5,27 +5,29 @@ import { Board } from "../../../../Board";
|
|
|
5
5
|
import { DrawingContext } from "../../../DrawingContext";
|
|
6
6
|
import { DocumentFactory } from "../../../../api/DocumentFactory";
|
|
7
7
|
import { DiceOperation } from "./DiceOperation";
|
|
8
|
+
export type DiceType = "common" | "custom";
|
|
8
9
|
export declare const defaultDiceData: BaseItemData;
|
|
9
10
|
export declare class Dice extends BaseItem {
|
|
10
11
|
readonly itemType = "Dice";
|
|
12
|
+
private type;
|
|
11
13
|
private path;
|
|
12
14
|
readonly subject: Subject<Dice>;
|
|
13
15
|
private borderWidth;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
max: number;
|
|
18
|
-
};
|
|
16
|
+
valueIndex: number;
|
|
17
|
+
values: number[] | string[];
|
|
18
|
+
renderValues: Record<number, number | HTMLImageElement>;
|
|
19
19
|
private animationFrameId?;
|
|
20
20
|
drawingContext: DrawingContext | null;
|
|
21
|
-
constructor(board: Board, id?: string);
|
|
21
|
+
constructor(board: Board, id?: string, type?: DiceType, values?: number[] | string[]);
|
|
22
22
|
private transformPath;
|
|
23
|
+
createRenderValues(): void;
|
|
23
24
|
render(context: DrawingContext): void;
|
|
24
25
|
updateMbr(): void;
|
|
25
26
|
getPath(): Path;
|
|
26
27
|
renderHTML(documentFactory: DocumentFactory): HTMLElement;
|
|
27
28
|
deserialize(data: SerializedItemData): this;
|
|
28
29
|
getIsRotating(): boolean;
|
|
30
|
+
getType(): DiceType;
|
|
29
31
|
getRange(): {
|
|
30
32
|
min: number;
|
|
31
33
|
max: number;
|
|
@@ -36,11 +38,8 @@ export declare class Dice extends BaseItem {
|
|
|
36
38
|
setBorderWidth(borderWidth: BorderWidth): void;
|
|
37
39
|
private applyBorderColor;
|
|
38
40
|
setBorderColor(borderColor: string): void;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
max: number;
|
|
42
|
-
}): void;
|
|
43
|
-
setValue(value: number): void;
|
|
41
|
+
setValues(values: number[]): void;
|
|
42
|
+
setValueIndex(valueIndex: number): void;
|
|
44
43
|
throwDice(): void;
|
|
45
44
|
apply(op: DiceOperation): void;
|
|
46
45
|
startRotation(): void;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { BaseOperation } from "Events/EventsOperations";
|
|
2
|
-
export type DiceOperation =
|
|
3
|
-
interface
|
|
4
|
-
|
|
2
|
+
export type DiceOperation = ChangeValueIndex | ChangeValues | SetBackgroundColor | SetBorderColor | SetBorderWidth;
|
|
3
|
+
interface ChangeValueIndex extends BaseOperation<{
|
|
4
|
+
valueIndex: number;
|
|
5
5
|
shouldRotate: boolean;
|
|
6
6
|
timeStamp?: number;
|
|
7
7
|
}> {
|
|
8
8
|
class: "Dice";
|
|
9
|
-
method: "
|
|
9
|
+
method: "changeValueIndex";
|
|
10
10
|
}
|
|
11
|
-
interface
|
|
12
|
-
|
|
13
|
-
max: number;
|
|
11
|
+
interface ChangeValues extends BaseOperation<{
|
|
12
|
+
values: number[];
|
|
14
13
|
}> {
|
|
15
14
|
class: "Dice";
|
|
16
|
-
method: "
|
|
15
|
+
method: "changeValues";
|
|
17
16
|
}
|
|
18
17
|
interface SetBackgroundColor extends BaseOperation<{
|
|
19
18
|
backgroundColor: string;
|