diff --git a/src/components/map/MapToken.js b/src/components/map/MapToken.js
index 2025ca9..f94b315 100644
--- a/src/components/map/MapToken.js
+++ b/src/components/map/MapToken.js
@@ -1,5 +1,5 @@
import React, { useState, useRef } from "react";
-import { Image as KonvaImage, Group, Line, Rect, Circle } from "react-konva";
+import { Image as KonvaImage, Group } from "react-konva";
import { useSpring, animated } from "react-spring/konva";
import useImage from "use-image";
import Konva from "konva";
@@ -18,8 +18,7 @@ import { useDataURL } from "../../contexts/AssetsContext";
import TokenStatus from "../token/TokenStatus";
import TokenLabel from "../token/TokenLabel";
-
-import colors from "../../helpers/colors";
+import TokenOutline from "../token/TokenOutline";
import { tokenSources } from "../../tokens";
@@ -235,43 +234,6 @@ function MapToken({
}
}
- function renderOutline() {
- const outline = getScaledOutline();
- const sharedProps = {
- fill: colors.black,
- opacity: tokenImage ? 0 : 0.8,
- };
- if (outline.type === "rect") {
- return (
-
- );
- } else if (outline.type === "circle") {
- return (
-
- );
- } else {
- return (
-
- );
- }
- }
-
return (
- {renderOutline()}
+
{
const tokenURL = useDataURL(
token,
@@ -13,7 +15,32 @@ const TokenImage = React.forwardRef(({ token, ...props }, ref) => {
token.type === "file"
);
- return ;
+ const [showOutline, setShowOutline] = useState(true);
+
+ return (
+ <>
+ {showOutline && (
+
+
+
+ )}
+ setShowOutline(false)}
+ src={tokenURL}
+ ref={ref}
+ style={showOutline ? { display: "none" } : props.style}
+ {...props}
+ />
+ >
+ );
});
export default TokenImage;
diff --git a/src/components/token/TokenOutline.js b/src/components/token/TokenOutline.js
new file mode 100644
index 0000000..20d4396
--- /dev/null
+++ b/src/components/token/TokenOutline.js
@@ -0,0 +1,94 @@
+import React from "react";
+import { Rect, Circle, Line } from "react-konva";
+
+import colors from "../../helpers/colors";
+
+export function TokenOutlineSVG({ outline, width, height }) {
+ if (outline.type === "rect") {
+ return (
+
+ );
+ } else if (outline.type === "circle") {
+ return (
+
+ );
+ } else {
+ let points = [];
+ for (let i = 0; i < outline.points.length; i += 2) {
+ points.push(`${outline.points[i]}, ${outline.points[i + 1]}`);
+ }
+ return (
+
+ );
+ }
+}
+
+function TokenOutline({ outline, hidden }) {
+ const sharedProps = {
+ fill: colors.black,
+ opacity: hidden ? 0 : 0.8,
+ };
+ if (outline.type === "rect") {
+ return (
+
+ );
+ } else if (outline.type === "circle") {
+ return (
+
+ );
+ } else {
+ return (
+
+ );
+ }
+}
+
+export default TokenOutline;