From aac47fab4006dde1c8e21fcd7eb70a4cdc98b3a6 Mon Sep 17 00:00:00 2001 From: Owen Date: Mon, 8 Jul 2024 10:05:29 +0100 Subject: [PATCH] calc area using points for squaremap --- src/api/squaremap/parser.ts | 15 +++++++++------ src/types/town.ts | 2 +- src/utils/functions.ts | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/api/squaremap/parser.ts b/src/api/squaremap/parser.ts index 24b15c9..dc4e633 100644 --- a/src/api/squaremap/parser.ts +++ b/src/api/squaremap/parser.ts @@ -1,7 +1,7 @@ /* eslint-disable no-unused-vars */ /* eslint-disable @typescript-eslint/no-unused-vars */ import striptags from 'striptags' -import { asBool, calcArea, fastMergeUnique, formatString, range, roundToNearest16, safeParseInt } from '../../utils/functions.js' +import { asBool, calcAreaPoints, fastMergeUnique, formatString, range, roundToNearest16, safeParseInt } from '../../utils/functions.js' import type { Resident, @@ -141,18 +141,17 @@ export const parseTowns = async(res: SquaremapMarkerset, removeAccents = false) name: formatString(townName, removeAccents), nation: nationName, foundedTimestamp: Math.floor(new Date(parsedPopup.founded).getTime() / 1000), - wealth: safeParseInt(parsedPopup.wealth.slice(0, -1)), mayor: parsedPopup.mayor, councillors: parsedPopup.councillors, residents: parsedPopup.residents, - area: calcArea(townX, townZ, townX.length), + x: range(townX), + z: range(townZ), + area: calcAreaPoints(points), + points, bounds: { x: townX, z: townZ }, - points, - x: range(townX), - z: range(townZ), flags: { // Flags no longer shown pvp: asBool(parsedPopup.flags.pvp), @@ -188,6 +187,10 @@ export const parseTowns = async(res: SquaremapMarkerset, removeAccents = false) } //#endregion + if (parsedPopup.wealth) { + town.wealth = safeParseInt(parsedPopup.wealth.slice(0, -1)) + } + towns.push(town) } diff --git a/src/types/town.ts b/src/types/town.ts index a884b66..20dac60 100644 --- a/src/types/town.ts +++ b/src/types/town.ts @@ -30,7 +30,7 @@ export interface BaseTown { export type SquaremapTown = Prettify t.nation?.toLowerCase() == name.toLowerCase()) return getAveragePos(nationTowns)