Module:Followers

local p = {}

local utils = require("Module:Utils")

local function renderFollowerInfoBox(id, name, aspect) return string.format(       ' ',        name,        name,        utils.singleAspect(aspect),        id    ) end

function p.byName(frame) local followers = mw.loadData("Module:Followers/data") local aspectsData = mw.loadData("Module:Aspects/data") local locationsData = mw.loadData("Module:Locations/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 == "Followers" or pageTitle == "Sandbox" then pageTitle = "Ysabet" end

local versions, followerId

for id, it in pairs(followers) do       if utils.startsWith(it.acquaintance.label, pageTitle) then versions = it           followerId = id            break end end local primaryAspect for aspect, _ in pairs(versions.follower.aspects) do       if utils.aspectColors[aspect] then primaryAspect = aspect end end

local t = {}

table.insert(t, renderFollowerInfoBox(followerId, pageTitle, primaryAspect)) table.insert(t, pageTitle .. " is a " .. utils.singleAspect(primaryAspect) .. " Follower. " .. extraHeader) local acquaintance = versions.acquaintance local follower = versions.follower local disciple = versions.disciple local exalted = versions.exalted local rival = versions.rival local prisoner = versions.prisoner table.insert(t, "==" .. acquaintance.label .. "==") table.insert(t, utils.renderQuote(acquaintance.description, "Acquaintance description")) table.insert(t, "Aspects: " .. utils.renderAspects(acquaintance.aspects)) table.insert(t, "==" .. follower.label .. "==") table.insert(t, utils.renderQuote(follower.description, "Believer description")) table.insert(t, "Aspects: " .. utils.renderAspects(follower.aspects)) table.insert(t, "==" .. disciple.label .. "==") table.insert(t, utils.renderQuote(disciple.description, "Disciple description")) table.insert(t, "Aspects: " .. utils.renderAspects(disciple.aspects)) table.insert(t, "==" .. exalted.label .. "==") table.insert(t, utils.renderQuote(exalted.description, "Exalt description")) table.insert(t, "Aspects: " .. utils.renderAspects(exalted.aspects)) table.insert(t, "==Rival==") table.insert(t, utils.renderQuote(rival.description, "Rival description")) table.insert(t, "Aspects: " .. utils.renderAspects(rival.aspects)) table.insert(t, "==Prisoner==") table.insert(t, utils.renderQuote(prisoner.description, "Prisoner description")) table.insert(t, "Aspects: " .. utils.renderAspects(prisoner.aspects)) local romance = versions.romance table.insert(t, "==Romance==") table.insert(t, pageTitle .. " can be romanced at " .. locationsData[romance.locationId].label .. ".") table.insert(t, utils.renderQuote(romance.inviteDescription, "Invitation description")) table.insert(t, utils.renderQuote(romance.startDescription, "Followup description")) table.insert(t, utils.renderQuote(romance.endDescription, "Success description")) table.insert(t, utils.renderQuote(romance.seasonDescription, "Season description"))

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

function p.list(frame) local followers = mw.loadData("Module:Followers/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 followerLabelToId = {} local followerLabels = {} for followerId, follower in pairs(followers) do       followerLabelToId[follower.label] = followerId table.insert(followerLabels, follower.label) end table.sort(followerLabels)

for _, followerLabel in ipairs(followerLabels) do       local followerId = followerLabelToId[followerLabel] local follower = followers[followerId] if follower.aspects.follower then table.insert(t, "|-") table.insert(t, "|" .. follower.label .. "") table.insert(t, "|") for aspect, value in pairs(follower.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 followers = mw.loadData("Module:Followers/data")

local followerLabels = {} local followerLabelToAspectLevel = {} local followerLabelToDescription = {} for _, follower in pairs(followers) do       if follower.aspects[pageAspect] then table.insert(followerLabels, follower.label) followerLabelToAspectLevel[follower.label] = follower.aspects[pageAspect] followerLabelToDescription[follower.label] = follower.description end end

table.sort(followerLabels)

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

return p