Compare commits

..

No commits in common. "6586da02a21df715ec15d9a9fbd4df928dafeab6" and "bd5fff40b544fabd86d66cd34b426dd3e53a9dfe" have entirely different histories.

1 changed files with 85 additions and 79 deletions

View File

@ -1,6 +1,9 @@
//#![allow(unused)] #![allow(unused)]
use toml::{value::Array, Table};
//use std::io; //use std::io;
use std::fs; use std::fs;
use std::option;
use std::any::{Any, TypeId};
use serde::Deserialize; use serde::Deserialize;
use struct_iterable::Iterable; use struct_iterable::Iterable;
@ -108,18 +111,18 @@ fn main() {
} }
} }
let mut i=0; let mut i=0;
for name in &toml_data.prof_throws { for (name) in &toml_data.prof_throws {
dnd_data.prof_throws[i]=name.to_string(); dnd_data.prof_throws[i]=name.to_string();
i=i+1; i=i+1;
} }
i=0; i=0;
for name in &toml_data.skill_prof_bonuses{ for (name) in &toml_data.skill_prof_bonuses{
dnd_data.skill_prof_bonuses[i][0]=name[0].to_string(); dnd_data.skill_prof_bonuses[i][0]=name[0].to_string();
dnd_data.skill_prof_bonuses[i][1]=name[1].to_string(); dnd_data.skill_prof_bonuses[i][1]=name[1].to_string();
i=i+1; i=i+1;
} }
i=0; i=0;
for name in &toml_data.prof_throws { for (name) in &toml_data.prof_throws {
match name.as_str(){ match name.as_str(){
"str" => dnd_data.prof_throws_vec[0]=dnd_data.profiency as i64, "str" => dnd_data.prof_throws_vec[0]=dnd_data.profiency as i64,
"dex" => dnd_data.prof_throws_vec[1]=dnd_data.profiency as i64, "dex" => dnd_data.prof_throws_vec[1]=dnd_data.profiency as i64,
@ -132,12 +135,12 @@ fn main() {
i=i+1; i=i+1;
} }
i=0; i=0;
for name in &toml_data.prof_skills { for (name) in &toml_data.prof_skills {
dnd_data.prof_skills[i]=name.to_string(); dnd_data.prof_skills[i]=name.to_string();
i=i+1; i=i+1;
} }
i=0; i=0;
for name in &toml_data.list.skills { for (name) in &toml_data.list.skills {
dnd_data.skills_names[i][0]=name[0].to_string(); dnd_data.skills_names[i][0]=name[0].to_string();
dnd_data.skills_names[i][1]=name[1].to_string(); dnd_data.skills_names[i][1]=name[1].to_string();
i=i+1; i=i+1;
@ -196,6 +199,7 @@ fn main() {
dnd_data.throws[i]=dnd_data.prof_throws_vec[i] + val; dnd_data.throws[i]=dnd_data.prof_throws_vec[i] + val;
i=i+1 i=i+1
} }
i=0;
fn base_to_num(str: String) -> usize{ fn base_to_num(str: String) -> usize{
match str.as_str(){ match str.as_str(){
"str" => return 0, "str" => return 0,
@ -206,8 +210,7 @@ fn main() {
"charis" => return 5, "charis" => return 5,
_ => return 0, _ => return 0,
} }
} };
i=0; i=0;
for name in &dnd_data.skills_names{ for name in &dnd_data.skills_names{
let mut modi=0; let mut modi=0;
@ -226,6 +229,7 @@ fn main() {
dnd_data.skills[i].modi=modi as i64; dnd_data.skills[i].modi=modi as i64;
i=i+1; i=i+1;
modi=0;
} }
println!("profiency: {}",dnd_data.profiency); println!("profiency: {}",dnd_data.profiency);
@ -259,40 +263,42 @@ fn main() {
i=i+1 i=i+1
} }
println!("---------"); println!("---------");
i=0;
for val in &dnd_data.skills{ for val in &dnd_data.skills{
if val.name!=""{ if val.name!=""{
println!("{} : {}",val.name,val.modi); println!("{} : {}",val.name,val.modi);
} }
} }
i=0;
} }
// need to convert to hash map // need to convert to hash map
/* /*
// Deserialize the entire TOML data into a HashMap<String, toml::Value> // Deserialize the entire TOML data into a HashMap<String, toml::Value>
let toml_data: HashMap<String, Value> = from_str(toml_str).unwrap(); let toml_data: HashMap<String, Value> = from_str(toml_str).unwrap();
// Accessing base_bonuses as a Table (nested structure) // Accessing base_bonuses as a Table (nested structure)
if let Some(base_bonuses) = toml_data.get("base_bonuses").and_then(Value::as_table) { if let Some(base_bonuses) = toml_data.get("base_bonuses").and_then(Value::as_table) {
// Iterate over the keys and values in the base_bonuses table // Iterate over the keys and values in the base_bonuses table
for (name, val) in base_bonuses.iter() { for (name, val) in base_bonuses.iter() {
// Try to downcast to Option<i64> // Try to downcast to Option<i64>
match val.downcast_ref::<Option<i64>>() { match val.downcast_ref::<Option<i64>>() {
Some(Some(x)) => { Some(Some(x)) => {
// Handle the case where it's an Option<i64> with a value // Handle the case where it's an Option<i64> with a value
println!("{}: {}", name, x); println!("{}: {}", name, x);
}, },
Some(None) => { Some(None) => {
// Handle the case where it's an Option<i64> but the value is None // Handle the case where it's an Option<i64> but the value is None
println!("{}: None", name); println!("{}: None", name);
}, },
None => { None => {
// Handle the case where it's not an Option<i64> // Handle the case where it's not an Option<i64>
println!("{}: Not an Option<i64>", name); println!("{}: Not an Option<i64>", name);
} }
} }
} }
} else { } else {
println!("base_bonuses not found or not a table"); println!("base_bonuses not found or not a table");
} }
*/ */