require('TemplateLoader'); class PlayerShipHud { constructor() { this.templateLoader = new TemplateLoader(); this.containerId = "ship-container"; } async attach(parent) { let template = await this.templateLoader.get('ship'); let container = document.getElementById(this.containerId); container.innerHTML = template; this.shipName = document.getElementById('ship--name'); this.shipStatus = document.getElementById('ship--status'); this.shipRepairButton = document.getElementById('ship--repair'); this.shipBoardButton = document.getElementById('ship--board'); this.shipUndockButton = document.getElementById('ship--undock'); this.updateShipName(); this.updateShipStatus(); this.shipName.addEventListener('click', (event) => this.changeShipName(event)); this.shipRepairButton.addEventListener('click', (event) => this.repairShip(event)); } changeShipName() { let newShipName = prompt("Please input your desired ship name:", this.shipName.innerHTML); if (!newShipName) { return; } this.shipName.innerHTML = newShipName; } updateShipStatus() { this.shipStatus.innerHTML = game.ship.status; } updateShipName() { this.shipName.innerHTML = game.ship.name; } repairShip() { game.repairShip(); } disableRepair() { this.shipRepairButton.style.display = 'none'; } enableRepair() { this.shipRepairButton.style.visibility = 'inline-block'; } enableDocking() { this.shipBoardButton.style.display = 'inline-block'; this.shipUndockButton.style.display = 'inline-block'; } }