use dmn::dice; use dmn::random_tables::RandomTables; use dmn::rules::classes::CLASSES; use dmn::rules::npcs::Npc; mod cli; fn main() { let matches = cli::cli().get_matches(); let random_tables = RandomTables::new().expect("Failed to load random tables."); match matches.subcommand() { Some(("random", sub_matches)) => { let random_command = sub_matches.subcommand().unwrap(); match random_command { ("henchman", _) => { let class_name = random_tables.roll_table("henchman_class").to_string(); // HACK: Need a proper way to do lookups, shouldn't rely on // downcasing the class name. This whole situation is really // indicative of the need for an architectural improvement. // Need to think about roll_table()'s return type, // and how we want to get table results in general. let class_ref = CLASSES.get(&*class_name.to_lowercase()).unwrap_or_else(|| { eprintln!("Class '{}' not found.", &*class_name); std::process::exit(1); }); let npc = Npc::new( Some(random_tables.roll_table("npc_alignment")), Some(random_tables.roll_table("henchman_race")), Some(class_ref), None, ); println!( "{} {} {}", npc.alignment.unwrap(), npc.race.unwrap(), npc.class.unwrap().name ); } ("magic", _) => { let magic = random_tables.roll_table("ua_magic"); println!("{}", magic); } _ => unreachable!(), } } Some(("roll", sub_matches)) => { let formula = sub_matches.get_one::("FORMULA").expect("required"); match dice::roll_formula(formula) { Some(roll_result) => println!("Rolled: {}", roll_result), None => eprintln!("Error: Invalid roll formula or calculation failed."), } } Some(("table", sub_matches)) => { let table_name = sub_matches.get_one::("TABLE").expect("required"); let output_text = random_tables.roll_table(table_name); println!("{}", output_text) } _ => unreachable!(), } }