remove duplicate findModuleDef from ShipLayoutPreview

This commit is contained in:
2026-08-03 22:00:25 +02:00
parent 785ce3ebfe
commit edd1c31785
3 changed files with 6 additions and 19 deletions

View File

@@ -604,7 +604,7 @@ void SelectedBuildingPanel::updateShipyardLayoutWidgets(
layout = *shipLayout; layout = *shipLayout;
} }
m_layoutPreview->setShipAndLayout( m_layoutPreview->setShipAndLayout(
shipDef->layout, layout, &m_config->modules.modules); shipDef->layout, layout, &m_config->modules);
} }
else else
{ {

View File

@@ -12,19 +12,6 @@ const int kCellSize = 8;
const int kPlaceholderWidth = 64; const int kPlaceholderWidth = 64;
const int kPlaceholderHeight = 40; const int kPlaceholderHeight = 40;
const ModuleDef* findModuleDef(const std::vector<ModuleDef>& modules,
const std::string& id)
{
for (const ModuleDef& def : modules)
{
if (def.id == id)
{
return &def;
}
}
return nullptr;
}
std::vector<std::string> rotateMaskCW(const std::vector<std::string>& grid) std::vector<std::string> rotateMaskCW(const std::vector<std::string>& grid)
{ {
if (grid.empty()) if (grid.empty())
@@ -113,7 +100,7 @@ void ShipLayoutPreview::showPlaceholder()
void ShipLayoutPreview::setShipAndLayout(const std::vector<std::string>& shipLayout, void ShipLayoutPreview::setShipAndLayout(const std::vector<std::string>& shipLayout,
const ShipLayoutConfig& layout, const ShipLayoutConfig& layout,
const std::vector<ModuleDef>* modules) const ModulesConfig* modules)
{ {
m_placeholder = false; m_placeholder = false;
m_modules = modules; m_modules = modules;
@@ -144,7 +131,7 @@ void ShipLayoutPreview::setShipAndLayout(const std::vector<std::string>& shipLay
for (int i = 0; i < static_cast<int>(m_placedModules.size()); ++i) for (int i = 0; i < static_cast<int>(m_placedModules.size()); ++i)
{ {
const PlacedModule& pm = m_placedModules[i]; const PlacedModule& pm = m_placedModules[i];
const ModuleDef* def = findModuleDef(*m_modules, pm.moduleId); const ModuleDef* def = m_modules->findModuleDef(pm.moduleId);
if (!def) if (!def)
{ {
continue; continue;
@@ -208,7 +195,7 @@ void ShipLayoutPreview::paintEvent(QPaintEvent* /*event*/)
else if (cell.moduleIndex.has_value()) else if (cell.moduleIndex.has_value())
{ {
const PlacedModule& pm = m_placedModules[*cell.moduleIndex]; const PlacedModule& pm = m_placedModules[*cell.moduleIndex];
const ModuleDef* def = findModuleDef(*m_modules, pm.moduleId); const ModuleDef* def = m_modules->findModuleDef(pm.moduleId);
QColor color(Qt::gray); QColor color(Qt::gray);
if (def) if (def)
{ {

View File

@@ -18,7 +18,7 @@ public:
void setShipAndLayout(const std::vector<std::string>& shipLayout, void setShipAndLayout(const std::vector<std::string>& shipLayout,
const ShipLayoutConfig& layout, const ShipLayoutConfig& layout,
const std::vector<ModuleDef>* modules); const ModulesConfig* modules);
void clear(); void clear();
// Shows an empty placeholder box (no ship layout) so the preview stays // Shows an empty placeholder box (no ship layout) so the preview stays
@@ -37,7 +37,7 @@ private:
std::vector<std::vector<CellInfo>> m_grid; std::vector<std::vector<CellInfo>> m_grid;
std::vector<PlacedModule> m_placedModules; std::vector<PlacedModule> m_placedModules;
const std::vector<ModuleDef>* m_modules; const ModulesConfig* m_modules;
int m_rows; int m_rows;
int m_cols; int m_cols;
bool m_placeholder = false; bool m_placeholder = false;