vbox apply

This commit is contained in:
ntr 2019-03-31 17:51:13 +11:00
parent cdd45894ce
commit 1358259512
5 changed files with 73 additions and 19 deletions

View File

@ -195,10 +195,15 @@ button:hover {
.vbox-table td { .vbox-table td {
border: 1px solid whitesmoke; border: 1px solid whitesmoke;
padding: 0 0.5em; padding: 0.2em;
text-align: center; text-align: center;
height: 40px; height: 40px;
cursor: pointer; cursor: pointer;
text-transform: uppercase;
}
.vbox-table td div {
border: 1px solid whitesmoke;
} }
.spacer { .spacer {

View File

@ -6,8 +6,8 @@ const VboxContainer = require('./vbox.container');
const molecule = require('./molecule'); const molecule = require('./molecule');
const saw = require('./saw.component'); const saw = require('./saw.component');
function Cryp(cryp) { function Cryp(cryp, sendVboxApply) {
const skills = range(0, 4).map((i) => { const skills = range(0, 4).map(i => {
const s = cryp.skills[i] const s = cryp.skills[i]
? cryp.skills[i].skill ? cryp.skills[i].skill
: (<span>&nbsp;</span>); : (<span>&nbsp;</span>);
@ -15,6 +15,19 @@ function Cryp(cryp) {
return <button key={i} className="cryp-skill-btn" >{s}</button>; return <button key={i} className="cryp-skill-btn" >{s}</button>;
}); });
// needed for ondrop to fire
function onDragOver(e) {
e.preventDefault();
return false;
}
function onDrop(e) {
e.stopPropagation();
e.preventDefault();
const item = parseInt(e.dataTransfer.getData('text'), 10);
return sendVboxApply(cryp.id, item);
}
const stats = [ const stats = [
{ stat: 'hp', colour: '#1FF01F' }, { stat: 'hp', colour: '#1FF01F' },
{ stat: 'green_damage', colour: '#1FF01F' }, { stat: 'green_damage', colour: '#1FF01F' },
@ -31,7 +44,12 @@ function Cryp(cryp) {
)); ));
return ( return (
<div className="cryp-box"> <div
key={cryp.id}
className="cryp-box"
onDragOver={onDragOver}
onDrop={onDrop}
>
<figure className="img"> <figure className="img">
{molecule} {molecule}
<figcaption>{cryp.name}</figcaption> <figcaption>{cryp.name}</figcaption>
@ -52,11 +70,12 @@ function InstanceComponent(args) {
instance, instance,
quit, quit,
sendInstanceReady, sendInstanceReady,
sendVboxApply,
} = args; } = args;
if (!instance) return <div>...</div>; if (!instance) return <div>...</div>;
const cryps = instance.cryps.map(Cryp); const cryps = instance.cryps.map(c => Cryp(c, sendVboxApply));
return ( return (
<section className="instance" > <section className="instance" >

View File

@ -12,7 +12,11 @@ const addState = connect(
return ws.sendInstanceReady(instance.instance); return ws.sendInstanceReady(instance.instance);
} }
return { instance, account, sendInstanceReady }; function sendVboxApply(crypId, i) {
return ws.sendVboxApply(instance.instance, crypId, i);
}
return { instance, account, sendInstanceReady, sendVboxApply };
}, },
function receiveDispatch(dispatch, { instance, combiner }) { function receiveDispatch(dispatch, { instance, combiner }) {

View File

@ -1,7 +1,13 @@
const preact = require('preact'); const preact = require('preact');
const range = require('lodash/range');
function convertVar(v) { function convertVar(v) {
return v || ''; return v || '';
// uncomment for double borders in vbox
// if (v) {
// return <div>{v}</div>;
// }
// return;
} }
function Vbox(args) { function Vbox(args) {
@ -20,6 +26,19 @@ 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 boundClick(i) {
if (reclaiming) {
return sendVboxReclaim(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) { function combinerRmv(i) {
combiner[i] = null; combiner[i] = null;
@ -47,21 +66,31 @@ function Vbox(args) {
); );
}); });
const boundTds = range(0, 9).map(i => (
<td
key={i}
draggable="true"
onDragStart={e => e.dataTransfer.setData('text', i)}
onClick={() => boundClick(i) }>
{convertVar(vbox.bound[i])}
</td>
));
const boundRows = [ const boundRows = [
<tr key={0} > <tr key={0} >
<td onClick={() => boundClick(0) }>{convertVar(vbox.bound[0])}</td> {boundTds[0]}
<td onClick={() => boundClick(1) }>{convertVar(vbox.bound[1])}</td> {boundTds[1]}
<td onClick={() => boundClick(2) }>{convertVar(vbox.bound[2])}</td> {boundTds[2]}
</tr>, </tr>,
<tr key={1}> <tr key={1}>
<td onClick={() => boundClick(3) }>{convertVar(vbox.bound[3])}</td> {boundTds[3]}
<td onClick={() => boundClick(4) }>{convertVar(vbox.bound[4])}</td> {boundTds[4]}
<td onClick={() => boundClick(5) }>{convertVar(vbox.bound[5])}</td> {boundTds[5]}
</tr>, </tr>,
<tr key={2}> <tr key={2}>
<td onClick={() => boundClick(6) }>{convertVar(vbox.bound[6])}</td> {boundTds[6]}
<td onClick={() => boundClick(7) }>{convertVar(vbox.bound[7])}</td> {boundTds[7]}
<td onClick={() => boundClick(8) }>{convertVar(vbox.bound[8])}</td> {boundTds[8]}
</tr>, </tr>,
]; ];

View File

@ -21,11 +21,8 @@ const addState = connect(
} }
function sendVboxReclaim(i) { function sendVboxReclaim(i) {
if (reclaiming) {
return ws.sendVboxReclaim(instance.instance, i); return ws.sendVboxReclaim(instance.instance, i);
} }
return false;
}
return { return {
instance, instance,