refactor delay matching logic
This commit is contained in:
parent
279ab5795e
commit
79f5e7e1be
@ -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);
|
||||
|
||||
@ -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)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user