nearly there

This commit is contained in:
ntr 2019-07-19 16:19:44 +10:00
parent 47b9d496dc
commit 18ac220006

View File

@ -23,6 +23,7 @@ class ConstructAvatar extends Component {
// When a new construct animation is communicated with state it will have a corresponding Id // When a new construct animation is communicated with state it will have a corresponding Id
// which is a count of how many resoluttions have passed // which is a count of how many resoluttions have passed
this.animations = []; this.animations = [];
this.resetAnimations = this.resetAnimations.bind(this);
} }
render() { render() {
@ -36,52 +37,62 @@ class ConstructAvatar extends Component {
} }
componentDidMount() { componentDidMount() {
const { animSource, animTarget, construct } = this.props; console.log(this.props.construct.name, 'mounted');
this.idle = idleAnimation(this.props.construct.id);
this.animations.push(this.idle);
}
const isSource = animSource && animSource.constructId === construct.id; componentDidUpdate(newProps) {
const isTarget = animTarget && animTarget.constructId === construct.id; const { animSource, animTarget, construct } = newProps;
console.log(isSource, isTarget); // back to idle
if (!animTarget || !animSource) {
if (!isSource || !isTarget) { return this.idle.play();
return this.animations.push(idleAnimation(construct.id));
} }
const avatarAnim = () => { const isSource = animSource && animSource.constructId === construct.id;
console.log(isSource);
const selectAnim = () => {
if (isSource) { if (isSource) {
console.log(construct.name, 'source anim');
return sourceCast(animSource.constructId, animSource.direction); return sourceCast(animSource.constructId, animSource.direction);
} }
// if (!animTarget) return false; switch (animTarget.skill) {
// match(animTarget.skill, [ case 'banish': return banish(construct.id);
// ['banish', () => banish(construct.id)], case 'invert': return invert(construct.id);
// ['invert', () => invert(this.props.construct.id)], default: return null;
// ]); }
}; };
const anim = avatarAnim(); const anim = selectAnim();
if (anim) { if (anim) {
console.log(anim); this.idle.pause();
this.animations.push(anim); this.animations.push(anim);
anim.finished.then(() => { return true;
console.log('anim finished');
return this.animations.push(idleAnimation(construct.id));
});
} }
return true; return false;
} }
componentWillUnmount() { resetAnimations() {
for (let i = this.animations.length - 1; i >= 0; i--) { for (let i = this.animations.length - 1; i >= 0; i--) {
this.animations[i].reset(); this.animations[i].reset();
} }
} }
// never update, wait til it gets nuked by parent componentWillUnmount() {
shouldComponentUpdate({ animTarget, sourceTarget }) { this.resetAnimations();
return (animTarget === this.props.animTarget) && (sourceTarget === this.props.sourceTarget); }
shouldComponentUpdate({ animTarget, animSource, construct }) {
const updated = (animTarget !== this.props.animTarget) || (animSource !== this.props.animSource);
if (!updated) return false;
const isSource = animSource && animSource.constructId === construct.id;
const isTarget = animTarget && animTarget.constructId === construct.id;
return isSource || isTarget;
} }
} }