reimplement animations
This commit is contained in:
@@ -4,9 +4,7 @@ const toast = require('izitoast');
|
||||
const eachSeries = require('async/eachSeries');
|
||||
|
||||
const actions = require('./actions');
|
||||
const { TIMES } = require('./constants');
|
||||
const animations = require('./animations.utils');
|
||||
const { removeTier } = require('./utils');
|
||||
const { setAnimations, clearAnimations } = require('./animations.utils');
|
||||
|
||||
const SOCKET_URL = process.env.NODE_ENV === 'production' ? 'wss://mnml.gg/api/ws' : 'ws://localhost/api/ws';
|
||||
|
||||
@@ -20,73 +18,32 @@ function createSocket(store) {
|
||||
ws.send(cbor.encode(msg));
|
||||
}
|
||||
|
||||
function sendDevResolve(a, b, skill) {
|
||||
send(['DevResolve', { a, b, skill }]);
|
||||
function sendDevResolve(skill) {
|
||||
send(['DevResolve', { skill }]);
|
||||
}
|
||||
|
||||
function onDevResolutions(newRes) {
|
||||
const { game, account, animating } = store.getState();
|
||||
|
||||
if (animating) return false;
|
||||
function setGame(game) {
|
||||
store.dispatch(actions.setGame(game));
|
||||
store.dispatch(actions.setAnimating(true));
|
||||
store.dispatch(actions.setGameSkillInfo(null));
|
||||
// stop fetching the game state til animations are done
|
||||
|
||||
const newRes = game.resolutions[game.resolutions.length - 1];
|
||||
return eachSeries(newRes, (r, cb) => {
|
||||
if (!r.event) return cb();
|
||||
const timeout = animations.getTime(r.stages);
|
||||
const anims = animations.getObjects(r, game, account);
|
||||
const text = animations.getText(r);
|
||||
store.dispatch(actions.setAnimFocus(animations.getFocusTargets(r, game)));
|
||||
if (anims.animSkill) store.dispatch(actions.setAnimSkill(anims.animSkill));
|
||||
|
||||
if (r.stages.includes('START_SKILL') && anims.animSource) {
|
||||
store.dispatch(actions.setAnimSource(anims.animSource));
|
||||
}
|
||||
|
||||
if (r.stages.includes('END_SKILL') && anims.animTarget) {
|
||||
store.dispatch(actions.setAnimTarget(anims.animTarget));
|
||||
if (animations.isCbAnim(anims.animSkill)) store.dispatch(actions.setAnimCb(cb));
|
||||
}
|
||||
|
||||
if (r.stages.includes('POST_SKILL') && text) {
|
||||
// timeout to prevent text classes from being added too soon
|
||||
if (timeout === TIMES.POST_SKILL_DURATION_MS) {
|
||||
store.dispatch(actions.setResolution(text));
|
||||
} else {
|
||||
setTimeout(
|
||||
() => store.dispatch(actions.setResolution(text)),
|
||||
timeout - TIMES.POST_SKILL_DURATION_MS
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return setTimeout(() => {
|
||||
store.dispatch(actions.setAnimSkill(null));
|
||||
store.dispatch(actions.setAnimSource(null));
|
||||
store.dispatch(actions.setAnimTarget(null));
|
||||
store.dispatch(actions.setResolution(null));
|
||||
store.dispatch(actions.setAnimFocus([]));
|
||||
if (r.stages.includes('END_SKILL') && animations.isCbAnim(anims.animSkill)) return true;
|
||||
return cb();
|
||||
}, timeout);
|
||||
// if (r.delay === 0) return cb(); // TargetKo etc
|
||||
setAnimations(r, store);
|
||||
return setTimeout(cb, r.delay);
|
||||
}, 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.setResolution(null));
|
||||
store.dispatch(actions.setAnimating(false));
|
||||
store.dispatch(actions.setGameEffectInfo(null));
|
||||
|
||||
clearAnimations(store);
|
||||
// set the game state so resolutions don't fire twice
|
||||
store.dispatch(actions.setGame(game));
|
||||
// ws.sendGameState(game.id);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
const handlers = {
|
||||
DevResolutions: onDevResolutions,
|
||||
GameState: setGame,
|
||||
};
|
||||
|
||||
// decodes the cbor and
|
||||
|
||||
@@ -5,18 +5,7 @@ const { createStore, combineReducers } = require('redux');
|
||||
const reducers = require('./reducers');
|
||||
const actions = require('./actions');
|
||||
const createSocket = require('./animations.socket');
|
||||
|
||||
// const TrippyTriangle = require('./components/svgs/trippy.triangle');
|
||||
// const Amplify = require('./components/svgs/amplify');
|
||||
// const Hex = require('./components/svgs/hex');
|
||||
const Game = require('./components/game');
|
||||
const testGameBuilder = require('./test.game');
|
||||
|
||||
const testGame = testGameBuilder('8552e0bf-340d-4fc8-b6fc-cccccccccccc');
|
||||
const testAccount = {
|
||||
id: '8552e0bf-340d-4fc8-b6fc-cccccccccccc',
|
||||
name: 'ntr',
|
||||
};
|
||||
|
||||
// Redux Store
|
||||
const store = createStore(
|
||||
@@ -24,20 +13,15 @@ const store = createStore(
|
||||
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(),
|
||||
);
|
||||
|
||||
const testAccount = {
|
||||
id: '8552e0bf-340d-4fc8-b6fc-cccccccccccc',
|
||||
name: 'ntr',
|
||||
};
|
||||
store.dispatch(actions.setAccount(testAccount));
|
||||
store.dispatch(actions.setGame(testGame));
|
||||
|
||||
function animationsNav(ws) {
|
||||
function useSkill(skill) {
|
||||
const ateam = Math.round(Math.random());
|
||||
const bteam = Math.round(Math.random());
|
||||
const acon = Math.floor(Math.random() * 3);
|
||||
const bcon = Math.floor(Math.random() * 3);
|
||||
|
||||
const a = testGame.players[ateam].constructs[acon].id;
|
||||
const b = testGame.players[bteam].constructs[bcon].id;
|
||||
|
||||
return ws.sendDevResolve(a, b, skill);
|
||||
return ws.sendDevResolve(skill);
|
||||
}
|
||||
|
||||
return SKILLS.map((s, i) => (
|
||||
@@ -81,19 +65,19 @@ const SKILLS = [
|
||||
'Buff',
|
||||
'Chaos',
|
||||
'Counter',
|
||||
'CounterAttack',
|
||||
// 'CounterAttack',
|
||||
'Curse',
|
||||
'Debuff',
|
||||
'Decay',
|
||||
'DecayTick',
|
||||
'Electrify',
|
||||
'Electrocute',
|
||||
'ElectrocuteTick',
|
||||
// 'ElectrocuteTick',
|
||||
'Haste',
|
||||
'HasteStrike',
|
||||
// 'HasteStrike',
|
||||
'Heal',
|
||||
'Hybrid',
|
||||
'HybridBlast',
|
||||
// 'HybridBlast',
|
||||
'Intercept',
|
||||
'Invert',
|
||||
'Link',
|
||||
@@ -105,12 +89,12 @@ const SKILLS = [
|
||||
'Ruin',
|
||||
'Silence',
|
||||
'Siphon',
|
||||
'SiphonTick',
|
||||
// 'SiphonTick',
|
||||
'Slay',
|
||||
'Sleep',
|
||||
'Strike',
|
||||
'Stun',
|
||||
'Sustain',
|
||||
'Triage',
|
||||
'TriageTick',
|
||||
// 'TriageTick',
|
||||
];
|
||||
|
||||
@@ -75,7 +75,6 @@ class ConstructAnimation extends Component {
|
||||
const animSkill = removeTier(skill);
|
||||
if (!constructId.includes(construct.id)) return false;
|
||||
|
||||
|
||||
// find target animation
|
||||
const chooseAnim = () => {
|
||||
switch (animSkill) {
|
||||
|
||||
@@ -87,7 +87,6 @@ function registerEvents(store) {
|
||||
store.dispatch(actions.setGameSkillInfo(null));
|
||||
// stop fetching the game state til animations are done
|
||||
const newRes = game.resolutions[game.resolutions.length - 1];
|
||||
console.log(newRes);
|
||||
return eachSeries(newRes, (r, cb) => {
|
||||
if (r.delay === 0) return cb(); // TargetKo etc
|
||||
setAnimations(r, store);
|
||||
|
||||
Reference in New Issue
Block a user