From 79bd2da8452d7ac997a9f83f56047ec3032a84ff Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 14 Oct 2024 15:49:26 +0100 Subject: [PATCH] Add faux deckDB/array to add cards/decklists --- public/board.js | 81 +++++++++++++++++++++++++++-------------------- public/cards.js | 21 ++++++++++++ public/index.html | 4 +++ 3 files changed, 71 insertions(+), 35 deletions(-) create mode 100644 public/cards.js diff --git a/public/board.js b/public/board.js index 1037faf..568b222 100644 --- a/public/board.js +++ b/public/board.js @@ -158,6 +158,7 @@ class Board{ let colourId = cardData[itemKey].colour; if(colourId == 0){ fill = '#EEE'; } else if(colourId == 1){ fill = '#0033EE'; } + else if(colourId == 2){ fill = '#ED344A'; } }else{ fill = '#B0B0B0'; } @@ -541,7 +542,7 @@ class Board{ alert('Hand full '+elementLength+'/'+maxHandSize); return 0; } - this.addFromBoardElement(playerId, 0, 'deck', 'hand', null, null); + this.addFromBoardElement(playerId, 1, 'deck', 'hand', null, null); } } @@ -841,12 +842,12 @@ let board = new Board; // TODO: TEMP!! Replace soon createDeck(); -createDeckList(playerDeck, deckCount, 0); -createDeckList(opponentDeck, deckCountOpponent, 1); +//createDeckList(playerDeck, deckCount, 0); +//createDeckList(opponentDeck, deckCountOpponent, 1); // Play 4 shield from top (0) of each players deck for(let currentPlayer = 0; currentPlayer <= players-1; currentPlayer++){ - board.playShield(0, 'deck', currentPlayer, 4); + board.playShield(1, 'deck', currentPlayer, 4); } board.drawBoard(true); @@ -1047,43 +1048,40 @@ function createDeck(){ itemCount++; } - console.log(item.length); // createDeckList will need to continue from here, not 0 + // Loop again and create the deckLists + for(let i = 0; i < players; i++){ + createDeckList(i); + } + } -// TEMP: Create a deck of X different cards that can be drawn/played -// for UI development, will be done on server and not shown to clients -// TODO: Randomly create a deck from objects stored in file (for now) then DB -// 3 of each card max, and likely one colour too for time being -function createDeckList(deck, deckCount, playerId){ - let i = item.length; // Continue from the last item, don't overwrite - deckCount = deckCount + i; - for(i; i < deckCount; i++){ - // Randomise colour - let colour = Math.floor(Math.random() * 2); - let effect = Math.floor(Math.random() * 5); - if(effect == 0){ effect = 'effect here'; } else{ effect = null } - +// TODO: USE DATABASE FOR THIS!!! +function createDeckList(playerId){ + // TODO:Create the deckList by loading the deckDB + // For now pulling from a deckList array that uses a cardArray + let deckList = null; + if(playerId == 0){ deckList = deckListPlayer; } + if(playerId == 1){ deckList = deckListOpponent; } + + for(let deckItem = 0; deckItem < deckList.length; deckItem++){ + // Create new item for ECS item.push(itemCount); + // Set card data for new item + // Use the ID from the deckList of player, and return the card of that ID from cardList/DB + cardData[itemCount] = cardArray[deckList[deckItem]]; + // Set to base position of 'deck' boardElement[itemCount] = 'deck'; - cardData[itemCount] = { - 'name':'CardName '+(i+1) - , 'cost':1 - , 'atk':1 - , 'def':1 - , 'rarity': 'common' - , 'effect':effect - , 'type':'human' - , 'colour':colour - , 'tapped':false - }; + // Set Attack, ManaCost, ManaColours TODO: When these are implemented seperately + + // Set the player player[itemCount] = playerId; - listPosition[itemCount] = i; - // Previous iteration, kept to prevent errors for now - deck.push(cardData[itemCount]); + // Set the position in the deck (as was added), will be shuffled on game start + listPosition[itemCount] = deckItem+1; + // Increment the itemCount to prevent overwriting stuff itemCount++; } + let cardsInDeck = board.ECSLoop(null, playerId); - // Shuffle the deck straight away after generating/loading it in shuffleDeck(playerId); } @@ -1102,7 +1100,6 @@ function shuffleDeck(playerId){ [ tempDeck[i], tempDeck[shuffle] ] = [ tempDeck[shuffle], tempDeck[i] ]; } - console.log(getCurrentPositionAndLength('deck', playerId)[1]); // For each item in the actual deck, set the listPosition to the random number from tempDeck let items = board.ECSLoop('deck', playerId, null, null); for(let item = 0; item < items.length; item++){ @@ -1114,7 +1111,6 @@ function shuffleDeck(playerId){ //console.log('NEW LIST POSITION: '+listPosition[itemKey]); } - console.log(getCurrentPositionAndLength('deck', playerId)[1]); } @@ -1312,4 +1308,19 @@ function printECSData(items){ ); } } +function echoCards(){ + console.log(cardArray); +} +function echoCardsInDeck(playerId){ + // Get all the cards that belong to player + let cardsInDeck = board.ECSLoop(null, playerId); + let deckList = []; + for(let i = 0; i < cardsInDeck.length; i++){ + // If it's a card TODO: Change this to check 'card' from some ECS element + if(cardData[i] !== null && cardData[i] !== undefined){ + deckList.push(cardData[i]); + } + } + console.log(deckList); +} diff --git a/public/cards.js b/public/cards.js new file mode 100644 index 0000000..f6f6092 --- /dev/null +++ b/public/cards.js @@ -0,0 +1,21 @@ +// 0,1,2 = white,blue,red (for now) +// TODO: Use a DB in future, this is just for testing +let cardArray = +[ + { id: 1, name: 'Red1', colour: 2, cost: 1, type: 'Goblin', atk: 500, rarity: 'common', effect:'[[Sneak]] 500'}, + { id: 2, name: 'Red2', colour: 2, cost: 1, type: 'Goblin', atk: 1500, rarity: 'common', effect:'Cannot attack direct'}, + { id: 3, name: 'Red3', colour: 2, cost: 2, type: 'Goblin', atk: 1000, rarity: 'common', effect:'[[DEATH]] deal 1500 extra to killer'}, + { id: 4, name: 'Red4', colour: 2, cost: 2, type: 'Goblin', atk: 2000, rarity: 'common', effect:null}, + { id: 5, name: 'White1', colour: 0, cost: 1, type: 'Weapon', atk: 500, rarity: 'common', effect:'[[Equip]]'}, + { id: 6, name: 'White2', colour: 0, cost: 2, type: 'Human', atk: 1500, rarity: 'common', effect:null}, + { id: 7, name: 'White3', colour: 0, cost: 2, type: 'Human', atk: 2000, rarity: 'common', effect:'[[TAUNT]]'}, + { id: 8, name: 'White5', colour: 0, cost: 2, type: 'Human', atk: 1500, rarity: 'common', effect:'[[REACH]]'}, + { id: 9, name: 'Blue1', colour: 1, cost: 2, type: 'Spirit', atk: 1000, rarity: 'common', effect:null}, + { id: 10, name: 'Blue3', colour: 1, cost: 2, type: 'Spirit', atk: 1000, rarity: 'common', effect:'[[DRAW]] 1'}, + { id: 11, name: 'Blue4', colour: 1, cost: 2, type: 'Spirit', atk: 1500, rarity: 'common', effect:null}, + { id: 12, name: 'Blue5', colour: 1, cost: 3, type: 'Spirit', atk: 2500, rarity: 'common', effect:'[[FLIGHT]]'} +] + +let deckListPlayer = [5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10]; +let deckListOpponent = [1,1,1,1,2,2,3,3,4,4,7,7,7,7,5,5,5,3,3,8,8]; + diff --git a/public/index.html b/public/index.html index 0ae9165..d28ac6c 100644 --- a/public/index.html +++ b/public/index.html @@ -18,8 +18,12 @@ + + + +