const preact = require('preact');
const { connect } = require('preact-redux');
const { ConstructAvatar } = require('./construct');
const addState = connect(
function receiveState(state) {
const {
instance,
account,
} = state;
return {
instance,
account,
};
}
);
function FaceoffConstruct(args) {
const {
construct,
} = args;
return (
);
}
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 {
instance,
account,
} = props;
if (!instance) return ...
;
const otherTeam = instance.players.find(t => t.id !== account.id);
const playerTeam = instance.players.find(t => t.id === account.id);
function PlayerTeam(team) {
const constructs = team.constructs.map((c, i) =>
);
const winner = instance.winner === team.id;
const classes = `team player ${winner ? 'winner' : team.ready ? 'ready' : ''}`;
return (
{constructs}
);
}
function OpponentTeam(team) {
const constructs = team.constructs.map((c, i) =>
);
const winner = instance.winner === team.id;
const classes = `team opponent ${winner ? 'winner' : team.ready ? 'ready' : ''}`;
return (
{constructs}
);
}
function faceoffText() {
if (!instance.winner) {
if (instance.phase === 'Finished') return (
);
return (
{otherTeam.name}
vs
{playerTeam.name}
);
}
const winner = instance.winner === playerTeam.id ? playerTeam : otherTeam;
return (
)
}
return (
{OpponentTeam(otherTeam)}
{faceoffText()}
{PlayerTeam(playerTeam)}
);
}
}
module.exports = addState(Faceoff);