move construct calls into componentDidUpdate, change shouldCompUpdate

This commit is contained in:
Mashy 2019-10-28 19:01:22 +10:00
parent 6a4eb1837d
commit 84acb58573

View File

@ -61,42 +61,36 @@ class ConstructAvatar extends Component {
this.resetAnimations();
}
shouldComponentUpdate(newProps) {
const { animSource, animTarget, animText, construct } = newProps;
if (construct !== this.props.construct) {
return true;
}
if (animText && animText !== this.props.animText && animText.constructId === construct.id) {
componentDidUpdate(prevProps) {
const { animSource, animTarget, animText, construct } = this.props;
// a different text object and text construct
if (animText && animText !== prevProps.animText && animText.constructId === construct.id) {
return wiggle(construct.id, this.idle);
}
if (animSource === this.props.animSource && animTarget === this.props.animTarget) {
// console.warn(construct.name, 'thinks its same props')
return false;
}
// something has changed
// what do?
// this is the source
if (animSource && animSource.constructId === construct.id) {
// console.warn(construct.name, 'should update')
// different source object and source construct
if (animSource && animSource !== prevProps.animSource && animSource.constructId === construct.id) {
return sourceCast(animSource.constructId, animSource.direction, this.idle);
}
// this is the target
if (animTarget && animTarget.constructId.includes(construct.id)) {
// console.warn(construct.name, 'should update')
// different target object and target construct
if (animTarget && animTarget !== prevProps.animTarget && animTarget.constructId.includes(construct.id)) {
switch (animTarget.skill) {
case 'Banish': return banish(construct.id, this.idle);
case 'Invert': return invert(construct.id, this.idle);
default: return null;
}
}
return true;
}
shouldComponentUpdate(newProps) {
const { animSource, animTarget, animText, construct } = newProps;
if (animSource !== this.props.animSource) return true;
if (animTarget !== this.props.animTarget) return true;
if (animText !== this.props.animText) return true;
if (construct !== this.props.construct) return true;
return false;
}
}