anim fixes

This commit is contained in:
Mashy 2019-07-02 16:46:02 +10:00
parent 870940957f
commit 7ed13aa9db
9 changed files with 178 additions and 71 deletions

View File

@ -5,7 +5,7 @@ const AttackCharge = require('./anims/attack.charge');
const Amplify = require('./anims/amplify');
const Blast = require('./anims/blast');
const banish = require('./anims/banish');
const Banish = require('./anims/banish');
const Bash = require('./anims/bash');
const Block = require('./anims/block');
const Buff = require('./anims/buff');
@ -20,14 +20,14 @@ const Hex = require('./anims/hex');
const Strike = require('./anims/strike');
const Parry = require('./anims/parry');
const Chaos = require('./anims/chaos');
const invert = require('./anims/invert');
const Invert = require('./anims/invert');
const Slay = require('./anims/slay');
const Siphon = require('./anims/siphon');
const SiphonTick = require('./anims/siphon.tick');
// const Test = require('./anims/test');
const { removeTier, getCombatText } = require('../utils');
const { removeTier } = require('../utils');
const colours = {
red: '#a52a2a',
@ -98,7 +98,7 @@ function animations(props) {
switch (skill) {
case 'Attack': return <Strike id={construct.id} team={player} colour={colours.white}/>;
case 'Amplify': return <Amplify/>;
case 'Banish': return banish(construct.id);
case 'Banish': return <Banish id={construct.id} />;
case 'Bash': return <Bash />;
case 'Block': return <Block />;
case 'Buff': return <Buff />;
@ -114,7 +114,7 @@ function animations(props) {
case 'Hex': return <Hex />;
case 'Haste': return <Haste />;
case 'Parry': return <Parry team={player} />;
case 'Invert': return invert(construct.id);
case 'Invert': return <Invert id={construct.id} />
case 'Siphon': return <Siphon id={construct.id} team={player} />;
case 'SiphonTick': return <SiphonTick id={construct.id} team={player} />;
case 'Stun': return <Stun />;

View File

@ -35,8 +35,8 @@ class Amplify extends Component {
this.animations.push(anime({
targets: ['#amplify'],
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 },
{ value: 1, delay: TIMES.TARGET_DELAY_MS, duration: TIMES.TARGET_DURATION_MS * 0.2 },
{ value: 0, delay: TIMES.TARGET_DURATION_MS * 0.6, duration: TIMES.TARGET_DURATION_MS * 0.2 },
],
easing: 'easeInOutSine',
}));
@ -47,8 +47,8 @@ class Amplify extends Component {
stroke: ['#3498db', '#a52a2a'],
easing: 'easeInOutSine',
delay: TIMES.TARGET_DELAY_MS,
duration: TIMES.TARGET_DURATION_MS,
delay: TIMES.TARGET_FADE_IN_DELAY,
}));
this.animations.push(anime({
@ -57,8 +57,8 @@ class Amplify extends Component {
scale: 4,
easing: 'easeInOutExpo',
delay: TIMES.TARGET_DELAY_MS,
duration: TIMES.TARGET_DURATION_MS,
delay: TIMES.TARGET_FADE_IN_DELAY,
}));
}

View File

@ -1,19 +1,45 @@
const preact = require('preact');
const { Component } = require('preact');
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)],
scaleY: 0,
fill: '#fff',
class Banish extends Component {
constructor(props) {
super();
this.id = props.id;
this.animations = [];
}
easing: 'easeOutElastic',
delay: TIMES.TARGET_DELAY_MS,
duration: TIMES.TARGET_DURATION_MS + TIMES.POST_SKILL_DURATION_MS,
});
render() {
// Need this so unmount triggers
return <svg id='invert'></svg>;
}
componentDidMount() {
this.animations.push(anime({
targets: [document.getElementById(this.id)],
scaleY: 0,
fill: '#fff',
easing: 'easeOutElastic',
delay: TIMES.TARGET_DELAY_MS,
duration: TIMES.TARGET_DURATION_MS * 0.5,
direction: 'alternate',
}));
}
// 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 = banish;
module.exports = Banish;

View File

@ -39,8 +39,8 @@ class Bash extends Component {
this.animations.push(anime({
targets: ['#bash'],
opacity: [
{ value: 1, delay: TIMES.TARGET_FADE_IN_DELAY, duration: TIMES.TARGET_FADE_IN_DURATION },
{ value: 0, delay: TIMES.TARGET_MAIN_DURATION - 500, duration: TIMES.FADE_OUT_DURATION },
{ value: 1, delay: TIMES.TARGET_DELAY_MS, duration: TIMES.TARGET_DURATION_MS * 0.2 },
{ value: 0, delay: TIMES.TARGET_DURATION_MS * 0.6, duration: TIMES.TARGET_DURATION_MS * 0.2 },
],
easing: 'easeInOutSine',
}));

View File

@ -27,10 +27,9 @@ class AttackCharge extends Component {
constructor(props) {
super();
this.team = props.team;
// this.colour = props.colour;
this.colour = '#00aabb';
this.animations = [];
const points = randomPoints(8, 60, { x: 0, y: 0, width: 300, height: 400 });
this.charges = points.map(coord => projectile(coord[0], coord[1], 20, this.colour));
this.charges = points.map(coord => projectile(coord[0], coord[1], 20, '#00aabb'));
}
render() {
@ -45,7 +44,7 @@ class AttackCharge extends Component {
<defs>
<radialGradient id="grad1" cx="50%" cy="50%" r="70%" fx="50%" fy="50%">
<stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:0.6" />
<stop offset="100%" style={`stop-color:${this.colour};stop-opacity:1`} />
<stop offset="100%" style={'stop-color:#00aabb;stop-opacity:1'} />
</radialGradient>
</defs>
<filter id="explosion">
@ -71,8 +70,17 @@ class AttackCharge extends Component {
}
anime.set('.skill-anim', {
translateY: -200,
opacity: 0,
});
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 },
],
}));
anime.set('#explosion feDisplacementMap', {
scale: 1,
});
@ -81,6 +89,7 @@ class AttackCharge extends Component {
targets: '.skill-anim',
translateY: 0,
loop: false,
delay: TIMES.TARGET_DELAY_MS,
duration: (duration * 1 / 2),
easing: 'easeInQuad',
});
@ -88,10 +97,17 @@ class AttackCharge extends Component {
targets: '#explosion feDisplacementMap',
scale: 100,
loop: false,
delay: TIMES.TARGET_DELAY_MS,
duration,
easing: 'easeInQuad',
});
}
componentWillUnmount() {
for (let i = this.animations.length - 1; i >= 0; i--) {
this.animations[i].reset();
}
}
}
module.exports = AttackCharge;

View File

@ -25,11 +25,9 @@ function projectile(x, y, radius, colour) {
class AttackCharge extends Component {
constructor(props) {
super();
this.team = props.team;
// this.colour = props.colour;
this.colour = '#A25AC1';
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, this.colour));
this.charges = points.map(coord => projectile(coord[0], coord[1], 14, '#A25AC1'));
}
render() {
@ -44,7 +42,7 @@ class AttackCharge extends Component {
<defs>
<radialGradient id="grad1" cx="50%" cy="0%" r="85%" fx="50%" fy="50%">
<stop offset="0%" style="stop-color:#dba9a9;stop-opacity:0.6" />
<stop offset="100%" style={`stop-color:${this.colour};stop-opacity:1`} />
<stop offset="100%" style={`stop-color:#A25AC1;stop-opacity:1`} />
</radialGradient>
</defs>
<filter id="explosion">
@ -79,36 +77,55 @@ class AttackCharge extends Component {
anime.set('.skill-anim', {
translateY: -200,
translateX: 0,
opacity: 0,
});
anime.set('#explosion feDisplacementMap', {
scale: 1,
});
anime({
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: (duration * 1 / 2),
easing: 'easeInQuad',
});
anime({
}));
this.animations.push(anime({
targets: '#explosion feDisplacementMap',
scale: 75,
loop: false,
delay: (duration * 2 / 3),
delay: (TIMES.TARGET_DELAY_MS + duration * 2 / 3),
duration: (duration * 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: (duration * 2 / 3),
easing: 'easeInQuad',
}));
}
componentWillUnmount() {
for (let i = this.animations.length - 1; i >= 0; i--) {
this.animations[i].reset();
}
}
}
module.exports = AttackCharge;

View File

@ -27,10 +27,9 @@ class Heal extends Component {
constructor(props) {
super();
this.team = props.team;
// this.colour = props.colour;
this.colour = '#1FF01F';
this.animations = [];
const points = randomPoints(15, 30, { x: 0, y: 0, width: 300, height: 400 });
this.charges = points.map(coord => projectile(coord[0], coord[1], 14, this.colour));
this.charges = points.map(coord => projectile(coord[0], coord[1], 14, '#1FF01F'));
}
render() {
@ -44,7 +43,7 @@ class Heal extends Component {
<defs>
<radialGradient id="grad1" cx="50%" cy="0%" r="85%" fx="50%" fy="50%">
<stop offset="0%" style="stop-color:#dba9a9;stop-opacity:0.6" />
<stop offset="100%" style={`stop-color:${this.colour};stop-opacity:1`} />
<stop offset="100%" style={'stop-color:#1FF01F;stop-opacity:1'} />
</radialGradient>
</defs>
<filter id="explosion">
@ -59,46 +58,46 @@ class Heal extends Component {
}
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: -200,
// translateX: 0,
// });
anime.set('#explosion feDisplacementMap', {
scale: 100,
});
anime.set('.skill-anim', {
opacity: 0,
});
anime({
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.6, duration: TIMES.TARGET_DURATION_MS * 0.2 },
],
}));
this.animations.push(anime({
targets: '.skill-anim',
translateY: 0,
translateX: 0,
loop: false,
delay: TIMES.TARGET_DELAY_MS,
duration: (duration * 1 / 2),
easing: 'easeInQuad',
});
anime({
}));
this.animations.push(anime({
targets: '#explosion feDisplacementMap',
scale: 1,
loop: false,
delay: TIMES.TARGET_DELAY_MS,
duration: (duration * 1 / 2),
easing: 'easeInQuad',
});
anime({
}));
this.animations.push(anime({
targets: '#projectile',
cx: 150,
cy: 200,
delay: (duration * 1 / 2),
delay: (TIMES.TARGET_DELAY_MS + duration * 1 / 2),
duration: (duration * 1 / 2),
easing: 'easeInQuad',
});
}));
}
}

View File

@ -1,19 +1,45 @@
const preact = require('preact');
const { Component } = require('preact');
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)],
rotate: [
{ value: 180, delay: TIMES.TARGET_DELAY_MS, duration: TIMES.TARGET_DURATION_MS * 0.6 },
{ value: 0, duration: TIMES.POST_SKILL_DURATION_MS * 0.4 },
],
easing: 'easeInOutElastic',
direction: 'alternate',
});
class Invert extends Component {
constructor(props) {
super();
this.id = props.id;
this.animations = [];
}
render() {
// Need this so unmount triggers
return <svg id='invert'></svg>;
}
componentDidMount() {
console.log('mounting');
this.animations.push(anime({
targets: [document.getElementById(this.id)],
rotate: 180,
delay: TIMES.TARGET_DELAY_MS,
duration: TIMES.TARGET_DURATION_MS * 0.45,
easing: 'easeInOutElastic',
direction: 'alternate',
}));
}
// 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 = invert;
module.exports = Invert;

View File

@ -7,6 +7,11 @@ const { TIMES } = require('../../constants');
const duration = TIMES.TARGET_DURATION_MS;
class AttackCharge extends Component {
constructor() {
super();
this.animations = [];
}
render() {
return (
<svg
@ -14,7 +19,8 @@ class AttackCharge extends Component {
version="1.1"
id="Layer_1"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 300 400">
viewBox="0 0 300 400"
opacity="0">
<filter id="blur">
<feGaussianBlur in="SourceGraphic" stdDeviation="2" />
</filter>
@ -28,6 +34,15 @@ class AttackCharge extends Component {
r: '140',
stroke: '#3498db',
});
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 },
],
}));
anime({
targets: '#siphon',
keyframes: [
@ -36,10 +51,18 @@ class AttackCharge extends Component {
{ r: '50', stroke: '#3498db' },
{ r: '20', stroke: '#3498db' },
],
delay: TIMES.TARGET_DELAY_MS,
duration,
easing: 'easeInCubic',
});
}
componentWillUnmount() {
for (let i = this.animations.length - 1; i >= 0; i--) {
this.animations[i].reset();
}
}
}
module.exports = AttackCharge;