summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Cargo.lock224
-rw-r--r--Cargo.toml10
-rw-r--r--data.toml46
-rw-r--r--src/main.rs304
5 files changed, 585 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ea8c4bf
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/target
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..9cdaf3d
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,224 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "cc"
+version = "1.2.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "755717a7de9ec452bf7f3f1a3099085deabd7f2962b861dae91ecd7a365903d2"
+dependencies = [
+ "shlex",
+]
+
+[[package]]
+name = "dnd-calc"
+version = "0.1.0"
+dependencies = [
+ "ncurses",
+ "serde",
+ "struct_iterable",
+ "toml",
+]
+
+[[package]]
+name = "equivalent"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+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]]
+name = "hashbrown"
+version = "0.15.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
+
+[[package]]
+name = "indexmap"
+version = "2.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652"
+dependencies = [
+ "equivalent",
+ "hashbrown",
+]
+
+[[package]]
+name = "libc"
+version = "0.2.169"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
+
+[[package]]
+name = "memchr"
+version = "2.7.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+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]]
+name = "proc-macro2"
+version = "1.0.93"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.38"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "serde"
+version = "1.0.217"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.217"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "serde_spanned"
+version = "0.6.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1"
+dependencies = [
+ "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]]
+name = "syn"
+version = "2.0.98"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "toml"
+version = "0.8.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148"
+dependencies = [
+ "serde",
+ "serde_spanned",
+ "toml_datetime",
+ "toml_edit",
+]
+
+[[package]]
+name = "toml_datetime"
+version = "0.6.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
+dependencies = [
+ "serde",
+]
+
+[[package]]
+name = "toml_edit"
+version = "0.22.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "02a8b472d1a3d7c18e2d61a489aee3453fd9031c33e4f55bd533f4a7adca1bee"
+dependencies = [
+ "indexmap",
+ "serde",
+ "serde_spanned",
+ "toml_datetime",
+ "winnow",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"
+
+[[package]]
+name = "winnow"
+version = "0.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "86e376c75f4f43f44db463cf729e0d3acbf954d13e22c51e26e4c264b4ab545f"
+dependencies = [
+ "memchr",
+]
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..61ec837
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "dnd-calc"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
+ncurses = "6.0.1"
+serde = { version = "1.0.217", features = ["derive"] }
+struct_iterable = "0.1.1"
+toml = "0.8.20"
diff --git a/data.toml b/data.toml
new file mode 100644
index 0000000..2b92a83
--- /dev/null
+++ b/data.toml
@@ -0,0 +1,46 @@
+str=16
+dex=16
+consti=16
+intell=13
+wis=16
+charis=16
+
+profiency=2
+prof_throws=["str","consti"]
+prof_skills=["Perception","Insight","Athletics","Intimidation"]
+skill_prof_bonuses=[["intell","dex"]]
+
+
+[base_bonuses]
+intell=2
+charis=1
+
+[base_modifiers]
+str=3
+dex=3
+consti=3
+intell=2
+wis=3
+charis=3
+
+[list]
+skills=[
+["Acrobatics","dex"],
+["Animal Handling","wis"],
+["Arcana","intell"],
+["Athletics","str"],
+["Deception","charis"],
+["History","intell"],
+["Insight","wis"],
+["Intimidation","charis"],
+["Investigation","intell"],
+["Medicine","wis"],
+["Nature","intell"],
+["Perception","wis"],
+["Performance","charis"],
+["Persuasion","charis"],
+["Religion","intell"],
+["Sleight of Hand","dex"],
+["Stealth","dex"],
+["Survival","wis"]
+]
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..4ef6502
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,304 @@
+#![allow(unused)]
+use toml::{value::Array, Table};
+//use std::io;
+use std::fs;
+use std::option;
+use std::any::{Any, TypeId};
+use serde::Deserialize;
+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) {
+ println!("{}", std::any::type_name::<T>());
+}
+
+fn main() {
+ let toml_str: String = fs::read_to_string("data.toml").expect("error");
+ let toml_data: Config = toml::from_str(&toml_str).unwrap();
+ let mut dnd_data = DndData{
+ main_stats: vec![0,0,0,0,0,0],
+ profiency: toml_data.profiency,
+ prof_throws: vec![String::new(); 100],
+ prof_throws_vec: vec![0,0,0,0,0,0],
+ prof_skills: vec![String::new(); 100],
+ base_bonuses: vec![0,0,0,0,0,0],
+ base_modifiers: vec![0,0,0,0,0,0],
+ skill_prof_bonuses: vec![vec![String::new(); 2]; 100],
+ skills_names: vec![vec![String::new(); 2]; 100],
+ throws: vec![0,0,0,0,0,0],
+ skills: vec![SkillArr{ name: String::new(), modi: 0}; 100],
+ };
+ 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,
+ _ => {},
+ }
+ },
+ _ => {},
+ }
+ }
+ let mut i=0;
+ 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{
+ 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;
+ }
+
+ 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,
+ _ => {},
+ }
+ },
+ _ => {},
+ }
+
+ /*
+ 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,
+ _ => {},
+ }
+ },
+ _ => {},
+ }
+ }
+
+ i=0;
+ for val in &dnd_data.base_bonuses{
+ dnd_data.main_stats[i]=dnd_data.main_stats[i]+*val as u8;
+ i=i+1;
+ }
+ i=0;
+ for val in &dnd_data.base_modifiers{
+ 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,
+ "dex" => return 1,
+ "consti" => return 2,
+ "intell" => return 3,
+ "wis" => return 4,
+ "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;
+ }
+ }
+ 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;
+
+ i=i+1;
+ modi=0;
+ }
+
+ 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!("---------");
+ i=0;
+ for val in &dnd_data.skills{
+ if val.name!=""{
+ 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();
+
+ // 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");
+ }
+*/