PlayerShipHud.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. require('TemplateLoader');
  2. class PlayerShipHud {
  3. constructor() {
  4. this.templateLoader = new TemplateLoader();
  5. this.containerId = "ship-container";
  6. }
  7. async attach(parent) {
  8. let template = await this.templateLoader.get('ship');
  9. let container = document.getElementById(this.containerId);
  10. container.innerHTML = template;
  11. this.shipName = document.getElementById('ship--name');
  12. this.shipStatus = document.getElementById('ship--status');
  13. this.shipRepairButton = document.getElementById('ship--repair');
  14. this.shipBoardButton = document.getElementById('ship--board');
  15. this.shipUndockButton = document.getElementById('ship--undock');
  16. this.updateShipName();
  17. this.updateShipStatus();
  18. this.shipName.addEventListener('click', (event) => this.changeShipName(event));
  19. this.shipRepairButton.addEventListener('click', (event) => this.repairShip(event));
  20. }
  21. changeShipName() {
  22. let newShipName = prompt("Please input your desired ship name:", this.shipName.innerHTML);
  23. if (!newShipName) {
  24. return;
  25. }
  26. this.shipName.innerHTML = newShipName;
  27. }
  28. updateShipStatus() {
  29. this.shipStatus.innerHTML = game.ship.status;
  30. }
  31. updateShipName() {
  32. this.shipName.innerHTML = game.ship.name;
  33. }
  34. repairShip() {
  35. game.repairShip();
  36. }
  37. disableRepair() {
  38. this.shipRepairButton.style.display = 'none';
  39. }
  40. enableRepair() {
  41. this.shipRepairButton.style.visibility = 'inline-block';
  42. }
  43. enableDocking() {
  44. this.shipBoardButton.style.display = 'inline-block';
  45. this.shipUndockButton.style.display = 'inline-block';
  46. }
  47. }