Parcourir la source

Collection/Deck Card Holder events

Dim Dim il y a 6 ans
Parent
commit
d255023157

+ 8 - 3
src/Game/views/base/CollectionHolder.js

@@ -38,6 +38,9 @@ class CollectionHolder extends CardHolder {
         
         this.unsetEvents();
         this.refresh();
+
+        EventManager.on('CardAddedToDeck', this.deckAdd);
+        EventManager.on('CardRemovedFromDeck', this.deckRemove);
     }
 
     setEvents() {
@@ -58,16 +61,18 @@ class CollectionHolder extends CardHolder {
         this.z -= 1;
     }
 
-    remove(){
+    deckAdd(){
         //when you place card in deck
-        this.cards.pop();
+        let card = this.cards.pop();
+        card._kill();
         this.z += 1;
         if (this.counter - this.deckCards >0){
             this.createCard();
         }
+        //card should be killed
     }
 
-    deckRemoval(){
+    deckRemove(){
         //when you remove card from deck and it is added to collectionm, if you have only one copy in collection, add another copy
         if (this.counter - this.deckCards <2){
             this.createCard();

+ 51 - 0
src/Game/views/base/DeckCardHolder.js

@@ -0,0 +1,51 @@
+import * as PIXI from 'pixi.js';
+//import { getParam } from '../../../helpers/url';
+
+import CardHolder from './CardHolder';
+import Card from './Card';
+import EventManager from '../../services/EventManager';
+import Injector from '../../services/Injector';
+
+//const DefaultImageUrl = '/files/assets/ui/woodenbutton.png';
+//const DefaultImage = PIXI.Texture.fromImage(DefaultImageUrl);
+
+import config from '../../config.js';
+
+class DeckCardHolder extends CardHolder {
+    constructor(props) {
+        super(props);
+        let {
+
+        } = props;
+
+        // Properties Component 
+
+        this.construct(props);
+
+        this.appear();
+        this.uncloak();
+        this.show();
+        
+    }
+
+    lock(card = null) {
+        this.unsetEvents();
+        this._locked = true;
+        this._card = card;
+        if(card) {
+            card.attach(this);
+            EventManager.trigger('CardAddedToDeck');
+            //if(this._lockable)card.unsetEvents();
+        }
+    }
+
+    unlock() {
+        EventManager.trigger('CardRemovedFromDeck');
+        this.setEvents();
+        this._locked = false;
+        this._card = null;
+    }
+
+}
+
+export default DeckCardHolder;

+ 10 - 10
src/helpers/dragAndDrop.js

@@ -21,17 +21,17 @@ function dragAndDrop(sprite) {
     sprite.stopDND = () => {
         sprite
         // events for drag start
-        .off('mousedown', onDragStart)
-        .off('touchstart', onDragStart)
+            .off('mousedown', onDragStart)
+            .off('touchstart', onDragStart)
         // events for drag end
-        .off('mouseup', onDragEnd)
-        .off('mouseupoutside', onDragEnd)
-        .off('touchend', onDragEnd)
-        .off('touchendoutside', onDragEnd)
+            .off('mouseup', onDragEnd)
+            .off('mouseupoutside', onDragEnd)
+            .off('touchend', onDragEnd)
+            .off('touchendoutside', onDragEnd)
         //events for drag move
-        .off('mousemove', onDragMove)
-        .off('touchmove', onDragMove);
-    }
+            .off('mousemove', onDragMove)
+            .off('touchmove', onDragMove);
+    };
 }
 
 function place(holder) {
@@ -75,7 +75,7 @@ function onDragEnd()
     EventManager.emit('CardDraggingFinished');
     // Remove Card Placed Callbacks
     setTimeout(() => {
-        EventManager.off('CardPlaced', this.placeFn)
+        EventManager.off('CardPlaced', this.placeFn);
         this.dragging = false;
         this.alpha = 1;
         // set the interaction data to null