diff --git a/public/board.js b/public/board.js index 568b222..8d2bfcd 100644 --- a/public/board.js +++ b/public/board.js @@ -486,8 +486,15 @@ class Board{ playerTo = playerFrom; } + // Check if there's more than 1 thing add that position (something's gone wrong somewhere) + let items = this.ECSLoop(elementFrom, playerFrom, null, fromPosition); + if(board.ECSLoop(elementFrom, playerFrom, null, fromPosition).length > 1){ + alert('ERROR: There are more than 1 card being added'); + } + // First (and only) item returned is the key thins should be done with - let itemKey = this.ECSLoop(elementFrom, playerFrom, null, fromPosition)[0]; + let itemKey = items[0]; + if(listPosition[itemKey] == fromPosition){ // Check if a toPostion supplied if(toPosition == null){ @@ -571,7 +578,7 @@ class Board{ case 'hand': // Mana cost required and mana tapping for playing a card from hand, etc // The player casting/summoning should pay, ofc - let canPayMana = this.canPayMana(itemKey, fromPlayer) + let canPayMana = this.canPayMana(itemKey, fromPlayer); if(canPayMana !== true){ alert(canPayMana); return false; @@ -586,8 +593,9 @@ class Board{ // TODO: Tap mana of correct colour (also allow player to select in fut) if(!this.isTapped(mana) && cardData[mana].colour == cardData[itemKey].colour){ this.tapCard(mana); + break; // Temp TODO: Tap each mana needed until manacost/colours are met, also TODO: allow user to target own mana OR use non-multitypes first (not implemented yet) }else{ - return false; + continue; } } } @@ -634,13 +642,14 @@ class Board{ // TODO: Multicolours, and X of same colour checks let manaUsed = []; // For now, until adding colour, and other attributes to ECS modal - let manaRequired = cardData[itemToPlay].colour; - console.log(manaRequired); + let manaColourRequired = cardData[itemToPlay].colour; + console.log(manaColourRequired); let items = this.ECSLoop('mana', player[itemToPlay], null, null); for(let item = 0; item < items.length; item++){ let itemKey = items[item]; - if(cardData[itemKey].colour == manaRequired && !this.isTapped(itemKey)){ + if(cardData[itemKey].colour == manaColourRequired && !this.isTapped(itemKey)){ manaUsed.push(itemKey); // This would be how I'd loop for X colour, or multi + console.log(manaUsed); return true; } } @@ -771,11 +780,12 @@ class Board{ } } - playMana(fromPosition, fromElement, cardsToPlay = 1){ + playMana(fromPosition, fromElement, fromPlayer, cardsToPlay = 1){ // Move from player0, fromPosition of hand (for now), to mana // TODO: FOR ALL addFromBoardElements, if 'fromPosition' not passed get the // fromPosition and boardElementFrom from the itemId (will need to change to pass this) - this.addFromBoardElement(0, fromPosition, fromElement, 'mana', null, null); + console.log('playMana('+fromPosition+','+fromElement+','+cardsToPlay+')'); + this.addFromBoardElement(fromPlayer, fromPosition, fromElement, 'mana', null, null); } // HELPER METHODS, to simplify code-base for me in the future @@ -860,6 +870,8 @@ canvas.addEventListener('contextmenu', function(event) { var x = event.pageX - canvasLeft, y = event.pageY - canvasTop; + console.log('RIGHT CLICK X: '+x+' Y: '+y); + for(let itemKey = 0; itemKey < item.length; itemKey++){ if(elements[itemKey] == 'deck'){ @@ -874,6 +886,9 @@ canvas.addEventListener('contextmenu', function(event) { // Only want to happen once (for now) // Maybe in future add to hand would trigger another event if there's an effect? + // Player the item belongs to, not who's doing the action + let playerId = player[itemKey]; + // Check the location of element switch(boardElement[itemKey]){ // Check item location, and trigger events based on it @@ -886,15 +901,17 @@ canvas.addEventListener('contextmenu', function(event) { if(inEvent && inEvent[0] == 'attack' && itemKey == inEvent[1]){ board.cancelAttackFor(itemKey); } - board.drawBoard(); break; case 'hand': // Can be played as mana (right click for now) // Play item from boardElement hand. To boardElement mana (explanitory) - board.playMana(listPosition[itemKey], 'hand'); - board.drawBoard(); + board.playMana(listPosition[itemKey], 'hand', playerId); + break; + default: break; } + board.drawBoard(); + return true; } } } @@ -916,7 +933,7 @@ canvas.addEventListener('click', function(event) { // Will be the new way // TODO:Maybe write this into a function? If XY WH is hit return true, and the itemKey // then it can be re-used in contextclick, hover, etc without rewrite - console.log('X: '+x+' Y: '+y); + console.log('LEFT CLICK X: '+x+' Y: '+y); // TODO: Normalise this too for(let itemKey = 0; itemKey < item.length; itemKey++){ @@ -991,8 +1008,11 @@ canvas.addEventListener('click', function(event) { board.makeAttack(itemKey); } break; + default: + break; } board.drawBoard(); + return true; } } }