should comp updates

This commit is contained in:
Mashy 2019-10-31 11:50:27 +10:00
parent d52efc6c01
commit b554464802
5 changed files with 138 additions and 118 deletions

View File

@ -1,34 +1,25 @@
const preact = require('preact'); const preact = require('preact');
const { connect } = require('preact-redux'); const { connect } = require('preact-redux');
const actions = require('../actions');
const { ConstructAvatar } = require('./construct'); const { ConstructAvatar } = require('./construct');
const Controls = require('./controls');
const addState = connect( const addState = connect(
function receiveState(state) { function receiveState(state) {
const { const {
ws,
instance, instance,
account, account,
} = state; } = state;
function sendInstanceReady() {
return ws.sendInstanceReady(instance.id);
}
return { return {
instance, instance,
account, account,
sendInstanceReady,
}; };
}, }
); );
function FaceoffConstruct(args) { function FaceoffConstruct(args) {
const { const {
construct construct,
} = args; } = args;
return ( return (
@ -39,14 +30,20 @@ function FaceoffConstruct(args) {
<ConstructAvatar construct={construct} /> <ConstructAvatar construct={construct} />
</div> </div>
</div> </div>
) );
} }
function Faceoff(props) { class Faceoff extends preact.Component {
shouldComponentUpdate(newProps) {
if (newProps.instance !== this.props.instance) return true;
if (newProps.account !== this.props.account) return true;
return false;
}
render(props) {
const { const {
instance, instance,
account, account,
sendInstanceReady,
} = props; } = props;
if (!instance) return <div>...</div>; if (!instance) return <div>...</div>;
@ -59,7 +56,7 @@ function Faceoff(props) {
<FaceoffConstruct key={c.id} construct={c}/>); <FaceoffConstruct key={c.id} construct={c}/>);
const winner = instance.winner === team.id; const winner = instance.winner === team.id;
const classes = `team player ${winner ? 'winner' : team.ready ? 'ready' : ''}` const classes = `team player ${winner ? 'winner' : team.ready ? 'ready' : ''}`;
return ( return (
<div class={classes}> <div class={classes}>
{constructs} {constructs}
@ -73,7 +70,7 @@ function Faceoff(props) {
<FaceoffConstruct key={c.id} construct={c}/>); <FaceoffConstruct key={c.id} construct={c}/>);
const winner = instance.winner === team.id; const winner = instance.winner === team.id;
const classes = `team opponent ${winner ? 'winner' : team.ready ? 'ready' : ''}` const classes = `team opponent ${winner ? 'winner' : team.ready ? 'ready' : ''}`;
return ( return (
<div class={classes}> <div class={classes}>
@ -108,6 +105,7 @@ function Faceoff(props) {
{PlayerTeam(playerTeam)} {PlayerTeam(playerTeam)}
</main> </main>
); );
}
} }
module.exports = addState(Faceoff); module.exports = addState(Faceoff);

View File

@ -3,7 +3,7 @@ const reactStringReplace = require('react-string-replace');
const specThresholds = require('./info.thresholds'); const specThresholds = require('./info.thresholds');
const { INFO } = require('./../constants'); const { INFO } = require('./../constants');
const { convertItem, removeTier, formatInfo } = require('../utils'); const { convertItem, removeTier } = require('../utils');
const { tutorialStage } = require('../tutorial.utils'); const { tutorialStage } = require('../tutorial.utils');
const shapes = require('./shapes'); const shapes = require('./shapes');
@ -75,8 +75,8 @@ class InfoComponent extends preact.Component {
}; };
if (isSkill || isSpec) { if (isSkill || isSpec) {
let infoText = info; let infoName = info;
while (infoText.includes('Plus')) infoText = infoText.replace('Plus', '+'); while (infoName.includes('Plus')) infoName = infoName.replace('Plus', '+');
const header = isSkill ? <h3> SKILL </h3> : <h3> SPEC </h3>; const header = isSkill ? <h3> SKILL </h3> : <h3> SPEC </h3>;
@ -101,7 +101,7 @@ class InfoComponent extends preact.Component {
return ( return (
<div class={isSkill ? 'info-skill' : 'info-spec'}> <div class={isSkill ? 'info-skill' : 'info-spec'}>
<h2>{infoText} {fullInfo.cost}b</h2> <h2>{infoName} {fullInfo.cost}b</h2>
{header} {header}
{itemSourceInfo} {itemSourceInfo}
{cooldown} {cooldown}

View File

@ -13,11 +13,13 @@ const actions = require('../actions');
const addState = connect( const addState = connect(
function receiveState(state) { function receiveState(state) {
const { instance, const {
instance,
nav, nav,
navInstance, navInstance,
} = state; } = state;
return { instance, return {
instance,
nav, nav,
navInstance, navInstance,
}; };
@ -52,7 +54,7 @@ const addState = connect(
); );
class Instance extends Component { class Instance extends Component {
componentShouldUpdate(newProps) { shouldComponentUpdate(newProps) {
if (newProps.instance !== this.props.instance) return true; if (newProps.instance !== this.props.instance) return true;
return false; return false;
} }

View File

@ -16,7 +16,16 @@ const addState = connect(
} }
); );
function Main(props) { class Main extends preact.Component {
shouldComponentUpdate(newProps) {
if (newProps.game !== this.props.game) return true;
if (newProps.instance !== this.props.instance) return true;
if (newProps.account !== this.props.account) return true;
if (newProps.nav !== this.props.nav) return true;
return false;
}
render(props) {
const { const {
game, game,
instance, instance,
@ -45,6 +54,7 @@ function Main(props) {
<Bottom /> <Bottom />
</main> </main>
); );
}
} }
module.exports = addState(Main); module.exports = addState(Main);

View File

@ -10,11 +10,21 @@ const addState = connect(
state => ({ showNav: state.showNav }) state => ({ showNav: state.showNav })
); );
const Mnml = ({ showNav }) => class Mnml extends preact.Component {
<div id="mnml" class={showNav ? 'nav-visible' : ''}> shouldComponentUpdate(newProps) {
if (newProps.showNav !== this.props.showNav) return true;
return false;
}
render(args) {
return (
<div id="mnml" class={args.showNav ? 'nav-visible' : ''}>
<Main /> <Main />
<Controls /> <Controls />
<Footer /> <Footer />
</div>; </div>
);
}
}
module.exports = addState(Mnml); module.exports = addState(Mnml);