const preact = require('preact'); const range = require('lodash/range'); const { connect } = require('preact-redux'); const actions = require('../actions'); const { STATS, SPECS, crypAvatar } = require('../utils'); const shapes = require('./shapes'); const addState = connect( function receiveState(state) { const { activeCryp, player } = state; return { activeCryp, player }; }, function receiveDispatch(dispatch) { function setInfo(item, value) { dispatch(actions.setInfo([item, value])); } function setActiveCryp(value) { dispatch(actions.setActiveCryp(value)); } function setVboxHidden(value) { dispatch(actions.setVboxHidden(value)); } return { setInfo, setActiveCryp, setVboxHidden }; } ); function InfoCryp(args) { const { activeCryp, player, setVboxHidden, setInfo, setActiveCryp, } = args; if (!activeCryp) return false; const cryp = player.cryps.find(c => c.id === activeCryp.id); if (!cryp) return false; // onClick={() => setInfo('skill', { skill: s, cryp })} const skills = range(0, 3).map(i => { const skill = cryp.skills[i]; function skillClick(e) { if (!skill) { setVboxHidden(false); setInfo('highlight', 'skill'); } else setInfo('skill', { skill: skill.skill, cryp }); e.stopPropagation(); return setActiveCryp(cryp); } const s = cryp.skills[i] ? cryp.skills[i].skill : ( ); return ; }); const stats = Object.values(STATS).map((s, j) => (
{s.svg(`stat-icon ${s.colour}`)}
{cryp[s.stat].value}
)); const specs = range(0, 6).map(i => { const s = cryp.specs[i]; function blankSpecClick(e) { e.stopPropagation(); setActiveCryp(cryp); setInfo('highlight', 'spec'); setVboxHidden(true); } if (!s) { return (
{shapes.diamond('stat-icon gray')}
 
); } function specClick(e) { e.stopPropagation(); setActiveCryp(cryp); setInfo('spec', { spec: s, cryp }); } return (
{SPECS[s].svg(`stat-icon ${SPECS[s].colour}`)}
{SPECS[s].caption}
); }); return (
{stats}
{specs}
{skills}
); } module.exports = addState(InfoCryp);