Start building data fixture parsers
This commit is contained in:
parent
ff18c4a0e7
commit
ec759984cd
|
@ -191,6 +191,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_yaml",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
|
@ -234,6 +235,12 @@ dependencies = [
|
|||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dtoa"
|
||||
version = "0.4.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.6.1"
|
||||
|
@ -1327,6 +1334,18 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_yaml"
|
||||
version = "0.8.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8c608a35705a5d3cdc9fbe403147647ff34b921f8e833e49306df898f9b20af"
|
||||
dependencies = [
|
||||
"dtoa",
|
||||
"indexmap",
|
||||
"serde",
|
||||
"yaml-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha-1"
|
||||
version = "0.9.8"
|
||||
|
|
|
@ -9,3 +9,6 @@ edition = "2018"
|
|||
serde = { version = "1" }
|
||||
serde_derive = { version = "1" }
|
||||
thiserror = { version = "1" }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_yaml = { version = "*" }
|
||||
|
|
|
@ -8,43 +8,41 @@ pub enum Error {
|
|||
TierOutOfRange(u8),
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum CharacterType {
|
||||
Arkus,
|
||||
Delve,
|
||||
Glaive,
|
||||
Jack { edge: PoolType },
|
||||
Nano,
|
||||
Wright,
|
||||
}
|
||||
|
||||
impl From<&CharacterType> for String {
|
||||
fn from(type_: &CharacterType) -> String {
|
||||
match type_ {
|
||||
CharacterType::Arkus => "Arkus",
|
||||
CharacterType::Delve => "Delve",
|
||||
CharacterType::Glaive => "Glaive",
|
||||
CharacterType::Jack { .. } => "Jack",
|
||||
CharacterType::Nano => "Nano",
|
||||
CharacterType::Wright => "Wright",
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CharacterType> for String {
|
||||
fn from(type_: CharacterType) -> String {
|
||||
String::from(&type_)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum PoolType {
|
||||
Might,
|
||||
Speed,
|
||||
Intellect,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum CharacterTypeEdge {
|
||||
Flexible,
|
||||
Static(HashMap<PoolType, u8>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct CharacterType {
|
||||
text: String,
|
||||
starting_pools: HashMap<PoolType, u8>,
|
||||
edge: CharacterTypeEdge,
|
||||
}
|
||||
|
||||
impl CharacterType {
|
||||
fn pool(&self, type_: PoolType) -> u8 {
|
||||
self.starting_pools.get(&type_).unwrap().clone()
|
||||
}
|
||||
|
||||
fn edge(&self, type_: PoolType) -> u8 {
|
||||
match self.edge {
|
||||
CharacterTypeEdge::Flexible => 0,
|
||||
CharacterTypeEdge::Static(ref edge) => edge.get(&type_).unwrap_or(&0).clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum Cost {
|
||||
Nothing,
|
||||
|
@ -175,10 +173,7 @@ impl CharacterSheet {
|
|||
};
|
||||
format!(
|
||||
"{} {} {} who {}",
|
||||
article,
|
||||
self.descriptor,
|
||||
String::from(&self.character_type),
|
||||
self.focus
|
||||
article, self.descriptor, self.character_type.text, self.focus
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -196,6 +191,7 @@ impl CharacterSheet {
|
|||
}
|
||||
|
||||
fn might_pool(&self) -> Pool {
|
||||
/*
|
||||
let (base, edge) = match self.character_type {
|
||||
CharacterType::Glaive => (11, 1),
|
||||
CharacterType::Jack {
|
||||
|
@ -209,11 +205,16 @@ impl CharacterSheet {
|
|||
};
|
||||
let max = base + self.initial_points.might;
|
||||
let current = max;
|
||||
*/
|
||||
let max = 10;
|
||||
let current = 10;
|
||||
let edge = 1;
|
||||
|
||||
Pool { max, current, edge }
|
||||
}
|
||||
|
||||
fn speed_pool(&self) -> Pool {
|
||||
/*
|
||||
let (base, edge) = match self.character_type {
|
||||
CharacterType::Glaive => (10, 1),
|
||||
CharacterType::Jack {
|
||||
|
@ -227,10 +228,16 @@ impl CharacterSheet {
|
|||
};
|
||||
let max = base + self.initial_points.speed;
|
||||
let current = max;
|
||||
*/
|
||||
|
||||
let max = 10;
|
||||
let current = 10;
|
||||
let edge = 1;
|
||||
Pool { max, current, edge }
|
||||
}
|
||||
|
||||
fn intellect_pool(&self) -> Pool {
|
||||
/*
|
||||
let (base, edge) = match self.character_type {
|
||||
CharacterType::Glaive => (7, 0),
|
||||
CharacterType::Jack {
|
||||
|
@ -244,7 +251,11 @@ impl CharacterSheet {
|
|||
};
|
||||
let max = base + self.initial_points.intellect;
|
||||
let current = max;
|
||||
*/
|
||||
|
||||
let max = 10;
|
||||
let current = 10;
|
||||
let edge = 1;
|
||||
Pool { max, current, edge }
|
||||
}
|
||||
}
|
||||
|
@ -269,6 +280,25 @@ struct Cypher {
|
|||
mod test_data {
|
||||
use super::*;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub const GLAIVE_DESCRIPTOR: &str = "text: Glaive
|
||||
starting_pools:
|
||||
might: 11
|
||||
speed: 10
|
||||
intellect: 7
|
||||
edge:
|
||||
static:
|
||||
might: 1
|
||||
speed: 1";
|
||||
pub const JACK_DESCRIPTOR: &str = "text: Jack
|
||||
starting_pools:
|
||||
might: 10
|
||||
speed: 10
|
||||
intellect: 10
|
||||
edge: flexible
|
||||
";
|
||||
|
||||
/*
|
||||
#[allow(dead_code)]
|
||||
pub fn opal() -> CharacterSheet {
|
||||
CharacterSheet {
|
||||
|
@ -349,12 +379,32 @@ mod test_data {
|
|||
*/
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use super::{test_data::*, *};
|
||||
use serde_yaml;
|
||||
|
||||
#[test]
|
||||
fn parses_character_type() {
|
||||
let glaive: CharacterType =
|
||||
serde_yaml::from_str(GLAIVE_DESCRIPTOR).expect("should deserialize");
|
||||
assert_eq!(glaive.text, "Glaive");
|
||||
assert_eq!(glaive.pool(PoolType::Might), 11);
|
||||
assert_eq!(glaive.edge(PoolType::Might), 1);
|
||||
assert_eq!(glaive.edge(PoolType::Intellect), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_character_type_with_flexible_edge() {
|
||||
let jack: CharacterType =
|
||||
serde_yaml::from_str(JACK_DESCRIPTOR).expect("should deserialize");
|
||||
assert_eq!(jack.text, "Jack");
|
||||
}
|
||||
|
||||
/*
|
||||
#[test]
|
||||
fn opals_character_sheet() {
|
||||
let opal = super::test_data::opal();
|
||||
|
@ -391,4 +441,5 @@ mod test {
|
|||
}
|
||||
);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue