Add toasts for unable to draw fog errors
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { Box } from "theme-ui";
|
import { Box } from "theme-ui";
|
||||||
|
import { useToasts } from "react-toast-notifications";
|
||||||
|
|
||||||
import MapControls from "./MapControls";
|
import MapControls from "./MapControls";
|
||||||
import MapInteraction from "./MapInteraction";
|
import MapInteraction from "./MapInteraction";
|
||||||
@@ -49,6 +50,8 @@ function Map({
|
|||||||
disabledTokens,
|
disabledTokens,
|
||||||
session,
|
session,
|
||||||
}) {
|
}) {
|
||||||
|
const { addToast } = useToasts();
|
||||||
|
|
||||||
const { tokensById } = useTokenData();
|
const { tokensById } = useTokenData();
|
||||||
|
|
||||||
const [selectedToolId, setSelectedToolId] = useState("move");
|
const [selectedToolId, setSelectedToolId] = useState("move");
|
||||||
@@ -232,6 +235,7 @@ function Map({
|
|||||||
onShapesCut={handleFogShapesCut}
|
onShapesCut={handleFogShapesCut}
|
||||||
onShapesRemove={handleFogShapesRemove}
|
onShapesRemove={handleFogShapesRemove}
|
||||||
onShapesEdit={handleFogShapesEdit}
|
onShapesEdit={handleFogShapesEdit}
|
||||||
|
onShapeError={addToast}
|
||||||
active={selectedToolId === "fog"}
|
active={selectedToolId === "fog"}
|
||||||
toolSettings={settings.fog}
|
toolSettings={settings.fog}
|
||||||
editable={allowFogDrawing && !settings.fog.preview}
|
editable={allowFogDrawing && !settings.fog.preview}
|
||||||
|
|||||||
@@ -38,8 +38,10 @@ import {
|
|||||||
Tick,
|
Tick,
|
||||||
getRelativePointerPosition,
|
getRelativePointerPosition,
|
||||||
} from "../../helpers/konva";
|
} from "../../helpers/konva";
|
||||||
|
import { keyBy } from "../../helpers/shared";
|
||||||
|
|
||||||
import SubtractShapeAction from "../../actions/SubtractShapeAction";
|
import SubtractShapeAction from "../../actions/SubtractShapeAction";
|
||||||
|
import CutShapeAction from "../../actions/CutShapeAction";
|
||||||
|
|
||||||
import useSetting from "../../hooks/useSetting";
|
import useSetting from "../../hooks/useSetting";
|
||||||
|
|
||||||
@@ -52,6 +54,7 @@ function MapFog({
|
|||||||
onShapesCut,
|
onShapesCut,
|
||||||
onShapesRemove,
|
onShapesRemove,
|
||||||
onShapesEdit,
|
onShapesEdit,
|
||||||
|
onShapeError,
|
||||||
active,
|
active,
|
||||||
toolSettings,
|
toolSettings,
|
||||||
editable,
|
editable,
|
||||||
@@ -214,6 +217,8 @@ function MapFog({
|
|||||||
) {
|
) {
|
||||||
const cut = toolSettings.useFogCut;
|
const cut = toolSettings.useFogCut;
|
||||||
let drawingShapes = [drawingShape];
|
let drawingShapes = [drawingShape];
|
||||||
|
|
||||||
|
// Filter out hidden or visible shapes if single layer enabled
|
||||||
if (!toolSettings.multilayer) {
|
if (!toolSettings.multilayer) {
|
||||||
const shapesToSubtract = shapes.filter((shape) =>
|
const shapesToSubtract = shapes.filter((shape) =>
|
||||||
cut ? !shape.visible : shape.visible
|
cut ? !shape.visible : shape.visible
|
||||||
@@ -228,22 +233,32 @@ function MapFog({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (drawingShapes.length > 0) {
|
if (drawingShapes.length > 0) {
|
||||||
drawingShapes = drawingShapes.map((shape) => {
|
|
||||||
if (cut) {
|
|
||||||
return {
|
|
||||||
id: shape.id,
|
|
||||||
type: shape.type,
|
|
||||||
data: shape.data,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return { ...shape, color: "black" };
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (cut) {
|
if (cut) {
|
||||||
onShapesCut(drawingShapes);
|
// Run a pre-emptive cut action to check whether we've cut anything
|
||||||
|
const cutAction = new CutShapeAction(drawingShapes);
|
||||||
|
const state = cutAction.execute(keyBy(shapes, "id"));
|
||||||
|
|
||||||
|
if (Object.keys(state).length === shapes.length) {
|
||||||
|
onShapeError("No fog found to cut");
|
||||||
|
} else {
|
||||||
|
onShapesCut(
|
||||||
|
drawingShapes.map((shape) => ({
|
||||||
|
id: shape.id,
|
||||||
|
type: shape.type,
|
||||||
|
data: shape.data,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
onShapesAdd(drawingShapes);
|
onShapesAdd(
|
||||||
|
drawingShapes.map((shape) => ({ ...shape, color: "black" }))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (cut) {
|
||||||
|
onShapeError("Fog already cut");
|
||||||
|
} else {
|
||||||
|
onShapeError("Fog already placed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setDrawingShape(null);
|
setDrawingShape(null);
|
||||||
@@ -373,6 +388,7 @@ function MapFog({
|
|||||||
};
|
};
|
||||||
|
|
||||||
let polygonShapes = [polygonShape];
|
let polygonShapes = [polygonShape];
|
||||||
|
// Filter out hidden or visible shapes if single layer enabled
|
||||||
if (!toolSettings.multilayer) {
|
if (!toolSettings.multilayer) {
|
||||||
const shapesToSubtract = shapes.filter((shape) =>
|
const shapesToSubtract = shapes.filter((shape) =>
|
||||||
cut ? !shape.visible : shape.visible
|
cut ? !shape.visible : shape.visible
|
||||||
@@ -388,7 +404,15 @@ function MapFog({
|
|||||||
|
|
||||||
if (polygonShapes.length > 0) {
|
if (polygonShapes.length > 0) {
|
||||||
if (cut) {
|
if (cut) {
|
||||||
onShapesCut(polygonShapes);
|
// Run a pre-emptive cut action to check whether we've cut anything
|
||||||
|
const cutAction = new CutShapeAction(polygonShapes);
|
||||||
|
const state = cutAction.execute(keyBy(shapes, "id"));
|
||||||
|
|
||||||
|
if (Object.keys(state).length === shapes.length) {
|
||||||
|
onShapeError("No fog found to cut");
|
||||||
|
} else {
|
||||||
|
onShapesCut(polygonShapes);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
onShapesAdd(
|
onShapesAdd(
|
||||||
polygonShapes.map((shape) => ({
|
polygonShapes.map((shape) => ({
|
||||||
@@ -399,6 +423,12 @@ function MapFog({
|
|||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (cut) {
|
||||||
|
onShapeError("Fog already cut");
|
||||||
|
} else {
|
||||||
|
onShapeError("Fog already placed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setDrawingShape(null);
|
setDrawingShape(null);
|
||||||
|
|||||||
Reference in New Issue
Block a user