mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 02:10:18 +01:00
Cleaning
This commit is contained in:
@@ -32,9 +32,9 @@ export default function Display() {
|
||||
const [bottomContainerHeight, setBottomContainerHeight] = useState(0);
|
||||
const router = useRouter();
|
||||
const {SERVER_URL} = useSocket();
|
||||
const {gameSettings, zoneType, zoneExtremities, nextZoneDate, isShrinking, location, startLocationTracking, stopLocationTracking, gameState} = useTeamContext();
|
||||
const {messages, zoneType, zoneExtremities, nextZoneDate, isShrinking, location, startLocationTracking, stopLocationTracking, gameState, startDate} = useTeamContext();
|
||||
const {loggedIn, logout, loading} = useTeamConnexion();
|
||||
const {sendCurrentPosition, capture, enemyLocation, enemyName, startingArea, captureCode, name, ready, captured, lastSentLocation, locationSendDeadline, teamId, outOfZone, outOfZoneDeadline, distance, startDate, finishDate, nCaptures, nSentLocation} = useGame();
|
||||
const {sendCurrentPosition, capture, enemyLocation, enemyName, startingArea, captureCode, name, ready, captured, lastSentLocation, locationSendDeadline, teamId, outOfZone, outOfZoneDeadline, distance, finishDate, nCaptures, nSentLocation} = useGame();
|
||||
const [enemyCaptureCode, setEnemyCaptureCode] = useState("");
|
||||
const [timeLeftSendLocation] = useTimeDifference(locationSendDeadline, 1000);
|
||||
const [timeLeftNextZone] = useTimeDifference(nextZoneDate, 1000);
|
||||
@@ -225,7 +225,7 @@ export default function Display() {
|
||||
const CapturedMessage = () => {
|
||||
return (
|
||||
<View style={[styles.timersContainer, {height: 61}]}>
|
||||
<Text style={{fontSize: 20}}>{gameSettings?.capturedMessage || "Vous avez été éliminé..."}</Text>
|
||||
<Text style={{fontSize: 20}}>{messages?.captured || "Vous avez été éliminé..."}</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -233,26 +233,28 @@ export default function Display() {
|
||||
const EndGameMessage = () => {
|
||||
return (
|
||||
<View style={[styles.timersContainer, {height: 61}]}>
|
||||
{captured && <Text style={{fontSize: 20}}>{gameSettings?.loserEndGameMessage || "Vous avez perdu..."}</Text>}
|
||||
{!captured && <Text style={{fontSize: 20}}>{gameSettings?.winnerEndGameMessage || "Vous avez gagné !"}</Text>}
|
||||
{captured && <Text style={{fontSize: 20}}>{messages?.loser || "Vous avez perdu..."}</Text>}
|
||||
{!captured && <Text style={{fontSize: 20}}>{messages?.winner || "Vous avez gagné !"}</Text>}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const Zones = () => {
|
||||
const latToLatitude = (pos) => ({latitude: pos.lat, longitude: pos.lng});
|
||||
|
||||
switch (zoneType) {
|
||||
case zoneTypes.circle:
|
||||
return (
|
||||
<View>
|
||||
{ zoneExtremities.begin && <Circle center={zoneExtremities.begin.center} radius={zoneExtremities.begin.radius} strokeColor="red" fillColor="rgba(255,0,0,0.1)" strokeWidth={2} />}
|
||||
{ zoneExtremities.end && <Circle center={zoneExtremities.end.center} radius={zoneExtremities.end.radius} strokeColor="green" fillColor="rgba(0,255,0,0.1)" strokeWidth={2} />}
|
||||
{ zoneExtremities.begin && <Circle center={latToLatitude(zoneExtremities.begin.center)} radius={zoneExtremities.begin.radius} strokeColor="red" fillColor="rgba(255,0,0,0.1)" strokeWidth={2} />}
|
||||
{ zoneExtremities.end && <Circle center={latToLatitude(zoneExtremities.end.center)} radius={zoneExtremities.end.radius} strokeColor="green" fillColor="rgba(0,255,0,0.1)" strokeWidth={2} />}
|
||||
</View>
|
||||
);
|
||||
case zoneTypes.polygon:
|
||||
return (
|
||||
<View>
|
||||
{ zoneExtremities.begin && <Polygon coordinates={zoneExtremities.begin.points} strokeColor="red" fillColor="rgba(255,0,0,0.1)" strokeWidth={2} /> }
|
||||
{ zoneExtremities.end && <Polygon coordinates={zoneExtremities.end.points} strokeColor="green" fillColor="rgba(0,255,0,0.1)" strokeWidth={2} /> }
|
||||
{ zoneExtremities.begin && <Polygon coordinates={zoneExtremities.begin.polygon.map(pos => latToLatitude(pos))} strokeColor="red" fillColor="rgba(255,0,0,0.1)" strokeWidth={2} /> }
|
||||
{ zoneExtremities.end && <Polygon coordinates={zoneExtremities.end.polygon.map(pos => latToLatitude(pos))} strokeColor="green" fillColor="rgba(0,255,0,0.1)" strokeWidth={2} /> }
|
||||
</View>
|
||||
);
|
||||
default:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useLocation } from "../hook/useLocation";
|
||||
import { useSocketListener } from "../hook/useSocketListener";
|
||||
import { createContext, useContext, useMemo, useRef, useState } from "react";
|
||||
import { createContext, useContext, useMemo, useState } from "react";
|
||||
import { useSocket } from "./socketContext";
|
||||
import { GameState } from "../util/gameState";
|
||||
import useSendDeviceInfo from "../hook/useSendDeviceInfo";
|
||||
@@ -14,52 +14,52 @@ const zoneTypes = {
|
||||
}
|
||||
|
||||
function TeamProvider({children}) {
|
||||
const { logout } = useTeamConnexion();
|
||||
const {teamSocket} = useSocket();
|
||||
const [location, getLocationAuthorization, startLocationTracking, stopLocationTracking] = useLocation(5000, 10);
|
||||
// update_team
|
||||
const [teamInfos, setTeamInfos] = useState({});
|
||||
// game_state
|
||||
const [gameState, setGameState] = useState(GameState.SETUP);
|
||||
const [gameSettings, setGameSettings] = useState(null);
|
||||
const [zoneType, setZoneType] = useState(null);
|
||||
const [startDate, setStartDate] = useState(null);
|
||||
// current_zone
|
||||
const [zoneExtremities, setZoneExtremities] = useState(null);
|
||||
const [nextZoneDate, setNextZoneDate] = useState(null);
|
||||
const [location, getLocationAuthorization, startLocationTracking, stopLocationTracking] = useLocation(5000, 10);
|
||||
const {teamSocket} = useSocket();
|
||||
const teamInfosRef = useRef();
|
||||
// settings
|
||||
const [messages, setMessages] = useState(null);
|
||||
const [zoneType, setZoneType] = useState(null);
|
||||
// logout
|
||||
const { logout } = useTeamConnexion();
|
||||
|
||||
useSendDeviceInfo();
|
||||
|
||||
teamInfosRef.current = teamInfos;
|
||||
useSocketListener(teamSocket, "update_team", (data) => {
|
||||
setTeamInfos(teamInfos => ({...teamInfos, ...data}))
|
||||
});
|
||||
|
||||
function setZone(data) {
|
||||
setZoneType(data.type);
|
||||
switch (data.type) {
|
||||
case zoneTypes.circle:
|
||||
setZoneExtremities({
|
||||
begin: {...data.begin, ...{center : {latitude: data.begin.center.lat, longitude: data.begin.center.lng} }},
|
||||
end: {...data.end, ...{center : {latitude: data.end.center.lat, longitude: data.end.center.lng} }}
|
||||
});
|
||||
break;
|
||||
case zoneTypes.polygon:
|
||||
setZoneExtremities({
|
||||
begin: {...data.begin, ...{points : data.begin.points.map( p => ({latitude: p.lat,longitude: p.lng}) )}},
|
||||
end: {...data.end, ...{points : data.end.points.map( p => ({latitude: p.lat,longitude: p.lng}) )}}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
setZoneExtremities({begin: data.begin, end: data.end});
|
||||
break;
|
||||
}
|
||||
useSocketListener(teamSocket, "game_state", (data) => {
|
||||
setGameState(data.state);
|
||||
setStartDate(data.date);
|
||||
});
|
||||
|
||||
useSocketListener(teamSocket, "settings", (data) => {
|
||||
setMessages(data.messages);
|
||||
setZoneType(data.zone.type);
|
||||
//TODO
|
||||
//setSendPositionDelay(data.sendPositionDelay);
|
||||
//setOutOfZoneDelay(data.outOfZoneDelay);
|
||||
});
|
||||
|
||||
useSocketListener(teamSocket, "current_zone", (data) => {
|
||||
setZoneExtremities({begin: data.begin, end: data.end});
|
||||
setNextZoneDate(data.endDate);
|
||||
}
|
||||
});
|
||||
|
||||
useSocketListener(teamSocket, "update_team", (newTeamInfos) => {setTeamInfos({...teamInfosRef.current, ...newTeamInfos})});
|
||||
useSocketListener(teamSocket, "game_state", setGameState);
|
||||
useSocketListener(teamSocket, "zone", setZone);
|
||||
useSocketListener(teamSocket, "game_settings", setGameSettings);
|
||||
useSocketListener(teamSocket, "logout", logout);
|
||||
|
||||
|
||||
const value = useMemo(() => (
|
||||
{teamInfos, gameState, zoneType, zoneExtremities, nextZoneDate, gameSettings, location, getLocationAuthorization, startLocationTracking, stopLocationTracking}
|
||||
), [teamInfos, gameState, zoneType, zoneExtremities, nextZoneDate, gameSettings, location]);
|
||||
{teamInfos, gameState, startDate, zoneType, zoneExtremities, nextZoneDate, messages, location, getLocationAuthorization, startLocationTracking, stopLocationTracking}
|
||||
), [teamInfos, gameState, startDate, zoneType, zoneExtremities, nextZoneDate, messages, location]);
|
||||
|
||||
return (
|
||||
<teamContext.Provider value={value}>
|
||||
|
||||
@@ -5,8 +5,8 @@ import { useTeamContext } from "../context/teamContext";
|
||||
export default function useGame() {
|
||||
const { teamSocket } = useSocket();
|
||||
const { teamId } = useTeamConnexion();
|
||||
const { teamInfos, gameState } = useTeamContext();
|
||||
|
||||
const { teamInfos } = useTeamContext();
|
||||
|
||||
function sendCurrentPosition() {
|
||||
console.log("Reveal position.")
|
||||
teamSocket.emit("send_position");
|
||||
@@ -29,5 +29,5 @@ export default function useGame() {
|
||||
});
|
||||
}
|
||||
|
||||
return {...teamInfos, sendCurrentPosition, capture, teamId, gameState};
|
||||
return {...teamInfos, sendCurrentPosition, capture, teamId};
|
||||
}
|
||||
Reference in New Issue
Block a user