Skip to content

Commit

Permalink
feat(map,ui): add system icons to legend
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMakesGames committed Sep 10, 2024
1 parent 32959de commit a33fa32
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/renderer/src/lib/map/Legend.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
y={0}
width={symbolSize}
height={symbolSize}
transform="scale({item.symbol.scale ?? 1})"
transform-origin="{symbolSize / 2} {symbolSize / 2}"
{...getFillColorAttributes({
mapSettings: $mapSettings,
colors,
Expand Down
39 changes: 37 additions & 2 deletions src/renderer/src/lib/map/data/processLegend.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { get } from 'svelte/store';

import { t } from '../../../intl';
import { type MessageID, t } from '../../../intl';
import type { GameState } from '../../GameState';
import type { ColorSetting, MapSettings } from '../../settings';
import type { ColorSetting, IconSetting, MapSettings } from '../../settings';
import { localizeText } from './locUtils';
import { mapModes, type MapModeSystemValue } from './mapModes';
import type processBorders from './processBorders';
Expand All @@ -15,6 +15,7 @@ interface LegendItem {
type: 'icon';
icon: string;
color: ColorSetting;
scale?: number;
}
| {
type: 'border';
Expand All @@ -41,6 +42,13 @@ export const processLegendDeps = [
'mapModePointOfView',
'legendFontSize',
'occupation',
'countryCapitalIcon',
'sectorCapitalIcon',
'populatedSystemIcon',
'wormholeIcon',
'gatewayIcon',
'lGateIcon',
'shroudTunnelIcon',
] satisfies (keyof MapSettings)[];

export default async function processLegend(
Expand Down Expand Up @@ -112,10 +120,37 @@ export default async function processLegend(
]
: [];

const systemIconSettings: [MessageID, IconSetting][] = [
['setting.countryCapitalIcon', settings.countryCapitalIcon],
['setting.sectorCapitalIcon', settings.sectorCapitalIcon],
['setting.populatedSystemIcon', settings.populatedSystemIcon],
['setting.wormholeIcon', settings.wormholeIcon],
['setting.gatewayIcon', settings.gatewayIcon],
['setting.lGateIcon', settings.lGateIcon],
['setting.shroudTunnelIcon', settings.shroudTunnelIcon],
];
const largestIconSize = Math.max(
...systemIconSettings
.filter(([_messageId, setting]) => setting.enabled)
.map(([_messageId, setting]) => setting.size),
);
const systemIconItems: LegendItem[] = systemIconSettings
.filter(([_messageId, setting]) => setting.enabled)
.map(([messageId, setting]) => ({
label: get(t)(messageId),
symbol: {
type: 'icon',
icon: setting.icon,
color: setting.color,
scale: setting.size / largestIconSize,
},
}));

const items = insertHrBetweenGroups([
countryMapModeLegendItems,
systemMapModeLegendItems,
occupationLegendItems,
systemIconItems,
]);
return {
items,
Expand Down
7 changes: 7 additions & 0 deletions src/renderer/src/lib/settings/mapSettingsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,17 @@ export const mapSettingsConfig: MapSettingConfigGroup[] = [
{
id: 'countryCapitalIcon',
type: 'icon',
requiresReprocessing: true,
},
{
id: 'sectorCapitalIcon',
type: 'icon',
requiresReprocessing: true,
},
{
id: 'populatedSystemIcon',
type: 'icon',
requiresReprocessing: true,
},
{
id: 'unpopulatedSystemIcon',
Expand All @@ -367,18 +370,22 @@ export const mapSettingsConfig: MapSettingConfigGroup[] = [
{
id: 'wormholeIcon',
type: 'icon',
requiresReprocessing: true,
},
{
id: 'gatewayIcon',
type: 'icon',
requiresReprocessing: true,
},
{
id: 'lGateIcon',
type: 'icon',
requiresReprocessing: true,
},
{
id: 'shroudTunnelIcon',
type: 'icon',
requiresReprocessing: true,
},
],
},
Expand Down

0 comments on commit a33fa32

Please sign in to comment.