|
@@ -4,8 +4,12 @@
|
|
import GuiableContainer from '../../../helpers/Guiable';
|
|
import GuiableContainer from '../../../helpers/Guiable';
|
|
// import Deck from '../../assets/deck';
|
|
// import Deck from '../../assets/deck';
|
|
import CardHolder from '../base/CardHolder';
|
|
import CardHolder from '../base/CardHolder';
|
|
|
|
+
|
|
import Card from '../base/Card';
|
|
import Card from '../base/Card';
|
|
|
|
|
|
|
|
+import EventManager from '../../services/EventManager';
|
|
|
|
+
|
|
|
|
+
|
|
class DeckHandler extends GuiableContainer{
|
|
class DeckHandler extends GuiableContainer{
|
|
constructor(props) {
|
|
constructor(props) {
|
|
super(props);
|
|
super(props);
|
|
@@ -28,6 +32,9 @@ class DeckHandler extends GuiableContainer{
|
|
this.addToFolder('Deck', this.options, 'x').onFinishChange((v) => this.position.x = v);
|
|
this.addToFolder('Deck', this.options, 'x').onFinishChange((v) => this.position.x = v);
|
|
this.addToFolder('Deck', this.options, 'y').onFinishChange((v) => this.position.y = v);
|
|
this.addToFolder('Deck', this.options, 'y').onFinishChange((v) => this.position.y = v);
|
|
|
|
|
|
|
|
+ EventManager.on('increaseDeckCards', this.increaseCardCounter, this._card.id);
|
|
|
|
+ EventManager.on('removeDeckCards',this.decreaseCardCounter, this._card.id);
|
|
|
|
+
|
|
this.construct(props);
|
|
this.construct(props);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -40,6 +47,7 @@ class DeckHandler extends GuiableContainer{
|
|
|
|
|
|
let DeckScale = 0.35;
|
|
let DeckScale = 0.35;
|
|
this.cards = [];
|
|
this.cards = [];
|
|
|
|
+ this.cardsMap = {};
|
|
|
|
|
|
this.cards.push(new CardHolder({GameLayer, 'x': 160, 'y': -230, team: 0, id: 3}).scaleTo(DeckScale));
|
|
this.cards.push(new CardHolder({GameLayer, 'x': 160, 'y': -230, team: 0, id: 3}).scaleTo(DeckScale));
|
|
this.cards.push(new CardHolder({GameLayer, 'x': 160, 'y': 0, team: 1, id: 1}).scaleTo(DeckScale));
|
|
this.cards.push(new CardHolder({GameLayer, 'x': 160, 'y': 0, team: 1, id: 1}).scaleTo(DeckScale));
|
|
@@ -99,6 +107,22 @@ class DeckHandler extends GuiableContainer{
|
|
team: this.options.team
|
|
team: this.options.team
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ increaseCardCounter(id){
|
|
|
|
+ if (this.cardsMap(id)){
|
|
|
|
+ this.cardsMap[id] += 1;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ this.cardsMap[id] = 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ decreaseCardCounter(id){
|
|
|
|
+ this.cardsMap[id] -= 1;
|
|
|
|
+ if (this.cardsMap[id] === 0){
|
|
|
|
+ delete this.cardsMap[id];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
export default DeckHandler;
|
|
export default DeckHandler;
|