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

50 lines
1.3 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.player);
updateDecks(data.component.deck);
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;
}