From aab10455fd1c6556d71bdbc1756c49e417b6d153 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Fri, 6 Jan 2023 13:05:34 +0200 Subject: [PATCH] sl changes and fixes --- sdbclient/src/util/sl.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/sdbclient/src/util/sl.rs b/sdbclient/src/util/sl.rs index dde58c6..a587af1 100644 --- a/sdbclient/src/util/sl.rs +++ b/sdbclient/src/util/sl.rs @@ -6,21 +6,26 @@ * See LICENSE for licensing information. */ +// TODO: We should encode the configs as base64 + use bevy::prelude::*; use bevy_console::PrintConsoleLine; pub fn load serde::Deserialize<'a>>( - file_path: &str, - mut console: EventWriter, + target_dir: &str, + file_name: &str, + console: &mut EventWriter, ) -> T { - match std::path::Path::new(file_path).exists() { + let file_path: String = format!("{}/{}", target_dir, file_name); + + match std::path::Path::new(&file_path).exists() { true => { console.send(PrintConsoleLine::new(format!( "sl::load found '{}'", file_path ))); - let yaml: Vec = std::fs::read(file_path.clone()).unwrap(); - serde_json::from_str(std::str::from_utf8(&yaml).unwrap()).expect(&format!( + let json: Vec = std::fs::read(file_path.clone()).unwrap(); + serde_json::from_str(std::str::from_utf8(&json).unwrap()).expect(&format!( "sl::load couldn't deserialize the config at '{}'", file_path )) @@ -39,13 +44,13 @@ pub fn save( target_dir: &str, file_name: &str, value: &T, - mut console: EventWriter, + console: &mut EventWriter, ) -> bool where T: ?Sized + serde::Serialize, { let file_path: String = format!("{}/{}", target_dir, file_name); - let yaml: String = serde_json::to_string(&value).unwrap(); + let json: String = serde_json::to_string(&value).unwrap(); match std::path::Path::new(target_dir).exists() { true => {} @@ -70,7 +75,7 @@ where } } - match std::fs::write(&file_path, yaml) { + match std::fs::write(&file_path, json) { Ok(_) => { console.send(PrintConsoleLine::new(format!( "sl::save wrote file '{}'", -- 2.44.1