From c69182b94e4345d9a826678f067864c3660c0b5b Mon Sep 17 00:00:00 2001 From: ntr Date: Sat, 20 Jul 2019 22:30:03 +1000 Subject: [PATCH] new combiner --- client/assets/styles/vbox.less | 35 +++--- client/src/components/vbox.component.jsx | 140 +++++++++++++---------- client/src/utils.jsx | 14 +++ 3 files changed, 116 insertions(+), 73 deletions(-) diff --git a/client/assets/styles/vbox.less b/client/assets/styles/vbox.less index 7cbb9073..42c6999b 100644 --- a/client/assets/styles/vbox.less +++ b/client/assets/styles/vbox.less @@ -71,27 +71,34 @@ button { height: 3em; margin: 0; - } - button.empty { - border-style: dashed; + &.empty { + border-style: dashed; + } + + &.highlight { + color: black; + background: @white; + border: 1px solid @white; + } } svg { stroke: none; margin: 0 auto; display: block; + + &.red { + fill: @red; + } + + &.green { + fill: @green; + } + + &.blue { + fill: @blue; + } } - svg.red { - fill: @red; - } - - svg.green { - fill: @green; - } - - .blue { - fill: @blue; - } } diff --git a/client/src/components/vbox.component.jsx b/client/src/components/vbox.component.jsx index af2664dd..3f8b9fa4 100644 --- a/client/src/components/vbox.component.jsx +++ b/client/src/components/vbox.component.jsx @@ -1,5 +1,6 @@ const preact = require('preact'); const range = require('lodash/range'); +const without = require('lodash/without'); const { connect } = require('preact-redux'); const shapes = require('./shapes'); @@ -142,7 +143,7 @@ function Vbox(args) { return true; } - function boundBtn(v, group, index) { + function availableBtn(v, group, index) { if (!v) return ; function onClick() { @@ -158,11 +159,21 @@ function Vbox(args) { if (['Red', 'Green', 'Blue'].includes(v)) { return ( - + ); } - return ; + return ( + + ); } @@ -176,11 +187,11 @@ function Vbox(args) {
hoverInfo(e, 'bits')} >{vbox.bits}b
- {range(0, 6).map(i => boundBtn(vbox.free[0][i], 0, i))} + {range(0, 6).map(i => availableBtn(vbox.free[0][i], 0, i))}
- {range(0, 3).map(i => boundBtn(vbox.free[1][i], 1, i))} - {range(0, 3).map(i => boundBtn(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))}
; + function onClick(e) { + if (reclaiming) return sendVboxReclaim(i); + + const combinerIndex = combiner.indexOf(i); + if (combinerIndex > -1) { + return combinerChange(without(combiner, i)); + } + + combiner.push(i); + return combinerChange(combiner); + } + + const highlighted = combiner.indexOf(i) > -1; + const classes = `${highlighted ? 'highlight' : ''}`; + if (['Red', 'Green', 'Blue'].includes(v)) { return ( - + ); } - return ; + return ( + + ); } + function combinerBtn() { + const dots = combiner.filter(v => v).length; + let text = ''; + + if (dots < 3) { + for (let i = 0; i < 3; i++) { + if (dots > i) { + text += '■ '; + } else { + text += '▫ '; + } + } + } else { + text = 'combine' + } + + return ( + + ); + } function inventoryElement() { return ( @@ -288,13 +322,7 @@ function Vbox(args) {
{range(0, 9).map(i => inventoryBtn(vbox.bound[i], i))}
- + {combinerBtn()} ); } @@ -303,10 +331,6 @@ function Vbox(args) { // EVERYTHING // - function reclaimClick(e) { - e.stopPropagation(); - return setReclaiming(!reclaiming); - } function hoverInfo(e, info) { e.stopPropagation(); @@ -314,8 +338,6 @@ function Vbox(args) { } const classes = 'vbox'; - const reclaimClass = `vbox-btn reclaim ${reclaiming ? 'reclaiming' : ''}`; - return (
{vboxElement()} diff --git a/client/src/utils.jsx b/client/src/utils.jsx index 9dbf20d2..bb0717ab 100644 --- a/client/src/utils.jsx +++ b/client/src/utils.jsx @@ -297,12 +297,26 @@ function errorToast(message) { }); } +function convertItem(v) { + if (['Red', 'Green', 'Blue'].includes(v)) { + return ( + shapes.vboxColour(v.toLowerCase()) + ); + } + return v ||  ; + // uncomment for double borders in vbox; + // if (v) { + // return
{v}
; + // } + // return; +} module.exports = { stringSort, numSort, eventClasses, postData, + convertItem, errorToast, NULL_UUID, STATS,