Parsing recipes subgroups ?

Place to get help with not working mods / modding interface.
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1525
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Parsing recipes subgroups ?

Post by binbinhfr »

Hi,

On LuaRecipe, you have group and subgroup that points to LuaGroup.
But I'd like to create a recipe browser (like the one that is used for crafting).
Is there a simple way to parse these groups/subgroups to recipes ?
Because I do not see any LuaForce.groups giving a liste of main groups,
not a LuaGroup.recipes giving the list of recipes in a subgroup...

Do I have to do this painful reverse engineering ?
My mods on the Factorio Mod Portal :geek:
Helfima
Fast Inserter
Fast Inserter
Posts: 202
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: Parsing recipes subgroups ?

Post by Helfima »

loop on all recipes and build group and subgroup tables.

@see https://github.com/Helfima/helmod/blob/ ... roller.lua

Code: Select all

-------------------------------------------------------------------------------
-- Return recipe groups
--
-- @function [parent=#PlayerController] getRecipeGroups
--
-- @param #LuaPlayer player
--
-- @return #table recipe groups
--
function PlayerController.methods:getRecipeGroups(player)
	-- recuperation des groupes avec les recipes
	local recipeGroups = {}
	for key, recipe in pairs(self:getRecipes(player)) do
		if recipe.group ~= nil then
			if recipeGroups[recipe.group.name] == nil then recipeGroups[recipe.group.name] = {} end
			table.insert(recipeGroups[recipe.group.name], recipe.name)
		end
	end
	return recipeGroups
end
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1525
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: Parsing recipes subgroups ?

Post by binbinhfr »

Yes, that's what I did...
My mods on the Factorio Mod Portal :geek:
Post Reply

Return to “Modding help”