Module:MementoGroup

local model = require("Module:Data").model local memoize = require('Module:Memoize').memoize

local p = {}

local render_memento_icon = require('Module:Render/Memento')._icon local mementoExtra = mw.loadData("Module:Data/Extra/Memento") local linkUtils = require("Module:LinkUtils") local enums = require('Module:Data/Enums') local originConvert = memoize(enums.originFromKey)

local skillPage = function(iname) if iname == nil then return nil end return 'Data:Game/MasterParam/Skill/' .. string.gsub(iname, '_', ' ') end

local getSkillExpr = function(skill) if skill == nil then return nil end if skill == '' then return nil end

return model.getLoc(skillPage(skill), 'expr') end

function p.mementoListItem(memData) local tempOutput = {} table.insert(tempOutput, '|-') table.insert(tempOutput, '|'..render_memento_icon({memData.iname, data=memData, name='none'})) table.insert(tempOutput, '|['..linkUtils.acdbLink(memData.iname)..' '..model.getLoc(memData._pageName, 'name')..']') table.insert(tempOutput, '|'..((tonumber(memData.rare) or 0)+1))

table.insert(tempOutput, '|'..(getSkillExpr(memData.leader_skill) or '')) table.insert(tempOutput, '|'..(originConvert(memData.birth_id) or 'Other'))

table.insert(tempOutput, '|'..((memData.iname and mementoExtra[memData.iname] and mementoExtra[memData.iname]['source']) or 'Unknown')) return { name = model.getLoc(memData._pageName, 'name'), output = table.concat(tempOutput, "\n") } end

function p.mementoLeaderOutput(memList) local sb = {}

table.insert(sb, '{| class="wikitable sortable frozen-header"') table.insert(sb, ' |-') table.insert(sb, ' ! Image !! Name !! Rarity !! Leader Skill !! Origin !! Source')

local rows = {} for iname, unit in pairs(memList) do       table.insert(rows, p.mementoListItem(unit)) end table.sort(rows, function(a, b) return a.name < b.name end)

for i, row in ipairs(rows) do       table.insert(sb, row.output) end table.insert(sb, "|}") return table.concat(sb, "\n") end

function p._mementoGroupList(groupKey) local baseMementoFields = "_pageName,iname,rare,icon,concept_card_groups,leader_skill,birth_id" local memList = model.query("ConceptCard", baseMementoFields, {where = 'server = "gl" and concept_card_groups HOLDS "'..groupKey..'"'}) or {} return p.mementoLeaderOutput(memList) end

function p.mementoGroupList(frame) local args = require('Module:Arguments').getArgs(frame, {       parentFirst = true,    }) local groupKey = args[1] return p._mementoGroupList(groupKey) end

return p