Adds more parsing

This commit is contained in:
Dandaedre 2024-04-08 21:31:12 +02:00
parent 2af2398389
commit a4b1206cb0
2 changed files with 52 additions and 70 deletions

View File

@ -3,7 +3,7 @@ use std::{fs, path::Path};
use crate::{
loader::LoadError,
skills_structures::{Renderable, Section, Skill, SkillList, SkillTypes, SubSection, SubSkill},
skills_structures::{Section, Skill, SkillList, SkillTypes, SubSection, SubSkill},
};
/// Defines a parser, able to extract a character sheet
@ -55,7 +55,7 @@ impl Parser<SkillList> for SkillList {
}
let list_sect = globlist.make_skilllist()?;
// Make a skillist with the given vec
let ls = SkillList::from_vec(&path.to_string(), 0, 0, Some(list_sect));
let ls = SkillList::from_vec(&path.to_string(), 0, 0, list_sect);
// let ls = SkillList::with_config(&ConfigList::new(path.to_string(), 0, 0, global_id));
// ls.populate(globlist);
Ok(ls)
@ -159,7 +159,7 @@ impl ListId {
return Err(LoadError::WrongHierarchy);
}
*index += 1;
let sec = SubSkill::from_vec::<SubSkill>(name, id, global_id, None);
let sec = SubSkill::from_vec(name, id, global_id);
Ok(sec)
}

View File

@ -35,11 +35,6 @@ impl ConfigList {
}
}
// trait NewTrait {
// /// Creates a new [`ConfigList`].
// fn new(name: String, id: usize, global_id: usize, capacity: usize) -> Self;
// }
/// The global list of skills
pub struct SkillList {
/// The list of all section in this skilllist
@ -56,6 +51,20 @@ impl SkillList {
data: DataCell::new(&cfg.name, cfg.id, cfg.global_id),
}
}
pub fn from_vec(name: &str, id: usize, global_id: usize, list_sect: Vec<Section>) -> SkillList {
Self {
list: list_sect,
data: DataCell::new(name, id, global_id),
}
}
}
/// A node, with a level instead of a hierarchy
pub struct Node {
list: Option<Vec<Node>>,
data: DataCell,
level: SkillTypes,
}
/// A section, marked by @
@ -64,12 +73,16 @@ pub struct Section {
pub list: Vec<SubSection>,
/// The name of the cell
data: DataCell,
// /// The identifier number of the cell
// id: usize,
// /// The global identifier of the cell
// global_id: usize,
// /// The various fields needed to transform a skill Section html
// vars: HashReplace,
}
impl Section {
pub(crate) fn from_vec(
name: &str,
id: usize,
global_id: usize,
list_subsection: Option<Vec<SubSection>>,
) -> Section {
todo!()
}
}
/// A subsection, marked by +
@ -78,12 +91,16 @@ pub struct SubSection {
pub list: Vec<Skill>,
/// The name of the cell
data: DataCell,
// /// The identifier number of the cell
// id: usize,
// /// The global identifier of the cell
// global_id: usize,
// /// The various fields needed to transform a subsection into html
// vars: HashReplace,
}
impl SubSection {
pub(crate) fn from_vec(
name: &str,
id: usize,
global_id: usize,
list_skills: Option<Vec<Skill>>,
) -> SubSection {
todo!()
}
}
/// A skill, marked by =
@ -92,20 +109,27 @@ pub struct Skill {
pub list: Vec<SubSkill>,
/// The name of the cell
data: DataCell,
// /// The identifier number of the cell
// id: usize,
// /// The global identifier of the cell
// global_id: usize,
// /// The various fields needed to transform a skill into html
// vars: HashMap<String, String>,
}
impl Skill {
pub(crate) fn from_vec(
name: &str,
id: usize,
global_id: usize,
list_subskills: Option<Vec<SubSection>>,
) -> Skill {
todo!()
}
}
/// A subskill, marked by -
pub struct SubSkill {
/// The name of the cell
data: DataCell,
// /// The various fields needed to transform a subskill into html
// vars: HashMap<String, String>,
}
impl SubSkill {
pub(crate) fn from_vec(name: &str, id: usize, global_id: usize) -> SubSkill {
todo!()
}
}
/// The data of a cell
@ -187,8 +211,6 @@ pub(crate) trait Renderable {
fn get_mut_data(&mut self) -> &DataCell;
/// Create a new renderable
fn new(name: &str, id: usize, global_id: usize, size_hint: usize) -> Self;
/// Create a renderable with a given vector
fn from_vec<T>(name: &str, id: usize, global_id: usize, data: Option<T>) -> Self;
/// Get the vars hashmap
fn get_vars(&self) -> HashReplace;
// /// Render the element and all sub elements
@ -229,14 +251,6 @@ impl Renderable for Section {
data: DataCell::new(name, id, global_id),
}
}
fn from_vec<T>(name: &str, id: usize, global_id: usize, data: Option<T>) -> Self {
let _ = id;
let _ = data;
let _ = global_id;
let _ = name;
todo!()
}
}
impl Renderable for SkillList {
@ -256,14 +270,6 @@ impl Renderable for SkillList {
fn get_vars(&self) -> HashReplace {
todo!()
}
fn from_vec<T>(name: &str, id: usize, global_id: usize, data: Option<T>) -> Self {
let _ = data;
let _ = global_id;
let _ = id;
let _ = name;
todo!()
}
}
impl Renderable for SubSection {
@ -279,14 +285,6 @@ impl Renderable for SubSection {
fn get_vars(&self) -> HashReplace {
todo!()
}
fn from_vec<T>(name: &str, id: usize, global_id: usize, data: Option<T>) -> Self {
let _ = data;
let _ = global_id;
let _ = id;
let _ = name;
todo!()
}
}
impl Renderable for Skill {
fn get_data(&self) -> &DataCell {
@ -304,14 +302,6 @@ impl Renderable for Skill {
fn get_vars(&self) -> HashReplace {
todo!()
}
fn from_vec<T>(name: &str, id: usize, global_id: usize, data: Option<T>) -> Self {
let _ = id;
let _ = global_id;
let _ = data;
let _ = name;
todo!()
}
}
impl Renderable for SubSkill {
fn get_data(&self) -> &DataCell {
@ -329,14 +319,6 @@ impl Renderable for SubSkill {
fn get_vars(&self) -> HashReplace {
todo!()
}
fn from_vec<T>(name: &str, id: usize, global_id: usize, data: Option<T>) -> Self {
let _ = id;
let _ = global_id;
let _ = data;
let _ = name;
todo!()
}
}
/// A parsable type for dispatch