const preact = require('preact'); const { connect } = require('preact-redux'); const shapes = require('./shapes'); const addState = connect(({ animText }) => ({ animText })); class GameConstructLife extends preact.Component { shouldComponentUpdate(newProps) { if (newProps.animText !== this.props.animText) { if (newProps.animText && newProps.animText.target === this.props.construct.id) { const [type] = newProps.animText.variant; if (type === 'Damage' || type === 'Healing' || type === 'Recharge') return true; } } if (newProps.construct !== this.props.construct) return true; return false; } render() { const { construct, animText } = this.props; const lifeBars = (redLife, greenLife, blueLife) => { return (
{shapes.RedLife()}
{redLife} / {construct.red_life.max}
{shapes.GreenLife()}
{greenLife} / {construct.green_life.max}
{shapes.BlueLife()}
{blueLife} / {construct.blue_life.max}
); }; if (animText) { const { red, blue, green } = animText.variant[1].display; return lifeBars(red, green, blue); } return lifeBars(construct.red_life.value, construct.green_life.value, construct.blue_life.value); } } module.exports = addState(GameConstructLife);