const preact = require('preact'); const { STATS, eventClasses, getCombatText, crypAvatar } = require('../utils'); const { animationDivs } = require('../animations'); const GameCryp = require('./game.cryp'); function GamePanel(props) { const { game, account, resolution, activeSkill, setActiveSkill, setActiveCryp, selectSkillTarget, sendInstanceState, sendGameReady, showLog, toggleLog, skip, quit, } = props; if (!game) return
...
; // if (showLog) { // const logs = game.log.map((l, i) => (
{l}
)).reverse(); // return ( //
//
// //
//
 
//
//
//
// {logs} //
//
// ); // } function actionClick() { if (game.phase === 'Finish') { sendInstanceState(game.instance); quit(); return true; } if (resolution) { return skip(); } return sendGameReady(); } const otherTeams = game.players.filter(t => t.id !== account.id); const playerTeam = game.players.find(t => t.id === account.id); let actionText = 'Ready'; let actionStyles = 'instance-btn instance-ui-btn right'; if (game.phase === 'Finish') actionText = 'Done'; if (resolution) actionText = 'Skip'; if (actionText === 'Ready' && playerTeam.ready) actionStyles += ' ready'; 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 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 || game.phase === 'Finish' ? 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, combatClass] = getCombatText(cryp, resolution); const combatTextClass = `combat-text ${combatClass}`; const combatTextEl = combatText ?
{combatText}
: null; const effects = cryp.effects.length ? cryp.effects.map(c =>
{c.effect} - {c.duration}T
) :
 
; const playerTeamIds = playerTeam.cryps.map(c => c.id); const targeting = game.stack .filter(s => playerTeamIds.includes(s.source_cryp_id) && s.target_cryp_id === cryp.id) .map((s, i) =>

{`< ${s.skill}`}

); const anim = (
{animationDivs(combatClass)}
); return (
selectSkillTarget(cryp.id)} >
{stats}

{cryp.name}

{effects}
{targeting}
selectSkillTarget(cryp.id)} > {crypAvatar(cryp.name)} {combatTextEl} {anim}
); } function OpponentTeam(team) { const cryps = team.cryps.map(OpponentCryp); return (
{cryps}
); } const gameClasses = `game ${resolution ? 'resolving': ''}`; function gameClick(e) { e.stopPropagation(); setActiveCryp(null); } return (
{header} {timer} {otherTeams.map(OpponentTeam)} {PlayerTeam(playerTeam, setActiveSkill)}
); } module.exports = GamePanel;