mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
front end design for zone selection
This commit is contained in:
@@ -4,7 +4,11 @@ import BlueButton, { GreenButton, RedButton } from "@/components/util/button";
|
|||||||
import { useAdminConnexion } from "@/context/adminConnexionContext";
|
import { useAdminConnexion } from "@/context/adminConnexionContext";
|
||||||
import useAdmin from "@/hook/useAdmin";
|
import useAdmin from "@/hook/useAdmin";
|
||||||
import { GameState } from "@/util/gameState";
|
import { GameState } from "@/util/gameState";
|
||||||
|
import dynamic from "next/dynamic";
|
||||||
|
|
||||||
|
const ZoneSelector = dynamic(() => import('@/components/admin/zoneSelector').then((mod) => mod.ZoneSelector), {
|
||||||
|
ssr: false
|
||||||
|
});
|
||||||
export default function AdminPage() {
|
export default function AdminPage() {
|
||||||
const { useProtect } = useAdminConnexion();
|
const { useProtect } = useAdminConnexion();
|
||||||
const { gameState, changeState } = useAdmin();
|
const { gameState, changeState } = useAdmin();
|
||||||
@@ -19,6 +23,7 @@ export default function AdminPage() {
|
|||||||
<BlueButton onClick={() => changeState(GameState.PLAYING)}>Start game</BlueButton>
|
<BlueButton onClick={() => changeState(GameState.PLAYING)}>Start game</BlueButton>
|
||||||
</div>
|
</div>
|
||||||
{gameState == GameState.PLACEMENT && <div className="max-h-5/6"><TeamReady /></div>}
|
{gameState == GameState.PLACEMENT && <div className="max-h-5/6"><TeamReady /></div>}
|
||||||
|
{gameState == GameState.SETUP && <ZoneSelector />}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -50,18 +50,36 @@ export function CircularAreaPicker({area, setArea, ...props}) {
|
|||||||
<MapEventListener onClick={handleClick} onMouseMove={handleMouseMove} />
|
<MapEventListener onClick={handleClick} onMouseMove={handleMouseMove} />
|
||||||
</MapContainer>)
|
</MapContainer>)
|
||||||
}
|
}
|
||||||
|
export const EditMode = {
|
||||||
export function ZonePicker({minArea, setMinArea, maxArea, setMaxArea, ...props}) {
|
MIN: 0,
|
||||||
|
MAX: 1
|
||||||
|
}
|
||||||
|
export function ZonePicker({minArea, setMinArea, maxArea, setMaxArea,editMode, ...props}) {
|
||||||
const location = useLocation(Infinity);
|
const location = useLocation(Infinity);
|
||||||
const {handleClick: maxClick, handleMouseMove: maxHover, center: maxCenter, radius: maxRadius} = useMapCircleDraw(minArea, setMinArea);
|
const {handleClick: maxClick, handleMouseMove: maxHover, center: maxCenter, radius: maxRadius} = useMapCircleDraw(minArea, setMinArea);
|
||||||
const {handleClick: minClick, handleMouseMove: minHover, center: minCenter, radius: minRadius} = useMapCircleDraw(maxArea, setMaxArea);
|
const {handleClick: minClick, handleMouseMove: minHover, center: minCenter, radius: minRadius} = useMapCircleDraw(maxArea, setMaxArea);
|
||||||
|
function handleClick(e) {
|
||||||
|
if (editMode == EditMode.MAX) {
|
||||||
|
maxClick(e);
|
||||||
|
} else {
|
||||||
|
minClick(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function handleMouseMove(e) {
|
||||||
|
if (editMode == EditMode.MAX) {
|
||||||
|
maxHover(e);
|
||||||
|
} else {
|
||||||
|
minHover(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<MapContainer {...props} className='min-h-full w-full ' center={[0, 0]} zoom={0} scrollWheelZoom={true}>
|
<MapContainer {...props} className='min-h-full w-full ' center={[0, 0]} zoom={0} scrollWheelZoom={true}>
|
||||||
<TileLayer
|
<TileLayer
|
||||||
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||||
/>
|
/>
|
||||||
{center && radius && <Circle center={center} radius={radius} fillColor="blue"/>}
|
{minCenter && minRadius && <Circle center={minCenter} radius={minRadius} color="blue" fillColor="blue"/>}
|
||||||
|
{maxCenter && maxRadius && <Circle center={maxCenter} radius={maxRadius} color="red" fillColor="red"/>}
|
||||||
<MapPan center={location} zoom={DEFAULT_ZOOM} />
|
<MapPan center={location} zoom={DEFAULT_ZOOM} />
|
||||||
<MapEventListener onClick={handleClick} onMouseMove={handleMouseMove} />
|
<MapEventListener onClick={handleClick} onMouseMove={handleMouseMove} />
|
||||||
</MapContainer>)
|
</MapContainer>)
|
||||||
|
|||||||
17
traque-front/components/admin/zoneSelector.jsx
Normal file
17
traque-front/components/admin/zoneSelector.jsx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import BlueButton, { RedButton } from "../util/button";
|
||||||
|
import { EditMode, ZonePicker } from "./mapPicker";
|
||||||
|
|
||||||
|
export function ZoneSelector() {
|
||||||
|
const [editMode, setEditMode] = useState(EditMode.MIN);
|
||||||
|
const [minZone, setMinZone] = useState(null);
|
||||||
|
const [maxZone, setMaxZone] = useState(null);
|
||||||
|
return <div className='w-2/5 h-full gap-1 bg-gray-200 p-10 flex flex-col text-center shadow-2xl overflow-y-scroll'>
|
||||||
|
<h2 className="text-2xl">Teams ready status</h2>
|
||||||
|
{editMode == EditMode.MIN && <RedButton onClick={() => setEditMode(EditMode.MAX)}>Edit end zone</RedButton>}
|
||||||
|
{editMode == EditMode.MAX && <BlueButton onClick={() => setEditMode(EditMode.MIN)}>Edit start zone</BlueButton>}
|
||||||
|
<div className='h-96'>
|
||||||
|
<ZonePicker minZone={minZone} maxZone={maxZone} editMode={editMode} setMinZone={setMinZone} setMaxZone={setMaxZone} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ const adminContext = createContext();
|
|||||||
|
|
||||||
function AdminProvider({children}) {
|
function AdminProvider({children}) {
|
||||||
const [teams, setTeams] = useState([]);
|
const [teams, setTeams] = useState([]);
|
||||||
|
const [zone, setZone] = useState(null)
|
||||||
const { adminSocket } = useSocket();
|
const { adminSocket } = useSocket();
|
||||||
const {loggedIn} = useAdminConnexion();
|
const {loggedIn} = useAdminConnexion();
|
||||||
const [gameState, setGameState] = useState(GameState.SETUP);
|
const [gameState, setGameState] = useState(GameState.SETUP);
|
||||||
@@ -21,8 +22,9 @@ function AdminProvider({children}) {
|
|||||||
|
|
||||||
//Bind listeners to update the team list and the game status on socket message
|
//Bind listeners to update the team list and the game status on socket message
|
||||||
useSocketListener(adminSocket, "teams", setTeams);
|
useSocketListener(adminSocket, "teams", setTeams);
|
||||||
|
useSocketListener(adminSocket, "zone", setZone);
|
||||||
|
|
||||||
const value = useMemo(() => ({teams, setTeams, gameState}), [teams, gameState]);
|
const value = useMemo(() => ({teams, zone, setZone, setTeams, gameState}), [zone,teams, gameState]);
|
||||||
return (
|
return (
|
||||||
<adminContext.Provider value={value}>
|
<adminContext.Provider value={value}>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useAdminContext } from "@/context/adminContext";
|
|||||||
import { useSocket } from "@/context/socketContext";
|
import { useSocket } from "@/context/socketContext";
|
||||||
|
|
||||||
export default function useAdmin(){
|
export default function useAdmin(){
|
||||||
const {teams, gameState } = useAdminContext();
|
const {teams, gameState, zone } = useAdminContext();
|
||||||
const {adminSocket} = useSocket();
|
const {adminSocket} = useSocket();
|
||||||
|
|
||||||
function pollTeams() {
|
function pollTeams() {
|
||||||
@@ -38,6 +38,10 @@ export default function useAdmin(){
|
|||||||
adminSocket.emit("change_state", state);
|
adminSocket.emit("change_state", state);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {teams, gameState, pollTeams, getTeam, getTeamName, reorderTeams, addTeam, removeTeam, changeState, updateTeam };
|
function setZone(zone) {
|
||||||
|
adminSocket.emit("set_zone", zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {teams, zone, gameState,setZone, pollTeams, getTeam, getTeamName, reorderTeams, addTeam, removeTeam, changeState, updateTeam };
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user