mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-02-12 02:49:20 +00:00
Shortened and simplified shape tooltip code
This commit is contained in:
parent
d0a580a685
commit
6ba12f094f
@ -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,36 +25,17 @@ 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,7 +43,28 @@ export class HUDShapeTooltip extends BaseHUDPart {
|
|||||||
* @param {DrawParameters} parameters
|
* @param {DrawParameters} parameters
|
||||||
*/
|
*/
|
||||||
draw(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 ejectorComp = this.currentEntity.components.ItemEjector;
|
||||||
const staticComp = this.currentEntity.components.StaticMapEntity;
|
const staticComp = this.currentEntity.components.StaticMapEntity;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user