|
|
|
@ -157,7 +157,7 @@ function isUserInRoom(playerName, roomId){
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function startGame(roomId){
|
|
|
|
async function startGame(roomId){
|
|
|
|
|
|
|
|
|
|
|
|
console.log('>> Room: ' + roomId + ': Requesting game...');
|
|
|
|
console.log('>> Room: ' + roomId + ': Requesting game...');
|
|
|
|
let people = global.roomData[roomId].players;
|
|
|
|
let people = global.roomData[roomId].players;
|
|
|
|
@ -189,27 +189,34 @@ function startGame(roomId){
|
|
|
|
// ideally only returning the items that the user can/should
|
|
|
|
// ideally only returning the items that the user can/should
|
|
|
|
// see i.e. shouldn't give them the inDeck card list just a counter
|
|
|
|
// see i.e. shouldn't give them the inDeck card list just a counter
|
|
|
|
// shouldn't have opponent card data/their hand shouldn't be flipped
|
|
|
|
// shouldn't have opponent card data/their hand shouldn't be flipped
|
|
|
|
roomMod.roomGeneration(roomId).then(data => {
|
|
|
|
|
|
|
|
response.success = true;
|
|
|
|
// Not sure how to catch errors for these await alls
|
|
|
|
response.message = data;
|
|
|
|
// TODO: Look into error handling for await alls
|
|
|
|
// Each player then gets the roomGeneration stuff
|
|
|
|
const [itemData] =
|
|
|
|
for (const clientId of clients) {
|
|
|
|
await Promise.all([
|
|
|
|
const clientSocket = global.io.sockets.sockets.get(clientId);
|
|
|
|
roomMod.roomGeneration(roomId),
|
|
|
|
console.log('>> responseStartGame: '+clientSocket.playerId);
|
|
|
|
]);
|
|
|
|
// Emit to client socket
|
|
|
|
|
|
|
|
global.io.to(clientSocket.id).emit('responseStartGame', response);
|
|
|
|
|
|
|
|
}
|
|
|
|
// data is the 'itemData' not all the roomData
|
|
|
|
|
|
|
|
response.success = true;
|
|
|
|
})
|
|
|
|
response.message = itemData;
|
|
|
|
.catch(err => {
|
|
|
|
|
|
|
|
response.message = err;
|
|
|
|
// Each player then gets sent the roomGeneration stuff
|
|
|
|
// Each player then gets the error message
|
|
|
|
for (const clientId of clients) {
|
|
|
|
for (const clientId of clients) {
|
|
|
|
|
|
|
|
const clientSocket = global.io.sockets.sockets.get(clientId);
|
|
|
|
const clientSocket = global.io.sockets.sockets.get(clientId);
|
|
|
|
// Emit to client socket
|
|
|
|
console.log('>> responseStartGame: '+clientSocket.playerId);
|
|
|
|
global.io.to(clientSocket.id).emit('responseStartGame', err);
|
|
|
|
|
|
|
|
}
|
|
|
|
// TODO: TESTING STUFF, REMOVE WHEN SORTED
|
|
|
|
});
|
|
|
|
let message = 'You are player: '+roomData[roomId].playerOrder[clientSocket.playerId];
|
|
|
|
|
|
|
|
global.socketAlert(clientSocket.id, message, 'alert');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Emit the itemData to client socket (TODO: only emit what each player should see/recieve)
|
|
|
|
|
|
|
|
global.io.to(clientSocket.id).emit('responseStartGame', response);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|