diff options
-rw-r--r-- | Cargo.lock | 52 | ||||
-rw-r--r-- | client/player/controllable_player.gd | 12 | ||||
-rw-r--r-- | client/server_list.gd | 2 | ||||
-rw-r--r-- | server/Cargo.toml | 2 | ||||
-rw-r--r-- | server/src/scoreboard.rs | 26 |
5 files changed, 78 insertions, 16 deletions
@@ -647,6 +647,27 @@ dependencies = [ ] [[package]] +name = "directories" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f5094c54661b38d03bd7e50df373292118db60b585c08a411c6d840017fe7d" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.59.0", +] + +[[package]] name = "displaydoc" version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1268,6 +1289,7 @@ dependencies = [ "anyhow", "bincode", "clap", + "directories", "env_logger", "futures-util", "get_if_addrs", @@ -1287,7 +1309,6 @@ dependencies = [ "shlex", "tokio", "tokio-tungstenite", - "xdg", ] [[package]] @@ -1718,7 +1739,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -1728,6 +1749,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" [[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.9.1", + "libc", +] + +[[package]] name = "libyml" version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2037,6 +2068,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" [[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] name = "overload" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2483,6 +2520,17 @@ dependencies = [ ] [[package]] +name = "redox_users" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b" +dependencies = [ + "getrandom 0.2.16", + "libredox", + "thiserror 2.0.12", +] + +[[package]] name = "ref-cast" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/client/player/controllable_player.gd b/client/player/controllable_player.gd index 5fb99872..d329aeea 100644 --- a/client/player/controllable_player.gd +++ b/client/player/controllable_player.gd @@ -273,7 +273,7 @@ func update_interact_target_dirsnap(): var tile_center := Vector2(offset_cursor) + Vector2(0.5, 0.5) if game.get_tile_interactive(offset_cursor): - var cursor_tile_distance := (interact_target - tile_center).length() + var cursor_tile_distance := interact_target.distance_to(tile_center) var player_tile_distance := Vector2( movement_base.position.x - tile_center.x, movement_base.position.z - tile_center.y @@ -288,6 +288,7 @@ func update_interact_target_dirsnap(): # Check if there are any players on this tile. # If there are multilpe, remember the player closest to the center of the tile # (They will be the interact target) + var best_cursor_tile_distance := 100. var best_player_tile_distance := 100. var best_player_pos: Vector3 for p_id: int in player_positions.keys(): @@ -295,13 +296,16 @@ func update_interact_target_dirsnap(): var p_pos: Vector3 = player_positions[p_id] var p_pos_2d := Vector2(p_pos.x, p_pos.z) var tile_center_distance := p_pos_2d.distance_to(tile_center) + var cursor_tile_distance := interact_target.distance_to(tile_center) var player_tile_distance := Vector2(movement_base.position.x, movement_base.position.z).distance_to(tile_center) if tile_center_distance < 0.7: - if player_tile_distance < best_player_tile_distance: + if cursor_tile_distance < best_cursor_tile_distance: + best_cursor_tile_distance = cursor_tile_distance best_player_tile_distance = player_tile_distance best_player_pos = p_pos - if best_player_tile_distance < MAX_PLAYER_INTERACT_DIST && best_player_tile_distance < best_distance: + + if best_player_tile_distance < MAX_PLAYER_INTERACT_DIST && best_cursor_tile_distance < best_distance: found_interact_target = true - best_distance = best_player_tile_distance + best_distance = best_cursor_tile_distance target_visual = best_player_pos target_tile = offset_cursor diff --git a/client/server_list.gd b/client/server_list.gd index 32feb242..4e03a429 100644 --- a/client/server_list.gd +++ b/client/server_list.gd @@ -136,5 +136,3 @@ func _exit_tree(): if thread != null: thread.wait_to_finish() if pid != -1: OS.kill(pid) - var x = null - OS.kill(x) # TODO this somehow prevents a crash on exit; but is invalid according to docs diff --git a/server/Cargo.toml b/server/Cargo.toml index f23c2c7c..a90496d0 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -26,7 +26,7 @@ reqwest = { version = "0.12.19", optional = true, default-features = false, feat ] } pollster = "0.4.0" bincode = "2.0.1" -xdg = "3.0.0" +directories = "6.0.0" igd = { version = "0.12.1", optional = true, features = ["aio"] } get_if_addrs = { version = "0.5.3", optional = true } mdns-sd = { version = "0.13.9", optional = true } diff --git a/server/src/scoreboard.rs b/server/src/scoreboard.rs index f2fb86a2..421a110e 100644 --- a/server/src/scoreboard.rs +++ b/server/src/scoreboard.rs @@ -16,11 +16,13 @@ */ use anyhow::Result; +use directories::ProjectDirs; use hurrycurry_protocol::Score; +use log::warn; use serde::{Deserialize, Serialize}; use std::{cmp::Reverse, collections::HashMap}; use tokio::{ - fs::{read_to_string, rename, File}, + fs::{create_dir_all, read_to_string, rename, File}, io::AsyncWriteExt, }; @@ -39,22 +41,32 @@ pub struct ScoreboardEntry { pub score: Score, } +fn project_dirs() -> Option<ProjectDirs> { + ProjectDirs::from("org", "hurrycurry", "hurrycurry") +} + impl ScoreboardStore { pub async fn load() -> Result<Self> { - let path = - xdg::BaseDirectories::with_prefix("hurrycurry").place_data_file("scoreboards.json")?; + let Some(dir) = project_dirs() else { + warn!("scoreboard load skipped; no data dir for this platform"); + return Ok(Self::default()); + }; // TOCTOU because its easier that way + let path = dir.data_dir().join("scoreboards.json"); if !path.exists() { + create_dir_all(dir.data_dir()).await?; ScoreboardStore::default().save().await?; } let s = read_to_string(path).await?; Ok(serde_json::from_str(&s)?) } pub async fn save(&self) -> Result<()> { - let path = - xdg::BaseDirectories::with_prefix("hurrycurry").place_data_file("scoreboards.json")?; - let buffer_path = - xdg::BaseDirectories::with_prefix("hurrycurry").place_data_file("scoreboards.json~")?; + let Some(dir) = project_dirs() else { + warn!("scoreboard save skipped; no data dir for this platform"); + return Ok(()); + }; + let path = dir.data_dir().join("scoreboards.json"); + let buffer_path = dir.data_dir().join("scoreboards.json~"); File::create(&buffer_path) .await? .write_all(serde_json::to_string(self)?.as_bytes()) |