summaryrefslogtreecommitdiff
path: root/src/systems
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
parent33c1054d528efd896415baf08d4a52e1cdd7b801 (diff)
can base sprite on equipped items
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/take.rs5
-rw-r--r--src/systems/view.rs30
2 files changed, 28 insertions, 7 deletions
diff --git a/src/systems/take.rs b/src/systems/take.rs
index eedb83c..b055220 100644
--- a/src/systems/take.rs
+++ b/src/systems/take.rs
@@ -6,7 +6,8 @@ use specs::{
WriteStorage,
System,
Join,
- Write
+ Write,
+ Entity
};
use crate::components::{
@@ -41,7 +42,7 @@ impl <'a> System<'a> for Take {
for (ent, controller, position, inventory) in (&entities, &controllers, &positions, &mut inventories).join(){
match &controller.control {
Control::Take(rank) if inventory.items.len() < inventory.capacity => {
- let mut ents = ground.by_height(&position.pos, &visibles, &ent);
+ let mut ents: Vec<Entity> = ground.by_height(&position.pos, &visibles).into_iter().filter(|e| *e != ent).collect();
if let Some(idx) = rank {
if *idx >= ents.len() {
return
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()