microboard-temp 0.4.24 → 0.4.25
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 +73 -25
- package/dist/cjs/index.js +73 -25
- package/dist/cjs/node.js +73 -25
- package/dist/esm/browser.js +73 -25
- package/dist/esm/index.js +73 -25
- package/dist/esm/node.js +73 -25
- package/dist/types/Items/Examples/CardGame/Dice/Dice.d.ts +9 -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() {
|
|
@@ -46314,7 +46356,10 @@ class Dice extends BaseItem {
|
|
|
46314
46356
|
return !!this.animationFrameId;
|
|
46315
46357
|
}
|
|
46316
46358
|
getRange() {
|
|
46317
|
-
|
|
46359
|
+
if (this.type === "custom") {
|
|
46360
|
+
return { min: 1, max: this.values.length };
|
|
46361
|
+
}
|
|
46362
|
+
return { min: this.values[0], max: this.values[this.values.length - 1] };
|
|
46318
46363
|
}
|
|
46319
46364
|
applyBackgroundColor(backgroundColor) {
|
|
46320
46365
|
this.backgroundColor = backgroundColor;
|
|
@@ -46355,26 +46400,26 @@ class Dice extends BaseItem {
|
|
|
46355
46400
|
prevData: { borderColor: this.borderColor }
|
|
46356
46401
|
});
|
|
46357
46402
|
}
|
|
46358
|
-
|
|
46403
|
+
setValues(values2) {
|
|
46359
46404
|
this.emit({
|
|
46360
46405
|
class: "Dice",
|
|
46361
|
-
method: "
|
|
46406
|
+
method: "changeValues",
|
|
46362
46407
|
item: [this.getId()],
|
|
46363
|
-
newData:
|
|
46364
|
-
prevData: this.
|
|
46408
|
+
newData: { values: values2 },
|
|
46409
|
+
prevData: { values: this.values }
|
|
46365
46410
|
});
|
|
46366
46411
|
}
|
|
46367
|
-
|
|
46412
|
+
setValueIndex(valueIndex) {
|
|
46368
46413
|
this.emit({
|
|
46369
46414
|
class: "Dice",
|
|
46370
|
-
method: "
|
|
46415
|
+
method: "changeValueIndex",
|
|
46371
46416
|
item: [this.getId()],
|
|
46372
|
-
newData: {
|
|
46373
|
-
prevData: { value: this.
|
|
46417
|
+
newData: { valueIndex, shouldRotate: true, timeStamp: Date.now() },
|
|
46418
|
+
prevData: { value: this.valueIndex, shouldRotate: false }
|
|
46374
46419
|
});
|
|
46375
46420
|
}
|
|
46376
46421
|
throwDice() {
|
|
46377
|
-
this.
|
|
46422
|
+
this.setValueIndex(Math.floor(Math.random() * this.values.length));
|
|
46378
46423
|
}
|
|
46379
46424
|
apply(op) {
|
|
46380
46425
|
super.apply(op);
|
|
@@ -46390,19 +46435,22 @@ class Dice extends BaseItem {
|
|
|
46390
46435
|
case "setBorderColor":
|
|
46391
46436
|
this.applyBorderColor(op.newData.borderColor);
|
|
46392
46437
|
break;
|
|
46393
|
-
case "
|
|
46438
|
+
case "changeValueIndex":
|
|
46394
46439
|
if (op.newData.shouldRotate && op.newData.timeStamp && Date.now() - op.newData.timeStamp < 1e4) {
|
|
46395
46440
|
this.startRotation();
|
|
46396
46441
|
setTimeout(() => {
|
|
46397
46442
|
this.stopRotation();
|
|
46398
|
-
this.
|
|
46443
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46399
46444
|
}, TIMEOUT);
|
|
46400
46445
|
} else {
|
|
46401
|
-
this.
|
|
46446
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46402
46447
|
}
|
|
46403
46448
|
break;
|
|
46404
|
-
case "
|
|
46405
|
-
|
|
46449
|
+
case "changeValues":
|
|
46450
|
+
if (!op.newData.values[this.valueIndex]) {
|
|
46451
|
+
this.valueIndex = 0;
|
|
46452
|
+
}
|
|
46453
|
+
this.values = op.newData.values;
|
|
46406
46454
|
break;
|
|
46407
46455
|
}
|
|
46408
46456
|
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() {
|
|
@@ -46314,7 +46356,10 @@ class Dice extends BaseItem {
|
|
|
46314
46356
|
return !!this.animationFrameId;
|
|
46315
46357
|
}
|
|
46316
46358
|
getRange() {
|
|
46317
|
-
|
|
46359
|
+
if (this.type === "custom") {
|
|
46360
|
+
return { min: 1, max: this.values.length };
|
|
46361
|
+
}
|
|
46362
|
+
return { min: this.values[0], max: this.values[this.values.length - 1] };
|
|
46318
46363
|
}
|
|
46319
46364
|
applyBackgroundColor(backgroundColor) {
|
|
46320
46365
|
this.backgroundColor = backgroundColor;
|
|
@@ -46355,26 +46400,26 @@ class Dice extends BaseItem {
|
|
|
46355
46400
|
prevData: { borderColor: this.borderColor }
|
|
46356
46401
|
});
|
|
46357
46402
|
}
|
|
46358
|
-
|
|
46403
|
+
setValues(values2) {
|
|
46359
46404
|
this.emit({
|
|
46360
46405
|
class: "Dice",
|
|
46361
|
-
method: "
|
|
46406
|
+
method: "changeValues",
|
|
46362
46407
|
item: [this.getId()],
|
|
46363
|
-
newData:
|
|
46364
|
-
prevData: this.
|
|
46408
|
+
newData: { values: values2 },
|
|
46409
|
+
prevData: { values: this.values }
|
|
46365
46410
|
});
|
|
46366
46411
|
}
|
|
46367
|
-
|
|
46412
|
+
setValueIndex(valueIndex) {
|
|
46368
46413
|
this.emit({
|
|
46369
46414
|
class: "Dice",
|
|
46370
|
-
method: "
|
|
46415
|
+
method: "changeValueIndex",
|
|
46371
46416
|
item: [this.getId()],
|
|
46372
|
-
newData: {
|
|
46373
|
-
prevData: { value: this.
|
|
46417
|
+
newData: { valueIndex, shouldRotate: true, timeStamp: Date.now() },
|
|
46418
|
+
prevData: { value: this.valueIndex, shouldRotate: false }
|
|
46374
46419
|
});
|
|
46375
46420
|
}
|
|
46376
46421
|
throwDice() {
|
|
46377
|
-
this.
|
|
46422
|
+
this.setValueIndex(Math.floor(Math.random() * this.values.length));
|
|
46378
46423
|
}
|
|
46379
46424
|
apply(op) {
|
|
46380
46425
|
super.apply(op);
|
|
@@ -46390,19 +46435,22 @@ class Dice extends BaseItem {
|
|
|
46390
46435
|
case "setBorderColor":
|
|
46391
46436
|
this.applyBorderColor(op.newData.borderColor);
|
|
46392
46437
|
break;
|
|
46393
|
-
case "
|
|
46438
|
+
case "changeValueIndex":
|
|
46394
46439
|
if (op.newData.shouldRotate && op.newData.timeStamp && Date.now() - op.newData.timeStamp < 1e4) {
|
|
46395
46440
|
this.startRotation();
|
|
46396
46441
|
setTimeout(() => {
|
|
46397
46442
|
this.stopRotation();
|
|
46398
|
-
this.
|
|
46443
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46399
46444
|
}, TIMEOUT);
|
|
46400
46445
|
} else {
|
|
46401
|
-
this.
|
|
46446
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46402
46447
|
}
|
|
46403
46448
|
break;
|
|
46404
|
-
case "
|
|
46405
|
-
|
|
46449
|
+
case "changeValues":
|
|
46450
|
+
if (!op.newData.values[this.valueIndex]) {
|
|
46451
|
+
this.valueIndex = 0;
|
|
46452
|
+
}
|
|
46453
|
+
this.values = op.newData.values;
|
|
46406
46454
|
break;
|
|
46407
46455
|
}
|
|
46408
46456
|
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() {
|
|
@@ -48854,7 +48896,10 @@ class Dice extends BaseItem {
|
|
|
48854
48896
|
return !!this.animationFrameId;
|
|
48855
48897
|
}
|
|
48856
48898
|
getRange() {
|
|
48857
|
-
|
|
48899
|
+
if (this.type === "custom") {
|
|
48900
|
+
return { min: 1, max: this.values.length };
|
|
48901
|
+
}
|
|
48902
|
+
return { min: this.values[0], max: this.values[this.values.length - 1] };
|
|
48858
48903
|
}
|
|
48859
48904
|
applyBackgroundColor(backgroundColor) {
|
|
48860
48905
|
this.backgroundColor = backgroundColor;
|
|
@@ -48895,26 +48940,26 @@ class Dice extends BaseItem {
|
|
|
48895
48940
|
prevData: { borderColor: this.borderColor }
|
|
48896
48941
|
});
|
|
48897
48942
|
}
|
|
48898
|
-
|
|
48943
|
+
setValues(values2) {
|
|
48899
48944
|
this.emit({
|
|
48900
48945
|
class: "Dice",
|
|
48901
|
-
method: "
|
|
48946
|
+
method: "changeValues",
|
|
48902
48947
|
item: [this.getId()],
|
|
48903
|
-
newData:
|
|
48904
|
-
prevData: this.
|
|
48948
|
+
newData: { values: values2 },
|
|
48949
|
+
prevData: { values: this.values }
|
|
48905
48950
|
});
|
|
48906
48951
|
}
|
|
48907
|
-
|
|
48952
|
+
setValueIndex(valueIndex) {
|
|
48908
48953
|
this.emit({
|
|
48909
48954
|
class: "Dice",
|
|
48910
|
-
method: "
|
|
48955
|
+
method: "changeValueIndex",
|
|
48911
48956
|
item: [this.getId()],
|
|
48912
|
-
newData: {
|
|
48913
|
-
prevData: { value: this.
|
|
48957
|
+
newData: { valueIndex, shouldRotate: true, timeStamp: Date.now() },
|
|
48958
|
+
prevData: { value: this.valueIndex, shouldRotate: false }
|
|
48914
48959
|
});
|
|
48915
48960
|
}
|
|
48916
48961
|
throwDice() {
|
|
48917
|
-
this.
|
|
48962
|
+
this.setValueIndex(Math.floor(Math.random() * this.values.length));
|
|
48918
48963
|
}
|
|
48919
48964
|
apply(op) {
|
|
48920
48965
|
super.apply(op);
|
|
@@ -48930,19 +48975,22 @@ class Dice extends BaseItem {
|
|
|
48930
48975
|
case "setBorderColor":
|
|
48931
48976
|
this.applyBorderColor(op.newData.borderColor);
|
|
48932
48977
|
break;
|
|
48933
|
-
case "
|
|
48978
|
+
case "changeValueIndex":
|
|
48934
48979
|
if (op.newData.shouldRotate && op.newData.timeStamp && Date.now() - op.newData.timeStamp < 1e4) {
|
|
48935
48980
|
this.startRotation();
|
|
48936
48981
|
setTimeout(() => {
|
|
48937
48982
|
this.stopRotation();
|
|
48938
|
-
this.
|
|
48983
|
+
this.valueIndex = op.newData.valueIndex;
|
|
48939
48984
|
}, TIMEOUT);
|
|
48940
48985
|
} else {
|
|
48941
|
-
this.
|
|
48986
|
+
this.valueIndex = op.newData.valueIndex;
|
|
48942
48987
|
}
|
|
48943
48988
|
break;
|
|
48944
|
-
case "
|
|
48945
|
-
|
|
48989
|
+
case "changeValues":
|
|
48990
|
+
if (!op.newData.values[this.valueIndex]) {
|
|
48991
|
+
this.valueIndex = 0;
|
|
48992
|
+
}
|
|
48993
|
+
this.values = op.newData.values;
|
|
48946
48994
|
break;
|
|
48947
48995
|
}
|
|
48948
48996
|
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() {
|
|
@@ -46164,7 +46206,10 @@ class Dice extends BaseItem {
|
|
|
46164
46206
|
return !!this.animationFrameId;
|
|
46165
46207
|
}
|
|
46166
46208
|
getRange() {
|
|
46167
|
-
|
|
46209
|
+
if (this.type === "custom") {
|
|
46210
|
+
return { min: 1, max: this.values.length };
|
|
46211
|
+
}
|
|
46212
|
+
return { min: this.values[0], max: this.values[this.values.length - 1] };
|
|
46168
46213
|
}
|
|
46169
46214
|
applyBackgroundColor(backgroundColor) {
|
|
46170
46215
|
this.backgroundColor = backgroundColor;
|
|
@@ -46205,26 +46250,26 @@ class Dice extends BaseItem {
|
|
|
46205
46250
|
prevData: { borderColor: this.borderColor }
|
|
46206
46251
|
});
|
|
46207
46252
|
}
|
|
46208
|
-
|
|
46253
|
+
setValues(values2) {
|
|
46209
46254
|
this.emit({
|
|
46210
46255
|
class: "Dice",
|
|
46211
|
-
method: "
|
|
46256
|
+
method: "changeValues",
|
|
46212
46257
|
item: [this.getId()],
|
|
46213
|
-
newData:
|
|
46214
|
-
prevData: this.
|
|
46258
|
+
newData: { values: values2 },
|
|
46259
|
+
prevData: { values: this.values }
|
|
46215
46260
|
});
|
|
46216
46261
|
}
|
|
46217
|
-
|
|
46262
|
+
setValueIndex(valueIndex) {
|
|
46218
46263
|
this.emit({
|
|
46219
46264
|
class: "Dice",
|
|
46220
|
-
method: "
|
|
46265
|
+
method: "changeValueIndex",
|
|
46221
46266
|
item: [this.getId()],
|
|
46222
|
-
newData: {
|
|
46223
|
-
prevData: { value: this.
|
|
46267
|
+
newData: { valueIndex, shouldRotate: true, timeStamp: Date.now() },
|
|
46268
|
+
prevData: { value: this.valueIndex, shouldRotate: false }
|
|
46224
46269
|
});
|
|
46225
46270
|
}
|
|
46226
46271
|
throwDice() {
|
|
46227
|
-
this.
|
|
46272
|
+
this.setValueIndex(Math.floor(Math.random() * this.values.length));
|
|
46228
46273
|
}
|
|
46229
46274
|
apply(op) {
|
|
46230
46275
|
super.apply(op);
|
|
@@ -46240,19 +46285,22 @@ class Dice extends BaseItem {
|
|
|
46240
46285
|
case "setBorderColor":
|
|
46241
46286
|
this.applyBorderColor(op.newData.borderColor);
|
|
46242
46287
|
break;
|
|
46243
|
-
case "
|
|
46288
|
+
case "changeValueIndex":
|
|
46244
46289
|
if (op.newData.shouldRotate && op.newData.timeStamp && Date.now() - op.newData.timeStamp < 1e4) {
|
|
46245
46290
|
this.startRotation();
|
|
46246
46291
|
setTimeout(() => {
|
|
46247
46292
|
this.stopRotation();
|
|
46248
|
-
this.
|
|
46293
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46249
46294
|
}, TIMEOUT);
|
|
46250
46295
|
} else {
|
|
46251
|
-
this.
|
|
46296
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46252
46297
|
}
|
|
46253
46298
|
break;
|
|
46254
|
-
case "
|
|
46255
|
-
|
|
46299
|
+
case "changeValues":
|
|
46300
|
+
if (!op.newData.values[this.valueIndex]) {
|
|
46301
|
+
this.valueIndex = 0;
|
|
46302
|
+
}
|
|
46303
|
+
this.values = op.newData.values;
|
|
46256
46304
|
break;
|
|
46257
46305
|
}
|
|
46258
46306
|
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() {
|
|
@@ -46157,7 +46199,10 @@ class Dice extends BaseItem {
|
|
|
46157
46199
|
return !!this.animationFrameId;
|
|
46158
46200
|
}
|
|
46159
46201
|
getRange() {
|
|
46160
|
-
|
|
46202
|
+
if (this.type === "custom") {
|
|
46203
|
+
return { min: 1, max: this.values.length };
|
|
46204
|
+
}
|
|
46205
|
+
return { min: this.values[0], max: this.values[this.values.length - 1] };
|
|
46161
46206
|
}
|
|
46162
46207
|
applyBackgroundColor(backgroundColor) {
|
|
46163
46208
|
this.backgroundColor = backgroundColor;
|
|
@@ -46198,26 +46243,26 @@ class Dice extends BaseItem {
|
|
|
46198
46243
|
prevData: { borderColor: this.borderColor }
|
|
46199
46244
|
});
|
|
46200
46245
|
}
|
|
46201
|
-
|
|
46246
|
+
setValues(values2) {
|
|
46202
46247
|
this.emit({
|
|
46203
46248
|
class: "Dice",
|
|
46204
|
-
method: "
|
|
46249
|
+
method: "changeValues",
|
|
46205
46250
|
item: [this.getId()],
|
|
46206
|
-
newData:
|
|
46207
|
-
prevData: this.
|
|
46251
|
+
newData: { values: values2 },
|
|
46252
|
+
prevData: { values: this.values }
|
|
46208
46253
|
});
|
|
46209
46254
|
}
|
|
46210
|
-
|
|
46255
|
+
setValueIndex(valueIndex) {
|
|
46211
46256
|
this.emit({
|
|
46212
46257
|
class: "Dice",
|
|
46213
|
-
method: "
|
|
46258
|
+
method: "changeValueIndex",
|
|
46214
46259
|
item: [this.getId()],
|
|
46215
|
-
newData: {
|
|
46216
|
-
prevData: { value: this.
|
|
46260
|
+
newData: { valueIndex, shouldRotate: true, timeStamp: Date.now() },
|
|
46261
|
+
prevData: { value: this.valueIndex, shouldRotate: false }
|
|
46217
46262
|
});
|
|
46218
46263
|
}
|
|
46219
46264
|
throwDice() {
|
|
46220
|
-
this.
|
|
46265
|
+
this.setValueIndex(Math.floor(Math.random() * this.values.length));
|
|
46221
46266
|
}
|
|
46222
46267
|
apply(op) {
|
|
46223
46268
|
super.apply(op);
|
|
@@ -46233,19 +46278,22 @@ class Dice extends BaseItem {
|
|
|
46233
46278
|
case "setBorderColor":
|
|
46234
46279
|
this.applyBorderColor(op.newData.borderColor);
|
|
46235
46280
|
break;
|
|
46236
|
-
case "
|
|
46281
|
+
case "changeValueIndex":
|
|
46237
46282
|
if (op.newData.shouldRotate && op.newData.timeStamp && Date.now() - op.newData.timeStamp < 1e4) {
|
|
46238
46283
|
this.startRotation();
|
|
46239
46284
|
setTimeout(() => {
|
|
46240
46285
|
this.stopRotation();
|
|
46241
|
-
this.
|
|
46286
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46242
46287
|
}, TIMEOUT);
|
|
46243
46288
|
} else {
|
|
46244
|
-
this.
|
|
46289
|
+
this.valueIndex = op.newData.valueIndex;
|
|
46245
46290
|
}
|
|
46246
46291
|
break;
|
|
46247
|
-
case "
|
|
46248
|
-
|
|
46292
|
+
case "changeValues":
|
|
46293
|
+
if (!op.newData.values[this.valueIndex]) {
|
|
46294
|
+
this.valueIndex = 0;
|
|
46295
|
+
}
|
|
46296
|
+
this.values = op.newData.values;
|
|
46249
46297
|
break;
|
|
46250
46298
|
}
|
|
46251
46299
|
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() {
|
|
@@ -48692,7 +48734,10 @@ class Dice extends BaseItem {
|
|
|
48692
48734
|
return !!this.animationFrameId;
|
|
48693
48735
|
}
|
|
48694
48736
|
getRange() {
|
|
48695
|
-
|
|
48737
|
+
if (this.type === "custom") {
|
|
48738
|
+
return { min: 1, max: this.values.length };
|
|
48739
|
+
}
|
|
48740
|
+
return { min: this.values[0], max: this.values[this.values.length - 1] };
|
|
48696
48741
|
}
|
|
48697
48742
|
applyBackgroundColor(backgroundColor) {
|
|
48698
48743
|
this.backgroundColor = backgroundColor;
|
|
@@ -48733,26 +48778,26 @@ class Dice extends BaseItem {
|
|
|
48733
48778
|
prevData: { borderColor: this.borderColor }
|
|
48734
48779
|
});
|
|
48735
48780
|
}
|
|
48736
|
-
|
|
48781
|
+
setValues(values2) {
|
|
48737
48782
|
this.emit({
|
|
48738
48783
|
class: "Dice",
|
|
48739
|
-
method: "
|
|
48784
|
+
method: "changeValues",
|
|
48740
48785
|
item: [this.getId()],
|
|
48741
|
-
newData:
|
|
48742
|
-
prevData: this.
|
|
48786
|
+
newData: { values: values2 },
|
|
48787
|
+
prevData: { values: this.values }
|
|
48743
48788
|
});
|
|
48744
48789
|
}
|
|
48745
|
-
|
|
48790
|
+
setValueIndex(valueIndex) {
|
|
48746
48791
|
this.emit({
|
|
48747
48792
|
class: "Dice",
|
|
48748
|
-
method: "
|
|
48793
|
+
method: "changeValueIndex",
|
|
48749
48794
|
item: [this.getId()],
|
|
48750
|
-
newData: {
|
|
48751
|
-
prevData: { value: this.
|
|
48795
|
+
newData: { valueIndex, shouldRotate: true, timeStamp: Date.now() },
|
|
48796
|
+
prevData: { value: this.valueIndex, shouldRotate: false }
|
|
48752
48797
|
});
|
|
48753
48798
|
}
|
|
48754
48799
|
throwDice() {
|
|
48755
|
-
this.
|
|
48800
|
+
this.setValueIndex(Math.floor(Math.random() * this.values.length));
|
|
48756
48801
|
}
|
|
48757
48802
|
apply(op) {
|
|
48758
48803
|
super.apply(op);
|
|
@@ -48768,19 +48813,22 @@ class Dice extends BaseItem {
|
|
|
48768
48813
|
case "setBorderColor":
|
|
48769
48814
|
this.applyBorderColor(op.newData.borderColor);
|
|
48770
48815
|
break;
|
|
48771
|
-
case "
|
|
48816
|
+
case "changeValueIndex":
|
|
48772
48817
|
if (op.newData.shouldRotate && op.newData.timeStamp && Date.now() - op.newData.timeStamp < 1e4) {
|
|
48773
48818
|
this.startRotation();
|
|
48774
48819
|
setTimeout(() => {
|
|
48775
48820
|
this.stopRotation();
|
|
48776
|
-
this.
|
|
48821
|
+
this.valueIndex = op.newData.valueIndex;
|
|
48777
48822
|
}, TIMEOUT);
|
|
48778
48823
|
} else {
|
|
48779
|
-
this.
|
|
48824
|
+
this.valueIndex = op.newData.valueIndex;
|
|
48780
48825
|
}
|
|
48781
48826
|
break;
|
|
48782
|
-
case "
|
|
48783
|
-
|
|
48827
|
+
case "changeValues":
|
|
48828
|
+
if (!op.newData.values[this.valueIndex]) {
|
|
48829
|
+
this.valueIndex = 0;
|
|
48830
|
+
}
|
|
48831
|
+
this.values = op.newData.values;
|
|
48784
48832
|
break;
|
|
48785
48833
|
}
|
|
48786
48834
|
break;
|
|
@@ -5,21 +5,22 @@ 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;
|
|
@@ -36,11 +37,8 @@ export declare class Dice extends BaseItem {
|
|
|
36
37
|
setBorderWidth(borderWidth: BorderWidth): void;
|
|
37
38
|
private applyBorderColor;
|
|
38
39
|
setBorderColor(borderColor: string): void;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
max: number;
|
|
42
|
-
}): void;
|
|
43
|
-
setValue(value: number): void;
|
|
40
|
+
setValues(values: number[]): void;
|
|
41
|
+
setValueIndex(valueIndex: number): void;
|
|
44
42
|
throwDice(): void;
|
|
45
43
|
apply(op: DiceOperation): void;
|
|
46
44
|
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;
|