const preact = require('preact');
const range = require('lodash/range');
const molecule = require('./molecule');
const { STATS } = require('../utils');
// const SKILL_HOT_KEYS = ['Q', 'W', 'E', 'R'];
function GamePanel(props) {
const {
game,
activeSkill,
setActiveSkill,
selectSkillTarget,
account,
showLog,
toggleLog,
quit,
} = props;
if (!game) return
...
;
const header = (
);
if (showLog) {
const logs = game.log.map((l, i) => ({l}
)).reverse();
return (
{header}
{logs}
);
}
function findCryp(id) {
const team = game.teams.find(t => t.cryps.find(c => c.id === id));
if (team) return team.cryps.find(c => c.id === id);
return null;
}
const otherTeams = game.teams.filter(t => t.id !== account.id);
const playerTeam = game.teams.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 = (
);
return (
{skills}
);
}
function Cryp(cryp) {
const ko = cryp.hp.value === 0 ? 'ko' : '';
const skills = range(0, 4).map(i => {
const s = cryp.skills[i];
if (!s) {
return (
);
}
const cdText = cryp.skills[i].cd > 0
? `- ${s.cd}`
: '';
const highlight = activeSkill
? activeSkill.crypId === cryp.id && activeSkill.skill === s
: false;
return (
);
});
const stats = Object.values(STATS).map((s, i) => (
{s.svg(`stat-icon ${s.colour}`)}
{cryp[s.stat].value} / {cryp[s.stat].max}
));
return (
selectSkillTarget(cryp.id)} >
{molecule}
{cryp.name}
{skills}
{stats}
);
}
function PlayerTeam(team) {
const cryps = team.cryps.map(c => Cryp(c));
return (
{cryps}
);
}
function OpponentCryp(cryp, i) {
const stats = [STATS.hp, STATS.redShield, STATS.blueShield].map((s, j) => (
{s.svg(`stat-icon ${s.colour}`)}
{cryp[s.stat].value} / {cryp[s.stat].max}
));
return (
selectSkillTarget(cryp.id)} >
{molecule}
{cryp.name}
{stats}
);
}
function OpponentTeam(team) {
const cryps = team.cryps.map(OpponentCryp);
return (
{cryps}
);
}
const selectedSkills = playerTeam.cryps.map((c, i) => stackElement(c, i));
return (
{header}
{PlayerTeam(playerTeam, setActiveSkill)}
{selectedSkills}
{otherTeams.map(OpponentTeam)}
);
}
module.exports = GamePanel;