Add amount to resources

This commit is contained in:
Aaron Fischer 2015-08-29 15:16:57 +02:00
parent 24f4eaaf55
commit dac9619ffa
2 changed files with 30 additions and 5 deletions

View file

@ -9,10 +9,10 @@
<nav> <nav>
Cargo: Cargo:
<ul> <ul>
<li>Dust: <strong id="res-dust">0</strong></li> <li>Dust: <strong class="res-dust">0</strong></li>
<li>Stone: <strong id="res-stone">0</strong></li> <li>Stone: <strong class="res-stone">0</strong></li>
<li>Carbon: <strong id="res-carbon">0</strong></li> <li>Carbon: <strong class="res-carbon">0</strong></li>
<li>Metal: <strong id="res-metal">0</strong></li> <li>Metal: <strong class="res-metal">0</strong></li>
</ul> </ul>
</nav> </nav>
@ -34,6 +34,14 @@
Buy: Buy:
<ul id="station-inventory"></ul> <ul id="station-inventory"></ul>
Sell:
<ul id="ship-inventory">
<li>Dust: <input type="text" class="res-dust" name="sell-res-dust"> <a href="#" data-res="dust">sell</a></li>
<li>Stone: <input type="text" class="res-stone" name="sell-res-stone"> <a href="#" data-res="stone">sell</a></li>
<li>Carbon: <input type="text" class="res-carbon" name="sell-res-carbon"> <a href="#" data-res="carbon">sell</a></li>
<li>Metal: <input type="text" class="res-metal" name="sell-res-metal"> <a href="#" data-res="metal">sell</a></li>
</ul>
<button id="btn-to-asteroid">Fly to the asteroid</button> <button id="btn-to-asteroid">Fly to the asteroid</button>
</div> </div>

View file

@ -20,7 +20,7 @@ class Engine {
update() { update() {
// Resources // Resources
_.eachObj(this.ship.resources, (key, value) => { _.eachObj(this.ship.resources, (key, value) => {
$('#res-' + key).fill(value); $('nav .res-' + key).fill(value);
}); });
// The ship // The ship
@ -41,6 +41,10 @@ class Engine {
if (this.ship.docked_to instanceof Station) { if (this.ship.docked_to instanceof Station) {
$('#asteroid').hide(); $('#asteroid').hide();
$('#station').show(); $('#station').show();
_.eachObj(this.ship.resources, (key, value) => {
$('#ship-inventory .res-' + key).set('@value', value);
});
} }
if (this.ship.docked_to instanceof Asteroid) { if (this.ship.docked_to instanceof Asteroid) {
@ -136,6 +140,11 @@ class Station {
!_.keys(ship.equipment).contains(tool)) !_.keys(ship.equipment).contains(tool))
ship.equip(tool, this.inventory[tool]); ship.equip(tool, this.inventory[tool]);
} }
buy(ship, resource, amount) {
// TODO: Check if the ship has enough resources loaded
console.log(ship, resource, amount);
}
} }
var engine = new Engine(); var engine = new Engine();
@ -172,6 +181,14 @@ $(() => {
}) })
$('#station-inventory').add(EE('li', tool+' ').add(buy_button)); $('#station-inventory').add(EE('li', tool+' ').add(buy_button));
}); });
$('#ship-inventory a').onClick((e) => {
let res = $(e.target).get('%res');
let amount = $('#ship-inventory input[name="sell-res-'+res+'"]').get('value');
engine.station.buy(engine.ship, res, amount);
engine.update();
});
engine.update(); engine.update();
}) })