const preact = require('preact'); const range = require('lodash/range'); const { STATS, eventClasses, getCombatText, crypAvatar } = require('../utils'); const GameCryp = require('./game.cryp'); const TargetingArrows = require('./targeting.arrows'); function GamePanel(props) { const { game, resolution, activeSkill, setActiveSkill, setActiveCryp, selectSkillTarget, sendInstanceState, sendGameReady, account, showLog, toggleLog, quit, } = props; if (!game) return
...
; console.log(showLog); if (showLog) { const logs = game.log.map((l, i) => (
{l}
)).reverse(); return (
 
{logs}
); } function backClick() { if (game.phase === 'Finish') sendInstanceState(game.instance); return quit(); } const header = (
 
); function findCryp(id) { const team = game.players.find(t => t.cryps.find(c => c.id === id)); if (team) return team.cryps.find(c => c.id === id); return null; } const otherTeams = game.players.filter(t => t.id !== account.id); const playerTeam = game.players.find(t => t.id === account.id); const zero = Date.parse(game.phase_end) - (1000 * 60); const now = Date.now(); const end = Date.parse(game.phase_end); const timerPct = ((now - zero) / (end - zero) * 100); const displayPct = resolution ? 0 : Math.min(timerPct, 100); const displayColour = playerTeam.ready ? 'forestgreen' : timerPct > 80 ? 'red' : 'whitesmoke'; const timerStyles = { width: `${displayPct}%`, background: displayColour, }; const timer = (
 
); function PlayerTeam(team) { const cryps = team.cryps.map((c, i) => ); return (
{cryps}
); } function OpponentCryp(cryp, i) { const ko = cryp.green_life.value === 0 ? 'ko' : ''; const classes = eventClasses(resolution, cryp); const stats = [STATS.greenLife, STATS.redLife, STATS.blueLife].map((s, j) => (
{s.svg(`stat-icon ${s.colour}`)}
{cryp[s.stat].value} / {cryp[s.stat].max}
)); const combatText = getCombatText(cryp, resolution); const combatTextEl = combatText ?
{combatText}
: null; const effects = cryp.effects.length ? cryp.effects.map(c =>
{c.effect} - {c.duration}T
) :
 
; return (
selectSkillTarget(cryp.id)} >
selectSkillTarget(cryp.id)} > {crypAvatar(cryp.name)} {combatTextEl}
{effects}
{stats}
); } function OpponentTeam(team) { const cryps = team.cryps.map(OpponentCryp); return (
{cryps}
); } const gameClasses = `game ${resolution ? 'resolving': ''}`; return (
setActiveCryp(null)} > {header} {timer} {PlayerTeam(playerTeam, setActiveSkill)} {otherTeams.map(OpponentTeam)}
); } module.exports = GamePanel;