Clean up data structure redundancies
This commit is contained in:
parent
0588a803cf
commit
39e9b0564b
|
@ -77,28 +77,11 @@ pub struct Pool {
|
|||
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)]
|
||||
pub struct PointAllocation(HashMap<PoolType, u8>);
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct SpecialAbility {
|
||||
pub struct Action {
|
||||
name: String,
|
||||
#[serde(default)]
|
||||
cost: Cost,
|
||||
|
@ -116,9 +99,37 @@ pub enum SkillLevel {
|
|||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Skill {
|
||||
name: String,
|
||||
description: String,
|
||||
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)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Range {
|
||||
|
@ -143,40 +154,6 @@ pub struct Defense {
|
|||
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)]
|
||||
pub struct CharacterSheet {
|
||||
name: String,
|
||||
|
@ -189,7 +166,6 @@ pub struct CharacterSheet {
|
|||
tier: Tier,
|
||||
effort: u8,
|
||||
cypher_limit: u8,
|
||||
special_abilities: Vec<SpecialAbility>,
|
||||
skills: Vec<Skill>,
|
||||
attacks: Vec<Attack>,
|
||||
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 {
|
||||
let max =
|
||||
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)]
|
||||
|
@ -339,14 +271,16 @@ edge: flexible
|
|||
pub const ADAPTABLE: &str = "
|
||||
name: Adaptable
|
||||
effects:
|
||||
- specialability:
|
||||
- action:
|
||||
name: Versatile
|
||||
description: +2 to any pool, changeable every ten hours
|
||||
- skill:
|
||||
name: Pleasant Social Interactions
|
||||
description: Pleasant Social Interactions
|
||||
level: trained
|
||||
- skill:
|
||||
name: Overcoming deprivation, sorrow, or pain
|
||||
name: Resilient
|
||||
description: Overcoming deprivation, sorrow, or pain
|
||||
level: trained
|
||||
";
|
||||
|
||||
|
@ -354,16 +288,17 @@ effects:
|
|||
Descriptor {
|
||||
name: "Adaptable".to_owned(),
|
||||
effects: vec![
|
||||
DescriptorAbility::SpecialAbility(versatile()),
|
||||
DescriptorAbility::Skill(pleasant_social()),
|
||||
DescriptorAbility::Skill(overcoming_adversity()),
|
||||
Ability::Action(versatile()),
|
||||
Ability::Skill(pleasant_social()),
|
||||
Ability::Skill(overcoming_adversity()),
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn overcoming_adversity() -> 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,
|
||||
}
|
||||
}
|
||||
|
@ -373,8 +308,8 @@ name: Versatile
|
|||
description: +2 to any pool, changeable every ten hours
|
||||
";
|
||||
|
||||
pub fn versatile() -> SpecialAbility {
|
||||
SpecialAbility {
|
||||
pub fn versatile() -> Action {
|
||||
Action {
|
||||
name: "Versatile".to_owned(),
|
||||
cost: Cost::Nothing,
|
||||
description: "+2 to any pool, changeable every ten hours".to_owned(),
|
||||
|
@ -422,20 +357,15 @@ tier2:
|
|||
pub fn silver_tongue() -> Focus {
|
||||
Focus {
|
||||
name: "Speaks with a Silver Tongue".to_owned(),
|
||||
tier1: vec![FocusAbility {
|
||||
tier1: vec![Ability::Skill(Skill {
|
||||
name: "Poetic License".to_owned(),
|
||||
effect: DescriptorAbility::Skill(Skill {
|
||||
name: "all social interactions".to_owned(),
|
||||
level: SkillLevel::Trained,
|
||||
}),
|
||||
}],
|
||||
tier2: vec![FocusAbility {
|
||||
description: "all social interactions".to_owned(),
|
||||
level: SkillLevel::Trained,
|
||||
})],
|
||||
tier2: vec![Ability::Enabler(Enabler {
|
||||
name: "A Smile and a Word".to_owned(),
|
||||
effect: DescriptorAbility::Enabler(Enabler {
|
||||
name: "".to_owned(),
|
||||
descriptor: "free level of effort on any interaction task".to_owned(),
|
||||
}),
|
||||
}],
|
||||
description: "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 = "
|
||||
name: Pleasant social interactions
|
||||
description: Pleasant social interactions
|
||||
level: trained
|
||||
";
|
||||
|
||||
pub fn pleasant_social() -> Skill {
|
||||
Skill {
|
||||
name: "Pleasant social interactions".to_owned(),
|
||||
description: "Pleasant social interactions".to_owned(),
|
||||
level: SkillLevel::Trained,
|
||||
}
|
||||
}
|
||||
|
@ -503,13 +435,13 @@ mod test {
|
|||
|
||||
#[test]
|
||||
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());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_special_ability_with_cost() {
|
||||
let deflect = SpecialAbility {
|
||||
let deflect = Action {
|
||||
name: "Deflect Attacks".to_owned(),
|
||||
cost: Cost::Constant {
|
||||
stat: PoolType::Intellect,
|
||||
|
@ -518,19 +450,15 @@ mod test {
|
|||
description: "Trained in speed defense for ten minutes".to_owned(),
|
||||
};
|
||||
println!("SPECIAL: {}", serde_yaml::to_string(&deflect).unwrap());
|
||||
let ability: SpecialAbility =
|
||||
serde_yaml::from_str(DEFLECT_ATTACKS).expect("should deserialize");
|
||||
assert_eq!(ability, deflect);
|
||||
let action: Action = serde_yaml::from_str(DEFLECT_ATTACKS).expect("should deserialize");
|
||||
assert_eq!(action, deflect);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_adaptable_descriptor() {
|
||||
let descriptor: Descriptor = serde_yaml::from_str(ADAPTABLE).expect("should deserialize");
|
||||
assert_eq!(descriptor.effects.len(), 3);
|
||||
assert_eq!(
|
||||
descriptor.effects[0],
|
||||
DescriptorAbility::SpecialAbility(versatile())
|
||||
);
|
||||
assert_eq!(descriptor.effects[0], Ability::Action(versatile()));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue