Module:RecipeList

local p = {}

local recipes = mw.loadData('Module:Recipes') local craftingStationInheritances = { ["Craftsman's Workbench"] = {"Workbench"}; ["Tinkerer's Workbench"] = {"Craftsman's Workbench", "Workbench"}; ["Advanced Drafting Table"] = {"Drafting Table"}; ["Blueprint Table"] = {"Advanced Drafting Table", "Drafting Table"}; ["Advanced Smithy"] = {"Smithy"}; ["Culinary Kitchen"] = {"Culinary Site"}; ["Harbor"] = {"Dock"}; }; function getRecipeWikitext(recipeName, recipeData) wikitext = "" for _, ingredient in pairs(recipeData.Ingredients) do       wikitext = wikitext .. "" .. ingredient .. " + " end wikitext = wikitext .. " > Craft through " .. recipeData.CraftingStation .. " > " .. recipeName .. " \n" return wikitext end function p.CreateRecipeList(Frame) wikitext = "" for categoryName, categoryItems in pairs(recipes) do       wikitext = wikitext .. "== " .. categoryName .. " ==\n" for recipeName, recipeData in pairs(categoryItems) do           wikitext = wikitext .. "=== " .. recipeName .. " ===\n" if recipeData.Ingredients == nil then --There are multiple recipes for this item, so recipeData is a list of recipes. for _, innerRecipeData in pairs(recipeData) do                   wikitext = wikitext .. getRecipeWikitext(recipeName, innerRecipeData) end else wikitext = wikitext .. getRecipeWikitext(recipeName, recipeData) end end end return wikitext end

local extraRecipes = { ["Refined Steel"] = "Steel Mix", ["Pure Bluesteel"] = "Raw Bluesteel" }

local materialOverrides = { ["Boulder"] = {"Boulder"}, ["String"] = {"Flax"}, ["Raw Bluesteel"] = {}, --REALLY hacky fix - the material for all 6 crafts of this recipe are added after the list is processed ["Small Stone"] = {"Small Stone"}, ["Wall"] = {"Plank", "Plank"}, ["Green Dye"] = {"Leaves"}, ["Sandstone Brick"] = {"Sandstone Brick"} }

function GetRawMaterials(item, isRecursive) --Early exit if one of the specified materials is in the overrides list. --Excludes the case where this material is specifically being crafted for JoAT. if isRecursive then if materialOverrides[item] then return materialOverrides[item] end end if extraRecipes[item] then return GetRawMaterials(extraRecipes[item], true) end for _, categoryItems in pairs(recipes) do       if categoryItems[item] ~= nil then local recipeData = categoryItems[item] local ingredients = {} if recipeData.Ingredients == nil then --There are multiple recipes for this item, so recipeData is a list of recipes ingredients = recipeData[1].Ingredients else ingredients = recipeData.Ingredients end local rawMaterials = {} for _, ingredient in pairs(ingredients) do               for _, rawMaterial in pairs(GetRawMaterials(ingredient, true)) do                    table.insert(rawMaterials, rawMaterial) end end return rawMaterials end end return {item} end

function p.CreateRawMaterialList(Frame) local totalRawMaterials = {} for _, categoryItems in pairs(recipes) do       for recipeName, _ in pairs(categoryItems) do            for _, rawMaterial in pairs(GetRawMaterials(recipeName)) do                if totalRawMaterials[rawMaterial] == nil then totalRawMaterials[rawMaterial] = 1 else totalRawMaterials[rawMaterial] = totalRawMaterials[rawMaterial] + 1 end end end end --This system can't handle an intermediate product being crafted in quantities larger --than one, and will craft intermediates one extra time unncessarily. --This isn't very important, except for the Raw Bluesteel case, which is handled here. for i = 1, 6 do       for _, ingredient in pairs({"Charcoal", "Refined Gold", "Refined Steel", "Refined Steel", "Refined Steel", "Refined Chromium", "Refined Chromium", "Refined Chromium", "Refined Chromium", "Refined Chromium", "Teraphyx Dust"}) do            for _, rawMaterial in pairs(GetRawMaterials(ingredient)) do                if totalRawMaterials[rawMaterial] == nil then totalRawMaterials[rawMaterial] = 1 else totalRawMaterials[rawMaterial] = totalRawMaterials[rawMaterial] + 1 end end end end totalRawMaterialsArray = {} for key, value in pairs(totalRawMaterials) do       table.insert(totalRawMaterialsArray, {key, value}) end table.sort(totalRawMaterialsArray, function(item1, item2)           if item1[2] > item2[2] then                return true            end            return false        end) text = "" for _, material in pairs(totalRawMaterialsArray) do       text = text .. material[1] .. ": " .. material[2] .. "\n" end return text end

return p