bugfix with countdown() on early pong.destroy call
+ svelte reactivity with forfeit button + little matchmaking changes + Wip audio rework
This commit is contained in:
@@ -250,10 +250,10 @@ export class GameSession {
|
||||
}
|
||||
}
|
||||
|
||||
private async _matchEnd(winner: en.PlayerSide, forfeit_flag: boolean = false)
|
||||
private async _matchEnd(winner: en.PlayerSide, forfeitFlag: boolean = false)
|
||||
{
|
||||
this.matchEnded = true;
|
||||
const eventEnd = new ev.EventMatchEnd(winner, forfeit_flag);
|
||||
const eventEnd = new ev.EventMatchEnd(winner, forfeitFlag);
|
||||
this.playersMap.forEach( (client) => {
|
||||
client.socket.send(JSON.stringify(eventEnd));
|
||||
});
|
||||
@@ -261,19 +261,18 @@ export class GameSession {
|
||||
client.socket.send(JSON.stringify(eventEnd));
|
||||
});
|
||||
|
||||
// TODO: mettre à jour la route pour gerer les forfaits (actuellement le plus haut score gagne par defaut)
|
||||
const gc = this.components;
|
||||
console.log("================================= MATCH ENDED");
|
||||
if (forfeit_flag) {
|
||||
if (forfeitFlag) {
|
||||
if (winner === en.PlayerSide.left)
|
||||
{
|
||||
gc.scoreLeft = 3
|
||||
gc.scoreRight = 0
|
||||
gc.scoreLeft = 3;
|
||||
gc.scoreRight = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
gc.scoreLeft = 0
|
||||
gc.scoreRight = 3
|
||||
gc.scoreLeft = 0;
|
||||
gc.scoreRight = 3;
|
||||
}
|
||||
}
|
||||
await fetch(c.addressBackEnd + "/game/gameserver/updategame",
|
||||
|
||||
@@ -150,10 +150,10 @@ function publicMatchmaking(player: ClientPlayer)
|
||||
{
|
||||
const minPlayersNumber = 2;
|
||||
const maxPlayersNumber = 2;
|
||||
matchmakingMap.set(player.id, player);
|
||||
const matchOptions = player.matchOptions;
|
||||
|
||||
const compatiblePlayers: ClientPlayer[] = [];
|
||||
compatiblePlayers.push(player);
|
||||
for (const [id, client] of matchmakingMap)
|
||||
{
|
||||
if (client.matchOptions === matchOptions)
|
||||
@@ -165,12 +165,27 @@ function publicMatchmaking(player: ClientPlayer)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Replace with this code to disable the possibility to play against self
|
||||
/* for (const [id, client] of matchmakingMap)
|
||||
{
|
||||
if (client.matchOptions === matchOptions && client.username !== player.username)
|
||||
{
|
||||
compatiblePlayers.push(client);
|
||||
if (compatiblePlayers.length === maxPlayersNumber) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
if (compatiblePlayers.length >= minPlayersNumber) {
|
||||
compatiblePlayers.forEach((client) => {
|
||||
matchmakingMap.delete(client.id);
|
||||
});
|
||||
createGameSession(compatiblePlayers, matchOptions);
|
||||
}
|
||||
else {
|
||||
matchmakingMap.set(player.id, player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -178,11 +193,11 @@ function privateMatchmaking(player: ClientPlayer)
|
||||
{
|
||||
const minPlayersNumber = 2;
|
||||
const maxPlayersNumber = 2;
|
||||
privateMatchmakingMap.set(player.id, player);
|
||||
const matchOptions = player.matchOptions;
|
||||
|
||||
const token = player.token;
|
||||
const compatiblePlayers: ClientPlayer[] = [];
|
||||
compatiblePlayers.push(player);
|
||||
for (const [id, client] of privateMatchmakingMap)
|
||||
{
|
||||
if (client.token === token)
|
||||
@@ -202,6 +217,7 @@ function privateMatchmaking(player: ClientPlayer)
|
||||
}
|
||||
else
|
||||
{
|
||||
privateMatchmakingMap.set(player.id, player);
|
||||
setTimeout(async function abortMatch() {
|
||||
if (!player.gameSession)
|
||||
{
|
||||
@@ -226,7 +242,6 @@ function privateMatchmaking(player: ClientPlayer)
|
||||
|
||||
function createGameSession(playersArr: ClientPlayer[], matchOptions: en.MatchOptions)
|
||||
{
|
||||
// const id = c.gameSessionIdPLACEHOLDER; // Force ID, TESTING SPECTATOR
|
||||
const id = uuidv4();
|
||||
const gameSession = new GameSession(id, matchOptions);
|
||||
gameSessionsMap.set(id, gameSession);
|
||||
|
||||
Reference in New Issue
Block a user