Skip to content

Commit

Permalink
feat(map,data): add option to display player names in addition to or …
Browse files Browse the repository at this point in the history
…instead of country names
  • Loading branch information
MichaelMakesGames committed Mar 13, 2024
1 parent ca15d63 commit 8dd09db
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 6 deletions.
20 changes: 18 additions & 2 deletions src/renderer/src/lib/map/CountryLabels.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
fill="transparent"
/>
{/if}
{#if textWidth && textHeight && label.name}
{#if textWidth && textHeight && label.primaryName}
<text
x={point[0]}
y={point[1] + (emblemHeight ? textHeight / 2 : 0)}
Expand All @@ -68,7 +68,23 @@
: ''}
style:text-shadow="0px 0px 3px black"
>
{label.name}
{label.primaryName}
</text>
{/if}
{#if textWidth && textHeight && label.secondaryName}
<text
x={point[0]}
y={point[1] +
(emblemHeight ? textHeight / 2 : 0) +
textHeight * ($lastProcessedMapSettings.countryNamesSecondaryRelativeSize ?? 1) * 1.25}
text-anchor="middle"
dominant-baseline="middle"
font-size={textHeight * ($lastProcessedMapSettings.countryNamesSecondaryRelativeSize ?? 1)}
fill="white"
font-family={$lastProcessedMapSettings.countryNamesFont}
style:text-shadow="0px 0px 3px black"
>
{label.secondaryName}
</text>
{/if}
{/each}
Expand Down
33 changes: 30 additions & 3 deletions src/renderer/src/lib/map/data/processLabels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const processLabelsDeps = [
'countryEmblemsMinSize',
'countryEmblemsMaxSize',
'countryNames',
'countryNamesType',
'countryNamesFont',
'countryNamesMinSize',
'countryNamesMaxSize',
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -153,7 +179,8 @@ export default function processLabels(
: null;
return {
labelPoints,
name,
primaryName,
secondaryName,
emblemKey,
isUnionLeader: isUnionLeader(countryId, gameState, settings),
isKnown: knownCountries.has(countryId),
Expand Down
40 changes: 39 additions & 1 deletion src/renderer/src/lib/mapSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ type NumberOptionalMapSettings =
| 'countryEmblemsMinSize'
| 'countryNamesMaxSize'
| 'countryNamesMinSize'
| 'countryNamesSecondaryRelativeSize'
| 'claimVoidMaxSize'
| 'starScapeStarsCount';

type StringMapSettings =
| 'labelsAvoidHoles'
| 'countryNamesType'
| 'countryNamesFont'
| 'unionFederations'
| 'unionFederationsColor'
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 8dd09db

Please sign in to comment.