This commit is contained in:
iceyrazor 2025-02-09 17:14:55 -06:00
parent f52ac5b5e1
commit a1f5d5f917
1 changed files with 79 additions and 85 deletions

View File

@ -1,9 +1,6 @@
#![allow(unused)]
use toml::{value::Array, Table};
//#![allow(unused)]
//use std::io;
use std::fs;
use std::option;
use std::any::{Any, TypeId};
use serde::Deserialize;
use struct_iterable::Iterable;
@ -96,33 +93,33 @@ fn main() {
};
for (name, val) in toml_data.iter() {
match val.downcast_ref::<u8>() {
Some(x) => {
match name{
"str" => dnd_data.main_stats[0]=*x,
"dex" => dnd_data.main_stats[1]=*x,
"consti" => dnd_data.main_stats[2]=*x,
"intell" => dnd_data.main_stats[3]=*x,
"wis" => dnd_data.main_stats[4]=*x,
"charis" => dnd_data.main_stats[5]=*x,
_ => {},
}
},
_ => {},
Some(x) => {
match name{
"str" => dnd_data.main_stats[0]=*x,
"dex" => dnd_data.main_stats[1]=*x,
"consti" => dnd_data.main_stats[2]=*x,
"intell" => dnd_data.main_stats[3]=*x,
"wis" => dnd_data.main_stats[4]=*x,
"charis" => dnd_data.main_stats[5]=*x,
_ => {},
}
},
_ => {},
}
}
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();
i=i+1;
}
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][1]=name[1].to_string();
i=i+1;
}
i=0;
for (name) in &toml_data.prof_throws {
for name in &toml_data.prof_throws {
match name.as_str(){
"str" => dnd_data.prof_throws_vec[0]=dnd_data.profiency as i64,
"dex" => dnd_data.prof_throws_vec[1]=dnd_data.profiency as i64,
@ -135,12 +132,12 @@ fn main() {
i=i+1;
}
i=0;
for (name) in &toml_data.prof_skills {
for name in &toml_data.prof_skills {
dnd_data.prof_skills[i]=name.to_string();
i=i+1;
}
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][1]=name[1].to_string();
i=i+1;
@ -149,44 +146,44 @@ fn main() {
for (name, val) in toml_data.base_bonuses.iter() {
// Try to downcast to Option<i64>
match val.downcast_ref::<Option<i64>>() {
Some(Some(x)) => {
match name{
"str" => dnd_data.base_bonuses[0]=*x,
"dex" => dnd_data.base_bonuses[1]=*x,
"consti" => dnd_data.base_bonuses[2]=*x,
"intell" => dnd_data.base_bonuses[3]=*x,
"wis" => dnd_data.base_bonuses[4]=*x,
"charis" => dnd_data.base_bonuses[5]=*x,
_ => {},
}
},
_ => {},
Some(Some(x)) => {
match name{
"str" => dnd_data.base_bonuses[0]=*x,
"dex" => dnd_data.base_bonuses[1]=*x,
"consti" => dnd_data.base_bonuses[2]=*x,
"intell" => dnd_data.base_bonuses[3]=*x,
"wis" => dnd_data.base_bonuses[4]=*x,
"charis" => dnd_data.base_bonuses[5]=*x,
_ => {},
}
},
_ => {},
}
/*
if let Some(option_val) = val.downcast_ref::<Option<i64>>() {
match option_val {
Some(x) => println!("{}, val (Option<i64>): {}", name, x),
None => println!("none in Option<i64>"),
}
}
*/
if let Some(option_val) = val.downcast_ref::<Option<i64>>() {
match option_val {
Some(x) => println!("{}, val (Option<i64>): {}", name, x),
None => println!("none in Option<i64>"),
}
}
*/
}
for (name, val) in toml_data.base_modifiers.iter() {
match val.downcast_ref::<Option<i64>>() {
Some(Some(x)) => {
match name{
"str" => dnd_data.base_modifiers[0]=*x,
"dex" => dnd_data.base_modifiers[1]=*x,
"consti" => dnd_data.base_modifiers[2]=*x,
"intell" => dnd_data.base_modifiers[3]=*x,
"wis" => dnd_data.base_modifiers[4]=*x,
"charis" => dnd_data.base_modifiers[5]=*x,
_ => {},
}
},
_ => {},
}
Some(Some(x)) => {
match name{
"str" => dnd_data.base_modifiers[0]=*x,
"dex" => dnd_data.base_modifiers[1]=*x,
"consti" => dnd_data.base_modifiers[2]=*x,
"intell" => dnd_data.base_modifiers[3]=*x,
"wis" => dnd_data.base_modifiers[4]=*x,
"charis" => dnd_data.base_modifiers[5]=*x,
_ => {},
}
},
_ => {},
}
}
i=0;
@ -199,7 +196,6 @@ fn main() {
dnd_data.throws[i]=dnd_data.prof_throws_vec[i] + val;
i=i+1
}
i=0;
fn base_to_num(str: String) -> usize{
match str.as_str(){
"str" => return 0,
@ -210,13 +206,14 @@ fn main() {
"charis" => return 5,
_ => return 0,
}
};
}
i=0;
for name in &dnd_data.skills_names{
let mut modi=0;
for prof_skills in &dnd_data.prof_skills{
if name[0]==*prof_skills && name[0]!="" {
modi=dnd_data.profiency;
modi=dnd_data.profiency;
}
}
for skill_prof_bonuses in &dnd_data.skill_prof_bonuses{
@ -229,7 +226,6 @@ fn main() {
dnd_data.skills[i].modi=modi as i64;
i=i+1;
modi=0;
}
println!("profiency: {}",dnd_data.profiency);
@ -263,42 +259,40 @@ fn main() {
i=i+1
}
println!("---------");
i=0;
for val in &dnd_data.skills{
if val.name!=""{
println!("{} : {}",val.name,val.modi);
println!("{} : {}",val.name,val.modi);
}
}
i=0;
}
// need to convert to hash map
/*
// Deserialize the entire TOML data into a HashMap<String, toml::Value>
let toml_data: HashMap<String, Value> = from_str(toml_str).unwrap();
// Deserialize the entire TOML data into a HashMap<String, toml::Value>
let toml_data: HashMap<String, Value> = from_str(toml_str).unwrap();
// Accessing base_bonuses as a Table (nested structure)
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
for (name, val) in base_bonuses.iter() {
// Try to downcast to Option<i64>
match val.downcast_ref::<Option<i64>>() {
Some(Some(x)) => {
// Handle the case where it's an Option<i64> with a value
println!("{}: {}", name, x);
},
Some(None) => {
// Handle the case where it's an Option<i64> but the value is None
println!("{}: None", name);
},
None => {
// Handle the case where it's not an Option<i64>
println!("{}: Not an Option<i64>", name);
}
}
}
} else {
println!("base_bonuses not found or not a table");
}
// Accessing base_bonuses as a Table (nested structure)
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
for (name, val) in base_bonuses.iter() {
// Try to downcast to Option<i64>
match val.downcast_ref::<Option<i64>>() {
Some(Some(x)) => {
// Handle the case where it's an Option<i64> with a value
println!("{}: {}", name, x);
},
Some(None) => {
// Handle the case where it's an Option<i64> but the value is None
println!("{}: None", name);
},
None => {
// Handle the case where it's not an Option<i64>
println!("{}: Not an Option<i64>", name);
}
}
}
} else {
println!("base_bonuses not found or not a table");
}
*/