From f5af1cff43533684056034eb2c6c250674281837 Mon Sep 17 00:00:00 2001 From: Owen Date: Sun, 28 Jul 2024 16:33:46 +0100 Subject: [PATCH] much more accurately determine capital --- src/api/squaremap/parser.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/api/squaremap/parser.ts b/src/api/squaremap/parser.ts index d4c0b44..9e6aad3 100644 --- a/src/api/squaremap/parser.ts +++ b/src/api/squaremap/parser.ts @@ -5,6 +5,7 @@ import { asBool, calcAreaPoints, fastMergeUnique, formatString, range, roundToNe import type { Resident, + SquaremapArea, SquaremapMarkerset, SquaremapNation, SquaremapOnlinePlayer, @@ -130,6 +131,14 @@ interface TownCoords { townZ: number[] } +const isCapital = (marker: SquaremapArea) => { + const desc = striptags(marker.tooltip.replaceAll('\n', '')).trim() + const bracketMatch = desc.match(/\((.*)\)/) + + const tooltipBracketContent = bracketMatch ? bracketMatch[1].trim() : null + return tooltipBracketContent?.startsWith("Capital of") ?? false +} + export const parseTowns = async(res: SquaremapMarkerset, removeAccents = false) => { if (res.id == "chunky") throw new Error("Error parsing towns: Chunky markerset detected, pass a towny markerset instead.") if (!res?.markers) throw new ReferenceError('Error parsing towns: Missing or invalid markers!') @@ -170,10 +179,9 @@ export const parseTowns = async(res: SquaremapMarkerset, removeAccents = false) z: townZ }, flags: { - // Flags no longer shown pvp: asBool(parsedPopup.flags.pvp), public: asBool(parsedPopup.flags.public), - capital: curMarker.tooltip.includes('Capital of') + capital: nationName == "No Nation" ? false : isCapital(curMarker) }, colours: { fill: curMarker.fillColor || curMarker.color,