Module:Ingredients

local p = {}

local utils = require("Module:Utils")

local loreColors = { grail = "fe6150", moth = "f2e9c2", lantern = "ffe300", forge = "ff8e3e", heart = "fe7e8b", edge = "d7dd49", winter = "beeeff", knock = "b54efc", secrethistories = "fe43f0" }

local auctionableToFunds = { [1] = 1,   [2] = 2,    [3] = 4,    [4] = 8,    [5] = 16,    [6] = 20 }

function renderAspects(aspects) local aspectsData = mw.loadData("Module:Aspects/data")

local t = {}

for aspect, value in pairs(aspects) do       if loreColors[aspect] then table.insert(               t,                "' .. aspectsData[aspect].label .. "  " .. value            ) else if value == 1 then table.insert(t, "" .. aspectsData[aspect].label .. "") else table.insert(t, "" .. aspectsData[aspect].label .. " " .. value) end end end

return table.concat(t, " ") end

function getIngredientLocations(ingredientId) local vaults = mw.loadData("Module:Vaults/data") local vaultRewards = mw.loadData("Module:Vaults/rewardsData") local ingredients = mw.loadData("Module:Ingredients/data")

local t = {}

for _, vault in pairs(vaults) do       if vault.rewards[ingredientId] then table.insert(t, "" .. vault.label .. "") end if vault.randomRewards then for deckId in pairs(vault.randomRewards) do               if utils.listContainsItem(vaultRewards[deckId].items, ingredientId) then table.insert(t, "" .. vault.label .. " chance") end end end end

return t end

local function renderIngredientInfoBox(id, ingredient) return string.format(       ' ',        ingredient.label,        ingredient.label:gsub(" ", "_"),        renderAspects(ingredient.aspects),        ingredient.unique and " Unique" or "",        id    ) end

function p.byName(frame) local aspectsData = mw.loadData("Module:Aspects/data")

frame = frame or {args = {}} local pageTitle = frame.args[1] or frame.args["name"] or mw.title.getCurrentTitle.text local extraHeader = frame.args["header"] or ""

-- for debugging; if it's on the module page set the title to something known if pageTitle == "Ingredients" then pageTitle = "Holiest Hemolymph" end

local ingredientId, ingredient ingredientId, ingredient = utils.findByLabel(mw.loadData("Module:Ingredients/data"), pageTitle) if ingredientId == nil then ingredientId, ingredient = utils.findByLabel(mw.loadData("Module:Mundane/data"), pageTitle) end if ingredientId == nil then ingredientId, ingredient = utils.findByLabel(mw.loadData("Module:Tools/data"), pageTitle) end

local t = {}

table.insert(t, renderIngredientInfoBox(ingredientId, ingredient))

local ingredientPrinciple, principleLevel

for aspect, value in pairs(ingredient.aspects) do       if (loreColors[aspect]) then ingredientPrinciple = aspect principleLevel = value end end

table.insert(       t,        "" ..            pageTitle ..                " is the ' ..                                    aspectsData[ingredientPrinciple].label ..                                        "  " .. principleLevel .. " Ingredient. "    )

local auctionable = ingredient.aspects["auctionable"] local auctionableText = "" if auctionable then auctionableText = string.format(", or sold at auction for a minimum of %s", frame:expandTemplate{ title = "Funds", args = { auctionableToFunds[auctionable] } }) end table.insert(t, string.format("It can be used in any Rite with the appropriate slot%s.", auctionableText))

--this should be updated to display the name of the masterpiece if ingredient.aspects["pigment"] then table.insert(           t,            "It can also be used to Paint to create the  ' .. aspectsData[ingredientPrinciple].label .. "  Masterpiece."        ) end if ingredient.aspects["poison"] then table.insert(           t,            "Additionally, it can be used in Talk with a non-Wary Hunter to poison them, which will kill them unless they are Tenacious."        ) end

table.insert(t, extraHeader)

table.insert(t, "== Text ==") table.insert(t, utils.renderQuote(ingredient.description, "Description"))

local locations = getIngredientLocations(ingredientId) if #locations > 0 then table.insert(t, "== Locations ==") for _, location in ipairs(locations) do           if (location:sub(-6) == "chance") then table.insert(t, "* " .. location .. " of receiving as reward for completing this vault") else table.insert(t, "* " .. location) end end end

table.insert(t, "") table.insert(t, "") if ingredient.unique then table.insert(t, "") end return table.concat(t, "\n") end

--list and byAspect functions are incomplete - don't use yet. need to add Poison, Pigment, etc. info to them.

function p.list(frame) local ingredients = mw.loadData("Module:Ingredients/data") local aspectsData = mw.loadData("Module:Aspects/data")

local t = {} table.insert(t, '{| class="wikitable sortable"') table.insert(t, "|+") table.insert(t, '!style="width: 30%"|Name') table.insert(t, "!Principle") table.insert(t, "!Level")

local ingredientLabelToId = {} local ingredientLabels = {} for ingredientId, ingredient in pairs(ingredients) do       ingredientLabelToId[ingredient.label] = ingredientId table.insert(ingredientLabels, ingredient.label) end table.sort(ingredientLabels)

for _, ingredientLabel in ipairs(ingredientLabels) do       local ingredientId = ingredientLabelToId[ingredientLabel] local ingredient = ingredients[ingredientId] if ingredient.aspects.ingredient then table.insert(t, "|-") table.insert(t, "|" .. ingredient.label .. "") table.insert(t, "|") for aspect, value in pairs(ingredient.aspects or {}) do               if loreColors[aspect] then table.insert(                       t,                        "' .. aspectsData[aspect].label .. " "                    )

table.insert(t, "|" .. value) break end end table.insert(t, "|") end end

table.insert(t, "|}")

return table.concat(t, "\n") end

function p.byAspect(frame) local pageAspect = (frame or {args = {}}).args[1] or "winter" local ingredients = mw.loadData("Module:Ingredients/data")

local ingredientLabels = {} local ingredientLabelToAspectLevel = {} local ingredientLabelToDescription = {} for _, ingredient in pairs(ingredients) do       if ingredient.aspects[pageAspect] then table.insert(ingredientLabels, ingredient.label) ingredientLabelToAspectLevel[ingredient.label] = ingredient.aspects[pageAspect] ingredientLabelToDescription[ingredient.label] = ingredient.description end end

table.sort(ingredientLabels)

local t = {} table.insert(t, '{| class="wikitable sortable"') table.insert(t, "|+") table.insert(t, "!Ingredient") table.insert(t, "!Aspect level") table.insert(t, "!Description") for _, label in pairs(ingredientLabels) do       table.insert(t, "|-") table.insert(t, "|" .. label .. "") table.insert(t, "|" .. ingredientLabelToAspectLevel[label]) table.insert(t, "|" .. ingredientLabelToDescription[label]) end table.insert(t, "|}") return table.concat(t, "\n") end

return p