combiner stuff

This commit is contained in:
ntr 2019-03-30 21:42:43 +11:00
parent 058a368d7b
commit e2169ea890
5 changed files with 39 additions and 26 deletions

View File

@ -37,6 +37,8 @@ button:hover {
.menu-cryps { .menu-cryps {
display: flex; display: flex;
flex-flow: row wrap; flex-flow: row wrap;
align-items: stretch;
justify-content: flex-end;
} }
.menu-cryp-ctr { .menu-cryp-ctr {
@ -45,6 +47,7 @@ button:hover {
} }
.menu-cryp { .menu-cryp {
height: 100%;
margin: 0.5em; margin: 0.5em;
box-sizing: border-box; box-sizing: border-box;
border: 2px solid whitesmoke; border: 2px solid whitesmoke;

View File

@ -9,6 +9,7 @@ function Vbox(args) {
const { const {
instance, instance,
combiner, combiner,
setCombiner,
sendVboxAccept, sendVboxAccept,
sendVboxDiscard, sendVboxDiscard,
sendVboxReclaim, sendVboxReclaim,
@ -18,6 +19,21 @@ function Vbox(args) {
const { vbox } = instance; const { vbox } = instance;
if (!instance.vbox) return false; if (!instance.vbox) return false;
// lots of rubbish to make it flow nice
function combinerAdd(i) {
if (combiner.indexOf(i) === -1) {
const insert = combiner.findIndex(j => j === null);
combiner[insert] = i;
return setCombiner(combiner);
}
return setCombiner([i, null, null]);
}
function combinerRmv(i) {
combiner[i] = null;
return setCombiner(combiner);
}
const free = []; const free = [];
for (let i = 0 ; i < 6; i++) { for (let i = 0 ; i < 6; i++) {
free.push([vbox.free[0][i], vbox.free[1][i], vbox.free[2][i]]); free.push([vbox.free[0][i], vbox.free[1][i], vbox.free[2][i]]);
@ -41,19 +57,19 @@ function Vbox(args) {
const boundRows = [ const boundRows = [
<tr key={0} > <tr key={0} >
<td>{convertVar(vbox.bound[0])}</td> <td onClick={() => combinerAdd(0) }>{convertVar(vbox.bound[0])}</td>
<td>{convertVar(vbox.bound[1])}</td> <td onClick={() => combinerAdd(1) }>{convertVar(vbox.bound[1])}</td>
<td>{convertVar(vbox.bound[2])}</td> <td onClick={() => combinerAdd(2) }>{convertVar(vbox.bound[2])}</td>
</tr>, </tr>,
<tr key={1}> <tr key={1}>
<td>{convertVar(vbox.bound[3])}</td> <td onClick={() => combinerAdd(3) }>{convertVar(vbox.bound[3])}</td>
<td>{convertVar(vbox.bound[4])}</td> <td onClick={() => combinerAdd(4) }>{convertVar(vbox.bound[4])}</td>
<td>{convertVar(vbox.bound[5])}</td> <td onClick={() => combinerAdd(5) }>{convertVar(vbox.bound[5])}</td>
</tr>, </tr>,
<tr key={2}> <tr key={2}>
<td>{convertVar(vbox.bound[6])}</td> <td onClick={() => combinerAdd(6) }>{convertVar(vbox.bound[6])}</td>
<td>{convertVar(vbox.bound[7])}</td> <td onClick={() => combinerAdd(7) }>{convertVar(vbox.bound[7])}</td>
<td>{convertVar(vbox.bound[8])}</td> <td onClick={() => combinerAdd(8) }>{convertVar(vbox.bound[8])}</td>
</tr>, </tr>,
]; ];
@ -61,9 +77,9 @@ function Vbox(args) {
<table className="vbox-table"> <table className="vbox-table">
<tbody> <tbody>
<tr> <tr>
<td>{convertVar(combiner[0])}</td> <td onClick={() => combinerRmv(0)}>{convertVar(vbox.bound[combiner[0]])}</td>
<td>{convertVar(combiner[1])}</td> <td onClick={() => combinerRmv(1)}>{convertVar(vbox.bound[combiner[1]])}</td>
<td>{convertVar(combiner[2])}</td> <td onClick={() => combinerRmv(2)}>{convertVar(vbox.bound[combiner[2]])}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -17,13 +17,11 @@ const addState = connect(
} }
function sendVboxCombine() { function sendVboxCombine() {
return console.log('combine', combiner); return ws.sendVboxCombine(combiner);
return ws.sendVboxDiscard(instance.instance);
} }
function sendVboxReclaim(v) { function sendVboxReclaim(v) {
return console.log('reclaim', v); return ws.sendVboxDiscard(instance.instance, v);
return ws.sendVboxDiscard(instance.instance);
} }
return { return {
@ -36,16 +34,12 @@ const addState = connect(
}; };
}, },
function receiveDispatch(dispatch, { combiner }) { function receiveDispatch(dispatch) {
function addToCombiner(v) { function setCombiner(c) {
combiner.push(v); dispatch(actions.setCombiner(c));
if (combiner.length > 3) {
dispatch(actions.setCombiner([v]));
}
dispatch(actions.setCombiner(combiner));
} }
return { addToCombiner }; return { setCombiner };
} }
); );

View File

@ -60,7 +60,7 @@ function selectedCrypsReducer(state = defaultSelectedCryps, action) {
} }
} }
const defaultCombiner = []; const defaultCombiner = [null, null, null];
function combinerReducer(state = defaultCombiner, action) { function combinerReducer(state = defaultCombiner, action) {
switch (action.type) { switch (action.type) {
case actions.SET_COMBINER: case actions.SET_COMBINER:

View File

@ -201,7 +201,7 @@ pub fn account_players(tx: &mut Transaction, account: &Account) -> Result<Vec<Pl
}; };
} }
list.sort_by_key(|c| c.id); list.sort_by_key(|c| c.instance);
return Ok(list); return Ok(list);
} }