library

Online co-op book organization video game
git clone https://git.bradleygannon.com/library.git
Log | Files | Refs

commit e6fdc7a48fe32e03c74b661e721a7769fc5bd4d5
parent 8bd43575af176dcf239b6e1a5ed33d16a67ebffd
Author: Bradley Gannon <bradley@bradleygannon.com>
Date:   Sun, 30 Aug 2026 18:32:40 -0400

Save player name and server to config file

Diffstat:
MCargo.lock | 187++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mclient/Cargo.toml | 1+
Mclient/src/main.rs | 31++++++++++++++++++++++---------
3 files changed, 208 insertions(+), 11 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -62,6 +62,7 @@ version = "0.1.0" dependencies = [ "anyhow", "common", + "confy", "macroquad", "mio", "postcard", @@ -98,6 +99,19 @@ dependencies = [ ] [[package]] +name = "confy" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8807c397789cbe02bbdb1a27ea5f345584132808697b2a3f957c829829ee4814" +dependencies = [ + "etcetera", + "lazy_static", + "serde", + "thiserror", + "toml", +] + +[[package]] name = "core_maths" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -134,6 +148,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] +name = "etcetera" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26c7b13d0780cb82722fd59f6f57f925e143427e4a75313a6c77243bf5326ae6" +dependencies = [ + "cfg-if", + "home", + "windows-sys 0.59.0", +] + +[[package]] name = "fdeflate" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -164,7 +189,7 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7894823fa221401399e2598f8b63f81ac77ff5c63248b7656779bff1632d7d3d" dependencies = [ - "hashbrown", + "hashbrown 0.15.5", "ttf-parser", ] @@ -224,6 +249,21 @@ dependencies = [ ] [[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "home" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] name = "image" version = "0.24.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -237,6 +277,16 @@ dependencies = [ ] [[package]] +name = "indexmap" +version = "2.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07aa2048142242915a31d35844fb311e0e53fcca590c3a0a40dcf1b841fa09eb" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", +] + +[[package]] name = "js-sys" version = "0.3.104" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -331,7 +381,7 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -462,6 +512,15 @@ dependencies = [ ] [[package]] +name = "serde_spanned" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26" +dependencies = [ + "serde_core", +] + +[[package]] name = "server" version = "0.1.0" dependencies = [ @@ -529,6 +588,45 @@ dependencies = [ ] [[package]] +name = "toml" +version = "0.9.12+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf92845e79fc2e2def6a5d828f0801e29a2f8acc037becc5ab08595c7d5e9863" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow 0.7.15", +] + +[[package]] +name = "toml_datetime" +version = "0.7.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d38ac1cf9b95face32296c0a3ede1fdc270627c9d9c02a7274dd6d960dc4d56" +dependencies = [ + "winnow 1.0.4", +] + +[[package]] +name = "toml_writer" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2" + +[[package]] name = "ttf-parser" version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -636,9 +734,94 @@ checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ "windows-link", ] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" + +[[package]] +name = "winnow" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81" diff --git a/client/Cargo.toml b/client/Cargo.toml @@ -7,6 +7,7 @@ default-run = "client" [dependencies] anyhow = "1.0.104" common = { path = "../common/" } +confy = "2.0.0" macroquad = { version = "0.4.16", features = ["glam-serde"] } mio = { version = "1.2.2", features = ["net", "os-poll"] } postcard = { version = "1.1.3", default-features = false, features = ["use-std"] } diff --git a/client/src/main.rs b/client/src/main.rs @@ -14,6 +14,7 @@ use macroquad::{ widgets::{Button, InputText, Label}, }, }; +use serde::{Deserialize, Serialize}; use uuid::Uuid; use crate::{ @@ -28,6 +29,15 @@ pub mod game; pub mod net; pub mod render; +const CONFY_APP_NAME: &str = "library-game"; +const CONFY_CONFIG_NAME: &str = "config"; + +#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] +struct Config { + player_name: String, + server: String, +} + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] enum ViewMode { #[default] @@ -51,8 +61,7 @@ struct ClientState { dt: Duration, tx: Option<Sender<Action>>, rx: Option<Receiver<Response>>, - player_name: String, - server: String, + config: Config, menu_error: String, } @@ -73,8 +82,7 @@ impl Default for ClientState { dt: Duration::ZERO, tx: None, rx: None, - player_name: String::new(), - server: String::new(), + config: confy::load(CONFY_APP_NAME, Some(CONFY_CONFIG_NAME)).unwrap_or_default(), menu_error: String::new(), } } @@ -96,7 +104,7 @@ impl ClientState { self.sequence_number, id, ActionKind::Join { - name: self.player_name.clone(), + name: self.config.player_name.clone(), }, ); if let Some(ref mut tx) = self.tx @@ -174,21 +182,21 @@ async fn main() { .position(menu_top_left) .size(ELEMENT_SIZE) .margin(Vec2::ZERO) - .ui(&mut ui, &mut client.player_name); + .ui(&mut ui, &mut client.config.player_name); InputText::new(hash!()) .label("server") .position(menu_top_left) .size(ELEMENT_SIZE) .margin(Vec2::ZERO) - .ui(&mut ui, &mut client.server); + .ui(&mut ui, &mut client.config.server); let connect_button_clicked = Button::new("connect") .position(menu_top_left + ELEMENT_PITCH * 2.) .size(ELEMENT_SIZE) .ui(&mut ui); let addr = if connect_button_clicked || is_key_pressed(KeyCode::Enter) { - if let Ok(addr) = client.server.parse::<SocketAddr>() { + if let Ok(addr) = client.config.server.parse::<SocketAddr>() { Some(addr) - } else if client.player_name.is_empty() { + } else if client.config.player_name.is_empty() { client.menu_error = "enter your name pls".to_string(); None } else { @@ -206,6 +214,11 @@ async fn main() { ui.set_input_focus(name_input_token); } if let Some(addr) = addr { + let _ = confy::store( + CONFY_APP_NAME, + Some(CONFY_CONFIG_NAME), + client.config.clone(), + ); let (client_to_server_tx, client_to_server_rx) = channel(); let (server_to_client_tx, server_to_client_rx) = channel(); thread::spawn(move || {