mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
fix: don't throw error in rulers if map file is corrupted
This commit is contained in:
parent
6cd2419f10
commit
db519c40c8
3 changed files with 12 additions and 13 deletions
|
|
@ -16,21 +16,20 @@ class Rulers {
|
|||
fromString(string) {
|
||||
this.data = [];
|
||||
|
||||
const typeMap = {
|
||||
Ruler: Ruler,
|
||||
Opisometer: Opisometer,
|
||||
RouteOpisometer: RouteOpisometer,
|
||||
Planimeter: Planimeter
|
||||
};
|
||||
|
||||
const rulers = string.split("; ");
|
||||
for (const rulerString of rulers) {
|
||||
const [type, pointsString] = rulerString.split(": ");
|
||||
if (!type || !pointsString) continue;
|
||||
|
||||
const points = pointsString.split(" ").map(el => el.split(",").map(n => +n));
|
||||
const Type =
|
||||
type === "Ruler"
|
||||
? Ruler
|
||||
: type === "Opisometer"
|
||||
? Opisometer
|
||||
: type === "RouteOpisometer"
|
||||
? RouteOpisometer
|
||||
: type === "Planimeter"
|
||||
? Planimeter
|
||||
: null;
|
||||
this.create(Type, points);
|
||||
this.create(typeMap[type], points);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue