]> git.lizzy.rs Git - dragonblocks.git/blobdiff - game/furnace/inventory.js
Code style overhaul
[dragonblocks.git] / game / furnace / inventory.js
index c70864a0e3f411b96ae3bde1eb4f7007da5d6ee8..d28ba3b4a8aa257406f1a57212625e9a3c032e00 100644 (file)
@@ -8,28 +8,28 @@ furnace.Inventory = class extends dragonblocks.InventoryContainer{
                        right: 2,
                });
                let self = this;
-               this.input = new dragonblocks.Itemstack();
-               this.input.addUpdateListener(_ => {
+               this.input = new dragonblocks.ItemStack();
+               this.input.addEventListener("update", _ => {
                        self.update();
                });
-               this.fuel = new dragonblocks.Itemstack();
-               this.fuel.addUpdateListener(_ => {
+               this.fuel = new dragonblocks.ItemStack();
+               this.fuel.addEventListener("update", _ => {
                        self.update();
                });
-               this.burnProgressDisplay = new dragonblocks.Itemstack();
-               this.burnProgressDisplay.parse("furnace:burn_progress_0");
+               this.burnProgressDisplay = new dragonblocks.ItemStack();
+               this.burnProgressDisplay.deserialize("furnace:burn_progress_0");
                this.burnProgressDisplay.action = _ => {};
-               this.burnProgressDisplay.onredraw = _ => {
+               this.burnProgressDisplay.addEventListener("redraw", _ => {
                        dragonblocks.Inventory.getStackDisplay(self.burnProgressDisplay.id).style.backgroundColor = "";
                        dragonblocks.Inventory.getStackDisplay(self.burnProgressDisplay.id).style.border = "none";
-               };
-               this.fuelProgressDisplay = new dragonblocks.Itemstack();
-               this.fuelProgressDisplay.parse("furnace:fuel_progress_0");
+               });
+               this.fuelProgressDisplay = new dragonblocks.ItemStack();
+               this.fuelProgressDisplay.deserialize("furnace:fuel_progress_0");
                this.fuelProgressDisplay.action = _ => {};
-               this.fuelProgressDisplay.onredraw = _ => {
+               this.fuelProgressDisplay.addEventListener("redraw", _ => {
                        dragonblocks.Inventory.getStackDisplay(self.fuelProgressDisplay.id).style.backgroundColor = "";
                        dragonblocks.Inventory.getStackDisplay(self.fuelProgressDisplay.id).style.border = "none";
-               };
+               });
                this.clear();
                this.clearFuel();
                this.update();
@@ -37,26 +37,26 @@ furnace.Inventory = class extends dragonblocks.InventoryContainer{
        draw(parent, x, y){
                if(! super.draw(parent, x, y))
                        return false;
-               dragonblocks.Inventory.drawStack(this.getDisplay(), 2 * dragonblocks.settings.inventory.scale * 1.1, 0.5 * dragonblocks.settings.inventory.scale * 1.1, this.input);
-               dragonblocks.Inventory.drawStack(this.getDisplay(), 3 * dragonblocks.settings.inventory.scale * 1.1, 1.5 * dragonblocks.settings.inventory.scale * 1.1, this.burnProgressDisplay);
-               dragonblocks.Inventory.drawStack(this.getDisplay(), 2 * dragonblocks.settings.inventory.scale * 1.1, 1.5 * dragonblocks.settings.inventory.scale * 1.1, this.fuelProgressDisplay);
-               dragonblocks.Inventory.drawStack(this.getDisplay(), 2 * dragonblocks.settings.inventory.scale * 1.1, 2.5 * dragonblocks.settings.inventory.scale * 1.1, this.fuel);
+               this.input.draw(this.getDisplay(), 2 * dragonblocks.settings.inventory.scale * 1.1, 0.5 * dragonblocks.settings.inventory.scale * 1.1);
+               this.burnProgressDisplay.draw(this.getDisplay(), 3 * dragonblocks.settings.inventory.scale * 1.1, 1.5 * dragonblocks.settings.inventory.scale * 1.1);
+               this.fuelProgressDisplay.draw(this.getDisplay(), 2 * dragonblocks.settings.inventory.scale * 1.1, 1.5 * dragonblocks.settings.inventory.scale * 1.1);
+               this.fuel.draw(this.getDisplay(), 2 * dragonblocks.settings.inventory.scale * 1.1, 2.5 * dragonblocks.settings.inventory.scale * 1.1);
                return true;
        }
        isEmpty(){
                return this.inventory.isEmpty() && ! this.fuel.item && ! this.input.item;
        }
-       parse(str){
+       deserialize(str){
                let obj = JSON.parse(str);
-               this.inventory.parse(obj.inventory);
-               this.input.parse(obj.input);
-               this.fuel.parse(obj.fuel);
+               this.inventory.deserialize(obj.inventory);
+               this.input.deserialize(obj.input);
+               this.fuel.deserialize(obj.fuel);
        }
-       stringify(){
+       serialize(){
                return JSON.stringify({
-                       inventory: this.inventory.stringify(),
-                       input: this.input.stringify(),
-                       fuel: this.fuel.stringify()
+                       inventory: this.inventory.serialize(),
+                       input: this.input.serialize(),
+                       fuel: this.fuel.serializes()
                });
        }
        getRecipe(){
@@ -114,7 +114,7 @@ furnace.Inventory = class extends dragonblocks.InventoryContainer{
                        else
                                this.clear();
                }
-               this.burnProgressDisplay.parse("furnace:burn_progress_" + parseInt(this.burnProgress / this.getRecipeTime() * 5));
-               this.fuelProgressDisplay.parse("furnace:fuel_progress_" + (parseInt(this.fuelPower / this.fullFuelPower * 5) || 0));
+               this.burnProgressDisplay.deserialize("furnace:burn_progress_" + parseInt(this.burnProgress / this.getRecipeTime() * 5));
+               this.fuelProgressDisplay.deserialize("furnace:fuel_progress_" + (parseInt(this.fuelPower / this.fullFuelPower * 5) || 0));
        }
 }