Added map fog permissions

This commit is contained in:
Mitchell McCaffrey 2020-04-29 21:12:57 +10:00
parent aeb33058bb
commit 4b9b06395d
4 changed files with 32 additions and 4 deletions

View File

@ -29,7 +29,8 @@ function Map({
onFogDraw, onFogDraw,
onMapUndo, onMapUndo,
onMapRedo, onMapRedo,
allowDrawing, allowMapDrawing,
allowFogDrawing,
allowTokenChange, allowTokenChange,
allowMapChange, allowMapChange,
}) { }) {
@ -139,7 +140,7 @@ function Map({
if (!allowMapChange) { if (!allowMapChange) {
disabledControls.push("map"); disabledControls.push("map");
} }
if (!allowDrawing) { if (!allowMapDrawing) {
disabledControls.push("drawing"); disabledControls.push("drawing");
} }
if (!map) { if (!map) {
@ -152,6 +153,9 @@ function Map({
if (!mapState || mapState.mapDrawActionIndex < 0) { if (!mapState || mapState.mapDrawActionIndex < 0) {
disabledControls.push("undo"); disabledControls.push("undo");
} }
if (!allowFogDrawing) {
disabledControls.push("fog");
}
if ( if (
!mapState || !mapState ||
mapState.mapDrawActionIndex === mapState.mapDrawActions.length - 1 mapState.mapDrawActionIndex === mapState.mapDrawActions.length - 1
@ -266,7 +270,7 @@ function Map({
map={map} map={map}
aspectRatio={aspectRatio} aspectRatio={aspectRatio}
isEnabled={selectedToolId === "pan"} isEnabled={selectedToolId === "pan"}
controls={(allowMapChange || allowDrawing) && mapControls} controls={(allowMapChange || allowMapDrawing) && mapControls}
> >
{map && mapImage} {map && mapImage}
{map && mapDrawing} {map && mapDrawing}

View File

@ -202,6 +202,13 @@ function MapContols({
} }
} }
// Move back to pan tool if selected tool becomes disabled
useEffect(() => {
if (disabledControls.includes(selectedToolId)) {
onSelectedToolChange("pan");
}
}, [disabledControls]);
// Stop map drawing from happening when selecting controls // Stop map drawing from happening when selecting controls
// Not using react events as they seem to trigger after dom events // Not using react events as they seem to trigger after dom events
useEffect(() => { useEffect(() => {

View File

@ -59,6 +59,16 @@ function MapSettings({
<Box mt={2} sx={{ flexGrow: 1 }}> <Box mt={2} sx={{ flexGrow: 1 }}>
<Label>Allow others to edit</Label> <Label>Allow others to edit</Label>
<Flex my={1}> <Flex my={1}>
<Label>
<Checkbox
checked={
mapState !== null && mapState.editFlags.includes("fog")
}
disabled={mapState === null}
onChange={(e) => handleFlagChange(e, "fog")}
/>
Fog
</Label>
<Label> <Label>
<Checkbox <Checkbox
checked={ checked={

View File

@ -44,6 +44,7 @@ function Game() {
const [map, setMap] = useState(null); const [map, setMap] = useState(null);
const [mapState, setMapState] = useState(null); const [mapState, setMapState] = useState(null);
// TODO: move into map, consider removing map lockdown
const canChangeMap = const canChangeMap =
map === null || map === null ||
(map !== null && (map !== null &&
@ -55,6 +56,11 @@ function Game() {
mapState !== null && mapState !== null &&
(mapState.editFlags.includes("drawings") || map.owner === userId); (mapState.editFlags.includes("drawings") || map.owner === userId);
const canEditFogDrawing =
map !== null &&
mapState !== null &&
(mapState.editFlags.includes("fog") || map.owner === userId);
const canEditTokens = const canEditTokens =
map !== null && map !== null &&
mapState !== null && mapState !== null &&
@ -416,7 +422,8 @@ function Game() {
onMapUndo={handleMapUndo} onMapUndo={handleMapUndo}
onMapRedo={handleMapRedo} onMapRedo={handleMapRedo}
onFogDraw={handleFogDraw} onFogDraw={handleFogDraw}
allowDrawing={canEditMapDrawings} allowMapDrawing={canEditMapDrawings}
allowFogDrawing={canEditFogDrawing}
allowTokenChange={canEditTokens} allowTokenChange={canEditTokens}
allowMapChange={canChangeMap} allowMapChange={canChangeMap}
/> />