@ -225,6 +225,8 @@ function requestDeck(itemData = null){
// To continue from previous item/itemCount from other funcs, something like this
let item = [ ] ;
let itemCount = 0 ;
let player = { } ;
let players = [ ] ;
// Jank check to allow current client call, and new roomMod.roomGeneration call to
// both work (will replace client call with roomGeneration when closer)
@ -235,28 +237,53 @@ function requestDeck(itemData = null){
if ( itemData [ 'itemCount' ] !== undefined ) {
itemCount = itemData [ 'itemCount' ] ;
}
if ( itemData [ 'player' ] !== undefined ) {
player = itemData [ 'player' ] ;
}
if ( itemData [ 'players' ] !== undefined ) {
players = itemData [ 'players' ] ;
}
} else {
itemData = { } ;
}
// TODO: Deck data/deckIn should be in deckGen, other stuff probably in a cardGen
// function
let deckData = { } ; // New but may be useful
let deckIn = { } ; // Which deck the item is in? Kinda the player/boardelement thing?
let cardData = { } ;
let boardElement = { } ;
// New(in here)
let cardStatus = { } ; // Tapped, etc
// player
let listPosition = { } ;
let cardFace = { } ;
// REALLY NEW
let cardColours = { } ; // Array of req.
let cardAttack = { } ; // Base, Current
let cardSprite = { } ; // Maybe from DB?
// TODO: Set the player. For now will do this in front-end as testing currently
let forPlayer = 0 ; // TODO: Change to actually have each player select a deck
// Loop and create the deck first
//console.log(decks);
decks . forEach ( ( deck ) => {
item . push ( itemCount ) ; // Add new item to add stuff for
deckData [ itemCount ] = { 'deckId' : deck . deckId , 'playerId' : deck . playerId , 'deckName' : deck . deckName } ;
deckData [ itemCount ] = { 'deckId' : deck . deckId , 'playerId' : deck . playerId , 'deckName' : deck . deckName , 'maxLength' : 0 }; // Max length for listPositioning later in cardBuild
boardElement [ itemCount ] = 'realDeck' ;
itemCount ++ ;
cardFace [ itemCount ] = 0 ; // Face down for deck
player [ itemCount ] = forPlayer ;
itemCount ++ ; // Needed/good
forPlayer ++ ; // Jank/bad
} )
console . log ( deckData ) ;
console . log ( deckList ) ;
//console.log(deckData);
//console.log(deckList);
// Loop each item in the deckList
// Loop inside it X times where X is cardCount
// Add the builtCard with same cardId as deckList item X times
// and load that deck for them. This just sets first deck to player0 to players.length
deckList . forEach ( ( deckListItem ) => {
let deckItem = null ;
@ -266,9 +293,12 @@ function requestDeck(itemData = null){
// Needs to check deck AND player id, as that's the primary key (together)
if ( deckData [ key ] . deckId == deckListItem . deckId && deckData [ key ] . playerId == deckListItem . playerId ) {
deckItem = key ; // Key is the `item` key
// Now add cards to the player that this deck belongs to
forPlayer = player [ key ] ;
}
} ;
// For each new card, loop to the cardCount (how many cards in deck)
// and add to the deck
for ( let i = 0 ; i < deckListItem . cardCount ; i ++ ) {
@ -280,25 +310,49 @@ function requestDeck(itemData = null){
// Associate the card with the deck
// TODO: Change deckIn to something more sensical
deckIn [ itemCount ] = deckItem ;
// Attempt to set the listPosition of each card in related deck
// Increase the length of the deck in deckItem
listPosition [ itemCount ] = deckData [ deckItem ] . maxLength ; // TODO: better
deckData [ deckItem ] . maxLength ++ ;
// Adding to get everything sorted in one!
cardStatus [ itemCount ] = null ;
cardFace [ itemCount ] = 0 ; // Face down by default (in deck)
cardColours [ itemCount ] = [ ] ; // TODO;
// From cardData set the base attack, and current (same when deckbuild)
let atk = cardData [ itemCount ] . atk ;
cardAttack [ itemCount ] = [ atk , atk ] ; // Base, Current
player [ itemCount ] = forPlayer ; // Jank TODO: actually set to correct player
itemCount ++ ; // Increment item to not overwrite
}
} ) ;
// ADD all new elements, and updated data into itemData
itemData . item = item ;
itemData . itemCount = itemCount ;
itemData . player = player ;
itemData . players = players ;
itemData . deckData = deckData ;
itemData . deckIn = deckIn ;
itemData . cardData = cardData ;
itemData . boardElement = boardElement ;
itemData . cardStatus = cardStatus ;
itemData . listPosition = listPosition ;
itemData . cardFace = cardFace ;
itemData . cardColours = cardColours ;
//itemData.cardSprite = cardSprite;
// item, itemCount, deckData, cardData, boardElement
//console.log(cardData);
// Returning everything to be looped in the front-end
// This won't be looped as it will at final, instead just for deck generation
// Returned as object over array, as easier to disect when gets to front-end
let dataReturn = {
item : item ,
itemCount : itemCount ,
deckData : deckData ,
deckIn : deckIn ,
cardData : cardData ,
boardElement : boardElement ,
} ;
let dataReturn = itemData ;
return resolve ( dataReturn ) ;
//return resolve(cardData);