From 79f5e7e1be5182ea0d59f17fa7ff34ff0b07975a Mon Sep 17 00:00:00 2001 From: Mashy Date: Wed, 11 Dec 2019 08:25:55 +1000 Subject: [PATCH] refactor delay matching logic --- client/src/events.jsx | 5 ++- core/src/game.rs | 78 +++++++++++++++++++++++++++---------------- 2 files changed, 51 insertions(+), 32 deletions(-) diff --git a/client/src/events.jsx b/client/src/events.jsx index 19a06f23..653db33b 100644 --- a/client/src/events.jsx +++ b/client/src/events.jsx @@ -89,10 +89,9 @@ function registerEvents(store) { const newRes = game.resolutions[game.resolutions.length - 2]; console.log(newRes); return eachSeries(newRes, (r, cb) => { - const timeout = r.delay; - if (timeout === 0) return cb(); // TargetKo etc + if (r.delay === 0) return cb(); // TargetKo etc setAnimations(r, store); - return setTimeout(cb, timeout); + return setTimeout(cb, r.delay); }, err => { if (err) return console.error(err); clearAnimations(store); diff --git a/core/src/game.rs b/core/src/game.rs index 9ad3daec..d0d66a71 100644 --- a/core/src/game.rs +++ b/core/src/game.rs @@ -960,7 +960,7 @@ pub enum Event { } impl Event { - fn delay(&self, next_event: Option<&&mut Resolution>) -> i64 { + fn delay(&self, next: Option<&&mut Resolution>) -> i64 { let source_overlapping = 500; let target_overlapping = 900; @@ -968,33 +968,46 @@ impl Event { let target_duration = 1500; let combat_text_duration = 1300; - // Exhaustively match all events so they're all properly considered + let animation = self.animation(); + let next_animation = match next { + Some(r) => r.event.animation(), + None => Animation::Skip, + }; + + // Exhaustively match all types so they're all properly considered + match animation { + Animation::Source => { + match next_animation { + Animation::Target | + Animation::Text => source_overlapping, + + Animation::Source | + Animation::Skip => source_duration, + } + }, + + Animation::Target => { + match next_animation { + Animation::Text => target_overlapping, + + Animation::Source | + Animation::Target | + Animation::Skip => target_duration, + } + }, + + Animation::Text => combat_text_duration, + Animation::Skip => 0, + } + } + + fn animation(&self) -> Animation { match self { - Event::Cast { construct: _, direction: _, player: _ } => { - match next_event { - Some(e) => { - match e.event { - Event::Cast { construct: _, direction: _, player: _ } => source_duration, - _ => source_overlapping, - } - }, - None => source_duration - } - }, + Event::Cast { construct: _, direction: _, player: _ } => Animation::Source, + Event::Hit { construct: _, direction: _, player: _ } | - Event::HitAoe { construct: _, direction: _, player: _ } => { - match next_event { - Some(e) => { - match e.event { - Event::Cast { construct: _, direction: _, player: _ } | - Event::Hit { construct: _, direction: _, player: _ } => target_duration, - _ => target_overlapping, - } - } - None => target_duration, - } - }, - // Events that show combat text + Event::HitAoe { construct: _, direction: _, player: _ } => Animation::Target, + Event::Damage { construct: _, amount: _, mitigation: _, colour: _, display: _ } | Event::Effect { construct: _, effect: _, duration: _, display: _ } | Event::Removal { construct: _, effect: _, display: _ } | @@ -1003,16 +1016,23 @@ impl Event { Event::Reflection { construct: _ } | Event::Ko { construct: _ } | Event::CooldownIncrease { construct: _, turns: _ } | - Event::CooldownDecrease { construct: _, turns: _ } => combat_text_duration, + Event::CooldownDecrease { construct: _, turns: _ } => Animation::Text, - // Events that are skipped on client Event::TargetKo { construct: _ } | Event::Disable { construct: _, effects: _ } | - Event::Forfeit() => 0, + Event::Forfeit() => Animation::Skip, } } } +#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)] +pub enum Animation { + Source, + Target, + Text, + Skip, +} + // used to show the progress of a construct // while the resolutions are animating #[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]