nearly there
This commit is contained in:
parent
47b9d496dc
commit
18ac220006
@ -23,6 +23,7 @@ class ConstructAvatar extends Component {
|
||||
// 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
|
||||
this.animations = [];
|
||||
this.resetAnimations = this.resetAnimations.bind(this);
|
||||
}
|
||||
|
||||
render() {
|
||||
@ -36,52 +37,62 @@ class ConstructAvatar extends Component {
|
||||
}
|
||||
|
||||
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;
|
||||
const isTarget = animTarget && animTarget.constructId === construct.id;
|
||||
componentDidUpdate(newProps) {
|
||||
const { animSource, animTarget, construct } = newProps;
|
||||
|
||||
console.log(isSource, isTarget);
|
||||
|
||||
if (!isSource || !isTarget) {
|
||||
return this.animations.push(idleAnimation(construct.id));
|
||||
// back to idle
|
||||
if (!animTarget || !animSource) {
|
||||
return this.idle.play();
|
||||
}
|
||||
|
||||
const avatarAnim = () => {
|
||||
console.log(isSource);
|
||||
const isSource = animSource && animSource.constructId === construct.id;
|
||||
|
||||
const selectAnim = () => {
|
||||
if (isSource) {
|
||||
console.log(construct.name, 'source anim');
|
||||
return sourceCast(animSource.constructId, animSource.direction);
|
||||
}
|
||||
|
||||
// if (!animTarget) return false;
|
||||
// match(animTarget.skill, [
|
||||
// ['banish', () => banish(construct.id)],
|
||||
// ['invert', () => invert(this.props.construct.id)],
|
||||
// ]);
|
||||
switch (animTarget.skill) {
|
||||
case 'banish': return banish(construct.id);
|
||||
case 'invert': return invert(construct.id);
|
||||
default: return null;
|
||||
}
|
||||
};
|
||||
|
||||
const anim = avatarAnim();
|
||||
const anim = selectAnim();
|
||||
if (anim) {
|
||||
console.log(anim);
|
||||
this.idle.pause();
|
||||
this.animations.push(anim);
|
||||
anim.finished.then(() => {
|
||||
console.log('anim finished');
|
||||
return this.animations.push(idleAnimation(construct.id));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
resetAnimations() {
|
||||
for (let i = this.animations.length - 1; i >= 0; i--) {
|
||||
this.animations[i].reset();
|
||||
}
|
||||
}
|
||||
|
||||
// never update, wait til it gets nuked by parent
|
||||
shouldComponentUpdate({ animTarget, sourceTarget }) {
|
||||
return (animTarget === this.props.animTarget) && (sourceTarget === this.props.sourceTarget);
|
||||
componentWillUnmount() {
|
||||
this.resetAnimations();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user