clean up anim functions
This commit is contained in:
parent
b405608510
commit
22ac2b502e
@ -1,29 +1,58 @@
|
||||
function getAnimSource(resolution, account) {
|
||||
const { player } = resolution.cast;
|
||||
const { x, y, target } = resolution.variant[1];
|
||||
const animY = y && player === account.id ? -1 : y;
|
||||
const actions = require('./actions');
|
||||
const { TIMES } = require('./constants');
|
||||
|
||||
return {
|
||||
animation: 'sourceCast',
|
||||
constructId: target,
|
||||
direction: { x, y: animY },
|
||||
};
|
||||
function setAnimations(r, store, account) {
|
||||
store.dispatch(actions.setAnimFocus(r.focus));
|
||||
|
||||
if (r.variant[0] === 'Cast') {
|
||||
store.dispatch(actions.setAnimText(null));
|
||||
|
||||
const { player } = r.cast;
|
||||
const { x, y, target } = r.variant[1];
|
||||
const animY = y && player === account.id ? -1 : y;
|
||||
const animSource = {
|
||||
animation: 'sourceCast',
|
||||
constructId: target,
|
||||
direction: { x, y: animY },
|
||||
};
|
||||
store.dispatch(actions.setAnimSource(animSource));
|
||||
|
||||
return setTimeout(() => store.dispatch(actions.setAnimSource(null)), TIMES.SOURCE_DURATION_MS);
|
||||
}
|
||||
|
||||
if (r.variant[0].includes('Hit')) {
|
||||
store.dispatch(actions.setAnimText(null));
|
||||
|
||||
const { player, skill } = r.cast;
|
||||
const { x, y, target } = r.variant[1];
|
||||
const animY = y && player === account.id ? -1 : y;
|
||||
const isPlayer = player === account.id;
|
||||
const animTarget = {
|
||||
constructId: target,
|
||||
player: isPlayer,
|
||||
skill,
|
||||
direction: { x, y: animY },
|
||||
};
|
||||
store.dispatch(actions.setAnimTarget(animTarget));
|
||||
|
||||
return setTimeout(() => store.dispatch(actions.setAnimTarget(null)), TIMES.TARGET_DURATION_MS);
|
||||
}
|
||||
|
||||
return store.dispatch(actions.setAnimText(r));
|
||||
}
|
||||
|
||||
function getAnimTarget(resolution, account) {
|
||||
const { player, skill } = resolution.cast;
|
||||
const { x, y, target } = resolution.variant[1];
|
||||
const animY = y && player === account.id ? -1 : y;
|
||||
const isPlayer = player === account.id;
|
||||
return {
|
||||
constructId: target,
|
||||
player: isPlayer,
|
||||
skill,
|
||||
direction: { x, y: animY },
|
||||
};
|
||||
function clearAnimations(store) {
|
||||
store.dispatch(actions.setAnimSkill(null));
|
||||
store.dispatch(actions.setAnimSource(null));
|
||||
store.dispatch(actions.setAnimTarget(null));
|
||||
store.dispatch(actions.setAnimText(null));
|
||||
store.dispatch(actions.setAnimating(false));
|
||||
store.dispatch(actions.setGameEffectInfo(null));
|
||||
store.dispatch(actions.setAnimFocus(null));
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
getAnimSource,
|
||||
getAnimTarget,
|
||||
setAnimations,
|
||||
clearAnimations,
|
||||
};
|
||||
|
||||
@ -5,10 +5,9 @@ const eachSeries = require('async/eachSeries');
|
||||
const sample = require('lodash/sample');
|
||||
|
||||
const actions = require('./actions');
|
||||
const { getAnimSource, getAnimTarget } = require('./animations.utils');
|
||||
const { setAnimations, clearAnimations } = require('./animations.utils');
|
||||
const { infoToast, errorToast } = require('./utils');
|
||||
const { tutorialVbox } = require('./tutorial.utils');
|
||||
const { TIMES } = require('./constants');
|
||||
|
||||
function registerEvents(store) {
|
||||
function notify(msg) {
|
||||
@ -90,34 +89,11 @@ function registerEvents(store) {
|
||||
const newRes = game.events[currentGame.events.length];
|
||||
return eachSeries(newRes, (r, cb) => {
|
||||
const timeout = r.delay;
|
||||
store.dispatch(actions.setAnimFocus(r.focus));
|
||||
|
||||
if (r.variant[0] === 'Cast') {
|
||||
const animSource = getAnimSource(r, account);
|
||||
store.dispatch(actions.setAnimSource(animSource));
|
||||
store.dispatch(actions.setAnimText(null));
|
||||
|
||||
setTimeout(() => store.dispatch(actions.setAnimSource(null)), TIMES.SOURCE_DURATION_MS);
|
||||
} else if (r.variant[0].includes('Hit')) {
|
||||
const animTarget = getAnimTarget(r, account);
|
||||
store.dispatch(actions.setAnimTarget(animTarget));
|
||||
store.dispatch(actions.setAnimText(null));
|
||||
|
||||
setTimeout(() => store.dispatch(actions.setAnimTarget(null)), TIMES.TARGET_DURATION_MS);
|
||||
} else {
|
||||
store.dispatch(actions.setAnimText(r));
|
||||
}
|
||||
setAnimations(r, store, account);
|
||||
return setTimeout(cb, timeout);
|
||||
}, err => {
|
||||
if (err) return console.error(err);
|
||||
// clear animation state
|
||||
store.dispatch(actions.setAnimSkill(null));
|
||||
store.dispatch(actions.setAnimSource(null));
|
||||
store.dispatch(actions.setAnimTarget(null));
|
||||
store.dispatch(actions.setAnimText(null));
|
||||
store.dispatch(actions.setAnimating(false));
|
||||
store.dispatch(actions.setGameEffectInfo(null));
|
||||
store.dispatch(actions.setAnimFocus(null));
|
||||
clearAnimations(store);
|
||||
// set the game state so resolutions don't fire twice
|
||||
store.dispatch(actions.setGame(game));
|
||||
ws.sendGameState(game.id);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user