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/cjs/browser.js
CHANGED
|
@@ -47789,8 +47789,7 @@ var defaultCardData = {
|
|
|
47789
47789
|
itemType: "Card",
|
|
47790
47790
|
isOpen: false,
|
|
47791
47791
|
faceUrl: "",
|
|
47792
|
-
backsideUrl: ""
|
|
47793
|
-
isInDeck: false
|
|
47792
|
+
backsideUrl: ""
|
|
47794
47793
|
};
|
|
47795
47794
|
var CARD_DIMENSIONS = { width: 250, height: 400 };
|
|
47796
47795
|
|
|
@@ -47799,7 +47798,6 @@ class Card extends BaseItem {
|
|
|
47799
47798
|
faceUrl = "";
|
|
47800
47799
|
backsideUrl = "";
|
|
47801
47800
|
isOpen = false;
|
|
47802
|
-
isInDeck = false;
|
|
47803
47801
|
throttledBringToFront;
|
|
47804
47802
|
face = null;
|
|
47805
47803
|
backside = null;
|
|
@@ -47835,35 +47833,20 @@ class Card extends BaseItem {
|
|
|
47835
47833
|
};
|
|
47836
47834
|
this.updateImageToRender();
|
|
47837
47835
|
}
|
|
47838
|
-
setIsInDeck(isInDeck) {
|
|
47839
|
-
this.emit({
|
|
47840
|
-
class: "Card",
|
|
47841
|
-
method: "setIsInDeck",
|
|
47842
|
-
item: [this.getId()],
|
|
47843
|
-
newData: { isInDeck },
|
|
47844
|
-
prevData: { isInDeck: this.isInDeck }
|
|
47845
|
-
});
|
|
47846
|
-
}
|
|
47847
47836
|
updateImageToRender() {
|
|
47848
47837
|
this.imageToRender = this.backside;
|
|
47849
47838
|
if (this.isOpen) {
|
|
47850
47839
|
this.imageToRender = this.face;
|
|
47851
47840
|
}
|
|
47852
47841
|
}
|
|
47853
|
-
render(context
|
|
47854
|
-
if (this.transformationRenderBlock
|
|
47842
|
+
render(context) {
|
|
47843
|
+
if (this.transformationRenderBlock) {
|
|
47855
47844
|
return;
|
|
47856
47845
|
}
|
|
47857
47846
|
const ctx = context.ctx;
|
|
47858
47847
|
if (this.imageToRender && this.imageToRender.complete) {
|
|
47859
47848
|
ctx.save();
|
|
47860
|
-
|
|
47861
|
-
let top = this.top;
|
|
47862
|
-
if (deckRenderData) {
|
|
47863
|
-
left = deckRenderData.left + 2 * deckRenderData.cardPosition;
|
|
47864
|
-
top = deckRenderData.top;
|
|
47865
|
-
}
|
|
47866
|
-
ctx.drawImage(this.imageToRender, left, top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
|
|
47849
|
+
ctx.drawImage(this.imageToRender, this.left, this.top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
|
|
47867
47850
|
ctx.restore();
|
|
47868
47851
|
}
|
|
47869
47852
|
}
|
|
@@ -47874,12 +47857,6 @@ class Card extends BaseItem {
|
|
|
47874
47857
|
this.right = this.left + CARD_DIMENSIONS.width * scaleX;
|
|
47875
47858
|
this.bottom = this.top + CARD_DIMENSIONS.height * scaleY;
|
|
47876
47859
|
}
|
|
47877
|
-
getMbr() {
|
|
47878
|
-
if (this.isInDeck) {
|
|
47879
|
-
return new Mbr(1e4, 1e4, 1e4, 1e4);
|
|
47880
|
-
}
|
|
47881
|
-
return super.getMbr();
|
|
47882
|
-
}
|
|
47883
47860
|
getPath() {
|
|
47884
47861
|
return new Path(this.getMbr().getLines());
|
|
47885
47862
|
}
|
|
@@ -47912,9 +47889,6 @@ class Card extends BaseItem {
|
|
|
47912
47889
|
this.isOpen = op.newData.isOpen;
|
|
47913
47890
|
this.updateImageToRender();
|
|
47914
47891
|
break;
|
|
47915
|
-
case "setIsInDeck":
|
|
47916
|
-
this.isInDeck = op.newData.isInDeck;
|
|
47917
|
-
break;
|
|
47918
47892
|
}
|
|
47919
47893
|
break;
|
|
47920
47894
|
}
|
|
@@ -47927,22 +47901,20 @@ registerItem({
|
|
|
47927
47901
|
});
|
|
47928
47902
|
// src/Items/Examples/CardGame/Deck/Deck.ts
|
|
47929
47903
|
var defaultDeckData = {
|
|
47930
|
-
itemType: "Deck"
|
|
47931
|
-
cardIds: []
|
|
47904
|
+
itemType: "Deck"
|
|
47932
47905
|
};
|
|
47933
47906
|
|
|
47934
47907
|
class Deck extends BaseItem {
|
|
47935
47908
|
subject = new Subject;
|
|
47936
47909
|
shouldUseCustomRender = false;
|
|
47937
|
-
cardIds = [];
|
|
47938
|
-
cards = [];
|
|
47939
47910
|
constructor(board, id = "", defaultData2, cards) {
|
|
47940
|
-
super(board, id, defaultDeckData);
|
|
47911
|
+
super(board, id, defaultDeckData, true);
|
|
47912
|
+
this.index.getUnderPoint = () => [];
|
|
47913
|
+
this.index.getEnclosed = () => [];
|
|
47914
|
+
this.index.getEnclosedOrCrossed = () => [];
|
|
47941
47915
|
if (cards) {
|
|
47942
|
-
this.
|
|
47943
|
-
cards.
|
|
47944
|
-
this.transformation.matrix = cards[cards.length - 1].transformation.matrix;
|
|
47945
|
-
this.cardIds = cards.map((card) => card.getId());
|
|
47916
|
+
this.transformation.matrix = cards[0].transformation.matrix;
|
|
47917
|
+
this.applyAddChildren(cards.map((card) => card.getId()));
|
|
47946
47918
|
}
|
|
47947
47919
|
this.transformation.subject.subscribe(() => {
|
|
47948
47920
|
this.updateMbr();
|
|
@@ -47950,128 +47922,113 @@ class Deck extends BaseItem {
|
|
|
47950
47922
|
});
|
|
47951
47923
|
this.updateMbr();
|
|
47952
47924
|
}
|
|
47925
|
+
applyAddChildren(childIds) {
|
|
47926
|
+
if (!this.index) {
|
|
47927
|
+
return;
|
|
47928
|
+
}
|
|
47929
|
+
childIds.forEach((childId) => {
|
|
47930
|
+
const foundItem = this.board.items.getById(childId);
|
|
47931
|
+
if (this.parent !== childId && this.getId() !== childId) {
|
|
47932
|
+
if (!this.index?.getById(childId) && foundItem?.itemType === "Card") {
|
|
47933
|
+
foundItem.transformation.apply({
|
|
47934
|
+
class: "Transformation",
|
|
47935
|
+
method: "translateTo",
|
|
47936
|
+
item: [this.id],
|
|
47937
|
+
x: this.left + (this.index?.list().length || 0) * 2,
|
|
47938
|
+
y: this.top
|
|
47939
|
+
});
|
|
47940
|
+
foundItem.parent = this.getId();
|
|
47941
|
+
this.board.items.index.remove(foundItem);
|
|
47942
|
+
this.index?.insert(foundItem);
|
|
47943
|
+
}
|
|
47944
|
+
}
|
|
47945
|
+
});
|
|
47946
|
+
this.updateMbr();
|
|
47947
|
+
this.subject.publish(this);
|
|
47948
|
+
}
|
|
47949
|
+
applyRemoveChildren(childIds) {
|
|
47950
|
+
if (!this.index) {
|
|
47951
|
+
return;
|
|
47952
|
+
}
|
|
47953
|
+
childIds.forEach((childId) => {
|
|
47954
|
+
const foundItem = this.index?.getById(childId);
|
|
47955
|
+
if (this.parent !== childId && this.getId() !== childId) {
|
|
47956
|
+
if (foundItem) {
|
|
47957
|
+
foundItem.transformation.apply({
|
|
47958
|
+
class: "Transformation",
|
|
47959
|
+
method: "translateTo",
|
|
47960
|
+
item: [this.id],
|
|
47961
|
+
x: this.left,
|
|
47962
|
+
y: this.top - this.getHeight() / 2
|
|
47963
|
+
});
|
|
47964
|
+
foundItem.parent = "Board";
|
|
47965
|
+
this.index?.remove(foundItem);
|
|
47966
|
+
this.board.items.index.insert(foundItem);
|
|
47967
|
+
}
|
|
47968
|
+
}
|
|
47969
|
+
});
|
|
47970
|
+
this.updateMbr();
|
|
47971
|
+
this.subject.publish(this);
|
|
47972
|
+
}
|
|
47953
47973
|
getDeck() {
|
|
47954
|
-
return this.
|
|
47974
|
+
return this.index?.list() || [];
|
|
47955
47975
|
}
|
|
47956
47976
|
getTopCard() {
|
|
47957
|
-
const
|
|
47958
|
-
|
|
47977
|
+
const card = this.index?.list()[this.index?.list().length - 1];
|
|
47978
|
+
if (card) {
|
|
47979
|
+
this.removeChildItems(card);
|
|
47980
|
+
return card;
|
|
47981
|
+
}
|
|
47959
47982
|
}
|
|
47960
47983
|
getBottomCard() {
|
|
47961
|
-
const
|
|
47962
|
-
|
|
47984
|
+
const card = this.index?.list()[0];
|
|
47985
|
+
if (card) {
|
|
47986
|
+
this.removeChildItems(card);
|
|
47987
|
+
return card;
|
|
47988
|
+
}
|
|
47963
47989
|
}
|
|
47964
47990
|
getRandomCard() {
|
|
47965
|
-
const
|
|
47966
|
-
|
|
47967
|
-
|
|
47968
|
-
|
|
47969
|
-
const cards = this.findCardsOnBoard(cardIds);
|
|
47970
|
-
this.removeCards(cards);
|
|
47971
|
-
return cards;
|
|
47972
|
-
}
|
|
47973
|
-
findCardsOnBoard(cardIds) {
|
|
47974
|
-
return cardIds.map((cardId) => {
|
|
47975
|
-
return this.board.items.getById(cardId);
|
|
47976
|
-
}).filter((card) => !!card);
|
|
47977
|
-
}
|
|
47978
|
-
updateCards() {
|
|
47979
|
-
if (this.cardIds.length === this.cards.length) {
|
|
47980
|
-
return this.cards;
|
|
47991
|
+
const card = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
|
|
47992
|
+
if (card) {
|
|
47993
|
+
this.removeChildItems(card);
|
|
47994
|
+
return card;
|
|
47981
47995
|
}
|
|
47982
|
-
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
47983
|
-
return this.cards;
|
|
47984
47996
|
}
|
|
47985
47997
|
shuffleDeck() {
|
|
47986
|
-
|
|
47998
|
+
if (!this.index) {
|
|
47999
|
+
return;
|
|
48000
|
+
}
|
|
48001
|
+
const shuffled = [...this.index.list()];
|
|
47987
48002
|
for (let i = shuffled.length - 1;i > 0; i--) {
|
|
47988
48003
|
const j = Math.floor(Math.random() * (i + 1));
|
|
47989
48004
|
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
47990
48005
|
}
|
|
47991
|
-
|
|
47992
|
-
this.
|
|
47993
|
-
}
|
|
47994
|
-
addCards(cards, shouldReplaceExistingCards = false) {
|
|
47995
|
-
cards.forEach((card) => {
|
|
47996
|
-
card.setIsInDeck(true);
|
|
47997
|
-
});
|
|
47998
|
-
this.board.bringToFront(cards);
|
|
47999
|
-
this.emit({
|
|
48000
|
-
class: "Deck",
|
|
48001
|
-
method: "addCards",
|
|
48002
|
-
item: [this.getId()],
|
|
48003
|
-
newData: {
|
|
48004
|
-
cardIds: cards.map((card) => card.getId()),
|
|
48005
|
-
shouldReplaceExistingCards
|
|
48006
|
-
},
|
|
48007
|
-
prevData: { cardIds: this.cardIds, shouldReplaceExistingCards }
|
|
48008
|
-
});
|
|
48009
|
-
}
|
|
48010
|
-
removeCards(cards) {
|
|
48011
|
-
cards.forEach((card) => {
|
|
48012
|
-
card.setIsInDeck(false);
|
|
48013
|
-
});
|
|
48014
|
-
this.emit({
|
|
48015
|
-
class: "Deck",
|
|
48016
|
-
method: "removeCards",
|
|
48017
|
-
item: [this.getId()],
|
|
48018
|
-
newData: { cardIds: cards.map((card) => card.getId()) },
|
|
48019
|
-
prevData: { cardIds: this.cardIds }
|
|
48020
|
-
});
|
|
48006
|
+
this.index.clear();
|
|
48007
|
+
shuffled.forEach((card) => this.index.insert(card));
|
|
48021
48008
|
}
|
|
48022
48009
|
apply(op) {
|
|
48023
48010
|
super.apply(op);
|
|
48024
|
-
switch (op.class) {
|
|
48025
|
-
case "Deck":
|
|
48026
|
-
switch (op.method) {
|
|
48027
|
-
case "addCards":
|
|
48028
|
-
if (op.newData.shouldReplaceExistingCards) {
|
|
48029
|
-
this.cardIds = op.newData.cardIds;
|
|
48030
|
-
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
48031
|
-
} else {
|
|
48032
|
-
this.cardIds = [
|
|
48033
|
-
...op.newData.cardIds,
|
|
48034
|
-
...this.cardIds
|
|
48035
|
-
];
|
|
48036
|
-
this.updateCards();
|
|
48037
|
-
this.updateMbr();
|
|
48038
|
-
}
|
|
48039
|
-
break;
|
|
48040
|
-
case "removeCards":
|
|
48041
|
-
this.cardIds = this.cardIds.filter((card) => {
|
|
48042
|
-
return !op.newData.cardIds.includes(card);
|
|
48043
|
-
});
|
|
48044
|
-
this.updateCards();
|
|
48045
|
-
this.updateMbr();
|
|
48046
|
-
break;
|
|
48047
|
-
}
|
|
48048
|
-
break;
|
|
48049
|
-
}
|
|
48050
48011
|
this.subject.publish(this);
|
|
48051
48012
|
}
|
|
48052
48013
|
updateMbr() {
|
|
48053
|
-
const { translateX, translateY
|
|
48014
|
+
const { translateX, translateY } = this.transformation.matrix;
|
|
48015
|
+
const { right, bottom } = this.index.getMbr();
|
|
48054
48016
|
this.left = translateX;
|
|
48055
48017
|
this.top = translateY;
|
|
48056
|
-
this.right =
|
|
48057
|
-
this.bottom =
|
|
48018
|
+
this.right = right;
|
|
48019
|
+
this.bottom = bottom;
|
|
48058
48020
|
}
|
|
48059
48021
|
deserialize(data) {
|
|
48060
48022
|
super.deserialize(data);
|
|
48061
|
-
this.
|
|
48023
|
+
this.updateMbr();
|
|
48024
|
+
this.subject.publish(this);
|
|
48062
48025
|
return this;
|
|
48063
48026
|
}
|
|
48064
48027
|
render(context) {
|
|
48065
48028
|
if (this.transformationRenderBlock) {
|
|
48066
48029
|
return;
|
|
48067
48030
|
}
|
|
48068
|
-
|
|
48069
|
-
card.render(context, {
|
|
48070
|
-
top: this.top,
|
|
48071
|
-
left: this.left,
|
|
48072
|
-
cardPosition: index2 + 1
|
|
48073
|
-
});
|
|
48074
|
-
});
|
|
48031
|
+
super.render(context);
|
|
48075
48032
|
}
|
|
48076
48033
|
}
|
|
48077
48034
|
registerItem({
|
|
@@ -48419,6 +48376,18 @@ class Hand extends BaseItem {
|
|
|
48419
48376
|
}
|
|
48420
48377
|
this.subject.publish(this);
|
|
48421
48378
|
}
|
|
48379
|
+
getBackgroundColor() {
|
|
48380
|
+
return this.backgroundColor;
|
|
48381
|
+
}
|
|
48382
|
+
getBorderStyle() {
|
|
48383
|
+
return this.borderStyle;
|
|
48384
|
+
}
|
|
48385
|
+
getStrokeColor() {
|
|
48386
|
+
return this.borderColor;
|
|
48387
|
+
}
|
|
48388
|
+
getStrokeWidth() {
|
|
48389
|
+
return this.borderWidth;
|
|
48390
|
+
}
|
|
48422
48391
|
applyBackgroundColor(backgroundColor) {
|
|
48423
48392
|
this.backgroundColor = backgroundColor;
|
|
48424
48393
|
this.path.setBackgroundColor(backgroundColor);
|
package/dist/cjs/index.js
CHANGED
|
@@ -47789,8 +47789,7 @@ var defaultCardData = {
|
|
|
47789
47789
|
itemType: "Card",
|
|
47790
47790
|
isOpen: false,
|
|
47791
47791
|
faceUrl: "",
|
|
47792
|
-
backsideUrl: ""
|
|
47793
|
-
isInDeck: false
|
|
47792
|
+
backsideUrl: ""
|
|
47794
47793
|
};
|
|
47795
47794
|
var CARD_DIMENSIONS = { width: 250, height: 400 };
|
|
47796
47795
|
|
|
@@ -47799,7 +47798,6 @@ class Card extends BaseItem {
|
|
|
47799
47798
|
faceUrl = "";
|
|
47800
47799
|
backsideUrl = "";
|
|
47801
47800
|
isOpen = false;
|
|
47802
|
-
isInDeck = false;
|
|
47803
47801
|
throttledBringToFront;
|
|
47804
47802
|
face = null;
|
|
47805
47803
|
backside = null;
|
|
@@ -47835,35 +47833,20 @@ class Card extends BaseItem {
|
|
|
47835
47833
|
};
|
|
47836
47834
|
this.updateImageToRender();
|
|
47837
47835
|
}
|
|
47838
|
-
setIsInDeck(isInDeck) {
|
|
47839
|
-
this.emit({
|
|
47840
|
-
class: "Card",
|
|
47841
|
-
method: "setIsInDeck",
|
|
47842
|
-
item: [this.getId()],
|
|
47843
|
-
newData: { isInDeck },
|
|
47844
|
-
prevData: { isInDeck: this.isInDeck }
|
|
47845
|
-
});
|
|
47846
|
-
}
|
|
47847
47836
|
updateImageToRender() {
|
|
47848
47837
|
this.imageToRender = this.backside;
|
|
47849
47838
|
if (this.isOpen) {
|
|
47850
47839
|
this.imageToRender = this.face;
|
|
47851
47840
|
}
|
|
47852
47841
|
}
|
|
47853
|
-
render(context
|
|
47854
|
-
if (this.transformationRenderBlock
|
|
47842
|
+
render(context) {
|
|
47843
|
+
if (this.transformationRenderBlock) {
|
|
47855
47844
|
return;
|
|
47856
47845
|
}
|
|
47857
47846
|
const ctx = context.ctx;
|
|
47858
47847
|
if (this.imageToRender && this.imageToRender.complete) {
|
|
47859
47848
|
ctx.save();
|
|
47860
|
-
|
|
47861
|
-
let top = this.top;
|
|
47862
|
-
if (deckRenderData) {
|
|
47863
|
-
left = deckRenderData.left + 2 * deckRenderData.cardPosition;
|
|
47864
|
-
top = deckRenderData.top;
|
|
47865
|
-
}
|
|
47866
|
-
ctx.drawImage(this.imageToRender, left, top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
|
|
47849
|
+
ctx.drawImage(this.imageToRender, this.left, this.top, CARD_DIMENSIONS.width, CARD_DIMENSIONS.height);
|
|
47867
47850
|
ctx.restore();
|
|
47868
47851
|
}
|
|
47869
47852
|
}
|
|
@@ -47874,12 +47857,6 @@ class Card extends BaseItem {
|
|
|
47874
47857
|
this.right = this.left + CARD_DIMENSIONS.width * scaleX;
|
|
47875
47858
|
this.bottom = this.top + CARD_DIMENSIONS.height * scaleY;
|
|
47876
47859
|
}
|
|
47877
|
-
getMbr() {
|
|
47878
|
-
if (this.isInDeck) {
|
|
47879
|
-
return new Mbr(1e4, 1e4, 1e4, 1e4);
|
|
47880
|
-
}
|
|
47881
|
-
return super.getMbr();
|
|
47882
|
-
}
|
|
47883
47860
|
getPath() {
|
|
47884
47861
|
return new Path(this.getMbr().getLines());
|
|
47885
47862
|
}
|
|
@@ -47912,9 +47889,6 @@ class Card extends BaseItem {
|
|
|
47912
47889
|
this.isOpen = op.newData.isOpen;
|
|
47913
47890
|
this.updateImageToRender();
|
|
47914
47891
|
break;
|
|
47915
|
-
case "setIsInDeck":
|
|
47916
|
-
this.isInDeck = op.newData.isInDeck;
|
|
47917
|
-
break;
|
|
47918
47892
|
}
|
|
47919
47893
|
break;
|
|
47920
47894
|
}
|
|
@@ -47927,22 +47901,20 @@ registerItem({
|
|
|
47927
47901
|
});
|
|
47928
47902
|
// src/Items/Examples/CardGame/Deck/Deck.ts
|
|
47929
47903
|
var defaultDeckData = {
|
|
47930
|
-
itemType: "Deck"
|
|
47931
|
-
cardIds: []
|
|
47904
|
+
itemType: "Deck"
|
|
47932
47905
|
};
|
|
47933
47906
|
|
|
47934
47907
|
class Deck extends BaseItem {
|
|
47935
47908
|
subject = new Subject;
|
|
47936
47909
|
shouldUseCustomRender = false;
|
|
47937
|
-
cardIds = [];
|
|
47938
|
-
cards = [];
|
|
47939
47910
|
constructor(board, id = "", defaultData2, cards) {
|
|
47940
|
-
super(board, id, defaultDeckData);
|
|
47911
|
+
super(board, id, defaultDeckData, true);
|
|
47912
|
+
this.index.getUnderPoint = () => [];
|
|
47913
|
+
this.index.getEnclosed = () => [];
|
|
47914
|
+
this.index.getEnclosedOrCrossed = () => [];
|
|
47941
47915
|
if (cards) {
|
|
47942
|
-
this.
|
|
47943
|
-
cards.
|
|
47944
|
-
this.transformation.matrix = cards[cards.length - 1].transformation.matrix;
|
|
47945
|
-
this.cardIds = cards.map((card) => card.getId());
|
|
47916
|
+
this.transformation.matrix = cards[0].transformation.matrix;
|
|
47917
|
+
this.applyAddChildren(cards.map((card) => card.getId()));
|
|
47946
47918
|
}
|
|
47947
47919
|
this.transformation.subject.subscribe(() => {
|
|
47948
47920
|
this.updateMbr();
|
|
@@ -47950,128 +47922,113 @@ class Deck extends BaseItem {
|
|
|
47950
47922
|
});
|
|
47951
47923
|
this.updateMbr();
|
|
47952
47924
|
}
|
|
47925
|
+
applyAddChildren(childIds) {
|
|
47926
|
+
if (!this.index) {
|
|
47927
|
+
return;
|
|
47928
|
+
}
|
|
47929
|
+
childIds.forEach((childId) => {
|
|
47930
|
+
const foundItem = this.board.items.getById(childId);
|
|
47931
|
+
if (this.parent !== childId && this.getId() !== childId) {
|
|
47932
|
+
if (!this.index?.getById(childId) && foundItem?.itemType === "Card") {
|
|
47933
|
+
foundItem.transformation.apply({
|
|
47934
|
+
class: "Transformation",
|
|
47935
|
+
method: "translateTo",
|
|
47936
|
+
item: [this.id],
|
|
47937
|
+
x: this.left + (this.index?.list().length || 0) * 2,
|
|
47938
|
+
y: this.top
|
|
47939
|
+
});
|
|
47940
|
+
foundItem.parent = this.getId();
|
|
47941
|
+
this.board.items.index.remove(foundItem);
|
|
47942
|
+
this.index?.insert(foundItem);
|
|
47943
|
+
}
|
|
47944
|
+
}
|
|
47945
|
+
});
|
|
47946
|
+
this.updateMbr();
|
|
47947
|
+
this.subject.publish(this);
|
|
47948
|
+
}
|
|
47949
|
+
applyRemoveChildren(childIds) {
|
|
47950
|
+
if (!this.index) {
|
|
47951
|
+
return;
|
|
47952
|
+
}
|
|
47953
|
+
childIds.forEach((childId) => {
|
|
47954
|
+
const foundItem = this.index?.getById(childId);
|
|
47955
|
+
if (this.parent !== childId && this.getId() !== childId) {
|
|
47956
|
+
if (foundItem) {
|
|
47957
|
+
foundItem.transformation.apply({
|
|
47958
|
+
class: "Transformation",
|
|
47959
|
+
method: "translateTo",
|
|
47960
|
+
item: [this.id],
|
|
47961
|
+
x: this.left,
|
|
47962
|
+
y: this.top - this.getHeight() / 2
|
|
47963
|
+
});
|
|
47964
|
+
foundItem.parent = "Board";
|
|
47965
|
+
this.index?.remove(foundItem);
|
|
47966
|
+
this.board.items.index.insert(foundItem);
|
|
47967
|
+
}
|
|
47968
|
+
}
|
|
47969
|
+
});
|
|
47970
|
+
this.updateMbr();
|
|
47971
|
+
this.subject.publish(this);
|
|
47972
|
+
}
|
|
47953
47973
|
getDeck() {
|
|
47954
|
-
return this.
|
|
47974
|
+
return this.index?.list() || [];
|
|
47955
47975
|
}
|
|
47956
47976
|
getTopCard() {
|
|
47957
|
-
const
|
|
47958
|
-
|
|
47977
|
+
const card = this.index?.list()[this.index?.list().length - 1];
|
|
47978
|
+
if (card) {
|
|
47979
|
+
this.removeChildItems(card);
|
|
47980
|
+
return card;
|
|
47981
|
+
}
|
|
47959
47982
|
}
|
|
47960
47983
|
getBottomCard() {
|
|
47961
|
-
const
|
|
47962
|
-
|
|
47984
|
+
const card = this.index?.list()[0];
|
|
47985
|
+
if (card) {
|
|
47986
|
+
this.removeChildItems(card);
|
|
47987
|
+
return card;
|
|
47988
|
+
}
|
|
47963
47989
|
}
|
|
47964
47990
|
getRandomCard() {
|
|
47965
|
-
const
|
|
47966
|
-
|
|
47967
|
-
|
|
47968
|
-
|
|
47969
|
-
const cards = this.findCardsOnBoard(cardIds);
|
|
47970
|
-
this.removeCards(cards);
|
|
47971
|
-
return cards;
|
|
47972
|
-
}
|
|
47973
|
-
findCardsOnBoard(cardIds) {
|
|
47974
|
-
return cardIds.map((cardId) => {
|
|
47975
|
-
return this.board.items.getById(cardId);
|
|
47976
|
-
}).filter((card) => !!card);
|
|
47977
|
-
}
|
|
47978
|
-
updateCards() {
|
|
47979
|
-
if (this.cardIds.length === this.cards.length) {
|
|
47980
|
-
return this.cards;
|
|
47991
|
+
const card = this.index?.list()[Math.floor(Math.random() * this.index?.list().length)];
|
|
47992
|
+
if (card) {
|
|
47993
|
+
this.removeChildItems(card);
|
|
47994
|
+
return card;
|
|
47981
47995
|
}
|
|
47982
|
-
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
47983
|
-
return this.cards;
|
|
47984
47996
|
}
|
|
47985
47997
|
shuffleDeck() {
|
|
47986
|
-
|
|
47998
|
+
if (!this.index) {
|
|
47999
|
+
return;
|
|
48000
|
+
}
|
|
48001
|
+
const shuffled = [...this.index.list()];
|
|
47987
48002
|
for (let i = shuffled.length - 1;i > 0; i--) {
|
|
47988
48003
|
const j = Math.floor(Math.random() * (i + 1));
|
|
47989
48004
|
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
47990
48005
|
}
|
|
47991
|
-
|
|
47992
|
-
this.
|
|
47993
|
-
}
|
|
47994
|
-
addCards(cards, shouldReplaceExistingCards = false) {
|
|
47995
|
-
cards.forEach((card) => {
|
|
47996
|
-
card.setIsInDeck(true);
|
|
47997
|
-
});
|
|
47998
|
-
this.board.bringToFront(cards);
|
|
47999
|
-
this.emit({
|
|
48000
|
-
class: "Deck",
|
|
48001
|
-
method: "addCards",
|
|
48002
|
-
item: [this.getId()],
|
|
48003
|
-
newData: {
|
|
48004
|
-
cardIds: cards.map((card) => card.getId()),
|
|
48005
|
-
shouldReplaceExistingCards
|
|
48006
|
-
},
|
|
48007
|
-
prevData: { cardIds: this.cardIds, shouldReplaceExistingCards }
|
|
48008
|
-
});
|
|
48009
|
-
}
|
|
48010
|
-
removeCards(cards) {
|
|
48011
|
-
cards.forEach((card) => {
|
|
48012
|
-
card.setIsInDeck(false);
|
|
48013
|
-
});
|
|
48014
|
-
this.emit({
|
|
48015
|
-
class: "Deck",
|
|
48016
|
-
method: "removeCards",
|
|
48017
|
-
item: [this.getId()],
|
|
48018
|
-
newData: { cardIds: cards.map((card) => card.getId()) },
|
|
48019
|
-
prevData: { cardIds: this.cardIds }
|
|
48020
|
-
});
|
|
48006
|
+
this.index.clear();
|
|
48007
|
+
shuffled.forEach((card) => this.index.insert(card));
|
|
48021
48008
|
}
|
|
48022
48009
|
apply(op) {
|
|
48023
48010
|
super.apply(op);
|
|
48024
|
-
switch (op.class) {
|
|
48025
|
-
case "Deck":
|
|
48026
|
-
switch (op.method) {
|
|
48027
|
-
case "addCards":
|
|
48028
|
-
if (op.newData.shouldReplaceExistingCards) {
|
|
48029
|
-
this.cardIds = op.newData.cardIds;
|
|
48030
|
-
this.cards = this.findCardsOnBoard(this.cardIds);
|
|
48031
|
-
} else {
|
|
48032
|
-
this.cardIds = [
|
|
48033
|
-
...op.newData.cardIds,
|
|
48034
|
-
...this.cardIds
|
|
48035
|
-
];
|
|
48036
|
-
this.updateCards();
|
|
48037
|
-
this.updateMbr();
|
|
48038
|
-
}
|
|
48039
|
-
break;
|
|
48040
|
-
case "removeCards":
|
|
48041
|
-
this.cardIds = this.cardIds.filter((card) => {
|
|
48042
|
-
return !op.newData.cardIds.includes(card);
|
|
48043
|
-
});
|
|
48044
|
-
this.updateCards();
|
|
48045
|
-
this.updateMbr();
|
|
48046
|
-
break;
|
|
48047
|
-
}
|
|
48048
|
-
break;
|
|
48049
|
-
}
|
|
48050
48011
|
this.subject.publish(this);
|
|
48051
48012
|
}
|
|
48052
48013
|
updateMbr() {
|
|
48053
|
-
const { translateX, translateY
|
|
48014
|
+
const { translateX, translateY } = this.transformation.matrix;
|
|
48015
|
+
const { right, bottom } = this.index.getMbr();
|
|
48054
48016
|
this.left = translateX;
|
|
48055
48017
|
this.top = translateY;
|
|
48056
|
-
this.right =
|
|
48057
|
-
this.bottom =
|
|
48018
|
+
this.right = right;
|
|
48019
|
+
this.bottom = bottom;
|
|
48058
48020
|
}
|
|
48059
48021
|
deserialize(data) {
|
|
48060
48022
|
super.deserialize(data);
|
|
48061
|
-
this.
|
|
48023
|
+
this.updateMbr();
|
|
48024
|
+
this.subject.publish(this);
|
|
48062
48025
|
return this;
|
|
48063
48026
|
}
|
|
48064
48027
|
render(context) {
|
|
48065
48028
|
if (this.transformationRenderBlock) {
|
|
48066
48029
|
return;
|
|
48067
48030
|
}
|
|
48068
|
-
|
|
48069
|
-
card.render(context, {
|
|
48070
|
-
top: this.top,
|
|
48071
|
-
left: this.left,
|
|
48072
|
-
cardPosition: index2 + 1
|
|
48073
|
-
});
|
|
48074
|
-
});
|
|
48031
|
+
super.render(context);
|
|
48075
48032
|
}
|
|
48076
48033
|
}
|
|
48077
48034
|
registerItem({
|
|
@@ -48419,6 +48376,18 @@ class Hand extends BaseItem {
|
|
|
48419
48376
|
}
|
|
48420
48377
|
this.subject.publish(this);
|
|
48421
48378
|
}
|
|
48379
|
+
getBackgroundColor() {
|
|
48380
|
+
return this.backgroundColor;
|
|
48381
|
+
}
|
|
48382
|
+
getBorderStyle() {
|
|
48383
|
+
return this.borderStyle;
|
|
48384
|
+
}
|
|
48385
|
+
getStrokeColor() {
|
|
48386
|
+
return this.borderColor;
|
|
48387
|
+
}
|
|
48388
|
+
getStrokeWidth() {
|
|
48389
|
+
return this.borderWidth;
|
|
48390
|
+
}
|
|
48422
48391
|
applyBackgroundColor(backgroundColor) {
|
|
48423
48392
|
this.backgroundColor = backgroundColor;
|
|
48424
48393
|
this.path.setBackgroundColor(backgroundColor);
|