diff options
author | Griffin Smith <root@gws.fyi> | 2019-07-20T01·55-0400 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2019-07-20T01·55-0400 |
commit | 29c80ac8ba0d733c6c452d8fd39e9561553495b0 (patch) | |
tree | f8384229d84b0d281c2fbbe976aeb5ebc21bdc24 /src/entities/raws.rs | |
parent | 4e9138aa6ff72e34392e3467c40d5ddf095f0027 (diff) |
Add the beginning of item entities
Add a new Item raw type and entity type, with preliminary, basic support for food. There's a really frustrating toml-rs bug that prevents writing these nicely as toml right now, so I also added support for mixing JSON and TOML in a single config dir
Diffstat (limited to 'src/entities/raws.rs')
-rw-r--r-- | src/entities/raws.rs | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/src/entities/raws.rs b/src/entities/raws.rs index da061d89d8d6..2c4a8203cb17 100644 --- a/src/entities/raws.rs +++ b/src/entities/raws.rs @@ -1,37 +1,8 @@ -use crate::entities::entity_char::EntityChar; -use crate::types::Speed; +pub use crate::entities::raw_types::{CreatureType, EntityRaw, ItemType}; use std::collections::HashMap; -#[derive(Debug, Deserialize)] -pub struct CreatureType<'a> { - /// The name of the creature. Used in raw lookups. - pub name: &'a str, - - /// A description of the entity, used by the "look" command - pub description: &'a str, - - #[serde(rename = "char")] - pub chr: EntityChar, - pub max_hitpoints: u16, - pub speed: Speed, - pub friendly: bool, -} - -#[derive(Debug, Deserialize)] -pub enum EntityRaw<'a> { - Creature(#[serde(borrow)] CreatureType<'a>), -} - -impl<'a> EntityRaw<'a> { - pub fn name(&self) -> &'a str { - match self { - EntityRaw::Creature(typ) => typ.name, - } - } -} - static_cfg! { - static ref RAWS: Vec<EntityRaw<'static>> = toml_dir("src/entities/raws"); + static ref RAWS: Vec<EntityRaw<'static>> = cfg_dir("src/entities/raws"); } lazy_static! { @@ -54,3 +25,14 @@ pub fn raw(name: &'static str) -> &'static EntityRaw<'static> { .map(|e| *e) .expect(format!("Raw not found: {}", name).as_str()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_raws() { + RAWS_BY_NAME.keys(); + assert_eq!(raw("noodles").name(), "noodles"); + } +} |