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

117 lines
3.4 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; // Change to all listPositions
gameData.cardData = data.handCardData; // Changed to all cardData
// Changes made here, as when drawing a card updateBoard data was wiped and caused
// 'undefined' listPositions and other data...
}
function updateBoard(data){
// TODO: ONLY RETURN NEEDED DATA
// AND ONLY UPDATE NEEDED DATA
// TODO: Currently everything is being passed
// which is 1 slow, and 2 bad because it gives players
// too much information, they only need what's to be
// drawn and interacted with
console.log('TODO: updateBoard correctly');
console.log(data);
gameData.board = data.board;
gameData.passive = data.passive;
gameData.listPosition = data.listPosition
gameData.cardData = data.cardData;
gameData.cardCost = data.cardCost;
gameData.cardColours = data.cardColours;
//console.log(data);
}
function updateShield(data){
console.log('TODO: updateShield correctly');
console.log(data);
gameData.shield = data.shield;
gameData.listPosition = data.listPosition;
// TODO: Tapped
}
function updateMana(data){
console.log('TODO: updateMana correctly');
console.log(data);
gameData.mana = data.mana;
gameData.listPosition = data.listPosition;
gameData.cardData = data.cardData;
gameData.cardColours = data.cardColours;
}
// Tapped
function updateTapped(data){
console.log(data);
gameData.cardStatus.tapped = data;
console.log(gameData.cardStatus.tapped);
}
// To prevent typical functionality (draw, etc.)
// if there's a stack in play.
// TODO: Can only chain the stack or resolve it
function updateStack(data){
alert('You must resolve the stack, or chain an effect');
console.log(data);
console.log(gameData);
}