diff options
| author | troido <troido@protonmail.com> | 2020-03-09 16:54:26 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-03-09 16:54:26 +0100 |
| commit | 69ac6eb6153b016c39bbe55c85f15e3478032182 (patch) | |
| tree | 31a0a5cf3d768688c7600902364446d55e3f4395 /src/componentwrapper.rs | |
| parent | a1f45d1b40b23cb7e9f0b277f24ad66880b0bc56 (diff) | |
can now include variables (like health) in serialisation
Diffstat (limited to 'src/componentwrapper.rs')
| -rw-r--r-- | src/componentwrapper.rs | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index a49ac79..b1fd64d 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -83,27 +83,24 @@ macro_rules! components { } use specs::{World, Entity, WorldExt}; - pub fn extract_parameter(typ: ComponentType, parameter: &str, world: World, ent: Entity) -> Option<Parameter> { + pub fn extract_parameter(typ: ComponentType, parameter: &str, world: &World, ent: Entity) -> Option<Parameter> { match typ { $( #[allow(path_statements)] ComponentType::$comp => { - None::<Parameter> $( - ; if parameter == stringify!($paramname) { #[allow(unreachable_code, non_snake_case)] - Some(Parameter::$paramtype({ + return Some(Parameter::$paramtype({ let components = world.read_component::<crate::components::$comp>(); #[allow(unused_variables)] let $comp = components.get(ent)?; $extraction })) - } else { - None } )* + None::<Parameter> } )* } @@ -119,7 +116,7 @@ macro_rules! components { }; // full definition minus variable exraction (pre: ($($done: tt)*) $comp: ident ($($paramname: ident : $paramtype: ident),*) $creation: expr; $($tail:tt)*) => { - components!(pre: ($($done)* $comp ($($paramname : $paramtype, {panic!(format!("can not extract {} for {}", stringify!($paramname), stringify!($comp)))}),*) $creation;) $($tail)*); + components!(pre: ($($done)* $comp ($($paramname : $paramtype, {None?}),*) $creation;) $($tail)*); }; // full definition (pre: ($($done: tt)*) $comp: ident ($($paramname: ident : $paramtype: ident ($extraction: expr)),*) $creation: expr; $($tail:tt)*) => { @@ -146,7 +143,7 @@ components!( Item (ent: Template, name: String, action: Action); Inventory () {panic!("inventory from parameters not implemented")}; Health (health: Int, maxhealth: Int); - Serialise (template: Template); + Serialise () {panic!("serialise from parameters not implemented")}; RoomExit (destination: String, dest_pos: String) { RoomExit { destination: RoomId::from_str(&destination), |
