mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 18:56:38 +00:00
Consolidated the duplicate tile lookup into a single getTileFromScreenCoords(x, y)
This commit is contained in:
@@ -264,7 +264,7 @@ export class NukeTrajectoryPreviewLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
// Shared helper to resolve the current target tile, preferring a locked ghost tile when present
|
||||
// resolve the current target tile, preferring a locked ghost tile when present
|
||||
private getTargetTile(): TileRef | null {
|
||||
if (this.uiState.lockedGhostTile) {
|
||||
return this.uiState.lockedGhostTile;
|
||||
|
||||
@@ -558,24 +558,22 @@ export class StructureIconsLayer implements Layer {
|
||||
this.removeGhostStructure();
|
||||
}
|
||||
|
||||
private getTileFromContextMenuEvent(e: ContextMenuEvent): TileRef | null {
|
||||
private getTileFromScreenCoords(x: number, y: number): TileRef | null {
|
||||
const rect = this.transformHandler.boundingRect();
|
||||
if (!rect) return null;
|
||||
const x = e.x - rect.left;
|
||||
const y = e.y - rect.top;
|
||||
const tile = this.transformHandler.screenToWorldCoordinates(x, y);
|
||||
const localX = x - rect.left;
|
||||
const localY = y - rect.top;
|
||||
const tile = this.transformHandler.screenToWorldCoordinates(localX, localY);
|
||||
if (!this.game.isValidCoord(tile.x, tile.y)) return null;
|
||||
return this.game.ref(tile.x, tile.y);
|
||||
}
|
||||
|
||||
private getTileFromContextMenuEvent(e: ContextMenuEvent): TileRef | null {
|
||||
return this.getTileFromScreenCoords(e.x, e.y);
|
||||
}
|
||||
|
||||
private getTileFromMouseEvent(e: MouseUpEvent): TileRef | null {
|
||||
const rect = this.transformHandler.boundingRect();
|
||||
if (!rect) return null;
|
||||
const x = e.x - rect.left;
|
||||
const y = e.y - rect.top;
|
||||
const tile = this.transformHandler.screenToWorldCoordinates(x, y);
|
||||
if (!this.game.isValidCoord(tile.x, tile.y)) return null;
|
||||
return this.game.ref(tile.x, tile.y);
|
||||
return this.getTileFromScreenCoords(e.x, e.y);
|
||||
}
|
||||
|
||||
private resolveTargetTileFromEvent(e: MouseUpEvent): TileRef | null {
|
||||
|
||||
Reference in New Issue
Block a user