mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
implemented game state in front end
This commit is contained in:
@@ -5,14 +5,17 @@ import { createContext, useContext, useEffect, useMemo, useState } from "react";
|
||||
import { useSocket } from "./socketContext";
|
||||
import { useTeamConnexion } from "./teamConnexionContext";
|
||||
|
||||
|
||||
const teamContext = createContext()
|
||||
function TeamProvider({children}) {
|
||||
const [enemyPosition, setEnemyPosition] = useState();
|
||||
const [currentPosition, setCurrentPosition] = useState();
|
||||
const [gameState, setGameState] = useState(GameState.SETUP);
|
||||
const measuredLocation = useLocation(10000);
|
||||
const {teamSocket} = useSocket();
|
||||
const {loggedIn} = useTeamConnexion();
|
||||
|
||||
useSocketListener(teamSocket, "game_state", setGameState);
|
||||
useSocketListener(teamSocket, "enemy_position", setEnemyPosition);
|
||||
useSocketListener(teamSocket, "live_location", setCurrentPosition);
|
||||
|
||||
@@ -24,7 +27,7 @@ function TeamProvider({children}) {
|
||||
}
|
||||
}, [loggedIn, measuredLocation]);
|
||||
|
||||
const value = useMemo(() => ({enemyPosition, currentPosition}), [enemyPosition, currentPosition]);
|
||||
const value = useMemo(() => ({enemyPosition, currentPosition, gameState}), [enemyPosition, currentPosition, gameState]);
|
||||
return (
|
||||
<teamContext.Provider value={value}>
|
||||
{children}
|
||||
|
||||
Reference in New Issue
Block a user