aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/packages/ui/src/stores/game.svelte.ts
diff options
context:
space:
mode:
author苏向夜 <fu050409@163.com>2026-01-19 14:17:32 +0800
committer苏向夜 <fu050409@163.com>2026-01-19 14:17:32 +0800
commitda0d79f0db873c08fab3bc85023167e174d18b0e (patch)
tree4a1934780d0d723ec8b834088188d4714f2cf3e7 /packages/ui/src/stores/game.svelte.ts
parent887e415314014c3da7db3048fa0e724f3078c5cb (diff)
downloadDropOut-da0d79f0db873c08fab3bc85023167e174d18b0e.tar.gz
DropOut-da0d79f0db873c08fab3bc85023167e174d18b0e.zip
chore(ui): refactor workspace to monorepo
Diffstat (limited to 'packages/ui/src/stores/game.svelte.ts')
-rw-r--r--packages/ui/src/stores/game.svelte.ts78
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();