diff --git a/client/src/components/vbox.combos.jsx b/client/src/components/vbox.combos.jsx index f3831a57..01c959d2 100644 --- a/client/src/components/vbox.combos.jsx +++ b/client/src/components/vbox.combos.jsx @@ -1,66 +1,51 @@ const preact = require('preact'); -const { connect } = require('preact-redux'); const { convertItem } = require('../utils'); -const addState = connect(({ info, itemInfo, instance, tutorial, vboxInfo }) => - ({ info, itemInfo, instance, tutorial, vboxInfo })); +function Combos(props) { + const { + info, + instance, + itemInfo, + tutorial, + vboxInfo, + } = props; + if (tutorial && instance.time_control === 'Practice' && instance.rounds.length === 1) return false; -class Combos extends preact.Component { - shouldComponentUpdate(newProps) { - if (newProps.info !== this.props.info) return true; - if (newProps.tutorial !== this.props.tutorial) return true; - if (newProps.vboxInfo !== this.props.vboxInfo) return true; - return false; - } + const vboxCombos = itemInfo.combos.filter(c => c.components.includes(vboxInfo || info)); + if (vboxCombos.length > 6 || vboxCombos.length === 0) return
; - render(props) { - const { - // Variables that will change - info, - tutorial, - vboxInfo, - // Static - itemInfo, - instance, // Only used for tutorial check - } = props; - - if (tutorial && instance.time_control === 'Practice' && instance.rounds.length === 1) return false; - - 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 }); - }; - 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 ( -
-
- {convertItem(c.item)} -
- {componentTable} -
- ); - }); + 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 ( -
-
-

COMBOS

- Combine colours and items. -
-
- {comboTable} +
+
+ {convertItem(c.item)}
+ {componentTable}
); - } + }); + return ( +
+
+

COMBOS

+ Combine colours and items. +
+
e.stopPropagation()}> + {comboTable} +
+
+ ); } -module.exports = addState(Combos); +module.exports = Combos; diff --git a/client/src/components/vbox.component.jsx b/client/src/components/vbox.component.jsx index 017398ee..8db81e37 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 StashElement = require('./vbox.stash'); -const StoreElement = require('./vbox.store'); +const { StashHdr, StashElement } = require('./vbox.stash'); +const { StoreHdr, StoreElement } = require('./vbox.store'); const Combiner = require('./vbox.combiner'); const Combos = require('./vbox.combos'); @@ -28,6 +28,10 @@ const addState = connect( vboxSelected, } = state; + function clearTutorial() { + return ws.clearTutorial(instance.id); + } + function sendVboxDiscard() { return ws.sendVboxDiscard(instance.id); } @@ -64,6 +68,7 @@ const addState = connect( vboxInfo, vboxSelected, + clearTutorial, sendVboxAccept, sendVboxCombine, sendVboxDiscard, @@ -105,15 +110,18 @@ class Vbox extends preact.Component { const { // Changing state variables itemUnequip, + info, + instance, player, tutorial, - instance, vboxCombiner, vboxHighlight, + vboxInfo, vboxSelected, // Static itemInfo, // Function Calls + clearTutorial, dispatchVboxSelect, sendItemUnequip, sendVboxAccept, @@ -140,67 +148,16 @@ 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 -

- -
- ); - } - - 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 = ( - - ); - - 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 26f0a975..dac8e2e2 100644 --- a/client/src/components/vbox.info.jsx +++ b/client/src/components/vbox.info.jsx @@ -1,70 +1,55 @@ const preact = require('preact'); -const { connect } = require('preact-redux'); const { tutorialStage } = require('../tutorial.utils'); const { genItemInfo } = require('./vbox.utils'); -const addState = connect(({ info, player, tutorial, vboxInfo, ws, itemInfo, instance }) => - ({ info, player, tutorial, vboxInfo, ws, itemInfo, instance })); +function Info(props) { + const { + // Variables that will change + info, + player, + tutorial, + vboxInfo, + // Static + clearTutorial, + itemInfo, + instance, + } = props; -class Info extends preact.Component { - shouldComponentUpdate(newProps) { - // Single variable props - 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; - return false; + if (tutorial) { + const tutorialStageInfo = tutorialStage(tutorial, clearTutorial, instance); + if (tutorialStageInfo) return tutorialStageInfo; } - render(props) { - const { - // Variables that will change - info, - player, - tutorial, - vboxInfo, - // Static - ws, - itemInfo, - instance, - } = props; + // Prioritise the vbox info + if (vboxInfo) return genItemInfo(vboxInfo, itemInfo, player, info); - if (tutorial) { - const tutorialStageInfo = tutorialStage(tutorial, ws, 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); + // 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); } -module.exports = addState(Info); +module.exports = Info; diff --git a/client/src/components/vbox.stash.jsx b/client/src/components/vbox.stash.jsx index 264a9f60..243f890b 100644 --- a/client/src/components/vbox.stash.jsx +++ b/client/src/components/vbox.stash.jsx @@ -6,6 +6,46 @@ 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 = ( + + ); + + return ( +
+

e.target.scrollIntoView(true)} + onMouseOver={e => vboxHover(e, 'stash')}> STASH +

+ {refundBtn} +
+ ); +} + function stashElement(props) { const { itemUnequip, @@ -105,4 +145,4 @@ function stashElement(props) { ); } -module.exports = stashElement; +module.exports = { stashHdr, stashElement }; diff --git a/client/src/components/vbox.store.jsx b/client/src/components/vbox.store.jsx index 4dfda70a..50c2e337 100644 --- a/client/src/components/vbox.store.jsx +++ b/client/src/components/vbox.store.jsx @@ -3,6 +3,40 @@ const range = require('lodash/range'); const shapes = require('./shapes'); +function storeHdr(props) { + const { + instance, + tutorial, + sendVboxDiscard, + vbox, + vboxHover, + } = props; + + return ( +
+

e.target.scrollIntoView(true)} + onMouseOver={e => vboxHover(e, 'store')}> STORE +

+

vboxHover(e, 'bits')}> + {vbox.bits}b +

+ +
+ ); +} + function storeElement(props) { const { @@ -75,4 +109,4 @@ function storeElement(props) { ); } -module.exports = storeElement; +module.exports = { storeHdr, storeElement }; diff --git a/client/src/tutorial.utils.jsx b/client/src/tutorial.utils.jsx index 2e311ead..05fedee5 100644 --- a/client/src/tutorial.utils.jsx +++ b/client/src/tutorial.utils.jsx @@ -97,10 +97,10 @@ function tutorialVbox(player, store, tutorial) { store.dispatch(actions.setTutorial(stage)); } -function tutorialStage(tutorial, ws, instance) { +function tutorialStage(tutorial, clearTutorial, instance) { if (!(instance.time_control === 'Practice' && instance.rounds.length === 1)) return false; - const exit = () => ws.clearTutorial(instance.id); + const exit = () => clearTutorial(); const tutorialText = () => { if (tutorial === 1) {