const preact = require('preact'); 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 Combiner = require('./vbox.combiner'); const Combos = require('./vbox.combos'); const { setVboxState } = require('./vbox.utils'); const addState = connect( function receiveState(state) { const { ws, itemUnequip, instance, player, tutorial, vboxSelected, itemInfo, } = state; function sendInstance() { return ws.sendInstanceState(instance.id); } function sendVboxRefill() { return ws.sendVboxRefill(instance.id); } function sendVboxBuy(group, index) { if (!(vboxSelected.storeSelect.length === 1 && vboxSelected.stashSelect.length === 0)) return false; document.activeElement.blur(); return ws.sendVboxBuy(instance.id, group, index); } function sendVboxCombine() { return ws.sendVboxCombine(instance.id, vboxSelected.stashSelect, vboxSelected.storeSelect); } function sendVboxRefund(i) { return ws.sendVboxRefund(instance.id, i); } function sendItemUnequip([constructId, item]) { return ws.sendVboxUnequip(instance.id, constructId, item); } return { itemUnequip, instance, player, tutorial, vboxSelected, itemInfo, sendInstance, sendItemUnequip, sendVboxBuy, sendVboxCombine, sendVboxRefill, sendVboxRefund, }; }, function receiveDispatch(dispatch) { function setInfo(item) { return dispatch(actions.setInfo(item)); } function setTutorial(stage) { return dispatch(actions.setTutorial(stage)); } function dispatchVboxSelect(v, state) { setVboxState(dispatch, v, state); dispatch(actions.setItemUnequip([])); return dispatch(actions.setVboxSelected(v)); } return { dispatchVboxSelect, setInfo, setTutorial, }; } ); class Vbox extends preact.Component { shouldComponentUpdate(newProps) { 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; return false; } render(args) { const { // Changing state variables itemUnequip, instance, player, tutorial, vboxSelected, // Static itemInfo, // Function Calls dispatchVboxSelect, sendItemUnequip, sendInstance, sendVboxBuy, sendVboxCombine, sendVboxRefill, sendVboxRefund, setInfo, setTutorial, } = args; if (!player) return false; const { vbox } = player; const { storeSelect, stashSelect } = vboxSelected; const setVboxSelected = v => dispatchVboxSelect(v, { itemInfo, itemUnequip, vbox }); const clearVboxSelected = () => setVboxSelected({ storeSelect: [], stashSelect: [] }); const vboxBuySelected = () => sendVboxBuy(storeSelect[0][0], storeSelect[0][1]); const clearTutorial = () => { setTutorial(null); sendInstance(); }; function vboxHover(e, v) { if (v) { e.stopPropagation(); if (stashSelect.length !== 0 || storeSelect.length !== 0) return true; setInfo(v); } return true; } function storeHdr() { return (