@ -271,7 +271,7 @@ function requestDeck(socket, playerId, deckId){
// Add the cards (x of how many cardObjects with cardId are in count in decklist)
// Add the cards (x of how many cardObjects with cardId are in count in decklist)
// to a deck array to pass through. Or decks array with deckId specified?
// to a deck array to pass through. Or decks array with deckId specified?
console . log ( deckList ) ;
//console.log(deckList);
// These are the four basic fellas for this
// These are the four basic fellas for this
// from public/board.js where current game testing/logic is applied
// from public/board.js where current game testing/logic is applied
// So creating as a test for a 'room' to see if it's simple enough to
// So creating as a test for a 'room' to see if it's simple enough to
@ -280,22 +280,37 @@ function requestDeck(socket, playerId, deckId){
let item = [ ] ;
let item = [ ] ;
let itemCount = 0 ;
let itemCount = 0 ;
let deckData = { } ; // New but may be useful
let deckData = { } ; // New but may be useful
let deckIn = { } ; // Which deck the item is in? Kinda the player/boardelement thing?
let cardData = { } ;
let cardData = { } ;
let boardElement = { } ;
let boardElement = { } ;
// TODO: Set the player. For now will do this in front-end as testing currently
// TODO: Set the player. For now will do this in front-end as testing currently
// 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 } ;
boardElement [ itemCount ] = 'realDeck' ;
itemCount ++ ;
} )
console . log ( deckData ) ;
console . log ( deckList ) ;
// Loop each item in the deckList
// Loop each item in the deckList
// Loop inside it X times where X is cardCount
// Loop inside it X times where X is cardCount
// Add the builtCard with same cardId as deckList item X times
// Add the builtCard with same cardId as deckList item X times
deckList . forEach ( ( deckListItem ) => {
deckList . forEach ( ( deckListItem ) => {
// Check if it's a new deck (not sure how)
if ( false ) { // TODO: Logic check
item . push ( itemCount ) ; // Add new item to add stuff for
deckData [ itemCount ] = [ deckListItem . deckId , deckListItem . playerId ] ;
boardElement [ itemCount ] = 'realDeck' ;
itemCount ++ ;
}
let deckItem = null ;
// Loop each deck, if the deck/playerIds match, add association
for ( key in deckData ) {
//Object.keys(deckData).forEach(function(key) { // Less efficient than for
// 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
}
} ;
// For each new card, loop to the cardCount (how many cards in deck)
// For each new card, loop to the cardCount (how many cards in deck)
// and add to the deck
// and add to the deck
for ( let i = 0 ; i < deckListItem . cardCount ; i ++ ) {
for ( let i = 0 ; i < deckListItem . cardCount ; i ++ ) {
@ -304,13 +319,30 @@ function requestDeck(socket, playerId, deckId){
// from item for instance
// from item for instance
cardData [ itemCount ] = builtCards [ deckListItem . cardId ] ; // builtCards id set to cardId from DB, so adding the builtCard object is based on the deckList's cardId (from DB)
cardData [ itemCount ] = builtCards [ deckListItem . cardId ] ; // builtCards id set to cardId from DB, so adding the builtCard object is based on the deckList's cardId (from DB)
boardElement [ itemCount ] = 'deck' ; // Add all cards to deck at match start
boardElement [ itemCount ] = 'deck' ; // Add all cards to deck at match start
// Associate the card with the deck
// TODO: Change deckIn to something more sensical
deckIn [ itemCount ] = deckItem ;
itemCount ++ ; // Increment item to not overwrite
itemCount ++ ; // Increment item to not overwrite
}
}
} ) ;
} ) ;
// item, itemCount, deckData, cardData, boardElement
//console.log(cardData);
//console.log(cardData);
return resolve ( 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 ,
} ;
return resolve ( dataReturn ) ;
//return resolve(cardData);
// Promise stuff testing
// Promise stuff testing
} ) ( )
} ) ( )
@ -325,6 +357,8 @@ function requestDeck(socket, playerId, deckId){
// things, but outside of testing that won't occur(?), may need to test this at some
// things, but outside of testing that won't occur(?), may need to test this at some
// point to see. For now DB, and generating is ok, as still working on it
// point to see. For now DB, and generating is ok, as still working on it
}
}
// For testing
requestDeck ( ) ;
function requestDeckStart ( socket ) {
function requestDeckStart ( socket ) {
// For future:
// For future: