- {convertItem(c.item)}
+ const vboxCombos = itemInfo.combos.filter(c => c.components.includes(vboxInfo || info));
+ if (vboxCombos.length > 6 || vboxCombos.length === 0) return
;
+
+ const comboTable = vboxCombos.map((c, i) => {
+ const mouseOver = e => {
+ e.stopPropagation();
+ // this.setState({ comboItem: c.item });
+ // set comboInfo state here
+ };
+ const componentTable = (c.components.some(ci => ['Red', 'Blue', 'Green'].includes(ci)))
+ ? [
{convertItem(c.components[0])} {convertItem(c.components[1])}
,
+
{convertItem(c.components[2])}
]
+ : c.components.map((u, j) =>
{convertItem(u)}
);
+ return (
+
+ );
+ });
+ return (
+
+
+
e.stopPropagation()}>
+ {comboTable}
- {componentTable}
);
- });
- return (
-
-
-
e.stopPropagation()}>
- {comboTable}
-
-
- );
+ }
}
-module.exports = Combos;
+module.exports = addState(Combos);
diff --git a/client/src/components/vbox.component.jsx b/client/src/components/vbox.component.jsx
index 8db81e37..7cd5c0dc 100644
--- a/client/src/components/vbox.component.jsx
+++ b/client/src/components/vbox.component.jsx
@@ -4,8 +4,8 @@ const { connect } = require('preact-redux');
const actions = require('../actions');
const InfoContainer = require('./vbox.info');
-const { StashHdr, StashElement } = require('./vbox.stash');
-const { StoreHdr, StoreElement } = require('./vbox.store');
+const StashElement = require('./vbox.stash');
+const StoreElement = require('./vbox.store');
const Combiner = require('./vbox.combiner');
const Combos = require('./vbox.combos');
@@ -96,13 +96,11 @@ const addState = connect(
class Vbox extends preact.Component {
shouldComponentUpdate(newProps) {
- // Single variable props
if (newProps.itemUnequip !== this.props.itemUnequip) return true;
+ if (newProps.instance !== this.props.instance) return true;
+ if (newProps.player !== this.props.player) return true;
if (newProps.tutorial !== this.props.tutorial) return true;
if (newProps.vboxSelected !== this.props.vboxSelected) return true;
- if (newProps.vboxHighlight !== this.props.vboxHighlight) return true;
- if (newProps.player !== this.props.player) return true;
- if (newProps.instance !== this.props.instance) return true;
return false;
}
@@ -110,13 +108,9 @@ class Vbox extends preact.Component {
const {
// Changing state variables
itemUnequip,
- info,
instance,
player,
tutorial,
- vboxCombiner,
- vboxHighlight,
- vboxInfo,
vboxSelected,
// Static
itemInfo,
@@ -148,72 +142,94 @@ class Vbox extends preact.Component {
return true;
}
+ function storeHdr() {
+ return (
+
+
e.target.scrollIntoView(true)}
+ onMouseOver={e => vboxHover(e, 'store')}> STORE
+
+ vboxHover(e, 'bits')}>
+ {vbox.bits}b
+
+ vboxHover(e, 'refill')}
+ disabled={vbox.bits < 2
+ || (tutorial && tutorial < 7
+ && instance.time_control === 'Practice' && instance.rounds.length === 1)
+ }
+ onClick={e => e.stopPropagation()}
+ onMouseDown={() => sendVboxDiscard()}>
+ refill
+ 2b
+
+
+ );
+ }
+
+ function stashHdr() {
+ const refund = storeSelect.length === 0 && stashSelect.length === 1
+ ? itemInfo.items.find(i => i.item === vbox.bound[stashSelect[0]]).cost
+ : 0;
+ const tutorialDisabled = tutorial && tutorial < 8
+ && instance.time_control === 'Practice' && instance.rounds.length === 1;
+ const refundBtn = (
+
e.stopPropagation()}
+ onMouseDown={e => {
+ e.stopPropagation();
+ sendVboxReclaim(vboxSelected.stashSelect[0]);
+ }}>
+ refund
+ {refund}b
+
+ );
+
+ return (
+
+
e.target.scrollIntoView(true)}
+ onMouseOver={e => vboxHover(e, 'stash')}> STASH
+
+ {refundBtn}
+
+ );
+ }
+
// EVERYTHING
return (
-
+ {storeHdr()}
+ {stashHdr()}
-
-
+
);
}
diff --git a/client/src/components/vbox.info.jsx b/client/src/components/vbox.info.jsx
index dac8e2e2..e71d75a0 100644
--- a/client/src/components/vbox.info.jsx
+++ b/client/src/components/vbox.info.jsx
@@ -1,55 +1,74 @@
const preact = require('preact');
+const { connect } = require('preact-redux');
+
const { tutorialStage } = require('../tutorial.utils');
const { genItemInfo } = require('./vbox.utils');
-function Info(props) {
- const {
- // Variables that will change
- info,
- player,
- tutorial,
- vboxInfo,
- // Static
- clearTutorial,
- itemInfo,
- instance,
- } = props;
+const addState = connect(
+ ({ info, player, tutorial, vboxInfo, itemInfo, instance }) => ({
+ info, player, tutorial, vboxInfo, itemInfo, instance,
+ }));
- if (tutorial) {
- const tutorialStageInfo = tutorialStage(tutorial, clearTutorial, instance);
- if (tutorialStageInfo) return tutorialStageInfo;
+
+class Info extends preact.Component {
+ shouldComponentUpdate(newProps) {
+ if (newProps.clearTutorial !== this.props.clearTutorial) return true;
+ if (newProps.info !== this.props.info) return true;
+ if (newProps.player !== this.props.player) return true;
+ if (newProps.tutorial !== this.props.tutorial) return true;
+ if (newProps.vboxInfo !== this.props.vboxInfo) return true;
+ if (newProps.itemInfo !== this.props.itemInfo) return true;
+ if (newProps.instance !== this.props.instance) return true;
+ return false;
}
- // Prioritise the vbox info
- if (vboxInfo) return genItemInfo(vboxInfo, itemInfo, player, info);
+ render(props) {
+ const {
+ clearTutorial,
+ info,
+ player,
+ tutorial,
+ vboxInfo,
+ itemInfo,
+ instance,
+ } = props;
- // check normal info state
- if (!info) return false;
- if (info.includes('constructName')) {
- return (
-
-
{info.replace('constructName ', '')}
-
This is the name of your construct.
- Names are randomly generated and are purely cosmetic.
- You can change change your construct name in the RESHAPE tab outside of games.
-
-
- );
+ if (tutorial) {
+ const tutorialStageInfo = tutorialStage(tutorial, clearTutorial, instance);
+ if (tutorialStageInfo) return tutorialStageInfo;
+ }
+
+ // Prioritise the vbox info
+ if (vboxInfo) return genItemInfo(vboxInfo, itemInfo, player, info);
+
+ // check normal info state
+ if (!info) return false;
+ if (info.includes('constructName')) {
+ return (
+
+
{info.replace('constructName ', '')}
+
This is the name of your construct.
+ Names are randomly generated and are purely cosmetic.
+ You can change change your construct name in the RESHAPE tab outside of games.
+
+
+ );
+ }
+
+ if (info.includes('constructAvatar')) {
+ return (
+
+
{info.replace('constructAvatar ', '')}
+
This is your construct avatar.
+ Avatars are randomly generated and are purely cosmetic.
+ You can change your construct avatar in the RESHAPE tab outside of games.
+
+
+ );
+ }
+
+ return genItemInfo(info, itemInfo, player, info);
}
-
- if (info.includes('constructAvatar')) {
- return (
-
-
{info.replace('constructAvatar ', '')}
-
This is your construct avatar.
- Avatars are randomly generated and are purely cosmetic.
- You can change your construct avatar in the RESHAPE tab outside of games.
-
-
- );
- }
-
- return genItemInfo(info, itemInfo, player, info);
}
-module.exports = Info;
+module.exports = addState(Info);
diff --git a/client/src/components/vbox.stash.jsx b/client/src/components/vbox.stash.jsx
index 243f890b..eab47d50 100644
--- a/client/src/components/vbox.stash.jsx
+++ b/client/src/components/vbox.stash.jsx
@@ -1,4 +1,6 @@
const preact = require('preact');
+const { connect } = require('preact-redux');
+
const range = require('lodash/range');
const without = require('lodash/without');
@@ -6,143 +8,124 @@ const shapes = require('./shapes');
const buttons = require('./buttons');
const { removeTier } = require('../utils');
-function stashHdr(props) {
- const {
- instance,
- itemInfo,
- sendVboxReclaim,
- tutorial,
- vbox,
- vboxHover,
- vboxSelected,
- } = props;
- const { storeSelect, stashSelect } = vboxSelected;
- const refund = storeSelect.length === 0 && stashSelect.length === 1
- ? itemInfo.items.find(i => i.item === vbox.bound[stashSelect[0]]).cost
- : 0;
- const tutorialDisabled = tutorial && tutorial < 8
- && instance.time_control === 'Practice' && instance.rounds.length === 1;
- const refundBtn = (
-
e.stopPropagation()}
- onMouseDown={e => {
- e.stopPropagation();
- sendVboxReclaim(vboxSelected.stashSelect[0]);
- }}>
- refund
- {refund}b
-
- );
+const addState = connect(
+ ({ itemUnequip, vboxHighlight, vboxSelected }) => ({ itemUnequip, vboxHighlight, vboxSelected }));
- return (
-
-
e.target.scrollIntoView(true)}
- onMouseOver={e => vboxHover(e, 'stash')}> STASH
-
- {refundBtn}
-
- );
-}
+class stashElement extends preact.Component {
+ shouldComponentUpdate(newProps) {
+ if (newProps.sendItemUnequip !== this.props.sendItemUnequip) return true;
+ if (newProps.setInfo !== this.props.setInfo) return true;
+ if (newProps.setVboxSelected !== this.props.setVboxSelected) return true;
+ if (newProps.vbox !== this.props.vbox) return true;
+ if (newProps.vboxBuySelected !== this.props.vboxBuySelected) return true;
+ if (newProps.vboxHover !== this.props.vboxHover) return true;
-function stashElement(props) {
- const {
- itemUnequip,
- sendItemUnequip,
- setInfo,
- setVboxSelected,
- stashSelect,
- storeSelect,
- vbox,
- vboxBuySelected,
- vboxHighlight,
- vboxHover,
- } = props;
-
- const vboxSelecting = storeSelect.length === 1 && stashSelect.length === 0;
-
- function stashClick(e) {
- e.stopPropagation();
- if (itemUnequip.length) return sendItemUnequip(itemUnequip);
- if (vboxSelecting) return vboxBuySelected();
- return true;
+ if (newProps.itemUnequip !== this.props.itemUnequip) return true;
+ if (newProps.vboxHighlight !== this.props.vboxHighlight) return true;
+ if (newProps.vboxSelected !== this.props.vboxSelected) return true;
+ return false;
}
- function stashBtn(v, i) {
- const stashHighlight = vboxSelecting || itemUnequip.length;
+ render(props) {
+ const {
+ sendItemUnequip,
+ setInfo,
+ setVboxSelected,
+ vbox,
+ vboxBuySelected,
+ vboxHover,
- if (!v && v !== 0) {
- const emptyInvClick = () => {
- if (vboxSelecting) return vboxBuySelected();
- return false;
- };
- return
;
- }
+ itemUnequip,
+ vboxHighlight,
+ vboxSelected,
+ } = props;
- const notValidCombo = vboxHighlight && !vboxHighlight.includes(v);
+ const { storeSelect, stashSelect } = vboxSelected;
- function onClick(type, e) {
+ const vboxSelecting = storeSelect.length === 1 && stashSelect.length === 0;
+
+ function stashClick(e) {
e.stopPropagation();
- const combinerContainsIndex = stashSelect.indexOf(i) > -1;
- // removing
- if (combinerContainsIndex) {
- if (type === 'click') {
- return setVboxSelected({ storeSelect, stashSelect: without(stashSelect, i) });
- }
- return true;
- }
-
- if (notValidCombo) {
- setInfo(vbox.bound[i]);
- return setVboxSelected({ storeSelect: [], stashSelect: [i] });
- }
-
- return setVboxSelected({ storeSelect, stashSelect: [...stashSelect, i] });
+ if (itemUnequip.length) return sendItemUnequip(itemUnequip);
+ if (vboxSelecting) return vboxBuySelected();
+ return true;
}
- const highlighted = stashSelect.indexOf(i) > -1;
- const border = buttons[removeTier(v)] ? buttons[removeTier(v)]() : '';
- const classes = highlighted
- ? 'highlight'
- : `${border} ${notValidCombo ? 'fade' : ''}`;
+ function stashBtn(v, i) {
+ const stashHighlight = vboxSelecting || itemUnequip.length;
- const invObject = shapes[v] ? shapes[v]() : v;
+ if (!v && v !== 0) {
+ const emptyInvClick = () => {
+ if (vboxSelecting) return vboxBuySelected();
+ return false;
+ };
+ return
;
+ }
+
+ const notValidCombo = vboxHighlight && !vboxHighlight.includes(v);
+
+ function onClick(type, e) {
+ e.stopPropagation();
+ const combinerContainsIndex = stashSelect.indexOf(i) > -1;
+ // removing
+ if (combinerContainsIndex) {
+ if (type === 'click') {
+ return setVboxSelected({ storeSelect, stashSelect: without(stashSelect, i) });
+ }
+ return true;
+ }
+
+ if (notValidCombo) {
+ setInfo(vbox.bound[i]);
+ return setVboxSelected({ storeSelect: [], stashSelect: [i] });
+ }
+
+ return setVboxSelected({ storeSelect, stashSelect: [...stashSelect, i] });
+ }
+
+ const highlighted = stashSelect.indexOf(i) > -1;
+ const border = buttons[removeTier(v)] ? buttons[removeTier(v)]() : '';
+ const classes = highlighted
+ ? 'highlight'
+ : `${border} ${notValidCombo ? 'fade' : ''}`;
+
+ const invObject = shapes[v] ? shapes[v]() : v;
+
+ return (
+
{
+ onClick('drag', ev);
+ ev.dataTransfer.setData('text', '');
+ }}>
+ vboxHover(e, v)}
+ onClick={e => e.stopPropagation()}
+ onMouseDown={e => onClick('click', e)}>
+ {invObject}
+
+
+ );
+ }
return (
-
{
- onClick('drag', ev);
- ev.dataTransfer.setData('text', '');
- }}>
- vboxHover(e, v)}
- onClick={e => e.stopPropagation()}
- onMouseDown={e => onClick('click', e)}>
- {invObject}
-
-
+
e.stopPropagation()}
+ onDragOver={ev => ev.preventDefault()}
+ onDrop={stashClick}
+ >
+ {range(0, 6).map(i => stashBtn(vbox.bound[i], i))}
+
);
}
-
- return (
-
e.stopPropagation()}
- onDragOver={ev => ev.preventDefault()}
- onDrop={stashClick}
- >
- {range(0, 6).map(i => stashBtn(vbox.bound[i], i))}
-
- );
}
-module.exports = { stashHdr, stashElement };
+module.exports = addState(stashElement);
diff --git a/client/src/components/vbox.store.jsx b/client/src/components/vbox.store.jsx
index 50c2e337..25ea4904 100644
--- a/client/src/components/vbox.store.jsx
+++ b/client/src/components/vbox.store.jsx
@@ -1,112 +1,95 @@
const preact = require('preact');
+const { connect } = require('preact-redux');
const range = require('lodash/range');
const shapes = require('./shapes');
-function storeHdr(props) {
- const {
- instance,
- tutorial,
- sendVboxDiscard,
- vbox,
- vboxHover,
- } = props;
+const addState = connect(({ vboxHighlight }) => ({ vboxHighlight }));
- return (
-
-
e.target.scrollIntoView(true)}
- onMouseOver={e => vboxHover(e, 'store')}> STORE
-
- vboxHover(e, 'bits')}>
- {vbox.bits}b
-
- vboxHover(e, 'refill')}
- disabled={vbox.bits < 2
- || (tutorial && tutorial < 7
- && instance.time_control === 'Practice' && instance.rounds.length === 1)
- }
- onClick={e => e.stopPropagation()}
- onMouseDown={() => sendVboxDiscard()}>
- refill
- 2b
-
-
- );
-}
-
-
-function storeElement(props) {
- const {
- clearVboxSelected,
- setVboxSelected,
- storeSelect,
- stashSelect,
- vbox,
- vboxHighlight,
- vboxHover,
- } = props;
-
- function availableBtn(v, group, index) {
- if (!v) return
;
- const selected = storeSelect.length && storeSelect.some(vs => vs[0] === group && vs[1] === index);
-
- const notValidCombo = vboxHighlight && !vboxHighlight.includes(v);
-
- function onClick(e) {
- e.stopPropagation();
- if (storeSelect.length && storeSelect.some(vs => vs[0] === group && vs[1] === index)) {
- return setVboxSelected(
- { storeSelect: storeSelect.filter(vs => !(vs[0] === group && vs[1] === index)), stashSelect }
- );
- }
-
- if (!storeSelect.length && !stashSelect.length) {
- return setVboxSelected({ storeSelect: [[group, index]], stashSelect });
- }
- if (notValidCombo) {
- return setVboxSelected({ storeSelect: [[group, index]], stashSelect: [] });
- }
- return setVboxSelected({ storeSelect: [...storeSelect, [group, index]], stashSelect });
- }
-
-
- const classes = selected
- ? `${v.toLowerCase()} highlight`
- : `${v.toLowerCase()} ${notValidCombo ? 'fade' : ''}`;
-
- const vboxObject = shapes[v] ? shapes[v]() : v;
- const disabled = vbox.bits <= group;
- return (
-
- vboxHover(e, v)}
- onMouseDown={onClick}
- onClick={e => e.stopPropagation()}
- > {vboxObject}
-
-
- );
+class storeElement extends preact.Component {
+ shouldComponentUpdate(newProps) {
+ if (newProps.clearVboxSelected !== this.props.clearVboxSelected) return true;
+ if (newProps.setVboxSelected !== this.props.setVboxSelected) return true;
+ if (newProps.vbox !== this.props.vbox) return true;
+ if (newProps.vboxHighlight !== this.props.vboxHighlight) return true;
+ if (newProps.vboxHover !== this.props.vboxHover) return true;
+ if (newProps.vboxSelected !== this.props.vboxSelected) return true;
+ return false;
}
- return (
-
e.stopPropagation()}>
-
- {range(0, 6).map(i => availableBtn(vbox.free[0][i], 0, i))}
+ render(props) {
+ const {
+ // passed
+ clearVboxSelected,
+ setVboxSelected,
+ vbox,
+ vboxHover,
+ vboxSelected,
+ // state
+ vboxHighlight,
+ } = props;
+
+ const { storeSelect, stashSelect } = vboxSelected;
+
+ function availableBtn(v, group, index) {
+ if (!v) return
;
+ const selected = storeSelect.length && storeSelect.some(vs => vs[0] === group && vs[1] === index);
+
+ const notValidCombo = vboxHighlight && !vboxHighlight.includes(v);
+
+ function onClick(e) {
+ e.stopPropagation();
+ if (storeSelect.length && storeSelect.some(vs => vs[0] === group && vs[1] === index)) {
+ return setVboxSelected(
+ { storeSelect: storeSelect.filter(vs => !(vs[0] === group && vs[1] === index)), stashSelect }
+ );
+ }
+
+ if (!storeSelect.length && !stashSelect.length) {
+ return setVboxSelected({ storeSelect: [[group, index]], stashSelect });
+ }
+ if (notValidCombo) {
+ return setVboxSelected({ storeSelect: [[group, index]], stashSelect: [] });
+ }
+ return setVboxSelected({ storeSelect: [...storeSelect, [group, index]], stashSelect });
+ }
+
+
+ const classes = selected
+ ? `${v.toLowerCase()} highlight`
+ : `${v.toLowerCase()} ${notValidCombo ? 'fade' : ''}`;
+
+ const vboxObject = shapes[v] ? shapes[v]() : v;
+ const disabled = vbox.bits <= group;
+ return (
+
+ vboxHover(e, v)}
+ onMouseDown={onClick}
+ onClick={e => e.stopPropagation()}
+ > {vboxObject}
+
+
+ );
+ }
+
+ return (
+
e.stopPropagation()}>
+
+ {range(0, 6).map(i => availableBtn(vbox.free[0][i], 0, i))}
+
+
+ {range(0, 3).map(i => availableBtn(vbox.free[1][i], 1, i))}
+ {range(0, 3).map(i => availableBtn(vbox.free[2][i], 2, i))}
+
-
- {range(0, 3).map(i => availableBtn(vbox.free[1][i], 1, i))}
- {range(0, 3).map(i => availableBtn(vbox.free[2][i], 2, i))}
-
-
- );
+ );
+ }
}
-module.exports = { storeHdr, storeElement };
+module.exports = addState(storeElement);