mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
Remove out of zone penality + upgrades
This commit is contained in:
@@ -3,6 +3,7 @@ import { useSocket } from "./socketContext";
|
||||
import { useSocketAuth } from "../hook/useSocketAuth";
|
||||
|
||||
const teamConnexionContext = createContext();
|
||||
|
||||
const TeamConnexionProvider = ({ children }) => {
|
||||
const { teamSocket } = useSocket();
|
||||
const { login, password: teamId, loggedIn, loading, logout } = useSocketAuth(teamSocket, "team_password");
|
||||
|
||||
@@ -4,13 +4,21 @@ import { createContext, useContext, useMemo, useRef, useState } from "react";
|
||||
import { useSocket } from "./socketContext";
|
||||
import { GameState } from "../util/gameState";
|
||||
import useSendDeviceInfo from "../hook/useSendDeviceInfo";
|
||||
import { useTeamConnexion } from "./teamConnexionContext";
|
||||
|
||||
const teamContext = createContext();
|
||||
|
||||
const zoneTypes = {
|
||||
circle: "circle",
|
||||
polygon: "polygon"
|
||||
}
|
||||
|
||||
const teamContext = createContext()
|
||||
function TeamProvider({children}) {
|
||||
const { logout } = useTeamConnexion();
|
||||
const [teamInfos, setTeamInfos] = useState({});
|
||||
const [gameState, setGameState] = useState(GameState.SETUP);
|
||||
const [gameSettings, setGameSettings] = useState(null);
|
||||
const [zoneType, setZoneType] = useState(null);
|
||||
const [zoneExtremities, setZoneExtremities] = useState(null);
|
||||
const [nextZoneDate, setNextZoneDate] = useState(null);
|
||||
const [location, getLocationAuthorization, startLocationTracking, stopLocationTracking] = useLocation(5000, 10);
|
||||
@@ -21,21 +29,38 @@ function TeamProvider({children}) {
|
||||
|
||||
teamInfosRef.current = teamInfos;
|
||||
|
||||
function setCurrentZone(data) {
|
||||
const newBegin = {points : data.begin.points.map( p => ({latitude: p.lat,longitude: p.lng}) ), duration: data.begin.duration};
|
||||
const newEnd = {points : data.end.points.map( p => ({latitude: p.lat,longitude: p.lng}) ), duration: data.end.duration};
|
||||
setZoneExtremities({begin: newBegin, end: newEnd});
|
||||
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;
|
||||
}
|
||||
setNextZoneDate(data.endDate);
|
||||
}
|
||||
|
||||
useSocketListener(teamSocket, "update_team", (newTeamInfos) => {setTeamInfos({...teamInfosRef.current, ...newTeamInfos})});
|
||||
useSocketListener(teamSocket, "game_state", setGameState);
|
||||
useSocketListener(teamSocket, "current_zone", setCurrentZone);
|
||||
useSocketListener(teamSocket, "zone", setZone);
|
||||
useSocketListener(teamSocket, "game_settings", setGameSettings);
|
||||
useSocketListener(teamSocket, "logout", logout);
|
||||
|
||||
const value = useMemo(() => (
|
||||
{teamInfos, gameState, zoneExtremities, nextZoneDate, gameSettings, location, getLocationAuthorization, startLocationTracking, stopLocationTracking}
|
||||
), [teamInfos, gameState, zoneExtremities, nextZoneDate, gameSettings, location]);
|
||||
{teamInfos, gameState, zoneType, zoneExtremities, nextZoneDate, gameSettings, location, getLocationAuthorization, startLocationTracking, stopLocationTracking}
|
||||
), [teamInfos, gameState, zoneType, zoneExtremities, nextZoneDate, gameSettings, location]);
|
||||
|
||||
return (
|
||||
<teamContext.Provider value={value}>
|
||||
{children}
|
||||
@@ -47,4 +72,4 @@ function useTeamContext() {
|
||||
return useContext(teamContext);
|
||||
}
|
||||
|
||||
export { TeamProvider, useTeamContext };
|
||||
export { TeamProvider, useTeamContext };
|
||||
|
||||
Reference in New Issue
Block a user