diff --git a/doc/TODO.md b/doc/TODO.md index fe1f491..50a6d94 100644 --- a/doc/TODO.md +++ b/doc/TODO.md @@ -38,7 +38,7 @@ - [x] Refaire les flèches de chasse sur la map - [x] Pouvoir définir la zone de départ de chaque équipe - [x] Nommer les polygons par des lettres de l'alphabet -- [ ] Plein écran +- [x] Plein écran - [ ] Pouvoir faire pause dans la partie - [ ] Mettre en évidence le menu paramètre - [ ] Afficher un feedback quand un paramètre est sauvegardé diff --git a/traque-app/app/display.js b/traque-app/app/display.js index 062cfe7..6bcc71d 100644 --- a/traque-app/app/display.js +++ b/traque-app/app/display.js @@ -58,7 +58,7 @@ export default function Display() { // Activating geolocation tracking useEffect(() => { - if (loggedIn && (gameState == GameState.SETUP || gameState == GameState.PLAYING || gameState == GameState.PLACEMENT) && !captured) { + if (loggedIn) { startLocationTracking(); } else { stopLocationTracking(); @@ -89,8 +89,9 @@ export default function Display() { // Update the average speed useEffect(() => { - const time = finishDate ? (finishDate - startDate) : timeSinceStart; - setAvgSpeed(distance/time); + const hours = (finishDate ? (finishDate - startDate) : timeSinceStart*1000) / 1000 / 3600; + const km = distance / 1000; + setAvgSpeed(Math.floor(km / hours * 10) / 10); }, [distance, finishDate, timeSinceStart]); function toggleCollapsible() { @@ -172,11 +173,11 @@ export default function Display() { const GameLog = () => { return ( - { gameState == GameState.SETUP && Préparation de la partie} + { gameState == GameState.SETUP && {messages?.waiting || "Préparation de la partie"}} { gameState == GameState.PLACEMENT && Phase de placement} { gameState == GameState.PLAYING && !outOfZone && La partie est en cours} - { gameState == GameState.PLAYING && outOfZone && !hasHandicap && Hors zone (handicap dans {formatTimeMinutes(-timeLeftOutOfZone)})} - { gameState == GameState.PLAYING && hasHandicap && Hors zone (position révélée en continue)} + { gameState == GameState.PLAYING && outOfZone && !hasHandicap && {`Veuillez retourner dans la zone\nHandicap dans ${formatTimeMinutes(-timeLeftOutOfZone)}`}} + { gameState == GameState.PLAYING && hasHandicap && {`Veuillez retourner dans la zone\nVotre position est révélée en continue`}} { gameState == GameState.FINISHED && La partie est terminée} ); @@ -243,44 +244,34 @@ export default function Display() { const Zones = () => { const latToLatitude = (pos) => ({latitude: pos.lat, longitude: pos.lng}); - switch (zoneType) { - case zoneTypes.circle: - return ( - - { zoneExtremities.begin && } - { zoneExtremities.end && } - - ); - case zoneTypes.polygon: - return ( - - { zoneExtremities.begin && latToLatitude(pos))} strokeColor="red" fillColor="rgba(255,0,0,0.1)" strokeWidth={2} /> } - { zoneExtremities.end && latToLatitude(pos))} strokeColor="green" fillColor="rgba(0,255,0,0.1)" strokeWidth={2} /> } - - ); - default: - return null; - } + return ( + + { zoneType == zoneTypes.circle && zoneExtremities.begin && } + { zoneType == zoneTypes.circle && zoneExtremities.end && } + { zoneType == zoneTypes.polygon && zoneExtremities.begin && latToLatitude(pos))} strokeColor="red" fillColor="rgba(255,0,0,0.1)" strokeWidth={2} /> } + { zoneType == zoneTypes.polygon && zoneExtremities.end && latToLatitude(pos))} strokeColor="green" fillColor="rgba(0,255,0,0.1)" strokeWidth={2} /> } + + ); } const Map = () => { return ( - setCenterMap(false)}> + setCenterMap(false)} toolbarEnabled={false}> { gameState == GameState.PLACEMENT && startingArea && circle("0, 0, 255", startingArea)} { gameState == GameState.PLAYING && zoneExtremities && } { location && - + Alert.alert("Position actuelle", "Ceci est votre position")}> } { gameState == GameState.PLAYING && lastSentLocation && !hasHandicap && - + Alert.alert("Position envoyée", "Ceci est votre dernière position connue par le serveur")}> } { gameState == GameState.PLAYING && enemyLocation && !hasHandicap && - + Alert.alert("Position ennemie", "Ceci est la dernière position de vos ennemis connue")}/> } @@ -329,7 +320,6 @@ export default function Display() { return ( {{"Cible (" + (enemyName ?? "Indisponible") + ")"}} - {enemyHasHandicap && Position ennemie révélée en continue} {} ); @@ -357,9 +347,9 @@ export default function Display() { return ( - {(distance / 1000).toFixed(1)}km + {Math.floor(distance / 100) / 10}km {formatTimeHours((finishDate ? Math.floor((finishDate - startDate) / 1000) : timeSinceStart))} - {(avgSpeed*3.6).toFixed(1)}km/h + {avgSpeed}km/h {nCaptures} @@ -394,6 +384,7 @@ export default function Display() { { gameState == GameState.FINISHED && EndGameMessage() } + {enemyHasHandicap && Position ennemie révélée en continue !} {setBottomContainerHeight(event.nativeEvent.layout.height)}}> @@ -411,15 +402,15 @@ export default function Display() { } - { gameState == GameState.PLAYING && !captured && + { (gameState == GameState.PLAYING || gameState == GameState.FINISHED) && { CollapsibleButton() } - { TeamCaptureCode() } - { !hasHandicap && + { gameState == GameState.PLAYING && TeamCaptureCode() } + { gameState == GameState.PLAYING && !hasHandicap && { ChasedTeamImage() } { CaptureCode() } @@ -468,7 +459,7 @@ const styles = StyleSheet.create({ borderRadius: 10, width: "100%", backgroundColor: 'white', - fontSize: 20, + fontSize: 18, padding: 10, }, gameStateOutOfZone: { @@ -476,7 +467,7 @@ const styles = StyleSheet.create({ borderRadius: 10, width: "100%", backgroundColor: 'white', - fontSize: 20, + fontSize: 18, padding: 10, borderColor: 'red' }, diff --git a/traque-app/context/socketContext.jsx b/traque-app/context/socketContext.jsx index 4654056..d98ae4b 100644 --- a/traque-app/context/socketContext.jsx +++ b/traque-app/context/socketContext.jsx @@ -1,7 +1,7 @@ import { createContext, useContext, useMemo } from "react"; import { io } from "socket.io-client"; -const HOST = '192.168.15.129'; // IP of the machine hosting the server +const HOST = 'traque.rezel.net'; // IP of the machine hosting the server const SOCKET_URL = (HOST == "traque.rezel.net" ? "wss://" : "ws://") + HOST + "/player"; const SERVER_URL = (HOST == "traque.rezel.net" ? "https://" : "http://") + HOST + "/back"; diff --git a/traque-app/context/teamContext.jsx b/traque-app/context/teamContext.jsx index a7e60c9..b5e338f 100644 --- a/traque-app/context/teamContext.jsx +++ b/traque-app/context/teamContext.jsx @@ -8,11 +8,6 @@ import { useTeamConnexion } from "./teamConnexionContext"; const teamContext = createContext(); -const zoneTypes = { - circle: "circle", - polygon: "polygon" -} - function TeamProvider({children}) { const {teamSocket} = useSocket(); const [location, getLocationAuthorization, startLocationTracking, stopLocationTracking] = useLocation(5000, 10); diff --git a/traque-back/admin_socket.js b/traque-back/admin_socket.js index 7e278dc..d5a2c9f 100644 --- a/traque-back/admin_socket.js +++ b/traque-back/admin_socket.js @@ -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) => { diff --git a/traque-back/game.js b/traque-back/game.js index eee69b5..c9a382c 100644 --- a/traque-back/game.js +++ b/traque-back/game.js @@ -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); diff --git a/traque-back/team_socket.js b/traque-back/team_socket.js index bdb2617..734c8ea 100644 --- a/traque-back/team_socket.js +++ b/traque-back/team_socket.js @@ -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"}); diff --git a/traque-back/trajectories/367440.txt b/traque-back/trajectories/367440.txt new file mode 100644 index 0000000..1715ea6 --- /dev/null +++ b/traque-back/trajectories/367440.txt @@ -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 diff --git a/traque-back/zone_manager.js b/traque-back/zone_manager.js index ad44e14..252cfd3 100644 --- a/traque-back/zone_manager.js +++ b/traque-back/zone_manager.js @@ -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(), diff --git a/traque-front/app/admin/components/liveMap.jsx b/traque-front/app/admin/components/liveMap.jsx index 87321dc..1186604 100644 --- a/traque-front/app/admin/components/liveMap.jsx +++ b/traque-front/app/admin/components/liveMap.jsx @@ -8,6 +8,8 @@ import { mapZooms } from "@/util/configurations"; export default function LiveMap({ selectedTeamId, onSelected, isFocusing, setIsFocusing, mapStyle, showZones, showNames, showArrows }) { const { zoneType, zoneExtremities, teams, nextZoneDate, getTeam, gameState } = useAdmin(); const [timeLeftNextZone, setTimeLeftNextZone] = useState(null); + const [isFullScreen, setIsFullScreen] = useState(false); + useEffect(() => { if (nextZoneDate) { @@ -50,8 +52,7 @@ export default function LiveMap({ selectedTeamId, onSelected, isFocusing, setIsF } return ( -
- {gameState == GameState.PLAYING &&

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

} +
{isFocusing && } setIsFocusing(false)}/> @@ -60,12 +61,21 @@ export default function LiveMap({ selectedTeamId, onSelected, isFocusing, setIsF - + onSelected(team.id)} display={!team.captured}> )} + { gameState == GameState.PLAYING && +
+

Durée zone

+

{formatTime(timeLeftNextZone)}

+
+ } +
) } diff --git a/traque-front/app/admin/components/teamSidePanel.jsx b/traque-front/app/admin/components/teamSidePanel.jsx index 95ead05..7797c72 100644 --- a/traque-front/app/admin/components/teamSidePanel.jsx +++ b/traque-front/app/admin/components/teamSidePanel.jsx @@ -2,8 +2,7 @@ import { env } from 'next-runtime-env'; import { useEffect, useState } from "react"; import useAdmin from "@/hook/useAdmin"; import { getStatus } from '@/util/functions'; -import { Colors } from '@/util/types'; -import { teamStatus } from '@/util/configurations'; +import { Colors, GameState } from '@/util/types'; function DotLine({ label, value }) { return ( @@ -32,6 +31,7 @@ function IconValue({ color, icon, value }) { export default function TeamSidePanel({ selectedTeamId, onClose }) { const { getTeam, startDate, gameState } = useAdmin(); const [imgSrc, setImgSrc] = useState(""); + const [_, setRefreshKey] = useState(0); const team = getTeam(selectedTeamId); const NO_VALUE = "XX"; const NEXT_PUBLIC_SOCKET_HOST = env("NEXT_PUBLIC_SOCKET_HOST"); @@ -43,6 +43,14 @@ export default function TeamSidePanel({ selectedTeamId, onClose }) { if (!team) return null; + useEffect(() => { + const interval = setInterval(() => { + setRefreshKey(prev => prev + 1); + }, 1000); + + return () => clearInterval(interval); + }, []); + function formatTime(startDate, endDate) { // startDate in milliseconds if (endDate == null || startDate == null || startDate < 0) return NO_VALUE + ":" + NO_VALUE; @@ -92,18 +100,22 @@ export default function TeamSidePanel({ selectedTeamId, onClose }) {
-
- - -
-
- - - - - - -
+ { gameState != GameState.FINISHED && +
+ + +
+ } + { (gameState == GameState.PLAYING || gameState == GameState.FINISHED) && +
+ + + + + + +
+ }
diff --git a/traque-front/app/admin/login/page.js b/traque-front/app/admin/login/page.js index 682ebd9..eedfd1e 100644 --- a/traque-front/app/admin/login/page.js +++ b/traque-front/app/admin/login/page.js @@ -17,9 +17,9 @@ export default function AdminLoginPage() { return (
-

Admin login

- setValue(e.target.value)}/> - +

Connexion admin

+ setValue(e.target.value)}/> +
); diff --git a/traque-front/app/admin/page.js b/traque-front/app/admin/page.js index 80c881a..31668de 100644 --- a/traque-front/app/admin/page.js +++ b/traque-front/app/admin/page.js @@ -45,7 +45,7 @@ export default function AdminPage() { const [mapStyle, setMapStyle] = useState(mapStyles.default); const [showZones, setShowZones] = useState(true); const [showNames, setShowNames] = useState(true); - const [showArrows, setShowArrows] = useState(false); + const [showArrows, setShowArrows] = useState(true); const [isFocusing, setIsFocusing] = useState(true); useProtect(); diff --git a/traque-front/app/admin/parameters/components/circleZoneSelector.jsx b/traque-front/app/admin/parameters/components/circleZoneSelector.jsx index ef8c9fc..f84f0ee 100644 --- a/traque-front/app/admin/parameters/components/circleZoneSelector.jsx +++ b/traque-front/app/admin/parameters/components/circleZoneSelector.jsx @@ -89,21 +89,21 @@ export default function CircleZoneSelector({ display }) {
- {editMode == EditMode.MIN && } - {editMode == EditMode.MAX && } + {editMode == EditMode.MAX && } + {editMode == EditMode.MIN && }
-

Reduction number

+

Nombre de rétrécissements

-

Zone duration

+

Durée d'une zone

-

Timeout

+

Temps permis hors zone

- +
} diff --git a/traque-front/app/admin/parameters/components/messages.jsx b/traque-front/app/admin/parameters/components/messages.jsx index e67ca89..1a1362c 100644 --- a/traque-front/app/admin/parameters/components/messages.jsx +++ b/traque-front/app/admin/parameters/components/messages.jsx @@ -20,7 +20,7 @@ export default function Messages() { }; return ( -
+
modifyLocalZoneSettings("waiting", e.target.value)} onBlur={applyLocalGameSettings}/> modifyLocalZoneSettings("captured", e.target.value)} onBlur={applyLocalGameSettings}/> modifyLocalZoneSettings("winner", e.target.value)} onBlur={applyLocalGameSettings}/> diff --git a/traque-front/app/admin/parameters/components/placementZoneSelector.jsx b/traque-front/app/admin/parameters/components/placementZoneSelector.jsx index a498d21..46afc3f 100644 --- a/traque-front/app/admin/parameters/components/placementZoneSelector.jsx +++ b/traque-front/app/admin/parameters/components/placementZoneSelector.jsx @@ -54,7 +54,7 @@ export default function PlacementZoneSelector({ display }) {
-

Teams

+

Équipes

setSelectedTeamId(selectedTeamId != id ? id : null)}> { (team) => diff --git a/traque-front/app/admin/parameters/components/playingZoneSelector.jsx b/traque-front/app/admin/parameters/components/playingZoneSelector.jsx index e2b18d7..d748be8 100644 --- a/traque-front/app/admin/parameters/components/playingZoneSelector.jsx +++ b/traque-front/app/admin/parameters/components/playingZoneSelector.jsx @@ -1,6 +1,7 @@ -import { useState } from "react"; import dynamic from "next/dynamic"; import { ZoneTypes } from "@/util/types"; +import useLocalVariable from "@/hook/useLocalVariable"; +import useAdmin from "@/hook/useAdmin"; // Imported at runtime and not at compile time const CircleZoneSelector = dynamic(() => import('./circleZoneSelector'), { ssr: false }); @@ -18,18 +19,19 @@ function ZoneTypeButton({title, onClick, isSelected}) { } export default function PlayingZoneSelector({ display }) { - const [zoneType, setZoneType] = useState(ZoneTypes.POLYGON); + const { zoneType } = useAdmin(); + const [localZoneType, setLocalZoneType] = useLocalVariable(zoneType, () => {}); return (

Type de zone :

- setZoneType(ZoneTypes.CIRCLE)} isSelected={zoneType == ZoneTypes.CIRCLE} /> - setZoneType(ZoneTypes.POLYGON)} isSelected={zoneType == ZoneTypes.POLYGON} /> + setLocalZoneType(ZoneTypes.CIRCLE)} isSelected={localZoneType == ZoneTypes.CIRCLE} /> + setLocalZoneType(ZoneTypes.POLYGON)} isSelected={localZoneType == ZoneTypes.POLYGON} />
- - + +
); diff --git a/traque-front/app/admin/parameters/components/polygonZoneSelector.jsx b/traque-front/app/admin/parameters/components/polygonZoneSelector.jsx index e6fa614..e13ba4e 100644 --- a/traque-front/app/admin/parameters/components/polygonZoneSelector.jsx +++ b/traque-front/app/admin/parameters/components/polygonZoneSelector.jsx @@ -106,7 +106,7 @@ export default function PolygonZoneSelector({ display }) {
-

Reduction order

+

Ordre de réduction

{ (zone) => @@ -117,10 +117,10 @@ export default function PolygonZoneSelector({ display }) { }
-

Timeout

+

Temps permis hors zone

- +
} diff --git a/traque-front/app/admin/parameters/components/teamManager.jsx b/traque-front/app/admin/parameters/components/teamManager.jsx index 131f9b8..caa5192 100644 --- a/traque-front/app/admin/parameters/components/teamManager.jsx +++ b/traque-front/app/admin/parameters/components/teamManager.jsx @@ -34,7 +34,7 @@ export default function TeamManager() { } return ( -
+
setTeamName(e.target.value)} type="text" className="w-full h-full p-4 ring-1 ring-inset ring-gray-300" /> @@ -51,7 +51,7 @@ export default function TeamManager() {
-

Interval between position updates

+

Intervalle entre les envois de position

diff --git a/traque-front/components/layer.jsx b/traque-front/components/layer.jsx index 39a8e01..fd61bce 100644 --- a/traque-front/components/layer.jsx +++ b/traque-front/components/layer.jsx @@ -158,7 +158,7 @@ export function Arrow({ pos1, pos2, color = 'black', weight = 5, arrowSize = 20, map.removeLayer(polyline); map.removeLayer(decorator); }; - }, [insetPositions]) + }, [display, insetPositions]) return null; } diff --git a/traque-front/hook/usePasswordProtect.jsx b/traque-front/hook/usePasswordProtect.jsx index 6507e6f..612740f 100644 --- a/traque-front/hook/usePasswordProtect.jsx +++ b/traque-front/hook/usePasswordProtect.jsx @@ -10,7 +10,7 @@ export default function usePasswordProtect(loginPath, redirectPath, loading, log redirect(loginPath); } if(loggedIn && !loading && path === loginPath) { - redirect(redirectPath) + redirect(redirectPath); } }, [loggedIn, loading, path]); } diff --git a/traque-front/hook/useSocketAuth.jsx b/traque-front/hook/useSocketAuth.jsx index 92a0d2e..07a55cc 100644 --- a/traque-front/hook/useSocketAuth.jsx +++ b/traque-front/hook/useSocketAuth.jsx @@ -14,15 +14,13 @@ export default function useSocketAuth(socket, passwordName) { const [savedPassword, setSavedPassword, savedPasswordLoading] = useLocalStorage(passwordName, null); useEffect(() => { - console.log("Checking saved password", savedPassword, loggedIn); if (savedPassword && !loggedIn) { - console.log("Logging in with saved password", savedPassword); + console.log("Try to log with :", savedPassword); socket.emit(LOGIN_MESSAGE, savedPassword); } }, [savedPassword]); function login(password) { - console.log("Logging", password); setSavedPassword(password) } @@ -32,9 +30,10 @@ export default function useSocketAuth(socket, passwordName) { socket.emit(LOGOUT_MESSAGE) } - useSocketListener(socket, LOGIN_RESPONSE_MESSAGE,(loginResponse) => { + useSocketListener(socket, LOGIN_RESPONSE_MESSAGE, (loginResponse) => { setWaitingForResponse(false); setLoggedIn(loginResponse); + console.log(loginResponse ? "Logged in" : "Not logged in"); }); useEffect(() => { diff --git a/traque-front/util/configurations.js b/traque-front/util/configurations.js index a3a8fd3..645f60b 100644 --- a/traque-front/util/configurations.js +++ b/traque-front/util/configurations.js @@ -33,4 +33,6 @@ export const teamStatus = { ready: { label: "Placée", color: Colors.green }, notready: { label: "Non placée", color: Colors.red }, waiting: { label: "En attente", color: Colors.grey }, + victory: { label: "Victoire", color: Colors.green }, + defeat: { label: "Défaite", color: Colors.red }, } diff --git a/traque-front/util/functions.js b/traque-front/util/functions.js index 7223830..6ea4d4b 100644 --- a/traque-front/util/functions.js +++ b/traque-front/util/functions.js @@ -11,7 +11,7 @@ export function getStatus(team, gamestate) { case GameState.PLAYING: return team.captured ? teamStatus.captured : team.outOfZone ? teamStatus.outofzone : teamStatus.playing; case GameState.FINISHED: - return team.captured ? teamStatus.captured : teamStatus.playing; + return team.captured ? teamStatus.defeat : teamStatus.victory; default: return teamStatus.default; }