microboard-temp 0.4.14 → 0.4.16
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 +206 -0
- package/dist/cjs/index.js +206 -0
- package/dist/cjs/node.js +206 -0
- package/dist/esm/browser.js +206 -0
- package/dist/esm/index.js +206 -0
- package/dist/esm/node.js +206 -0
- package/dist/types/Items/Examples/CardGame/Dice/Dice.d.ts +42 -0
- package/dist/types/Items/Examples/CardGame/Dice/DiceOperation.d.ts +40 -0
- package/dist/types/Items/Examples/CardGame/Dice/index.d.ts +1 -0
- package/dist/types/Items/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/esm/browser.js
CHANGED
|
@@ -46072,6 +46072,211 @@ registerItem({
|
|
|
46072
46072
|
item: Deck,
|
|
46073
46073
|
defaultData: defaultDeckData
|
|
46074
46074
|
});
|
|
46075
|
+
// src/Items/Examples/CardGame/Dice/Dice.ts
|
|
46076
|
+
var TIMEOUT = 3000;
|
|
46077
|
+
var defaultDiceData = {
|
|
46078
|
+
itemType: "Dice",
|
|
46079
|
+
backgroundColor: "#000207",
|
|
46080
|
+
backgroundOpacity: 1,
|
|
46081
|
+
borderColor: "#000207",
|
|
46082
|
+
borderOpacity: 1,
|
|
46083
|
+
borderStyle: "solid",
|
|
46084
|
+
borderWidth: 1,
|
|
46085
|
+
value: 1,
|
|
46086
|
+
range: { min: 1, max: 6 }
|
|
46087
|
+
};
|
|
46088
|
+
|
|
46089
|
+
class Dice extends BaseItem {
|
|
46090
|
+
itemType = "Dice";
|
|
46091
|
+
path;
|
|
46092
|
+
subject = new Subject;
|
|
46093
|
+
borderWidth = 1;
|
|
46094
|
+
isRotating = false;
|
|
46095
|
+
value = 1;
|
|
46096
|
+
range = { min: 1, max: 6 };
|
|
46097
|
+
constructor(board, id = "") {
|
|
46098
|
+
super(board, id, defaultDiceData);
|
|
46099
|
+
this.transformPath();
|
|
46100
|
+
this.transformation.subject.subscribe(() => {
|
|
46101
|
+
this.transformPath();
|
|
46102
|
+
this.updateMbr();
|
|
46103
|
+
this.subject.publish(this);
|
|
46104
|
+
});
|
|
46105
|
+
this.updateMbr();
|
|
46106
|
+
}
|
|
46107
|
+
transformPath() {
|
|
46108
|
+
this.path = createRoundedRectanglePath(this).copy();
|
|
46109
|
+
this.path.transform(this.transformation.matrix);
|
|
46110
|
+
this.path.setBackgroundColor(this.backgroundColor);
|
|
46111
|
+
this.path.setBorderColor(this.borderColor);
|
|
46112
|
+
this.path.setBorderWidth(this.borderWidth);
|
|
46113
|
+
}
|
|
46114
|
+
render(context) {
|
|
46115
|
+
if (this.transformationRenderBlock) {
|
|
46116
|
+
return;
|
|
46117
|
+
}
|
|
46118
|
+
context.ctx.save();
|
|
46119
|
+
if (this.isRotating) {
|
|
46120
|
+
const now = Date.now();
|
|
46121
|
+
const angle = now % 1000 / 1000 * 2 * Math.PI;
|
|
46122
|
+
const mbr2 = this.getMbr();
|
|
46123
|
+
const centerX2 = (mbr2.left + mbr2.right) / 2;
|
|
46124
|
+
const centerY2 = (mbr2.top + mbr2.bottom) / 2;
|
|
46125
|
+
context.ctx.translate(centerX2, centerY2);
|
|
46126
|
+
context.ctx.rotate(angle);
|
|
46127
|
+
context.ctx.translate(-centerX2, -centerY2);
|
|
46128
|
+
}
|
|
46129
|
+
this.path.render(context);
|
|
46130
|
+
const mbr = this.getMbr();
|
|
46131
|
+
const centerX = (mbr.left + mbr.right) / 2;
|
|
46132
|
+
const centerY = (mbr.top + mbr.bottom) / 2;
|
|
46133
|
+
context.ctx.fillStyle = "black";
|
|
46134
|
+
context.ctx.font = `bold ${this.getHeight() / 3}px sans-serif`;
|
|
46135
|
+
context.ctx.textAlign = "center";
|
|
46136
|
+
context.ctx.textBaseline = "middle";
|
|
46137
|
+
context.ctx.fillText(String(this.value), centerX, centerY);
|
|
46138
|
+
if (this.getLinkTo()) {
|
|
46139
|
+
const { top, right } = this.getMbr();
|
|
46140
|
+
this.linkTo.render(context, top, right, this.board.camera.getScale());
|
|
46141
|
+
}
|
|
46142
|
+
context.ctx.restore();
|
|
46143
|
+
}
|
|
46144
|
+
updateMbr() {
|
|
46145
|
+
const { left, top, right, bottom } = this.path.getMbr();
|
|
46146
|
+
this.left = left;
|
|
46147
|
+
this.right = right;
|
|
46148
|
+
this.top = top;
|
|
46149
|
+
this.bottom = bottom;
|
|
46150
|
+
}
|
|
46151
|
+
getPath() {
|
|
46152
|
+
return this.path.copy();
|
|
46153
|
+
}
|
|
46154
|
+
renderHTML(documentFactory) {
|
|
46155
|
+
const div = documentFactory.createElement("dice-item");
|
|
46156
|
+
return div;
|
|
46157
|
+
}
|
|
46158
|
+
deserialize(data) {
|
|
46159
|
+
super.deserialize(data);
|
|
46160
|
+
this.transformPath();
|
|
46161
|
+
this.subject.publish(this);
|
|
46162
|
+
return this;
|
|
46163
|
+
}
|
|
46164
|
+
isClosed() {
|
|
46165
|
+
return true;
|
|
46166
|
+
}
|
|
46167
|
+
applyBackgroundColor(backgroundColor) {
|
|
46168
|
+
this.backgroundColor = backgroundColor;
|
|
46169
|
+
this.path.setBackgroundColor(backgroundColor);
|
|
46170
|
+
}
|
|
46171
|
+
setBackgroundColor(backgroundColor) {
|
|
46172
|
+
this.emit({
|
|
46173
|
+
class: "Dice",
|
|
46174
|
+
method: "setBackgroundColor",
|
|
46175
|
+
item: [this.getId()],
|
|
46176
|
+
newData: { backgroundColor },
|
|
46177
|
+
prevData: { backgroundColor: this.backgroundColor }
|
|
46178
|
+
});
|
|
46179
|
+
}
|
|
46180
|
+
applyBorderWidth(borderWidth) {
|
|
46181
|
+
this.borderWidth = borderWidth;
|
|
46182
|
+
this.path.setBorderWidth(borderWidth);
|
|
46183
|
+
}
|
|
46184
|
+
setBorderWidth(borderWidth) {
|
|
46185
|
+
this.emit({
|
|
46186
|
+
class: "Dice",
|
|
46187
|
+
method: "setBorderWidth",
|
|
46188
|
+
item: [this.getId()],
|
|
46189
|
+
newData: { borderWidth },
|
|
46190
|
+
prevData: { borderWidth: this.borderWidth }
|
|
46191
|
+
});
|
|
46192
|
+
}
|
|
46193
|
+
applyBorderColor(borderColor) {
|
|
46194
|
+
this.borderColor = borderColor;
|
|
46195
|
+
this.path.setBorderColor(borderColor);
|
|
46196
|
+
}
|
|
46197
|
+
setBorderColor(borderColor) {
|
|
46198
|
+
this.emit({
|
|
46199
|
+
class: "Dice",
|
|
46200
|
+
method: "setBorderColor",
|
|
46201
|
+
item: [this.getId()],
|
|
46202
|
+
newData: { borderColor },
|
|
46203
|
+
prevData: { borderColor: this.borderColor }
|
|
46204
|
+
});
|
|
46205
|
+
}
|
|
46206
|
+
setIsRotating(isRotating) {
|
|
46207
|
+
this.emit({
|
|
46208
|
+
class: "Dice",
|
|
46209
|
+
method: "setIsRotating",
|
|
46210
|
+
item: [this.getId()],
|
|
46211
|
+
newData: { isRotating },
|
|
46212
|
+
prevData: { isRotating: false }
|
|
46213
|
+
});
|
|
46214
|
+
}
|
|
46215
|
+
setValuesRange(range) {
|
|
46216
|
+
this.emit({
|
|
46217
|
+
class: "Dice",
|
|
46218
|
+
method: "changeValuesRange",
|
|
46219
|
+
item: [this.getId()],
|
|
46220
|
+
newData: range,
|
|
46221
|
+
prevData: this.range
|
|
46222
|
+
});
|
|
46223
|
+
}
|
|
46224
|
+
setValue(value) {
|
|
46225
|
+
this.emit({
|
|
46226
|
+
class: "Dice",
|
|
46227
|
+
method: "changeValue",
|
|
46228
|
+
item: [this.getId()],
|
|
46229
|
+
newData: { value },
|
|
46230
|
+
prevData: { value: this.value }
|
|
46231
|
+
});
|
|
46232
|
+
}
|
|
46233
|
+
throwDice() {
|
|
46234
|
+
this.setIsRotating(true);
|
|
46235
|
+
setTimeout(() => {
|
|
46236
|
+
this.setValue(Math.ceil(Math.random() * (this.range.max - this.range.min)) + this.range.min);
|
|
46237
|
+
this.isRotating = false;
|
|
46238
|
+
}, TIMEOUT);
|
|
46239
|
+
}
|
|
46240
|
+
apply(op) {
|
|
46241
|
+
super.apply(op);
|
|
46242
|
+
switch (op.class) {
|
|
46243
|
+
case "Dice":
|
|
46244
|
+
switch (op.method) {
|
|
46245
|
+
case "setBorderWidth":
|
|
46246
|
+
this.applyBorderWidth(op.newData.borderWidth);
|
|
46247
|
+
break;
|
|
46248
|
+
case "setBackgroundColor":
|
|
46249
|
+
this.applyBackgroundColor(op.newData.backgroundColor);
|
|
46250
|
+
break;
|
|
46251
|
+
case "setBorderColor":
|
|
46252
|
+
this.applyBorderColor(op.newData.borderColor);
|
|
46253
|
+
break;
|
|
46254
|
+
case "setIsRotating":
|
|
46255
|
+
this.isRotating = op.newData.isRotating;
|
|
46256
|
+
if (op.newData.isRotating) {
|
|
46257
|
+
setTimeout(() => {
|
|
46258
|
+
this.isRotating = false;
|
|
46259
|
+
}, TIMEOUT);
|
|
46260
|
+
}
|
|
46261
|
+
break;
|
|
46262
|
+
case "changeValue":
|
|
46263
|
+
this.value = op.newData.value;
|
|
46264
|
+
this.isRotating = false;
|
|
46265
|
+
break;
|
|
46266
|
+
case "changeValuesRange":
|
|
46267
|
+
this.range = op.newData;
|
|
46268
|
+
break;
|
|
46269
|
+
}
|
|
46270
|
+
break;
|
|
46271
|
+
}
|
|
46272
|
+
this.subject.publish(this);
|
|
46273
|
+
}
|
|
46274
|
+
}
|
|
46275
|
+
registerItem({
|
|
46276
|
+
item: Dice,
|
|
46277
|
+
defaultData: defaultDiceData,
|
|
46278
|
+
toolData: { name: "AddDice", tool: ShapeTool }
|
|
46279
|
+
});
|
|
46075
46280
|
// src/Pointer/Cursor.ts
|
|
46076
46281
|
var defaultCursors = [
|
|
46077
46282
|
"default",
|
|
@@ -56181,6 +56386,7 @@ export {
|
|
|
56181
56386
|
EditorContainer,
|
|
56182
56387
|
DrawingContext,
|
|
56183
56388
|
Drawing,
|
|
56389
|
+
Dice,
|
|
56184
56390
|
DefaultTransformationData,
|
|
56185
56391
|
DefaultShapeData,
|
|
56186
56392
|
Deck,
|
package/dist/esm/index.js
CHANGED
|
@@ -46065,6 +46065,211 @@ registerItem({
|
|
|
46065
46065
|
item: Deck,
|
|
46066
46066
|
defaultData: defaultDeckData
|
|
46067
46067
|
});
|
|
46068
|
+
// src/Items/Examples/CardGame/Dice/Dice.ts
|
|
46069
|
+
var TIMEOUT = 3000;
|
|
46070
|
+
var defaultDiceData = {
|
|
46071
|
+
itemType: "Dice",
|
|
46072
|
+
backgroundColor: "#000207",
|
|
46073
|
+
backgroundOpacity: 1,
|
|
46074
|
+
borderColor: "#000207",
|
|
46075
|
+
borderOpacity: 1,
|
|
46076
|
+
borderStyle: "solid",
|
|
46077
|
+
borderWidth: 1,
|
|
46078
|
+
value: 1,
|
|
46079
|
+
range: { min: 1, max: 6 }
|
|
46080
|
+
};
|
|
46081
|
+
|
|
46082
|
+
class Dice extends BaseItem {
|
|
46083
|
+
itemType = "Dice";
|
|
46084
|
+
path;
|
|
46085
|
+
subject = new Subject;
|
|
46086
|
+
borderWidth = 1;
|
|
46087
|
+
isRotating = false;
|
|
46088
|
+
value = 1;
|
|
46089
|
+
range = { min: 1, max: 6 };
|
|
46090
|
+
constructor(board, id = "") {
|
|
46091
|
+
super(board, id, defaultDiceData);
|
|
46092
|
+
this.transformPath();
|
|
46093
|
+
this.transformation.subject.subscribe(() => {
|
|
46094
|
+
this.transformPath();
|
|
46095
|
+
this.updateMbr();
|
|
46096
|
+
this.subject.publish(this);
|
|
46097
|
+
});
|
|
46098
|
+
this.updateMbr();
|
|
46099
|
+
}
|
|
46100
|
+
transformPath() {
|
|
46101
|
+
this.path = createRoundedRectanglePath(this).copy();
|
|
46102
|
+
this.path.transform(this.transformation.matrix);
|
|
46103
|
+
this.path.setBackgroundColor(this.backgroundColor);
|
|
46104
|
+
this.path.setBorderColor(this.borderColor);
|
|
46105
|
+
this.path.setBorderWidth(this.borderWidth);
|
|
46106
|
+
}
|
|
46107
|
+
render(context) {
|
|
46108
|
+
if (this.transformationRenderBlock) {
|
|
46109
|
+
return;
|
|
46110
|
+
}
|
|
46111
|
+
context.ctx.save();
|
|
46112
|
+
if (this.isRotating) {
|
|
46113
|
+
const now = Date.now();
|
|
46114
|
+
const angle = now % 1000 / 1000 * 2 * Math.PI;
|
|
46115
|
+
const mbr2 = this.getMbr();
|
|
46116
|
+
const centerX2 = (mbr2.left + mbr2.right) / 2;
|
|
46117
|
+
const centerY2 = (mbr2.top + mbr2.bottom) / 2;
|
|
46118
|
+
context.ctx.translate(centerX2, centerY2);
|
|
46119
|
+
context.ctx.rotate(angle);
|
|
46120
|
+
context.ctx.translate(-centerX2, -centerY2);
|
|
46121
|
+
}
|
|
46122
|
+
this.path.render(context);
|
|
46123
|
+
const mbr = this.getMbr();
|
|
46124
|
+
const centerX = (mbr.left + mbr.right) / 2;
|
|
46125
|
+
const centerY = (mbr.top + mbr.bottom) / 2;
|
|
46126
|
+
context.ctx.fillStyle = "black";
|
|
46127
|
+
context.ctx.font = `bold ${this.getHeight() / 3}px sans-serif`;
|
|
46128
|
+
context.ctx.textAlign = "center";
|
|
46129
|
+
context.ctx.textBaseline = "middle";
|
|
46130
|
+
context.ctx.fillText(String(this.value), centerX, centerY);
|
|
46131
|
+
if (this.getLinkTo()) {
|
|
46132
|
+
const { top, right } = this.getMbr();
|
|
46133
|
+
this.linkTo.render(context, top, right, this.board.camera.getScale());
|
|
46134
|
+
}
|
|
46135
|
+
context.ctx.restore();
|
|
46136
|
+
}
|
|
46137
|
+
updateMbr() {
|
|
46138
|
+
const { left, top, right, bottom } = this.path.getMbr();
|
|
46139
|
+
this.left = left;
|
|
46140
|
+
this.right = right;
|
|
46141
|
+
this.top = top;
|
|
46142
|
+
this.bottom = bottom;
|
|
46143
|
+
}
|
|
46144
|
+
getPath() {
|
|
46145
|
+
return this.path.copy();
|
|
46146
|
+
}
|
|
46147
|
+
renderHTML(documentFactory) {
|
|
46148
|
+
const div = documentFactory.createElement("dice-item");
|
|
46149
|
+
return div;
|
|
46150
|
+
}
|
|
46151
|
+
deserialize(data) {
|
|
46152
|
+
super.deserialize(data);
|
|
46153
|
+
this.transformPath();
|
|
46154
|
+
this.subject.publish(this);
|
|
46155
|
+
return this;
|
|
46156
|
+
}
|
|
46157
|
+
isClosed() {
|
|
46158
|
+
return true;
|
|
46159
|
+
}
|
|
46160
|
+
applyBackgroundColor(backgroundColor) {
|
|
46161
|
+
this.backgroundColor = backgroundColor;
|
|
46162
|
+
this.path.setBackgroundColor(backgroundColor);
|
|
46163
|
+
}
|
|
46164
|
+
setBackgroundColor(backgroundColor) {
|
|
46165
|
+
this.emit({
|
|
46166
|
+
class: "Dice",
|
|
46167
|
+
method: "setBackgroundColor",
|
|
46168
|
+
item: [this.getId()],
|
|
46169
|
+
newData: { backgroundColor },
|
|
46170
|
+
prevData: { backgroundColor: this.backgroundColor }
|
|
46171
|
+
});
|
|
46172
|
+
}
|
|
46173
|
+
applyBorderWidth(borderWidth) {
|
|
46174
|
+
this.borderWidth = borderWidth;
|
|
46175
|
+
this.path.setBorderWidth(borderWidth);
|
|
46176
|
+
}
|
|
46177
|
+
setBorderWidth(borderWidth) {
|
|
46178
|
+
this.emit({
|
|
46179
|
+
class: "Dice",
|
|
46180
|
+
method: "setBorderWidth",
|
|
46181
|
+
item: [this.getId()],
|
|
46182
|
+
newData: { borderWidth },
|
|
46183
|
+
prevData: { borderWidth: this.borderWidth }
|
|
46184
|
+
});
|
|
46185
|
+
}
|
|
46186
|
+
applyBorderColor(borderColor) {
|
|
46187
|
+
this.borderColor = borderColor;
|
|
46188
|
+
this.path.setBorderColor(borderColor);
|
|
46189
|
+
}
|
|
46190
|
+
setBorderColor(borderColor) {
|
|
46191
|
+
this.emit({
|
|
46192
|
+
class: "Dice",
|
|
46193
|
+
method: "setBorderColor",
|
|
46194
|
+
item: [this.getId()],
|
|
46195
|
+
newData: { borderColor },
|
|
46196
|
+
prevData: { borderColor: this.borderColor }
|
|
46197
|
+
});
|
|
46198
|
+
}
|
|
46199
|
+
setIsRotating(isRotating) {
|
|
46200
|
+
this.emit({
|
|
46201
|
+
class: "Dice",
|
|
46202
|
+
method: "setIsRotating",
|
|
46203
|
+
item: [this.getId()],
|
|
46204
|
+
newData: { isRotating },
|
|
46205
|
+
prevData: { isRotating: false }
|
|
46206
|
+
});
|
|
46207
|
+
}
|
|
46208
|
+
setValuesRange(range) {
|
|
46209
|
+
this.emit({
|
|
46210
|
+
class: "Dice",
|
|
46211
|
+
method: "changeValuesRange",
|
|
46212
|
+
item: [this.getId()],
|
|
46213
|
+
newData: range,
|
|
46214
|
+
prevData: this.range
|
|
46215
|
+
});
|
|
46216
|
+
}
|
|
46217
|
+
setValue(value) {
|
|
46218
|
+
this.emit({
|
|
46219
|
+
class: "Dice",
|
|
46220
|
+
method: "changeValue",
|
|
46221
|
+
item: [this.getId()],
|
|
46222
|
+
newData: { value },
|
|
46223
|
+
prevData: { value: this.value }
|
|
46224
|
+
});
|
|
46225
|
+
}
|
|
46226
|
+
throwDice() {
|
|
46227
|
+
this.setIsRotating(true);
|
|
46228
|
+
setTimeout(() => {
|
|
46229
|
+
this.setValue(Math.ceil(Math.random() * (this.range.max - this.range.min)) + this.range.min);
|
|
46230
|
+
this.isRotating = false;
|
|
46231
|
+
}, TIMEOUT);
|
|
46232
|
+
}
|
|
46233
|
+
apply(op) {
|
|
46234
|
+
super.apply(op);
|
|
46235
|
+
switch (op.class) {
|
|
46236
|
+
case "Dice":
|
|
46237
|
+
switch (op.method) {
|
|
46238
|
+
case "setBorderWidth":
|
|
46239
|
+
this.applyBorderWidth(op.newData.borderWidth);
|
|
46240
|
+
break;
|
|
46241
|
+
case "setBackgroundColor":
|
|
46242
|
+
this.applyBackgroundColor(op.newData.backgroundColor);
|
|
46243
|
+
break;
|
|
46244
|
+
case "setBorderColor":
|
|
46245
|
+
this.applyBorderColor(op.newData.borderColor);
|
|
46246
|
+
break;
|
|
46247
|
+
case "setIsRotating":
|
|
46248
|
+
this.isRotating = op.newData.isRotating;
|
|
46249
|
+
if (op.newData.isRotating) {
|
|
46250
|
+
setTimeout(() => {
|
|
46251
|
+
this.isRotating = false;
|
|
46252
|
+
}, TIMEOUT);
|
|
46253
|
+
}
|
|
46254
|
+
break;
|
|
46255
|
+
case "changeValue":
|
|
46256
|
+
this.value = op.newData.value;
|
|
46257
|
+
this.isRotating = false;
|
|
46258
|
+
break;
|
|
46259
|
+
case "changeValuesRange":
|
|
46260
|
+
this.range = op.newData;
|
|
46261
|
+
break;
|
|
46262
|
+
}
|
|
46263
|
+
break;
|
|
46264
|
+
}
|
|
46265
|
+
this.subject.publish(this);
|
|
46266
|
+
}
|
|
46267
|
+
}
|
|
46268
|
+
registerItem({
|
|
46269
|
+
item: Dice,
|
|
46270
|
+
defaultData: defaultDiceData,
|
|
46271
|
+
toolData: { name: "AddDice", tool: ShapeTool }
|
|
46272
|
+
});
|
|
46068
46273
|
// src/Pointer/Cursor.ts
|
|
46069
46274
|
var defaultCursors = [
|
|
46070
46275
|
"default",
|
|
@@ -56079,6 +56284,7 @@ export {
|
|
|
56079
56284
|
EditorContainer,
|
|
56080
56285
|
DrawingContext,
|
|
56081
56286
|
Drawing,
|
|
56287
|
+
Dice,
|
|
56082
56288
|
DefaultTransformationData,
|
|
56083
56289
|
DefaultShapeData,
|
|
56084
56290
|
Deck,
|
package/dist/esm/node.js
CHANGED
|
@@ -48600,6 +48600,211 @@ registerItem({
|
|
|
48600
48600
|
item: Deck,
|
|
48601
48601
|
defaultData: defaultDeckData
|
|
48602
48602
|
});
|
|
48603
|
+
// src/Items/Examples/CardGame/Dice/Dice.ts
|
|
48604
|
+
var TIMEOUT = 3000;
|
|
48605
|
+
var defaultDiceData = {
|
|
48606
|
+
itemType: "Dice",
|
|
48607
|
+
backgroundColor: "#000207",
|
|
48608
|
+
backgroundOpacity: 1,
|
|
48609
|
+
borderColor: "#000207",
|
|
48610
|
+
borderOpacity: 1,
|
|
48611
|
+
borderStyle: "solid",
|
|
48612
|
+
borderWidth: 1,
|
|
48613
|
+
value: 1,
|
|
48614
|
+
range: { min: 1, max: 6 }
|
|
48615
|
+
};
|
|
48616
|
+
|
|
48617
|
+
class Dice extends BaseItem {
|
|
48618
|
+
itemType = "Dice";
|
|
48619
|
+
path;
|
|
48620
|
+
subject = new Subject;
|
|
48621
|
+
borderWidth = 1;
|
|
48622
|
+
isRotating = false;
|
|
48623
|
+
value = 1;
|
|
48624
|
+
range = { min: 1, max: 6 };
|
|
48625
|
+
constructor(board, id = "") {
|
|
48626
|
+
super(board, id, defaultDiceData);
|
|
48627
|
+
this.transformPath();
|
|
48628
|
+
this.transformation.subject.subscribe(() => {
|
|
48629
|
+
this.transformPath();
|
|
48630
|
+
this.updateMbr();
|
|
48631
|
+
this.subject.publish(this);
|
|
48632
|
+
});
|
|
48633
|
+
this.updateMbr();
|
|
48634
|
+
}
|
|
48635
|
+
transformPath() {
|
|
48636
|
+
this.path = createRoundedRectanglePath(this).copy();
|
|
48637
|
+
this.path.transform(this.transformation.matrix);
|
|
48638
|
+
this.path.setBackgroundColor(this.backgroundColor);
|
|
48639
|
+
this.path.setBorderColor(this.borderColor);
|
|
48640
|
+
this.path.setBorderWidth(this.borderWidth);
|
|
48641
|
+
}
|
|
48642
|
+
render(context) {
|
|
48643
|
+
if (this.transformationRenderBlock) {
|
|
48644
|
+
return;
|
|
48645
|
+
}
|
|
48646
|
+
context.ctx.save();
|
|
48647
|
+
if (this.isRotating) {
|
|
48648
|
+
const now = Date.now();
|
|
48649
|
+
const angle = now % 1000 / 1000 * 2 * Math.PI;
|
|
48650
|
+
const mbr2 = this.getMbr();
|
|
48651
|
+
const centerX2 = (mbr2.left + mbr2.right) / 2;
|
|
48652
|
+
const centerY2 = (mbr2.top + mbr2.bottom) / 2;
|
|
48653
|
+
context.ctx.translate(centerX2, centerY2);
|
|
48654
|
+
context.ctx.rotate(angle);
|
|
48655
|
+
context.ctx.translate(-centerX2, -centerY2);
|
|
48656
|
+
}
|
|
48657
|
+
this.path.render(context);
|
|
48658
|
+
const mbr = this.getMbr();
|
|
48659
|
+
const centerX = (mbr.left + mbr.right) / 2;
|
|
48660
|
+
const centerY = (mbr.top + mbr.bottom) / 2;
|
|
48661
|
+
context.ctx.fillStyle = "black";
|
|
48662
|
+
context.ctx.font = `bold ${this.getHeight() / 3}px sans-serif`;
|
|
48663
|
+
context.ctx.textAlign = "center";
|
|
48664
|
+
context.ctx.textBaseline = "middle";
|
|
48665
|
+
context.ctx.fillText(String(this.value), centerX, centerY);
|
|
48666
|
+
if (this.getLinkTo()) {
|
|
48667
|
+
const { top, right } = this.getMbr();
|
|
48668
|
+
this.linkTo.render(context, top, right, this.board.camera.getScale());
|
|
48669
|
+
}
|
|
48670
|
+
context.ctx.restore();
|
|
48671
|
+
}
|
|
48672
|
+
updateMbr() {
|
|
48673
|
+
const { left, top, right, bottom } = this.path.getMbr();
|
|
48674
|
+
this.left = left;
|
|
48675
|
+
this.right = right;
|
|
48676
|
+
this.top = top;
|
|
48677
|
+
this.bottom = bottom;
|
|
48678
|
+
}
|
|
48679
|
+
getPath() {
|
|
48680
|
+
return this.path.copy();
|
|
48681
|
+
}
|
|
48682
|
+
renderHTML(documentFactory) {
|
|
48683
|
+
const div = documentFactory.createElement("dice-item");
|
|
48684
|
+
return div;
|
|
48685
|
+
}
|
|
48686
|
+
deserialize(data) {
|
|
48687
|
+
super.deserialize(data);
|
|
48688
|
+
this.transformPath();
|
|
48689
|
+
this.subject.publish(this);
|
|
48690
|
+
return this;
|
|
48691
|
+
}
|
|
48692
|
+
isClosed() {
|
|
48693
|
+
return true;
|
|
48694
|
+
}
|
|
48695
|
+
applyBackgroundColor(backgroundColor) {
|
|
48696
|
+
this.backgroundColor = backgroundColor;
|
|
48697
|
+
this.path.setBackgroundColor(backgroundColor);
|
|
48698
|
+
}
|
|
48699
|
+
setBackgroundColor(backgroundColor) {
|
|
48700
|
+
this.emit({
|
|
48701
|
+
class: "Dice",
|
|
48702
|
+
method: "setBackgroundColor",
|
|
48703
|
+
item: [this.getId()],
|
|
48704
|
+
newData: { backgroundColor },
|
|
48705
|
+
prevData: { backgroundColor: this.backgroundColor }
|
|
48706
|
+
});
|
|
48707
|
+
}
|
|
48708
|
+
applyBorderWidth(borderWidth) {
|
|
48709
|
+
this.borderWidth = borderWidth;
|
|
48710
|
+
this.path.setBorderWidth(borderWidth);
|
|
48711
|
+
}
|
|
48712
|
+
setBorderWidth(borderWidth) {
|
|
48713
|
+
this.emit({
|
|
48714
|
+
class: "Dice",
|
|
48715
|
+
method: "setBorderWidth",
|
|
48716
|
+
item: [this.getId()],
|
|
48717
|
+
newData: { borderWidth },
|
|
48718
|
+
prevData: { borderWidth: this.borderWidth }
|
|
48719
|
+
});
|
|
48720
|
+
}
|
|
48721
|
+
applyBorderColor(borderColor) {
|
|
48722
|
+
this.borderColor = borderColor;
|
|
48723
|
+
this.path.setBorderColor(borderColor);
|
|
48724
|
+
}
|
|
48725
|
+
setBorderColor(borderColor) {
|
|
48726
|
+
this.emit({
|
|
48727
|
+
class: "Dice",
|
|
48728
|
+
method: "setBorderColor",
|
|
48729
|
+
item: [this.getId()],
|
|
48730
|
+
newData: { borderColor },
|
|
48731
|
+
prevData: { borderColor: this.borderColor }
|
|
48732
|
+
});
|
|
48733
|
+
}
|
|
48734
|
+
setIsRotating(isRotating) {
|
|
48735
|
+
this.emit({
|
|
48736
|
+
class: "Dice",
|
|
48737
|
+
method: "setIsRotating",
|
|
48738
|
+
item: [this.getId()],
|
|
48739
|
+
newData: { isRotating },
|
|
48740
|
+
prevData: { isRotating: false }
|
|
48741
|
+
});
|
|
48742
|
+
}
|
|
48743
|
+
setValuesRange(range) {
|
|
48744
|
+
this.emit({
|
|
48745
|
+
class: "Dice",
|
|
48746
|
+
method: "changeValuesRange",
|
|
48747
|
+
item: [this.getId()],
|
|
48748
|
+
newData: range,
|
|
48749
|
+
prevData: this.range
|
|
48750
|
+
});
|
|
48751
|
+
}
|
|
48752
|
+
setValue(value) {
|
|
48753
|
+
this.emit({
|
|
48754
|
+
class: "Dice",
|
|
48755
|
+
method: "changeValue",
|
|
48756
|
+
item: [this.getId()],
|
|
48757
|
+
newData: { value },
|
|
48758
|
+
prevData: { value: this.value }
|
|
48759
|
+
});
|
|
48760
|
+
}
|
|
48761
|
+
throwDice() {
|
|
48762
|
+
this.setIsRotating(true);
|
|
48763
|
+
setTimeout(() => {
|
|
48764
|
+
this.setValue(Math.ceil(Math.random() * (this.range.max - this.range.min)) + this.range.min);
|
|
48765
|
+
this.isRotating = false;
|
|
48766
|
+
}, TIMEOUT);
|
|
48767
|
+
}
|
|
48768
|
+
apply(op) {
|
|
48769
|
+
super.apply(op);
|
|
48770
|
+
switch (op.class) {
|
|
48771
|
+
case "Dice":
|
|
48772
|
+
switch (op.method) {
|
|
48773
|
+
case "setBorderWidth":
|
|
48774
|
+
this.applyBorderWidth(op.newData.borderWidth);
|
|
48775
|
+
break;
|
|
48776
|
+
case "setBackgroundColor":
|
|
48777
|
+
this.applyBackgroundColor(op.newData.backgroundColor);
|
|
48778
|
+
break;
|
|
48779
|
+
case "setBorderColor":
|
|
48780
|
+
this.applyBorderColor(op.newData.borderColor);
|
|
48781
|
+
break;
|
|
48782
|
+
case "setIsRotating":
|
|
48783
|
+
this.isRotating = op.newData.isRotating;
|
|
48784
|
+
if (op.newData.isRotating) {
|
|
48785
|
+
setTimeout(() => {
|
|
48786
|
+
this.isRotating = false;
|
|
48787
|
+
}, TIMEOUT);
|
|
48788
|
+
}
|
|
48789
|
+
break;
|
|
48790
|
+
case "changeValue":
|
|
48791
|
+
this.value = op.newData.value;
|
|
48792
|
+
this.isRotating = false;
|
|
48793
|
+
break;
|
|
48794
|
+
case "changeValuesRange":
|
|
48795
|
+
this.range = op.newData;
|
|
48796
|
+
break;
|
|
48797
|
+
}
|
|
48798
|
+
break;
|
|
48799
|
+
}
|
|
48800
|
+
this.subject.publish(this);
|
|
48801
|
+
}
|
|
48802
|
+
}
|
|
48803
|
+
registerItem({
|
|
48804
|
+
item: Dice,
|
|
48805
|
+
defaultData: defaultDiceData,
|
|
48806
|
+
toolData: { name: "AddDice", tool: ShapeTool }
|
|
48807
|
+
});
|
|
48603
48808
|
// src/Pointer/Cursor.ts
|
|
48604
48809
|
var defaultCursors = [
|
|
48605
48810
|
"default",
|
|
@@ -58714,6 +58919,7 @@ export {
|
|
|
58714
58919
|
EditorContainer,
|
|
58715
58920
|
DrawingContext,
|
|
58716
58921
|
Drawing,
|
|
58922
|
+
Dice,
|
|
58717
58923
|
DefaultTransformationData,
|
|
58718
58924
|
DefaultShapeData,
|
|
58719
58925
|
Deck,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BaseItem, BaseItemData, SerializedItemData } from "../../../BaseItem/BaseItem";
|
|
2
|
+
import { BorderWidth, Path } from "../../../Path";
|
|
3
|
+
import { Subject } from "../../../../Subject";
|
|
4
|
+
import { Board } from "../../../../Board";
|
|
5
|
+
import { DrawingContext } from "../../../DrawingContext";
|
|
6
|
+
import { DocumentFactory } from "../../../../api/DocumentFactory";
|
|
7
|
+
import { DiceOperation } from "./DiceOperation";
|
|
8
|
+
export declare const defaultDiceData: BaseItemData;
|
|
9
|
+
export declare class Dice extends BaseItem {
|
|
10
|
+
readonly itemType = "Dice";
|
|
11
|
+
private path;
|
|
12
|
+
readonly subject: Subject<Dice>;
|
|
13
|
+
private borderWidth;
|
|
14
|
+
isRotating: boolean;
|
|
15
|
+
value: number;
|
|
16
|
+
range: {
|
|
17
|
+
min: number;
|
|
18
|
+
max: number;
|
|
19
|
+
};
|
|
20
|
+
constructor(board: Board, id?: string);
|
|
21
|
+
private transformPath;
|
|
22
|
+
render(context: DrawingContext): void;
|
|
23
|
+
updateMbr(): void;
|
|
24
|
+
getPath(): Path;
|
|
25
|
+
renderHTML(documentFactory: DocumentFactory): HTMLElement;
|
|
26
|
+
deserialize(data: SerializedItemData): this;
|
|
27
|
+
isClosed(): boolean;
|
|
28
|
+
private applyBackgroundColor;
|
|
29
|
+
setBackgroundColor(backgroundColor: string): void;
|
|
30
|
+
private applyBorderWidth;
|
|
31
|
+
setBorderWidth(borderWidth: BorderWidth): void;
|
|
32
|
+
private applyBorderColor;
|
|
33
|
+
setBorderColor(borderColor: string): void;
|
|
34
|
+
setIsRotating(isRotating: boolean): void;
|
|
35
|
+
setValuesRange(range: {
|
|
36
|
+
min: number;
|
|
37
|
+
max: number;
|
|
38
|
+
}): void;
|
|
39
|
+
setValue(value: number): void;
|
|
40
|
+
throwDice(): void;
|
|
41
|
+
apply(op: DiceOperation): void;
|
|
42
|
+
}
|