Compare commits
No commits in common. "962d407b3fd8207e5d42c3cc9aac03ddc69b86c7" and "6586da02a21df715ec15d9a9fbd4df928dafeab6" have entirely different histories.
962d407b3f
...
6586da02a2
|
@ -2,10 +2,22 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.2.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "755717a7de9ec452bf7f3f1a3099085deabd7f2962b861dae91ecd7a365903d2"
|
||||||
|
dependencies = [
|
||||||
|
"shlex",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dnd-calc"
|
name = "dnd-calc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"ncurses",
|
||||||
|
"serde",
|
||||||
|
"struct_iterable",
|
||||||
"toml",
|
"toml",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -15,6 +27,15 @@ version = "1.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "erased-serde"
|
||||||
|
version = "0.3.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6c138974f9d5e7fe373eb04df7cae98833802ae4b11c24ac7039a21d5af4b26c"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.15.2"
|
version = "0.15.2"
|
||||||
|
@ -31,12 +52,35 @@ dependencies = [
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.169"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.7.4"
|
version = "2.7.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ncurses"
|
||||||
|
version = "6.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fbd71afa95710e841d173521e8483e764004eb332bdf47bd01d00f568688027f"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"pkg-config",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkg-config"
|
||||||
|
version = "0.3.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.93"
|
version = "1.0.93"
|
||||||
|
@ -84,6 +128,41 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shlex"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "struct_iterable"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "849a064c6470a650b72e41fa6c057879b68f804d113af92900f27574828e7712"
|
||||||
|
dependencies = [
|
||||||
|
"struct_iterable_derive",
|
||||||
|
"struct_iterable_internal",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "struct_iterable_derive"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8bb939ce88a43ea4e9d012f2f6b4cc789deb2db9d47bad697952a85d6978662c"
|
||||||
|
dependencies = [
|
||||||
|
"erased-serde",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"struct_iterable_internal",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "struct_iterable_internal"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e9426b2a0c03e6cc2ea8dbc0168dbbf943f88755e409fb91bcb8f6a268305f4a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.98"
|
version = "2.0.98"
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
[package]
|
[package]
|
||||||
name = "dnd-calc"
|
name = "dnd-calc"
|
||||||
version = "1.0.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
ncurses = "6.0.1"
|
||||||
|
serde = { version = "1.0.217", features = ["derive"] }
|
||||||
|
struct_iterable = "0.1.1"
|
||||||
toml = "0.8.20"
|
toml = "0.8.20"
|
||||||
|
|
349
src/main.rs
349
src/main.rs
|
@ -1,8 +1,75 @@
|
||||||
//#![allow(unused)]
|
//#![allow(unused)]
|
||||||
//use std::io;
|
//use std::io;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use toml::{Table, Value};
|
use serde::Deserialize;
|
||||||
use std::collections::HashMap;
|
use struct_iterable::Iterable;
|
||||||
|
|
||||||
|
// https://crates.io/crates/toml
|
||||||
|
// https://docs.rs/toml/0.8.20/toml/
|
||||||
|
// https://crates.io/crates/ncurses
|
||||||
|
|
||||||
|
#[derive(Deserialize,Iterable)]
|
||||||
|
struct Config {
|
||||||
|
str: u8,
|
||||||
|
dex: u8,
|
||||||
|
consti: u8,
|
||||||
|
intell: u8,
|
||||||
|
wis: u8,
|
||||||
|
charis: u8,
|
||||||
|
profiency: u8,
|
||||||
|
prof_throws: Vec<String>,
|
||||||
|
prof_skills: Vec<String>,
|
||||||
|
skill_prof_bonuses: Vec<Vec<String>>,
|
||||||
|
base_bonuses: BaseBonuses,
|
||||||
|
base_modifiers: BaseModifiers,
|
||||||
|
list: List,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize,Iterable)]
|
||||||
|
struct BaseBonuses {
|
||||||
|
str: Option<i64>,
|
||||||
|
dex: Option<i64>,
|
||||||
|
consti: Option<i64>,
|
||||||
|
intell: Option<i64>,
|
||||||
|
wis: Option<i64>,
|
||||||
|
charis: Option<i64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize,Iterable)]
|
||||||
|
struct BaseModifiers{
|
||||||
|
str: Option<i64>,
|
||||||
|
dex: Option<i64>,
|
||||||
|
consti: Option<i64>,
|
||||||
|
intell: Option<i64>,
|
||||||
|
wis: Option<i64>,
|
||||||
|
charis: Option<i64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize,Iterable)]
|
||||||
|
struct List{
|
||||||
|
skills: Vec<Vec<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct SkillArr{
|
||||||
|
name: String,
|
||||||
|
modi: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DndData{
|
||||||
|
main_stats: Vec<u8>,
|
||||||
|
profiency: u8,
|
||||||
|
prof_throws: Vec<String>,
|
||||||
|
prof_throws_vec: Vec<i64>,
|
||||||
|
base_bonuses: Vec<i64>,
|
||||||
|
base_modifiers: Vec<i64>,
|
||||||
|
prof_skills: Vec<String>,
|
||||||
|
skill_prof_bonuses: Vec<Vec<String>>,
|
||||||
|
skills_names: Vec<Vec<String>>,
|
||||||
|
skills: Vec<SkillArr>,
|
||||||
|
throws: Vec<i64>,
|
||||||
|
}
|
||||||
|
|
||||||
fn print_type_of<T>(_: &T) {
|
fn print_type_of<T>(_: &T) {
|
||||||
println!("{}", std::any::type_name::<T>());
|
println!("{}", std::any::type_name::<T>());
|
||||||
|
@ -10,100 +77,222 @@ fn print_type_of<T>(_: &T) {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let toml_str: String = fs::read_to_string("data.toml").expect("error");
|
let toml_str: String = fs::read_to_string("data.toml").expect("error");
|
||||||
let mut toml_data = toml_str.parse::<Table>().unwrap();
|
let toml_data: Config = toml::from_str(&toml_str).unwrap();
|
||||||
let mut throws = HashMap::new();
|
let mut dnd_data = DndData{
|
||||||
let mut skills = HashMap::new();
|
main_stats: vec![0,0,0,0,0,0],
|
||||||
|
profiency: toml_data.profiency,
|
||||||
let binding = toml_data.clone();
|
prof_throws: vec![String::new(); 100],
|
||||||
//for whatever reason. if i dont have this as a var, and instead put toml_data.clone in the
|
prof_throws_vec: vec![0,0,0,0,0,0],
|
||||||
//loop below, the throws.insert makes a borrow error. i dont get it
|
prof_skills: vec![String::new(); 100],
|
||||||
for (key,val) in &binding{
|
base_bonuses: vec![0,0,0,0,0,0],
|
||||||
match key.as_str(){
|
base_modifiers: vec![0,0,0,0,0,0],
|
||||||
"base_bonuses" => {
|
skill_prof_bonuses: vec![vec![String::new(); 2]; 100],
|
||||||
if let Some(base_bonuses) = val.as_table() {
|
skills_names: vec![vec![String::new(); 2]; 100],
|
||||||
for (base_key, base_val) in base_bonuses {
|
throws: vec![0,0,0,0,0,0],
|
||||||
//toml_data["str"] = toml::Value::Integer(base_val);
|
skills: vec![SkillArr{ name: String::new(), modi: 0}; 100],
|
||||||
if let (Some(existing_num), Some(base_num)) = (toml_data[base_key].as_integer(), base_val.as_integer()) {
|
};
|
||||||
toml_data[base_key] = Value::Integer(existing_num + base_num);
|
for (name, val) in toml_data.iter() {
|
||||||
}
|
match val.downcast_ref::<u8>() {
|
||||||
|
Some(x) => {
|
||||||
}
|
match name{
|
||||||
}
|
"str" => dnd_data.main_stats[0]=*x,
|
||||||
// for (base_key, base_val) in val.as_table_mut().unwrap_or(&Default::default()) {
|
"dex" => dnd_data.main_stats[1]=*x,
|
||||||
// toml_data["str"] = Value::Integer(0);
|
"consti" => dnd_data.main_stats[2]=*x,
|
||||||
// }
|
"intell" => dnd_data.main_stats[3]=*x,
|
||||||
|
"wis" => dnd_data.main_stats[4]=*x,
|
||||||
//print_type_of(&val.get("base_bonuses"));
|
"charis" => dnd_data.main_stats[5]=*x,
|
||||||
},
|
_ => {},
|
||||||
"base_modifiers" =>{
|
|
||||||
if let Some(base_modifiers) = val.as_table(){
|
|
||||||
for(base_key, base_val) in base_modifiers{
|
|
||||||
if let (Some(profiency), Some(base_num)) = (toml_data["profiency"].as_integer(), base_val.as_integer()) {
|
|
||||||
if toml_data["prof_throws"]
|
|
||||||
.as_array()
|
|
||||||
.map_or(false, |arr| arr.iter().any(|val2| val2.as_str().map_or(false, |s| s.contains(base_key))))
|
|
||||||
{
|
|
||||||
throws.insert(base_key,profiency + base_num);
|
|
||||||
} else {
|
|
||||||
throws.insert(base_key,base_num);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"list" =>{
|
_ => {},
|
||||||
if let Some(list) = val.as_table(){
|
}
|
||||||
if let Some(base_skills) = list["skills"].as_array(){
|
}
|
||||||
for skill in base_skills{
|
let mut i=0;
|
||||||
//make this cleaner
|
for name in &toml_data.prof_throws {
|
||||||
if let (Some(skill_name),Some(skill_mod),Some(base_modifiers),Some(profiency),Some(skill_bonus)) = (skill[0].as_str(),skill[1].as_str(),toml_data["base_modifiers"].as_table(),toml_data["profiency"].as_integer(),toml_data["skill_prof_bonuses"].as_array()){
|
dnd_data.prof_throws[i]=name.to_string();
|
||||||
|
i=i+1;
|
||||||
|
}
|
||||||
|
i=0;
|
||||||
|
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 {
|
||||||
|
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,
|
||||||
|
"consti" => dnd_data.prof_throws_vec[2]=dnd_data.profiency as i64,
|
||||||
|
"intell" => dnd_data.prof_throws_vec[3]=dnd_data.profiency as i64,
|
||||||
|
"wis" => dnd_data.prof_throws_vec[4]=dnd_data.profiency as i64,
|
||||||
|
"charis" => dnd_data.prof_throws_vec[5]=dnd_data.profiency as i64,
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
i=i+1;
|
||||||
|
}
|
||||||
|
i=0;
|
||||||
|
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 {
|
||||||
|
dnd_data.skills_names[i][0]=name[0].to_string();
|
||||||
|
dnd_data.skills_names[i][1]=name[1].to_string();
|
||||||
|
i=i+1;
|
||||||
|
}
|
||||||
|
|
||||||
let mut add_number=0;
|
for (name, val) in toml_data.base_bonuses.iter() {
|
||||||
if toml_data["prof_skills"]
|
// Try to downcast to Option<i64>
|
||||||
.as_array()
|
match val.downcast_ref::<Option<i64>>() {
|
||||||
.map_or(false, |arr| arr.iter().any(|val2| val2.as_str().map_or(false, |s| s.contains(&String::from(skill_name)))))
|
Some(Some(x)) => {
|
||||||
{
|
match name{
|
||||||
add_number = add_number + base_modifiers[skill_mod].as_integer().expect("none") + profiency;
|
"str" => dnd_data.base_bonuses[0]=*x,
|
||||||
} else {
|
"dex" => dnd_data.base_bonuses[1]=*x,
|
||||||
add_number = add_number + base_modifiers[skill_mod].as_integer().expect("none");
|
"consti" => dnd_data.base_bonuses[2]=*x,
|
||||||
}
|
"intell" => dnd_data.base_bonuses[3]=*x,
|
||||||
for bone in skill_bonus{
|
"wis" => dnd_data.base_bonuses[4]=*x,
|
||||||
if skill_mod == bone[1].as_str().expect("none"){
|
"charis" => dnd_data.base_bonuses[5]=*x,
|
||||||
add_number = add_number + base_modifiers[bone[0].as_str().expect("none")].as_integer().expect("none");
|
_ => {},
|
||||||
}
|
|
||||||
}
|
|
||||||
skills.insert(skill_name,add_number);
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
_ => {},
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
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,
|
||||||
|
_ => {},
|
||||||
}
|
}
|
||||||
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//fin
|
i=0;
|
||||||
for (key,val) in toml_data{
|
for val in &dnd_data.base_bonuses{
|
||||||
match key.as_str(){
|
dnd_data.main_stats[i]=dnd_data.main_stats[i]+*val as u8;
|
||||||
"str" => println!("{}:{}",key,val),
|
i=i+1;
|
||||||
"dex" => println!("{}:{}",key,val),
|
}
|
||||||
"consti" => println!("{}:{}",key,val),
|
i=0;
|
||||||
"intell" => println!("{}:{}",key,val),
|
for val in &dnd_data.base_modifiers{
|
||||||
"wis" => println!("{}:{}",key,val),
|
dnd_data.throws[i]=dnd_data.prof_throws_vec[i] + val;
|
||||||
"charis" => println!("{}:{}",key,val),
|
i=i+1
|
||||||
"profiency" => println!("{}:{}",key,val),
|
}
|
||||||
_ => {},
|
fn base_to_num(str: String) -> usize{
|
||||||
|
match str.as_str(){
|
||||||
|
"str" => return 0,
|
||||||
|
"dex" => return 1,
|
||||||
|
"consti" => return 2,
|
||||||
|
"intell" => return 3,
|
||||||
|
"wis" => return 4,
|
||||||
|
"charis" => return 5,
|
||||||
|
_ => return 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("-------");
|
|
||||||
|
|
||||||
for (key,val) in throws.iter(){
|
i=0;
|
||||||
println!("throws: {}::{}",key,val);
|
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;
|
||||||
}
|
}
|
||||||
println!("-------");
|
}
|
||||||
|
for skill_prof_bonuses in &dnd_data.skill_prof_bonuses{
|
||||||
|
if name[1]==skill_prof_bonuses[1] && name[0]!="" {
|
||||||
|
modi=modi+dnd_data.base_modifiers[base_to_num(String::from(skill_prof_bonuses[0].as_str()))] as u8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modi=modi+dnd_data.base_modifiers[base_to_num(String::from(name[1].as_str()))] as u8;
|
||||||
|
dnd_data.skills[i].name=String::from(name[0].as_str());
|
||||||
|
dnd_data.skills[i].modi=modi as i64;
|
||||||
|
|
||||||
for (key,val) in skills.iter(){
|
i=i+1;
|
||||||
println!("skills: {}::{}",key,val);
|
}
|
||||||
|
|
||||||
|
println!("profiency: {}",dnd_data.profiency);
|
||||||
|
fn num_to_base(num: usize) -> String{
|
||||||
|
match num{
|
||||||
|
0 => return String::from("str"),
|
||||||
|
1 => return String::from("dex"),
|
||||||
|
2 => return String::from("consti"),
|
||||||
|
3 => return String::from("intell"),
|
||||||
|
4 => return String::from("wis"),
|
||||||
|
5 => return String::from("charis"),
|
||||||
|
_ => return String::from("Null"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
println!("---------");
|
||||||
|
i=0;
|
||||||
|
for val in &dnd_data.main_stats{
|
||||||
|
println!("{}: {}",num_to_base(i),val);
|
||||||
|
i=i+1
|
||||||
|
}
|
||||||
|
println!("---------");
|
||||||
|
i=0;
|
||||||
|
for val in &dnd_data.base_modifiers{
|
||||||
|
println!("mod {}: {}",num_to_base(i),val);
|
||||||
|
i=i+1
|
||||||
|
}
|
||||||
|
println!("---------");
|
||||||
|
i=0;
|
||||||
|
for val in &dnd_data.throws{
|
||||||
|
println!("throws {}: {}",num_to_base(i),val);
|
||||||
|
i=i+1
|
||||||
|
}
|
||||||
|
println!("---------");
|
||||||
|
for val in &dnd_data.skills{
|
||||||
|
if val.name!=""{
|
||||||
|
println!("{} : {}",val.name,val.modi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
// 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");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
Loading…
Reference in New Issue