mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
Added placement zones
This commit is contained in:
@@ -68,6 +68,11 @@ export default function LiveMap({ selectedTeamId, onSelected, isFocusing, setIsF
|
||||
{isFocusing && <MapPan center={getTeam(selectedTeamId)?.currentLocation} zoom={mapZooms.high} animate />}
|
||||
<MapEventListener onDragStart={() => setIsFocusing(false)}/>
|
||||
<Zones/>
|
||||
{teams.map((team) => gameState == GameState.PLACEMENT && team.startingArea &&
|
||||
<Circle key={team.id} center={team.startingArea.center} radius={team.startingArea.radius} color="blue" fillColor="blue">
|
||||
<Tooltip permanent direction="top" offset={[0.5, -15]} className="custom-tooltip">{team.name}</Tooltip>
|
||||
</Circle>
|
||||
)}
|
||||
{teams.map((team) => team.currentLocation && !team.captured && <>
|
||||
<Marker key={team.id} position={team.currentLocation} icon={positionIcon} eventHandlers={{click: () => onSelected(team.id)}}>
|
||||
{showNames && <Tooltip permanent direction="top" offset={[0.5, -15]} className="custom-tooltip">{team.name}</Tooltip>}
|
||||
|
||||
@@ -2,12 +2,12 @@ import { List } from '@/components/list';
|
||||
import useAdmin from '@/hook/useAdmin';
|
||||
import { getStatus } from '@/util/functions';
|
||||
|
||||
function TeamViewerItem({ team, itemSelected, onSelected }) {
|
||||
function TeamViewerItem({ team }) {
|
||||
const { gameState } = useAdmin();
|
||||
const status = getStatus(team, gameState);
|
||||
|
||||
return (
|
||||
<div className={'w-full flex flex-row gap-3 p-2 bg-white justify-between cursor-pointer ' + (itemSelected ? "outline outline-4 outline-black" : "")} onClick={() => onSelected(team.id)}>
|
||||
<div className={'w-full flex flex-row gap-3 p-2 bg-white justify-between'}>
|
||||
<div className='flex flex-row items-center gap-3'>
|
||||
<div className='flex flex-row gap-1'>
|
||||
<img src={`/icons/user/${team.sockets.length > 0 ? "green" : "red"}.png`} className="w-4 h-4" />
|
||||
@@ -27,9 +27,9 @@ export default function TeamViewer({selectedTeamId, onSelected}) {
|
||||
const { teams } = useAdmin();
|
||||
|
||||
return (
|
||||
<List array={teams}>
|
||||
<List array={teams} selectedId={selectedTeamId} onSelected={onSelected} >
|
||||
{(team) => (
|
||||
<TeamViewerItem team={team} itemSelected={selectedTeamId === team.id} onSelected={onSelected}/>
|
||||
<TeamViewerItem team={team}/>
|
||||
)}
|
||||
</List>
|
||||
);
|
||||
|
||||
@@ -5,8 +5,10 @@ import { CustomButton } from "@/components/button";
|
||||
import { CustomMapContainer, MapEventListener } from "@/components/map";
|
||||
import { TextInput } from "@/components/input";
|
||||
import useAdmin from "@/hook/useAdmin";
|
||||
import useMapCircleDraw from "@/hook/useMapCircleDraw";
|
||||
import useMapCircleDraw from "@/hook/useCircleDraw";
|
||||
import useLocalVariable from "@/hook/useLocalVariable";
|
||||
import { defaultZoneSettings } from "@/util/configurations";
|
||||
import { ZoneTypes } from "@/util/types";
|
||||
|
||||
const EditMode = {
|
||||
MIN: 0,
|
||||
@@ -28,17 +30,40 @@ function Drawings({ minZone, setMinZone, maxZone, setMaxZone, editMode }) {
|
||||
</>);
|
||||
}
|
||||
|
||||
export default function CircleZoneSelector({zoneSettings, modifyZoneSettings, applyZoneSettings}) {
|
||||
const {outOfZoneDelay, updateSettings} = useAdmin();
|
||||
export default function CircleZoneSelector() {
|
||||
const {zoneSettings, outOfZoneDelay, updateSettings} = useAdmin();
|
||||
const [localZoneSettings, setLocalZoneSettings, applyLocalZoneSettings] = useLocalVariable(zoneSettings, (e) => updateSettings({zone: e}));
|
||||
const [localOutOfZoneDelay, setLocalOutOfZoneDelay, applyLocalOutOfZoneDelay] = useLocalVariable(outOfZoneDelay, (e) => updateSettings({outOfZoneDelay: e}));
|
||||
const [editMode, setEditMode] = useState(EditMode.MIN);
|
||||
|
||||
useEffect(() => {
|
||||
setEditMode(editMode == EditMode.MIN ? EditMode.MAX : EditMode.MIN);
|
||||
}, [zoneSettings.min, zoneSettings.max]);
|
||||
if (localZoneSettings.type != ZoneTypes.CIRCLE) {
|
||||
setLocalZoneSettings(defaultZoneSettings.circle);
|
||||
}
|
||||
}, [localZoneSettings]);
|
||||
|
||||
function handleSettingsSubmit() {
|
||||
applyZoneSettings();
|
||||
useEffect(() => {
|
||||
setEditMode(editMode == EditMode.MIN ? EditMode.MAX : EditMode.MIN);
|
||||
}, [localZoneSettings.min, localZoneSettings.max]);
|
||||
|
||||
function setMinZone(minZone) {
|
||||
setLocalZoneSettings({...localZoneSettings, min: minZone});
|
||||
}
|
||||
|
||||
function setMaxZone(maxZone) {
|
||||
setLocalZoneSettings({...localZoneSettings, max: maxZone});
|
||||
}
|
||||
|
||||
function updateReductionCount(reductionCount) {
|
||||
setLocalZoneSettings({...localZoneSettings, reductionCount: reductionCount});
|
||||
}
|
||||
|
||||
function updateDuration(duration) {
|
||||
setLocalZoneSettings({...localZoneSettings, duration: duration});
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
applyLocalZoneSettings();
|
||||
applyLocalOutOfZoneDelay();
|
||||
}
|
||||
|
||||
@@ -48,38 +73,40 @@ export default function CircleZoneSelector({zoneSettings, modifyZoneSettings, ap
|
||||
|
||||
return (
|
||||
<div className='h-full w-full gap-3 flex flex-row'>
|
||||
<div className="h-full flex-1">
|
||||
<CustomMapContainer>
|
||||
<Drawings minZone={zoneSettings.min} setMinZone={(e) => modifyZoneSettings("min", e)} maxZone={zoneSettings.max} setMaxZone={(e) => modifyZoneSettings("max", e)} editMode={editMode} />
|
||||
</CustomMapContainer>
|
||||
</div>
|
||||
<div className="h-full w-1/6 flex flex-col gap-3">
|
||||
<div className="w-full h-15">
|
||||
{editMode == EditMode.MIN && <CustomButton color="blue" onClick={() => setEditMode(EditMode.MAX)}>Click to edit first zone</CustomButton>}
|
||||
{editMode == EditMode.MAX && <CustomButton color="red" onClick={() => setEditMode(EditMode.MIN)}>Click to edit last zone</CustomButton>}
|
||||
{localZoneSettings.type == ZoneTypes.CIRCLE && <>
|
||||
<div className="h-full flex-1">
|
||||
<CustomMapContainer>
|
||||
<Drawings minZone={localZoneSettings.min} setMinZone={setMinZone} maxZone={localZoneSettings.max} setMaxZone={setMaxZone} editMode={editMode} />
|
||||
</CustomMapContainer>
|
||||
</div>
|
||||
<div className="w-full flex flex-row gap-2 items-center justify-between">
|
||||
<p>Reduction number</p>
|
||||
<div className="w-16 h-10">
|
||||
<TextInput id="reduction-number" value={zoneSettings?.reductionCount ?? ""} onChange={(e) => modifyZoneSettings("reductionCount", customStringToInt(e.target.value))} />
|
||||
<div className="h-full w-1/6 flex flex-col gap-3">
|
||||
<div className="w-full h-15">
|
||||
{editMode == EditMode.MIN && <CustomButton color="blue" onClick={() => setEditMode(EditMode.MAX)}>Click to edit first zone</CustomButton>}
|
||||
{editMode == EditMode.MAX && <CustomButton color="red" onClick={() => setEditMode(EditMode.MIN)}>Click to edit last zone</CustomButton>}
|
||||
</div>
|
||||
<div className="w-full flex flex-row gap-2 items-center justify-between">
|
||||
<p>Reduction number</p>
|
||||
<div className="w-16 h-10">
|
||||
<TextInput id="reduction-number" value={localZoneSettings.reductionCount ?? ""} onChange={(e) => updateReductionCount(customStringToInt(e.target.value))} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-full flex flex-row gap-2 items-center justify-between">
|
||||
<p>Zone duration</p>
|
||||
<div className="w-16 h-10">
|
||||
<TextInput id="duration" value={localZoneSettings.duration ?? ""} onChange={(e) => updateDuration(customStringToInt(e.target.value))} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-full flex flex-row gap-2 items-center justify-between">
|
||||
<p>Timeout</p>
|
||||
<div className="w-16 h-10">
|
||||
<TextInput id="timeout" value={localOutOfZoneDelay ?? ""} onChange={(e) => setLocalOutOfZoneDelay(customStringToInt(e.target.value))} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-full h-15">
|
||||
<CustomButton color="green" onClick={handleSubmit}>Apply</CustomButton>
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-full flex flex-row gap-2 items-center justify-between">
|
||||
<p>Zone duration</p>
|
||||
<div className="w-16 h-10">
|
||||
<TextInput id="duration" value={zoneSettings?.duration ?? ""} onChange={(e) => modifyZoneSettings("duration", customStringToInt(e.target.value))} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-full flex flex-row gap-2 items-center justify-between">
|
||||
<p>Timeout</p>
|
||||
<div className="w-16 h-10">
|
||||
<TextInput id="timeout" value={localOutOfZoneDelay ?? ""} onChange={(e) => setLocalOutOfZoneDelay(customStringToInt(e.target.value))} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-full h-15">
|
||||
<CustomButton color="green" onClick={handleSettingsSubmit}>Apply</CustomButton>
|
||||
</div>
|
||||
</div>
|
||||
</>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Circle, Tooltip } from "react-leaflet";
|
||||
import { List } from "@/components/list";
|
||||
import { CustomMapContainer, MapEventListener } from "@/components/map";
|
||||
import useAdmin from '@/hook/useAdmin';
|
||||
import useMultipleCircleDraw from "@/hook/useMultipleCircleDraw";
|
||||
|
||||
function Drawings({ placementZones, addZone, removeZone, handleRightClick }) {
|
||||
const { handleLeftClick, handleRightClick: handleRightClickDrawing } = useMultipleCircleDraw(placementZones, addZone, removeZone, 30);
|
||||
|
||||
function modifiedHandleRightClick(e) {
|
||||
handleRightClickDrawing(e);
|
||||
handleRightClick();
|
||||
}
|
||||
|
||||
return (<>
|
||||
<MapEventListener onLeftClick={handleLeftClick} onRightClick={modifiedHandleRightClick} />
|
||||
{ placementZones.map(placementZone =>
|
||||
<Circle key={placementZone.id} center={placementZone.center} radius={placementZone.radius} color="blue" fillColor="blue">
|
||||
<Tooltip permanent direction="top" offset={[0.5, -15]} className="custom-tooltip">{placementZone.name}</Tooltip>
|
||||
</Circle>
|
||||
)}
|
||||
</>);
|
||||
}
|
||||
|
||||
export default function PlacementZoneSelector() {
|
||||
const { teams, getTeam, placementTeam } = useAdmin();
|
||||
const [selectedTeamId, setSelectedTeamId] = useState(null);
|
||||
const [placementZones, setPlacementZones] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
setPlacementZones(teams.filter(team => team.startingArea).map(team => ({id: team.id, name: team.name, center: team.startingArea.center, radius: team.startingArea.radius})));
|
||||
}, [teams]);
|
||||
|
||||
function addPlacementZone(center, radius) {
|
||||
if (!selectedTeamId) return;
|
||||
const placementZonesFiltered = placementZones.filter(placementZone => placementZone.id !== selectedTeamId);
|
||||
const newZone = {id: selectedTeamId, name: getTeam(selectedTeamId).name, center: center, radius: radius};
|
||||
placementTeam(selectedTeamId, newZone);
|
||||
setPlacementZones([...placementZonesFiltered, newZone]);
|
||||
}
|
||||
|
||||
function removePlacementZone(id) {
|
||||
placementTeam(id, null);
|
||||
setPlacementZones(placementZones.filter((placementZone) => placementZone.id !== id));
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='w-full h-full gap-3 flex flex-row'>
|
||||
<div className="h-full flex-1">
|
||||
<CustomMapContainer>
|
||||
<Drawings placementZones={placementZones} addZone={addPlacementZone} removeZone={removePlacementZone} handleRightClick={() => setSelectedTeamId(null)} />
|
||||
</CustomMapContainer>
|
||||
</div>
|
||||
<div className="h-full w-1/6 flex flex-col gap-3">
|
||||
<div className="w-full text-center">
|
||||
<h2 className="text-xl">Teams</h2>
|
||||
</div>
|
||||
<List array={teams} selectedId={selectedTeamId} onSelected={(id) => setSelectedTeamId(selectedTeamId != id ? id : null)}>
|
||||
{ (team) =>
|
||||
<div className="w-full flex flex-row items-center justify-between gap-2 p-2 bg-white">
|
||||
<p className='text-xl font-bold'>{team.name}</p>
|
||||
</div>
|
||||
}
|
||||
</List>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { useState } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import { ZoneTypes } from "@/util/types";
|
||||
|
||||
// Imported at runtime and not at compile time
|
||||
const CircleZoneSelector = dynamic(() => import('./circleZoneSelector'), { ssr: false });
|
||||
const PolygonZoneSelector = dynamic(() => import('./polygonZoneSelector'), { ssr: false });
|
||||
|
||||
function ZoneTypeButton({title, onClick, isSelected}) {
|
||||
const grayStyle = "bg-gray-300 hover:bg-gray-400";
|
||||
const blueStyle = "bg-custom-light-blue";
|
||||
|
||||
return (
|
||||
<div className={`flex justify-center items-center rounded-md cursor-pointer ${isSelected ? blueStyle : grayStyle}`} onClick={onClick}>
|
||||
<p className="text-l font-bold p-2">{title}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function PlayingZoneSelector() {
|
||||
const [zoneType, setZoneType] = useState(ZoneTypes.POLYGON);
|
||||
|
||||
return (
|
||||
<div className="w-full h-full flex flex-col gap-3">
|
||||
<div className="w-full flex flex-row gap-3 items-center">
|
||||
<p className="text-l">Type de zone :</p>
|
||||
<ZoneTypeButton title="Cercles" onClick={() => setZoneType(ZoneTypes.CIRCLE)} isSelected={zoneType == ZoneTypes.CIRCLE} />
|
||||
<ZoneTypeButton title="Polygones" onClick={() => setZoneType(ZoneTypes.POLYGON)} isSelected={zoneType == ZoneTypes.POLYGON} />
|
||||
</div>
|
||||
<div className="w-full flex-1">
|
||||
{zoneType == ZoneTypes.CIRCLE &&
|
||||
<CircleZoneSelector/>
|
||||
}
|
||||
{zoneType == ZoneTypes.POLYGON &&
|
||||
<PolygonZoneSelector/>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -7,15 +7,24 @@ import { CustomMapContainer, MapEventListener } from "@/components/map";
|
||||
import { TextInput } from "@/components/input";
|
||||
import { Node, LabeledPolygon } from "@/components/layer";
|
||||
import useAdmin from "@/hook/useAdmin";
|
||||
import useMapPolygonDraw from "@/hook/useMapPolygonDraw";
|
||||
import useMapPolygonDraw from "@/hook/usePolygonDraw";
|
||||
import useLocalVariable from "@/hook/useLocalVariable";
|
||||
import { defaultZoneSettings } from "@/util/configurations";
|
||||
import { ZoneTypes } from "@/util/types";
|
||||
|
||||
function Drawings({ polygons, addPolygon, removePolygon }) {
|
||||
const { currentPolygon, highlightNodes, handleLeftClick, handleRightClick, handleMouseMove } = useMapPolygonDraw(polygons, addPolygon, removePolygon);
|
||||
function Drawings({ localZoneSettings, addZone, removeZone }) {
|
||||
const [polygons, setPolygons] = useState([]);
|
||||
const { currentPolygon, highlightNodes, handleLeftClick, handleRightClick, handleMouseMove } = useMapPolygonDraw(polygons, addZone, removeZone);
|
||||
|
||||
useEffect(() => {
|
||||
if (localZoneSettings.type == ZoneTypes.POLYGON) {
|
||||
setPolygons(localZoneSettings.polygons.map(zone => zone.polygon));
|
||||
}
|
||||
}, [localZoneSettings]);
|
||||
|
||||
return (<>
|
||||
<MapEventListener onLeftClick={handleLeftClick} onRightClick={handleRightClick} onMouseMove={handleMouseMove} />
|
||||
{polygons.map((polygon, i) => <LabeledPolygon key={i} polygon={polygon} number={i+1} />)}
|
||||
{localZoneSettings.polygons.map((zone, i) => <LabeledPolygon key={i} polygon={zone.polygon} label={zone.id} />)}
|
||||
{ currentPolygon.length > 0 && <>
|
||||
<Node pos={currentPolygon[0]} color={"red"} />
|
||||
<Polyline positions={currentPolygon} pathOptions={{ color: "red", weight: 3 }} />
|
||||
@@ -24,73 +33,87 @@ function Drawings({ polygons, addPolygon, removePolygon }) {
|
||||
</>);
|
||||
}
|
||||
|
||||
export default function PolygonZoneSelector({zoneSettings, modifyZoneSettings, applyZoneSettings}) {
|
||||
export default function PolygonZoneSelector() {
|
||||
const defaultDuration = 10;
|
||||
const [polygons, setPolygons] = useState([]);
|
||||
const {outOfZoneDelay, updateSettings} = useAdmin();
|
||||
const {zoneSettings, outOfZoneDelay, updateSettings} = useAdmin();
|
||||
const [localZoneSettings, setLocalZoneSettings, applyLocalZoneSettings] = useLocalVariable(zoneSettings, (e) => updateSettings({zone: e}));
|
||||
const [localOutOfZoneDelay, setLocalOutOfZoneDelay, applyLocalOutOfZoneDelay] = useLocalVariable(outOfZoneDelay, (e) => updateSettings({outOfZoneDelay: e}));
|
||||
|
||||
useEffect(() => {
|
||||
if (zoneSettings) {
|
||||
setPolygons(zoneSettings.polygons.map((zone) => zone.polygon));
|
||||
if (localZoneSettings.type != ZoneTypes.POLYGON) {
|
||||
setLocalZoneSettings(defaultZoneSettings.polygon);
|
||||
}
|
||||
}, [zoneSettings]);
|
||||
}, [localZoneSettings]);
|
||||
|
||||
function idFromPolygon(polygon) {
|
||||
return (polygon[0].lat + polygon[1].lat + polygon[2].lat).toString() + (polygon[0].lng + polygon[1].lng + polygon[2].lng).toString();
|
||||
function getNewPolygonName() {
|
||||
const existingIds = new Set(localZoneSettings.polygons.map(zone => zone.id));
|
||||
for (let i = 0; i < 26; i++) {
|
||||
const letter = String.fromCharCode(65 + i);
|
||||
if (!existingIds.has(letter)) {
|
||||
return letter;
|
||||
}
|
||||
}
|
||||
return "XXX";
|
||||
}
|
||||
|
||||
function addPolygon(polygon) {
|
||||
const newPolygons = [...zoneSettings.polygons, {id: idFromPolygon(polygon), polygon: polygon, duration: defaultDuration}];
|
||||
modifyZoneSettings("polygons", newPolygons);
|
||||
function setLocalZoneSettingsPolygons(polygons) {
|
||||
setLocalZoneSettings({type: localZoneSettings.type, polygons: polygons});
|
||||
}
|
||||
|
||||
function removePolygon(i) {
|
||||
const newPolygons = zoneSettings.polygons.filter((_, index) => index !== i);
|
||||
modifyZoneSettings("polygons", newPolygons);
|
||||
function addZone(polygon) {
|
||||
setLocalZoneSettingsPolygons([...localZoneSettings.polygons, {id: getNewPolygonName(), polygon: polygon, duration: defaultDuration}]);
|
||||
}
|
||||
|
||||
function updateDuration(i, duration) {
|
||||
const newPolygons = zoneSettings.polygons.map((zone, index) => index === i ? {id: zone.id, polygon: zone.polygon, duration: duration} : zone);
|
||||
modifyZoneSettings("polygons", newPolygons);
|
||||
function removeZone(i) {
|
||||
setLocalZoneSettingsPolygons(localZoneSettings.polygons.filter((_, index) => index !== i));
|
||||
}
|
||||
|
||||
function handleSettingsSubmit() {
|
||||
applyZoneSettings();
|
||||
function updateDuration(id, duration) {
|
||||
setLocalZoneSettingsPolygons(localZoneSettings.polygons.map(zone => zone.id === id ? {...zone, duration: duration} : zone));
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
applyLocalZoneSettings();
|
||||
applyLocalOutOfZoneDelay();
|
||||
}
|
||||
|
||||
function customStringToInt(e) {
|
||||
return parseInt(e, 10) || null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='h-full w-full gap-3 flex flex-row'>
|
||||
<div className="h-full flex-1">
|
||||
<CustomMapContainer>
|
||||
<Drawings polygons={polygons} addPolygon={addPolygon} removePolygon={removePolygon} />
|
||||
</CustomMapContainer>
|
||||
</div>
|
||||
<div className="h-full w-1/6 flex flex-col gap-3">
|
||||
<div className="w-full text-center">
|
||||
<h2 className="text-xl">Reduction order</h2>
|
||||
{localZoneSettings.type == ZoneTypes.POLYGON && <>
|
||||
<div className="h-full flex-1">
|
||||
<CustomMapContainer>
|
||||
<Drawings localZoneSettings={localZoneSettings} addZone={addZone} removeZone={removeZone} />
|
||||
</CustomMapContainer>
|
||||
</div>
|
||||
<ReorderList droppableId="zones-order" array={zoneSettings.polygons} setArray={(polygons) => modifyZoneSettings("polygons", polygons)}>
|
||||
{ (zone, i) =>
|
||||
<div className="w-full p-2 bg-white flex flex-row gap-2 items-center justify-between">
|
||||
<p>Zone {i+1}</p>
|
||||
<div className="w-16 h-10">
|
||||
<TextInput value={zone?.duration || ""} onChange={(e) => updateDuration(i, parseInt(e.target.value, 10))}/>
|
||||
<div className="h-full w-1/6 flex flex-col gap-3">
|
||||
<div className="w-full text-center">
|
||||
<h2 className="text-xl">Reduction order</h2>
|
||||
</div>
|
||||
<ReorderList droppableId="zones-order" array={localZoneSettings.polygons} setArray={setLocalZoneSettingsPolygons}>
|
||||
{ (zone) =>
|
||||
<div className="w-full p-2 bg-white flex flex-row gap-2 items-center justify-between">
|
||||
<p>Zone {zone.id}</p>
|
||||
<div className="w-16 h-10">
|
||||
<TextInput value={zone.duration || ""} onChange={(e) => updateDuration(zone.id, customStringToInt(e.target.value))}/>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</ReorderList>
|
||||
<div className="w-full flex flex-row gap-2 items-center justify-between">
|
||||
<p>Timeout</p>
|
||||
<div className="w-16 h-10">
|
||||
<TextInput id="timeout" value={localOutOfZoneDelay ?? ""} onChange={(e) => setLocalOutOfZoneDelay(customStringToInt(e.target.value))}/>
|
||||
</div>
|
||||
}
|
||||
</ReorderList>
|
||||
<div className="w-full flex flex-row gap-2 items-center justify-between">
|
||||
<p>Timeout</p>
|
||||
<div className="w-16 h-10">
|
||||
<TextInput id="timeout" value={localOutOfZoneDelay ?? ""} onChange={(e) => setLocalOutOfZoneDelay(parseInt(e.target.value, 10))} />
|
||||
</div>
|
||||
<div className="w-full h-15">
|
||||
<CustomButton color="green" onClick={handleSubmit}>Apply</CustomButton>
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-full h-15">
|
||||
<CustomButton color="green" onClick={handleSettingsSubmit}>Apply</CustomButton>
|
||||
</div>
|
||||
</div>
|
||||
</>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,31 +1,61 @@
|
||||
import { useState } from "react";
|
||||
import { ReorderList } from '@/components/list';
|
||||
import useAdmin from '@/hook/useAdmin';
|
||||
import useLocalVariable from "@/hook/useLocalVariable";
|
||||
import { TextInput } from "@/components/input";
|
||||
import { Section } from "@/components/section";
|
||||
|
||||
function TeamManagerItem({ team }) {
|
||||
const { captureTeam, removeTeam } = useAdmin();
|
||||
|
||||
return (
|
||||
<div className='w-full p-2 bg-white flex flex-row items-center text-xl gap-3 font-bold'>
|
||||
<div className='flex-1 w-full h-full flex flex-row items-center justify-between'>
|
||||
<p>{team.name}</p>
|
||||
<div className='flex flex-row items-center justify-between gap-3'>
|
||||
<p>{String(team.id).padStart(6, '0').replace(/(\d{3})(\d{3})/, "$1 $2")}</p>
|
||||
<img src={`/icons/heart/${team.captured ? "grey" : "pink"}.png`} className="w-8 h-8" onClick={() => captureTeam(team.id)} />
|
||||
<img src="/icons/trash.png" className="w-8 h-8" onClick={() => removeTeam(team.id)} />
|
||||
</div>
|
||||
<div className='w-full flex flex-row items-center justify-between p-2 gap-3 bg-white'>
|
||||
<p className='text-xl font-bold'>{team.name}</p>
|
||||
<div className='flex flex-row items-center justify-between gap-3'>
|
||||
<p className='text-xl font-bold'>{String(team.id).padStart(6, '0').replace(/(\d{3})(\d{3})/, "$1 $2")}</p>
|
||||
<img src={`/icons/heart/${team.captured ? "grey" : "pink"}.png`} className="w-8 h-8 cursor-pointer" onClick={() => captureTeam(team.id)} />
|
||||
<img src="/icons/trash.png" className="w-8 h-8 cursor-pointer" onClick={() => removeTeam(team.id)} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function TeamManager() {
|
||||
const { teams, reorderTeams } = useAdmin();
|
||||
const { teams, addTeam, reorderTeams, sendPositionDelay, updateSettings } = useAdmin();
|
||||
const [teamName, setTeamName] = useState('');
|
||||
const [localSendPositionDelay, setLocalSendPositionDelay, applyLocalSendPositionDelay] = useLocalVariable(sendPositionDelay, (e) => updateSettings({sendPositionDelay: e}));
|
||||
|
||||
function handleTeamSubmit(e) {
|
||||
e.preventDefault();
|
||||
if (teamName !== "") {
|
||||
addTeam(teamName);
|
||||
setTeamName("")
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<ReorderList droppableId="team-manager" array={teams} setArray={(teams) => reorderTeams(teams.map(team => team.id))}>
|
||||
{(team) => (
|
||||
<TeamManagerItem team={team}/>
|
||||
)}
|
||||
</ReorderList>
|
||||
<Section title="Équipe" outerClassName="flex-1 min-h-0" innerClassName="flex flex-col items-center gap-3">
|
||||
<form className='w-full flex flex-row gap-3' onSubmit={handleTeamSubmit}>
|
||||
<div className='w-full'>
|
||||
<input name="teamName" label='Team name' value={teamName} onChange={(e) => setTeamName(e.target.value)} type="text" className="w-full h-full p-4 ring-1 ring-inset ring-gray-300" />
|
||||
</div>
|
||||
<div className='w-1/5'>
|
||||
<button type="submit" className="w-full h-full bg-custom-light-blue hover:bg-blue-500 transition text-3xl font-bold">+</button>
|
||||
</div>
|
||||
</form>
|
||||
<div className="w-full flex-1 min-h-0 ">
|
||||
<ReorderList droppableId="team-manager" array={teams} setArray={(teams) => reorderTeams(teams.map(team => team.id))}>
|
||||
{(team) => (
|
||||
<TeamManagerItem team={team}/>
|
||||
)}
|
||||
</ReorderList>
|
||||
</div>
|
||||
<div className="w-full flex flex-row gap-2 items-center justify-between">
|
||||
<p>Interval between position updates</p>
|
||||
<div className="w-16 h-10">
|
||||
<TextInput id="position-update" value={localSendPositionDelay ?? ""} onChange={(e) => setLocalSendPositionDelay(parseInt(e.target.value, 10))} onBlur={applyLocalSendPositionDelay} />
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,87 +2,66 @@
|
||||
import { useState } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import Link from "next/link";
|
||||
import { TextInput } from "@/components/input";
|
||||
import { Section } from "@/components/section";
|
||||
import { CustomButton } from "@/components/button";
|
||||
import { useAdminConnexion } from "@/context/adminConnexionContext";
|
||||
import useAdmin from '@/hook/useAdmin';
|
||||
import Messages from "./components/messages";
|
||||
import TeamManager from './components/teamManager';
|
||||
import useLocalVariable from "@/hook/useLocalVariable";
|
||||
import { ZoneTypes } from "@/util/types";
|
||||
import { defaultZoneSettings } from "@/util/configurations";
|
||||
import PlayingZoneSelector from "./components/playingZoneSelector";
|
||||
|
||||
// Imported at runtime and not at compile time
|
||||
const CircleZoneSelector = dynamic(() => import('./components/circleZoneSelector'), { ssr: false });
|
||||
const PolygonZoneSelector = dynamic(() => import('./components/polygonZoneSelector'), { ssr: false });
|
||||
const PlacementZoneSelector = dynamic(() => import('./components/placementZoneSelector'), { ssr: false });
|
||||
|
||||
const Tabs = {
|
||||
PLACEMENT_ZONES: "placement_zones",
|
||||
PLAYING_ZONES: "playing_zones",
|
||||
}
|
||||
|
||||
function ParametersTitle() {
|
||||
return (
|
||||
<div className='w-full bg-custom-light-blue gap-5 p-5 flex flex-row shadow-2xl'>
|
||||
<Link href="/admin">
|
||||
<img src="/icons/backarrow.png" className="w-8 h-8" title="Main page" />
|
||||
</Link>
|
||||
<h2 className="text-3xl font-bold">Paramètres</h2>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TabButton({title, onClick, isSelected}) {
|
||||
const grayStyle = "bg-gray-300 hover:bg-gray-400";
|
||||
const blueStyle = "bg-custom-light-blue";
|
||||
|
||||
return (
|
||||
<div className={`flex-1 h-full flex justify-center items-center cursor-pointer ${isSelected ? blueStyle : grayStyle}`} onClick={onClick}>
|
||||
<p className="text-2xl font-bold">{title}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function ConfigurationPage() {
|
||||
const { useProtect } = useAdminConnexion();
|
||||
const {zoneSettings, sendPositionDelay, updateSettings, addTeam} = useAdmin();
|
||||
const [teamName, setTeamName] = useState('');
|
||||
const [localZoneSettings, setLocalZoneSettings, applyLocalZoneSettings] = useLocalVariable(zoneSettings, (e) => updateSettings({zone: e}));
|
||||
const [localSendPositionDelay, setLocalSendPositionDelay, applyLocalSendPositionDelay] = useLocalVariable(sendPositionDelay, (e) => updateSettings({sendPositionDelay: e}));
|
||||
const [currentTab, setCurrentTab] = useState(Tabs.PLACEMENT_ZONES);
|
||||
|
||||
useProtect();
|
||||
|
||||
function modifyLocalZoneSettings(key, value) {
|
||||
setLocalZoneSettings(prev => ({...prev, [key]: value}));
|
||||
}
|
||||
|
||||
function handleChangeZoneType() {
|
||||
setLocalZoneSettings(localZoneSettings.type == ZoneTypes.CIRCLE ? defaultZoneSettings.polygon : defaultZoneSettings.circle)
|
||||
}
|
||||
|
||||
function handleTeamSubmit(e) {
|
||||
e.preventDefault();
|
||||
if (teamName !== "") {
|
||||
addTeam(teamName);
|
||||
setTeamName("")
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='h-full bg-gray-200 p-3 flex flex-row gap-3'>
|
||||
<div className="h-full w-2/6 gap-3 flex flex-col">
|
||||
<div className='w-full bg-custom-light-blue gap-5 p-5 flex flex-row shadow-2xl'>
|
||||
<Link href="/admin">
|
||||
<img src="/icons/backarrow.png" className="w-8 h-8" title="Main page" />
|
||||
</Link>
|
||||
<h2 className="text-3xl font-bold">Paramètres</h2>
|
||||
</div>
|
||||
<ParametersTitle/>
|
||||
<Messages/>
|
||||
<Section title="Équipe" outerClassName="flex-1 min-h-0" innerClassName="flex flex-col items-center gap-3">
|
||||
<form className='w-full flex flex-row gap-3' onSubmit={handleTeamSubmit}>
|
||||
<div className='w-full'>
|
||||
<input name="teamName" label='Team name' value={teamName} onChange={(e) => setTeamName(e.target.value)} type="text" className="w-full h-full p-4 ring-1 ring-inset ring-gray-300" />
|
||||
</div>
|
||||
<div className='w-1/5'>
|
||||
<button type="submit" className="w-full h-full bg-custom-light-blue hover:bg-blue-500 transition text-3xl font-bold">+</button>
|
||||
</div>
|
||||
</form>
|
||||
<div className="w-full flex-1 min-h-0 ">
|
||||
<TeamManager/>
|
||||
</div>
|
||||
<div className="w-full flex flex-row gap-2 items-center justify-between">
|
||||
<p>Interval between position updates</p>
|
||||
<div className="w-16 h-10">
|
||||
<TextInput id="position-update" value={localSendPositionDelay ?? ""} onChange={(e) => setLocalSendPositionDelay(parseInt(e.target.value, 10))} onBlur={applyLocalSendPositionDelay} />
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
<TeamManager/>
|
||||
</div>
|
||||
<div className="h-full flex-1 flex flex-col p-3 gap-3 bg-white shadow-2xl">
|
||||
<div className="w-full h-15">
|
||||
{localZoneSettings && <CustomButton color="blue" onClick={handleChangeZoneType}>Change zone type</CustomButton>}
|
||||
<div className="h-full flex-1 flex flex-col bg-white shadow-2xl">
|
||||
<div className="w-full h-20 flex flex-row bg-gray-300">
|
||||
<TabButton title="Zones de placement" onClick={() => setCurrentTab(Tabs.PLACEMENT_ZONES)} isSelected={currentTab == Tabs.PLACEMENT_ZONES}/>
|
||||
<TabButton title="Zones de jeu" onClick={() => setCurrentTab(Tabs.PLAYING_ZONES)} isSelected={currentTab == Tabs.PLAYING_ZONES}/>
|
||||
</div>
|
||||
<div className="w-full flex-1">
|
||||
{localZoneSettings && localZoneSettings.type == ZoneTypes.CIRCLE &&
|
||||
<CircleZoneSelector zoneSettings={localZoneSettings} modifyZoneSettings={modifyLocalZoneSettings} applyZoneSettings={applyLocalZoneSettings}/>
|
||||
}
|
||||
{localZoneSettings && localZoneSettings.type == ZoneTypes.POLYGON &&
|
||||
<PolygonZoneSelector zoneSettings={localZoneSettings} modifyZoneSettings={modifyLocalZoneSettings} applyZoneSettings={applyLocalZoneSettings}/>
|
||||
}
|
||||
<div className="w-full flex-1 p-3 bg-white">
|
||||
{ currentTab == Tabs.PLAYING_ZONES &&
|
||||
<PlayingZoneSelector />
|
||||
}
|
||||
{ currentTab == Tabs.PLACEMENT_ZONES &&
|
||||
<PlacementZoneSelector />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user