Delete thes skilllist
This commit is contained in:
parent
b7148e3604
commit
5596c4564f
|
|
@ -1,7 +1,7 @@
|
|||
//! Reads and parse a skill sheet
|
||||
use crate::{
|
||||
loader::LoadError,
|
||||
skills_structures::{Node, Renderable, SkillList, SkillTypes},
|
||||
skills_structures::{Node, Renderable, SkillTypes},
|
||||
};
|
||||
use debug_print::debug_println;
|
||||
use std::{fs, path::Path};
|
||||
|
|
@ -14,18 +14,18 @@ trait Parser<T> {
|
|||
fn from_path(path: impl AsRef<Path> + ToString) -> Result<T, Self::Err>;
|
||||
}
|
||||
|
||||
impl Parser<SkillList> for SkillList {
|
||||
impl Parser<Node> for Node {
|
||||
type Err = LoadError;
|
||||
fn from_path(path: impl AsRef<Path> + ToString) -> Result<SkillList, LoadError> {
|
||||
fn from_path(path: impl AsRef<Path> + ToString) -> Result<Node, LoadError> {
|
||||
let file_content = fs::read_to_string(&path).map_err(LoadError::Io)?;
|
||||
// let mut globlist = Vec::with_capacity(100);
|
||||
let mut globlist = ListId::from_string(file_content)?;
|
||||
let list_sect = globlist.make_list_sections()?;
|
||||
let list_sect = globlist.make_all_nodes()?;
|
||||
// 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, Some(list_sect));
|
||||
// let ls = SkillList::with_config(&ConfigList::new(path.to_string(), 0, 0, global_id));
|
||||
// ls.populate(globlist);
|
||||
Ok(ls)
|
||||
Ok(list_sect)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -55,26 +55,10 @@ impl ListId {
|
|||
}
|
||||
|
||||
/// Populate all section and return a SkillList
|
||||
fn make_list_sections(&mut self) -> Result<Vec<Node>, LoadError> {
|
||||
fn make_all_nodes(&mut self) -> Result<Node, LoadError> {
|
||||
let mut index = 0;
|
||||
let mut list_section = Vec::new();
|
||||
while index < self.list.len() {
|
||||
let (name, global_id, id) = self.get_info(&index);
|
||||
debug_println!(
|
||||
"[{}]|| => Processing {} [{}/{}]",
|
||||
index,
|
||||
name,
|
||||
global_id,
|
||||
id
|
||||
);
|
||||
if matches!(self.get_kind(&index), SkillTypes::Section) {
|
||||
list_section.push(self.make_node(&mut index, SkillTypes::Section)?);
|
||||
} else {
|
||||
// return Err(LoadError::WrongHierarchy);
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
Ok(list_section)
|
||||
let node = self.make_node(&mut index, SkillTypes::Root)?;
|
||||
Ok(node)
|
||||
}
|
||||
|
||||
/// Make a node of a certain level and all subsequent subnodes
|
||||
|
|
@ -469,28 +453,6 @@ mod test {
|
|||
#[test]
|
||||
fn test_parser() {}
|
||||
|
||||
#[test]
|
||||
fn test_skilllist() {
|
||||
let test_dt = [("@s0\n+ss0\n=sk0\n-sks0\n-sks1\n-sks2\n-sks3\n\
|
||||
=sk1\n-sks0\n-sks1\n-sks2\n-sks3\n+ss1\n=sk0\n\
|
||||
-sks0\n-sks1\n-sks2\n-sks3\n=sk1\n-sks0\n-sks1\n\
|
||||
-sks2\n-sks3\n+ss2\n#ri0\n#ri1\n+ss3\n.rpts0\n.rpts1\n\
|
||||
@s1\n+ss1\n#ri0"," [Section] s0 [0/1]\n [SubSection] ss0 [0/2]\n [Skill] sk0 [0/3]\n [SubSkill] sks0 [0/4]\n [SubSkill] sks1 [1/5]\n [SubSkill] sks2 [2/6]\n [SubSkill] sks3 [3/7]\n [Skill] sk1 [1/8]\n [SubSkill] sks0 [0/9]\n [SubSkill] sks1 [1/10]\n [SubSkill] sks2 [2/11]\n [SubSkill] sks3 [3/12]\n [SubSection] ss1 [1/13]\n [Skill] sk0 [0/14]\n [SubSkill] sks0 [0/15]\n [SubSkill] sks1 [1/16]\n [SubSkill] sks2 [2/17]\n [SubSkill] sks3 [3/18]\n [Skill] sk1 [1/19]\n [SubSkill] sks0 [0/20]\n [SubSkill] sks1 [1/21]\n [SubSkill] sks2 [2/22]\n [SubSkill] sks3 [3/23]\n [SubSection] ss2 [2/24]\n [RepeatingItem] ri0 [0/25]\n [RepeatingItem] ri1 [0/26]\n [SubSection] ss3 [3/27]\n [RepeatingSkills] rpts0 [0/28]\n [RepeatingSkills] rpts1 [0/29]\n [Section] s1 [1/30]\n [SubSection] ss1 [0/31]\n [RepeatingItem] ri0 [0/32]"),
|
||||
];
|
||||
for (data, res) in test_dt.iter() {
|
||||
let mut line_id = ListId::from_string(data.to_string()).unwrap();
|
||||
let node = line_id.make_list_sections();
|
||||
let node = node
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|v| v.debug_display())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
assert_eq!(node, res.to_string());
|
||||
// println!("{}", node);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_node() {
|
||||
let test_dt = [
|
||||
|
|
@ -510,8 +472,11 @@ mod test {
|
|||
let mut index = 0;
|
||||
let node = line_ids.make_node(&mut index, SkillTypes::Root);
|
||||
let node = node.unwrap();
|
||||
let mut line_ids = ListId::from_string(file_content.to_string()).unwrap();
|
||||
let node2 = line_ids.make_all_nodes().unwrap();
|
||||
println!("Final Nodes: \n{}", node.debug_display());
|
||||
assert_eq!(node.debug_display(), expected.to_string());
|
||||
assert_eq!(node.debug_display(), node2.debug_display());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Reference in New Issue