From c6b39fef8f18420b55bd0698aedd2fd66061733f Mon Sep 17 00:00:00 2001 From: ntr Date: Tue, 2 Jul 2019 15:25:47 +1000 Subject: [PATCH] recharge --- client/src/components/animations.jsx | 2 + client/src/components/anims/banish.jsx | 3 - client/src/components/anims/electrify.jsx | 3 - client/src/components/anims/electrocute.jsx | 3 - client/src/components/anims/invert.jsx | 3 - client/src/components/anims/recharge.jsx | 93 +++++++++++++++++++++ 6 files changed, 95 insertions(+), 12 deletions(-) create mode 100644 client/src/components/anims/recharge.jsx diff --git a/client/src/components/animations.jsx b/client/src/components/animations.jsx index 4bbb2bb4..e4612aa6 100644 --- a/client/src/components/animations.jsx +++ b/client/src/components/animations.jsx @@ -19,6 +19,7 @@ const Heal = require('./anims/heal'); const Hex = require('./anims/hex'); const Strike = require('./anims/strike'); const Parry = require('./anims/parry'); +const Recharge = require('./anims/recharge'); const Chaos = require('./anims/chaos'); const invert = require('./anims/invert'); const Slay = require('./anims/slay'); @@ -114,6 +115,7 @@ function animations(props) { case 'Hex': return ; case 'Haste': return ; case 'Parry': return ; + case 'Recharge': return ; case 'Invert': return invert(construct.id); case 'Siphon': return ; case 'SiphonTick': return ; diff --git a/client/src/components/anims/banish.jsx b/client/src/components/anims/banish.jsx index 3e6a8f08..4ccd76fa 100644 --- a/client/src/components/anims/banish.jsx +++ b/client/src/components/anims/banish.jsx @@ -1,9 +1,6 @@ const anime = require('animejs').default; const { TIMES } = require('../../constants'); -// shamelessly lifted from teh anime docs -// https://animejs.com/documentation/#svgAttr - function banish(id) { anime({ targets: [document.getElementById(id)], diff --git a/client/src/components/anims/electrify.jsx b/client/src/components/anims/electrify.jsx index 37ac198d..05e8a4f3 100644 --- a/client/src/components/anims/electrify.jsx +++ b/client/src/components/anims/electrify.jsx @@ -6,9 +6,6 @@ const anime = require('animejs').default; const { TIMES } = require('../../constants'); -// shamelessly lifted from teh anime docs -// https://animejs.com/documentation/#svgAttr - class Electrify extends Component { constructor() { super(); diff --git a/client/src/components/anims/electrocute.jsx b/client/src/components/anims/electrocute.jsx index 4bf24bd8..d28198d7 100644 --- a/client/src/components/anims/electrocute.jsx +++ b/client/src/components/anims/electrocute.jsx @@ -6,9 +6,6 @@ const anime = require('animejs').default; const { TIMES } = require('../../constants'); -// shamelessly lifted from teh anime docs -// https://animejs.com/documentation/#svgAttr - class Electrify extends Component { constructor() { super(); diff --git a/client/src/components/anims/invert.jsx b/client/src/components/anims/invert.jsx index 3827ff2d..d1736fc4 100644 --- a/client/src/components/anims/invert.jsx +++ b/client/src/components/anims/invert.jsx @@ -1,9 +1,6 @@ const anime = require('animejs').default; const { TIMES } = require('../../constants'); -// shamelessly lifted from teh anime docs -// https://animejs.com/documentation/#svgAttr - function invert(id) { anime({ targets: [document.getElementById(id)], diff --git a/client/src/components/anims/recharge.jsx b/client/src/components/anims/recharge.jsx new file mode 100644 index 00000000..22d77ab4 --- /dev/null +++ b/client/src/components/anims/recharge.jsx @@ -0,0 +1,93 @@ +const preact = require('preact'); +const { Component } = require('preact'); +const anime = require('animejs').default; + +const { TIMES } = require('../../constants'); + +class Recharge extends Component { + constructor() { + super(); + this.animations = []; + } + + render({ team }) { + return ( + + + + + + + + + + + + + + + + + ); + } + + componentDidMount() { + this.animations.push(anime({ + targets: ['#recharge'], + opacity: [ + { value: 1, delay: TIMES.TARGET_FADE_IN_DELAY, duration: TIMES.TARGET_FADE_IN_DURATION }, + { value: 0, delay: TIMES.TARGET_FADE_OUT_DELAY, duration: TIMES.FADE_OUT_DURATION }, + ], + easing: 'easeInOutSine', + })); + + this.animations.push(anime({ + targets: ['#recharge path.white'], + strokeWidth: [2, 1], + easing: 'easeInOutSine', + direction: 'alternate', + + delay: TIMES.TARGET_MAIN_DELAY, + duration: TIMES.TARGET_MAIN_DURATION, + })); + + this.animations.push(anime({ + targets: ['#rechargeFilter feTurbulence', ' #rechargeFilter feDisplacementMap'], + baseFrequency: 2, + scale: 10, + numOctaves: 5, + easing: 'easeOutSine', + + delay: TIMES.TARGET_FADE_IN_DELAY, + duration: TIMES.RESOLUTION_TOTAL_MS, + })); + } + + // this is necessary because + // skipping / timing / unmounting race conditions + // can cause the animations to cut short, this will ensure the values are reset + // because preact will recycle all these components + componentWillUnmount() { + for (let i = this.animations.length - 1; i >= 0; i--) { + this.animations[i].reset(); + } + } +} + +module.exports = Recharge;