Add frontend console.log tool, renamed ECSLoop

develop
Nathan Steel 1 year ago
parent 515067936e
commit 997ffae3c4

@ -372,7 +372,7 @@ class Board{
} }
// boardElement, cardData?, position?, size?, cardStatus, player, listPosition // boardElement, cardData?, position?, size?, cardStatus, player, listPosition
ECSLoop(boardElementId = null, playerId = null, cardStatusId = null, listPositionId = null){ getItems(boardElementId = null, playerId = null, cardStatusId = null, listPositionId = null){
// So, the intent here is to normalise my nested loop I keep duping (parts of) // So, the intent here is to normalise my nested loop I keep duping (parts of)
// This will recieve each piece of content that can be stored in each ECS element // This will recieve each piece of content that can be stored in each ECS element
// Then will loop each individually, setting a new array to be returned // Then will loop each individually, setting a new array to be returned
@ -487,8 +487,8 @@ class Board{
} }
// Check if there's more than 1 thing add that position (something's gone wrong somewhere) // Check if there's more than 1 thing add that position (something's gone wrong somewhere)
let items = this.ECSLoop(elementFrom, playerFrom, null, fromPosition); let items = this.getItems(elementFrom, playerFrom, null, fromPosition);
if(board.ECSLoop(elementFrom, playerFrom, null, fromPosition).length > 1){ if(board.getItems(elementFrom, playerFrom, null, fromPosition).length > 1){
alert('ERROR: There are more than 1 card being added'); alert('ERROR: There are more than 1 card being added');
} }
@ -525,7 +525,7 @@ class Board{
// Loop the elementFrom, and move positions for anything after // Loop the elementFrom, and move positions for anything after
// item taken from position 34, 35..60 need to be moved down to 34..59 // item taken from position 34, 35..60 need to be moved down to 34..59
let items = this.ECSLoop(elementFrom, playerFrom, null, null); let items = this.getItems(elementFrom, playerFrom, null, null);
for(let item = 0; item < items.length; item++){ for(let item = 0; item < items.length; item++){
let itemKey = items[item]; let itemKey = items[item];
if(listPosition[itemKey] > fromPosition){ if(listPosition[itemKey] > fromPosition){
@ -586,7 +586,7 @@ class Board{
// Tap mana and play TODO: TEMP SOLUTION // Tap mana and play TODO: TEMP SOLUTION
// TODO: May want to make this recursive, it's better and less bulky // TODO: May want to make this recursive, it's better and less bulky
// but still lots of dupe code // but still lots of dupe code
let items = this.ECSLoop('mana', fromPlayer, null, null); let items = this.getItems('mana', fromPlayer, null, null);
for(let item = 0; item < items.length; item++){ for(let item = 0; item < items.length; item++){
let mana = items[item]; let mana = items[item];
// For now just tapping the first untapped mana // For now just tapping the first untapped mana
@ -609,7 +609,7 @@ class Board{
} }
getItemKey(boardElementId, listPositionId){ getItemKey(boardElementId, listPositionId){
let itemKey = this.ECSLoop(boardElementId, null, null, listPositionId); let itemKey = this.getItems(boardElementId, null, null, listPositionId);
if(itemKey.length < 1){ if(itemKey.length < 1){
alert('Could not find key'); alert('Could not find key');
return false; return false;
@ -634,7 +634,7 @@ class Board{
} }
canPayMana(itemToPlay, playerId){ canPayMana(itemToPlay, playerId){
// Check player has enough mana // Check player has enough mana
if(this.ECSLoop('mana', playerId, null, null).length < cardData[itemToPlay].cost){ if(this.getItems('mana', playerId, null, null).length < cardData[itemToPlay].cost){
return 'Not enough mana'; return 'Not enough mana';
} }
@ -644,7 +644,7 @@ class Board{
// For now, until adding colour, and other attributes to ECS modal // For now, until adding colour, and other attributes to ECS modal
let manaColourRequired = cardData[itemToPlay].colour; let manaColourRequired = cardData[itemToPlay].colour;
console.log(manaColourRequired); console.log(manaColourRequired);
let items = this.ECSLoop('mana', player[itemToPlay], null, null); let items = this.getItems('mana', player[itemToPlay], null, null);
for(let item = 0; item < items.length; item++){ for(let item = 0; item < items.length; item++){
let itemKey = items[item]; let itemKey = items[item];
if(cardData[itemKey].colour == manaColourRequired && !this.isTapped(itemKey)){ if(cardData[itemKey].colour == manaColourRequired && !this.isTapped(itemKey)){
@ -804,7 +804,7 @@ class Board{
} }
// Get all shields, that belong to the player whose shield was targetted. // Get all shields, that belong to the player whose shield was targetted.
// Check if they're all tapped before destroying the target // Check if they're all tapped before destroying the target
let items = this.ECSLoop('shield', player[itemKey], null, null); let items = this.getItems('shield', player[itemKey], null, null);
for(let item = 0; item < items.length; item++){ for(let item = 0; item < items.length; item++){
let itemKey = items[item]; let itemKey = items[item];
// If ANY of their shields are untapped, you can't destroy target // If ANY of their shields are untapped, you can't destroy target
@ -1100,7 +1100,7 @@ function createDeckList(playerId){
// Increment the itemCount to prevent overwriting stuff // Increment the itemCount to prevent overwriting stuff
itemCount++; itemCount++;
} }
let cardsInDeck = board.ECSLoop(null, playerId); let cardsInDeck = board.getItems(null, playerId);
shuffleDeck(playerId); shuffleDeck(playerId);
} }
@ -1121,7 +1121,7 @@ function shuffleDeck(playerId){
} }
// For each item in the actual deck, set the listPosition to the random number from tempDeck // For each item in the actual deck, set the listPosition to the random number from tempDeck
let items = board.ECSLoop('deck', playerId, null, null); let items = board.getItems('deck', playerId, null, null);
for(let item = 0; item < items.length; item++){ for(let item = 0; item < items.length; item++){
let itemKey = items[item]; let itemKey = items[item];
//console.log('ITEM KEY: '+itemKey); //console.log('ITEM KEY: '+itemKey);
@ -1136,7 +1136,7 @@ function shuffleDeck(playerId){
} }
function untapZone(elementFrom, playerFrom){ function untapZone(elementFrom, playerFrom){
let items = board.ECSLoop(elementFrom, playerFrom, null, null); let items = board.getItems(elementFrom, playerFrom, null, null);
for(let item = 0; item < items.length; item++){ for(let item = 0; item < items.length; item++){
let itemKey = items[item]; let itemKey = items[item];
if(board.isTapped(itemKey)){ board.untapCard(itemKey); } if(board.isTapped(itemKey)){ board.untapCard(itemKey); }
@ -1161,7 +1161,7 @@ function getCurrentPositionAndLength(elementName, playerId){
let highestListPosition = 0; let highestListPosition = 0;
let length = 0; let length = 0;
let items = board.ECSLoop(elementName, playerId, null, null); let items = board.getItems(elementName, playerId, null, null);
for(let item = 0; item < items.length; item++){ for(let item = 0; item < items.length; item++){
let itemKey = items[item]; let itemKey = items[item];
@ -1302,17 +1302,24 @@ function calculateItemSizePosition(itemKey){
position[itemKey] = [positionX,positionY]; position[itemKey] = [positionX,positionY];
} }
function ECSLoopTest(){
// boardElement, player, cardStatus, listPosition
// TODO: ?cardData?, position?, size?
let boardElementId = 'realDeck';
let playerId = null;
let cardStatusId = null;
let listPositionId = null;
let items = board.ECSLoop(boardElementId, playerId, cardStatusId, listPositionId);
console.log(items); // For checking data without needing to change the codebase with logs
function getItemsAndPrintFrontEnd(){
let boardElementId = document.getElementById("boardElementId").value;
if(boardElementId == ""){ boardElementId = null; }
let playerId = document.getElementById("playerId").value;
if(playerId == ""){ playerId = null; }
let cardStatusId = document.getElementById("cardStatusId").value;
if(cardStatusId == ""){ cardStatusId = null; }
let listPositionId = document.getElementById("listPositionId").value;
if(listPositionId == ""){ listPositionId = null; }
getItemsAndPrint(boardElementId, playerId, cardStatusId, listPositionId);
}
function getItemsAndPrint(boardElementId = null, playerId = null, cardStatusId = null, listPositionId = null){
let items = board.getItems(boardElementId, playerId, cardStatusId, listPositionId);
console.log('----- Items -----');
printECSData(items); printECSData(items);
console.log('Items array length: '+items.length);
} }
function printECSData(items){ function printECSData(items){
for(let item = 0; item < items.length; item++){ for(let item = 0; item < items.length; item++){
@ -1333,7 +1340,7 @@ function echoCards(){
} }
function echoCardsInDeck(playerId){ function echoCardsInDeck(playerId){
// Get all the cards that belong to player // Get all the cards that belong to player
let cardsInDeck = board.ECSLoop(null, playerId); let cardsInDeck = board.getItems(null, playerId);
let deckList = []; let deckList = [];
for(let i = 0; i < cardsInDeck.length; i++){ for(let i = 0; i < cardsInDeck.length; i++){
// If it's a card TODO: Change this to check 'card' from some ECS element // If it's a card TODO: Change this to check 'card' from some ECS element

Loading…
Cancel
Save