By the power of macros, reduce the amount of syntax required to register components

This commit is contained in:
Timothy Warren 2021-11-04 11:27:44 -04:00
parent cb475708c7
commit 7070fb0357

View File

@ -27,6 +27,17 @@ use player::*;
pub use rect::Rect;
use visibility_system::VisibilitySystem;
/// Cut down on the amount of syntax to register components
macro_rules! register {
// $gs is needed to get the scope at the usage point
// $Type is the Component type that is being registered
($gs: ident, $( $Type: ty ),*,) => {
$(
$gs.ecs.register::<$Type>();
)*
}
}
pub const MAP_SIZE: usize = 80 * 50;
#[derive(PartialEq, Copy, Clone)]
@ -183,22 +194,25 @@ fn main() -> rltk::BError {
let mut gs = State { ecs: World::new() };
gs.ecs.register::<Position>();
gs.ecs.register::<Renderable>();
gs.ecs.register::<Player>();
gs.ecs.register::<Viewshed>();
gs.ecs.register::<Monster>();
gs.ecs.register::<Name>();
gs.ecs.register::<BlocksTile>();
gs.ecs.register::<CombatStats>();
gs.ecs.register::<WantsToMelee>();
gs.ecs.register::<SufferDamage>();
gs.ecs.register::<Item>();
gs.ecs.register::<Potion>();
gs.ecs.register::<InBackpack>();
gs.ecs.register::<WantsToPickupItem>();
gs.ecs.register::<WantsToDrinkPotion>();
gs.ecs.register::<WantsToDropItem>();
register!(
gs,
Position,
Renderable,
Player,
Viewshed,
Monster,
Name,
BlocksTile,
CombatStats,
WantsToMelee,
SufferDamage,
Item,
Potion,
InBackpack,
WantsToPickupItem,
WantsToDrinkPotion,
WantsToDropItem,
);
let map: Map = Map::new_map_rooms_and_corridors();
let (player_x, player_y) = map.rooms[0].center();