Clean up data structure redundancies

This commit is contained in:
Savanni D'Gerinel 2022-03-05 23:26:29 -05:00
parent 0588a803cf
commit 39e9b0564b
1 changed files with 54 additions and 126 deletions

View File

@ -77,28 +77,11 @@ pub struct Pool {
pub edge: u8, pub edge: u8,
} }
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct Pools {
pools: HashMap<PoolType, Pool>,
}
impl Pools {
pub fn might(&self) -> &Pool {
self.pools.get(&PoolType::Might).unwrap()
}
pub fn speed(&self) -> &Pool {
self.pools.get(&PoolType::Speed).unwrap()
}
pub fn intellect(&self) -> &Pool {
self.pools.get(&PoolType::Intellect).unwrap()
}
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct PointAllocation(HashMap<PoolType, u8>); pub struct PointAllocation(HashMap<PoolType, u8>);
#[derive(Debug, Serialize, Deserialize, PartialEq)] #[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct SpecialAbility { pub struct Action {
name: String, name: String,
#[serde(default)] #[serde(default)]
cost: Cost, cost: Cost,
@ -116,9 +99,37 @@ pub enum SkillLevel {
#[derive(Debug, Serialize, Deserialize, PartialEq)] #[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Skill { pub struct Skill {
name: String, name: String,
description: String,
level: SkillLevel, level: SkillLevel,
} }
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Enabler {
name: String,
description: String,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum Ability {
Skill(Skill),
Enabler(Enabler),
Action(Action),
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Descriptor {
name: String,
effects: Vec<Ability>,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Focus {
name: String,
tier1: Vec<Ability>,
tier2: Vec<Ability>,
}
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")] #[serde(rename_all = "lowercase")]
pub enum Range { pub enum Range {
@ -143,40 +154,6 @@ pub struct Defense {
speed_cost: u8, speed_cost: u8,
} }
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Enabler {
name: String,
descriptor: String,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum DescriptorAbility {
Skill(Skill),
Enabler(Enabler),
SpecialAbility(SpecialAbility),
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Descriptor {
name: String,
effects: Vec<DescriptorAbility>,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub struct FocusAbility {
name: String,
effect: DescriptorAbility,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Focus {
name: String,
tier1: Vec<FocusAbility>,
tier2: Vec<FocusAbility>,
}
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct CharacterSheet { pub struct CharacterSheet {
name: String, name: String,
@ -189,7 +166,6 @@ pub struct CharacterSheet {
tier: Tier, tier: Tier,
effort: u8, effort: u8,
cypher_limit: u8, cypher_limit: u8,
special_abilities: Vec<SpecialAbility>,
skills: Vec<Skill>, skills: Vec<Skill>,
attacks: Vec<Attack>, attacks: Vec<Attack>,
defenses: Vec<Defense>, defenses: Vec<Defense>,
@ -218,21 +194,6 @@ impl CharacterSheet {
) )
} }
/*
pub fn pools(&self) -> Pools {
Pools {
pools: HashMap::from_iter(
vec![
(PoolType::Might, self.might_pool()),
(PoolType::Speed, self.speed_pool()),
(PoolType::Intellect, self.intellect_pool()),
]
.into_iter(),
),
}
}
*/
fn pool(&self, pool: &PoolType) -> Pool { fn pool(&self, pool: &PoolType) -> Pool {
let max = let max =
self.character_type.pool(pool) + self.initial_points.0.get(pool).cloned().unwrap_or(0); self.character_type.pool(pool) + self.initial_points.0.get(pool).cloned().unwrap_or(0);
@ -255,35 +216,6 @@ impl CharacterSheet {
} }
} }
} }
/*
fn might_pool(&self) -> Pool {
Pool {
current: max,
max,
edge: self.edge(PoolType::Might),
}
}
fn speed_pool(&self) -> Pool {
let max = self.character_type.pool(PoolType::Speed) + self.initial_points.speed;
Pool {
current: max,
max,
edge: self.edge(PoolType::Speed),
}
}
fn intellect_pool(&self) -> Pool {
let max = self.character_type.pool(PoolType::Intellect) + self.initial_points.intellect;
Pool {
current: max,
max,
edge: self.edge(PoolType::Intellect),
}
}
*/
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
@ -339,14 +271,16 @@ edge: flexible
pub const ADAPTABLE: &str = " pub const ADAPTABLE: &str = "
name: Adaptable name: Adaptable
effects: effects:
- specialability: - action:
name: Versatile name: Versatile
description: +2 to any pool, changeable every ten hours description: +2 to any pool, changeable every ten hours
- skill: - skill:
name: Pleasant Social Interactions name: Pleasant Social Interactions
description: Pleasant Social Interactions
level: trained level: trained
- skill: - skill:
name: Overcoming deprivation, sorrow, or pain name: Resilient
description: Overcoming deprivation, sorrow, or pain
level: trained level: trained
"; ";
@ -354,16 +288,17 @@ effects:
Descriptor { Descriptor {
name: "Adaptable".to_owned(), name: "Adaptable".to_owned(),
effects: vec![ effects: vec![
DescriptorAbility::SpecialAbility(versatile()), Ability::Action(versatile()),
DescriptorAbility::Skill(pleasant_social()), Ability::Skill(pleasant_social()),
DescriptorAbility::Skill(overcoming_adversity()), Ability::Skill(overcoming_adversity()),
], ],
} }
} }
pub fn overcoming_adversity() -> Skill { pub fn overcoming_adversity() -> Skill {
Skill { Skill {
name: "Overcoming deprivation, sorrow, or pain".to_owned(), name: "Resilient".to_owned(),
description: "Overcoming the effects of deprivation, sorrow, or pain".to_owned(),
level: SkillLevel::Trained, level: SkillLevel::Trained,
} }
} }
@ -373,8 +308,8 @@ name: Versatile
description: +2 to any pool, changeable every ten hours description: +2 to any pool, changeable every ten hours
"; ";
pub fn versatile() -> SpecialAbility { pub fn versatile() -> Action {
SpecialAbility { Action {
name: "Versatile".to_owned(), name: "Versatile".to_owned(),
cost: Cost::Nothing, cost: Cost::Nothing,
description: "+2 to any pool, changeable every ten hours".to_owned(), description: "+2 to any pool, changeable every ten hours".to_owned(),
@ -422,20 +357,15 @@ tier2:
pub fn silver_tongue() -> Focus { pub fn silver_tongue() -> Focus {
Focus { Focus {
name: "Speaks with a Silver Tongue".to_owned(), name: "Speaks with a Silver Tongue".to_owned(),
tier1: vec![FocusAbility { tier1: vec![Ability::Skill(Skill {
name: "Poetic License".to_owned(), name: "Poetic License".to_owned(),
effect: DescriptorAbility::Skill(Skill { description: "all social interactions".to_owned(),
name: "all social interactions".to_owned(), level: SkillLevel::Trained,
level: SkillLevel::Trained, })],
}), tier2: vec![Ability::Enabler(Enabler {
}],
tier2: vec![FocusAbility {
name: "A Smile and a Word".to_owned(), name: "A Smile and a Word".to_owned(),
effect: DescriptorAbility::Enabler(Enabler { description: "free level of effort on any interaction task".to_owned(),
name: "".to_owned(), })],
descriptor: "free level of effort on any interaction task".to_owned(),
}),
}],
} }
} }
@ -447,12 +377,14 @@ description: Trained in speed defense for ten minutes
pub const PLEASANT_SOCIAL: &str = " pub const PLEASANT_SOCIAL: &str = "
name: Pleasant social interactions name: Pleasant social interactions
description: Pleasant social interactions
level: trained level: trained
"; ";
pub fn pleasant_social() -> Skill { pub fn pleasant_social() -> Skill {
Skill { Skill {
name: "Pleasant social interactions".to_owned(), name: "Pleasant social interactions".to_owned(),
description: "Pleasant social interactions".to_owned(),
level: SkillLevel::Trained, level: SkillLevel::Trained,
} }
} }
@ -503,13 +435,13 @@ mod test {
#[test] #[test]
fn parses_special_ability() { fn parses_special_ability() {
let special: SpecialAbility = serde_yaml::from_str(VERSATILE).expect("should deserialize"); let special: Action = serde_yaml::from_str(VERSATILE).expect("should deserialize");
assert_eq!(special, versatile()); assert_eq!(special, versatile());
} }
#[test] #[test]
fn parses_special_ability_with_cost() { fn parses_special_ability_with_cost() {
let deflect = SpecialAbility { let deflect = Action {
name: "Deflect Attacks".to_owned(), name: "Deflect Attacks".to_owned(),
cost: Cost::Constant { cost: Cost::Constant {
stat: PoolType::Intellect, stat: PoolType::Intellect,
@ -518,19 +450,15 @@ mod test {
description: "Trained in speed defense for ten minutes".to_owned(), description: "Trained in speed defense for ten minutes".to_owned(),
}; };
println!("SPECIAL: {}", serde_yaml::to_string(&deflect).unwrap()); println!("SPECIAL: {}", serde_yaml::to_string(&deflect).unwrap());
let ability: SpecialAbility = let action: Action = serde_yaml::from_str(DEFLECT_ATTACKS).expect("should deserialize");
serde_yaml::from_str(DEFLECT_ATTACKS).expect("should deserialize"); assert_eq!(action, deflect);
assert_eq!(ability, deflect);
} }
#[test] #[test]
fn parses_adaptable_descriptor() { fn parses_adaptable_descriptor() {
let descriptor: Descriptor = serde_yaml::from_str(ADAPTABLE).expect("should deserialize"); let descriptor: Descriptor = serde_yaml::from_str(ADAPTABLE).expect("should deserialize");
assert_eq!(descriptor.effects.len(), 3); assert_eq!(descriptor.effects.len(), 3);
assert_eq!( assert_eq!(descriptor.effects[0], Ability::Action(versatile()));
descriptor.effects[0],
DescriptorAbility::SpecialAbility(versatile())
);
} }
/* /*