moved combiner wip

This commit is contained in:
Mashy 2019-11-23 17:03:04 +10:00
parent cfeac949e0
commit 34f790caa3
6 changed files with 252 additions and 212 deletions

View File

@ -5,114 +5,17 @@
.instance { .instance {
overflow: hidden; overflow: hidden;
display: grid; display: grid;
grid-template-columns: 1fr minmax(min-content, 1fr);
grid-template-rows: min-content 1fr; grid-template-rows: min-content 1fr;
grid-template-areas: grid-template-areas:
"vbox info" "vbox"
"constructs constructs"; "constructs";
.info {
h2 {
text-transform: uppercase;
}
svg {
display: inline;
height: 1em;
}
figure {
display: inline;
height: 0.5em;
svg {
margin-right: 0.5em;
}
}
figcaption {
font-size: 1em;
display: inline-block;
vertical-align: middle;
}
margin-left: 1em;
grid-area: info;
display: grid;
grid-template-columns: 1fr min-content;
grid-template-areas:
"item combos";
.info-item {
grid-area: item;
}
.combos {
display: grid;
grid-area: combos;
margin-left: 0.5em;
grid-template-rows: min-content min-content;
grid-template-areas:
"comboHeader"
"comboList";
.combo-header {
text-align: center;
}
.combo-list {
display: grid;
grid-template-rows: min-content min-content min-content;
grid-template-columns: min-content min-content;
grid-gap: 0.5em;
margin-top: 0.5em;
width: 15.5em;
.table-button {
display: grid;
text-align: center;
align-content: center;
grid-template-areas:
"item"
"ingr";
cursor: pointer;
&:hover {
color: whitesmoke;
background-color: @gray;
}
.item {
border-top: 2px solid #222;
border-bottom: 2px solid #222;
flex: 1;
grid-area: item;
font-weight: bold;
div {
width: 5em;
}
}
div {
border-left: 2px solid #222;
border-right: 2px solid #222;
height: 1.75em;
width: 7.5em;
svg {
vertical-align: middle;
}
&:last-child {
border-bottom: 2px solid #222;
}
}
}
}
}
}
.constructs { .constructs {
grid-area: constructs; grid-area: constructs;
} }
} }
@keyframes action { @keyframes action {
0% { 0% {
color: palegoldenrod; color: palegoldenrod;

View File

@ -3,10 +3,10 @@
grid-area: vbox; grid-area: vbox;
display: grid; display: grid;
grid-template-rows: 3fr 2fr; grid-template-rows: 3fr 2fr;
grid-template-columns: 1fr 4fr 1fr; grid-template-columns: 1fr 4fr 6fr;
grid-template-areas: grid-template-areas:
"store-hdr store combiner" "store-hdr store info"
"stash-hdr stash combiner"; "stash-hdr stash info";
margin-bottom: 1em; margin-bottom: 1em;
line-height: 0; line-height: 0;
@ -46,38 +46,6 @@
} }
} }
.combiner {
grid-area: combiner;
display: flex;
flex-direction: column;
line-height: 1.3;
padding: 0;
.vbox-padding {
margin-right: 0em;
margin-bottom: 0em;
}
button {
line-height: 1.3;
font-size: 1.25em;
letter-spacing: 0.1em;
background-color: @yellow;
color: black;
border-radius: 0;
border: 0;
&[disabled] {
border: 0.1em solid @gray;
border-left: 0;
color: @gray-exists;
};
transition-property: 0;
}
}
.stash { .stash {
grid-area: stash; grid-area: stash;
display: grid; display: grid;
@ -210,6 +178,126 @@
line-height: initial; line-height: initial;
} }
} }
.info {
line-height: 1.6;
h2 {
text-transform: uppercase;
}
svg {
display: inline;
height: 1em;
}
figure {
display: inline;
height: 0.5em;
svg {
margin-right: 0.5em;
}
}
figcaption {
font-size: 1em;
display: inline-block;
vertical-align: middle;
}
margin-left: 1em;
grid-area: info;
display: grid;
grid-template-rows: min-content min-content;
grid-template-columns: 1fr min-content;
grid-template-areas:
"item combos"
"combiner combos";
.combiner {
grid-area: combiner;
button {
margin-top: 1em;
line-height: 1.3;
font-size: 1.25em;
letter-spacing: 0.1em;
background-color: @yellow;
color: black;
border-radius: 0;
border: 0;
&[disabled] {
border: 0.1em solid @gray;
border-left: 0;
color: @gray-exists;
};
transition-property: 0;
}
}
.info-item {
grid-area: item;
}
.combos {
display: grid;
grid-area: combos;
margin-left: 0.5em;
grid-template-rows: min-content min-content;
grid-template-areas:
"comboHeader"
"comboList";
.combo-header {
text-align: center;
}
.combo-list {
display: grid;
grid-template-rows: min-content min-content min-content;
grid-template-columns: min-content min-content;
grid-gap: 0.5em;
margin-top: 0.5em;
width: 15.5em;
.table-button {
display: grid;
text-align: center;
align-content: center;
grid-template-areas:
"item"
"ingr";
cursor: pointer;
&:hover {
color: whitesmoke;
background-color: @gray;
}
.item {
border-top: 2px solid #222;
border-bottom: 2px solid #222;
flex: 1;
grid-area: item;
font-weight: bold;
div {
width: 5em;
}
}
div {
border-left: 2px solid #222;
border-right: 2px solid #222;
height: 1.75em;
width: 7.5em;
svg {
vertical-align: middle;
}
&:last-child {
border-bottom: 2px solid #222;
}
}
}
}
}
}
} }
@media (min-width: 2000px) { @media (min-width: 2000px) {

View File

@ -7,9 +7,12 @@ const { convertItem, removeTier } = require('../utils');
const { tutorialStage } = require('../tutorial.utils'); const { tutorialStage } = require('../tutorial.utils');
const shapes = require('./shapes'); const shapes = require('./shapes');
const Combiner = require('./vbox.combiner');
class InfoComponent extends preact.Component { class InfoComponent extends preact.Component {
shouldComponentUpdate(newProps, newState) { shouldComponentUpdate(newProps, newState) {
if (newProps.vboxHighlight !== this.props.vboxHighlight) return true;
if (newProps.tutorial !== this.props.tutorial) return true; if (newProps.tutorial !== this.props.tutorial) return true;
// We don't care about info during tutorial // We don't care about info during tutorial
if (newProps.tutorial && this.props.instance.time_control === 'Practice' if (newProps.tutorial && this.props.instance.time_control === 'Practice'
@ -30,6 +33,7 @@ class InfoComponent extends preact.Component {
// Variables that will change // Variables that will change
info, info,
tutorial, tutorial,
vboxHighlight,
// Static // Static
player, // Only used for colour calcs which will be update if info changes player, // Only used for colour calcs which will be update if info changes
@ -37,7 +41,6 @@ class InfoComponent extends preact.Component {
itemInfo, itemInfo,
instance, // Only used for instance id instance, // Only used for instance id
// functions // functions
setInfo,
setTutorialNull, setTutorialNull,
} = args; } = args;
const { comboItem } = this.state; const { comboItem } = this.state;
@ -181,6 +184,7 @@ class InfoComponent extends preact.Component {
<div class='info'> <div class='info'>
<div onMouseOver={() => this.setState({ comboItem: null })}> <div onMouseOver={() => this.setState({ comboItem: null })}>
<Info /> <Info />
<Combiner vboxHighlight={vboxHighlight} />
</div> </div>
<Combos /> <Combos />
</div> </div>

View File

@ -2,7 +2,6 @@ const preact = require('preact');
const { connect } = require('preact-redux'); const { connect } = require('preact-redux');
const Vbox = require('./vbox.component'); const Vbox = require('./vbox.component');
const InfoContainer = require('./info.container');
const InstanceConstructsContainer = require('./instance.constructs'); const InstanceConstructsContainer = require('./instance.constructs');
const Faceoff = require('./faceoff'); const Faceoff = require('./faceoff');
@ -63,7 +62,6 @@ function Instance(args) {
return ( return (
<main id="instance" class='instance' onClick={instanceClick}> <main id="instance" class='instance' onClick={instanceClick}>
<Vbox /> <Vbox />
<InfoContainer />
<InstanceConstructsContainer /> <InstanceConstructsContainer />
</main> </main>
); );

View File

@ -1,17 +1,79 @@
const preact = require('preact'); const preact = require('preact');
const { connect } = require('preact-redux');
const countBy = require('lodash/countBy'); const countBy = require('lodash/countBy');
function combinerBtn(props) { const actions = require('../actions');
const addState = connect(
function receiveState(state) {
const { const {
ws,
instance,
vboxSelected,
itemInfo, itemInfo,
sendVboxCombine, player,
setInfo, } = state;
stashSelect,
storeSelect, const { vbox } = player;
function sendVboxAccept(group, index) {
document.activeElement.blur();
return ws.sendVboxAccept(instance.id, group, index);
}
function sendVboxCombine() {
return ws.sendVboxCombine(instance.id, vboxSelected.stashSelect, vboxSelected.storeSelect);
}
return {
vbox, vbox,
vboxBuySelected, vboxSelected,
itemInfo,
sendVboxAccept,
sendVboxCombine,
};
},
function receiveDispatch(dispatch) {
function setInfo(item) {
return dispatch(actions.setInfo(item));
}
return {
setInfo,
};
}
);
class CombinerBtn extends preact.Component {
shouldComponentUpdate(newProps) {
// Single variable props
if (newProps.vbox !== this.props.vbox) return true;
if (newProps.vboxHighlight !== this.props.vboxHighlight) return true;
if (newProps.vboxSelected !== this.props.vboxSelected) return true;
return false;
}
render(props) {
const {
vboxHighlight, vboxHighlight,
vbox,
vboxSelected,
itemInfo,
sendVboxAccept,
sendVboxCombine,
setInfo,
} = props; } = props;
const { stashSelect, storeSelect } = vboxSelected;
function vboxBuySelected() {
if (!(storeSelect.length === 1 && stashSelect.length === 0)) return false;
document.activeElement.blur();
sendVboxAccept(storeSelect[0][0], storeSelect[0][1]);
return true;
}
let text = ''; let text = '';
let mouseEvent = false; let mouseEvent = false;
const combineLength = stashSelect.length + storeSelect.length; const combineLength = stashSelect.length + storeSelect.length;
@ -34,21 +96,15 @@ function combinerBtn(props) {
let bits = 0; let bits = 0;
storeSelect.forEach(item => bits += item[0] + 1); storeSelect.forEach(item => bits += item[0] + 1);
text = bits text = bits
? <p>Buy<br/>{comboItem}<br />{bits}b</p> ? `Buy ${comboItem} ${bits}b`
: <p>Combine<br />{comboItem}</p>; : `Combine${comboItem}`;
if (vbox.bits >= bits) mouseEvent = sendVboxCombine; if (vbox.bits >= bits) mouseEvent = sendVboxCombine;
} else if (stashSelect.length === 0 && storeSelect.length === 1) { } else if (stashSelect.length === 0 && storeSelect.length === 1) {
const item = storeSelect[0]; const item = storeSelect[0];
text = <p>Buy<br />{vbox.free[item[0]][item[1]]}<br />{item[0] + 1}b</p>; text = `Buy ${vbox.free[item[0]][item[1]]} ${item[0] + 1}b`;
mouseEvent = vboxBuySelected; mouseEvent = vboxBuySelected;
} else { } else {
for (let i = 0; i < 3; i++) { return false;
if (combineLength > i) {
text += '■ ';
} else {
text += '▫ ';
}
}
} }
return ( return (
<div class='combiner'> <div class='combiner'>
@ -62,5 +118,6 @@ function combinerBtn(props) {
</div> </div>
); );
} }
}
module.exports = combinerBtn; module.exports = addState(CombinerBtn);

View File

@ -5,9 +5,9 @@ const forEach = require('lodash/forEach');
const actions = require('../actions'); const actions = require('../actions');
const InfoContainer = require('./info.container');
const StashElement = require('./vbox.stash'); const StashElement = require('./vbox.stash');
const StoreElement = require('./vbox.store'); const StoreElement = require('./vbox.store');
const CombinerElement = require('./vbox.combiner');
const addState = connect( const addState = connect(
function receiveState(state) { function receiveState(state) {
@ -16,6 +16,7 @@ const addState = connect(
instance, instance,
player, player,
vboxSelected, vboxSelected,
info,
itemInfo, itemInfo,
itemUnequip, itemUnequip,
tutorial, tutorial,
@ -30,10 +31,6 @@ const addState = connect(
return ws.sendVboxAccept(instance.id, group, index); return ws.sendVboxAccept(instance.id, group, index);
} }
function sendVboxCombine() {
return ws.sendVboxCombine(instance.id, vboxSelected.stashSelect, vboxSelected.storeSelect);
}
function sendVboxReclaim(i) { function sendVboxReclaim(i) {
return ws.sendVboxReclaim(instance.id, i); return ws.sendVboxReclaim(instance.id, i);
} }
@ -44,9 +41,9 @@ const addState = connect(
return { return {
instance, instance,
info,
player, player,
sendVboxAccept, sendVboxAccept,
sendVboxCombine,
sendVboxDiscard, sendVboxDiscard,
sendVboxReclaim, sendVboxReclaim,
vboxSelected, vboxSelected,
@ -130,7 +127,6 @@ class Vbox extends preact.Component {
// Function Calls // Function Calls
sendItemUnequip, sendItemUnequip,
sendVboxAccept, sendVboxAccept,
sendVboxCombine,
sendVboxDiscard, sendVboxDiscard,
sendVboxReclaim, sendVboxReclaim,
setVboxSelected, setVboxSelected,
@ -235,6 +231,10 @@ class Vbox extends preact.Component {
<div class='vbox'> <div class='vbox'>
{storeHdr()} {storeHdr()}
{stashHdr()} {stashHdr()}
<InfoContainer
vboxHighlight={vboxHighlight}
vboxBuySelected={vboxBuySelected}
/>
<StoreElement <StoreElement
clearVboxSelected = {clearVboxSelected} clearVboxSelected = {clearVboxSelected}
setInfo = {setInfo} setInfo = {setInfo}
@ -258,16 +258,6 @@ class Vbox extends preact.Component {
setInfo = {setInfo} setInfo = {setInfo}
setVboxSelected = {setVboxSelected} setVboxSelected = {setVboxSelected}
/> />
<CombinerElement
itemInfo = {itemInfo}
sendVboxCombine = {sendVboxCombine}
setInfo = {setInfo}
stashSelect = {stashSelect}
storeSelect = {storeSelect}
vbox = {vbox}
vboxBuySelected = {vboxBuySelected}
vboxHighlight = {vboxHighlight}
/>
</div> </div>
); );
} }