event structure clean up

This commit is contained in:
Mashy 2019-12-09 08:32:56 +10:00
parent 2cc7be5b50
commit 912b2c9059
4 changed files with 22 additions and 22 deletions

View File

@ -2,15 +2,14 @@ const actions = require('./actions');
const { TIMES } = require('./constants'); const { TIMES } = require('./constants');
function setAnimations(r, store, account) { function setAnimations(r, store, account) {
const { cast, focus, event, delay } = r; const { skill, focus, event: [type, variant] } = r;
const { source, target, player, skill } = cast;
store.dispatch(actions.setAnimFocus(r.focus)); store.dispatch(actions.setAnimFocus(focus));
if (r.event[0] === 'Cast') { if (type === 'Cast') {
store.dispatch(actions.setAnimText(null)); store.dispatch(actions.setAnimText(null));
const { construct, direction: [x, y] } = r.event[1]; const { construct, player, direction: [x, y] } = variant;
const animY = y && player === account.id ? -1 : y; const animY = y && player === account.id ? -1 : y;
const animSource = { const animSource = {
animation: 'sourceCast', animation: 'sourceCast',
@ -22,10 +21,10 @@ function setAnimations(r, store, account) {
return setTimeout(() => store.dispatch(actions.setAnimSource(null)), TIMES.SOURCE_DURATION_MS); return setTimeout(() => store.dispatch(actions.setAnimSource(null)), TIMES.SOURCE_DURATION_MS);
} }
if (r.event[0].includes('Hit')) { if (type.includes('Hit')) {
store.dispatch(actions.setAnimText(null)); store.dispatch(actions.setAnimText(null));
const { construct, direction: [x, y] } = r.event[1]; const { construct, player, direction: [x, y] } = variant;
const animY = y && player === account.id ? -1 : y; const animY = y && player === account.id ? -1 : y;
const isPlayer = player === account.id; const isPlayer = player === account.id;
const animTarget = { const animTarget = {

View File

@ -31,7 +31,7 @@ class AnimText extends preact.Component {
const { construct, animText, itemInfo } = this.props; const { construct, animText, itemInfo } = this.props;
if (animText && animText.event[1].construct === construct.id) { if (animText && animText.event[1].construct === construct.id) {
const itemSourceDescription = () => { const itemSourceDescription = () => {
const itemSource = itemInfo.combos.filter(c => c.item === removeTier(animText.cast.skill)); const itemSource = itemInfo.combos.filter(c => c.item === removeTier(animText.skill));
const itemSourceInfo = itemSource.length const itemSourceInfo = itemSource.length
? `${itemSource[0].components[0]} ${itemSource[0].components[1]} ${itemSource[0].components[2]}` ? `${itemSource[0].components[0]} ${itemSource[0].components[1]} ${itemSource[0].components[2]}`
: false; : false;
@ -82,7 +82,7 @@ class AnimText extends preact.Component {
return ( return (
<div class="combat-text"> <div class="combat-text">
<h2><span>{animText.cast.skill}</span></h2> <h2><span>{animText.skill}</span></h2>
<span>{itemSourceDescription()}</span> <span>{itemSourceDescription()}</span>
{generateAnimText()} {generateAnimText()}
</div> </div>

View File

@ -535,17 +535,17 @@ impl Game {
for action in cast.actions() { for action in cast.actions() {
let events = match action { let events = match action {
Action::Cast { construct } => self.cast(cast), Action::Cast { construct } => self.cast(construct, cast),
Action::Hit { construct } => self.hit(cast), Action::Hit { construct } => self.hit(construct, cast),
Action::Damage { construct, values, colour } => { Action::Damage { construct, values, colour } => {
let amount = self.calculate_amount(&values, &resolved); let amount = self.calculate_amount(&values, &resolved);
self.damage(cast, construct, amount, colour) self.damage(construct, amount, colour)
}, },
Action::Heal { construct, values, colour } => { Action::Heal { construct, values, colour } => {
let amount = self.calculate_amount(&values, &resolved); let amount = self.calculate_amount(&values, &resolved);
self.heal(cast, construct, amount, colour) self.heal(construct, amount, colour)
}, },
Action::Effect { construct, effect } => self.effect(construct, effect), Action::Effect { construct, effect } => self.effect(construct, effect),
@ -628,21 +628,21 @@ impl Game {
// } // }
} }
fn cast(&mut self, cast: Cast) -> Vec<Event> { fn cast(&mut self, construct: Uuid, cast: Cast) -> Vec<Event> {
vec![Event::Cast { construct: cast.source, player: cast.player, direction: self.direction(cast) }] vec![Event::Cast { construct, player: cast.player, direction: self.direction(cast) }]
} }
fn hit(&mut self, cast: Cast) -> Vec<Event> { fn hit(&mut self, construct: Uuid, cast: Cast) -> Vec<Event> {
vec![Event::Hit { construct: cast.target, player: cast.player, direction: self.direction(cast) }] vec![Event::Hit { construct, player: cast.player, direction: self.direction(cast) }]
} }
fn damage(&mut self, cast: Cast, construct: Uuid, amount: usize, colour: Colour) -> Vec<Event> { fn damage(&mut self, construct: Uuid, amount: usize, colour: Colour) -> Vec<Event> {
match colour { match colour {
_ => self.construct_by_id(construct).unwrap().deal_red_damage(amount) // fixme unwrap _ => self.construct_by_id(construct).unwrap().deal_red_damage(amount) // fixme unwrap
} }
} }
fn heal(&mut self, cast: Cast, construct: Uuid, value: usize, colour: Colour) -> Vec<Event> { fn heal(&mut self, construct: Uuid, value: usize, colour: Colour) -> Vec<Event> {
match colour { match colour {
_ => self.construct_by_id(construct).unwrap().deal_red_damage(value) // fixme unwrap _ => self.construct_by_id(construct).unwrap().deal_red_damage(value) // fixme unwrap
} }
@ -870,7 +870,7 @@ pub enum Action {
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)] #[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
pub struct Resolution { pub struct Resolution {
pub cast: Cast, pub skill: Skill,
pub focus: Vec<Uuid>, pub focus: Vec<Uuid>,
pub event: Event, pub event: Event,
pub delay: i64, pub delay: i64,
@ -888,7 +888,7 @@ impl Resolution {
let delay = event.delay(); let delay = event.delay();
Resolution { Resolution {
cast, skill: cast.skill,
delay, delay,
focus, focus,
event, event,

View File

@ -599,7 +599,8 @@ impl Cast {
}, },
], ],
_ => unimplemented!() // _ => unimplemented!(),
_ => vec![], // for client testing
}; };
actions.append(&mut rest); actions.append(&mut rest);