const preact = require('preact'); const { Component } = require('preact'); const anime = require('animejs').default; const { connect } = require('preact-redux'); const { TIMES } = require('../../constants'); const { randomPoints } = require('../../utils'); const addState = connect( function receiveState(state) { const { animCb } = state; return { animCb }; } ); function projectile(x, y, radius, colour) { return ( ); } class Chaos extends Component { constructor() { super(); this.animations = []; const points = randomPoints(7, 30, { x: 0, y: 0, width: 300, height: 100 }); this.charges = points.map(coord => projectile(coord[0], coord[1], 14, '#A25AC1')); } render() { return ( // {this.charges} {this.charges} ); } componentDidMount() { const projectiles = document.querySelectorAll('.skill-anim circle'); projectiles.forEach(proj => { const colour = Math.random() >= 0.5 ? '#a52a2a' : '#3050f8'; anime.set(proj, { stroke: colour, }); }); anime.set('.skill-anim', { translateY: -(window.screen.height) * 0.35 * this.props.direction.y, translateX: -(window.screen.width) * 0.15 * this.props.direction.x, opacity: 0, }); anime.set('#explosion feDisplacementMap', { scale: 1, }); 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, duration: TIMES.POST_SKILL_DURATION_MS }, ], })); this.animations.push(anime({ targets: '.skill-anim', translateY: 0, translateX: 0, loop: false, delay: TIMES.TARGET_DELAY_MS, duration: (TIMES.TARGET_DURATION_MS * 1 / 2), easing: 'easeInQuad', })); this.animations.push(anime({ targets: '#explosion feDisplacementMap', scale: 75, loop: false, delay: (TIMES.TARGET_DELAY_MS + TIMES.TARGET_DURATION_MS * 2 / 3), duration: (TIMES.TARGET_DURATION_MS * 1 / 3), easing: 'easeInQuad', })); projectiles.forEach(proj => anime({ targets: proj, cx: Math.random() * 250 + 25, cy: Math.random() * 300 + 50, delay: TIMES.TARGET_DELAY_MS, duration: (TIMES.TARGET_DURATION_MS * 2 / 3), easing: 'easeInQuad', })); } componentWillUnmount() { for (let i = this.animations.length - 1; i >= 0; i--) { this.animations[i].reset(); } this.props.animCb && this.props.animCb(); } } module.exports = addState(Chaos);