summaryrefslogtreecommitdiff
path: root/src/systems/view.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-09-22 15:36:58 +0200
committertroido <troido@protonmail.com>2020-09-22 15:36:58 +0200
commit37ad98cf725aa22f1c793b66102c99c9a76a4ec2 (patch)
treea1f35b025abb36b48c7646e84af76c05fcfac3cf /src/systems/view.rs
parent33c1054d528efd896415baf08d4a52e1cdd7b801 (diff)
can base sprite on equipped items
Diffstat (limited to 'src/systems/view.rs')
-rw-r--r--src/systems/view.rs30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/systems/view.rs b/src/systems/view.rs
index 5ea7ed8..604878f 100644
--- a/src/systems/view.rs
+++ b/src/systems/view.rs
@@ -1,5 +1,4 @@
-
use specs::{
ReadStorage,
WriteStorage,
@@ -7,7 +6,8 @@ use specs::{
Write,
System,
Join,
- Entities
+ Entities,
+ Entity
};
use crate::{
@@ -38,8 +38,15 @@ impl <'a> System<'a> for View {
let changes: Vec<(Pos, Vec<Sprite>)> = ground.changes
.iter()
- .map(|pos| (*pos, cell_sprites(ground.components_on(*pos, &visible))))
- .collect();
+ .map(|pos|
+ (
+ *pos,
+ ground.by_height(pos, &visible).into_iter()
+ .filter_map(|e|
+ entity_sprite(e, &visible, &inventories)
+ ).collect()
+ )
+ ).collect();
let has_changed: bool = !changes.is_empty();
output.output.clear();
@@ -71,8 +78,9 @@ impl <'a> System<'a> for View {
}
updates.ground = Some(
ground
- .by_height(&pos.pos, &visible, &ent)
+ .by_height(&pos.pos, &visible)
.into_iter()
+ .filter(|e| *e != ent)
.map(|ent| visible.get(ent).unwrap().name.clone())
.collect()
);
@@ -84,6 +92,18 @@ impl <'a> System<'a> for View {
}
}
+fn entity_sprite(ent: Entity, visibles: &ReadStorage<Visible>, inventories: &ReadStorage<Inventory>) -> Option<Sprite> {
+ if let Some(inventory) = inventories.get(ent) {
+ if let Some(sprite) = inventory.equipment_sprites().into_iter().next() {
+ return Some(sprite);
+ }
+ }
+ if let Some(visible) = visibles.get(ent) {
+ return Some(visible.sprite.clone());
+ }
+ None
+}
+
fn cell_sprites(mut visibles: Vec<&Visible>) -> Vec<Sprite> {
visibles.sort_by(|a, b| b.height.partial_cmp(&a.height).unwrap());
visibles.iter().map(|vis| vis.sprite.clone()).collect()