From 7570729449aff1213c440240dbe03cda628b6299 Mon Sep 17 00:00:00 2001 From: Nathan Date: Sun, 20 Oct 2024 17:06:18 +0100 Subject: [PATCH] Create temp function for jank 'getPrimaryColour' --- public/board.js | 59 ++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/public/board.js b/public/board.js index 0fe9163..e6e4591 100644 --- a/public/board.js +++ b/public/board.js @@ -553,22 +553,8 @@ class Board{ continue; } + let colourId = this.tempGetPrimaryManaOfCard(mana); - // TODO: do better. - let manaType = null; // TODO: Will use the highest mana req as it's colour for now - let manaColours = cardColours[mana]; - for(let i = 0; i < manaColours.length; i++){ - // Set mana colour for card if there isn't one - if(manaType == null){ manaType = manaColours[i]; } - // Check each other colour, use the highest cost colour - // as the colour type for this specific mana - // TODO: Do better, and nicer, manaType in DB with the colour? - if(manaColours[i][1] > manaType[1]){ - manaType = manaColours[i]; - } - } - - let colourId = manaType[0]; console.log(JSON.stringify(manaRequired)); // Loop the requirements of the cost to pay for (const manaColour in manaRequired) { @@ -647,6 +633,29 @@ class Board{ continue; } + let colourId = this.tempGetPrimaryManaOfCard(itemKey); + manaAvailable[colourId] += 1; + + } + + // If the manaReq is satiated by the manaAvailable then return true + for (const manaColour in manaRequired) { + //console.log('req'); + //console.log(manaRequired[manaColour]); + //console.log('av'); + //console.log(manaAvailable[manaColour]); + if(manaRequired[manaColour] > manaAvailable[manaColour]){ + return 'Do not have enough: '+manaColour+' mana'; + } + } + + //console.log('manaAvailable: '); + //console.log(manaAvailable); + + return true; + } + + tempGetPrimaryManaOfCard(targetCard){ // Loop the mana card's colours // can be multi-coloured, and can be used as diff costs @@ -657,7 +666,7 @@ class Board{ // cards aren't all those when in mana (ie. 6 colour decks can't play // everything all the time) let manaType = null; // TODO: Will use the highest mana req as it's colour for now - let manaColours = cardColours[itemKey]; + let manaColours = cardColours[targetCard]; for(let i = 0; i < manaColours.length; i++){ // Set mana colour for card if there isn't one if(manaType == null){ manaType = manaColours[i]; } @@ -669,24 +678,8 @@ class Board{ } } let colourId = manaType[0]; - manaAvailable[colourId] += 1; - } + return colourId; - // If the manaReq is satiated by the manaAvailable then return true - for (const manaColour in manaRequired) { - //console.log('req'); - //console.log(manaRequired[manaColour]); - //console.log('av'); - //console.log(manaAvailable[manaColour]); - if(manaRequired[manaColour] > manaAvailable[manaColour]){ - return 'Do not have enough: '+manaColour+' mana'; - } - } - - //console.log('manaAvailable: '); - //console.log(manaAvailable); - - return true; } getManaTotalOf(itemKey){