diff --git a/src/index.html b/src/index.html index 12056c8..e99f17b 100644 --- a/src/index.html +++ b/src/index.html @@ -18,6 +18,8 @@
Active tool: Probe + Equipment: +
@@ -30,9 +32,8 @@

Docked to station

- + Buy: +
diff --git a/src/main.js b/src/main.js index 851a5e4..18b1607 100644 --- a/src/main.js +++ b/src/main.js @@ -26,6 +26,18 @@ class Engine { // The ship $('#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) { $('#asteroid').hide(); $('#station').show(); @@ -57,11 +69,14 @@ class Ship { } } - mount(tool, props) { - this.equipment[tool] = props; + mount(tool) { this.active_tool = tool; } + equip(tool, props) { + this.equipment[tool] = props; + } + mine() { if (this.docked_to instanceof Asteroid) { let [type, amount] = this.docked_to.harvest(this); @@ -92,8 +107,6 @@ class Asteroid { }[this.classification]; let res_type = resources[Helper.random_number(0, resources.length)]; let amount = ship.equipment[ship.active_tool][this.classification]; - - console.log(amount); return [res_type, amount]; } } @@ -121,7 +134,7 @@ class Station { sell(ship, tool) { if (_.keys(this.inventory).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 tool = $(e.target).get('%tool'); engine.station.sell(engine.ship, tool); + engine.update(); }) $('#station-inventory').add(EE('li', tool+' ').add(buy_button)); });