const preact = require('preact'); const { Component } = require('preact'); const anime = require('animejs').default; const { TIMES } = require('../../constants'); const { randomPoints } = require('../../utils'); const duration = TIMES.TARGET_DURATION_MS; function projectile(x, y, radius, colour) { return ( ); } function sword(colour) { return ( ); } class AttackCharge extends Component { constructor(props) { super(); this.animations = []; this.colour = '#a52a2a'; const points = new Array(30).fill(0); this.charges = points.map(() => projectile(150, 420, 7, '#1FF01F')); } render() { return ( {sword(this.colour)} {this.charges} ); } componentDidMount() { if (!this.props.team) { anime.set('.skill-anim', { rotate: Math.random() * 180 + 90, }); } else { anime.set('.skill-anim', { rotate: Math.random() * 180 + 270, }); } anime.set('.skill-anim', { translateY: -400, translateX: 0, opacity: 0, }); anime.set('#explosion feDisplacementMap', { scale: 100, }); anime.set('#sword', { fill: this.colour, stroke: this.colour, }); this.animations.push(anime({ targets: '.skill-anim', opacity: [ { value: 1, delay: TIMES.TARGET_DELAY_MS, duration: TIMES.TARGET_DURATION_MS * 0.3 }, { value: 0, delay: TIMES.TARGET_DURATION_MS * 0.7 + TIMES.POST_SKILL_DURATION_MS * 0.8, duration: TIMES.POST_SKILL_DURATION_MS * 0.2, }], translateY: 0, translateX: 0, loop: false, delay: TIMES.TARGET_DELAY_MS, duration: (duration * 1 / 2), easing: 'easeInQuad', })); this.animations.push(anime({ targets: '#explosion feDisplacementMap', scale: 10000, loop: false, delay: (TIMES.TARGET_DELAY_MS + duration * 1 / 2), duration: (duration * 1 / 2), easing: 'easeInQuad', })); this.animations.push(anime({ targets: '#sword', fill: '#1FF01F', stroke: '#1FF01F', delay: (TIMES.TARGET_DELAY_MS + duration + TIMES.POST_SKILL_DURATION_MS * 0.7), })); const projectiles = document.querySelectorAll('#projectile'); projectiles.forEach(proj => { this.animations.push(anime({ targets: proj, cx: Math.random() * 250 + 25, cy: Math.random() * 200 - 100, delay: (TIMES.TARGET_DELAY_MS + duration + TIMES.POST_SKILL_DURATION_MS * 0.7), duration: (TIMES.POST_SKILL_DURATION_MS * 0.3), easing: 'easeInQuad', })); }); } componentWillUnmount() { for (let i = this.animations.length - 1; i >= 0; i--) { this.animations[i].reset(); } } } module.exports = AttackCharge;