Module:RecipeDetails/data

From IdleOn MMO Wiki

Find the generated data string in the Doccumenation page.


local data = {}
local cargo = mw.ext.cargo
-- Query smithing table for the recipe and retrieve the ingeredients
local function _buildRecipeTable()
	local allRecipes = {}
	-- Query
    local args = {
        orderBy = 'AnvilCraft.Item'
    }
    local recipes = cargo.query('AnvilCraft', 'Item, Resource1, Quantity1, Resource2, Quantity2, Resource3, Quantity3, Resource4, Quantity4', args )
    if #recipes == 0 then return {} end -- if no results, exit with an empty table.
    for r=1, #recipes do
    	local itemRecipe = {}
    	local itemName = recipes[r].Item
    	itemRecipe.Item = itemName
    	local recipeArray = {}
	    for n=1, 4 do
	    	if recipes[r]['Resource'..n] == nil or recipes[r]['Resource'..n] == '' then break end -- If an empty cell is encountered, stop processing items.
	    	-- Append item and resource to array.
	    	recipeArray[#recipeArray+1] = recipes[r]['Resource'..n]
	    	recipeArray[#recipeArray+1] = recipes[r]['Quantity'..n]
	    end
	    itemRecipe.Recipe = recipeArray
	    -- Set item index to name of item.
	    allRecipes[itemName] = itemRecipe
	end
    -- Item = { Item = Item_Name, Recipe = {Item1, Amount1, Item2, Amount2, ...} }
	return allRecipes
end

data.allRecipes = _buildRecipeTable()
return data