From 51556b81e44c005f859a06746e8a4e9dba5e340b Mon Sep 17 00:00:00 2001 From: Michael Moore Date: Mon, 13 May 2024 20:33:01 -0500 Subject: [PATCH] feat(map,data): separate union settings for hegemony and non-hegemony federations --- src/renderer/src/intl/en-US.ts | 3 +- src/renderer/src/lib/GameState.ts | 5 +++ .../src/lib/map/data/processBorders.ts | 1 + .../src/lib/map/data/processLabels.ts | 1 + .../lib/map/data/processSystemOwnership.ts | 1 + .../src/lib/map/data/processSystems.ts | 1 + src/renderer/src/lib/map/data/utils.ts | 31 ++++++++++++------- src/renderer/src/lib/settings/mapSettings.ts | 2 ++ .../src/lib/settings/mapSettingsConfig.ts | 19 ++++++++++-- 9 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/renderer/src/intl/en-US.ts b/src/renderer/src/intl/en-US.ts index c51f059..e17d466 100644 --- a/src/renderer/src/intl/en-US.ts +++ b/src/renderer/src/intl/en-US.ts @@ -256,7 +256,8 @@ export default { unionBorderColor: 'Union Border Color', unionMode: 'Union Mode', unionSubjects: 'Subjects', - unionFederations: 'Federations', + unionHegemonies: 'Hegemony Federations', + unionFederations: 'Other Federations', unionFederationsColor: 'Federation Member Color', unionLeaderSymbol: 'Union Leader Symbol', unionLeaderSymbolSize: 'Union Leader Symbol Size', diff --git a/src/renderer/src/lib/GameState.ts b/src/renderer/src/lib/GameState.ts index b66d883..68fd76a 100644 --- a/src/renderer/src/lib/GameState.ts +++ b/src/renderer/src/lib/GameState.ts @@ -200,6 +200,11 @@ const federationSchema = z.object({ leader: z.number(), members: preprocessedArray(z.number()), name: localizedTextSchema, + federation_progress: z + .object({ + federation_type: z.string().default('default_federation'), + }) + .default({}), }); /** diff --git a/src/renderer/src/lib/map/data/processBorders.ts b/src/renderer/src/lib/map/data/processBorders.ts index ba0f86f..c3a7f63 100644 --- a/src/renderer/src/lib/map/data/processBorders.ts +++ b/src/renderer/src/lib/map/data/processBorders.ts @@ -29,6 +29,7 @@ import { export const processBordersDeps = [ 'unionMode', 'unionFederations', + 'unionHegemonies', 'unionSubjects', 'unionFederationsColor', 'hyperlaneMetroStyle', diff --git a/src/renderer/src/lib/map/data/processLabels.ts b/src/renderer/src/lib/map/data/processLabels.ts index 967e68c..960c1f7 100644 --- a/src/renderer/src/lib/map/data/processLabels.ts +++ b/src/renderer/src/lib/map/data/processLabels.ts @@ -17,6 +17,7 @@ import { export const processLabelsDeps = [ 'unionMode', 'unionFederations', + 'unionHegemonies', 'unionSubjects', 'borderStroke', 'labelsAvoidHoles', diff --git a/src/renderer/src/lib/map/data/processSystemOwnership.ts b/src/renderer/src/lib/map/data/processSystemOwnership.ts index 0b6b8ed..f824a86 100644 --- a/src/renderer/src/lib/map/data/processSystemOwnership.ts +++ b/src/renderer/src/lib/map/data/processSystemOwnership.ts @@ -8,6 +8,7 @@ import { getFrontierSectorPseudoId, getUnionLeaderId, pointToGeoJSON } from './u export const processSystemOwnershipDeps = [ 'unionMode', 'unionFederations', + 'unionHegemonies', 'unionSubjects', 'unionFederationsColor', ] satisfies (keyof MapSettings)[]; diff --git a/src/renderer/src/lib/map/data/processSystems.ts b/src/renderer/src/lib/map/data/processSystems.ts index d9b69b3..091a184 100644 --- a/src/renderer/src/lib/map/data/processSystems.ts +++ b/src/renderer/src/lib/map/data/processSystems.ts @@ -7,6 +7,7 @@ import { getCountryColors } from './utils'; export const processSystemsDeps = [ 'unionMode', 'unionFederations', + 'unionHegemonies', 'unionSubjects', 'unionFederationsColor', ] satisfies (keyof MapSettings)[]; diff --git a/src/renderer/src/lib/map/data/utils.ts b/src/renderer/src/lib/map/data/utils.ts index 7ab402a..02d36e4 100644 --- a/src/renderer/src/lib/map/data/utils.ts +++ b/src/renderer/src/lib/map/data/utils.ts @@ -28,7 +28,7 @@ export function getUnionLeaderId( gameState: GameState, settings: Pick< MapSettings, - 'unionMode' | 'unionFederations' | 'unionSubjects' | 'unionFederationsColor' + 'unionMode' | 'unionFederations' | 'unionHegemonies' | 'unionSubjects' | 'unionFederationsColor' >, values: ('joinedBorders' | 'separateBorders' | 'off')[], ): number { @@ -38,6 +38,10 @@ export function getUnionLeaderId( const overlordId = country.overlord; const overlord = overlordId != null ? gameState.country[overlordId] : null; const federation = country.federation != null ? gameState.federation[country.federation] : null; + const isHegemonyFederation = federation + ? federation.federation_progress.federation_type === 'hegemony_federation' + : false; + const isNonHegemonyFederation = federation ? !isHegemonyFederation : false; const overlordFederation = overlord?.federation != null ? gameState.federation[overlord.federation] : null; if (!settings.unionMode) { @@ -50,7 +54,11 @@ export function getUnionLeaderId( return settings.unionFederationsColor === 'leader' ? overlordFederation.leader : overlordFederation.members[0] ?? countryId; - } else if (isIncludedValue(settings.unionFederations) && federation) { + } else if ( + federation && + ((isIncludedValue(settings.unionFederations) && isNonHegemonyFederation) || + (isIncludedValue(settings.unionHegemonies) && isHegemonyFederation)) + ) { return settings.unionFederationsColor === 'leader' ? federation.leader : federation.members[0] ?? countryId; @@ -64,20 +72,21 @@ export function getUnionLeaderId( export function isUnionLeader( countryId: number, gameState: GameState, - settings: Pick, + settings: Pick< + MapSettings, + 'unionMode' | 'unionFederations' | 'unionHegemonies' | 'unionSubjects' + >, ) { const country = gameState.country[countryId]; if (country == null) return false; const federation = country.federation != null ? gameState.federation[country.federation] : null; + const federationIsDisplayedAsUnion = + federation?.federation_progress.federation_type === 'hegemony_federation' + ? settings.unionHegemonies !== 'off' + : settings.unionFederations !== 'off'; if (!settings.unionMode) { return false; - } else if (settings.unionFederations !== 'off' && settings.unionSubjects !== 'off') { - if (federation) { - return federation.leader === countryId; - } else { - return Boolean(country.subjects.length); - } - } else if (settings.unionFederations !== 'off' && federation) { + } else if (federation && federationIsDisplayedAsUnion) { return federation.leader === countryId; } else if (settings.unionSubjects !== 'off') { return Boolean(country.subjects.length); @@ -145,7 +154,7 @@ export function getCountryColors( gameState: GameState, settings: Pick< MapSettings, - 'unionMode' | 'unionFederations' | 'unionSubjects' | 'unionFederationsColor' + 'unionMode' | 'unionFederations' | 'unionHegemonies' | 'unionSubjects' | 'unionFederationsColor' >, ) { return gameState.country[ diff --git a/src/renderer/src/lib/settings/mapSettings.ts b/src/renderer/src/lib/settings/mapSettings.ts index 12b5ce2..6309e6a 100644 --- a/src/renderer/src/lib/settings/mapSettings.ts +++ b/src/renderer/src/lib/settings/mapSettings.ts @@ -26,6 +26,7 @@ export type StringMapSettings = | 'labelsAvoidHoles' | 'countryNamesType' | 'countryNamesFont' + | 'unionHegemonies' | 'unionFederations' | 'unionFederationsColor' | 'unionSubjects' @@ -245,6 +246,7 @@ export const defaultMapSettings: MapSettings = { color: { color: 'white', colorAdjustments: [] }, }, unionMode: false, + unionHegemonies: 'joinedBorders', unionFederations: 'joinedBorders', unionFederationsColor: 'founder', unionSubjects: 'joinedBorders', diff --git a/src/renderer/src/lib/settings/mapSettingsConfig.ts b/src/renderer/src/lib/settings/mapSettingsConfig.ts index f85c2c8..120f155 100644 --- a/src/renderer/src/lib/settings/mapSettingsConfig.ts +++ b/src/renderer/src/lib/settings/mapSettingsConfig.ts @@ -52,7 +52,9 @@ export const mapSettingsConfig: MapSettingConfigGroup[] = [ requiresReprocessing: (prev, next) => prev.smoothing !== next.smoothing, hideIf: (settings) => !settings.unionMode || - (settings.unionFederations === 'off' && settings.unionSubjects === 'off'), + ![settings.unionFederations, settings.unionHegemonies, settings.unionSubjects].includes( + 'joinedBorders', + ), }, { id: 'unionBorderColor', @@ -60,7 +62,9 @@ export const mapSettingsConfig: MapSettingConfigGroup[] = [ hideIf: (settings) => !settings.unionBorderStroke.enabled || !settings.unionMode || - (settings.unionFederations === 'off' && settings.unionSubjects === 'off'), + ![settings.unionFederations, settings.unionHegemonies, settings.unionSubjects].includes( + 'joinedBorders', + ), }, ], }, @@ -80,6 +84,13 @@ export const mapSettingsConfig: MapSettingConfigGroup[] = [ options: unionOptions, hideIf: (settings) => !settings.unionMode, }, + { + id: 'unionHegemonies', + requiresReprocessing: true, + type: 'select', + options: unionOptions, + hideIf: (settings) => !settings.unionMode, + }, { id: 'unionFederations', requiresReprocessing: true, @@ -95,7 +106,9 @@ export const mapSettingsConfig: MapSettingConfigGroup[] = [ { id: 'founder', name: 'option.union_federations_color.founder' }, { id: 'leader', name: 'option.union_federations_color.leader' }, ], - hideIf: (settings) => !settings.unionMode || settings.unionFederations === 'off', + hideIf: (settings) => + !settings.unionMode || + (settings.unionFederations === 'off' && settings.unionHegemonies === 'off'), }, { id: 'unionLeaderSymbol',