DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

aab10455fd1c6556d71bdbc1756c49e417b6d153 — Jonni Liljamo 1 year, 11 months ago 1fdcbae
sl changes and fixes
1 files changed, 13 insertions(+), 8 deletions(-)

M sdbclient/src/util/sl.rs
M sdbclient/src/util/sl.rs => sdbclient/src/util/sl.rs +13 -8
@@ 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<T: Default + for<'a> serde::Deserialize<'a>>(
    file_path: &str,
    mut console: EventWriter<PrintConsoleLine>,
    target_dir: &str,
    file_name: &str,
    console: &mut EventWriter<PrintConsoleLine>,
) -> 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<u8> = std::fs::read(file_path.clone()).unwrap();
            serde_json::from_str(std::str::from_utf8(&yaml).unwrap()).expect(&format!(
            let json: Vec<u8> = 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<T>(
    target_dir: &str,
    file_name: &str,
    value: &T,
    mut console: EventWriter<PrintConsoleLine>,
    console: &mut EventWriter<PrintConsoleLine>,
) -> 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 '{}'",