1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-02-12 19:09:21 +00:00

Shortened and simplified shape tooltip code

This commit is contained in:
Sense101 2021-07-01 14:01:21 +01:00
parent d0a580a685
commit 6ba12f094f

View File

@ -15,7 +15,6 @@ export class HUDShapeTooltip extends BaseHUDPart {
this.currentEntity = null; this.currentEntity = null;
this.isPlacingBuilding = false; this.isPlacingBuilding = false;
this.active = false;
this.root.signals.entityQueuedForDestroy.add(() => { this.root.signals.entityQueuedForDestroy.add(() => {
this.currentEntity = null; this.currentEntity = null;
@ -26,24 +25,28 @@ export class HUDShapeTooltip extends BaseHUDPart {
}, this); }, this);
} }
update() { isActive() {
// don't show the tooltip when any other placer is active
const hudParts = this.root.hud.parts; 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.root.keyMapper.getBinding(KEYMAPPINGS.ingame.showShapeTooltip).pressed &&
!this.isPlacingBuilding && !this.isPlacingBuilding &&
!hudParts.massSelector.currentSelectionStartWorld && !hudParts.massSelector.currentSelectionStartWorld &&
hudParts.massSelector.selectedUids.size < 1 && hudParts.massSelector.selectedUids.size < 1 &&
!hudParts.blueprintPlacer.currentBlueprint.get(); !hudParts.blueprintPlacer.currentBlueprint.get()
);
const mousePos = this.root.app.mousePosition;
if (!mousePos) {
// Not on screen
return;
} }
/**
*
* @param {DrawParameters} parameters
*/
draw(parameters) {
if (this.isActive()) {
const mousePos = this.root.app.mousePosition;
if (mousePos) {
const tile = this.root.camera.screenToWorld(mousePos.copy()).toTileSpace(); const tile = this.root.camera.screenToWorld(mousePos.copy()).toTileSpace();
if (!tile.equals(this.currentTile)) { if (!tile.equals(this.currentTile)) {
this.currentTile = tile; this.currentTile = tile;
@ -58,12 +61,10 @@ export class HUDShapeTooltip extends BaseHUDPart {
} }
} }
/** if (!this.currentEntity) {
* return;
* @param {DrawParameters} parameters }
*/
draw(parameters) {
if (this.active && this.currentEntity) {
const ejectorComp = this.currentEntity.components.ItemEjector; const ejectorComp = this.currentEntity.components.ItemEjector;
const staticComp = this.currentEntity.components.StaticMapEntity; const staticComp = this.currentEntity.components.StaticMapEntity;