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];
|
const newRes = game.resolutions[game.resolutions.length - 2];
|
||||||
console.log(newRes);
|
console.log(newRes);
|
||||||
return eachSeries(newRes, (r, cb) => {
|
return eachSeries(newRes, (r, cb) => {
|
||||||
const timeout = r.delay;
|
if (r.delay === 0) return cb(); // TargetKo etc
|
||||||
if (timeout === 0) return cb(); // TargetKo etc
|
|
||||||
setAnimations(r, store);
|
setAnimations(r, store);
|
||||||
return setTimeout(cb, timeout);
|
return setTimeout(cb, r.delay);
|
||||||
}, err => {
|
}, err => {
|
||||||
if (err) return console.error(err);
|
if (err) return console.error(err);
|
||||||
clearAnimations(store);
|
clearAnimations(store);
|
||||||
|
|||||||
@ -960,7 +960,7 @@ pub enum Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 source_overlapping = 500;
|
||||||
let target_overlapping = 900;
|
let target_overlapping = 900;
|
||||||
|
|
||||||
@ -968,33 +968,46 @@ impl Event {
|
|||||||
let target_duration = 1500;
|
let target_duration = 1500;
|
||||||
let combat_text_duration = 1300;
|
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 {
|
match self {
|
||||||
Event::Cast { construct: _, direction: _, player: _ } => {
|
Event::Cast { construct: _, direction: _, player: _ } => Animation::Source,
|
||||||
match next_event {
|
|
||||||
Some(e) => {
|
|
||||||
match e.event {
|
|
||||||
Event::Cast { construct: _, direction: _, player: _ } => source_duration,
|
|
||||||
_ => source_overlapping,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => source_duration
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Event::Hit { construct: _, direction: _, player: _ } |
|
Event::Hit { construct: _, direction: _, player: _ } |
|
||||||
Event::HitAoe { construct: _, direction: _, player: _ } => {
|
Event::HitAoe { construct: _, direction: _, player: _ } => Animation::Target,
|
||||||
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::Damage { construct: _, amount: _, mitigation: _, colour: _, display: _ } |
|
Event::Damage { construct: _, amount: _, mitigation: _, colour: _, display: _ } |
|
||||||
Event::Effect { construct: _, effect: _, duration: _, display: _ } |
|
Event::Effect { construct: _, effect: _, duration: _, display: _ } |
|
||||||
Event::Removal { construct: _, effect: _, display: _ } |
|
Event::Removal { construct: _, effect: _, display: _ } |
|
||||||
@ -1003,16 +1016,23 @@ impl Event {
|
|||||||
Event::Reflection { construct: _ } |
|
Event::Reflection { construct: _ } |
|
||||||
Event::Ko { construct: _ } |
|
Event::Ko { construct: _ } |
|
||||||
Event::CooldownIncrease { construct: _, turns: _ } |
|
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::TargetKo { construct: _ } |
|
||||||
Event::Disable { construct: _, effects: _ } |
|
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
|
// used to show the progress of a construct
|
||||||
// while the resolutions are animating
|
// while the resolutions are animating
|
||||||
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
|
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user