You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cardGame/public/js/game/dataUpdate.js

67 lines
1.9 KiB
JavaScript

// To set the server data to related client data
// Update all the relevent game data from the server's data response
function updateGameData(data){
console.log(data);
updatePlayers(data.players);
updatePlayerId(data.playerId);
updateOpponentId(data.opponentId);
updateRoomId(data.roomId);
updateTurn(data.component.turn, data.component.playerTurn);
updateItems(data.component.item, data.component.itemCount);
updatePlayerComponent(data.component.player);
updateDecks(data.component.deck);
updateCardCount(data.component.cardCount);
console.log(gameData);
}
// Individual or minor updates
// This will ideally be how each game function updates the data
// e.g. drawACard() would update the hand, deck, cardData, effects?
function updatePlayers(players = null){
gameData.players = players;
}
function updatePlayerId(playerId = null){
gameData.playerId = playerId;
}
function updateOpponentId(opponentId = null){
gameData.opponentId = opponentId;
}
function updateRoomId(roomId = null){
gameData.roomId = roomId;
}
function updateTurn(turn = null, playersTurn = null){
gameData.turn = turn;
gameData.playerTurn = playersTurn;
}
function updateItems(item = null, itemCount = null){
gameData.item = item;
gameData.itemCount = itemCount;
}
function updateDecks(deck = null){
gameData.deck = deck;
}
function updatePlayerComponent(player = null){
gameData.player = player;
}
function updateCardCount(cardCount = null){
console.log(cardCount);
gameData.cardCount = cardCount;
}
// Cards in hand
function updatePlayerHand(data){
console.log('Update player hand');
// TODO: These will likely not be = as will overwrite.
// Likely to union all the data server-side and pass as one
// function such as updateEntities() or something
gameData.hand = data.handEntities;
gameData.listPosition = data.handPositions;
gameData.cardData = data.handCardData;
console.log(gameData);
}