diff options
| author | troido <troido@protonmail.com> | 2020-04-16 10:54:23 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-04-16 10:54:23 +0200 |
| commit | 905c6b649521296bba609db5b5c9a39008d34325 (patch) | |
| tree | 8d253de507b3663399e23819bf8b4a222e7b64a5 /src/systems/deduplicate.rs | |
| parent | 43bde225ebbadd0b917ca87f3164a50455a2b588 (diff) | |
add visit whitelist to homeportal, save and dedup its data even though it is loaded from template
Diffstat (limited to 'src/systems/deduplicate.rs')
| -rw-r--r-- | src/systems/deduplicate.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/systems/deduplicate.rs b/src/systems/deduplicate.rs new file mode 100644 index 0000000..e9fb88a --- /dev/null +++ b/src/systems/deduplicate.rs @@ -0,0 +1,57 @@ + +use std::collections::HashSet; + +use specs::{ + Read, + WriteStorage, + ReadStorage, + Entities, + Entity, + System, + Join +}; + +use crate::{ + components::{Dedup, Removed, New, Position}, + resources::Ground +}; + + +pub struct Deduplicate; +impl <'a> System<'a> for Deduplicate { + type SystemData = ( + Entities<'a>, + WriteStorage<'a, Dedup>, + WriteStorage<'a, Removed>, + ReadStorage<'a, New>, + ReadStorage<'a, Position>, + Read<'a, Ground> + ); + fn run(&mut self, (entities, mut dedups, mut removeds, news, positions, ground): Self::SystemData) { + for (entity, dedup, position, _) in (&entities, &dedups, &positions, &news).join() { + let others: Vec<(Entity, &Dedup)> = ground.cells + .get(&position.pos) + .unwrap_or(&HashSet::new()) + .iter() + .filter_map(|e| Some((*e, dedups.get(*e)?))) + .collect(); + for (e, d) in others { + if dedup.id == d.id { + if dedup.priority > d.priority { + removeds.insert(e, Removed).unwrap(); + } else if dedup.priority < d.priority { + removeds.insert(entity, Removed).unwrap(); + } else if entity > e { + removeds.insert(e, Removed).unwrap(); + } else if entity < e { + removeds.insert(entity, Removed).unwrap(); + } + } + } + } + for (dedup, _) in (&mut dedups, &news).join() { + dedup.priority += 1; + } + } +} + |
