const preact = require('preact'); const range = require('lodash/range'); const molecule = require('./molecule'); const { STATS, eventClasses, getCombatText } = require('../utils'); const GameCryp = require('./game.cryp'); const SkillBtn = require('./skill.btn'); // const SKILL_HOT_KEYS = ['Q', 'W', 'E', 'R']; function GamePanel(props) { const { game, resolution, activeSkill, setActiveSkill, setActiveCryp, selectSkillTarget, sendInstanceState, activeCryp, account, showLog, toggleLog, quit, } = props; if (!game) return
...
; if (showLog) { const logs = game.log.map((l, i) => (
{l}
)).reverse(); return (
 
{logs}
); } function backClick() { quit(); return sendInstanceState(game.instance); } 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); function stackElement(c, i) { let skills = game.stack.filter(s => s.source_cryp_id === c.id).map((s, j) => { const target = findCryp(s.target_cryp_id); return (
{s.skill} -> {target.name}
); }); if (!skills.length) skills = (
 
); const effects = c.effects.map((e, j) =>
{e.effect} - {e.duration}T
); return (
{effects} {skills}
); } 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); return (
selectSkillTarget(cryp.id)} >
{molecule(combatText)}
{cryp.name}
{stats}
); } function OpponentTeam(team) { const cryps = team.cryps.map(OpponentCryp); return (
{cryps}
); } const selectedSkills = resolution ?
 
: playerTeam.cryps.map((c, i) => stackElement(c, i)); const mobileSkills = activeCryp && activeCryp.green_life.value ? range(0, 3).map(i => ) : (
); return (
setActiveCryp(null)} > {header} {PlayerTeam(playerTeam, setActiveSkill)}
{mobileSkills}
{selectedSkills}
{otherTeams.map(OpponentTeam)}
); } module.exports = GamePanel;