Added bounds to grid name match

This commit is contained in:
Mitchell McCaffrey 2020-10-22 12:07:06 +11:00
parent 76e650e478
commit d4ccad8e0a
2 changed files with 10 additions and 7 deletions

View File

@ -39,7 +39,7 @@ const gridSizeStd = { x: 14.438842, y: 15.582376 };
const minGridSize = 10; const minGridSize = 10;
const maxGridSize = 200; const maxGridSize = 200;
function gridSizeVaild(x, y) { export function gridSizeVaild(x, y) {
return ( return (
x > minGridSize && y > minGridSize && x < maxGridSize && y < maxGridSize x > minGridSize && y > minGridSize && x < maxGridSize && y < maxGridSize
); );

View File

@ -16,7 +16,7 @@ import blobToBuffer from "../helpers/blobToBuffer";
import useKeyboard from "../helpers/useKeyboard"; import useKeyboard from "../helpers/useKeyboard";
import { resizeImage } from "../helpers/image"; import { resizeImage } from "../helpers/image";
import { useSearch, useGroup, handleItemSelect } from "../helpers/select"; 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 MapDataContext from "../contexts/MapDataContext";
import AuthContext from "../contexts/AuthContext"; import AuthContext from "../contexts/AuthContext";
@ -120,11 +120,14 @@ function SelectMapModal({
// Match against a regex to find the grid size in the file name // Match against a regex to find the grid size in the file name
// e.g. Cave 22x23 will return [["22x22", "22", "x", "23"]] // e.g. Cave 22x23 will return [["22x22", "22", "x", "23"]]
const gridMatches = [...file.name.matchAll(/(\d+) ?(x|X) ?(\d+)/g)]; const gridMatches = [...file.name.matchAll(/(\d+) ?(x|X) ?(\d+)/g)];
if (gridMatches.length > 0) { for (let match of gridMatches) {
const lastMatch = gridMatches[gridMatches.length - 1]; const matchX = parseInt(match[1]);
const matchX = parseInt(lastMatch[1]); const matchY = parseInt(match[3]);
const matchY = parseInt(lastMatch[3]); if (
if (!isNaN(matchX) && !isNaN(matchY)) { !isNaN(matchX) &&
!isNaN(matchY) &&
gridSizeVaild(matchX, matchY)
) {
gridSize = { x: matchX, y: matchY }; gridSize = { x: matchX, y: matchY };
} }
} }