From f878efe456e8f5c557f2cde9d71f120f3e0b38cd Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Tue, 13 Jan 2026 14:31:37 +0800 Subject: feat: add Minecraft DropOut launcher with version fetching and basic UI - Implemented version manifest fetching from Mojang API. - Created launcher configuration and main launcher logic. - Added SVG and PNG icons for the application. - Developed a simple HTML/CSS interface for the launcher. - Integrated Tauri commands for backend communication. - Added utility functions for file operations and config parsing. --- src-tauri/src/core/manifest.rs | 31 +++++++++++++++++++++++++++++++ src-tauri/src/core/mod.rs | 1 + src-tauri/src/launcher/config.rs | 13 +++++++++++++ src-tauri/src/launcher/launcher.rs | 15 +++++++++++++++ src-tauri/src/launcher/mod.rs | 19 +++++++++++++++++++ src-tauri/src/main.rs | 32 ++++++++++++++++++++++++++++++++ src-tauri/src/utils/mod.rs | 34 ++++++++++++++++++++++++++++++++++ 7 files changed, 145 insertions(+) create mode 100644 src-tauri/src/core/manifest.rs create mode 100644 src-tauri/src/core/mod.rs create mode 100644 src-tauri/src/launcher/config.rs create mode 100644 src-tauri/src/launcher/launcher.rs create mode 100644 src-tauri/src/launcher/mod.rs create mode 100644 src-tauri/src/main.rs create mode 100644 src-tauri/src/utils/mod.rs (limited to 'src-tauri/src') diff --git a/src-tauri/src/core/manifest.rs b/src-tauri/src/core/manifest.rs new file mode 100644 index 0000000..1450e77 --- /dev/null +++ b/src-tauri/src/core/manifest.rs @@ -0,0 +1,31 @@ +use serde::Deserialize; +use std::error::Error; + +#[derive(Debug, Deserialize)] +pub struct VersionManifest { + pub latest: Latest, + pub versions: Vec, +} + +#[derive(Debug, Deserialize)] +pub struct Latest { + pub release: String, + pub snapshot: String, +} + +#[derive(Debug, Deserialize)] +pub struct Version { + pub id: String, + #[serde(rename = "type")] + pub type_: String, + pub url: String, + pub time: String, + #[serde(rename = "releaseTime")] + pub release_time: String, +} + +pub async fn fetch_version_manifest() -> Result> { + let url = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"; + let resp = reqwest::get(url).await?.json::().await?; + Ok(resp) +} diff --git a/src-tauri/src/core/mod.rs b/src-tauri/src/core/mod.rs new file mode 100644 index 0000000..640fc64 --- /dev/null +++ b/src-tauri/src/core/mod.rs @@ -0,0 +1 @@ +pub mod manifest; diff --git a/src-tauri/src/launcher/config.rs b/src-tauri/src/launcher/config.rs new file mode 100644 index 0000000..fafc229 --- /dev/null +++ b/src-tauri/src/launcher/config.rs @@ -0,0 +1,13 @@ +pub struct Config { + pub username: String, + pub resolution: (u32, u32), +} + +impl Config { + pub fn new(username: &str, resolution: (u32, u32)) -> Self { + Config { + username: username.to_string(), + resolution, + } + } +} \ No newline at end of file diff --git a/src-tauri/src/launcher/launcher.rs b/src-tauri/src/launcher/launcher.rs new file mode 100644 index 0000000..5ccf443 --- /dev/null +++ b/src-tauri/src/launcher/launcher.rs @@ -0,0 +1,15 @@ +pub struct Launcher { + pub config: crate::launcher::config::Config, +} + +impl Launcher { + pub fn new(config: crate::launcher::config::Config) -> Self { + Launcher { config } + } + + pub fn launch(&self) { + // 启动游戏的逻辑 + println!("启动游戏,用户名: {}", self.config.username); + println!("分辨率: {}x{}", self.config.resolution.0, self.config.resolution.1); + } +} \ No newline at end of file diff --git a/src-tauri/src/launcher/mod.rs b/src-tauri/src/launcher/mod.rs new file mode 100644 index 0000000..0359d3e --- /dev/null +++ b/src-tauri/src/launcher/mod.rs @@ -0,0 +1,19 @@ +pub mod config; +pub mod launcher; + +pub use config::Config; +pub use launcher::Launcher; + +pub fn start() { + // 启动器的代码 + println!("启动器启动中..."); + + // 创建配置 + let config = Config::new("玩家", (1920, 1080)); + + // 创建启动器 + let launcher = Launcher::new(config); + + // 启动游戏 + launcher.launch(); +} \ No newline at end of file diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs new file mode 100644 index 0000000..fdd0794 --- /dev/null +++ b/src-tauri/src/main.rs @@ -0,0 +1,32 @@ +// Prevents additional console window on Windows in release, DO NOT REMOVE!! +#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] + +mod core; +mod launcher; + +#[tauri::command] +async fn start_game() -> Result { + println!("Backend received StartGame"); + match core::manifest::fetch_version_manifest().await { + Ok(manifest) => { + let msg = format!( + "Fetched manifest.\nLatest release: {}\nLatest snapshot: {}", + manifest.latest.release, manifest.latest.snapshot + ); + println!("{}", msg); + Ok(msg) + } + Err(e) => { + eprintln!("Error fetching manifest: {}", e); + Err(e.to_string()) + } + } +} + +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_shell::init()) + .invoke_handler(tauri::generate_handler![start_game]) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); +} diff --git a/src-tauri/src/utils/mod.rs b/src-tauri/src/utils/mod.rs new file mode 100644 index 0000000..088da95 --- /dev/null +++ b/src-tauri/src/utils/mod.rs @@ -0,0 +1,34 @@ +// utils/mod.rs +pub mod file_utils; +pub mod config_parser; + +// 文件操作相关的实用工具函数 +pub mod file_utils { + use std::fs; + use std::io::{self, Write}; + + pub fn read_file_to_string(path: &str) -> io::Result { + fs::read_to_string(path) + } + + pub fn write_string_to_file(path: &str, content: &str) -> io::Result<()> { + let mut file = fs::File::create(path)?; + file.write_all(content.as_bytes()) + } +} + +// 配置解析相关的实用工具函数 +pub mod config_parser { + use std::collections::HashMap; + + pub fn parse_config(content: &str) -> HashMap { + let mut config = HashMap::new(); + for line in content.lines() { + let mut parts = line.splitn(2, '='); + if let (Some(key), Some(value)) = (parts.next(), parts.next()) { + config.insert(key.trim().to_string(), value.trim().to_string()); + } + } + config + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2