remove the last duplicate findModuleDef from ShipLayoutPreview
ShipLayoutPreview was the one widget the findFooDef sweep missed: it held a bare const std::vector<ModuleDef>* rather than a config, so the shared ModulesConfig::findModuleDef was not a drop-in and the file-local copy survived. Hold the ModulesConfig instead and call the shared finder. The sole caller already had the ModulesConfig one dereference away. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YHcUerKAZKWNvSKJxYKbnG
This commit is contained in:
@@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user