Skip to content

Commit

Permalink
much more accurately determine capital
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Jul 28, 2024
1 parent 0a0ae4c commit f5af1cf
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/api/squaremap/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { asBool, calcAreaPoints, fastMergeUnique, formatString, range, roundToNe

import type {
Resident,
SquaremapArea,
SquaremapMarkerset,
SquaremapNation,
SquaremapOnlinePlayer,
Expand Down Expand Up @@ -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!')
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f5af1cf

Please sign in to comment.