Skip to content

Commit

Permalink
3/5/22 11:15 PM
Browse files Browse the repository at this point in the history
 - fixed Inventory.drop()
 - updated example / testing code
  • Loading branch information
eboatwright committed Mar 5, 2022
1 parent b66c074 commit afd047a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,11 +846,13 @@ class Inventory extends Component {

const index = this.getItemIndex(itemName);
this.inventory[index].amount -= 1;
if(this.inventory[index] <= 0)
this.inventory.splice(index, 1);

var item = this.inventory[index];
var item = this.inventory[index].item;
item.destroyed = false;

if(this.inventory[index].amount <= 0)
this.inventory.splice(index, 1);

return item;
}

Expand Down
8 changes: 5 additions & 3 deletions src/jscii/extras/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ class Inventory extends Component {

const index = this.getItemIndex(itemName);
this.inventory[index].amount -= 1;
if(this.inventory[index] <= 0)
this.inventory.splice(index, 1);

var item = this.inventory[index];
var item = this.inventory[index].item;
item.destroyed = false;

if(this.inventory[index].amount <= 0)
this.inventory.splice(index, 1);

return item;
}

Expand Down
15 changes: 8 additions & 7 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ class UIManager extends Entity {
}

update(level) {
if(keyJustDown("i") && this.inventory === undefined)
this.inventory = level.addEntity(new InventoryPanel());

if(keyJustDown("Escape")) {
this.inventory.destroy();
this.inventory = undefined;
if(this.inventory == undefined) {
if(keyJustDown("i"))
this.inventory = level.addEntity(new InventoryPanel());
} else {
if(keyJustDown("Escape")) {
this.inventory.destroy();
this.inventory = undefined;
}
}
}
}
Expand Down Expand Up @@ -132,7 +134,6 @@ init = function() {

level.addEntity(new Player(playerPosition));
level.addEntity(new Item("item", playerPosition.minus(2), "ICE STAFF", new CharRenderer(null, "item", FWD_SLASH, LIGHT_BLUE, BLACK)));
level.addEntity(new Item("item", playerPosition.minus(3), "ICE STAFF", new CharRenderer(null, "item", FWD_SLASH, LIGHT_BLUE, BLACK)));

level.addEntity(new Text("hud", vector2(1, 1), "HP: X", WHITE, BLACK));
level.addEntity(new Seperator(vector2(0, 2), LIGHT_GRAY));
Expand Down

0 comments on commit afd047a

Please sign in to comment.