diff options
| author | 2026-01-20 13:44:21 +0800 | |
|---|---|---|
| committer | 2026-01-20 13:44:21 +0800 | |
| commit | 7338b8627833018a0e3c05c3c4f3cc7fc182e8d2 (patch) | |
| tree | 23e39e5603aadc10d6b2d7efad063c68f357a860 /packages/ui/src/stores/game.svelte.ts | |
| parent | dbf781a35b96252e0199fec4337515651e49a8f6 (diff) | |
| parent | cf6cd6ba667b35e352b705946420cf4acab2b004 (diff) | |
| download | DropOut-7338b8627833018a0e3c05c3c4f3cc7fc182e8d2.tar.gz DropOut-7338b8627833018a0e3c05c3c4f3cc7fc182e8d2.zip | |
[Chore] branch: Sync with main (#75)
Diffstat (limited to 'packages/ui/src/stores/game.svelte.ts')
| -rw-r--r-- | packages/ui/src/stores/game.svelte.ts | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/packages/ui/src/stores/game.svelte.ts b/packages/ui/src/stores/game.svelte.ts new file mode 100644 index 0000000..504d108 --- /dev/null +++ b/packages/ui/src/stores/game.svelte.ts @@ -0,0 +1,78 @@ +import { invoke } from "@tauri-apps/api/core"; +import type { Version } from "../types"; +import { uiState } from "./ui.svelte"; +import { authState } from "./auth.svelte"; +import { instancesState } from "./instances.svelte"; + +export class GameState { + versions = $state<Version[]>([]); + selectedVersion = $state(""); + + constructor() { + // Constructor intentionally empty + // Instance switching handled in App.svelte with $effect + } + + get latestRelease() { + return this.versions.find((v) => v.type === "release"); + } + + async loadVersions(instanceId?: string) { + const id = instanceId || instancesState.activeInstanceId; + if (!id) { + this.versions = []; + return; + } + + try { + this.versions = await invoke<Version[]>("get_versions", { + instanceId: id, + }); + // Don't auto-select version here - let BottomBar handle version selection + // based on installed versions only + } catch (e) { + console.error("Failed to fetch versions:", e); + uiState.setStatus("Error fetching versions: " + e); + } + } + + async startGame() { + if (!authState.currentAccount) { + alert("Please login first!"); + authState.openLoginModal(); + return; + } + + if (!this.selectedVersion) { + alert("Please select a version!"); + return; + } + + if (!instancesState.activeInstanceId) { + alert("Please select an instance first!"); + uiState.setView("instances"); + return; + } + + uiState.setStatus("Preparing to launch " + this.selectedVersion + "..."); + console.log( + "Invoking start_game for version:", + this.selectedVersion, + "instance:", + instancesState.activeInstanceId, + ); + try { + const msg = await invoke<string>("start_game", { + instanceId: instancesState.activeInstanceId, + versionId: this.selectedVersion, + }); + console.log("Response:", msg); + uiState.setStatus(msg); + } catch (e) { + console.error(e); + uiState.setStatus("Error: " + e); + } + } +} + +export const gameState = new GameState(); |