Skip to content

Commit

Permalink
feat(map,data): separate union settings for hegemony and non-hegemony…
Browse files Browse the repository at this point in the history
… federations
  • Loading branch information
MichaelMakesGames committed May 14, 2024
1 parent 2cbc067 commit 51556b8
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/renderer/src/intl/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/src/lib/GameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({}),
});

/**
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/lib/map/data/processBorders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
export const processBordersDeps = [
'unionMode',
'unionFederations',
'unionHegemonies',
'unionSubjects',
'unionFederationsColor',
'hyperlaneMetroStyle',
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/lib/map/data/processLabels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
export const processLabelsDeps = [
'unionMode',
'unionFederations',
'unionHegemonies',
'unionSubjects',
'borderStroke',
'labelsAvoidHoles',
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/lib/map/data/processSystemOwnership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getFrontierSectorPseudoId, getUnionLeaderId, pointToGeoJSON } from './u
export const processSystemOwnershipDeps = [
'unionMode',
'unionFederations',
'unionHegemonies',
'unionSubjects',
'unionFederationsColor',
] satisfies (keyof MapSettings)[];
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/lib/map/data/processSystems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getCountryColors } from './utils';
export const processSystemsDeps = [
'unionMode',
'unionFederations',
'unionHegemonies',
'unionSubjects',
'unionFederationsColor',
] satisfies (keyof MapSettings)[];
Expand Down
31 changes: 20 additions & 11 deletions src/renderer/src/lib/map/data/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -64,20 +72,21 @@ export function getUnionLeaderId(
export function isUnionLeader(
countryId: number,
gameState: GameState,
settings: Pick<MapSettings, 'unionMode' | 'unionFederations' | 'unionSubjects'>,
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);
Expand Down Expand Up @@ -145,7 +154,7 @@ export function getCountryColors(
gameState: GameState,
settings: Pick<
MapSettings,
'unionMode' | 'unionFederations' | 'unionSubjects' | 'unionFederationsColor'
'unionMode' | 'unionFederations' | 'unionHegemonies' | 'unionSubjects' | 'unionFederationsColor'
>,
) {
return gameState.country[
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/lib/settings/mapSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type StringMapSettings =
| 'labelsAvoidHoles'
| 'countryNamesType'
| 'countryNamesFont'
| 'unionHegemonies'
| 'unionFederations'
| 'unionFederationsColor'
| 'unionSubjects'
Expand Down Expand Up @@ -245,6 +246,7 @@ export const defaultMapSettings: MapSettings = {
color: { color: 'white', colorAdjustments: [] },
},
unionMode: false,
unionHegemonies: 'joinedBorders',
unionFederations: 'joinedBorders',
unionFederationsColor: 'founder',
unionSubjects: 'joinedBorders',
Expand Down
19 changes: 16 additions & 3 deletions src/renderer/src/lib/settings/mapSettingsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ 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',
type: 'color',
hideIf: (settings) =>
!settings.unionBorderStroke.enabled ||
!settings.unionMode ||
(settings.unionFederations === 'off' && settings.unionSubjects === 'off'),
![settings.unionFederations, settings.unionHegemonies, settings.unionSubjects].includes(
'joinedBorders',
),
},
],
},
Expand All @@ -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,
Expand All @@ -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',
Expand Down

0 comments on commit 51556b8

Please sign in to comment.