|
|
|
|
@ -372,7 +372,7 @@ class Board{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
// 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
|
|
|
|
|
@ -487,8 +487,8 @@ class Board{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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){
|
|
|
|
|
let items = this.getItems(elementFrom, playerFrom, null, fromPosition);
|
|
|
|
|
if(board.getItems(elementFrom, playerFrom, null, fromPosition).length > 1){
|
|
|
|
|
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
|
|
|
|
|
// 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++){
|
|
|
|
|
let itemKey = items[item];
|
|
|
|
|
if(listPosition[itemKey] > fromPosition){
|
|
|
|
|
@ -586,7 +586,7 @@ class Board{
|
|
|
|
|
// Tap mana and play TODO: TEMP SOLUTION
|
|
|
|
|
// TODO: May want to make this recursive, it's better and less bulky
|
|
|
|
|
// 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++){
|
|
|
|
|
let mana = items[item];
|
|
|
|
|
// For now just tapping the first untapped mana
|
|
|
|
|
@ -609,7 +609,7 @@ class Board{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getItemKey(boardElementId, listPositionId){
|
|
|
|
|
let itemKey = this.ECSLoop(boardElementId, null, null, listPositionId);
|
|
|
|
|
let itemKey = this.getItems(boardElementId, null, null, listPositionId);
|
|
|
|
|
if(itemKey.length < 1){
|
|
|
|
|
alert('Could not find key');
|
|
|
|
|
return false;
|
|
|
|
|
@ -634,7 +634,7 @@ class Board{
|
|
|
|
|
}
|
|
|
|
|
canPayMana(itemToPlay, playerId){
|
|
|
|
|
// 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';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -644,7 +644,7 @@ class Board{
|
|
|
|
|
// For now, until adding colour, and other attributes to ECS modal
|
|
|
|
|
let manaColourRequired = cardData[itemToPlay].colour;
|
|
|
|
|
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++){
|
|
|
|
|
let itemKey = items[item];
|
|
|
|
|
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.
|
|
|
|
|
// 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++){
|
|
|
|
|
let itemKey = items[item];
|
|
|
|
|
// 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
|
|
|
|
|
itemCount++;
|
|
|
|
|
}
|
|
|
|
|
let cardsInDeck = board.ECSLoop(null, playerId);
|
|
|
|
|
let cardsInDeck = board.getItems(null, 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
|
|
|
|
|
let items = board.ECSLoop('deck', playerId, null, null);
|
|
|
|
|
let items = board.getItems('deck', playerId, null, null);
|
|
|
|
|
for(let item = 0; item < items.length; item++){
|
|
|
|
|
let itemKey = items[item];
|
|
|
|
|
//console.log('ITEM KEY: '+itemKey);
|
|
|
|
|
@ -1136,7 +1136,7 @@ function shuffleDeck(playerId){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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++){
|
|
|
|
|
let itemKey = items[item];
|
|
|
|
|
if(board.isTapped(itemKey)){ board.untapCard(itemKey); }
|
|
|
|
|
@ -1161,7 +1161,7 @@ function getCurrentPositionAndLength(elementName, playerId){
|
|
|
|
|
let highestListPosition = 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++){
|
|
|
|
|
let itemKey = items[item];
|
|
|
|
|
|
|
|
|
|
@ -1302,17 +1302,24 @@ function calculateItemSizePosition(itemKey){
|
|
|
|
|
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);
|
|
|
|
|
console.log('Items array length: '+items.length);
|
|
|
|
|
}
|
|
|
|
|
function printECSData(items){
|
|
|
|
|
for(let item = 0; item < items.length; item++){
|
|
|
|
|
@ -1333,7 +1340,7 @@ function echoCards(){
|
|
|
|
|
}
|
|
|
|
|
function echoCardsInDeck(playerId){
|
|
|
|
|
// Get all the cards that belong to player
|
|
|
|
|
let cardsInDeck = board.ECSLoop(null, playerId);
|
|
|
|
|
let cardsInDeck = board.getItems(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
|
|
|
|
|
|