Module:Tools

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" }

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 getToolLocations(toolId) local vaults = mw.loadData("Module:Vaults/data") local vaultRewards = mw.loadData("Module:Vaults/rewardsData") local tools = mw.loadData("Module:Tools/data") local crackedToolId = toolId .. "cracked"

local t = {}

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

return t end

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

function p.byName(frame) local tools = mw.loadData("Module:Tools/data") local aspectsData = mw.loadData("Module:Aspects/data") local ingredientsData = mw.loadData("Module:Ingredients/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 == "Tools" then pageTitle = "Alakapurine Shears" end

local toolId, tool = utils.findByLabel(tools, pageTitle)

local t = {}

table.insert(t, renderToolInfoBox(toolId, tool)) local toolPrinciple, principleLevel local isMirror = false local crackedTool = tools[toolId .. "cracked"] for aspect, value in pairs(tool.aspects) do       if (loreColors[aspect]) then toolPrinciple = aspect principleLevel = value end if (aspect == "mirror") then isMirror = true end end

table.insert(t, "" .. pageTitle .. " is the ' .. aspectsData[toolPrinciple].label .. "  " .. principleLevel .. " Tool. ") table.insert(t, "It can be used in any Rite with the appropriate slot, or gifted to a follower to increase their ' .. aspectsData[toolPrinciple].label .. "  by " .. principleLevel/4 .. " and reduce their Resentment by 1. ") if (isMirror) then table.insert(t, "It can also be used to enter the Peacock Door. Using it this way will cause it to become a " .. crackedTool.label .. ". ") end if (toolId == "toolknockf") then table.insert(t, "It can also be used to enter the Peacock Door. Using it this way will not cause it to break, unlike the other methods of entering the Peacock door. ") end if (crackedTool) then table.insert(t, "The cracked version can be repaired by a ' .. aspectsData["forge"].label .. " -aspected Follower at the cost of ") if (toolId == "toollanternb") then table.insert(t, frame:expandTemplate{ title = "Funds", args = { "one" } } .. ". ") end if (toolId == "toollanternd") then table.insert(t, "a Bronze Spintria or better. ") end if (toolId == "toollanternf") then table.insert(t, "a Silver Spintria. ") end end table.insert(t, extraHeader)

table.insert(t, "== Text ==") table.insert(t, utils.renderQuote(tool.description, "Description")) if (crackedTool) then table.insert(t, utils.renderQuote(crackedTool.description, "Cracked Description")) end if (tool.gift) then table.insert(t, utils.renderQuote(tool.gift["description"], "Gift text")) end

table.insert(t, "== Locations ==") for _, location in ipairs(getToolLocations(toolId)) 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

table.insert(t, "") if tool.unique then table.insert(t, "") end table.insert(t, "")

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

function p.list(frame) local tools = mw.loadData("Module:Tools/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 toolLabelToId = {} local toolLabels = {} for toolId, tool in pairs(tools) do       toolLabelToId[tool.label] = toolId table.insert(toolLabels, tool.label) end table.sort(toolLabels)

for _, toolLabel in ipairs(toolLabels) do       local toolId = toolLabelToId[toolLabel] local tool = tools[toolId] if tool.aspects.tool then table.insert(t, "|-") table.insert(t, "|" .. tool.label .. "") table.insert(t, "|") for aspect, value in pairs(tool.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 tools = mw.loadData("Module:Tools/data")

local toolLabels = {} local toolLabelToAspectLevel = {} local toolLabelToDescription = {} for _, tool in pairs(tools) do       if tool.aspects[pageAspect] then table.insert(toolLabels, tool.label) toolLabelToAspectLevel[tool.label] = tool.aspects[pageAspect] toolLabelToDescription[tool.label] = tool.description end end

table.sort(toolLabels)

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

return p