const preact = require('preact'); // const key = require('keymaster'); const range = require('lodash/range'); const mapValues = require('lodash/mapValues'); const VboxContainer = require('./vbox.container'); const InfoContainer = require('./info.container'); const molecule = require('./molecule'); const { SPECS } = require('../utils'); function Cryp(props) { const { cryp, sendVboxApply, setInfo, activeVar, setActiveCryp, } = props; const skills = range(0, 3).map(i => { const skill = cryp.skills[i]; const s = skill ? skill.skill : ( ); function skillClick() { if (!skill) return false; setInfo('skill', { skill: skill.skill, cryp }); return setActiveCryp(cryp); } return ; }); // needed for ondrop to fire function onDragOver(e) { e.preventDefault(); return false; } function onDrop(e) { e.stopPropagation(); e.preventDefault(); const item = parseInt(e.dataTransfer.getData('text'), 10); return sendVboxApply(cryp.id, item); } function onClick(e) { e.stopPropagation(); e.preventDefault(); if (activeVar !== null) return sendVboxApply(cryp.id, activeVar); setInfo(null); return setActiveCryp(cryp); } const specs = cryp.specs.map((s, i) => { function specClick() { setActiveCryp(cryp); setInfo('spec', { spec: s, cryp }); } return (
{SPECS[s].svg(`stat-icon ${SPECS[s].colour}`)}
{SPECS[s].caption}
); }); const cTotal = cryp.colours.red + cryp.colours.blue + cryp.colours.green; const colours = mapValues(cryp.colours, c => { if (cTotal === 0) return 245; return Math.floor(c / cTotal * 255); }); const alpha = cTotal === 0 ? 1 : 0.75; const thickness = total => { if (total < 3) return 1; if (total < 6) return 2; if (total < 9) return 3; return 4; }; const border = { border: `${thickness(cTotal)}px solid rgba(${colours.red}, ${colours.green}, ${colours.blue}, ${alpha})` }; return (
{molecule()}
{cryp.name}
{skills}
{specs}
); } function InstanceComponent(args) { const { account, instance, quit, // clearInfo, sendInstanceReady, sendVboxApply, setInfo, activeVar, activeCryp, setActiveVar, setActiveCryp, } = args; if (!instance) return
...
; const player = instance.players.find(p => p.account === account.id); const cryps = player.cryps.map((c, i) => Cryp({ cryp: c, sendVboxApply, setInfo, activeVar, setActiveCryp, })); function showVbox(e) { setActiveVar(null); setActiveCryp(null); e.stopPropagation(); } function showTeam(e) { setActiveCryp(player.cryps[0]); e.stopPropagation(); } const vboxBtn = ( ); const teamBtn = ( ); const infoSelected = activeVar !== null || activeCryp; const navBtn = infoSelected ? vboxBtn : teamBtn; const crypListClass = `cryp-list ${infoSelected ? '' : 'hidden'}`; const menuBtn = ( ); return (
{navBtn} {menuBtn}
 
{cryps}
); } module.exports = InstanceComponent;