const preact = require('preact'); const { connect } = require('preact-redux'); const actions = require('../actions'); const { ConstructAvatar } = require('./construct'); const Controls = require('./controls'); const addState = connect( function receiveState(state) { const { ws, instance, account, } = state; function sendInstanceReady() { return ws.sendInstanceReady(instance.id); } return { instance, account, sendInstanceReady, }; }, ); function FaceoffConstruct(args) { const { construct } = args; return (

{construct.name}

) } function Faceoff(props) { const { instance, account, sendInstanceReady, } = 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 classes = `team player ${team.ready ? 'ready' : ''}` return (
{constructs}
); } function OpponentTeam(team) { const constructs = team.constructs.map((c, i) => ); const classes = `team opponent ${team.ready ? 'ready' : ''}` return (
{constructs}
); } function faceoffText() { if (!instance.winner) { const zero = Date.parse(instance.phase_start); const now = Date.now(); const end = Date.parse(instance.phase_end); const timerPct = instance.phase_end ? ((now - zero) / (end - zero) * 100) : 100; const fight = timerPct > 10 ?

FIGHT

: null; return (

{otherTeam.name}

vs

{playerTeam.name}

{fight}
); } if (instance.winner === playerTeam.id) { return (

You are the champion

) } return (

You lose

) } return (
{OpponentTeam(otherTeam)} {faceoffText()} {PlayerTeam(playerTeam)}
); } module.exports = addState(Faceoff);