Added bounds to grid name match
This commit is contained in:
parent
76e650e478
commit
d4ccad8e0a
@ -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
|
||||
);
|
||||
|
@ -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 };
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user