const preact = require('preact');
const key = require('keymaster');
const SKILL_HOT_KEYS = ['Q', 'W', 'E', 'R'];
function GamePanel(props) {
const {
game,
activeSkill,
activeIncoming,
setActiveSkill,
setActiveIncoming,
selectSkillTarget,
selectIncomingTarget,
account,
} = props;
if (!game) return
...
;
const otherTeams = game.teams.filter(t => t.id !== account.id);
const playerTeam = game.teams.find(t => t.id === account.id);
const incoming = game.stack.filter(s => s.target_team_id === playerTeam.id).map((inc) => {
key.unbind('1');
key('1', () => setActiveIncoming(inc.id));
return (
{JSON.stringify(inc)}
);
});
function PlayerCrypCard(cryp) {
const skills = cryp.skills.map((skill, i) => {
const hotkey = SKILL_HOT_KEYS[i];
key.unbind(hotkey);
key(hotkey, () => setActiveSkill(cryp.id, skill));
return (
);
});
const statuses = cryp.statuses.map((status, i) => (
{status} for {status.turns}T
));
return (
selectIncomingTarget(cryp.id)}
className="tile is-vertical">
{cryp.name}
Level {cryp.lvl}
{cryp.hp.value} / {cryp.stam.value} HP
{cryp.xp} / {Math.pow(2, cryp.lvl + 1)} XP
{statuses}
{skills}
);
}
function PlayerTeam(team) {
const cryps = team.cryps.map(c => PlayerCrypCard(c, setActiveSkill));
return (
{cryps}
);
}
function OpponentCrypCard(cryp) {
const statuses = cryp.statuses.map((status, i) => (
{status.status} for {status.turns}T
));
return (
{cryp.name}
Level {cryp.lvl}
{cryp.hp.value} / {cryp.stam.value} HP
{cryp.xp} / {Math.pow(2, cryp.lvl + 1)} XP
{statuses}
);
}
function OpponentTeam(team) {
const cryps = team.cryps.map(OpponentCrypCard);
return (
selectSkillTarget(team.id)} >
{cryps}
);
}
// style={{ "min-height": "100%" }}
function phaseText(phase) {
switch (phase) {
case 'Skill':
return 'Choose abilities';
case 'Target':
return 'Block abilities';
case 'Finish':
return 'Game over';
}
}
return (
{phaseText(game.phase)}
{PlayerTeam(playerTeam, setActiveSkill)}
{otherTeams.map(OpponentTeam)}
{incoming}
);
}
module.exports = GamePanel;