Module:Influences

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 mansusLinks = { mansus_wood = "Way: The Wood", mansus_wood1 = "The Well in the Wood", mansus_wood2 = "Temple of the Wheel", mansus_whitedoor = "Way: The White Door", mansus_whitedoor1 = "Lodge of the Sage Knight", mansus_whitedoor2 = "The Orchard of Lights", mansus_stagdoor = "Way: Through the Stag Door", mansus_stagdoor1 = "The Ascent of Knives", mansus_stagdoor2 = "The Painted River", mansus_spiderdoor = "Way: The Spider's Door", mansus_spiderdoor1 = "The Malleary", mansus_spiderdoor2 = "The Concursum", mansus_peacockdoor = "Way: The Peacock's Door", mansus_peacockdoor1 = "The Red Church", mansus_peacockdoor2 = "The Worm Museum", }

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

local function renderInfluenceInfoBox(id, influence) return string.format(       ' ',        influence.label,        id,        renderAspects(influence.aspects),        influence.unique and " Unique" or "",        id    ) end

function p.byName(frame) local influences = mw.loadData("Module:Influences/data") local aspectsData = mw.loadData("Module:Aspects/data") local mansusData = mw.loadData("Module:Mansus/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 == "Influences" then pageTitle = "A Furious Air" end

local influence, influenceId

for id, it in pairs(influences) do       if it.label == pageTitle then influence = it           influenceId = id            break end end

local t = {}

table.insert(t, renderInfluenceInfoBox(influenceId, influence)) local influencePrinciple, principleLevel for aspect, value in pairs(influence.aspects) do       if (loreColors[aspect]) then influencePrinciple = aspect principleLevel = value end end

table.insert(t, "" .. pageTitle .. " is the ' .. aspectsData[influencePrinciple].label .. "  " .. principleLevel .. " Influence. ") if (influence.decayTo) then if (influence.decayTo == "dread") then table.insert(t, "It decays to Dread. ") else if (influence.decayTo == "fascination") then table.insert(t, "It decays to Fascination. ") else if (influence.decayTo == "restlessness") then table.insert(t, "It decays to Restlessness. ") else if (influence.decayTo == "vitality") then table.insert(t, "It decays to Vitality. ") else table.insert(t, "It decays to ' .. influences[influence.decayTo].label .. " . ") end end end end end table.insert(t, extraHeader)

table.insert(t, "== Text ==") table.insert(t, utils.renderQuote(influence.description, "Description")) for id, door in pairs(mansusData) do       if (utils.listContainsItem(door.items, influenceId)) then table.insert(t, utils.renderQuote(door.messages[influenceId], mansusLinks[id] .. " draw message")) end end table.insert(t, "== Obtaining ==") for id, door in pairs(mansusData) do       if (utils.listContainsItem(door.items, influenceId)) then table.insert(t, "* Possible draw from " .. mansusLinks[id] .. "\n") end end if (influence.decayTo and principleLevel > 2) then table.insert(t, "* Can be obtained by studying two ' .. influences[influence.decayTo].label .. " ") end for id, otherInfluence in pairs(influences) do       if otherInfluence.decayTo == influenceId then table.insert(t, "* Decays from ' .. influences[id].label .. " \n") end end

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

function p.list(frame) local influences = mw.loadData("Module:Influences/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 influenceLabelToId = {} local influenceLabels = {} for influenceId, influence in pairs(influences) do       influenceLabelToId[influence.label] = influenceId table.insert(influenceLabels, influence.label) end table.sort(influenceLabels)

for _, influenceLabel in ipairs(influenceLabels) do       local influenceId = influenceLabelToId[influenceLabel] local influence = influences[influenceId] if influence.aspects.influence then table.insert(t, "|-") table.insert(t, "|" .. influence.label .. "") table.insert(t, "|") for aspect, value in pairs(influence.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 influences = mw.loadData("Module:Influences/data")

local influenceLabels = {} local influenceLabelToAspectLevel = {} local influenceLabelToDescription = {} for _, influence in pairs(influences) do       if influence.aspects[pageAspect] then table.insert(influenceLabels, influence.label) influenceLabelToAspectLevel[influence.label] = influence.aspects[pageAspect] influenceLabelToDescription[influence.label] = influence.description end end

table.sort(influenceLabels)

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

return p