Page 1 of 1

Parsing recipes subgroups ?

Posted: Sat Jul 23, 2016 11:29 pm
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 ?

Re: Parsing recipes subgroups ?

Posted: Sun Jul 24, 2016 9:41 am
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

Re: Parsing recipes subgroups ?

Posted: Sun Jul 24, 2016 10:12 am
by binbinhfr
Yes, that's what I did...