PlayerHud.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. require('PlayerMainHud');
  2. require('PlayerShipHud');
  3. require('PlayerNavigationHud');
  4. require('PlayerCraftingHud');
  5. require('PlayerInventoryHud');
  6. require('Dialog');
  7. require('TemplateLoader');
  8. class PlayerHud {
  9. constructor() {
  10. this.templateLoader = new TemplateLoader();
  11. this.hudContainer = null;
  12. this.main = new PlayerMainHud();
  13. this.ship = new PlayerShipHud();
  14. this.navigation = new PlayerNavigationHud();
  15. this.crafting = new PlayerCraftingHud();
  16. this.inventory = new PlayerInventoryHud();
  17. this.dialog = new Dialog();
  18. }
  19. async attach(canvas) {
  20. this.hudContainer = document.getElementById('player-hud');
  21. let template = await this.templateLoader.get('playerhud');
  22. this.hudContainer.innerHTML = template;
  23. }
  24. init() {
  25. this.main.attach(this.hudContainer);
  26. this.ship.attach(this.hudContainer);
  27. this.navigation.attach(this.hudContainer);
  28. this.crafting.attach(this.hudContainer).then(() => this.crafting.init());
  29. this.inventory.attach(this.hudContainer).then(() => this.inventory.init());
  30. this.dialog.attach(this.hudContainer);
  31. }
  32. draw(context, delta) {
  33. this.main.draw(context, delta);
  34. this.navigation.draw();
  35. }
  36. handleResize(event) {
  37. if (this.navigation) {
  38. this.navigation.handleResize(event);
  39. }
  40. }
  41. updateInventory() {
  42. this.inventory.buildInventory();
  43. }
  44. }