diff --git a/Cargo.lock b/Cargo.lock index f997410..ba6a16a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -554,6 +554,7 @@ version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" dependencies = [ + "indexmap", "serde", "serde_spanned", "toml_datetime", diff --git a/Cargo.toml b/Cargo.toml index b6f9e18..a881529 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ edition = "2021" criterion = "0.5.1" divan = "0.1.14" serde = { version = "1.0.197", features = ["derive"] } -toml = "0.8.12" +toml = { version = "0.8.12", features = ["preserve_order"] } [profile.dev] debug = 0 diff --git a/src/data_structure.rs b/src/data_structure.rs index ea09cb1..10bcb77 100644 --- a/src/data_structure.rs +++ b/src/data_structure.rs @@ -2,11 +2,9 @@ //! //! The `data_structure` module provides data structures for representing the loaded sections of a character or a model. //! -//! To ensure correct usage of all datastructures, the following flow is applied -//! -//! Data -> CS_Raw -> CS_Empty -> CS_Ready -//! -> CH_Raw -> CH_Empty -> CH_Ready + use serde::Deserialize; +use toml::Table; #[derive(Deserialize, Debug)] pub struct GlobalConfig { @@ -29,7 +27,7 @@ struct Config { /// The data needed to generate a CharacterSheet this data is not implementation agnostic for now #[derive(Deserialize, Debug)] -struct Data { +pub struct Data { /// Head section head: String, /// Eventual custom script @@ -42,6 +40,11 @@ struct Data { css_footer: String, } +// #[derive(Deserialize, Debug)] +// pub struct SkillsData { +// sections: , +// } + // #[cfg(test)] // mod tests { // use super::{Config, Data, GlobalConfig}; diff --git a/src/generator.rs b/src/generator.rs index e90ec32..e5986da 100644 --- a/src/generator.rs +++ b/src/generator.rs @@ -6,20 +6,36 @@ //! Data -> CS_Raw -> CS_Empty -> CS_Ready //! -> CH_Raw -> CH_Ready -^ +use std::path::Path; + +use crate::{ + data_structure::Data, + loader::{LoadError, SheetModel}, +}; + /// A raw CharacterSheet, with everything ready to generate all fields -pub struct CS_Raw {} +pub trait CsRaw { + fn from_data(data: &Data) -> Self; + fn build(&self) -> impl CsEmpty; +} /// A build CharacterSheet, ready to be filled with the skills loaded -pub struct CS_Empty {} +pub trait CsEmpty { + fn fill(&self, skills: &impl ChRaw) -> impl ChReady; +} /// A finished CharacterSheet, ready to be exported -pub struct CS_Ready {} +pub trait CsReady { + fn export(&self, path: T) -> Result<(), LoadError>; +} /// A raw SkillList, loaded from file, ready to generate all skills -pub struct CH_Raw {} +pub trait ChRaw { + fn from_data(data: &SheetModel) -> impl ChReady; +} /// A build SkillList, ready to be added to a CharacterSheet -pub struct CH_Ready {} +pub trait ChReady {} /// Can generate a character sheet pub trait Generator {