Cut down on some struct boilerplate
This commit is contained in:
parent
4e9869b09f
commit
ef8d51de1f
@ -26,6 +26,16 @@ pub struct Viewshed {
|
||||
pub dirty: bool,
|
||||
}
|
||||
|
||||
impl Default for Viewshed {
|
||||
fn default() -> Self {
|
||||
Viewshed {
|
||||
visible_tiles: Vec::new(),
|
||||
range: 8,
|
||||
dirty: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct Monster {}
|
||||
|
||||
@ -34,6 +44,14 @@ pub struct Name {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl Name {
|
||||
pub fn new<S: ToString>(s: S) -> Self {
|
||||
Name {
|
||||
name: s.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct BlocksTile {}
|
||||
|
||||
|
@ -22,14 +22,8 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
|
||||
render_order: 0,
|
||||
})
|
||||
.with(Player {})
|
||||
.with(Viewshed {
|
||||
visible_tiles: Vec::new(),
|
||||
range: 8,
|
||||
dirty: true,
|
||||
})
|
||||
.with(Name {
|
||||
name: "Player".to_string(),
|
||||
})
|
||||
.with(Viewshed::default())
|
||||
.with(Name::new("Player"))
|
||||
.with(CombatStats {
|
||||
max_hp: 30,
|
||||
hp: 30,
|
||||
@ -71,15 +65,9 @@ fn monster<S: ToString>(ecs: &mut World, x: i32, y: i32, glyph: rltk::FontCharTy
|
||||
bg: RGB::named(rltk::BLACK),
|
||||
render_order: 1,
|
||||
})
|
||||
.with(Viewshed {
|
||||
visible_tiles: Vec::new(),
|
||||
range: 8,
|
||||
dirty: true,
|
||||
})
|
||||
.with(Viewshed::default())
|
||||
.with(Monster {})
|
||||
.with(Name {
|
||||
name: name.to_string(),
|
||||
})
|
||||
.with(Name::new(name))
|
||||
.with(BlocksTile {})
|
||||
.with(CombatStats {
|
||||
max_hp: 16,
|
||||
|
Loading…
Reference in New Issue
Block a user