const preact = require('preact'); // const key = require('keymaster'); function convertVar(v) { return v || ''; } function Vbox(args) { const { instance, combiner, setCombiner, sendVboxAccept, sendVboxDiscard, sendVboxReclaim, sendVboxCombine, } = args; const { vbox } = instance; 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 = []; for (let i = 0 ; i < 6; i++) { free.push([vbox.free[0][i], vbox.free[1][i], vbox.free[2][i]]); } const freeRows = free.map((row, i) => { const cells = row.map((c, j) => ( c && sendVboxAccept(j, i)} > {convertVar(c)} )); return ( {cells} ); }); const boundRows = [ combinerAdd(0) }>{convertVar(vbox.bound[0])} combinerAdd(1) }>{convertVar(vbox.bound[1])} combinerAdd(2) }>{convertVar(vbox.bound[2])} , combinerAdd(3) }>{convertVar(vbox.bound[3])} combinerAdd(4) }>{convertVar(vbox.bound[4])} combinerAdd(5) }>{convertVar(vbox.bound[5])} , combinerAdd(6) }>{convertVar(vbox.bound[6])} combinerAdd(7) }>{convertVar(vbox.bound[7])} combinerAdd(8) }>{convertVar(vbox.bound[8])} , ]; const combinerElement = (
combinerRmv(0)}>{convertVar(vbox.bound[combiner[0]])} combinerRmv(1)}>{convertVar(vbox.bound[combiner[1]])} combinerRmv(2)}>{convertVar(vbox.bound[combiner[2]])}
); return (
VBOX

{vbox.bits}b

{freeRows}
INVENTORY {boundRows}
I-COMBINATOR {combinerElement}
); } module.exports = Vbox;