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 effects = cryp.effects.map((effect, i) => (
{effect} for {effect.turns}T
));
return (
selectIncomingTarget(cryp.id)}
className="tile is-vertical">
{cryp.hp.value} / {cryp.hp.max} HP
{effects}
{skills}
);
}
function PlayerTeam(team) {
const cryps = team.cryps.map(c => PlayerCrypCard(c, setActiveSkill));
return (
{cryps}
);
}
function OpponentCrypCard(cryp) {
const effects = cryp.effects.map((effect, i) => (
{effect.effect} for {effect.turns}T
));
return (
selectSkillTarget(cryp.id)} >
{cryp.hp.value} / {cryp.hp.value} HP
{effects}
);
}
function OpponentTeam(team) {
const cryps = team.cryps.map(OpponentCrypCard);
return (
{cryps}
);
}
const logs = game.log.reverse().map((l, i) => ({l}
));
return (
{playerTeam.id}
{PlayerTeam(playerTeam, setActiveSkill)}
Round X
{otherTeams.id}
{otherTeams.map(OpponentTeam)}
);
}
module.exports = GamePanel;