summaryrefslogtreecommitdiff
path: root/src/resources/ground.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-04-04 23:48:07 +0200
committertroido <troido@protonmail.com>2020-04-04 23:48:07 +0200
commit068f98cec100772defce8ba966e5b917558b191c (patch)
tree80124cf89852dbedec9322258af36167cc99277b /src/resources/ground.rs
parent2cc5b468cfd4c28bf1ad17ef1b3600c3d42f8b83 (diff)
draw the room after new entities have been added
Diffstat (limited to 'src/resources/ground.rs')
-rw-r--r--src/resources/ground.rs30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/resources/ground.rs b/src/resources/ground.rs
index 8194a44..7411a15 100644
--- a/src/resources/ground.rs
+++ b/src/resources/ground.rs
@@ -8,27 +8,33 @@ use specs::{
};
use crate::{
- components::{Visible, Removed, Flags, Flag},
+ components::{Visible, Flags, Flag},
Pos
};
#[derive(Default)]
pub struct Ground {
- pub cells: HashMap<Pos, HashSet<Entity>>
+ pub cells: HashMap<Pos, HashSet<Entity>>,
+ pub changes: HashSet<Pos>
}
impl Ground {
- pub fn components_on<'a, C: Component>(&self, pos: Pos, component_type: &'a ReadStorage<C>, removals: &'a ReadStorage<Removed>) -> Vec<&'a C> {
- self.cells
- .get(&pos)
- .unwrap_or(&HashSet::new())
- .iter()
- .filter(|e| !removals.contains(**e))
- .filter_map(|e| component_type.get(*e))
- .collect()
+
+ pub fn insert(&mut self, pos: Pos, ent: Entity){
+ self.cells.entry(pos).or_insert_with(HashSet::new).insert(ent);
+ self.changes.insert(pos);
+ }
+
+ pub fn remove(&mut self, pos: &Pos, ent: Entity) -> bool{
+ if let Some(cell) = self.cells.get_mut(pos) {
+ self.changes.insert(*pos);
+ cell.remove(&ent)
+ } else {
+ false
+ }
}
- pub fn all_components_on<'a, C: Component>(&self, pos: Pos, component_type: &'a ReadStorage<C>) -> Vec<&'a C> {
+ pub fn components_on<'a, C: Component>(&self, pos: Pos, component_type: &'a ReadStorage<C>) -> Vec<&'a C> {
self.cells
.get(&pos)
.unwrap_or(&HashSet::new())
@@ -51,6 +57,6 @@ impl Ground {
}
pub fn flags_on<'a>(&self, pos: Pos, flags: &'a ReadStorage<Flags>) -> HashSet<Flag> {
- self.all_components_on::<Flags>(pos, flags).into_iter().fold(HashSet::new(), |a, b| &a | &b.0)
+ self.components_on::<Flags>(pos, flags).into_iter().fold(HashSet::new(), |a, b| &a | &b.0)
}
}