From 6ba12f094f06df4ae6ddb513ed857db806f47bab Mon Sep 17 00:00:00 2001 From: Sense101 <67970865+Sense101@users.noreply.github.com> Date: Thu, 1 Jul 2021 14:01:21 +0100 Subject: [PATCH] Shortened and simplified shape tooltip code --- src/js/game/hud/parts/shape_tooltip.js | 53 +++++++++++++------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/js/game/hud/parts/shape_tooltip.js b/src/js/game/hud/parts/shape_tooltip.js index 690dae7e..282d963c 100644 --- a/src/js/game/hud/parts/shape_tooltip.js +++ b/src/js/game/hud/parts/shape_tooltip.js @@ -15,7 +15,6 @@ export class HUDShapeTooltip extends BaseHUDPart { this.currentEntity = null; this.isPlacingBuilding = false; - this.active = false; this.root.signals.entityQueuedForDestroy.add(() => { this.currentEntity = null; @@ -26,36 +25,17 @@ export class HUDShapeTooltip extends BaseHUDPart { }, this); } - update() { - // don't show the tooltip when any other placer is active + isActive() { const hudParts = this.root.hud.parts; - this.active = + // return false if any other placer is active + return ( this.root.keyMapper.getBinding(KEYMAPPINGS.ingame.showShapeTooltip).pressed && !this.isPlacingBuilding && !hudParts.massSelector.currentSelectionStartWorld && hudParts.massSelector.selectedUids.size < 1 && - !hudParts.blueprintPlacer.currentBlueprint.get(); - - const mousePos = this.root.app.mousePosition; - - if (!mousePos) { - // Not on screen - return; - } - - const tile = this.root.camera.screenToWorld(mousePos.copy()).toTileSpace(); - if (!tile.equals(this.currentTile)) { - this.currentTile = tile; - - const entity = this.root.map.getLayerContentXY(tile.x, tile.y, this.root.currentLayer); - - if (entity && entity.components.ItemProcessor && entity.components.ItemEjector) { - this.currentEntity = entity; - } else { - this.currentEntity = null; - } - } + !hudParts.blueprintPlacer.currentBlueprint.get() + ); } /** @@ -63,7 +43,28 @@ export class HUDShapeTooltip extends BaseHUDPart { * @param {DrawParameters} parameters */ draw(parameters) { - if (this.active && this.currentEntity) { + if (this.isActive()) { + const mousePos = this.root.app.mousePosition; + + if (mousePos) { + const tile = this.root.camera.screenToWorld(mousePos.copy()).toTileSpace(); + if (!tile.equals(this.currentTile)) { + this.currentTile = tile; + + const entity = this.root.map.getLayerContentXY(tile.x, tile.y, this.root.currentLayer); + + if (entity && entity.components.ItemProcessor && entity.components.ItemEjector) { + this.currentEntity = entity; + } else { + this.currentEntity = null; + } + } + } + + if (!this.currentEntity) { + return; + } + const ejectorComp = this.currentEntity.components.ItemEjector; const staticComp = this.currentEntity.components.StaticMapEntity;