From 2f5116b88a915d388e7991d44a26907106bc43e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rivi=C3=A8re?= Date: Thu, 26 Jun 2025 14:20:23 +0200 Subject: [PATCH] Corrections zones --- traque-back/penalty_controller.js | 2 +- traque-back/zone_manager.js | 9 ++++++--- traque-front/components/admin/liveMap.jsx | 6 +++--- traque-front/context/adminContext.jsx | 11 ++++++----- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/traque-back/penalty_controller.js b/traque-back/penalty_controller.js index 15bca3a..eb3152d 100644 --- a/traque-back/penalty_controller.js +++ b/traque-back/penalty_controller.js @@ -117,7 +117,7 @@ export default { if (team.currentLocation == null || !zoneManager.isRunning) { return; } - if (!zoneManager.isInCircle({ lat: team.currentLocation[0], lng: team.currentLocation[1] })) { + if (!zoneManager.isInZone({ lat: team.currentLocation[0], lng: team.currentLocation[1] })) { //The team was not previously out of the zone if (!this.outOfBoundsSince[team.id]) { this.outOfBoundsSince[team.id] = Date.now(); diff --git a/traque-back/zone_manager.js b/traque-back/zone_manager.js index 5630b6f..ecebf60 100644 --- a/traque-back/zone_manager.js +++ b/traque-back/zone_manager.js @@ -183,9 +183,12 @@ export default { goNextZone() { this.currentZone.id++; - if (this.currentZone.id >= this.zones.length) return; - this.currentZone.timeoutId = setTimeout(() => this.goNextZone(), this.getCurrentZone().duration * 60 * 1000); - this.currentZone.endDate = Date.now() + this.getCurrentZone().duration * 60 * 1000; + if (this.currentZone.id >= this.zones.length - 1) { + this.currentZone.endDate = Date.now(); + } else { + this.currentZone.timeoutId = setTimeout(() => this.goNextZone(), this.getCurrentZone().duration * 60 * 1000); + this.currentZone.endDate = Date.now() + this.getCurrentZone().duration * 60 * 1000; + } this.zoneBroadcast(); }, diff --git a/traque-front/components/admin/liveMap.jsx b/traque-front/components/admin/liveMap.jsx index 1a96f1e..8e91694 100644 --- a/traque-front/components/admin/liveMap.jsx +++ b/traque-front/components/admin/liveMap.jsx @@ -54,15 +54,15 @@ export default function LiveMap() { return (
- {gameState == GameState.PLAYING && timeLeftNextZone &&

{`Next zone in : ${formatTime(timeLeftNextZone)}`}

} + {gameState == GameState.PLAYING &&

{`Next zone in : ${formatTime(timeLeftNextZone)}`}

} - {gameState == GameState.PLAYING && zoneExtremities.begin && } - {gameState == GameState.PLAYING && zoneExtremities.end && } + {gameState == GameState.PLAYING && zoneExtremities.begin && } + {gameState == GameState.PLAYING && zoneExtremities.end && } {teams.map((team) => team.currentLocation && !team.captured && {team.name} diff --git a/traque-front/context/adminContext.jsx b/traque-front/context/adminContext.jsx index c093b2c..ed3e938 100644 --- a/traque-front/context/adminContext.jsx +++ b/traque-front/context/adminContext.jsx @@ -19,25 +19,26 @@ export function AdminProvider({ children }) { const [gameState, setGameState] = useState(GameState.SETUP); const [startDate, setStartDate] = useState(null); - useSocketListener(adminSocket, "game_state", (data) => {setGameState(data.state); setStartDate(data.startDate)}); // Send a request to get the teams when the user logs in useEffect(() => { adminSocket.emit("get_teams"); }, [loggedIn]); - function setCurrent_zone(data) { + function setCurrentZone(data) { setZoneExtremities({begin: data.begin, end: data.end}); setNextZoneDate(data.endDate); } - // Bind listeners to update the team list and the game status on socket message + useSocketListener(adminSocket, "game_state", (data) => {setGameState(data.state); setStartDate(data.startDate)}); useSocketListener(adminSocket, "teams", setTeams); useSocketListener(adminSocket, "zone_settings", setZoneSettings); useSocketListener(adminSocket, "game_settings", setGameSettings); useSocketListener(adminSocket, "penalty_settings", setPenaltySettings); - useSocketListener(adminSocket, "current_zone", setCurrent_zone); + useSocketListener(adminSocket, "current_zone", setCurrentZone); - const value = useMemo(() => ({ zoneExtremities, teams, zoneSettings, penaltySettings, gameSettings, gameState, nextZoneDate, startDate }), [zoneSettings, teams, gameState, zoneExtremities, penaltySettings, gameSettings, nextZoneDate, startDate]); + const value = useMemo(() => ( + { zoneExtremities, teams, zoneSettings, penaltySettings, gameSettings, gameState, nextZoneDate, startDate } + ), [zoneSettings, teams, gameState, zoneExtremities, penaltySettings, gameSettings, nextZoneDate, startDate]); return ( {children}