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,
|
pub dirty: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Viewshed {
|
||||||
|
fn default() -> Self {
|
||||||
|
Viewshed {
|
||||||
|
visible_tiles: Vec::new(),
|
||||||
|
range: 8,
|
||||||
|
dirty: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
pub struct Monster {}
|
pub struct Monster {}
|
||||||
|
|
||||||
@ -34,6 +44,14 @@ pub struct Name {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Name {
|
||||||
|
pub fn new<S: ToString>(s: S) -> Self {
|
||||||
|
Name {
|
||||||
|
name: s.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
pub struct BlocksTile {}
|
pub struct BlocksTile {}
|
||||||
|
|
||||||
|
@ -22,14 +22,8 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
|
|||||||
render_order: 0,
|
render_order: 0,
|
||||||
})
|
})
|
||||||
.with(Player {})
|
.with(Player {})
|
||||||
.with(Viewshed {
|
.with(Viewshed::default())
|
||||||
visible_tiles: Vec::new(),
|
.with(Name::new("Player"))
|
||||||
range: 8,
|
|
||||||
dirty: true,
|
|
||||||
})
|
|
||||||
.with(Name {
|
|
||||||
name: "Player".to_string(),
|
|
||||||
})
|
|
||||||
.with(CombatStats {
|
.with(CombatStats {
|
||||||
max_hp: 30,
|
max_hp: 30,
|
||||||
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),
|
bg: RGB::named(rltk::BLACK),
|
||||||
render_order: 1,
|
render_order: 1,
|
||||||
})
|
})
|
||||||
.with(Viewshed {
|
.with(Viewshed::default())
|
||||||
visible_tiles: Vec::new(),
|
|
||||||
range: 8,
|
|
||||||
dirty: true,
|
|
||||||
})
|
|
||||||
.with(Monster {})
|
.with(Monster {})
|
||||||
.with(Name {
|
.with(Name::new(name))
|
||||||
name: name.to_string(),
|
|
||||||
})
|
|
||||||
.with(BlocksTile {})
|
.with(BlocksTile {})
|
||||||
.with(CombatStats {
|
.with(CombatStats {
|
||||||
max_hp: 16,
|
max_hp: 16,
|
||||||
|
Loading…
Reference in New Issue
Block a user