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;
|
||||
}
|
||||
m_layoutPreview->setShipAndLayout(
|
||||
shipDef->layout, layout, &m_config->modules.modules);
|
||||
shipDef->layout, layout, &m_config->modules);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -12,19 +12,6 @@ const int kCellSize = 8;
|
||||
const int kPlaceholderWidth = 64;
|
||||
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)
|
||||
{
|
||||
if (grid.empty())
|
||||
@@ -113,7 +100,7 @@ void ShipLayoutPreview::showPlaceholder()
|
||||
|
||||
void ShipLayoutPreview::setShipAndLayout(const std::vector<std::string>& shipLayout,
|
||||
const ShipLayoutConfig& layout,
|
||||
const std::vector<ModuleDef>* modules)
|
||||
const ModulesConfig* modules)
|
||||
{
|
||||
m_placeholder = false;
|
||||
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)
|
||||
{
|
||||
const PlacedModule& pm = m_placedModules[i];
|
||||
const ModuleDef* def = findModuleDef(*m_modules, pm.moduleId);
|
||||
const ModuleDef* def = m_modules->findModuleDef(pm.moduleId);
|
||||
if (!def)
|
||||
{
|
||||
continue;
|
||||
@@ -208,7 +195,7 @@ void ShipLayoutPreview::paintEvent(QPaintEvent* /*event*/)
|
||||
else if (cell.moduleIndex.has_value())
|
||||
{
|
||||
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);
|
||||
if (def)
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
|
||||
void setShipAndLayout(const std::vector<std::string>& shipLayout,
|
||||
const ShipLayoutConfig& layout,
|
||||
const std::vector<ModuleDef>* modules);
|
||||
const ModulesConfig* modules);
|
||||
void clear();
|
||||
|
||||
// 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<PlacedModule> m_placedModules;
|
||||
const std::vector<ModuleDef>* m_modules;
|
||||
const ModulesConfig* m_modules;
|
||||
int m_rows;
|
||||
int m_cols;
|
||||
bool m_placeholder = false;
|
||||
|
||||
Reference in New Issue
Block a user