diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/manifest.rs | 31 | ||||
| -rw-r--r-- | src/core/mod.rs | 1 | ||||
| -rw-r--r-- | src/launcher/config.rs | 13 | ||||
| -rw-r--r-- | src/launcher/launcher.rs | 15 | ||||
| -rw-r--r-- | src/launcher/mod.rs | 19 | ||||
| -rw-r--r-- | src/main.rs | 39 | ||||
| -rw-r--r-- | src/ui/mod.rs | 39 | ||||
| -rw-r--r-- | src/utils/mod.rs | 34 |
8 files changed, 0 insertions, 191 deletions
diff --git a/src/core/manifest.rs b/src/core/manifest.rs deleted file mode 100644 index 1450e77..0000000 --- a/src/core/manifest.rs +++ /dev/null @@ -1,31 +0,0 @@ -use serde::Deserialize; -use std::error::Error; - -#[derive(Debug, Deserialize)] -pub struct VersionManifest { - pub latest: Latest, - pub versions: Vec<Version>, -} - -#[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<VersionManifest, Box<dyn Error>> { - let url = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json"; - let resp = reqwest::get(url).await?.json::<VersionManifest>().await?; - Ok(resp) -} diff --git a/src/core/mod.rs b/src/core/mod.rs deleted file mode 100644 index 640fc64..0000000 --- a/src/core/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod manifest; diff --git a/src/launcher/config.rs b/src/launcher/config.rs deleted file mode 100644 index fafc229..0000000 --- a/src/launcher/config.rs +++ /dev/null @@ -1,13 +0,0 @@ -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/launcher/launcher.rs b/src/launcher/launcher.rs deleted file mode 100644 index 5ccf443..0000000 --- a/src/launcher/launcher.rs +++ /dev/null @@ -1,15 +0,0 @@ -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/launcher/mod.rs b/src/launcher/mod.rs deleted file mode 100644 index 0359d3e..0000000 --- a/src/launcher/mod.rs +++ /dev/null @@ -1,19 +0,0 @@ -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/main.rs b/src/main.rs deleted file mode 100644 index 9161263..0000000 --- a/src/main.rs +++ /dev/null @@ -1,39 +0,0 @@ -mod core; -mod launcher; -mod ui; - -use tokio::sync::mpsc; -use tokio::runtime::Runtime; -use std::thread; - -fn main() { - // channel for UI -> Backend - let (tx, mut rx) = mpsc::channel(32); - - // Spawn Tokio runtime in a background thread - thread::spawn(move || { - let rt = Runtime::new().unwrap(); - rt.block_on(async move { - println!("Backend started"); - while let Some(msg) = rx.recv().await { - match msg { - ui::UiEvent::StartGame => { - println!("Backend received StartGame"); - match core::manifest::fetch_version_manifest().await { - Ok(manifest) => { - println!("Fetched manifest. Latest release: {}", manifest.latest.release); - println!("Latest snapshot: {}", manifest.latest.snapshot); - } - Err(e) => { - eprintln!("Error fetching manifest: {}", e); - } - } - } - } - } - }); - }); - - // Run UI on main thread (must be main thread for GTK on some platforms) - ui::init(tx); -} diff --git a/src/ui/mod.rs b/src/ui/mod.rs deleted file mode 100644 index 3ee1e6a..0000000 --- a/src/ui/mod.rs +++ /dev/null @@ -1,39 +0,0 @@ -use gtk::prelude::*; -use gtk::{Button, Window, WindowType}; -use tokio::sync::mpsc::Sender; - -pub enum UiEvent { - StartGame, -} - -pub fn init(tx: Sender<UiEvent>) { - if gtk::init().is_err() { - println!("Failed to initialize GTK."); - return; - } - - let window = Window::new(WindowType::Toplevel); - window.set_title("Minecraft 启动器"); - window.set_default_size(350, 70); - - let button = Button::with_label("开始游戏"); - let tx_clone = tx.clone(); - button.connect_clicked(move |_| { - println!("开始游戏按钮被点击"); - // Use blocking_send because we are in a synchronous callback - if let Err(e) = tx_clone.blocking_send(UiEvent::StartGame) { - eprintln!("Failed to send event: {}", e); - } - }); - - window.add(&button); - - window.connect_delete_event(|_, _| { - gtk::main_quit(); - Inhibit(false) - }); - - window.show_all(); - - gtk::main(); -} diff --git a/src/utils/mod.rs b/src/utils/mod.rs deleted file mode 100644 index 088da95..0000000 --- a/src/utils/mod.rs +++ /dev/null @@ -1,34 +0,0 @@ -// 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<String> { - 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<String, String> { - 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 |