PlayerInventoryHud.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. require('TemplateLoader');
  2. class PlayerInventoryHud {
  3. constructor() {
  4. this.templateLoader = new TemplateLoader();
  5. this.containerId = "inventory-container";
  6. }
  7. async attach(parent) {
  8. let template = await this.templateLoader.get('inventory');
  9. let container = document.getElementById(this.containerId);
  10. container.innerHTML = template;
  11. this.cargoHold = document.getElementById("cargo--hold");
  12. this.hide();
  13. }
  14. init() {
  15. this.buildInventory();
  16. }
  17. buildInventory() {
  18. this.cargoHold.innerHTML = "";
  19. game.inventory.getAll().forEach((item) => {
  20. let itemElement = document.createElement('div');
  21. itemElement.innerHTML = `${item.amount} ${item.name}`;
  22. this.cargoHold.appendChild(itemElement);
  23. });
  24. }
  25. hide() {
  26. document.getElementById(this.containerId).style.opacity = "0";
  27. document.getElementById(this.containerId).style.visibility = "hidden";
  28. }
  29. show() {
  30. document.getElementById(this.containerId).style.opacity = "1";
  31. document.getElementById(this.containerId).style.visibility = "visible";
  32. }
  33. }