Module:RecipeDetails/data: Difference between revisions
From IdleOn MMO Wiki
Kiokurashi (talk | contribs) mNo edit summary |
Kiokurashi (talk | contribs) mNo edit summary |
||
Line 13: | Line 13: | ||
local itemRecipe = {} | local itemRecipe = {} | ||
local itemName = recipes[r].Item | local itemName = recipes[r].Item | ||
local recipeArray = {} | local recipeArray = {} | ||
for n=1, 4 do | for n=1, 4 do | ||
Line 21: | Line 20: | ||
recipeArray[#recipeArray+1] = recipes[r]['Quantity'..n] | recipeArray[#recipeArray+1] = recipes[r]['Quantity'..n] | ||
end | end | ||
itemRecipe | itemRecipe = recipeArray | ||
-- Set item index to name of item. | -- Set item index to name of item. | ||
allRecipes[itemName] = itemRecipe | allRecipes[itemName] = itemRecipe | ||
end | end | ||
-- Item = { | -- Item = { Recipe = {Item1, Amount1, Item2, Amount2, ...} } | ||
return allRecipes | return allRecipes | ||
end | end |
Revision as of 18:50, 12 April 2024
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
data.allRecipes = _buildRecipeTable()
return data