fix blueprint rotation bug

This commit is contained in:
2026-04-26 22:36:49 +02:00
parent 1e2135dc5b
commit 7859b38d62
2 changed files with 143 additions and 12 deletions

View File

@@ -2,6 +2,7 @@
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <map>
#include <string>
@@ -936,7 +937,17 @@ void GameWorldView::keyPressEvent(QKeyEvent* event)
{
for (BlueprintBuilding& bb : m_blueprintMode->buildings)
{
bb.offset = QPoint(-bb.offset.y(), bb.offset.x());
const BuildingDef* def = findBuildingDef(bb.type);
if (!def) { continue; }
const ParsedSurfaceMask mask = parseSurfaceMask(def->surfaceMask, bb.rotation);
int minX = INT_MAX, minY = INT_MAX;
for (const QPoint& cell : mask.bodyCells)
{
const QPoint abs = bb.offset + cell;
minX = std::min(minX, -abs.y());
minY = std::min(minY, abs.x());
}
bb.offset = QPoint(minX, minY);
bb.rotation = rotateClockwise(bb.rotation);
}
}
@@ -951,7 +962,17 @@ void GameWorldView::keyPressEvent(QKeyEvent* event)
{
for (BlueprintBuilding& bb : m_blueprintMode->buildings)
{
bb.offset = QPoint(bb.offset.y(), -bb.offset.x());
const BuildingDef* def = findBuildingDef(bb.type);
if (!def) { continue; }
const ParsedSurfaceMask mask = parseSurfaceMask(def->surfaceMask, bb.rotation);
int minX = INT_MAX, minY = INT_MAX;
for (const QPoint& cell : mask.bodyCells)
{
const QPoint abs = bb.offset + cell;
minX = std::min(minX, abs.y());
minY = std::min(minY, -abs.x());
}
bb.offset = QPoint(minX, minY);
bb.rotation = rotateCounterClockwise(bb.rotation);
}
}