From 9890f5302bd3c03114a41b542c6624d1982cc5a8 Mon Sep 17 00:00:00 2001 From: Nathan Date: Sun, 13 Oct 2024 00:06:30 +0100 Subject: [PATCH] Redo basics of inspect item --- public/board.js | 53 +++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/public/board.js b/public/board.js index 48beb1f..6b1a3f9 100644 --- a/public/board.js +++ b/public/board.js @@ -48,6 +48,8 @@ let opponentManaZone = []; // To disable drawing each time something changes let drawEachEvent = true; +let yourPlayerId = 0; // To compare click events of your/opponents cards +let viewingPlayerId = 0; // To show the board from your/opponent/teammates perspective, etc. without play permission let deckCount = 60; let deckCountOpponent = 60; @@ -57,7 +59,6 @@ const maxHandSize = 4; const maxBoardSize = 3; const maxShield = 4; -let inspectCard = null; let attackingCard = null; // Gonna need lots of refactoring, and sorting @@ -92,7 +93,7 @@ class Board{ this.drawWin(); } - this.drawInspectedCard(); + //this.drawInspectedCard(); } checkGameWin(){ @@ -665,21 +666,15 @@ class Board{ this.drawBoard(); } - inspectOpponentBoard(index){ - // Get the card data - inspectCard = [opponentBoard, index]; - + inspectCard(cardToInspect){ + // Set inspectedCard (for now) to the card itemKey + inEvent = ['inspect', cardToInspect]; this.drawBoard(); } - drawInspectedCard(){ - if(inspectCard != null){ - let positionX = canvas.width/2 - cardWidth; - let positionY = canvas.height/2 - cardHeight; - let width = cardWidth*2; - let height = cardHeight*2; - - this.drawCard(inspectCard[0], inspectCard[1], name, positionX, positionY, width, height, '#D1D100'); - console.log('inspect'); + cancelInspect(){ + if(inEvent && inEvent[0] == 'inspect'){ + inEvent = null; + this.drawBoard(); } } @@ -999,20 +994,29 @@ canvas.addEventListener('click', function(event) { // Can attack console.log(inEvent); console.log(cardStatus[itemKey] != 'tapped'); - if(!inEvent && cardStatus[itemKey] != 'tapped'){ + // yourPlayerId in for now to prevent using opponents card + // however in future the cards may be used to attack, there will be another + // check like 'canUseOpponentsBoard' or something + if(!inEvent && cardStatus[itemKey] != 'tapped' && playerId == yourPlayerId){ board.startAttack(itemKey); } // opponentBoard // If there's an attack event, target other cards - if(inEvent && inEvent[0] == 'attack' && inEvent[1] != itemKey){ + // Again yourPlayerId check for now, this time so your can't hit your own + if(inEvent && inEvent[0] == 'attack' && inEvent[1] != itemKey && playerId != yourPlayerId){ // Make attack on the card clicked, with card in inEvent[1] board.makeAttack(itemKey); } // If no event, and clicked an OPPONENT CARD (for now) + // Wants to be on option on r/l click maybe + // left click inspects then you choose play from there? // inspect the card (zoom in on it) - if(!inEvent){ - board.inspectOpponentBoard(itemKey); + if(!inEvent && playerId != yourPlayerId){ + board.inspectCard(itemKey); + } + else if(inEvent && inEvent[0] == 'inspect' && inEvent[1] == itemKey){ + board.cancelInspect(); } board.drawBoard(); @@ -1289,6 +1293,17 @@ function calculateItemSizePosition(itemKey){ height = cHeight; } + // Inspected Card + // May need to make a new itemKey for inspectedCard to loop through + if(inEvent && inEvent[0] == 'inspect' && inEvent[1] == itemKey){ + positionX = canvas.width/2 - cardWidth; + positionY = canvas.height/2 - cardHeight; + width = cardWidth*2; + height = cardHeight*2; + } + + + //console.log('cardName: '+cardData[itemKey].name+', i/listPosition: '+i+', listPosition Length: '+itemListLength); // Set the size/position of the item