@ -812,10 +812,104 @@ requestDeck();
// public/main.js
// socket.on('responseGetDeck', function (data) {
function loadBoard ( ) {
function loadBoard ( data ) {
console . log ( 'DATA' ) ;
console . log ( data ) ;
// Built the original boardstate using the data passed from server
// This is only for the first time recieve (TODO: ALL) game data at match start
// Then ideally only what's needed to be passed to/from client/server sent after
item = data . item ;
itemCount = data . itemCount ;
boardElement = data . boardElement ;
cardData = data . cardData ;
// position; // Not to do, as calculated per client (and will be per screen-size)
// size; // Like position, calculated per client.
//cardStatus; // TODO: ? Statuses on load?, TODO: OR if player DCs and needs to reload!
player = { } ; // TODO: Set each item to correct player
listPosition = { } ; // TODO:
cardFace = { } ; // TODO: Like status, for DCs and reloads
cardSprite = { } ; // TODO: ? Maybe, or this could be done clientside based
// ^ on card id?
cardFace = { } ; // TODO: For DB/Reconnect more-so
let deckIn = data . deckIn ; // NEW, may be used, for now player substitute
let deckData = data . deckData ;
// Stuff not currently in the getDecks TODO: To be stripped down and
// rewritten/made into generateItems or something, for each match
// Decks can be as-is for getting deckLists for deckselection, but
// TODO: for matches need something to generate and return every item, and attribute
console . log ( cardData [ 0 ] ) ;
// Temp solution
// Loop all items, and set their related missing attributes
// TODO: some more jank to get it 'playable' with DB entries
let player0DeckCount = 0 ;
let player1DeckCount = 0 ;
for ( let i = 0 ; i < itemCount ; i ++ ) {
// Set player for decks (to just be their array index for now) TODO: Properly
if ( boardElement [ i ] == 'realDeck' ) {
player [ i ] = i ; // Jank...
//player[i] = deckData[i];
//console.log(deckData[i]);
} else {
// Everything else missing in a jank fashion
player [ i ] = deckIn [ i ] ; // 1-1 here, but likely not in future
}
cardStatus [ i ] = null ; // Just building on first load, as deck gen
// substite at the mo, so all cards are free of status
cardFace [ i ] = 0 ; // As above, deck gen sub. Everything starts facedown
// Set position for cards in each deck...
// TODO: JANK, tidy, remove, make good!!
// using the new player set just above, which in itself is jank
if ( player [ i ] == 0 && boardElement [ i ] != 'realDeck' ) {
listPosition [ i ] = player0DeckCount + 1 ;
player0DeckCount ++ ;
}
// Just an else, as in DB/for this test only 2 decks
// TODO: MAKE BETTER!
else {
listPosition [ i ] = player0DeckCount + 1 ;
player0DeckCount ++ ;
}
// TODO: JANK IN, CHANGE CODE TO USE NEW ARRAY!!
// Temp jank, set colour to first colour req.
if ( cardData [ i ] !== undefined ) { // i may not have carddata, as realDeck
cardData [ i ] . colour = 0 ; //cardData[itemCount].colour[0];
// Set the artwork (this would be done front-end I think)
cardSprite [ i ] = [ 0 , 0 ] ;
// Temp sprite set based on colour TODO: Change to set correct sprite from DB
switch ( cardData [ i ] . colour ) {
case 0 : // White
cardSprite [ i ] = [ 0 , 0 ] ;
break ;
case 1 : // Blue
cardSprite [ i ] = [ 0 , 1 ] ;
break ;
case 2 : // Red
cardSprite [ i ] = [ 1 , 0 ] ;
break ;
case 3 : // Green
cardSprite [ i ] = [ 1 , 1 ] ;
break ;
default :
break ;
}
}
}
shuffleDeck ( 0 ) ; // Shuffle player 0 deck
shuffleDeck ( 1 ) ; // Shuffle player 1 deck
//return false;
// Fill each players deck with their cards
createDecks ( ) ;
//createDecks();
// Play shield from top of each players deck to the maximum allowed (4 typically)
for ( let currentPlayer = 0 ; currentPlayer <= players - 1 ; currentPlayer ++ ) {
@ -1183,6 +1277,7 @@ function calculateItemSizePosition(itemKey){
positionY = 60 ;
width = cardWidth * 1.5 ;
height = cardHeight * 1.5 ;
console . log ( 'HELLO 1' ) ;
}
if ( itemPlayer == 0 && itemElement == 'realDeck' ) {
@ -1190,6 +1285,7 @@ function calculateItemSizePosition(itemKey){
positionY = canvas . height - cardHeight * 1.5 - 60 ;
width = cardWidth * 1.5 ;
height = cardHeight * 1.5 ;
console . log ( 'HELLO 0' ) ;
}
if ( itemPlayer == 1 && itemElement == 'board' ) {