Skip to content

Commit

Permalink
Weapon choosing :)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterkos committed Nov 1, 2021
1 parent d5b9bf5 commit 52168f5
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 11 deletions.
67 changes: 67 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ edition = "2021"
console = "0.15.0"
dialoguer = "0.9.0"
strum = "0.22" # Enum val iter
strum_macros = "0.22"
strum_macros = "0.22"
parse-display = "0.5.3"
1 change: 1 addition & 0 deletions src/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::data::*;
pub struct Character {
pub class: Class,
pub stats: Stats,
pub weapons: Vec<Weapon>,
// pub saving_throws: SavingThrows,
// pub skills: Skills
}
43 changes: 40 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


use dialoguer::{Select, Input};
use dialoguer::{MultiSelect, Select, Input};

// Data
use crate::character::*;
Expand Down Expand Up @@ -92,13 +92,50 @@ impl Config {

self.character.stats = Stats { strength, dexterity, constitution, intelligence, wisdom, charisma };
}
fn weapons(&self) {
unimplemented!()

fn weapons(&mut self) {

let weapons: Vec<Weapon> = self.build_weapons();

let selected_weapons = MultiSelect::new()
.items(&weapons)
.interact()
.unwrap();


let mapped_weapons = selected_weapons
.into_iter().map(|w|
weapons[w].clone()
)
.collect();

self.character.weapons = mapped_weapons;

println!("User selected {:?}", self.character.weapons);

}

fn saving_throws(&self) {
unimplemented!()
}
fn skills(&self) {
unimplemented!()
}


// MARK: - Helper build functions

fn build_weapons(&self) -> Vec<Weapon> {

// TODO: Do this from a database or something

let mut weapons: Vec<Weapon> = Vec::new();

weapons.push(Weapon {name: String::from("Club"), dice_count: 1, dice: Dice::D4, properties: Vec::new() });
weapons.push(Weapon {name: String::from("Dagger"), dice_count: 1, dice: Dice::D4, properties: Vec::new() });
weapons.push(Weapon {name: String::from("Greatclub"), dice_count: 1, dice: Dice::D8, properties: Vec::new() });

weapons

}
}
19 changes: 12 additions & 7 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use strum_macros::{EnumString, EnumVariantNames};
use parse_display::{Display};

#[derive(Default, Debug)]
pub struct Stats {
Expand Down Expand Up @@ -73,18 +74,22 @@ pub enum Class {
// TODO: Do more :)
}


pub enum Weapon {
Club(Dice, Vec<Properties>),
Dagger(Dice, Vec<Properties>),
Greatclub(Dice, Vec<Properties>)
// TODO: More weapons
#[derive(Display, Debug, Clone)]
#[display("{name}, {dice_count}d{dice}")]
pub struct Weapon {
pub name: String,
pub dice_count: u8,
pub dice: Dice,
pub properties: Vec<Properties>
}


#[derive(Debug, Clone)]
pub enum Properties {
// TODO
Empty
}

#[derive(Display, Debug, Clone)]
pub enum Dice {
D3,
D4,
Expand Down

0 comments on commit 52168f5

Please sign in to comment.