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>
Cargo:
<ul>
<li>Dust: <strong id="res-dust">0</strong></li>
<li>Stone: <strong id="res-stone">0</strong></li>
<li>Carbon: <strong id="res-carbon">0</strong></li>
<li>Metal: <strong id="res-metal">0</strong></li>
<li>Dust: <strong class="res-dust">0</strong></li>
<li>Stone: <strong class="res-stone">0</strong></li>
<li>Carbon: <strong class="res-carbon">0</strong></li>
<li>Metal: <strong class="res-metal">0</strong></li>
</ul>
</nav>
@ -35,6 +35,14 @@
Buy:
<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>
</div>
</body>

View file

@ -20,7 +20,7 @@ class Engine {
update() {
// Resources
_.eachObj(this.ship.resources, (key, value) => {
$('#res-' + key).fill(value);
$('nav .res-' + key).fill(value);
});
// The ship
@ -41,6 +41,10 @@ class Engine {
if (this.ship.docked_to instanceof Station) {
$('#asteroid').hide();
$('#station').show();
_.eachObj(this.ship.resources, (key, value) => {
$('#ship-inventory .res-' + key).set('@value', value);
});
}
if (this.ship.docked_to instanceof Asteroid) {
@ -136,6 +140,11 @@ class Station {
!_.keys(ship.equipment).contains(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();
@ -173,5 +182,13 @@ $(() => {
$('#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();
})