add findShipDef/findModuleDef/findRecipeDef to config structs and re-use them in the rest of the code base
This commit is contained in:
@@ -243,14 +243,7 @@ private:
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
for (const ModuleDef& def : m_config->modules.modules)
|
||||
{
|
||||
if (def.id == id)
|
||||
{
|
||||
return &def;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
return m_config->modules.findModuleDef(id);
|
||||
}
|
||||
|
||||
std::vector<std::string> rotateMask(const std::vector<std::string>& mask,
|
||||
@@ -426,13 +419,10 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
|
||||
setModal(true);
|
||||
|
||||
// Find the ship's layout grid.
|
||||
for (const ShipDef& def : config->ships.ships)
|
||||
const ShipDef* shipDef = config->ships.findShipDef(shipId);
|
||||
if (shipDef)
|
||||
{
|
||||
if (def.id == shipId)
|
||||
{
|
||||
m_shipLayout = def.layout;
|
||||
break;
|
||||
}
|
||||
m_shipLayout = shipDef->layout;
|
||||
}
|
||||
|
||||
m_rows = static_cast<int>(m_shipLayout.size());
|
||||
@@ -706,11 +696,7 @@ void ShipLayoutDialog::rebuildOccupancy()
|
||||
for (int i = 0; i < static_cast<int>(m_placedModules.size()); ++i)
|
||||
{
|
||||
const PlacedModule& pm = m_placedModules[i];
|
||||
const ModuleDef* def = nullptr;
|
||||
for (const ModuleDef& d : m_config->modules.modules)
|
||||
{
|
||||
if (d.id == pm.moduleId) { def = &d; break; }
|
||||
}
|
||||
const ModuleDef* def = m_config->modules.findModuleDef(pm.moduleId);
|
||||
if (!def)
|
||||
{
|
||||
continue;
|
||||
@@ -807,11 +793,7 @@ void ShipLayoutDialog::loadLayoutBlueprint(const std::vector<PlacedModule>& modu
|
||||
for (const PlacedModule& pm : modules)
|
||||
{
|
||||
// Validate module type exists and is unlocked.
|
||||
const ModuleDef* def = nullptr;
|
||||
for (const ModuleDef& d : m_config->modules.modules)
|
||||
{
|
||||
if (d.id == pm.moduleId) { def = &d; break; }
|
||||
}
|
||||
const ModuleDef* def = m_config->modules.findModuleDef(pm.moduleId);
|
||||
if (!def || m_unlockedModuleIds.count(def->id) == 0) { continue; }
|
||||
|
||||
const std::vector<std::string> mask = rotatedMask(*def, pm.rotation);
|
||||
|
||||
Reference in New Issue
Block a user