aboutsummaryrefslogtreecommitdiff
path: root/pixel-client/src
diff options
context:
space:
mode:
Diffstat (limited to 'pixel-client/src')
-rw-r--r--pixel-client/src/config.rs43
-rw-r--r--pixel-client/src/main.rs3
-rw-r--r--pixel-client/src/render/misc.rs2
3 files changed, 47 insertions, 1 deletions
diff --git a/pixel-client/src/config.rs b/pixel-client/src/config.rs
new file mode 100644
index 00000000..6d74fbe7
--- /dev/null
+++ b/pixel-client/src/config.rs
@@ -0,0 +1,43 @@
+use anyhow::{anyhow, Result};
+use serde::{Deserialize, Serialize};
+use std::{
+ fs::{read_to_string, rename, File},
+ io::Write,
+ path::PathBuf,
+};
+
+#[derive(Serialize, Deserialize)]
+pub struct Config {
+ username: String,
+}
+
+impl Config {
+ pub fn path() -> Result<PathBuf> {
+ Ok(xdg::BaseDirectories::with_prefix("pixelcurry")?.place_config_file("config.toml")?)
+ }
+ pub fn load() -> Result<Self> {
+ let path = Self::path()?;
+ if path.exists() {
+ Ok(toml::from_str(&read_to_string(path)?)?)
+ } else {
+ File::create(path)?.write_all(toml::to_string(&Self::initial()?)?.as_bytes())?;
+ Self::load()
+ }
+ }
+ pub fn save(&self) -> Result<()> {
+ let path = Self::path()?;
+ let temp = path.with_added_extension("~");
+ File::create(&temp)?.write_all(toml::to_string(self)?.as_bytes())?;
+ rename(temp, path)?;
+ Ok(())
+ }
+ pub fn initial() -> Result<Self> {
+ Ok(Config {
+ username: users::get_current_username()
+ .ok_or(anyhow!("current user has no name"))?
+ .to_str()
+ .ok_or(anyhow!("current user's name is not valid UTF8"))?
+ .to_owned(),
+ })
+ }
+}
diff --git a/pixel-client/src/main.rs b/pixel-client/src/main.rs
index 23d99bc8..24421994 100644
--- a/pixel-client/src/main.rs
+++ b/pixel-client/src/main.rs
@@ -15,7 +15,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-#![feature(map_many_mut)]
+#![feature(map_many_mut, path_add_extension)]
use clap::{Parser, Subcommand};
use game::Game;
use hurrycurry_client_lib::network::sync::Network;
@@ -26,6 +26,7 @@ use render::Renderer;
use sdl2::{event::Event, keyboard::KeyboardState, mouse::MouseState, pixels::Color};
use std::time::{Duration, Instant};
+pub mod config;
pub mod game;
pub mod helper;
pub mod menu;
diff --git a/pixel-client/src/render/misc.rs b/pixel-client/src/render/misc.rs
index 2197b89c..7a631154 100644
--- a/pixel-client/src/render/misc.rs
+++ b/pixel-client/src/render/misc.rs
@@ -25,6 +25,7 @@ pub struct MiscTextures {
pub interact_target: Sprite,
pub solid: Rect,
pub clouds: Rect,
+ pub itembubble: Rect,
}
impl MiscTextures {
@@ -39,6 +40,7 @@ impl MiscTextures {
),
solid: *layout.get("solid+a").unwrap(),
clouds: *layout.get("clouds+a").unwrap(),
+ itembubble: *layout.get("itembubble+a").unwrap(),
}
}
}