microboard-temp 0.4.68 → 0.4.70
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 +152 -129
- package/dist/cjs/index.js +152 -129
- package/dist/cjs/node.js +152 -129
- package/dist/esm/browser.js +152 -129
- package/dist/esm/index.js +152 -129
- package/dist/esm/node.js +152 -129
- package/dist/types/Items/Examples/CardGame/Card/Card.d.ts +1 -10
- package/dist/types/Items/Examples/CardGame/Deck/Deck.d.ts +2 -7
- package/dist/types/Items/Examples/CardGame/Hand/Hand.d.ts +15 -2
- package/dist/types/Items/Examples/CardGame/Hand/HandOperation.d.ts +21 -0
- package/package.json +1 -1
package/dist/cjs/node.js
CHANGED
|
@@ -50262,8 +50262,7 @@ var defaultCardData = {
|
|
|
50262
50262
|
itemType: "Card",
|
|
50263
50263
|
isOpen: false,
|
|
50264
50264
|
faceUrl: "",
|
|
50265
|
-
backsideUrl: ""
|
|
50266
|
-
isInDeck: false
|
|
50265
|
+
backsideUrl: ""
|
|
50267
50266
|
};
|
|
50268
50267
|
var CARD_DIMENSIONS = { width: 250, height: 400 };
|
|
50269
50268
|
|
|
@@ -50272,7 +50271,6 @@ class Card extends BaseItem {
|
|
|
50272
50271
|
faceUrl = "";
|
|
50273
50272
|
backsideUrl = "";
|
|
50274
50273
|
isOpen = false;
|
|
50275
|
-
isInDeck = false;
|
|
50276
50274
|
throttledBringToFront;
|
|
50277
50275
|
face = null;
|
|
50278
50276
|
backside = null;
|
|
@@ -50308,35 +50306,20 @@ class Card extends BaseItem {
|
|
|
50308
50306
|
};
|
|
50309
50307
|
this.updateImageToRender();
|
|
50310
50308
|
}
|
|
50311
|
-
setIsInDeck(isInDeck) {
|
|
50312
|
-
this.emit({
|
|
50313
|
-
class: "Card",
|
|
50314
|
-
method: "setIsInDeck",
|
|
50315
|
-
item: [this.getId()],
|
|
50316
|
-
newData: { isInDeck },
|
|
50317
|
-
prevData: { isInDeck: this.isInDeck }
|
|
50318
|
-
});
|
|
50319
|
-
}
|
|
50320
50309
|
updateImageToRender() {
|
|
50321
50310
|
this.imageToRender = this.backside;
|
|
50322
50311
|
if (this.isOpen) {
|
|
50323
50312
|
this.imageToRender = this.face;
|
|
50324
50313
|
}
|
|
50325
50314
|
}
|
|
50326
|
-
render(context
|
|
50327
|
-
if (this.transformationRenderBlock
|
|
50315
|
+
render(context) {
|
|
50316
|
+
if (this.transformationRenderBlock) {
|
|
50328
50317
|
return;
|
|
50329
50318
|
}
|
|
50330
50319
|
const ctx = context.ctx;
|
|
50331
50320
|
if (this.imageToRender && this.imageToRender.complete) {
|
|
50332
50321
|
ctx.save();
|
|
50333
|
-
|
|
50334
|
-
let top = this.top;
|
|
50335
|
-
if (deckRenderData) {
|
|
50336
|
-
left = deckRenderData.left + 2 * deckRenderData.cardPosition;
|
|
50337
|
-
top = deckRenderData.top;
|
|
50338
|
-
}
|
|
50339
|
-
ctx.drawImage(this.imageToRender, left, top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
|
|
50322
|
+
ctx.drawImage(this.imageToRender, this.left, this.top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
|
|
50340
50323
|
ctx.restore();
|
|
50341
50324
|
}
|
|
50342
50325
|
}
|
|
@@ -50347,12 +50330,6 @@ class Card extends BaseItem {
|
|
|
50347
50330
|
this.right = this.left + CARD_DIMENSIONS.width * scaleX;
|
|
50348
50331
|
this.bottom = this.top + CARD_DIMENSIONS.height * scaleY;
|
|
50349
50332
|
}
|
|
50350
|
-
getMbr() {
|
|
50351
|
-
if (this.isInDeck) {
|
|
50352
|
-
return new Mbr(1e4, 1e4, 1e4, 1e4);
|
|
50353
|
-
}
|
|
50354
|
-
return super.getMbr();
|
|
50355
|
-
}
|
|
50356
50333
|
getPath() {
|
|
50357
50334
|
return new Path(this.getMbr().getLines());
|
|
50358
50335
|
}
|
|
@@ -50385,9 +50362,6 @@ class Card extends BaseItem {
|
|
|
50385
50362
|
this.isOpen = op.newData.isOpen;
|
|
50386
50363
|
this.updateImageToRender();
|
|
50387
50364
|
break;
|
|
50388
|
-
case "setIsInDeck":
|
|
50389
|
-
this.isInDeck = op.newData.isInDeck;
|
|
50390
|
-
break;
|
|
50391
50365
|
}
|
|
50392
50366
|
break;
|
|
50393
50367
|
}
|
|
@@ -50400,22 +50374,17 @@ registerItem({
|
|
|
50400
50374
|
});
|
|
50401
50375
|
// src/Items/Examples/CardGame/Deck/Deck.ts
|
|
50402
50376
|
var defaultDeckData = {
|
|
50403
|
-
itemType: "Deck"
|
|
50404
|
-
cardIds: []
|
|
50377
|
+
itemType: "Deck"
|
|
50405
50378
|
};
|
|
50406
50379
|
|
|
50407
50380
|
class Deck extends BaseItem {
|
|
50408
50381
|
subject = new Subject;
|
|
50409
50382
|
shouldUseCustomRender = false;
|
|
50410
|
-
cardIds = [];
|
|
50411
|
-
cards = [];
|
|
50412
50383
|
constructor(board, id = "", defaultData2, cards) {
|
|
50413
|
-
super(board, id, defaultDeckData);
|
|
50384
|
+
super(board, id, defaultDeckData, true);
|
|
50414
50385
|
if (cards) {
|
|
50415
|
-
this.cards = cards;
|
|
50416
|
-
cards.forEach((card) => card.setIsInDeck(true));
|
|
50417
50386
|
this.transformation.matrix = cards[cards.length - 1].transformation.matrix;
|
|
50418
|
-
this.
|
|
50387
|
+
this.applyAddChildren(cards.map((card) => card.getId()));
|
|
50419
50388
|
}
|
|
50420
50389
|
this.transformation.subject.subscribe(() => {
|
|
50421
50390
|
this.updateMbr();
|
|
@@ -50423,128 +50392,113 @@ class Deck extends BaseItem {
|
|
|
50423
50392
|
});
|
|
50424
50393
|
this.updateMbr();
|
|
50425
50394
|
}
|
|
50395
|
+
applyAddChildren(childIds) {
|
|
50396
|
+
if (!this.index) {
|
|
50397
|
+
return;
|
|
50398
|
+
}
|
|
50399
|
+
childIds.forEach((childId) => {
|
|
50400
|
+
const foundItem = this.board.items.getById(childId);
|
|
50401
|
+
if (this.parent !== childId && this.getId() !== childId) {
|
|
50402
|
+
if (!this.index?.getById(childId) && foundItem && foundItem.itemType === "Card") {
|
|
50403
|
+
foundItem.transformation.apply({
|
|
50404
|
+
class: "Transformation",
|
|
50405
|
+
method: "translateTo",
|
|
50406
|
+
item: [this.id],
|
|
50407
|
+
x: this.left + (this.index?.list().length || 0) * 2,
|
|
50408
|
+
y: this.top
|
|
50409
|
+
});
|
|
50410
|
+
foundItem.parent = this.getId();
|
|
50411
|
+
this.board.items.index.remove(foundItem);
|
|
50412
|
+
this.index?.insert(foundItem);
|
|
50413
|
+
}
|
|
50414
|
+
}
|
|
50415
|
+
});
|
|
50416
|
+
this.updateMbr();
|
|
50417
|
+
this.subject.publish(this);
|
|
50418
|
+
}
|
|
50419
|
+
applyRemoveChildren(childIds) {
|
|
50420
|
+
if (!this.index) {
|
|
50421
|
+
return;
|
|
50422
|
+
}
|
|
50423
|
+
childIds.forEach((childId) => {
|
|
50424
|
+
const foundItem = this.index?.getById(childId);
|
|
50425
|
+
if (this.parent !== childId && this.getId() !== childId) {
|
|
50426
|
+
if (foundItem) {
|
|
50427
|
+
foundItem.transformation.apply({
|
|
50428
|
+
class: "Transformation",
|
|
50429
|
+
method: "translateTo",
|
|
50430
|
+
item: [this.id],
|
|
50431
|
+
x: this.left,
|
|
50432
|
+
y: this.top - this.getHeight() / 2
|
|
50433
|
+
});
|
|
50434
|
+
foundItem.parent = "Board";
|
|
50435
|
+
this.index?.remove(foundItem);
|
|
50436
|
+
this.board.items.index.insert(foundItem);
|
|
50437
|
+
}
|
|
50438
|
+
}
|
|
50439
|
+
});
|
|
50440
|
+
this.updateMbr();
|
|
50441
|
+
this.subject.publish(this);
|
|
50442
|
+
}
|
|
50426
50443
|
getDeck() {
|
|
50427
|
-
return this.
|
|
50444
|
+
return this.index?.list() || [];
|
|
50428
50445
|
}
|
|
50429
50446
|
getTopCard() {
|
|
50430
|
-
const
|
|
50431
|
-
|
|
50447
|
+
const card = this.index?.list()[this.index?.list().length - 1];
|
|
50448
|
+
if (card) {
|
|
50449
|
+
this.removeChildItems(card);
|
|
50450
|
+
return card;
|
|
50451
|
+
}
|
|
50432
50452
|
}
|
|
50433
50453
|
getBottomCard() {
|
|
50434
|
-
const
|
|
50435
|
-
|
|
50454
|
+
const card = this.index?.list()[0];
|
|
50455
|
+
if (card) {
|
|
50456
|
+
this.removeChildItems(card);
|
|
50457
|
+
return card;
|
|
50458
|
+
}
|
|
50436
50459
|
}
|
|
50437
50460
|
getRandomCard() {
|
|
50438
|
-
const
|
|
50439
|
-
|
|
50440
|
-
|
|
50441
|
-
|
|
50442
|
-
const cards = this.findCardsOnBoard(cardIds);
|
|
50443
|
-
this.removeCards(cards);
|
|
50444
|
-
return cards;
|
|
50445
|
-
}
|
|
50446
|
-
findCardsOnBoard(cardIds) {
|
|
50447
|
-
return cardIds.map((cardId) => {
|
|
50448
|
-
return this.board.items.getById(cardId);
|
|
50449
|
-
}).filter((card) => !!card);
|
|
50450
|
-
}
|
|
50451
|
-
updateCards() {
|
|
50452
|
-
if (this.cardIds.length === this.cards.length) {
|
|
50453
|
-
return this.cards;
|
|
50461
|
+
const card = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
|
|
50462
|
+
if (card) {
|
|
50463
|
+
this.removeChildItems(card);
|
|
50464
|
+
return card;
|
|
50454
50465
|
}
|
|
50455
|
-
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
50456
|
-
return this.cards;
|
|
50457
50466
|
}
|
|
50458
50467
|
shuffleDeck() {
|
|
50459
|
-
|
|
50468
|
+
if (!this.index) {
|
|
50469
|
+
return;
|
|
50470
|
+
}
|
|
50471
|
+
const shuffled = [...this.index.list()];
|
|
50460
50472
|
for (let i = shuffled.length - 1;i > 0; i--) {
|
|
50461
50473
|
const j = Math.floor(Math.random() * (i + 1));
|
|
50462
50474
|
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
50463
50475
|
}
|
|
50464
|
-
|
|
50465
|
-
this.
|
|
50466
|
-
}
|
|
50467
|
-
addCards(cards, shouldReplaceExistingCards = false) {
|
|
50468
|
-
cards.forEach((card) => {
|
|
50469
|
-
card.setIsInDeck(true);
|
|
50470
|
-
});
|
|
50471
|
-
this.board.bringToFront(cards);
|
|
50472
|
-
this.emit({
|
|
50473
|
-
class: "Deck",
|
|
50474
|
-
method: "addCards",
|
|
50475
|
-
item: [this.getId()],
|
|
50476
|
-
newData: {
|
|
50477
|
-
cardIds: cards.map((card) => card.getId()),
|
|
50478
|
-
shouldReplaceExistingCards
|
|
50479
|
-
},
|
|
50480
|
-
prevData: { cardIds: this.cardIds, shouldReplaceExistingCards }
|
|
50481
|
-
});
|
|
50482
|
-
}
|
|
50483
|
-
removeCards(cards) {
|
|
50484
|
-
cards.forEach((card) => {
|
|
50485
|
-
card.setIsInDeck(false);
|
|
50486
|
-
});
|
|
50487
|
-
this.emit({
|
|
50488
|
-
class: "Deck",
|
|
50489
|
-
method: "removeCards",
|
|
50490
|
-
item: [this.getId()],
|
|
50491
|
-
newData: { cardIds: cards.map((card) => card.getId()) },
|
|
50492
|
-
prevData: { cardIds: this.cardIds }
|
|
50493
|
-
});
|
|
50476
|
+
this.index.clear();
|
|
50477
|
+
shuffled.forEach((card) => this.index.insert(card));
|
|
50494
50478
|
}
|
|
50495
50479
|
apply(op) {
|
|
50496
50480
|
super.apply(op);
|
|
50497
|
-
switch (op.class) {
|
|
50498
|
-
case "Deck":
|
|
50499
|
-
switch (op.method) {
|
|
50500
|
-
case "addCards":
|
|
50501
|
-
if (op.newData.shouldReplaceExistingCards) {
|
|
50502
|
-
this.cardIds = op.newData.cardIds;
|
|
50503
|
-
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
50504
|
-
} else {
|
|
50505
|
-
this.cardIds = [
|
|
50506
|
-
...op.newData.cardIds,
|
|
50507
|
-
...this.cardIds
|
|
50508
|
-
];
|
|
50509
|
-
this.updateCards();
|
|
50510
|
-
this.updateMbr();
|
|
50511
|
-
}
|
|
50512
|
-
break;
|
|
50513
|
-
case "removeCards":
|
|
50514
|
-
this.cardIds = this.cardIds.filter((card) => {
|
|
50515
|
-
return !op.newData.cardIds.includes(card);
|
|
50516
|
-
});
|
|
50517
|
-
this.updateCards();
|
|
50518
|
-
this.updateMbr();
|
|
50519
|
-
break;
|
|
50520
|
-
}
|
|
50521
|
-
break;
|
|
50522
|
-
}
|
|
50523
50481
|
this.subject.publish(this);
|
|
50524
50482
|
}
|
|
50525
50483
|
updateMbr() {
|
|
50526
|
-
const { translateX, translateY
|
|
50484
|
+
const { translateX, translateY } = this.transformation.matrix;
|
|
50485
|
+
const { right, bottom } = this.index.getMbr();
|
|
50527
50486
|
this.left = translateX;
|
|
50528
50487
|
this.top = translateY;
|
|
50529
|
-
this.right =
|
|
50530
|
-
this.bottom =
|
|
50488
|
+
this.right = right;
|
|
50489
|
+
this.bottom = bottom;
|
|
50531
50490
|
}
|
|
50532
50491
|
deserialize(data) {
|
|
50533
50492
|
super.deserialize(data);
|
|
50534
|
-
this.
|
|
50493
|
+
this.updateMbr();
|
|
50494
|
+
this.subject.publish(this);
|
|
50535
50495
|
return this;
|
|
50536
50496
|
}
|
|
50537
50497
|
render(context) {
|
|
50538
50498
|
if (this.transformationRenderBlock) {
|
|
50539
50499
|
return;
|
|
50540
50500
|
}
|
|
50541
|
-
|
|
50542
|
-
card.render(context, {
|
|
50543
|
-
top: this.top,
|
|
50544
|
-
left: this.left,
|
|
50545
|
-
cardPosition: index2 + 1
|
|
50546
|
-
});
|
|
50547
|
-
});
|
|
50501
|
+
super.render(context);
|
|
50548
50502
|
}
|
|
50549
50503
|
}
|
|
50550
50504
|
registerItem({
|
|
@@ -50860,6 +50814,8 @@ class Hand extends BaseItem {
|
|
|
50860
50814
|
ownerId;
|
|
50861
50815
|
subject = new Subject;
|
|
50862
50816
|
path;
|
|
50817
|
+
borderWidth = 1;
|
|
50818
|
+
backgroundColor = "#FFFFFF";
|
|
50863
50819
|
constructor(board, id = "", ownerId = "") {
|
|
50864
50820
|
super(board, id, defaultHandData, true);
|
|
50865
50821
|
this.ownerId = ownerId;
|
|
@@ -50873,8 +50829,74 @@ class Hand extends BaseItem {
|
|
|
50873
50829
|
}
|
|
50874
50830
|
apply(op) {
|
|
50875
50831
|
super.apply(op);
|
|
50832
|
+
switch (op.class) {
|
|
50833
|
+
case "Hand":
|
|
50834
|
+
switch (op.method) {
|
|
50835
|
+
case "setBorderWidth":
|
|
50836
|
+
this.applyBorderWidth(op.newData.borderWidth);
|
|
50837
|
+
break;
|
|
50838
|
+
case "setBackgroundColor":
|
|
50839
|
+
this.applyBackgroundColor(op.newData.backgroundColor);
|
|
50840
|
+
break;
|
|
50841
|
+
case "setBorderColor":
|
|
50842
|
+
this.applyBorderColor(op.newData.borderColor);
|
|
50843
|
+
break;
|
|
50844
|
+
}
|
|
50845
|
+
break;
|
|
50846
|
+
}
|
|
50876
50847
|
this.subject.publish(this);
|
|
50877
50848
|
}
|
|
50849
|
+
getBackgroundColor() {
|
|
50850
|
+
return this.backgroundColor;
|
|
50851
|
+
}
|
|
50852
|
+
getBorderStyle() {
|
|
50853
|
+
return this.borderStyle;
|
|
50854
|
+
}
|
|
50855
|
+
getStrokeColor() {
|
|
50856
|
+
return this.borderColor;
|
|
50857
|
+
}
|
|
50858
|
+
getStrokeWidth() {
|
|
50859
|
+
return this.borderWidth;
|
|
50860
|
+
}
|
|
50861
|
+
applyBackgroundColor(backgroundColor) {
|
|
50862
|
+
this.backgroundColor = backgroundColor;
|
|
50863
|
+
this.path.setBackgroundColor(backgroundColor);
|
|
50864
|
+
}
|
|
50865
|
+
setBackgroundColor(backgroundColor) {
|
|
50866
|
+
this.emit({
|
|
50867
|
+
class: "Dice",
|
|
50868
|
+
method: "setBackgroundColor",
|
|
50869
|
+
item: [this.getId()],
|
|
50870
|
+
newData: { backgroundColor },
|
|
50871
|
+
prevData: { backgroundColor: this.backgroundColor }
|
|
50872
|
+
});
|
|
50873
|
+
}
|
|
50874
|
+
applyBorderWidth(borderWidth) {
|
|
50875
|
+
this.borderWidth = borderWidth;
|
|
50876
|
+
this.path.setBorderWidth(borderWidth);
|
|
50877
|
+
}
|
|
50878
|
+
setBorderWidth(borderWidth) {
|
|
50879
|
+
this.emit({
|
|
50880
|
+
class: "Dice",
|
|
50881
|
+
method: "setBorderWidth",
|
|
50882
|
+
item: [this.getId()],
|
|
50883
|
+
newData: { borderWidth },
|
|
50884
|
+
prevData: { borderWidth: this.borderWidth }
|
|
50885
|
+
});
|
|
50886
|
+
}
|
|
50887
|
+
applyBorderColor(borderColor) {
|
|
50888
|
+
this.borderColor = borderColor;
|
|
50889
|
+
this.path.setBorderColor(borderColor);
|
|
50890
|
+
}
|
|
50891
|
+
setBorderColor(borderColor) {
|
|
50892
|
+
this.emit({
|
|
50893
|
+
class: "Dice",
|
|
50894
|
+
method: "setBorderColor",
|
|
50895
|
+
item: [this.getId()],
|
|
50896
|
+
newData: { borderColor },
|
|
50897
|
+
prevData: { borderColor: this.borderColor }
|
|
50898
|
+
});
|
|
50899
|
+
}
|
|
50878
50900
|
applyOwnerId(ownerId) {
|
|
50879
50901
|
this.ownerId = ownerId;
|
|
50880
50902
|
}
|
|
@@ -50883,6 +50905,7 @@ class Hand extends BaseItem {
|
|
|
50883
50905
|
this.path.transform(this.transformation.matrix);
|
|
50884
50906
|
this.path.setBackgroundColor(this.backgroundColor);
|
|
50885
50907
|
this.path.setBorderColor(this.borderColor);
|
|
50908
|
+
this.path.setBorderWidth(this.borderWidth);
|
|
50886
50909
|
}
|
|
50887
50910
|
updateMbr() {
|
|
50888
50911
|
const { left, top, right, bottom } = this.path.getMbr();
|