89 lines
2.6 KiB
JavaScript
89 lines
2.6 KiB
JavaScript
const preact = require('preact');
|
|
const { Component } = require('preact');
|
|
const anime = require('animejs').default;
|
|
const { connect } = require('preact-redux');
|
|
|
|
const { TIMES, COLOURS } = require('../../constants');
|
|
const { randomPoints } = require('../../utils');
|
|
|
|
const addState = connect(
|
|
function receiveState(state) {
|
|
const { animCb } = state;
|
|
return { animCb };
|
|
}
|
|
);
|
|
|
|
function projectile(x, y, radius, colour) {
|
|
return (
|
|
<circle
|
|
cx={x}
|
|
cy={y}
|
|
r={radius}
|
|
fill={colour}
|
|
stroke="none"
|
|
/>
|
|
);
|
|
}
|
|
|
|
class Heal extends Component {
|
|
constructor(props) {
|
|
super();
|
|
this.team = props.team;
|
|
this.animations = [];
|
|
const points = randomPoints(30, 10, { x: 0, y: 0, width: 300, height: 400 });
|
|
this.charges = points.map(coord => projectile(coord[0], coord[1], 12, COLOURS.GREEN));
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<svg
|
|
class='skill-animation'
|
|
id='heal'
|
|
version="1.1"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
viewBox="0 0 300 400">
|
|
<defs>
|
|
<filter id="healFilter">
|
|
<feGaussianBlur stdDeviation="3"/>
|
|
<feColorMatrix mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 19 -9" result="cutoff"/>
|
|
<feComposite operator="atop" in="SourceGraphic" in2="cutoff"/>
|
|
</filter>
|
|
</defs>
|
|
<g filter="url(#healFilter)">
|
|
{this.charges}
|
|
</g>
|
|
</svg>
|
|
);
|
|
}
|
|
|
|
componentDidMount() {
|
|
this.animations.push(anime({
|
|
targets: ['#heal'],
|
|
opacity: [
|
|
{ value: 1, delay: TIMES.TARGET_DELAY_MS, duration: TIMES.TARGET_DURATION_MS * 0.2 },
|
|
{ value: 0, delay: TIMES.TARGET_DURATION_MS / 4, duration: TIMES.TARGET_DURATION_MS * 0.2 },
|
|
],
|
|
easing: 'easeInOutSine',
|
|
}));
|
|
|
|
this.animations.push(anime({
|
|
targets: ['#heal circle'],
|
|
cx: 150,
|
|
cy: 200,
|
|
delay: TIMES.TARGET_DELAY_MS * 4,
|
|
duration: TIMES.TARGET_DURATION_MS * 0.9,
|
|
easing: 'easeOutCirc',
|
|
direction: 'reverse',
|
|
}));
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
for (let i = this.animations.length - 1; i >= 0; i--) {
|
|
this.animations[i].reset();
|
|
}
|
|
this.props.animCb && this.props.animCb();
|
|
}
|
|
}
|
|
|
|
module.exports = addState(Heal);
|