Corrections + admin full screen

This commit is contained in:
Sebastien Riviere
2025-09-18 01:27:44 +02:00
parent 0f64fc59f9
commit a2c4b5c540
24 changed files with 201 additions and 135 deletions

View File

@@ -50,14 +50,15 @@ export function initAdminSocketHandler() {
socket.emit("teams", game.teams);
socket.emit("game_state", {
state: game.state,
date: game.stateDate
date: game.startDate
});
socket.emit("current_zone", {
begin: zoneManager.getCurrentZone(),
end: zoneManager.getNextZone(),
endDate: zoneManager.currentZone.endDate,
endDate: zoneManager.currentZone?.endDate,
});
socket.emit("settings", game.getAdminSettings());
socket.emit("login_response", true);
});
socket.on("add_team", (teamName) => {
@@ -77,7 +78,7 @@ export function initAdminSocketHandler() {
socket.on("capture_team", (teamId) => {
if (!loggedIn) return;
game.captureTeam(teamId);
game.switchCapturedTeam(teamId);
});
socket.on("placement_team", (teamId, placementZone) => {

View File

@@ -40,7 +40,7 @@ export default {
// Current state of the game
state: GameState.SETUP,
// Date since the state changed
stateDate: Date.now(),
startDate: null,
// Messages
messages: {
waiting: "",
@@ -84,7 +84,7 @@ export default {
}
// Update of enemyLocation now we have the lastSentLocation of the enemy
for (const team of this.teams) {
team.enemyLocation = this.getTeam(team.chasing).lastSentLocation;
team.enemyLocation = this.getTeam(team.chasing)?.lastSentLocation;
sendUpdatedTeamInformations(team.id);
}
// Broadcast new infos
@@ -153,6 +153,7 @@ export default {
setState(newState) {
const dateNow = Date.now();
if (newState == this.state) return true;
switch (newState) {
case GameState.SETUP:
trajectory.stop();
@@ -160,29 +161,32 @@ export default {
sendPositionTimeouts.clearAll();
outOfZoneTimeouts.clearAll();
this.resetTeamsInfos();
this.startDate = null;
break;
case GameState.PLACEMENT:
if (this.teams.length < 3) {
secureAdminBroadcast("game_state", {state: this.state, date: this.stateDate});
if (this.state == GameState.FINISHED || this.teams.length < 3) {
secureAdminBroadcast("game_state", {state: this.state, date: this.startDate});
return false;
}
trajectory.stop();
zoneManager.stop();
sendPositionTimeouts.clearAll();
outOfZoneTimeouts.clearAll();
this.startDate = null;
break;
case GameState.PLAYING:
if (this.teams.length < 3) {
secureAdminBroadcast("game_state", {state: this.state, date: this.stateDate});
if (this.state == GameState.FINISHED || this.teams.length < 3) {
secureAdminBroadcast("game_state", {state: this.state, date: this.startDate});
return false;
}
trajectory.start();
zoneManager.start();
this.initLastSentLocations();
this.startDate = dateNow;
break;
case GameState.FINISHED:
if (this.state != GameState.PLAYING) {
secureAdminBroadcast("game_state", {state: this.state, date: this.stateDate});
secureAdminBroadcast("game_state", {state: this.state, date: this.startDate});
return false;
}
trajectory.stop();
@@ -195,10 +199,9 @@ export default {
}
// Update the state
this.state = newState;
this.stateDate = dateNow;
// Broadcast new infos
secureAdminBroadcast("game_state", {state: newState, date: this.stateDate});
playersBroadcast("game_state", {state: newState, date: this.stateDate});
secureAdminBroadcast("game_state", {state: newState, date: this.startDate});
playersBroadcast("game_state", {state: newState, date: this.startDate});
return true;
},
@@ -257,7 +260,7 @@ export default {
// Identification
sockets: [],
name: teamName,
id: this.getNewTeamId(this.teams),
id: this.getNewTeamId(),
captureCode: randint(10_000),
// Chasing
captured: false,
@@ -319,19 +322,28 @@ export default {
return true;
},
captureTeam(teamId) {
switchCapturedTeam(teamId) {
// Test of parameters
if (!this.hasTeam(teamId)) return false;
// Variables
const team = this.getTeam(teamId);
const dateNow = Date.now();
// Make the capture
team.captured = true;
team.finishDate = dateNow;
team.chasing = null;
team.chased = null;
sendPositionTimeouts.clear(team.id);
outOfZoneTimeouts.clear(team.id);
// Switch team.captured
if (this.state != GameState.PLAYING) return false;
if (team.captured) {
team.captured = false;
team.finishDate = null;
team.lastSentLocation = team.currentLocation;
team.locationSendDeadline = dateNow + sendPositionTimeouts.delay * 60 * 1000;
sendPositionTimeouts.set(team.id);
} else {
team.captured = true;
team.finishDate = dateNow;
team.chasing = null;
team.chased = null;
sendPositionTimeouts.clear(team.id);
outOfZoneTimeouts.clear(team.id);
}
this.updateChasingChain();
this.checkEndGame();
// Broadcast new infos
@@ -384,21 +396,24 @@ export default {
updateLocation(teamId, location) {
// Test of parameters
if (!this.hasTeam(teamId)) return false;
if (!this.hasTeam(this.getTeam(teamId).chasing)) return false;
if (!location) return false;
// Variables
const team = this.getTeam(teamId);
const enemyTeam = this.getTeam(team.chasing);
const dateNow = Date.now();
// Update distance
if (team.currentLocation) team.distance += Math.floor(getDistanceFromLatLon({lat: location[0], lng: location[1]}, {lat: team.currentLocation[0], lng: team.currentLocation[1]}));
if (this.state == GameState.PLAYING && team.currentLocation) {
team.distance += Math.floor(getDistanceFromLatLon({lat: location[0], lng: location[1]}, {lat: team.currentLocation[0], lng: team.currentLocation[1]}));
}
// Update of currentLocation
team.currentLocation = location;
team.lastCurrentLocationDate = dateNow;
if (team.hasHandicap) {
if (this.state == GameState.PLAYING && team.hasHandicap) {
team.lastSentLocation = team.currentLocation;
}
// Update of enemyLocation
if (enemyTeam.hasHandicap) {
if (this.state == GameState.PLAYING && enemyTeam.hasHandicap) {
team.enemyLocation = enemyTeam.currentLocation;
}
// Update of ready
@@ -406,20 +421,22 @@ export default {
team.ready = isInCircle({ lat: location[0], lng: location[1] }, team.startingArea.center, team.startingArea.radius);
}
// Update out of zone
const teamCurrentlyOutOfZone = !zoneManager.isInZone({ lat: location[0], lng: location[1] })
if (teamCurrentlyOutOfZone && !team.outOfZone) {
team.outOfZone = true;
team.outOfZoneDeadline = dateNow + outOfZoneTimeouts.delay * 60 * 1000;
outOfZoneTimeouts.set(teamId);
} else if (!teamCurrentlyOutOfZone && team.outOfZone) {
team.outOfZone = false;
team.outOfZoneDeadline = null;
team.hasHandicap = false;
if (!sendPositionTimeouts.has(team.id)) {
team.locationSendDeadline = dateNow + sendPositionTimeouts.delay * 60 * 1000;
sendPositionTimeouts.set(team.id);
if (this.state == GameState.PLAYING) {
const teamCurrentlyOutOfZone = !zoneManager.isInZone({ lat: location[0], lng: location[1] })
if (teamCurrentlyOutOfZone && !team.outOfZone) {
team.outOfZone = true;
team.outOfZoneDeadline = dateNow + outOfZoneTimeouts.delay * 60 * 1000;
outOfZoneTimeouts.set(teamId);
} else if (!teamCurrentlyOutOfZone && team.outOfZone) {
team.outOfZone = false;
team.outOfZoneDeadline = null;
team.hasHandicap = false;
if (!sendPositionTimeouts.has(team.id)) {
team.locationSendDeadline = dateNow + sendPositionTimeouts.delay * 60 * 1000;
sendPositionTimeouts.set(team.id);
}
outOfZoneTimeouts.clear(teamId);
}
outOfZoneTimeouts.clear(teamId);
}
// Broadcast new infos
secureAdminBroadcast("teams", this.teams);
@@ -430,8 +447,11 @@ export default {
},
sendLocation(teamId) {
// Conditions
if (this.state != GameState.PLAYING) return false;
// Test of parameters
if (!this.hasTeam(teamId)) return false;
if (!this.hasTeam(this.getTeam(teamId).chasing)) return false;
// Variables
const team = this.getTeam(teamId);
const enemyTeam = this.getTeam(team.chasing);
@@ -454,8 +474,11 @@ export default {
},
tryCapture(teamId, captureCode) {
// Conditions
if (this.state != GameState.PLAYING) return false;
// Test of parameters
if (!this.hasTeam(teamId)) return false;
if (!this.hasTeam(this.getTeam(teamId).chasing)) return false;
// Variables
const team = this.getTeam(teamId);
const enemyTeam = this.getTeam(team.chasing);

View File

@@ -59,7 +59,6 @@ export function sendUpdatedTeamInformations(teamId) {
distance: team.distance,
nCaptures: team.nCaptures,
nSentLocation: team.nSentLocation,
stateDate: game.stateDate,
finishDate: team.finishDate,
});
}
@@ -99,12 +98,12 @@ export function initTeamSocket() {
sendUpdatedTeamInformations(loginTeamId);
socket.emit("game_state", {
state: game.state,
date: game.stateDate
date: game.startDate
});
socket.emit("current_zone", {
begin: zoneManager.getCurrentZone(),
end: zoneManager.getNextZone(),
endDate: zoneManager.currentZone.endDate,
endDate: zoneManager.currentZone?.endDate,
});
socket.emit("settings", game.getPlayerSettings());
callback({ isLoggedIn : true, message: "Logged in"});

View File

@@ -0,0 +1,21 @@
1758151340243,position,48.7119647,2.202376
1758151348183,position,48.7119684,2.2023519
1758151356935,position,48.7119613,2.2023486
1758151364187,position,48.7119464,2.2023686
1758151372354,position,48.7119567,2.2023589
1758151380901,position,48.7119705,2.2023828
1758151388892,position,48.7119695,2.2023512
1758151397527,position,48.7119742,2.2023338
1758151405867,position,48.7119592,2.2023596
1758151414004,position,48.7119691,2.2023728
1758151424855,position,48.7119702,2.2023816
1758151430282,position,48.7119739,2.2023721
1758151438203,position,48.7119633,2.2023841
1758151446373,position,48.7119647,2.2023806
1758151454699,position,48.7119593,2.2023871
1758151462553,position,48.7119616,2.2023903
1758151470342,position,48.7119594,2.2023859
1758151478473,position,48.7119605,2.2023748
1758151486112,position,48.7119559,2.2023561
1758151494133,position,48.7119617,2.2023674
1758151502319,position,48.7119549,2.2023335

View File

@@ -173,21 +173,25 @@ function polygonSettingsToZones(settings) {
export default {
isRunning: false,
zones: [], // A zone has to be connected space that doesn't contain an earth pole
currentZone: { id: 0, timeoutId: null, endDate: null },
currentZone: null,
settings: defaultPolygonSettings,
start() {
if (this.isRunning) return;
this.isRunning = true;
this.currentZone.id = -1;
this.currentZone = { id: -1, timeoutId: null, endDate: null };
this.goNextZone();
},
stop() {
this.isRunning = false;
if (!this.isRunning) return;
clearTimeout(this.currentZone.timeoutId);
this.isRunning = false;
this.currentZone = null;
},
goNextZone() {
if (!this.isRunning) return;
this.currentZone.id++;
if (this.currentZone.id >= this.zones.length - 1) {
this.currentZone.endDate = Date.now();
@@ -199,10 +203,12 @@ export default {
},
getCurrentZone() {
if (!this.isRunning) return null;
return this.zones[this.currentZone.id];
},
getNextZone() {
if (!this.isRunning) return null;
if (this.currentZone.id + 1 < this.zones.length) {
return this.zones[this.currentZone.id + 1];
} else {
@@ -211,6 +217,7 @@ export default {
},
isInZone(location) {
if (!this.isRunning) return false;
if (this.zones.length == 0) {
return true;
} else {
@@ -227,13 +234,17 @@ export default {
this.zones = polygonSettingsToZones(settings);
break;
default:
return;
this.zones = [];
break;
}
this.settings = settings;
this.stop();
this.start();
this.zoneBroadcast();
},
zoneBroadcast() {
if (!this.isRunning) return;
const zone = {
begin: this.getCurrentZone(),
end: this.getNextZone(),