diff --git a/client/src/components/renderer/map-parser/mesh/parseMesh.worker.ts b/client/src/components/renderer/map-parser/mesh/parseMesh.worker.ts index f27f3321..8916a832 100644 --- a/client/src/components/renderer/map-parser/mesh/parseMesh.worker.ts +++ b/client/src/components/renderer/map-parser/mesh/parseMesh.worker.ts @@ -39,9 +39,9 @@ function parseMesh({ const [, , counts, ...rest] = lines.filter(identity); - const [vertexCount] = counts.split(" ").map(parseInt); + const [vertexCount] = counts.split(/\s+/).map(parseInt); - const lines2 = rest.map((line) => line.split(" ").map(parseFloat)); + const lines2 = rest.map((line) => line.split(/\s+/).map(parseFloat)); // 1-indexed vertices const vertices = lines2.slice(0, vertexCount); diff --git a/client/src/hooks/useParsedMap.tsx b/client/src/hooks/useParsedMap.tsx index e093cef8..7213a52d 100644 --- a/client/src/hooks/useParsedMap.tsx +++ b/client/src/hooks/useParsedMap.tsx @@ -33,6 +33,7 @@ export function useParsedMap(map?: Map, options?: Record) { } catch (e) { console.error(e); notify("Error parsing", get(e, "message")); + return { error: get(e, "message") }; } } }), diff --git a/client/src/layers/map/index.tsx b/client/src/layers/map/index.tsx index 024d7271..62f4a7d2 100644 --- a/client/src/layers/map/index.tsx +++ b/client/src/layers/map/index.tsx @@ -1,4 +1,4 @@ -import { CircularProgress } from "@mui/material"; +import { CircularProgress, Typography } from "@mui/material"; import { MapPicker } from "components/app-bar/Input"; import { Heading, Option } from "components/layer-editor/Option"; import { getParser } from "components/renderer"; @@ -15,11 +15,12 @@ import { withProduce } from "produce"; import { useMemo } from "react"; import { Map } from "slices/UIState"; import { Layer, useLayer } from "slices/layers"; +import { usePaper } from "theme"; export type MapLayerData = { map?: Map; options?: Record; - parsedMap?: ParsedMap; + parsedMap?: ParsedMap & { error?: string }; }; export type MapLayer = Layer; @@ -30,7 +31,9 @@ export const controller = { layer?.source?.map ? `${layer.source.map.name} (${startCase(layer.source.map.format)})` : "Untitled Map", + error: (layer) => layer?.source?.parsedMap?.error, editor: withProduce(({ value, produce }) => { + const paper = usePaper(); const { result: Editor } = useMapOptions(value?.source?.map); return ( <> @@ -43,6 +46,22 @@ export const controller = { /> } /> + {value?.source?.parsedMap?.error && ( + t.palette.error.main} + sx={{ + whiteSpace: "pre-line", + mb: 1, + mt: 1, + ...paper(1), + p: 1, + borderRadius: 1, + }} + > + {value?.source?.parsedMap?.error} + + )} {!!value?.source?.map && ( <> diff --git a/resources/maps/Small Mesh.mesh b/resources/maps/Small Mesh.mesh new file mode 100644 index 00000000..8102f2c9 --- /dev/null +++ b/resources/maps/Small Mesh.mesh @@ -0,0 +1,12 @@ +mesh +3 +5 4 +0 0 +0 10 +10 10 +10 0 +5 5 +0 3 4 1 5 -4 0 -2 +1 3 1 2 5 -1 0 3 +1 3 2 3 5 3 0 4 +1 3 3 4 5 3 0 -1 \ No newline at end of file