Merge branch 'vbox-combine' into develop
This commit is contained in:
@@ -33,11 +33,9 @@ const addState = connect(
|
||||
function accountPage() {
|
||||
dispatch(actions.setGame(null));
|
||||
dispatch(actions.setInstance(null));
|
||||
dispatch(actions.setCombiner([]));
|
||||
dispatch(actions.setReclaiming(false));
|
||||
dispatch(actions.setActiveSkill(null));
|
||||
dispatch(actions.setInfo(null));
|
||||
dispatch(actions.setItemEquip(null));
|
||||
dispatch(actions.setItemUnequip([]));
|
||||
dispatch(actions.setVboxHighlight([]));
|
||||
return dispatch(actions.setNav('account'));
|
||||
|
||||
@@ -32,11 +32,9 @@ const addState = connect(
|
||||
function setNav(place) {
|
||||
dispatch(actions.setGame(null));
|
||||
dispatch(actions.setInstance(null));
|
||||
dispatch(actions.setCombiner([]));
|
||||
dispatch(actions.setReclaiming(false));
|
||||
dispatch(actions.setActiveSkill(null));
|
||||
dispatch(actions.setInfo(null));
|
||||
dispatch(actions.setItemEquip(null));
|
||||
dispatch(actions.setItemUnequip([]));
|
||||
dispatch(actions.setVboxHighlight([]));
|
||||
dispatch(actions.setMtxActive(null));
|
||||
|
||||
@@ -7,7 +7,6 @@ const addState = connect(
|
||||
function receiveState(state) {
|
||||
const {
|
||||
ws,
|
||||
combiner,
|
||||
info,
|
||||
itemInfo,
|
||||
instance,
|
||||
@@ -18,7 +17,6 @@ const addState = connect(
|
||||
|
||||
return {
|
||||
ws,
|
||||
combiner,
|
||||
info,
|
||||
itemInfo,
|
||||
instance,
|
||||
|
||||
@@ -27,12 +27,10 @@ const addState = connect(
|
||||
|
||||
|
||||
function clearItems() {
|
||||
dispatch(actions.setCombiner([]));
|
||||
dispatch(actions.setReclaiming(false));
|
||||
dispatch(actions.setItemEquip(null));
|
||||
dispatch(actions.setItemUnequip([]));
|
||||
dispatch(actions.setVboxHighlight([]));
|
||||
dispatch(actions.setVboxSelected([]));
|
||||
dispatch(actions.setVboxSelected({ shopSelect: [], stashSelect: [] }));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,24 +19,19 @@ const addState = connect(
|
||||
player,
|
||||
account,
|
||||
itemInfo,
|
||||
itemEquip,
|
||||
itemUnequip,
|
||||
vboxSelected,
|
||||
tutorial,
|
||||
} = state;
|
||||
|
||||
function sendVboxAcceptEquip(constructId) {
|
||||
return ws.sendVboxAcceptEquip(instance.id, vboxSelected[0], vboxSelected[1], constructId);
|
||||
return ws.sendVboxAcceptEquip(instance.id, vboxSelected.shopSelect[0][0], vboxSelected.shopSelect[0][1], constructId);
|
||||
}
|
||||
|
||||
function sendVboxApply(constructId, i) {
|
||||
return ws.sendVboxApply(instance.id, constructId, i);
|
||||
}
|
||||
|
||||
function sendUnequip(constructId, item) {
|
||||
return ws.sendVboxUnequip(instance.id, constructId, item);
|
||||
}
|
||||
|
||||
function sendVboxUnequipApply(targetConstructId) {
|
||||
return ws.sendVboxUnequipApply(instance.id, itemUnequip[0], itemUnequip[1], targetConstructId);
|
||||
}
|
||||
@@ -49,9 +44,7 @@ const addState = connect(
|
||||
sendVboxUnequipApply,
|
||||
sendVboxApply,
|
||||
itemInfo,
|
||||
itemEquip,
|
||||
itemUnequip,
|
||||
sendUnequip,
|
||||
vboxSelected,
|
||||
tutorial,
|
||||
};
|
||||
@@ -66,15 +59,12 @@ const addState = connect(
|
||||
dispatch(actions.setInfo(item));
|
||||
}
|
||||
|
||||
function setItemEquip(v) {
|
||||
return dispatch(actions.setItemEquip(v));
|
||||
}
|
||||
|
||||
function setItemUnequip(v) {
|
||||
dispatch(actions.setVboxSelected({ shopSelect: [], stashSelect: [] }));
|
||||
return dispatch(actions.setItemUnequip(v));
|
||||
}
|
||||
|
||||
return { quit, setInfo, setItemUnequip, setItemEquip };
|
||||
return { quit, setInfo, setItemUnequip };
|
||||
}
|
||||
|
||||
);
|
||||
@@ -84,7 +74,6 @@ function Construct(props) {
|
||||
// Changing state variables
|
||||
construct,
|
||||
iter,
|
||||
itemEquip,
|
||||
itemUnequip,
|
||||
instance,
|
||||
player,
|
||||
@@ -96,13 +85,16 @@ function Construct(props) {
|
||||
sendVboxApply,
|
||||
sendVboxAcceptEquip,
|
||||
sendVboxUnequipApply,
|
||||
sendUnequip,
|
||||
setItemUnequip,
|
||||
setItemEquip,
|
||||
setInfo,
|
||||
} = props;
|
||||
|
||||
const { vbox } = player;
|
||||
|
||||
const itemEquip = vboxSelected.shopSelect.length === 0 && vboxSelected.stashSelect.length === 1
|
||||
? vboxSelected.stashSelect[0]
|
||||
: -1;
|
||||
|
||||
const duplicateSkill = construct.skills.length !== 0 && construct.skills.every(sk => {
|
||||
if (!itemEquip && itemEquip !== 0) return false;
|
||||
if (!sk) return false;
|
||||
@@ -113,17 +105,16 @@ function Construct(props) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
if (duplicateSkill || tutorialDisableEquip) return true;
|
||||
if (itemEquip !== null) return sendVboxApply(construct.id, itemEquip);
|
||||
if (vboxSelected[0]) return sendVboxAcceptEquip(construct.id);
|
||||
if (itemEquip !== -1) return sendVboxApply(construct.id, itemEquip);
|
||||
if (vboxSelected.shopSelect.length === 1) return sendVboxAcceptEquip(construct.id);
|
||||
if (itemUnequip.length && itemUnequip[0] !== construct.id) return sendVboxUnequipApply(construct.id);
|
||||
setItemEquip(null);
|
||||
setItemUnequip([]);
|
||||
return true;
|
||||
}
|
||||
function hoverInfo(e, info) {
|
||||
e.stopPropagation();
|
||||
if (!info) return false;
|
||||
if (vboxSelected[0] || itemEquip > -1) return false;
|
||||
if (vboxSelected.shopSelect.length || vboxSelected.stashSelect.length) return false;
|
||||
return setInfo(info);
|
||||
}
|
||||
|
||||
@@ -138,20 +129,11 @@ function Construct(props) {
|
||||
|
||||
function skillClick(e) {
|
||||
if (!skill) return false;
|
||||
setItemUnequip([construct.id, skill.skill]);
|
||||
setItemUnequip([construct.id, skill.skill, i]);
|
||||
e.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
function skillDblClick(e) {
|
||||
if (!skill) return false;
|
||||
sendUnequip(construct.id, skill.skill);
|
||||
setItemUnequip([]);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
return true;
|
||||
}
|
||||
|
||||
const equipping = skillList.includes(vbox.bound[itemEquip]) && !skill
|
||||
&& !tutorialDisableEquip && !duplicateSkill && i === construct.skills.length;
|
||||
const border = () => {
|
||||
@@ -161,7 +143,9 @@ function Construct(props) {
|
||||
return borderFn();
|
||||
};
|
||||
|
||||
const classes = `${equipping ? 'equipping' : ''} ${!skill ? 'empty' : ''} ${border()}`;
|
||||
const highlight = itemUnequip[0] === construct.id && itemUnequip[1] === s ? 'highlight' : '';
|
||||
|
||||
const classes = `${highlight} ${equipping ? 'equipping' : ''} ${!skill ? 'empty' : ''} ${border()}`;
|
||||
return (
|
||||
<label onDragStart={ev => {
|
||||
ev.dataTransfer.setData('text', '');
|
||||
@@ -172,7 +156,6 @@ function Construct(props) {
|
||||
disabled={!skill && !equipping}
|
||||
class={classes}
|
||||
onClick={skillClick}
|
||||
onDblClick={skillDblClick}
|
||||
onMouseOver={e => hoverInfo(e, skill && skill.skill)} >
|
||||
{s}
|
||||
</button>
|
||||
@@ -195,18 +178,10 @@ function Construct(props) {
|
||||
|
||||
function specClick(e) {
|
||||
e.stopPropagation();
|
||||
setItemUnequip([construct.id, s]);
|
||||
setItemUnequip([construct.id, s, i]);
|
||||
}
|
||||
|
||||
function specDblClick(e) {
|
||||
sendUnequip(construct.id, s);
|
||||
setItemUnequip([]);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
const highlight = itemUnequip[0] === construct.id && itemUnequip[1] === s && i === itemUnequip[2];
|
||||
return (
|
||||
<label onDragStart={ev => {
|
||||
ev.dataTransfer.setData('text', '');
|
||||
@@ -214,8 +189,8 @@ function Construct(props) {
|
||||
}} key={i} draggable="true" onDragEnd={() => setItemUnequip([])}>
|
||||
<button
|
||||
key={i}
|
||||
class={`${highlight ? 'highlight' : ''}`}
|
||||
onClick={specClick}
|
||||
onDblClick={specDblClick}
|
||||
onMouseOver={e => hoverInfo(e, s)} >
|
||||
{shapes[s]()}
|
||||
</button>
|
||||
@@ -259,7 +234,6 @@ function Construct(props) {
|
||||
|
||||
class InstanceConstructs extends preact.Component {
|
||||
shouldComponentUpdate(newProps) {
|
||||
if (newProps.itemEquip !== this.props.itemEquip) return true;
|
||||
if (newProps.itemUnequip !== this.props.itemUnequip) return true;
|
||||
if (newProps.tutorial !== this.props.tutorial) return true;
|
||||
// JSON or Array objects
|
||||
@@ -272,7 +246,6 @@ class InstanceConstructs extends preact.Component {
|
||||
render(props) {
|
||||
const {
|
||||
// Changing state variables
|
||||
itemEquip,
|
||||
itemUnequip,
|
||||
instance,
|
||||
player,
|
||||
@@ -287,8 +260,6 @@ class InstanceConstructs extends preact.Component {
|
||||
sendVboxUnequipApply,
|
||||
setVboxHighlight,
|
||||
setItemUnequip,
|
||||
setItemEquip,
|
||||
sendUnequip,
|
||||
} = props;
|
||||
|
||||
if (!player) return false;
|
||||
@@ -301,11 +272,9 @@ class InstanceConstructs extends preact.Component {
|
||||
return Construct({
|
||||
iter: i,
|
||||
construct: player.constructs[i],
|
||||
itemEquip,
|
||||
itemUnequip,
|
||||
instance,
|
||||
setItemUnequip,
|
||||
setItemEquip,
|
||||
player,
|
||||
sendVboxApply,
|
||||
sendVboxAcceptEquip,
|
||||
@@ -313,7 +282,6 @@ class InstanceConstructs extends preact.Component {
|
||||
setInfo,
|
||||
itemInfo,
|
||||
setVboxHighlight,
|
||||
sendUnequip,
|
||||
vboxSelected,
|
||||
tutorial,
|
||||
});
|
||||
|
||||
@@ -33,11 +33,9 @@ const addState = connect(
|
||||
function setNav(place) {
|
||||
dispatch(actions.setGame(null));
|
||||
dispatch(actions.setInstance(null));
|
||||
dispatch(actions.setCombiner([]));
|
||||
dispatch(actions.setReclaiming(false));
|
||||
dispatch(actions.setActiveSkill(null));
|
||||
dispatch(actions.setInfo(null));
|
||||
dispatch(actions.setItemEquip(null));
|
||||
dispatch(actions.setItemUnequip([]));
|
||||
dispatch(actions.setVboxHighlight([]));
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ const { connect } = require('preact-redux');
|
||||
const range = require('lodash/range');
|
||||
const countBy = require('lodash/countBy');
|
||||
const without = require('lodash/without');
|
||||
const forEach = require('lodash/forEach');
|
||||
|
||||
const { removeTier } = require('../utils');
|
||||
const shapes = require('./shapes');
|
||||
@@ -15,7 +16,6 @@ const addState = connect(
|
||||
ws,
|
||||
instance,
|
||||
player,
|
||||
combiner,
|
||||
reclaiming,
|
||||
vboxSelected,
|
||||
itemInfo,
|
||||
@@ -33,7 +33,7 @@ const addState = connect(
|
||||
}
|
||||
|
||||
function sendVboxCombine() {
|
||||
return ws.sendVboxCombine(instance.id, combiner);
|
||||
return ws.sendVboxCombine(instance.id, vboxSelected.stashSelect, vboxSelected.shopSelect);
|
||||
}
|
||||
|
||||
function sendVboxReclaim(i) {
|
||||
@@ -45,7 +45,6 @@ const addState = connect(
|
||||
}
|
||||
|
||||
return {
|
||||
combiner,
|
||||
instance,
|
||||
player,
|
||||
reclaiming,
|
||||
@@ -62,11 +61,9 @@ const addState = connect(
|
||||
},
|
||||
|
||||
function receiveDispatch(dispatch) {
|
||||
function setCombiner(c) {
|
||||
return dispatch(actions.setCombiner(c));
|
||||
}
|
||||
|
||||
function setReclaiming(v) {
|
||||
dispatch(actions.setItemUnequip([]));
|
||||
dispatch(actions.setVboxSelected({ shopSelect: [], stashSelect: [] }));
|
||||
return dispatch(actions.setReclaiming(v));
|
||||
}
|
||||
|
||||
@@ -75,28 +72,52 @@ const addState = connect(
|
||||
}
|
||||
|
||||
function setVboxSelected(v) {
|
||||
dispatch(actions.setItemUnequip([]));
|
||||
dispatch(actions.setVboxSelected(v));
|
||||
return dispatch(actions.setVboxSelected(v));
|
||||
}
|
||||
|
||||
function setItemEquip(v) {
|
||||
return dispatch(actions.setItemEquip(v));
|
||||
}
|
||||
|
||||
return {
|
||||
setCombiner,
|
||||
setReclaiming,
|
||||
setInfo,
|
||||
setVboxSelected,
|
||||
setItemEquip,
|
||||
};
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
function validVboxSelect(vbox, itemInfo, shopSelect, stashSelect) {
|
||||
if (shopSelect.length === 0 && stashSelect.length === 0) return false;
|
||||
|
||||
const validSelects = [];
|
||||
|
||||
const stashItems = stashSelect.map(j => vbox.bound[j]);
|
||||
const shopItems = shopSelect.map(j => vbox.free[j[0]][j[1]]);
|
||||
|
||||
const selectedItems = stashItems.concat(shopItems);
|
||||
const itemCount = countBy(selectedItems, co => co);
|
||||
|
||||
itemInfo.combos.forEach(combo => {
|
||||
const comboCount = countBy(combo.components, co => co);
|
||||
const buyCount = countBy(combo.components, co => co);
|
||||
const valid = selectedItems.every(c => {
|
||||
if (!combo.components.includes(c)) return false;
|
||||
if (itemCount[c] > comboCount[c]) return false;
|
||||
buyCount[c] -= itemCount[c];
|
||||
return true;
|
||||
});
|
||||
if (valid) {
|
||||
forEach(buyCount, (value, key) => {
|
||||
if (value > 0 && !validSelects.includes(key)) validSelects.push(key);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return validSelects;
|
||||
}
|
||||
|
||||
class Vbox extends preact.Component {
|
||||
shouldComponentUpdate(newProps) {
|
||||
// Single variable props
|
||||
if (newProps.combiner !== this.props.combiner) return true;
|
||||
if (newProps.itemUnequip !== this.props.itemUnequip) return true;
|
||||
if (newProps.reclaiming !== this.props.reclaiming) return true;
|
||||
if (newProps.tutorial !== this.props.tutorial) return true;
|
||||
@@ -109,7 +130,6 @@ class Vbox extends preact.Component {
|
||||
render(args) {
|
||||
const {
|
||||
// Changing state variables
|
||||
combiner,
|
||||
itemUnequip,
|
||||
player,
|
||||
reclaiming,
|
||||
@@ -126,37 +146,29 @@ class Vbox extends preact.Component {
|
||||
sendVboxDiscard,
|
||||
sendVboxReclaim,
|
||||
setVboxSelected,
|
||||
setItemEquip,
|
||||
setInfo,
|
||||
setCombiner,
|
||||
setReclaiming,
|
||||
} = args;
|
||||
|
||||
if (!player) return false;
|
||||
const { vbox } = player;
|
||||
const vboxSelecting = vboxSelected.length;
|
||||
const { shopSelect, stashSelect } = vboxSelected;
|
||||
const vboxSelecting = shopSelect.length === 1 && stashSelect.length === 0;
|
||||
|
||||
function combinerChange(newCombiner) {
|
||||
setCombiner(newCombiner);
|
||||
|
||||
if (newCombiner.length === 1) {
|
||||
setItemEquip(newCombiner[0]);
|
||||
} else {
|
||||
setItemEquip(null);
|
||||
}
|
||||
|
||||
return true;
|
||||
function combinerChange(newStashSelect) {
|
||||
return setVboxSelected({ shopSelect, stashSelect: newStashSelect });
|
||||
}
|
||||
|
||||
const vboxHighlight = validVboxSelect(vbox, itemInfo, shopSelect, stashSelect);
|
||||
//
|
||||
// VBOX
|
||||
//
|
||||
function vboxHover(e, v) {
|
||||
if (v) {
|
||||
e.stopPropagation();
|
||||
if (vboxSelected[0]) return true; // There is a base skill or spec selected in the vbox
|
||||
if (combiner.length !== 0) {
|
||||
const base = combiner.find(c => !['Red', 'Blue', 'Green'].includes(vbox.bound[c]));
|
||||
if (shopSelect.find(c => c[0])) return true; // There is a base skill or spec selected in the vbox
|
||||
if (stashSelect.length !== 0) {
|
||||
const base = stashSelect.find(c => !['Red', 'Blue', 'Green'].includes(vbox.bound[c]));
|
||||
if (base || base === 0) return true;
|
||||
}
|
||||
setInfo(v);
|
||||
@@ -165,51 +177,36 @@ class Vbox extends preact.Component {
|
||||
}
|
||||
|
||||
function clearVboxSelected() {
|
||||
setVboxSelected([]);
|
||||
setVboxSelected({ shopSelect: [], stashSelect: [] });
|
||||
}
|
||||
|
||||
function vboxBuySelected() {
|
||||
if (!vboxSelecting) return false;
|
||||
document.activeElement.blur();
|
||||
clearVboxSelected();
|
||||
sendVboxAccept(vboxSelected[0], vboxSelected[1]);
|
||||
sendVboxAccept(shopSelect[0][0], shopSelect[0][1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
function availableBtn(v, group, index) {
|
||||
if (!v) return <button disabled class='empty' key={(group * 10) + index} > </button>;
|
||||
const selected = vboxSelected[0] === group && vboxSelected[1] === index;
|
||||
const selected = shopSelect.length && shopSelect.some(vs => vs[0] === group && vs[1] === index);
|
||||
|
||||
// state not yet set in double click handler
|
||||
function onDblClick(e) {
|
||||
clearVboxSelected();
|
||||
sendVboxAccept(group, index);
|
||||
e.stopPropagation();
|
||||
}
|
||||
const comboHighlight = vboxHighlight && vboxHighlight.includes(v) ? 'combo-border' : '';
|
||||
|
||||
function onClick(e) {
|
||||
e.stopPropagation();
|
||||
setItemEquip(null);
|
||||
setCombiner([]);
|
||||
setInfo(vbox.free[group][index]);
|
||||
if (vboxSelected[0] === group && vboxSelected[1] === index) return clearVboxSelected();
|
||||
return setVboxSelected([group, index]);
|
||||
if (!comboHighlight) setInfo(vbox.free[group][index]);
|
||||
if (shopSelect.length && shopSelect.some(vs => vs[0] === group && vs[1] === index)) {
|
||||
return setVboxSelected({ shopSelect: shopSelect.filter(vs => !(vs[0] === group && vs[1] === index)), stashSelect });
|
||||
}
|
||||
|
||||
if (!shopSelect.length && !stashSelect.length) return setVboxSelected({ shopSelect: [[group, index]], stashSelect });
|
||||
if (comboHighlight !== 'combo-border') {
|
||||
return setVboxSelected({ shopSelect: [[group, index]], stashSelect: [] });
|
||||
}
|
||||
return setVboxSelected({ shopSelect: [...shopSelect, [group, index]], stashSelect });
|
||||
}
|
||||
|
||||
const combinerItems = combiner.map(j => vbox.bound[j]);
|
||||
const combinerCount = countBy(combinerItems, co => co);
|
||||
|
||||
const comboHighlight = combinerItems.length > 0 && itemInfo.combos.some(combo => {
|
||||
if (combo.components.includes(v)) {
|
||||
return combinerItems.every(c => {
|
||||
if (!combo.components.includes(c)) return false;
|
||||
const comboCount = countBy(combo.components, co => co);
|
||||
if (combinerCount[c] > comboCount[c]) return false;
|
||||
if (c === v && combinerCount[c] + 1 > comboCount[c]) return false;
|
||||
return true;
|
||||
});
|
||||
} return false;
|
||||
}) ? 'combo-border' : '';
|
||||
|
||||
const classes = `${v.toLowerCase()} ${selected ? 'highlight' : ''} ${comboHighlight}`;
|
||||
|
||||
@@ -217,10 +214,7 @@ class Vbox extends preact.Component {
|
||||
const disabled = vbox.bits <= group;
|
||||
return (
|
||||
<label draggable='true'
|
||||
onDragStart={ev => {
|
||||
onClick(ev);
|
||||
ev.dataTransfer.setData('text', '')
|
||||
}}
|
||||
onDragStart={ev => ev.dataTransfer.setData('text', '')}
|
||||
key={group * 10 + index}
|
||||
onDragEnd={clearVboxSelected}>
|
||||
<button
|
||||
@@ -229,7 +223,6 @@ class Vbox extends preact.Component {
|
||||
onMouseOver={e => vboxHover(e, v)}
|
||||
onMouseDown={onClick}
|
||||
onClick={e => e.stopPropagation()}
|
||||
onDblClick={onDblClick}
|
||||
> {vboxObject}
|
||||
</button>
|
||||
</label>
|
||||
@@ -240,7 +233,6 @@ class Vbox extends preact.Component {
|
||||
function vboxElement() {
|
||||
return (
|
||||
<div class='vbox-vbox'
|
||||
onMouseDown={() => setReclaiming(false)}
|
||||
onClick={e => e.stopPropagation()}>
|
||||
<div class="vbox-hdr">
|
||||
<h3
|
||||
@@ -259,7 +251,9 @@ class Vbox extends preact.Component {
|
||||
<button
|
||||
class='vbox-btn'
|
||||
onMouseOver={e => hoverInfo(e, 'refill')}
|
||||
disabled={tutorial && tutorial < 7 && instance.time_control === 'Practice' && instance.rounds.length === 1}
|
||||
disabled={vbox.bits < 2
|
||||
|| (tutorial && tutorial < 7 && instance.time_control === 'Practice' && instance.rounds.length === 1)
|
||||
}
|
||||
onClick={e => e.stopPropagation()}
|
||||
onMouseDown={() => sendVboxDiscard()}>
|
||||
refill - 2b
|
||||
@@ -276,60 +270,42 @@ class Vbox extends preact.Component {
|
||||
return setReclaiming(!reclaiming);
|
||||
}
|
||||
|
||||
const inventoryClass = `vbox-section ${reclaiming ? 'reclaiming' : ''}`;
|
||||
|
||||
function inventoryBtn(v, i) {
|
||||
const inventoryHighlight = vboxSelecting || itemUnequip.length;
|
||||
|
||||
if (!v && v !== 0) {
|
||||
return <button key={i} disabled={!inventoryHighlight} class={inventoryHighlight ? 'receiving' : 'empty'} > </button>;
|
||||
const emptyInvClick = () => {
|
||||
if (vboxSelecting) return vboxBuySelected();
|
||||
return false;
|
||||
};
|
||||
return <button key={i} onClick={emptyInvClick} disabled={!inventoryHighlight} class={inventoryHighlight ? 'receiving' : 'empty'} > </button>;
|
||||
}
|
||||
|
||||
const combinerItems = combiner.map(j => vbox.bound[j]);
|
||||
const combinerCount = countBy(combinerItems, co => co);
|
||||
|
||||
const comboItem = itemInfo.combos.find(combo => {
|
||||
if (combo.components.includes(v)) {
|
||||
return combinerItems.every(c => {
|
||||
if (!combo.components.includes(c)) return false;
|
||||
const comboCount = countBy(combo.components, co => co);
|
||||
if (combinerCount[c] > comboCount[c]) return false;
|
||||
if (c === v && combinerCount[c] + 1 > comboCount[c]) return false;
|
||||
return true;
|
||||
});
|
||||
} return false;
|
||||
});
|
||||
const comboHighlight = combinerItems.length > 0 && comboItem ? 'combo-border' : '';
|
||||
const comboHighlight = vboxHighlight && vboxHighlight.includes(v) ? 'combo-border' : '';
|
||||
|
||||
function onClick(type) {
|
||||
if (vboxSelecting) clearVboxSelected();
|
||||
if (reclaiming) return sendVboxReclaim(i);
|
||||
|
||||
const combinerContainsIndex = combiner.indexOf(i) > -1;
|
||||
// 4 things selected
|
||||
if (combiner.length > 2 && !combinerContainsIndex) {
|
||||
setInfo(vbox.bound[i]);
|
||||
return combinerChange([i]);
|
||||
}
|
||||
const combinerContainsIndex = stashSelect.indexOf(i) > -1;
|
||||
// removing
|
||||
if (combinerContainsIndex) {
|
||||
if (type === 'click') {
|
||||
return combinerChange(without(combiner, i));
|
||||
return combinerChange(without(stashSelect, i));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!comboHighlight && !combinerContainsIndex) {
|
||||
if (!comboHighlight) {
|
||||
setInfo(vbox.bound[i]);
|
||||
return combinerChange([i]);
|
||||
return setVboxSelected({ shopSelect: [], stashSelect: [i] });
|
||||
}
|
||||
|
||||
combiner.push(i);
|
||||
if (combiner.length === 3) setInfo(comboItem.item);
|
||||
return combinerChange(combiner);
|
||||
stashSelect.push(i);
|
||||
// if (stashSelect.length === 3) setInfo(comboItem.item);
|
||||
return combinerChange(stashSelect);
|
||||
}
|
||||
|
||||
const highlighted = combiner.indexOf(i) > -1;
|
||||
const highlighted = stashSelect.indexOf(i) > -1;
|
||||
const border = buttons[removeTier(v)] ? buttons[removeTier(v)]() : '';
|
||||
const classes = `${highlighted ? 'highlight' : border} ${comboHighlight}`;
|
||||
|
||||
@@ -356,37 +332,49 @@ class Vbox extends preact.Component {
|
||||
|
||||
function combinerBtn() {
|
||||
let text = '';
|
||||
let comboItem = '';
|
||||
if (combiner.length < 3) {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (combiner.length > i) {
|
||||
text += '■ ';
|
||||
} else {
|
||||
text += '▫ ';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Since theres 3 items in combiner and you can't have invalid combos we can preview it
|
||||
const combinerItems = combiner.map(j => vbox.bound[j]);
|
||||
const combinerCount = countBy(combinerItems, co => co);
|
||||
const comboItemObj = itemInfo.combos.find(combo => combinerItems.every(c => {
|
||||
let mouseEvent = false;
|
||||
const combineLength = stashSelect.length + shopSelect.length;
|
||||
if (vboxHighlight && vboxHighlight.length === 0) {
|
||||
// The selected items can't be combined with additional items therefore valid combo
|
||||
const stashItems = stashSelect.map(j => vbox.bound[j]);
|
||||
const shopItems = shopSelect.map(j => vbox.free[j[0]][j[1]]);
|
||||
const selectedItems = stashItems.concat(shopItems);
|
||||
const combinerCount = countBy(selectedItems, co => co);
|
||||
|
||||
const comboItemObj = itemInfo.combos.find(combo => selectedItems.every(c => {
|
||||
if (!combo.components.includes(c)) return false;
|
||||
const comboCount = countBy(combo.components, co => co);
|
||||
if (combinerCount[c] > comboCount[c]) return false;
|
||||
return true;
|
||||
}));
|
||||
comboItem = comboItemObj ? comboItemObj.item : 'refine';
|
||||
let comboItem = comboItemObj ? comboItemObj.item : 'refine';
|
||||
setInfo(comboItem);
|
||||
comboItem = comboItem.replace('Plus', '+');
|
||||
text = `Combine - ${comboItem}`;
|
||||
let bits = 0;
|
||||
shopSelect.forEach(item => bits += item[0] + 1);
|
||||
text = bits
|
||||
? `Buy ${comboItem} - ${bits}b`
|
||||
: `Combine - ${comboItem}`;
|
||||
if (vbox.bits >= bits) mouseEvent = sendVboxCombine;
|
||||
} else if (stashSelect.length === 0 && shopSelect.length === 1) {
|
||||
const item = shopSelect[0];
|
||||
text = `Buy ${vbox.free[item[0]][item[1]]} ${item[0] + 1}b`;
|
||||
mouseEvent = vboxBuySelected;
|
||||
} else {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (combineLength > i) {
|
||||
text += '■ ';
|
||||
} else {
|
||||
text += '▫ ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
class='vbox-btn'
|
||||
disabled={combiner.length !== 3}
|
||||
onMouseOver={e => hoverInfo(e, comboItem)}
|
||||
disabled={!mouseEvent}
|
||||
onClick={e => e.stopPropagation()}
|
||||
onMouseDown={() => sendVboxCombine()}>
|
||||
onMouseDown={() => mouseEvent()}>
|
||||
{text}
|
||||
</button>
|
||||
);
|
||||
@@ -395,21 +383,18 @@ class Vbox extends preact.Component {
|
||||
function inventoryElement() {
|
||||
function inventoryClick(e) {
|
||||
e.stopPropagation();
|
||||
setReclaiming(false);
|
||||
if (vboxSelecting) return vboxBuySelected();
|
||||
if (itemUnequip.length) return sendItemUnequip(itemUnequip);
|
||||
return true;
|
||||
}
|
||||
|
||||
return (
|
||||
<div class={inventoryClass}
|
||||
<div
|
||||
onMouseDown={inventoryClick}
|
||||
onClick={e => e.stopPropagation()}
|
||||
style={vboxSelecting || (itemUnequip.length) ? { cursor: 'pointer' } : null}
|
||||
onDragOver={ev => ev.preventDefault()}
|
||||
onDrop={inventoryClick}
|
||||
>
|
||||
<div class="vbox-hdr">
|
||||
<div class={`vbox-hdr ${reclaiming ? 'reclaiming' : ''}`}>
|
||||
<h3
|
||||
onTouchStart={e => e.target.scrollIntoView(true)}
|
||||
onMouseOver={e => hoverInfo(e, 'inventory')}> INVENTORY
|
||||
@@ -423,7 +408,8 @@ class Vbox extends preact.Component {
|
||||
reclaim
|
||||
</button>
|
||||
</div>
|
||||
<div class='vbox-items'>
|
||||
|
||||
<div class={`vbox-items ${reclaiming ? 'reclaiming' : ''}`}>
|
||||
{range(0, 9).map(i => inventoryBtn(vbox.bound[i], i))}
|
||||
</div>
|
||||
{combinerBtn()}
|
||||
@@ -435,11 +421,9 @@ class Vbox extends preact.Component {
|
||||
// EVERYTHING
|
||||
//
|
||||
function hoverInfo(e, newInfo) {
|
||||
e.stopPropagation();
|
||||
|
||||
if (vboxSelected[0]) return true;
|
||||
if (combiner.length !== 0) {
|
||||
const base = combiner.find(c => !['Red', 'Blue', 'Green'].includes(vbox.bound[c]));
|
||||
if (shopSelect.find(c => c[0])) return true;
|
||||
if (stashSelect.length !== 0) {
|
||||
const base = stashSelect.find(c => !['Red', 'Blue', 'Green'].includes(vbox.bound[c]));
|
||||
if (base || base === 0) return true;
|
||||
}
|
||||
return setInfo(newInfo);
|
||||
|
||||
Reference in New Issue
Block a user