145 lines
4.0 KiB
JavaScript
145 lines
4.0 KiB
JavaScript
const { connect } = require('preact-redux');
|
|
const preact = require('preact');
|
|
const range = require('lodash/range');
|
|
|
|
const actions = require('../actions');
|
|
const shapes = require('./shapes');
|
|
const { convertItem } = require('./../utils');
|
|
|
|
const addState = connect(
|
|
function receiveState(state) {
|
|
const { account, activeConstruct, itemInfo, info, ws, instance, player, itemUnequip } = state;
|
|
|
|
function sendUnequip(constructId, item) {
|
|
return ws.sendVboxUnequip(instance.id, constructId, item);
|
|
}
|
|
|
|
return { player, itemInfo, instance, info, sendUnequip, activeConstruct, itemUnequip };
|
|
},
|
|
|
|
function receiveDispatch(dispatch) {
|
|
function setInfo(item) {
|
|
dispatch(actions.setInfo(item));
|
|
}
|
|
|
|
function clearInfo() {
|
|
return dispatch(actions.setInfo(null));
|
|
}
|
|
|
|
function setItemEquip(v) {
|
|
return dispatch(actions.setItemEquip(v));
|
|
}
|
|
|
|
function setItemUnequip(v) {
|
|
return dispatch(actions.setItemUnequip(v));
|
|
}
|
|
|
|
return { setInfo, setItemEquip, setItemUnequip, clearInfo };
|
|
}
|
|
|
|
);
|
|
|
|
function Equipment(props) {
|
|
const {
|
|
player,
|
|
instance,
|
|
|
|
itemUnequip,
|
|
setItemEquip,
|
|
setItemUnequip,
|
|
activeConstruct,
|
|
|
|
itemInfo,
|
|
sendUnequip,
|
|
|
|
setInfo,
|
|
} = props;
|
|
|
|
if (instance.phase === 'Lobby') return false;
|
|
|
|
const { vbox } = player;
|
|
|
|
const fullInfo = itemInfo.items.find(i => i.item === itemUnequip);
|
|
const isSkill = fullInfo && fullInfo.skill;
|
|
const isSpec = fullInfo && fullInfo.spec;
|
|
|
|
function skillClick(e, i) {
|
|
if (itemUnequip && activeConstruct) return false;
|
|
// const value = vbox.bound[i];
|
|
setItemEquip(i);
|
|
return false;
|
|
}
|
|
|
|
function unequipClick(e) {
|
|
e.stopPropagation();
|
|
if (!itemUnequip) return false;
|
|
if (!activeConstruct) return false;
|
|
setItemUnequip([]);
|
|
return sendUnequip(activeConstruct.id, itemUnequip);
|
|
}
|
|
|
|
function hoverInfo(e, info) {
|
|
e.stopPropagation();
|
|
return setInfo(info);
|
|
}
|
|
|
|
const skillClass = isSkill ? 'skills highlight' : 'skills';
|
|
const specClass = isSpec ? 'specs highlight' : 'specs';
|
|
|
|
const skills = range(0, 9).map(i => {
|
|
const item = convertItem(vbox.bound[i]);
|
|
const skillInfo = itemInfo.items.find(i => i.item === item);
|
|
if (skillInfo && skillInfo.skill) {
|
|
return (
|
|
<button key={i} onClick={e => skillClick(e, i)} onMouseOver={e => hoverInfo(e, item)}>
|
|
{item}
|
|
</button>
|
|
);
|
|
}
|
|
return false;
|
|
});
|
|
|
|
const specs = range(0, 9).map(i => {
|
|
const item = convertItem(vbox.bound[i]);
|
|
const specInfo = itemInfo.items.find(i => i.item === item);
|
|
if (specInfo && specInfo.spec) {
|
|
return (
|
|
<figure key={i} onClick={e => skillClick(e, i)} onMouseOver={e => hoverInfo(e, item)} >
|
|
{shapes[item]()}
|
|
<figcaption>{item ? item : '-'}</figcaption>
|
|
</figure>
|
|
);
|
|
}
|
|
return false;
|
|
});
|
|
|
|
if (skills.every(s => !s)) skills.push(<button disabled={true}> </button>);
|
|
if (specs.every(s => !s)) {
|
|
specs.push(
|
|
<figure>
|
|
{shapes.diamond('gray')}
|
|
<figcaption> </figcaption>
|
|
</figure>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div class="equip" >
|
|
<div class={skillClass} onClick={e => unequipClick(e)} onMouseOver={e => hoverInfo(e, 'equipSkills')} >
|
|
<h3>Skills</h3>
|
|
<div class ="items">
|
|
{skills}
|
|
</div>
|
|
</div>
|
|
<div class={specClass} onClick={e => unequipClick(e)} onMouseOver={e => hoverInfo(e, 'equipSpecs')} >
|
|
<h3>Specs</h3>
|
|
<div class ="items">
|
|
{specs}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
module.exports = addState(Equipment);
|