mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
added front end for showing zone to player
This commit is contained in:
@@ -5,6 +5,7 @@ import 'leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility
|
||||
import "leaflet-defaulticon-compatibility";
|
||||
import "leaflet/dist/leaflet.css";
|
||||
import useGame from '@/hook/useGame';
|
||||
import { useTeamContext } from '@/context/teamContext';
|
||||
|
||||
const DEFAULT_ZOOM = 17;
|
||||
|
||||
@@ -24,6 +25,22 @@ function MapPan(props) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function LiveZone() {
|
||||
const { zone } = useTeamContext();
|
||||
console.log('Zone', zone);
|
||||
return zone && <Circle center={zone.center} radius={zone.radius} color='blue' fill={false} />
|
||||
}
|
||||
|
||||
function ZoneExtremities() {
|
||||
const { zoneExtremities } = useTeamContext();
|
||||
console.log('Zone extremities', zoneExtremities);
|
||||
return zoneExtremities && zoneExtremities.begin && zoneExtremities.end && <>
|
||||
<Circle center={zoneExtremities.begin.center} radius={zoneExtremities.begin.radius} color='black' fill={false} />
|
||||
<Circle center={zoneExtremities.end.center} radius={zoneExtremities.end.radius} color='red' fill={false} />
|
||||
</>
|
||||
|
||||
}
|
||||
|
||||
export function LiveMap({ ...props }) {
|
||||
const { currentPosition, enemyPosition } = useGame();
|
||||
useEffect(() => {
|
||||
@@ -58,6 +75,8 @@ export function LiveMap({ ...props}) {
|
||||
</Popup>
|
||||
</Marker>}
|
||||
<MapPan center={currentPosition} />
|
||||
<LiveZone />
|
||||
<ZoneExtremities />
|
||||
</MapContainer>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
import { useLocation } from "@/hook/useLocation";
|
||||
import { useSocketListener } from "@/hook/useSocketListener";
|
||||
import { createContext, useContext, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { createContext, use, useContext, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useSocket } from "./socketContext";
|
||||
import { useTeamConnexion } from "./teamConnexionContext";
|
||||
import { GameState } from "@/util/gameState";
|
||||
@@ -11,6 +11,8 @@ const teamContext = createContext()
|
||||
function TeamProvider({children}) {
|
||||
const [teamInfos, setTeamInfos] = useState({});
|
||||
const [gameState, setGameState] = useState(GameState.SETUP);
|
||||
const [zone, setZone] = useState(null);
|
||||
const [zoneExtremities, setZoneExtremities] = useState(null);
|
||||
const measuredLocation = useLocation(10000);
|
||||
const {teamSocket} = useSocket();
|
||||
const {loggedIn} = useTeamConnexion();
|
||||
@@ -23,6 +25,9 @@ function TeamProvider({children}) {
|
||||
});
|
||||
|
||||
useSocketListener(teamSocket, "game_state", setGameState);
|
||||
useSocketListener(teamSocket, "zone", setZone);
|
||||
useSocketListener(teamSocket, "new_zone", setZoneExtremities);
|
||||
|
||||
|
||||
//Send the current position to the server when the user is logged in
|
||||
useEffect(() => {
|
||||
@@ -32,7 +37,7 @@ function TeamProvider({children}) {
|
||||
}
|
||||
}, [loggedIn, measuredLocation]);
|
||||
|
||||
const value = useMemo(() => ({teamInfos, gameState}), [teamInfos, gameState]);
|
||||
const value = useMemo(() => ({teamInfos, gameState, zone, zoneExtremities}), [teamInfos, gameState, zone, zoneExtremities]);
|
||||
return (
|
||||
<teamContext.Provider value={value}>
|
||||
{children}
|
||||
|
||||
Reference in New Issue
Block a user