From 8dd09dba0478194cb9c18ee7403c069dd557518a Mon Sep 17 00:00:00 2001 From: Michael Moore Date: Tue, 12 Mar 2024 19:48:47 -0500 Subject: [PATCH] feat(map,data): add option to display player names in addition to or instead of country names --- src/renderer/src/lib/map/CountryLabels.svelte | 20 +++++++++- .../src/lib/map/data/processLabels.ts | 33 +++++++++++++-- src/renderer/src/lib/mapSettings.ts | 40 ++++++++++++++++++- 3 files changed, 87 insertions(+), 6 deletions(-) diff --git a/src/renderer/src/lib/map/CountryLabels.svelte b/src/renderer/src/lib/map/CountryLabels.svelte index 567aa82..d64ffd7 100644 --- a/src/renderer/src/lib/map/CountryLabels.svelte +++ b/src/renderer/src/lib/map/CountryLabels.svelte @@ -52,7 +52,7 @@ fill="transparent" /> {/if} - {#if textWidth && textHeight && label.name} + {#if textWidth && textHeight && label.primaryName} - {label.name} + {label.primaryName} + + {/if} + {#if textWidth && textHeight && label.secondaryName} + + {label.secondaryName} {/if} {/each} diff --git a/src/renderer/src/lib/map/data/processLabels.ts b/src/renderer/src/lib/map/data/processLabels.ts index 3e9b89e..4ab34a0 100644 --- a/src/renderer/src/lib/map/data/processLabels.ts +++ b/src/renderer/src/lib/map/data/processLabels.ts @@ -25,6 +25,7 @@ export const processLabelsDeps = [ 'countryEmblemsMinSize', 'countryEmblemsMaxSize', 'countryNames', + 'countryNamesType', 'countryNamesFont', 'countryNamesMinSize', 'countryNamesMaxSize', @@ -54,11 +55,36 @@ export default function processLabels( }), ); const labels = idGeojsonPairs.map(([countryId, geojson]) => { - const name = countryNames[countryId] ?? ''; + const countryName = countryNames[countryId] ?? ''; + const playerName = gameState.player.find((player) => player.country === countryId)?.name ?? ''; + let primaryName = ''; + let secondaryName = ''; + switch (settings.countryNamesType) { + case 'countryOnly': { + primaryName = countryName; + break; + } + case 'playerOnly': { + primaryName = playerName; + break; + } + case 'countryThenPlayer': { + primaryName = countryName; + secondaryName = playerName; + break; + } + case 'playerThenCountry': { + primaryName = playerName !== '' ? playerName : countryName; + secondaryName = playerName !== '' ? countryName : ''; + break; + } + } const country = gameState.country[countryId]; const textAspectRatio = - name && settings.countryNames ? getTextAspectRatio(name, settings.countryNamesFont) : 0; + primaryName && settings.countryNames + ? getTextAspectRatio(primaryName, settings.countryNamesFont) + : 0; const emblemAspectRatio = settings.countryEmblems ? 1 / 1 : 0; let searchAspectRatio = 0; if (settings.countryEmblems && settings.countryNames) { @@ -153,7 +179,8 @@ export default function processLabels( : null; return { labelPoints, - name, + primaryName, + secondaryName, emblemKey, isUnionLeader: isUnionLeader(countryId, gameState, settings), isKnown: knownCountries.has(countryId), diff --git a/src/renderer/src/lib/mapSettings.ts b/src/renderer/src/lib/mapSettings.ts index f0ffa6f..227d939 100644 --- a/src/renderer/src/lib/mapSettings.ts +++ b/src/renderer/src/lib/mapSettings.ts @@ -18,11 +18,13 @@ type NumberOptionalMapSettings = | 'countryEmblemsMinSize' | 'countryNamesMaxSize' | 'countryNamesMinSize' + | 'countryNamesSecondaryRelativeSize' | 'claimVoidMaxSize' | 'starScapeStarsCount'; type StringMapSettings = | 'labelsAvoidHoles' + | 'countryNamesType' | 'countryNamesFont' | 'unionFederations' | 'unionFederationsColor' @@ -417,6 +419,30 @@ export const mapSettingConfig: MapSettingGroup[] = [ requiresReprocessing: true, type: 'toggle', }, + { + id: 'countryNamesType', + name: 'Name Type', + requiresReprocessing: true, + type: 'select', + options: [ + { + id: 'countryOnly', + name: 'Country Name Only', + }, + { + id: 'playerOnly', + name: 'Player Name Only', + }, + { + id: 'countryThenPlayer', + name: 'Country then Player Name', + }, + { + id: 'playerThenCountry', + name: 'Player then Country Name', + }, + ], + }, { id: 'countryNamesMinSize', name: 'Name Min Size', @@ -437,6 +463,16 @@ export const mapSettingConfig: MapSettingGroup[] = [ optional: true, hideIf: (settings) => !settings.countryNames, }, + { + id: 'countryNamesSecondaryRelativeSize', + name: 'Secondary Name Relative Size', + type: 'number', + min: 0, + step: 0.05, + optional: true, + hideIf: (settings) => + !['countryThenPlayer', 'playerThenCountry'].includes(settings.countryNamesType), + }, { id: 'countryNamesFont', name: 'Font', @@ -908,8 +944,10 @@ const defaultMapSettings: MapSettings = { colorAdjustments: [{ type: 'OPACITY', value: 0.15 }], }, countryNames: true, + countryNamesType: 'countryOnly', countryNamesMinSize: 5, countryNamesMaxSize: null, + countryNamesSecondaryRelativeSize: 0.75, countryNamesFont: 'Orbitron', countryEmblems: true, countryEmblemsMinSize: null, @@ -1310,7 +1348,7 @@ export function isColorDynamic(color: string, settings: MapSettings): boolean { ); } -function validateAndResetSettings(unvalidatedSettings: MapSettings): MapSettings { +export function validateAndResetSettings(unvalidatedSettings: MapSettings): MapSettings { const settings = { ...unvalidatedSettings }; const configs = mapSettingConfig.flatMap((category) => category.settings); for (const key of Object.keys(settings)) {