1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- require('PlayerMainHud');
- require('PlayerShipHud');
- require('PlayerNavigationHud');
- require('PlayerCraftingHud');
- require('PlayerInventoryHud');
- require('Dialog');
- require('TemplateLoader');
- class PlayerHud {
- constructor() {
- this.templateLoader = new TemplateLoader();
- this.hudContainer = null;
- this.main = new PlayerMainHud();
- this.ship = new PlayerShipHud();
- this.navigation = new PlayerNavigationHud();
- this.crafting = new PlayerCraftingHud();
- this.inventory = new PlayerInventoryHud();
- this.dialog = new Dialog();
- }
- async attach(canvas) {
- this.hudContainer = document.getElementById('player-hud');
- let template = await this.templateLoader.get('playerhud');
- this.hudContainer.innerHTML = template;
- }
- init() {
- this.main.attach(this.hudContainer);
- this.ship.attach(this.hudContainer);
- this.navigation.attach(this.hudContainer);
- this.crafting.attach(this.hudContainer).then(() => this.crafting.init());
- this.inventory.attach(this.hudContainer).then(() => this.inventory.init());
- this.dialog.attach(this.hudContainer);
- }
- draw(context, delta) {
- this.main.draw(context, delta);
- this.navigation.draw();
- }
- handleResize(event) {
- if (this.navigation) {
- this.navigation.handleResize(event);
- }
- }
- updateInventory() {
- this.inventory.buildInventory();
- }
- }
|