Started clientside turn communication

This commit is contained in:
Ben
2021-05-06 03:16:38 +01:00
parent 66edbbf51e
commit b5f6d678e1
6 changed files with 31 additions and 6 deletions

View File

@@ -71,6 +71,13 @@ NOTES
let ActiveGames = [];
function GetTurnUser(gameuid)
{
if (!ActiveGames[gameuid]) return false;
return ActiveGames[gameuid].players[ActiveGames[gameuid].turn];
}
function BeginGame(lobby)
{
// game uses the owners language - assumes it's valid
@@ -180,6 +187,7 @@ module.exports = {
// Game validation exports
// Get game exports
GetTurnUser: GetTurnUser,
// Change game state exports
BeginGame: BeginGame,

View File

@@ -424,10 +424,17 @@ function EmitGameBegin(game)
const gameuserconnection = Game.Registrar.GetConnectionByUser(gameuser.uid);
// TODO: consider not sending all users the entire game state
// due to cheating
// due to cheating - a few more considerations and maybe a
// getsafegame function is needed
io.to(gameuserconnection).emit('game-begin', {
game: game,
gameuser: gameuser
})
});
}
// Let starting player know it's their turn
const userturnstart = Game.Logic.GetTurnUser(game.uid).uid;
const userturnstartconnection = Game.Registrar.GetConnectionByUser(userturnstart);
io.to(userturnstartconnection).emit('game-your-turn');
}