microboard-temp 0.4.69 → 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 +95 -129
- package/dist/cjs/index.js +95 -129
- package/dist/cjs/node.js +95 -129
- package/dist/esm/browser.js +95 -129
- package/dist/esm/index.js +95 -129
- package/dist/esm/node.js +95 -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 +4 -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({
|
|
@@ -48261,6 +48215,18 @@ class Hand extends BaseItem {
|
|
|
48261
48215
|
}
|
|
48262
48216
|
this.subject.publish(this);
|
|
48263
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
|
+
}
|
|
48264
48230
|
applyBackgroundColor(backgroundColor) {
|
|
48265
48231
|
this.backgroundColor = backgroundColor;
|
|
48266
48232
|
this.path.setBackgroundColor(backgroundColor);
|
package/dist/esm/node.js
CHANGED
|
@@ -50099,8 +50099,7 @@ var defaultCardData = {
|
|
|
50099
50099
|
itemType: "Card",
|
|
50100
50100
|
isOpen: false,
|
|
50101
50101
|
faceUrl: "",
|
|
50102
|
-
backsideUrl: ""
|
|
50103
|
-
isInDeck: false
|
|
50102
|
+
backsideUrl: ""
|
|
50104
50103
|
};
|
|
50105
50104
|
var CARD_DIMENSIONS = { width: 250, height: 400 };
|
|
50106
50105
|
|
|
@@ -50109,7 +50108,6 @@ class Card extends BaseItem {
|
|
|
50109
50108
|
faceUrl = "";
|
|
50110
50109
|
backsideUrl = "";
|
|
50111
50110
|
isOpen = false;
|
|
50112
|
-
isInDeck = false;
|
|
50113
50111
|
throttledBringToFront;
|
|
50114
50112
|
face = null;
|
|
50115
50113
|
backside = null;
|
|
@@ -50145,35 +50143,20 @@ class Card extends BaseItem {
|
|
|
50145
50143
|
};
|
|
50146
50144
|
this.updateImageToRender();
|
|
50147
50145
|
}
|
|
50148
|
-
setIsInDeck(isInDeck) {
|
|
50149
|
-
this.emit({
|
|
50150
|
-
class: "Card",
|
|
50151
|
-
method: "setIsInDeck",
|
|
50152
|
-
item: [this.getId()],
|
|
50153
|
-
newData: { isInDeck },
|
|
50154
|
-
prevData: { isInDeck: this.isInDeck }
|
|
50155
|
-
});
|
|
50156
|
-
}
|
|
50157
50146
|
updateImageToRender() {
|
|
50158
50147
|
this.imageToRender = this.backside;
|
|
50159
50148
|
if (this.isOpen) {
|
|
50160
50149
|
this.imageToRender = this.face;
|
|
50161
50150
|
}
|
|
50162
50151
|
}
|
|
50163
|
-
render(context
|
|
50164
|
-
if (this.transformationRenderBlock
|
|
50152
|
+
render(context) {
|
|
50153
|
+
if (this.transformationRenderBlock) {
|
|
50165
50154
|
return;
|
|
50166
50155
|
}
|
|
50167
50156
|
const ctx = context.ctx;
|
|
50168
50157
|
if (this.imageToRender && this.imageToRender.complete) {
|
|
50169
50158
|
ctx.save();
|
|
50170
|
-
|
|
50171
|
-
let top = this.top;
|
|
50172
|
-
if (deckRenderData) {
|
|
50173
|
-
left = deckRenderData.left + 2 * deckRenderData.cardPosition;
|
|
50174
|
-
top = deckRenderData.top;
|
|
50175
|
-
}
|
|
50176
|
-
ctx.drawImage(this.imageToRender, left, top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
|
|
50159
|
+
ctx.drawImage(this.imageToRender, this.left, this.top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
|
|
50177
50160
|
ctx.restore();
|
|
50178
50161
|
}
|
|
50179
50162
|
}
|
|
@@ -50184,12 +50167,6 @@ class Card extends BaseItem {
|
|
|
50184
50167
|
this.right = this.left + CARD_DIMENSIONS.width * scaleX;
|
|
50185
50168
|
this.bottom = this.top + CARD_DIMENSIONS.height * scaleY;
|
|
50186
50169
|
}
|
|
50187
|
-
getMbr() {
|
|
50188
|
-
if (this.isInDeck) {
|
|
50189
|
-
return new Mbr(1e4, 1e4, 1e4, 1e4);
|
|
50190
|
-
}
|
|
50191
|
-
return super.getMbr();
|
|
50192
|
-
}
|
|
50193
50170
|
getPath() {
|
|
50194
50171
|
return new Path(this.getMbr().getLines());
|
|
50195
50172
|
}
|
|
@@ -50222,9 +50199,6 @@ class Card extends BaseItem {
|
|
|
50222
50199
|
this.isOpen = op.newData.isOpen;
|
|
50223
50200
|
this.updateImageToRender();
|
|
50224
50201
|
break;
|
|
50225
|
-
case "setIsInDeck":
|
|
50226
|
-
this.isInDeck = op.newData.isInDeck;
|
|
50227
|
-
break;
|
|
50228
50202
|
}
|
|
50229
50203
|
break;
|
|
50230
50204
|
}
|
|
@@ -50237,22 +50211,17 @@ registerItem({
|
|
|
50237
50211
|
});
|
|
50238
50212
|
// src/Items/Examples/CardGame/Deck/Deck.ts
|
|
50239
50213
|
var defaultDeckData = {
|
|
50240
|
-
itemType: "Deck"
|
|
50241
|
-
cardIds: []
|
|
50214
|
+
itemType: "Deck"
|
|
50242
50215
|
};
|
|
50243
50216
|
|
|
50244
50217
|
class Deck extends BaseItem {
|
|
50245
50218
|
subject = new Subject;
|
|
50246
50219
|
shouldUseCustomRender = false;
|
|
50247
|
-
cardIds = [];
|
|
50248
|
-
cards = [];
|
|
50249
50220
|
constructor(board, id = "", defaultData2, cards) {
|
|
50250
|
-
super(board, id, defaultDeckData);
|
|
50221
|
+
super(board, id, defaultDeckData, true);
|
|
50251
50222
|
if (cards) {
|
|
50252
|
-
this.cards = cards;
|
|
50253
|
-
cards.forEach((card) => card.setIsInDeck(true));
|
|
50254
50223
|
this.transformation.matrix = cards[cards.length - 1].transformation.matrix;
|
|
50255
|
-
this.
|
|
50224
|
+
this.applyAddChildren(cards.map((card) => card.getId()));
|
|
50256
50225
|
}
|
|
50257
50226
|
this.transformation.subject.subscribe(() => {
|
|
50258
50227
|
this.updateMbr();
|
|
@@ -50260,128 +50229,113 @@ class Deck extends BaseItem {
|
|
|
50260
50229
|
});
|
|
50261
50230
|
this.updateMbr();
|
|
50262
50231
|
}
|
|
50232
|
+
applyAddChildren(childIds) {
|
|
50233
|
+
if (!this.index) {
|
|
50234
|
+
return;
|
|
50235
|
+
}
|
|
50236
|
+
childIds.forEach((childId) => {
|
|
50237
|
+
const foundItem = this.board.items.getById(childId);
|
|
50238
|
+
if (this.parent !== childId && this.getId() !== childId) {
|
|
50239
|
+
if (!this.index?.getById(childId) && foundItem && foundItem.itemType === "Card") {
|
|
50240
|
+
foundItem.transformation.apply({
|
|
50241
|
+
class: "Transformation",
|
|
50242
|
+
method: "translateTo",
|
|
50243
|
+
item: [this.id],
|
|
50244
|
+
x: this.left + (this.index?.list().length || 0) * 2,
|
|
50245
|
+
y: this.top
|
|
50246
|
+
});
|
|
50247
|
+
foundItem.parent = this.getId();
|
|
50248
|
+
this.board.items.index.remove(foundItem);
|
|
50249
|
+
this.index?.insert(foundItem);
|
|
50250
|
+
}
|
|
50251
|
+
}
|
|
50252
|
+
});
|
|
50253
|
+
this.updateMbr();
|
|
50254
|
+
this.subject.publish(this);
|
|
50255
|
+
}
|
|
50256
|
+
applyRemoveChildren(childIds) {
|
|
50257
|
+
if (!this.index) {
|
|
50258
|
+
return;
|
|
50259
|
+
}
|
|
50260
|
+
childIds.forEach((childId) => {
|
|
50261
|
+
const foundItem = this.index?.getById(childId);
|
|
50262
|
+
if (this.parent !== childId && this.getId() !== childId) {
|
|
50263
|
+
if (foundItem) {
|
|
50264
|
+
foundItem.transformation.apply({
|
|
50265
|
+
class: "Transformation",
|
|
50266
|
+
method: "translateTo",
|
|
50267
|
+
item: [this.id],
|
|
50268
|
+
x: this.left,
|
|
50269
|
+
y: this.top - this.getHeight() / 2
|
|
50270
|
+
});
|
|
50271
|
+
foundItem.parent = "Board";
|
|
50272
|
+
this.index?.remove(foundItem);
|
|
50273
|
+
this.board.items.index.insert(foundItem);
|
|
50274
|
+
}
|
|
50275
|
+
}
|
|
50276
|
+
});
|
|
50277
|
+
this.updateMbr();
|
|
50278
|
+
this.subject.publish(this);
|
|
50279
|
+
}
|
|
50263
50280
|
getDeck() {
|
|
50264
|
-
return this.
|
|
50281
|
+
return this.index?.list() || [];
|
|
50265
50282
|
}
|
|
50266
50283
|
getTopCard() {
|
|
50267
|
-
const
|
|
50268
|
-
|
|
50284
|
+
const card = this.index?.list()[this.index?.list().length - 1];
|
|
50285
|
+
if (card) {
|
|
50286
|
+
this.removeChildItems(card);
|
|
50287
|
+
return card;
|
|
50288
|
+
}
|
|
50269
50289
|
}
|
|
50270
50290
|
getBottomCard() {
|
|
50271
|
-
const
|
|
50272
|
-
|
|
50291
|
+
const card = this.index?.list()[0];
|
|
50292
|
+
if (card) {
|
|
50293
|
+
this.removeChildItems(card);
|
|
50294
|
+
return card;
|
|
50295
|
+
}
|
|
50273
50296
|
}
|
|
50274
50297
|
getRandomCard() {
|
|
50275
|
-
const
|
|
50276
|
-
|
|
50277
|
-
|
|
50278
|
-
|
|
50279
|
-
const cards = this.findCardsOnBoard(cardIds);
|
|
50280
|
-
this.removeCards(cards);
|
|
50281
|
-
return cards;
|
|
50282
|
-
}
|
|
50283
|
-
findCardsOnBoard(cardIds) {
|
|
50284
|
-
return cardIds.map((cardId) => {
|
|
50285
|
-
return this.board.items.getById(cardId);
|
|
50286
|
-
}).filter((card) => !!card);
|
|
50287
|
-
}
|
|
50288
|
-
updateCards() {
|
|
50289
|
-
if (this.cardIds.length === this.cards.length) {
|
|
50290
|
-
return this.cards;
|
|
50298
|
+
const card = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
|
|
50299
|
+
if (card) {
|
|
50300
|
+
this.removeChildItems(card);
|
|
50301
|
+
return card;
|
|
50291
50302
|
}
|
|
50292
|
-
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
50293
|
-
return this.cards;
|
|
50294
50303
|
}
|
|
50295
50304
|
shuffleDeck() {
|
|
50296
|
-
|
|
50305
|
+
if (!this.index) {
|
|
50306
|
+
return;
|
|
50307
|
+
}
|
|
50308
|
+
const shuffled = [...this.index.list()];
|
|
50297
50309
|
for (let i = shuffled.length - 1;i > 0; i--) {
|
|
50298
50310
|
const j = Math.floor(Math.random() * (i + 1));
|
|
50299
50311
|
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
50300
50312
|
}
|
|
50301
|
-
|
|
50302
|
-
this.
|
|
50303
|
-
}
|
|
50304
|
-
addCards(cards, shouldReplaceExistingCards = false) {
|
|
50305
|
-
cards.forEach((card) => {
|
|
50306
|
-
card.setIsInDeck(true);
|
|
50307
|
-
});
|
|
50308
|
-
this.board.bringToFront(cards);
|
|
50309
|
-
this.emit({
|
|
50310
|
-
class: "Deck",
|
|
50311
|
-
method: "addCards",
|
|
50312
|
-
item: [this.getId()],
|
|
50313
|
-
newData: {
|
|
50314
|
-
cardIds: cards.map((card) => card.getId()),
|
|
50315
|
-
shouldReplaceExistingCards
|
|
50316
|
-
},
|
|
50317
|
-
prevData: { cardIds: this.cardIds, shouldReplaceExistingCards }
|
|
50318
|
-
});
|
|
50319
|
-
}
|
|
50320
|
-
removeCards(cards) {
|
|
50321
|
-
cards.forEach((card) => {
|
|
50322
|
-
card.setIsInDeck(false);
|
|
50323
|
-
});
|
|
50324
|
-
this.emit({
|
|
50325
|
-
class: "Deck",
|
|
50326
|
-
method: "removeCards",
|
|
50327
|
-
item: [this.getId()],
|
|
50328
|
-
newData: { cardIds: cards.map((card) => card.getId()) },
|
|
50329
|
-
prevData: { cardIds: this.cardIds }
|
|
50330
|
-
});
|
|
50313
|
+
this.index.clear();
|
|
50314
|
+
shuffled.forEach((card) => this.index.insert(card));
|
|
50331
50315
|
}
|
|
50332
50316
|
apply(op) {
|
|
50333
50317
|
super.apply(op);
|
|
50334
|
-
switch (op.class) {
|
|
50335
|
-
case "Deck":
|
|
50336
|
-
switch (op.method) {
|
|
50337
|
-
case "addCards":
|
|
50338
|
-
if (op.newData.shouldReplaceExistingCards) {
|
|
50339
|
-
this.cardIds = op.newData.cardIds;
|
|
50340
|
-
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
50341
|
-
} else {
|
|
50342
|
-
this.cardIds = [
|
|
50343
|
-
...op.newData.cardIds,
|
|
50344
|
-
...this.cardIds
|
|
50345
|
-
];
|
|
50346
|
-
this.updateCards();
|
|
50347
|
-
this.updateMbr();
|
|
50348
|
-
}
|
|
50349
|
-
break;
|
|
50350
|
-
case "removeCards":
|
|
50351
|
-
this.cardIds = this.cardIds.filter((card) => {
|
|
50352
|
-
return !op.newData.cardIds.includes(card);
|
|
50353
|
-
});
|
|
50354
|
-
this.updateCards();
|
|
50355
|
-
this.updateMbr();
|
|
50356
|
-
break;
|
|
50357
|
-
}
|
|
50358
|
-
break;
|
|
50359
|
-
}
|
|
50360
50318
|
this.subject.publish(this);
|
|
50361
50319
|
}
|
|
50362
50320
|
updateMbr() {
|
|
50363
|
-
const { translateX, translateY
|
|
50321
|
+
const { translateX, translateY } = this.transformation.matrix;
|
|
50322
|
+
const { right, bottom } = this.index.getMbr();
|
|
50364
50323
|
this.left = translateX;
|
|
50365
50324
|
this.top = translateY;
|
|
50366
|
-
this.right =
|
|
50367
|
-
this.bottom =
|
|
50325
|
+
this.right = right;
|
|
50326
|
+
this.bottom = bottom;
|
|
50368
50327
|
}
|
|
50369
50328
|
deserialize(data) {
|
|
50370
50329
|
super.deserialize(data);
|
|
50371
|
-
this.
|
|
50330
|
+
this.updateMbr();
|
|
50331
|
+
this.subject.publish(this);
|
|
50372
50332
|
return this;
|
|
50373
50333
|
}
|
|
50374
50334
|
render(context) {
|
|
50375
50335
|
if (this.transformationRenderBlock) {
|
|
50376
50336
|
return;
|
|
50377
50337
|
}
|
|
50378
|
-
|
|
50379
|
-
card.render(context, {
|
|
50380
|
-
top: this.top,
|
|
50381
|
-
left: this.left,
|
|
50382
|
-
cardPosition: index2 + 1
|
|
50383
|
-
});
|
|
50384
|
-
});
|
|
50338
|
+
super.render(context);
|
|
50385
50339
|
}
|
|
50386
50340
|
}
|
|
50387
50341
|
registerItem({
|
|
@@ -50729,6 +50683,18 @@ class Hand extends BaseItem {
|
|
|
50729
50683
|
}
|
|
50730
50684
|
this.subject.publish(this);
|
|
50731
50685
|
}
|
|
50686
|
+
getBackgroundColor() {
|
|
50687
|
+
return this.backgroundColor;
|
|
50688
|
+
}
|
|
50689
|
+
getBorderStyle() {
|
|
50690
|
+
return this.borderStyle;
|
|
50691
|
+
}
|
|
50692
|
+
getStrokeColor() {
|
|
50693
|
+
return this.borderColor;
|
|
50694
|
+
}
|
|
50695
|
+
getStrokeWidth() {
|
|
50696
|
+
return this.borderWidth;
|
|
50697
|
+
}
|
|
50732
50698
|
applyBackgroundColor(backgroundColor) {
|
|
50733
50699
|
this.backgroundColor = backgroundColor;
|
|
50734
50700
|
this.path.setBackgroundColor(backgroundColor);
|
|
@@ -6,12 +6,6 @@ import { Path } from "Items/Path/Path";
|
|
|
6
6
|
import { Subject } from "Subject";
|
|
7
7
|
import { Paths } from "Items/Path/Paths";
|
|
8
8
|
import { CardOperation } from "Items/Examples/CardGame/Card/CardOperation";
|
|
9
|
-
import { Mbr } from "Items/Mbr/Mbr";
|
|
10
|
-
export type DeckRenderData = {
|
|
11
|
-
left: number;
|
|
12
|
-
top: number;
|
|
13
|
-
cardPosition: number;
|
|
14
|
-
};
|
|
15
9
|
export declare const defaultCardData: BaseItemData;
|
|
16
10
|
export declare const CARD_DIMENSIONS: {
|
|
17
11
|
width: number;
|
|
@@ -22,7 +16,6 @@ export declare class Card extends BaseItem {
|
|
|
22
16
|
private faceUrl;
|
|
23
17
|
private backsideUrl;
|
|
24
18
|
private isOpen;
|
|
25
|
-
private isInDeck;
|
|
26
19
|
private throttledBringToFront;
|
|
27
20
|
face: HTMLImageElement | null;
|
|
28
21
|
backside: HTMLImageElement | null;
|
|
@@ -33,11 +26,9 @@ export declare class Card extends BaseItem {
|
|
|
33
26
|
backsideUrl: string;
|
|
34
27
|
});
|
|
35
28
|
createImages(): void;
|
|
36
|
-
setIsInDeck(isInDeck: boolean): void;
|
|
37
29
|
updateImageToRender(): void;
|
|
38
|
-
render(context: DrawingContext
|
|
30
|
+
render(context: DrawingContext): void;
|
|
39
31
|
updateMbr(): void;
|
|
40
|
-
getMbr(): Mbr;
|
|
41
32
|
getPath(): Path | Paths;
|
|
42
33
|
renderHTML(documentFactory: DocumentFactory): HTMLElement;
|
|
43
34
|
deserialize(data: SerializedItemData): this;
|