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
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 = recipeArray
-- Set item index to name of item.
allRecipes[itemName] = itemRecipe
end
-- Item = { Recipe = {Item1, Amount1, Item2, Amount2, ...} }
return allRecipes
end
function data.generateTableOut()
local fullList = _buildRecipeTable()
local tableStrings = {}
for item, recipe in pairs(fullList) do
local str = '["' .. item .. '"] = {'
for n=1, #recipe do
if recipe[n]:type() == 'number' then str = str .. recipe[n] else str = str .. '"' .. recipe[n] .. '"' end
if n < #recipe then str = str .. ", " else str = str .. "}" end
end
tableStrings[#tableStrings+1] = str
end
return "data.allRecipes = {" .. table.concat(tableStrings, ", ") .. "}"
end
data.allRecipes = {}
return data