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/esm/index.js
CHANGED
|
@@ -47631,8 +47631,7 @@ var defaultCardData = {
|
|
|
47631
47631
|
itemType: "Card",
|
|
47632
47632
|
isOpen: false,
|
|
47633
47633
|
faceUrl: "",
|
|
47634
|
-
backsideUrl: ""
|
|
47635
|
-
isInDeck: false
|
|
47634
|
+
backsideUrl: ""
|
|
47636
47635
|
};
|
|
47637
47636
|
var CARD_DIMENSIONS = { width: 250, height: 400 };
|
|
47638
47637
|
|
|
@@ -47641,7 +47640,6 @@ class Card extends BaseItem {
|
|
|
47641
47640
|
faceUrl = "";
|
|
47642
47641
|
backsideUrl = "";
|
|
47643
47642
|
isOpen = false;
|
|
47644
|
-
isInDeck = false;
|
|
47645
47643
|
throttledBringToFront;
|
|
47646
47644
|
face = null;
|
|
47647
47645
|
backside = null;
|
|
@@ -47677,35 +47675,20 @@ class Card extends BaseItem {
|
|
|
47677
47675
|
};
|
|
47678
47676
|
this.updateImageToRender();
|
|
47679
47677
|
}
|
|
47680
|
-
setIsInDeck(isInDeck) {
|
|
47681
|
-
this.emit({
|
|
47682
|
-
class: "Card",
|
|
47683
|
-
method: "setIsInDeck",
|
|
47684
|
-
item: [this.getId()],
|
|
47685
|
-
newData: { isInDeck },
|
|
47686
|
-
prevData: { isInDeck: this.isInDeck }
|
|
47687
|
-
});
|
|
47688
|
-
}
|
|
47689
47678
|
updateImageToRender() {
|
|
47690
47679
|
this.imageToRender = this.backside;
|
|
47691
47680
|
if (this.isOpen) {
|
|
47692
47681
|
this.imageToRender = this.face;
|
|
47693
47682
|
}
|
|
47694
47683
|
}
|
|
47695
|
-
render(context
|
|
47696
|
-
if (this.transformationRenderBlock
|
|
47684
|
+
render(context) {
|
|
47685
|
+
if (this.transformationRenderBlock) {
|
|
47697
47686
|
return;
|
|
47698
47687
|
}
|
|
47699
47688
|
const ctx = context.ctx;
|
|
47700
47689
|
if (this.imageToRender && this.imageToRender.complete) {
|
|
47701
47690
|
ctx.save();
|
|
47702
|
-
|
|
47703
|
-
let top = this.top;
|
|
47704
|
-
if (deckRenderData) {
|
|
47705
|
-
left = deckRenderData.left + 2 * deckRenderData.cardPosition;
|
|
47706
|
-
top = deckRenderData.top;
|
|
47707
|
-
}
|
|
47708
|
-
ctx.drawImage(this.imageToRender, left, top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
|
|
47691
|
+
ctx.drawImage(this.imageToRender, this.left, this.top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
|
|
47709
47692
|
ctx.restore();
|
|
47710
47693
|
}
|
|
47711
47694
|
}
|
|
@@ -47716,12 +47699,6 @@ class Card extends BaseItem {
|
|
|
47716
47699
|
this.right = this.left + CARD_DIMENSIONS.width * scaleX;
|
|
47717
47700
|
this.bottom = this.top + CARD_DIMENSIONS.height * scaleY;
|
|
47718
47701
|
}
|
|
47719
|
-
getMbr() {
|
|
47720
|
-
if (this.isInDeck) {
|
|
47721
|
-
return new Mbr(1e4, 1e4, 1e4, 1e4);
|
|
47722
|
-
}
|
|
47723
|
-
return super.getMbr();
|
|
47724
|
-
}
|
|
47725
47702
|
getPath() {
|
|
47726
47703
|
return new Path(this.getMbr().getLines());
|
|
47727
47704
|
}
|
|
@@ -47754,9 +47731,6 @@ class Card extends BaseItem {
|
|
|
47754
47731
|
this.isOpen = op.newData.isOpen;
|
|
47755
47732
|
this.updateImageToRender();
|
|
47756
47733
|
break;
|
|
47757
|
-
case "setIsInDeck":
|
|
47758
|
-
this.isInDeck = op.newData.isInDeck;
|
|
47759
|
-
break;
|
|
47760
47734
|
}
|
|
47761
47735
|
break;
|
|
47762
47736
|
}
|
|
@@ -47769,22 +47743,17 @@ registerItem({
|
|
|
47769
47743
|
});
|
|
47770
47744
|
// src/Items/Examples/CardGame/Deck/Deck.ts
|
|
47771
47745
|
var defaultDeckData = {
|
|
47772
|
-
itemType: "Deck"
|
|
47773
|
-
cardIds: []
|
|
47746
|
+
itemType: "Deck"
|
|
47774
47747
|
};
|
|
47775
47748
|
|
|
47776
47749
|
class Deck extends BaseItem {
|
|
47777
47750
|
subject = new Subject;
|
|
47778
47751
|
shouldUseCustomRender = false;
|
|
47779
|
-
cardIds = [];
|
|
47780
|
-
cards = [];
|
|
47781
47752
|
constructor(board, id = "", defaultData2, cards) {
|
|
47782
|
-
super(board, id, defaultDeckData);
|
|
47753
|
+
super(board, id, defaultDeckData, true);
|
|
47783
47754
|
if (cards) {
|
|
47784
|
-
this.cards = cards;
|
|
47785
|
-
cards.forEach((card) => card.setIsInDeck(true));
|
|
47786
47755
|
this.transformation.matrix = cards[cards.length - 1].transformation.matrix;
|
|
47787
|
-
this.
|
|
47756
|
+
this.applyAddChildren(cards.map((card) => card.getId()));
|
|
47788
47757
|
}
|
|
47789
47758
|
this.transformation.subject.subscribe(() => {
|
|
47790
47759
|
this.updateMbr();
|
|
@@ -47792,128 +47761,113 @@ class Deck extends BaseItem {
|
|
|
47792
47761
|
});
|
|
47793
47762
|
this.updateMbr();
|
|
47794
47763
|
}
|
|
47764
|
+
applyAddChildren(childIds) {
|
|
47765
|
+
if (!this.index) {
|
|
47766
|
+
return;
|
|
47767
|
+
}
|
|
47768
|
+
childIds.forEach((childId) => {
|
|
47769
|
+
const foundItem = this.board.items.getById(childId);
|
|
47770
|
+
if (this.parent !== childId && this.getId() !== childId) {
|
|
47771
|
+
if (!this.index?.getById(childId) && foundItem && foundItem.itemType === "Card") {
|
|
47772
|
+
foundItem.transformation.apply({
|
|
47773
|
+
class: "Transformation",
|
|
47774
|
+
method: "translateTo",
|
|
47775
|
+
item: [this.id],
|
|
47776
|
+
x: this.left + (this.index?.list().length || 0) * 2,
|
|
47777
|
+
y: this.top
|
|
47778
|
+
});
|
|
47779
|
+
foundItem.parent = this.getId();
|
|
47780
|
+
this.board.items.index.remove(foundItem);
|
|
47781
|
+
this.index?.insert(foundItem);
|
|
47782
|
+
}
|
|
47783
|
+
}
|
|
47784
|
+
});
|
|
47785
|
+
this.updateMbr();
|
|
47786
|
+
this.subject.publish(this);
|
|
47787
|
+
}
|
|
47788
|
+
applyRemoveChildren(childIds) {
|
|
47789
|
+
if (!this.index) {
|
|
47790
|
+
return;
|
|
47791
|
+
}
|
|
47792
|
+
childIds.forEach((childId) => {
|
|
47793
|
+
const foundItem = this.index?.getById(childId);
|
|
47794
|
+
if (this.parent !== childId && this.getId() !== childId) {
|
|
47795
|
+
if (foundItem) {
|
|
47796
|
+
foundItem.transformation.apply({
|
|
47797
|
+
class: "Transformation",
|
|
47798
|
+
method: "translateTo",
|
|
47799
|
+
item: [this.id],
|
|
47800
|
+
x: this.left,
|
|
47801
|
+
y: this.top - this.getHeight() / 2
|
|
47802
|
+
});
|
|
47803
|
+
foundItem.parent = "Board";
|
|
47804
|
+
this.index?.remove(foundItem);
|
|
47805
|
+
this.board.items.index.insert(foundItem);
|
|
47806
|
+
}
|
|
47807
|
+
}
|
|
47808
|
+
});
|
|
47809
|
+
this.updateMbr();
|
|
47810
|
+
this.subject.publish(this);
|
|
47811
|
+
}
|
|
47795
47812
|
getDeck() {
|
|
47796
|
-
return this.
|
|
47813
|
+
return this.index?.list() || [];
|
|
47797
47814
|
}
|
|
47798
47815
|
getTopCard() {
|
|
47799
|
-
const
|
|
47800
|
-
|
|
47816
|
+
const card = this.index?.list()[this.index?.list().length - 1];
|
|
47817
|
+
if (card) {
|
|
47818
|
+
this.removeChildItems(card);
|
|
47819
|
+
return card;
|
|
47820
|
+
}
|
|
47801
47821
|
}
|
|
47802
47822
|
getBottomCard() {
|
|
47803
|
-
const
|
|
47804
|
-
|
|
47823
|
+
const card = this.index?.list()[0];
|
|
47824
|
+
if (card) {
|
|
47825
|
+
this.removeChildItems(card);
|
|
47826
|
+
return card;
|
|
47827
|
+
}
|
|
47805
47828
|
}
|
|
47806
47829
|
getRandomCard() {
|
|
47807
|
-
const
|
|
47808
|
-
|
|
47809
|
-
|
|
47810
|
-
|
|
47811
|
-
const cards = this.findCardsOnBoard(cardIds);
|
|
47812
|
-
this.removeCards(cards);
|
|
47813
|
-
return cards;
|
|
47814
|
-
}
|
|
47815
|
-
findCardsOnBoard(cardIds) {
|
|
47816
|
-
return cardIds.map((cardId) => {
|
|
47817
|
-
return this.board.items.getById(cardId);
|
|
47818
|
-
}).filter((card) => !!card);
|
|
47819
|
-
}
|
|
47820
|
-
updateCards() {
|
|
47821
|
-
if (this.cardIds.length === this.cards.length) {
|
|
47822
|
-
return this.cards;
|
|
47830
|
+
const card = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
|
|
47831
|
+
if (card) {
|
|
47832
|
+
this.removeChildItems(card);
|
|
47833
|
+
return card;
|
|
47823
47834
|
}
|
|
47824
|
-
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
47825
|
-
return this.cards;
|
|
47826
47835
|
}
|
|
47827
47836
|
shuffleDeck() {
|
|
47828
|
-
|
|
47837
|
+
if (!this.index) {
|
|
47838
|
+
return;
|
|
47839
|
+
}
|
|
47840
|
+
const shuffled = [...this.index.list()];
|
|
47829
47841
|
for (let i = shuffled.length - 1;i > 0; i--) {
|
|
47830
47842
|
const j = Math.floor(Math.random() * (i + 1));
|
|
47831
47843
|
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
47832
47844
|
}
|
|
47833
|
-
|
|
47834
|
-
this.
|
|
47835
|
-
}
|
|
47836
|
-
addCards(cards, shouldReplaceExistingCards = false) {
|
|
47837
|
-
cards.forEach((card) => {
|
|
47838
|
-
card.setIsInDeck(true);
|
|
47839
|
-
});
|
|
47840
|
-
this.board.bringToFront(cards);
|
|
47841
|
-
this.emit({
|
|
47842
|
-
class: "Deck",
|
|
47843
|
-
method: "addCards",
|
|
47844
|
-
item: [this.getId()],
|
|
47845
|
-
newData: {
|
|
47846
|
-
cardIds: cards.map((card) => card.getId()),
|
|
47847
|
-
shouldReplaceExistingCards
|
|
47848
|
-
},
|
|
47849
|
-
prevData: { cardIds: this.cardIds, shouldReplaceExistingCards }
|
|
47850
|
-
});
|
|
47851
|
-
}
|
|
47852
|
-
removeCards(cards) {
|
|
47853
|
-
cards.forEach((card) => {
|
|
47854
|
-
card.setIsInDeck(false);
|
|
47855
|
-
});
|
|
47856
|
-
this.emit({
|
|
47857
|
-
class: "Deck",
|
|
47858
|
-
method: "removeCards",
|
|
47859
|
-
item: [this.getId()],
|
|
47860
|
-
newData: { cardIds: cards.map((card) => card.getId()) },
|
|
47861
|
-
prevData: { cardIds: this.cardIds }
|
|
47862
|
-
});
|
|
47845
|
+
this.index.clear();
|
|
47846
|
+
shuffled.forEach((card) => this.index.insert(card));
|
|
47863
47847
|
}
|
|
47864
47848
|
apply(op) {
|
|
47865
47849
|
super.apply(op);
|
|
47866
|
-
switch (op.class) {
|
|
47867
|
-
case "Deck":
|
|
47868
|
-
switch (op.method) {
|
|
47869
|
-
case "addCards":
|
|
47870
|
-
if (op.newData.shouldReplaceExistingCards) {
|
|
47871
|
-
this.cardIds = op.newData.cardIds;
|
|
47872
|
-
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
47873
|
-
} else {
|
|
47874
|
-
this.cardIds = [
|
|
47875
|
-
...op.newData.cardIds,
|
|
47876
|
-
...this.cardIds
|
|
47877
|
-
];
|
|
47878
|
-
this.updateCards();
|
|
47879
|
-
this.updateMbr();
|
|
47880
|
-
}
|
|
47881
|
-
break;
|
|
47882
|
-
case "removeCards":
|
|
47883
|
-
this.cardIds = this.cardIds.filter((card) => {
|
|
47884
|
-
return !op.newData.cardIds.includes(card);
|
|
47885
|
-
});
|
|
47886
|
-
this.updateCards();
|
|
47887
|
-
this.updateMbr();
|
|
47888
|
-
break;
|
|
47889
|
-
}
|
|
47890
|
-
break;
|
|
47891
|
-
}
|
|
47892
47850
|
this.subject.publish(this);
|
|
47893
47851
|
}
|
|
47894
47852
|
updateMbr() {
|
|
47895
|
-
const { translateX, translateY
|
|
47853
|
+
const { translateX, translateY } = this.transformation.matrix;
|
|
47854
|
+
const { right, bottom } = this.index.getMbr();
|
|
47896
47855
|
this.left = translateX;
|
|
47897
47856
|
this.top = translateY;
|
|
47898
|
-
this.right =
|
|
47899
|
-
this.bottom =
|
|
47857
|
+
this.right = right;
|
|
47858
|
+
this.bottom = bottom;
|
|
47900
47859
|
}
|
|
47901
47860
|
deserialize(data) {
|
|
47902
47861
|
super.deserialize(data);
|
|
47903
|
-
this.
|
|
47862
|
+
this.updateMbr();
|
|
47863
|
+
this.subject.publish(this);
|
|
47904
47864
|
return this;
|
|
47905
47865
|
}
|
|
47906
47866
|
render(context) {
|
|
47907
47867
|
if (this.transformationRenderBlock) {
|
|
47908
47868
|
return;
|
|
47909
47869
|
}
|
|
47910
|
-
|
|
47911
|
-
card.render(context, {
|
|
47912
|
-
top: this.top,
|
|
47913
|
-
left: this.left,
|
|
47914
|
-
cardPosition: index2 + 1
|
|
47915
|
-
});
|
|
47916
|
-
});
|
|
47870
|
+
super.render(context);
|
|
47917
47871
|
}
|
|
47918
47872
|
}
|
|
47919
47873
|
registerItem({
|
|
@@ -48229,6 +48183,8 @@ class Hand extends BaseItem {
|
|
|
48229
48183
|
ownerId;
|
|
48230
48184
|
subject = new Subject;
|
|
48231
48185
|
path;
|
|
48186
|
+
borderWidth = 1;
|
|
48187
|
+
backgroundColor = "#FFFFFF";
|
|
48232
48188
|
constructor(board, id = "", ownerId = "") {
|
|
48233
48189
|
super(board, id, defaultHandData, true);
|
|
48234
48190
|
this.ownerId = ownerId;
|
|
@@ -48242,8 +48198,74 @@ class Hand extends BaseItem {
|
|
|
48242
48198
|
}
|
|
48243
48199
|
apply(op) {
|
|
48244
48200
|
super.apply(op);
|
|
48201
|
+
switch (op.class) {
|
|
48202
|
+
case "Hand":
|
|
48203
|
+
switch (op.method) {
|
|
48204
|
+
case "setBorderWidth":
|
|
48205
|
+
this.applyBorderWidth(op.newData.borderWidth);
|
|
48206
|
+
break;
|
|
48207
|
+
case "setBackgroundColor":
|
|
48208
|
+
this.applyBackgroundColor(op.newData.backgroundColor);
|
|
48209
|
+
break;
|
|
48210
|
+
case "setBorderColor":
|
|
48211
|
+
this.applyBorderColor(op.newData.borderColor);
|
|
48212
|
+
break;
|
|
48213
|
+
}
|
|
48214
|
+
break;
|
|
48215
|
+
}
|
|
48245
48216
|
this.subject.publish(this);
|
|
48246
48217
|
}
|
|
48218
|
+
getBackgroundColor() {
|
|
48219
|
+
return this.backgroundColor;
|
|
48220
|
+
}
|
|
48221
|
+
getBorderStyle() {
|
|
48222
|
+
return this.borderStyle;
|
|
48223
|
+
}
|
|
48224
|
+
getStrokeColor() {
|
|
48225
|
+
return this.borderColor;
|
|
48226
|
+
}
|
|
48227
|
+
getStrokeWidth() {
|
|
48228
|
+
return this.borderWidth;
|
|
48229
|
+
}
|
|
48230
|
+
applyBackgroundColor(backgroundColor) {
|
|
48231
|
+
this.backgroundColor = backgroundColor;
|
|
48232
|
+
this.path.setBackgroundColor(backgroundColor);
|
|
48233
|
+
}
|
|
48234
|
+
setBackgroundColor(backgroundColor) {
|
|
48235
|
+
this.emit({
|
|
48236
|
+
class: "Dice",
|
|
48237
|
+
method: "setBackgroundColor",
|
|
48238
|
+
item: [this.getId()],
|
|
48239
|
+
newData: { backgroundColor },
|
|
48240
|
+
prevData: { backgroundColor: this.backgroundColor }
|
|
48241
|
+
});
|
|
48242
|
+
}
|
|
48243
|
+
applyBorderWidth(borderWidth) {
|
|
48244
|
+
this.borderWidth = borderWidth;
|
|
48245
|
+
this.path.setBorderWidth(borderWidth);
|
|
48246
|
+
}
|
|
48247
|
+
setBorderWidth(borderWidth) {
|
|
48248
|
+
this.emit({
|
|
48249
|
+
class: "Dice",
|
|
48250
|
+
method: "setBorderWidth",
|
|
48251
|
+
item: [this.getId()],
|
|
48252
|
+
newData: { borderWidth },
|
|
48253
|
+
prevData: { borderWidth: this.borderWidth }
|
|
48254
|
+
});
|
|
48255
|
+
}
|
|
48256
|
+
applyBorderColor(borderColor) {
|
|
48257
|
+
this.borderColor = borderColor;
|
|
48258
|
+
this.path.setBorderColor(borderColor);
|
|
48259
|
+
}
|
|
48260
|
+
setBorderColor(borderColor) {
|
|
48261
|
+
this.emit({
|
|
48262
|
+
class: "Dice",
|
|
48263
|
+
method: "setBorderColor",
|
|
48264
|
+
item: [this.getId()],
|
|
48265
|
+
newData: { borderColor },
|
|
48266
|
+
prevData: { borderColor: this.borderColor }
|
|
48267
|
+
});
|
|
48268
|
+
}
|
|
48247
48269
|
applyOwnerId(ownerId) {
|
|
48248
48270
|
this.ownerId = ownerId;
|
|
48249
48271
|
}
|
|
@@ -48252,6 +48274,7 @@ class Hand extends BaseItem {
|
|
|
48252
48274
|
this.path.transform(this.transformation.matrix);
|
|
48253
48275
|
this.path.setBackgroundColor(this.backgroundColor);
|
|
48254
48276
|
this.path.setBorderColor(this.borderColor);
|
|
48277
|
+
this.path.setBorderWidth(this.borderWidth);
|
|
48255
48278
|
}
|
|
48256
48279
|
updateMbr() {
|
|
48257
48280
|
const { left, top, right, bottom } = this.path.getMbr();
|