microboard-temp 0.4.69 → 0.4.71
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 +99 -130
- package/dist/cjs/index.js +99 -130
- package/dist/cjs/node.js +99 -130
- package/dist/esm/browser.js +99 -130
- package/dist/esm/index.js +99 -130
- package/dist/esm/node.js +99 -130
- 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,20 @@ 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);
|
|
47754
|
+
this.index.getUnderPoint = () => [];
|
|
47755
|
+
this.index.getEnclosed = () => [];
|
|
47756
|
+
this.index.getEnclosedOrCrossed = () => [];
|
|
47783
47757
|
if (cards) {
|
|
47784
|
-
this.
|
|
47785
|
-
cards.
|
|
47786
|
-
this.transformation.matrix = cards[cards.length - 1].transformation.matrix;
|
|
47787
|
-
this.cardIds = cards.map((card) => card.getId());
|
|
47758
|
+
this.transformation.matrix = cards[0].transformation.matrix;
|
|
47759
|
+
this.applyAddChildren(cards.map((card) => card.getId()));
|
|
47788
47760
|
}
|
|
47789
47761
|
this.transformation.subject.subscribe(() => {
|
|
47790
47762
|
this.updateMbr();
|
|
@@ -47792,128 +47764,113 @@ class Deck extends BaseItem {
|
|
|
47792
47764
|
});
|
|
47793
47765
|
this.updateMbr();
|
|
47794
47766
|
}
|
|
47767
|
+
applyAddChildren(childIds) {
|
|
47768
|
+
if (!this.index) {
|
|
47769
|
+
return;
|
|
47770
|
+
}
|
|
47771
|
+
childIds.forEach((childId) => {
|
|
47772
|
+
const foundItem = this.board.items.getById(childId);
|
|
47773
|
+
if (this.parent !== childId && this.getId() !== childId) {
|
|
47774
|
+
if (!this.index?.getById(childId) && foundItem?.itemType === "Card") {
|
|
47775
|
+
foundItem.transformation.apply({
|
|
47776
|
+
class: "Transformation",
|
|
47777
|
+
method: "translateTo",
|
|
47778
|
+
item: [this.id],
|
|
47779
|
+
x: this.left + (this.index?.list().length || 0) * 2,
|
|
47780
|
+
y: this.top
|
|
47781
|
+
});
|
|
47782
|
+
foundItem.parent = this.getId();
|
|
47783
|
+
this.board.items.index.remove(foundItem);
|
|
47784
|
+
this.index?.insert(foundItem);
|
|
47785
|
+
}
|
|
47786
|
+
}
|
|
47787
|
+
});
|
|
47788
|
+
this.updateMbr();
|
|
47789
|
+
this.subject.publish(this);
|
|
47790
|
+
}
|
|
47791
|
+
applyRemoveChildren(childIds) {
|
|
47792
|
+
if (!this.index) {
|
|
47793
|
+
return;
|
|
47794
|
+
}
|
|
47795
|
+
childIds.forEach((childId) => {
|
|
47796
|
+
const foundItem = this.index?.getById(childId);
|
|
47797
|
+
if (this.parent !== childId && this.getId() !== childId) {
|
|
47798
|
+
if (foundItem) {
|
|
47799
|
+
foundItem.transformation.apply({
|
|
47800
|
+
class: "Transformation",
|
|
47801
|
+
method: "translateTo",
|
|
47802
|
+
item: [this.id],
|
|
47803
|
+
x: this.left,
|
|
47804
|
+
y: this.top - this.getHeight() / 2
|
|
47805
|
+
});
|
|
47806
|
+
foundItem.parent = "Board";
|
|
47807
|
+
this.index?.remove(foundItem);
|
|
47808
|
+
this.board.items.index.insert(foundItem);
|
|
47809
|
+
}
|
|
47810
|
+
}
|
|
47811
|
+
});
|
|
47812
|
+
this.updateMbr();
|
|
47813
|
+
this.subject.publish(this);
|
|
47814
|
+
}
|
|
47795
47815
|
getDeck() {
|
|
47796
|
-
return this.
|
|
47816
|
+
return this.index?.list() || [];
|
|
47797
47817
|
}
|
|
47798
47818
|
getTopCard() {
|
|
47799
|
-
const
|
|
47800
|
-
|
|
47819
|
+
const card = this.index?.list()[this.index?.list().length - 1];
|
|
47820
|
+
if (card) {
|
|
47821
|
+
this.removeChildItems(card);
|
|
47822
|
+
return card;
|
|
47823
|
+
}
|
|
47801
47824
|
}
|
|
47802
47825
|
getBottomCard() {
|
|
47803
|
-
const
|
|
47804
|
-
|
|
47826
|
+
const card = this.index?.list()[0];
|
|
47827
|
+
if (card) {
|
|
47828
|
+
this.removeChildItems(card);
|
|
47829
|
+
return card;
|
|
47830
|
+
}
|
|
47805
47831
|
}
|
|
47806
47832
|
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;
|
|
47833
|
+
const card = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
|
|
47834
|
+
if (card) {
|
|
47835
|
+
this.removeChildItems(card);
|
|
47836
|
+
return card;
|
|
47823
47837
|
}
|
|
47824
|
-
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
47825
|
-
return this.cards;
|
|
47826
47838
|
}
|
|
47827
47839
|
shuffleDeck() {
|
|
47828
|
-
|
|
47840
|
+
if (!this.index) {
|
|
47841
|
+
return;
|
|
47842
|
+
}
|
|
47843
|
+
const shuffled = [...this.index.list()];
|
|
47829
47844
|
for (let i = shuffled.length - 1;i > 0; i--) {
|
|
47830
47845
|
const j = Math.floor(Math.random() * (i + 1));
|
|
47831
47846
|
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
47832
47847
|
}
|
|
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
|
-
});
|
|
47848
|
+
this.index.clear();
|
|
47849
|
+
shuffled.forEach((card) => this.index.insert(card));
|
|
47863
47850
|
}
|
|
47864
47851
|
apply(op) {
|
|
47865
47852
|
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
47853
|
this.subject.publish(this);
|
|
47893
47854
|
}
|
|
47894
47855
|
updateMbr() {
|
|
47895
|
-
const { translateX, translateY
|
|
47856
|
+
const { translateX, translateY } = this.transformation.matrix;
|
|
47857
|
+
const { right, bottom } = this.index.getMbr();
|
|
47896
47858
|
this.left = translateX;
|
|
47897
47859
|
this.top = translateY;
|
|
47898
|
-
this.right =
|
|
47899
|
-
this.bottom =
|
|
47860
|
+
this.right = right;
|
|
47861
|
+
this.bottom = bottom;
|
|
47900
47862
|
}
|
|
47901
47863
|
deserialize(data) {
|
|
47902
47864
|
super.deserialize(data);
|
|
47903
|
-
this.
|
|
47865
|
+
this.updateMbr();
|
|
47866
|
+
this.subject.publish(this);
|
|
47904
47867
|
return this;
|
|
47905
47868
|
}
|
|
47906
47869
|
render(context) {
|
|
47907
47870
|
if (this.transformationRenderBlock) {
|
|
47908
47871
|
return;
|
|
47909
47872
|
}
|
|
47910
|
-
|
|
47911
|
-
card.render(context, {
|
|
47912
|
-
top: this.top,
|
|
47913
|
-
left: this.left,
|
|
47914
|
-
cardPosition: index2 + 1
|
|
47915
|
-
});
|
|
47916
|
-
});
|
|
47873
|
+
super.render(context);
|
|
47917
47874
|
}
|
|
47918
47875
|
}
|
|
47919
47876
|
registerItem({
|
|
@@ -48261,6 +48218,18 @@ class Hand extends BaseItem {
|
|
|
48261
48218
|
}
|
|
48262
48219
|
this.subject.publish(this);
|
|
48263
48220
|
}
|
|
48221
|
+
getBackgroundColor() {
|
|
48222
|
+
return this.backgroundColor;
|
|
48223
|
+
}
|
|
48224
|
+
getBorderStyle() {
|
|
48225
|
+
return this.borderStyle;
|
|
48226
|
+
}
|
|
48227
|
+
getStrokeColor() {
|
|
48228
|
+
return this.borderColor;
|
|
48229
|
+
}
|
|
48230
|
+
getStrokeWidth() {
|
|
48231
|
+
return this.borderWidth;
|
|
48232
|
+
}
|
|
48264
48233
|
applyBackgroundColor(backgroundColor) {
|
|
48265
48234
|
this.backgroundColor = backgroundColor;
|
|
48266
48235
|
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,20 @@ 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);
|
|
50222
|
+
this.index.getUnderPoint = () => [];
|
|
50223
|
+
this.index.getEnclosed = () => [];
|
|
50224
|
+
this.index.getEnclosedOrCrossed = () => [];
|
|
50251
50225
|
if (cards) {
|
|
50252
|
-
this.
|
|
50253
|
-
cards.
|
|
50254
|
-
this.transformation.matrix = cards[cards.length - 1].transformation.matrix;
|
|
50255
|
-
this.cardIds = cards.map((card) => card.getId());
|
|
50226
|
+
this.transformation.matrix = cards[0].transformation.matrix;
|
|
50227
|
+
this.applyAddChildren(cards.map((card) => card.getId()));
|
|
50256
50228
|
}
|
|
50257
50229
|
this.transformation.subject.subscribe(() => {
|
|
50258
50230
|
this.updateMbr();
|
|
@@ -50260,128 +50232,113 @@ class Deck extends BaseItem {
|
|
|
50260
50232
|
});
|
|
50261
50233
|
this.updateMbr();
|
|
50262
50234
|
}
|
|
50235
|
+
applyAddChildren(childIds) {
|
|
50236
|
+
if (!this.index) {
|
|
50237
|
+
return;
|
|
50238
|
+
}
|
|
50239
|
+
childIds.forEach((childId) => {
|
|
50240
|
+
const foundItem = this.board.items.getById(childId);
|
|
50241
|
+
if (this.parent !== childId && this.getId() !== childId) {
|
|
50242
|
+
if (!this.index?.getById(childId) && foundItem?.itemType === "Card") {
|
|
50243
|
+
foundItem.transformation.apply({
|
|
50244
|
+
class: "Transformation",
|
|
50245
|
+
method: "translateTo",
|
|
50246
|
+
item: [this.id],
|
|
50247
|
+
x: this.left + (this.index?.list().length || 0) * 2,
|
|
50248
|
+
y: this.top
|
|
50249
|
+
});
|
|
50250
|
+
foundItem.parent = this.getId();
|
|
50251
|
+
this.board.items.index.remove(foundItem);
|
|
50252
|
+
this.index?.insert(foundItem);
|
|
50253
|
+
}
|
|
50254
|
+
}
|
|
50255
|
+
});
|
|
50256
|
+
this.updateMbr();
|
|
50257
|
+
this.subject.publish(this);
|
|
50258
|
+
}
|
|
50259
|
+
applyRemoveChildren(childIds) {
|
|
50260
|
+
if (!this.index) {
|
|
50261
|
+
return;
|
|
50262
|
+
}
|
|
50263
|
+
childIds.forEach((childId) => {
|
|
50264
|
+
const foundItem = this.index?.getById(childId);
|
|
50265
|
+
if (this.parent !== childId && this.getId() !== childId) {
|
|
50266
|
+
if (foundItem) {
|
|
50267
|
+
foundItem.transformation.apply({
|
|
50268
|
+
class: "Transformation",
|
|
50269
|
+
method: "translateTo",
|
|
50270
|
+
item: [this.id],
|
|
50271
|
+
x: this.left,
|
|
50272
|
+
y: this.top - this.getHeight() / 2
|
|
50273
|
+
});
|
|
50274
|
+
foundItem.parent = "Board";
|
|
50275
|
+
this.index?.remove(foundItem);
|
|
50276
|
+
this.board.items.index.insert(foundItem);
|
|
50277
|
+
}
|
|
50278
|
+
}
|
|
50279
|
+
});
|
|
50280
|
+
this.updateMbr();
|
|
50281
|
+
this.subject.publish(this);
|
|
50282
|
+
}
|
|
50263
50283
|
getDeck() {
|
|
50264
|
-
return this.
|
|
50284
|
+
return this.index?.list() || [];
|
|
50265
50285
|
}
|
|
50266
50286
|
getTopCard() {
|
|
50267
|
-
const
|
|
50268
|
-
|
|
50287
|
+
const card = this.index?.list()[this.index?.list().length - 1];
|
|
50288
|
+
if (card) {
|
|
50289
|
+
this.removeChildItems(card);
|
|
50290
|
+
return card;
|
|
50291
|
+
}
|
|
50269
50292
|
}
|
|
50270
50293
|
getBottomCard() {
|
|
50271
|
-
const
|
|
50272
|
-
|
|
50294
|
+
const card = this.index?.list()[0];
|
|
50295
|
+
if (card) {
|
|
50296
|
+
this.removeChildItems(card);
|
|
50297
|
+
return card;
|
|
50298
|
+
}
|
|
50273
50299
|
}
|
|
50274
50300
|
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;
|
|
50301
|
+
const card = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
|
|
50302
|
+
if (card) {
|
|
50303
|
+
this.removeChildItems(card);
|
|
50304
|
+
return card;
|
|
50291
50305
|
}
|
|
50292
|
-
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
50293
|
-
return this.cards;
|
|
50294
50306
|
}
|
|
50295
50307
|
shuffleDeck() {
|
|
50296
|
-
|
|
50308
|
+
if (!this.index) {
|
|
50309
|
+
return;
|
|
50310
|
+
}
|
|
50311
|
+
const shuffled = [...this.index.list()];
|
|
50297
50312
|
for (let i = shuffled.length - 1;i > 0; i--) {
|
|
50298
50313
|
const j = Math.floor(Math.random() * (i + 1));
|
|
50299
50314
|
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
50300
50315
|
}
|
|
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
|
-
});
|
|
50316
|
+
this.index.clear();
|
|
50317
|
+
shuffled.forEach((card) => this.index.insert(card));
|
|
50331
50318
|
}
|
|
50332
50319
|
apply(op) {
|
|
50333
50320
|
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
50321
|
this.subject.publish(this);
|
|
50361
50322
|
}
|
|
50362
50323
|
updateMbr() {
|
|
50363
|
-
const { translateX, translateY
|
|
50324
|
+
const { translateX, translateY } = this.transformation.matrix;
|
|
50325
|
+
const { right, bottom } = this.index.getMbr();
|
|
50364
50326
|
this.left = translateX;
|
|
50365
50327
|
this.top = translateY;
|
|
50366
|
-
this.right =
|
|
50367
|
-
this.bottom =
|
|
50328
|
+
this.right = right;
|
|
50329
|
+
this.bottom = bottom;
|
|
50368
50330
|
}
|
|
50369
50331
|
deserialize(data) {
|
|
50370
50332
|
super.deserialize(data);
|
|
50371
|
-
this.
|
|
50333
|
+
this.updateMbr();
|
|
50334
|
+
this.subject.publish(this);
|
|
50372
50335
|
return this;
|
|
50373
50336
|
}
|
|
50374
50337
|
render(context) {
|
|
50375
50338
|
if (this.transformationRenderBlock) {
|
|
50376
50339
|
return;
|
|
50377
50340
|
}
|
|
50378
|
-
|
|
50379
|
-
card.render(context, {
|
|
50380
|
-
top: this.top,
|
|
50381
|
-
left: this.left,
|
|
50382
|
-
cardPosition: index2 + 1
|
|
50383
|
-
});
|
|
50384
|
-
});
|
|
50341
|
+
super.render(context);
|
|
50385
50342
|
}
|
|
50386
50343
|
}
|
|
50387
50344
|
registerItem({
|
|
@@ -50729,6 +50686,18 @@ class Hand extends BaseItem {
|
|
|
50729
50686
|
}
|
|
50730
50687
|
this.subject.publish(this);
|
|
50731
50688
|
}
|
|
50689
|
+
getBackgroundColor() {
|
|
50690
|
+
return this.backgroundColor;
|
|
50691
|
+
}
|
|
50692
|
+
getBorderStyle() {
|
|
50693
|
+
return this.borderStyle;
|
|
50694
|
+
}
|
|
50695
|
+
getStrokeColor() {
|
|
50696
|
+
return this.borderColor;
|
|
50697
|
+
}
|
|
50698
|
+
getStrokeWidth() {
|
|
50699
|
+
return this.borderWidth;
|
|
50700
|
+
}
|
|
50732
50701
|
applyBackgroundColor(backgroundColor) {
|
|
50733
50702
|
this.backgroundColor = backgroundColor;
|
|
50734
50703
|
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;
|