add findShipDef/findModuleDef/findRecipeDef to config structs and re-use them in the rest of the code base
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user