add findShipDef/findModuleDef/findRecipeDef to config structs and re-use them in the rest of the code base

This commit is contained in:
2026-08-03 20:57:31 +02:00
parent af6828c348
commit 553a7e0701
12 changed files with 100 additions and 189 deletions

View File

@@ -47,4 +47,32 @@ struct RecipeDef
struct RecipesConfig
{
std::vector<RecipeDef> recipes;
// Returns the definition for the given recipe id, or nullptr if the id has
// no entry in recipes.toml.
const RecipeDef* findRecipeDef(const std::string& id) const
{
for (const RecipeDef& recipe : recipes)
{
if (recipe.id == id)
{
return &recipe;
}
}
return nullptr;
}
// Same, but additionally requires the recipe to belong to the given building
// type — recipe ids are only unique per building type.
const RecipeDef* findRecipeDef(const std::string& id, BuildingType building) const
{
for (const RecipeDef& recipe : recipes)
{
if (recipe.id == id && recipe.building == building)
{
return &recipe;
}
}
return nullptr;
}
};