Buy stuff on the station and show it in the inventory
This commit is contained in:
parent
152d9a6587
commit
24f4eaaf55
2 changed files with 23 additions and 8 deletions
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
<div id="ship">
|
<div id="ship">
|
||||||
Active tool: <strong id="active-tool">Probe</strong>
|
Active tool: <strong id="active-tool">Probe</strong>
|
||||||
|
Equipment:
|
||||||
|
<ul id="ship-equipment"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="asteroid">
|
<div id="asteroid">
|
||||||
|
@ -30,9 +32,8 @@
|
||||||
<div id="station">
|
<div id="station">
|
||||||
<h2>Docked to station</h2>
|
<h2>Docked to station</h2>
|
||||||
|
|
||||||
<ul id="station-inventory">
|
Buy:
|
||||||
<li>
|
<ul id="station-inventory"></ul>
|
||||||
</ul>
|
|
||||||
|
|
||||||
<button id="btn-to-asteroid">Fly to the asteroid</button>
|
<button id="btn-to-asteroid">Fly to the asteroid</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
24
src/main.js
24
src/main.js
|
@ -26,6 +26,18 @@ class Engine {
|
||||||
// The ship
|
// The ship
|
||||||
$('#active-tool').fill(this.ship.active_tool);
|
$('#active-tool').fill(this.ship.active_tool);
|
||||||
|
|
||||||
|
if (_.keys(engine.ship.equipment).length > $('#ship-equipment > li').length) {
|
||||||
|
$('#ship-equipment').fill();
|
||||||
|
_.eachObj(engine.ship.equipment, (tool, props) => {
|
||||||
|
// Add the tool to the DOM inventory and add a mount button
|
||||||
|
let mount_button = EE('a', {'@href': '#', '%tool': tool}, 'mount').onClick((e) => {
|
||||||
|
engine.ship.active_tool = tool;
|
||||||
|
engine.update();
|
||||||
|
});
|
||||||
|
$('#ship-equipment').add(EE('li', tool+' ').add(mount_button));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (this.ship.docked_to instanceof Station) {
|
if (this.ship.docked_to instanceof Station) {
|
||||||
$('#asteroid').hide();
|
$('#asteroid').hide();
|
||||||
$('#station').show();
|
$('#station').show();
|
||||||
|
@ -57,11 +69,14 @@ class Ship {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mount(tool, props) {
|
mount(tool) {
|
||||||
this.equipment[tool] = props;
|
|
||||||
this.active_tool = tool;
|
this.active_tool = tool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
equip(tool, props) {
|
||||||
|
this.equipment[tool] = props;
|
||||||
|
}
|
||||||
|
|
||||||
mine() {
|
mine() {
|
||||||
if (this.docked_to instanceof Asteroid) {
|
if (this.docked_to instanceof Asteroid) {
|
||||||
let [type, amount] = this.docked_to.harvest(this);
|
let [type, amount] = this.docked_to.harvest(this);
|
||||||
|
@ -92,8 +107,6 @@ class Asteroid {
|
||||||
}[this.classification];
|
}[this.classification];
|
||||||
let res_type = resources[Helper.random_number(0, resources.length)];
|
let res_type = resources[Helper.random_number(0, resources.length)];
|
||||||
let amount = ship.equipment[ship.active_tool][this.classification];
|
let amount = ship.equipment[ship.active_tool][this.classification];
|
||||||
|
|
||||||
console.log(amount);
|
|
||||||
return [res_type, amount];
|
return [res_type, amount];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +134,7 @@ class Station {
|
||||||
sell(ship, tool) {
|
sell(ship, tool) {
|
||||||
if (_.keys(this.inventory).contains(tool) &&
|
if (_.keys(this.inventory).contains(tool) &&
|
||||||
!_.keys(ship.equipment).contains(tool))
|
!_.keys(ship.equipment).contains(tool))
|
||||||
ship.mount(tool, this.inventory[tool]);
|
ship.equip(tool, this.inventory[tool]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,6 +168,7 @@ $(() => {
|
||||||
let buy_button = EE('a', {'@href': '#', '%tool': tool}, 'buy').onClick((e) => {
|
let buy_button = EE('a', {'@href': '#', '%tool': tool}, 'buy').onClick((e) => {
|
||||||
let tool = $(e.target).get('%tool');
|
let tool = $(e.target).get('%tool');
|
||||||
engine.station.sell(engine.ship, tool);
|
engine.station.sell(engine.ship, tool);
|
||||||
|
engine.update();
|
||||||
})
|
})
|
||||||
$('#station-inventory').add(EE('li', tool+' ').add(buy_button));
|
$('#station-inventory').add(EE('li', tool+' ').add(buy_button));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue