diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/mod.rs | 2 | ||||
| -rw-r--r-- | src/componentwrapper.rs | 10 | ||||
| -rw-r--r-- | src/room.rs | 6 | ||||
| -rw-r--r-- | src/systems/mod.rs | 4 | ||||
| -rw-r--r-- | src/systems/timeout.rs (renamed from src/systems/growth.rs) | 26 |
5 files changed, 24 insertions, 24 deletions
diff --git a/src/components/mod.rs b/src/components/mod.rs index 269b0b2..b1faf08 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -202,7 +202,7 @@ pub struct Loot { #[derive(Component, Debug, Clone)] #[storage(HashMapStorage)] -pub struct Grow { +pub struct Timer { pub delay: i64, pub spread: f64, pub target_time: Option<Timestamp>, diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index f9cb31f..996d922 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -202,19 +202,19 @@ components!( .collect::<Result<Vec<(Template, f64)>>>()? } }; - Grow ( + Timer ( trigger: String (panic!("can't turn trigger to string")), - delay: Int (Grow.delay), - spread: Float (Grow.spread), + delay: Int (Timer.delay), + spread: Float (Timer.spread), target_time: Int ({ - if let Some(time) = Grow.target_time { + if let Some(time) = Timer.target_time { time.0 } else { 0 } }) ) - Grow { + Timer { trigger: Trigger::from_str(&trigger).ok_or(aerr!("invalid trigger name {}", trigger))?, delay, spread, diff --git a/src/room.rs b/src/room.rs index c0e2cd7..dbdb46f 100644 --- a/src/room.rs +++ b/src/room.rs @@ -64,7 +64,7 @@ use crate::{ Spawn, Interact, DropLoot, - Growth, + Timeout, Clear, Building } @@ -72,7 +72,7 @@ use crate::{ pub fn default_dispatcher<'a, 'b>() -> Dispatcher<'a, 'b> { DispatcherBuilder::new() - .with(Growth, "growth", &[]) + .with(Timeout, "timeout", &[]) .with(UpdateCooldowns, "cool_down", &[]) .with(Spawn, "spawn", &[]) .with(ControlInput, "controlinput", &["cool_down"]) @@ -118,7 +118,7 @@ impl <'a, 'b>Room<'a, 'b> { world.insert(NewEntities::new(encyclopedia)); register_insert!( world, - (Position, Visible, Controller, Movable, New, Removed, Moved, Player, Inventory, Health, Serialise, RoomExit, Entered, TriggerBox, Trap, Fighter, Healing, ControlCooldown, Autofight, MonsterAI, Home, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Grow, Equipment, TimeOffset, Flags, Ear, Build), + (Position, Visible, Controller, Movable, New, Removed, Moved, Player, Inventory, Health, Serialise, RoomExit, Entered, TriggerBox, Trap, Fighter, Healing, ControlCooldown, Autofight, MonsterAI, Home, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Timer, Equipment, TimeOffset, Flags, Ear, Build), (Ground, Input, Output, Size, Spawn, Players, Emigration, Time) ); diff --git a/src/systems/mod.rs b/src/systems/mod.rs index fbd5c64..d45fc38 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -18,7 +18,7 @@ mod die; mod spawn; mod interact; mod droploot; -mod growth; +mod timeout; mod clear; mod building; @@ -42,7 +42,7 @@ pub use self::{ spawn::Spawn, interact::Interact, droploot::DropLoot, - growth::Growth, + timeout::Timeout, clear::Clear, building::Building }; diff --git a/src/systems/growth.rs b/src/systems/timeout.rs index 7daa3d7..087ffa9 100644 --- a/src/systems/growth.rs +++ b/src/systems/timeout.rs @@ -11,7 +11,7 @@ use specs::{ use crate::{ components::{ - Grow, + Timer, TimeOffset, TriggerBox }, @@ -19,36 +19,36 @@ use crate::{ }; -pub struct Growth; -impl <'a> System<'a> for Growth{ +pub struct Timeout; +impl <'a> System<'a> for Timeout { type SystemData = ( Entities<'a>, - WriteStorage<'a, Grow>, + WriteStorage<'a, Timer>, WriteStorage<'a, TriggerBox>, Read<'a, Time>, WriteStorage<'a, TimeOffset> ); - fn run(&mut self, (entities, mut grows, mut triggerboxes, time, mut time_offsets): Self::SystemData) { - for (entity, grow) in (&entities, &mut grows).join(){ - if grow.target_time == None { + fn run(&mut self, (entities, mut timers, mut triggerboxes, time, mut time_offsets): Self::SystemData) { + for (entity, timer) in (&entities, &mut timers).join(){ + if timer.target_time == None { let creation_time = time.time + time_offsets.get(entity).map(|ct| ct.dtime).unwrap_or(0); - let mut r = 1.0 - rand::random::<f64>() * grow.spread; + let mut r = 1.0 - rand::random::<f64>() * timer.spread; if rand::random() { r = 1.0 / r; } - let duration = (grow.delay as f64 * r + 0.4) as i64; - grow.target_time = Some(creation_time + duration); + let duration = (timer.delay as f64 * r + 0.4) as i64; + timer.target_time = Some(creation_time + duration); } - let target_time = grow.target_time.unwrap(); + let target_time = timer.target_time.unwrap(); if target_time <= time.time { if target_time < time.time { time_offsets.insert(entity, TimeOffset{dtime: target_time.0 - time.time.0}).unwrap(); } else { time_offsets.remove(entity); } - TriggerBox::add_message(&mut triggerboxes, entity, grow.trigger); - grow.target_time = None; + TriggerBox::add_message(&mut triggerboxes, entity, timer.trigger); + timer.target_time = None; } } } |
