Module:Skills

local guardians = require('Module:Guardian/data') local companions = require('Module:Companion/data')

local p = {}

local function skillkey(skill) return skill.name end

local function sortedkeys(tbl) local keys = {} for k, _ in pairs(tbl) do       table.insert(keys, k)    end table.sort(keys) return keys end

function NewSkillsTable return { skills = {}, users = {},

update = function(self, data) for _, g in pairs(data) do               for _, slot in ipairs(g.skills) do                    for _, skill in ipairs(slot) do                        local k = skillkey(skill) self.skills[k] = skill if self.users[k] == nil then self.users[k] = {} end self.users[k][g.name] = true end end end end,

addskill = function(self, skill, user) local k = skillkey(skill) self.skills[k] = skill if self.users[k] == nil then self.users[k] = {} end self.users[k][user] = true end,

wikitext = function(self) local s = {} table.insert(s, '{| class="wikitable sortable"') table.insert(s, '! ') table.insert(s, '! style="width: 25%" | Skill') table.insert(s, '! style="width: 50%" | Description') table.insert(s, '! style="width: 25%" | Users') for _, k in ipairs(sortedkeys(self.skills)) do               local skill = self.skills[k] local users = self.users[k] local icon = string.format("", skill.icon) table.insert(s, '|-') table.insert(s, '| ' .. icon) table.insert(s, '| ' .. " " .. skill.name) table.insert(s, '| ' .. skill.desc) local links = {} for k, user in ipairs(sortedkeys(users)) do                   local base = user:gsub(' DNA$', ):gsub(' RNA$', ) links[k] = string.format('%s', base, user) end table.insert(s, '| ' .. table.concat(links, ", ")) end table.insert(s, '|}') return table.concat(s, "\n") end, } end

function p.sortable_table local st = NewSkillsTable

for _, g in pairs(guardians) do       for _, slot in ipairs(g.skills) do            for _, skill in ipairs(slot) do                st:addskill(skill, g.name) end end end

for k, c in pairs(companions) do       st:addskill(c.skill, k)    end

return st:wikitext end

return p