Skip to content

Commit 0973558

Browse files
feat(ui): add app settings screen and refactor map settings
1 parent a7d1782 commit 0973558

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1867
-1620
lines changed

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ base64 = "0.21.7"
2323
image_dds = { version = "0.4.0", default-features = false, features = ["ddsfile", "image", "decode"] }
2424
ddsfile = "0.5.2"
2525
logos = "0.14.0"
26-
tauri = { version = "1.6", features = ["dialog-open", "dialog-save", "fs-write-file", "os-all", "path-all", "shell-open"] }
26+
tauri = { version = "1.6", features = [ "fs-read-file", "fs-exists", "fs-create-dir", "dialog-open", "dialog-save", "fs-write-file", "os-all", "path-all", "shell-open"] }
2727

2828
[features]
2929
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.

src-tauri/tauri.conf.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
"save": true
2323
},
2424
"fs": {
25-
"scope": ["$PICTURE/*"],
26-
"writeFile": true
25+
"scope": ["$PICTURE/*", "$APPCONFIG", "$APPCONFIG/*"],
26+
"exists": true,
27+
"createDir": true,
28+
"writeFile": true,
29+
"readFile": true
2730
},
2831
"os": {
2932
"all": true

src/preload/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,20 @@ const api: StellarMapsAPI = {
2424
path: {
2525
join: (...paths: string[]) => Promise.resolve(path.join(...paths)),
2626
pictureDir: () => platformPaths.pictures(),
27+
appConfigDir: () =>
28+
platformPaths.home().then((home) => `${home}/.config/games.michaelmakes.stellarmaps`),
2729
},
2830
fs: {
2931
writeFile: (path, content) => fs.writeFile(path, content, { encoding: 'utf-8' }),
3032
writeBinaryFile: (path, content) => fs.writeFile(path, new DataView(content)),
33+
createDir: (path, options) =>
34+
fs.mkdir(path, options.recursive ? options : undefined).then(() => {}),
35+
exists: (path) =>
36+
fs
37+
.lstat(path)
38+
.then(() => true)
39+
.catch(() => false),
40+
readTextFile: (path) => fs.readFile(path, { encoding: 'utf-8' }),
3141
},
3242
revealFile: (path) => Promise.resolve(shell.showItemInFolder(path)),
3343
};

src/renderer/src/App.svelte

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@
55
AppShell,
66
Modal,
77
Toast,
8+
getModalStore,
89
initializeStores,
910
storePopup,
1011
} from '@skeletonlabs/skeleton';
1112
import './app.postcss';
1213
import { t } from './intl';
14+
import AppSettingsModal from './lib/AppSettingsModal.svelte';
1315
import ExportModal from './lib/ExportModal.svelte';
1416
import Sidebar from './lib/Sidebar.svelte';
1517
import VersionInfo from './lib/VersionInfo.svelte';
1618
import Discord from './lib/icons/Discord.svelte';
19+
import HeroiconCog6ToothSolid from './lib/icons/HeroiconCog6ToothSolid.svelte';
1720
import MapContainer from './lib/map/MapContainer.svelte';
1821
1922
initializeStores();
2023
storePopup.set({ computePosition, autoUpdate, offset, shift, flip, arrow });
24+
25+
const modalStore = getModalStore();
2126
</script>
2227

2328
<Toast position="t" background="variant-filled-error" />
24-
<Modal components={{ export: { ref: ExportModal } }} />
29+
<Modal components={{ export: { ref: ExportModal }, settings: { ref: AppSettingsModal } }} />
2530
<AppShell slotPageContent="h-full" regionPage="h-full">
2631
<svelte:fragment slot="header">
2732
<AppBar>
@@ -33,6 +38,13 @@
3338
<a class="anchor" href="https://discord.gg/72kaXW782b" target="_blank" rel="noopener">
3439
<Discord />
3540
</a>
41+
<div class="mx-2 h-6 border-r border-r-surface-500"></div>
42+
<button
43+
type="button"
44+
on:click={() => modalStore.trigger({ type: 'component', component: 'settings' })}
45+
>
46+
<HeroiconCog6ToothSolid />
47+
</button>
3648
</svelte:fragment>
3749
</AppBar>
3850
</svelte:fragment>

src/renderer/src/intl/en-US.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default {
3030
enabled: 'Enabled',
3131
disabled: 'Disabled',
3232
cancel_button: 'Cancel',
33+
close_button: 'Close',
3334
loading: 'Loading...',
3435
confirmation: 'Are you sure?',
3536
},
@@ -83,6 +84,11 @@ export default {
8384
export_png_button: 'Export PNG',
8485
processing: 'Processing...',
8586
},
87+
// messages in the app settings popup
88+
app_settings: {
89+
title: 'Settings',
90+
description: 'All changes are automatically saved and applied.',
91+
},
8692
// labels for various types of setting controls
8793
// (shared by multiple settings)
8894
control: {
@@ -291,11 +297,12 @@ export default {
291297
hyperlaneSensitiveBorders_tooltip: `<ul>
292298
<li>When enabled, borders will follow hyperlanes.</li>
293299
<li>When disabled, only solar systems affect borders.</li>
294-
<li>Not supported if the following are enabled:</li>
295-
<li><ul>
296-
<li>Metro-style Hyperlanes</li>
297-
<li>Align Solar Systems to Grid</li>
298-
</ul></li>
300+
<li>Not supported if the following are enabled:
301+
<ul>
302+
<li>Metro-style Hyperlanes</li>
303+
<li>Align Solar Systems to Grid</li>
304+
</ul>
305+
</li>
299306
</ul>`,
300307
voronoiGridSize: 'Voronoi Grid Size',
301308
voronoiGridSize_tooltip: `<ul>
@@ -328,5 +335,8 @@ export default {
328335
starScapeStars: 'Stars',
329336
starScapeStarsColor: 'Stars Color',
330337
starScapeStarsCount: 'Star Count',
338+
appLocale: 'StellarMaps Language',
339+
appStellarisLanguage: 'Stellaris Language',
340+
appTranslatorMode: 'Translator Mode',
331341
},
332342
};

src/renderer/src/intl/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ function flattenMessages(messages: UnflattenedMessages, prefix = ''): Record<str
2323

2424
const locales = {
2525
'en-US': flattenMessages(enUS) as Record<MessageID, string>,
26-
placeholder: flattenMessages(enUS) as Partial<Record<MessageID, string>>,
26+
ENGLISH: Object.fromEntries(
27+
Object.entries(flattenMessages(enUS)).map(([k, v]) => [k, v.toUpperCase()]),
28+
) as Partial<Record<MessageID, string>>,
2729
};
2830
type Locale = keyof typeof locales;
2931

30-
console.warn(locales);
31-
3232
function getBestLocale(): Locale {
3333
const keys = Object.keys(locales) as [Locale, ...Locale[]];
3434
return (
@@ -41,7 +41,7 @@ function getBestLocale(): Locale {
4141
);
4242
}
4343

44-
const locale = writable<Locale>(getBestLocale());
44+
export const locale = writable<Locale>(getBestLocale());
4545

4646
export const t = derived(locale, (localeKey) => {
4747
const messages: Record<string, IntlMessageFormat> = {};
@@ -55,9 +55,6 @@ export const t = derived(locale, (localeKey) => {
5555
locales[localeKey][messageId] ?? locales['en-US'][messageId],
5656
localeKey,
5757
);
58-
if (values) {
59-
console.warn(message.format(values));
60-
}
6158
return `${message.format(values)}`;
6259
};
6360
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script>
2+
import { t } from '../intl';
3+
import SettingControl from './SettingControl/index.svelte';
4+
import { appSettings, appSettingsConfig, asUnknownSettingConfig } from './settings';
5+
</script>
6+
7+
<form
8+
class="bg-surface-100-800-token modal block h-auto w-[32rem] space-y-4 overflow-y-auto p-4 shadow-xl rounded-container-token"
9+
role="dialog"
10+
aria-modal="true"
11+
novalidate
12+
>
13+
<header class="modal-header text-2xl font-bold">{$t('app_settings.title')}</header>
14+
<p>{$t('app_settings.description')}</p>
15+
<div class="flex flex-col gap-4">
16+
{#each appSettingsConfig as config}
17+
<SettingControl config={asUnknownSettingConfig(config)} settings={appSettings} />
18+
{/each}
19+
</div>
20+
<footer class="modal-footer flex justify-end space-x-2">
21+
<button class="variant-ghost-surface btn" type="button">{$t('generic.close_button')}</button>
22+
</footer>
23+
</form>

src/renderer/src/lib/ApplyChangesButton.svelte

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
import { t } from '../intl';
33
import HeroiconPaintBrushMini from './icons/HeroiconPaintBrushMini.svelte';
44
import {
5+
asUnknownSettingConfig,
56
editedMapSettings,
6-
mapSettingConfig,
77
mapSettings,
8+
mapSettingsConfig,
89
settingsAreDifferent,
910
validateSetting,
10-
} from './mapSettings';
11+
} from './settings';
1112
1213
$: shouldShow = settingsAreDifferent($editedMapSettings, $mapSettings);
13-
$: valid = mapSettingConfig
14+
$: valid = mapSettingsConfig
1415
.flatMap((category) => category.settings)
15-
.every((config) => validateSetting($editedMapSettings[config.id], config)[0]);
16+
.every(
17+
(config) => validateSetting($editedMapSettings[config.id], asUnknownSettingConfig(config))[0],
18+
);
1619
</script>
1720

1821
{#if shouldShow}

src/renderer/src/lib/ExportModal.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import type { MapData } from './map/data/processMapData';
1313
import { getBackgroundColor, getFillColorAttributes, resolveColor } from './map/mapUtils';
1414
import processStarScape from './map/starScape/renderStarScape';
15-
import { mapSettings } from './mapSettings';
15+
import { mapSettings } from './settings';
1616
import stellarMapsApi from './stellarMapsApi';
1717
import { toastError } from './utils';
1818

0 commit comments

Comments
 (0)