diff --git a/src/helpers/map.js b/src/helpers/map.js index 943a2f4..a6875ba 100644 --- a/src/helpers/map.js +++ b/src/helpers/map.js @@ -39,7 +39,7 @@ const gridSizeStd = { x: 14.438842, y: 15.582376 }; const minGridSize = 10; const maxGridSize = 200; -function gridSizeVaild(x, y) { +export function gridSizeVaild(x, y) { return ( x > minGridSize && y > minGridSize && x < maxGridSize && y < maxGridSize ); diff --git a/src/modals/SelectMapModal.js b/src/modals/SelectMapModal.js index 62b67df..8f745f1 100644 --- a/src/modals/SelectMapModal.js +++ b/src/modals/SelectMapModal.js @@ -16,7 +16,7 @@ import blobToBuffer from "../helpers/blobToBuffer"; import useKeyboard from "../helpers/useKeyboard"; import { resizeImage } from "../helpers/image"; import { useSearch, useGroup, handleItemSelect } from "../helpers/select"; -import { getMapDefaultInset, getGridSize } from "../helpers/map"; +import { getMapDefaultInset, getGridSize, gridSizeVaild } from "../helpers/map"; import MapDataContext from "../contexts/MapDataContext"; import AuthContext from "../contexts/AuthContext"; @@ -120,11 +120,14 @@ function SelectMapModal({ // Match against a regex to find the grid size in the file name // e.g. Cave 22x23 will return [["22x22", "22", "x", "23"]] const gridMatches = [...file.name.matchAll(/(\d+) ?(x|X) ?(\d+)/g)]; - if (gridMatches.length > 0) { - const lastMatch = gridMatches[gridMatches.length - 1]; - const matchX = parseInt(lastMatch[1]); - const matchY = parseInt(lastMatch[3]); - if (!isNaN(matchX) && !isNaN(matchY)) { + for (let match of gridMatches) { + const matchX = parseInt(match[1]); + const matchY = parseInt(match[3]); + if ( + !isNaN(matchX) && + !isNaN(matchY) && + gridSizeVaild(matchX, matchY) + ) { gridSize = { x: matchX, y: matchY }; } }