12345678910111213141516171819202122232425262728293031323334353637383940 |
- require('TemplateLoader');
- class PlayerInventoryHud {
- constructor() {
- this.templateLoader = new TemplateLoader();
- this.containerId = "inventory-container";
- }
- async attach(parent) {
- let template = await this.templateLoader.get('inventory');
- let container = document.getElementById(this.containerId);
- container.innerHTML = template;
- this.cargoHold = document.getElementById("cargo--hold");
- this.hide();
- }
- init() {
- this.buildInventory();
- }
- buildInventory() {
- this.cargoHold.innerHTML = "";
- game.inventory.getAll().forEach((item) => {
- let itemElement = document.createElement('div');
- itemElement.innerHTML = `${item.amount} ${item.name}`;
- this.cargoHold.appendChild(itemElement);
- });
- }
- hide() {
- document.getElementById(this.containerId).style.opacity = "0";
- document.getElementById(this.containerId).style.visibility = "hidden";
- }
- show() {
- document.getElementById(this.containerId).style.opacity = "1";
- document.getElementById(this.containerId).style.visibility = "visible";
- }
- }
|