summaryrefslogtreecommitdiff
path: root/src/systems/growth.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-04-01 14:31:28 +0200
committertroido <troido@protonmail.com>2020-04-01 14:31:28 +0200
commita911b7fabbaac429efd1747c3b1e925f679752f9 (patch)
tree3a6a3f0482e485a546cbf6ac87b1d131dc9cd718 /src/systems/growth.rs
parent1ceb4c6f23287bca98f0c3946d5678dce5d0457c (diff)
growing should theoretically work after room unloading
Diffstat (limited to 'src/systems/growth.rs')
-rw-r--r--src/systems/growth.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/systems/growth.rs b/src/systems/growth.rs
index 7472115..97ae5f3 100644
--- a/src/systems/growth.rs
+++ b/src/systems/growth.rs
@@ -15,9 +15,11 @@ use crate::{
components::{
Position,
Grow,
- Removed
+ Removed,
+ CreationTime
},
- resources::{NewEntities, Time}
+ resources::{NewEntities, Time},
+ componentwrapper::ComponentWrapper
};
@@ -29,19 +31,24 @@ impl <'a> System<'a> for Growth{
Write<'a, NewEntities>,
WriteStorage<'a, Grow>,
WriteStorage<'a, Removed>,
- Read<'a, Time>
+ Read<'a, Time>,
+ ReadStorage<'a, CreationTime>
);
- fn run(&mut self, (entities, positions, mut new, mut grows, mut removeds, time): Self::SystemData) {
+ fn run(&mut self, (entities, positions, mut new, mut grows, mut removeds, time, creation_times): Self::SystemData) {
for (entity, position, grow) in (&entities, &positions, &mut grows).join(){
+ let creation_time = creation_times.get(entity).map(|ct| ct.time).unwrap_or(time.time);
if grow.target_time == None {
let duration = grow.delay as f64 * (1.0 + rand::random::<f64>()) / (if rand::random() {1.0} else {2.0});
- grow.target_time = Some(time.time + duration as i64);
+ grow.target_time = Some(creation_time + duration as i64);
}
- if grow.target_time.unwrap() <= time.time {
+ let target_time = grow.target_time.unwrap();
+ if target_time <= time.time {
removeds.insert(entity, Removed).unwrap();
// todo: error handling
- new.create(position.pos, grow.into.clone()).unwrap();
+ let mut preent = new.encyclopedia.construct(&grow.into).unwrap();
+ preent.push(ComponentWrapper::CreationTime(CreationTime{time: target_time + 1}));
+ new.to_build.push((position.pos, preent));
}
}
}