Module:SceneCard

-- -- Lua Templating for all Scene Card related info. local p = {}

local common = require( 'Module:Common' ) local data = mw.loadData( 'Module:SceneCard/Data' )

-- Retrieve any arbitrary field of SceneCard data -- Usage: function p.Data( frame ) return data[frame.args[1]][frame.args[2]] or "" end

function p.Name( frame ) return data[frame.args[1]]["name"] or "" end

function p.Profile( frame ) local codexId = frame.args[1] local cardData = data[codexId]

local boxes = { cardData["skill1"] and frame:expandTemplate{title = "Box", args = { tag  = "Skill 1", text = Skill(frame, cardData, 1), }}           or "", cardData["skill2"] and frame:expandTemplate{title = "Box", args = { tag  = "Skill 2", text = Skill(frame, cardData, 2), }}           or "", cardData["skill3"] and frame:expandTemplate{title = "Box", args = { tag  = "Skill 3", text = Skill(frame, cardData, 3), }}           or "", }   return table.concat(boxes) end

function p.Infobox( frame ) local codexId = frame.args[1] local cardData = data[codexId] local characters = cardData["characters"] return frame:expandTemplate{ title = "Scene Card Infobox", args = { no         = codexId, no_en      = cardData["codex_en"], title      = cardData["name"], rarity     = cardData["rarity"], characters = table.concat(characters), acquisition = cardData["acquisition"], }} or "" end

-- Renders a full Scene Card page -- Usage: function p.Page( frame ) local codexId = frame.args[1] local cardData = data[codexId] return table.concat({       p.Infobox(frame),        p.Profile(frame),    }) end

-- Renders the Scene Card list -- Usage: function p.List( frame ) local header = [=[{| class="article-table sortable" style="margin: 20px 8px 0px;" !style="white-space: nowrap;"| Rarity !style="white-space: nowrap;"| # (JP) !style="white-space: nowrap;"| # (EN) ! Name ! Featured Characters ]=]   local row = [=[|- %s local rows = {} for id, cardData in common.sortedPairs(data, --desctrue) do     rows[#rows+1] = string.format(row,          FilterDataAttributes(cardData),          cardData["rarity"],          id, id,          cardData["codex_en"] or "",          id, cardData["name"] or "",          table.concat(cardData["characters"], ', ')      ) end return frame:preprocess(header..table.concat(rows, "\n").."\n|}") end
 * data-sort-value="%s"| || %s || %s || %s || %s]=]

-- Renders the Scene Card Skills list -- Usage: function p.Skills( frame ) local header = [=[{| class="article-table sortable" style="margin: 20px 8px 0px;" !style="white-space: nowrap;"| Rarity !style="white-space: nowrap;"| # (JP) !style="white-space: nowrap;"| # (EN) ! Skill 1 !! Skill 2 !! Skill 3 ]=]   local row = [=[|- %s local rows = {} for id, cardData in common.sortedPairs(data, --desctrue) do     rows[#rows+1] = string.format(row,          FilterDataAttributes(cardData),          cardData["rarity"],          id, id,          cardData["codex_en"] or "",          cardData["skill1"] and Skill(frame, cardData, 1) or "",          cardData["skill2"] and Skill(frame, cardData, 2) or "",          cardData["skill3"] and Skill(frame, cardData, 3) or ""      ) end return frame:preprocess(header..table.concat(rows, "\n").."\n|}") end
 * data-sort-value="%s"| || %s || %s
 * %s
 * %s
 * %s]=]

-- Gets a single Skill description function Skill( frame, cardData, skillId ) local skill = cardData["skill"..skillId] or {} local row = '%s%s (%s)' local header = skill[2] and "Possible effects:\n" or "" local rows = {} for index,value in ipairs(skill) do     rows[#rows+1] = string.format(row,          skill[2] and "- " or "",          value["effect"],          value["scale"]) end return '\n'..header..table.concat(rows, "\n") end

-- Utility functions function FilterDataAttributes( cardData ) return string.format(       'class="scene-card-entry" data-rarity="%s" data-global="%s"',        cardData["rarity"] or "",        (cardData["codex_en"] or "") == "" and "JP" or "EN"    ) end

return p --