Please note that some information on this wiki is still based on the demo version.
If you notice any errors, feel free to correct them.
Module:UnitsRelicsTable
From Super Fantasy Kingdom Official Wiki
Displays a table of units and the relics they benefit from.
{{#invoke:UnitsRelicsTable|Main}}
Lua error: Error: Table Heroes not found..
local p = {}
local cargo = mw.ext.cargo
function p.Main( frame )
local allRelics = p.getAllRelics()
local tables = 'Heroes'
local fields = 'name, requiredForRelics, benefitsFromRelics'
local args = {
orderBy = 'name'
}
local heroes = cargo.query( tables, fields, args )
local headerColumns = {'Heroes', 'Unlocks'}
for i=1,#allRelics do
table.insert(headerColumns, p.itemLink(allRelics[i], ''))
end
local heroRows = {}
for i = 1, #heroes do
local hero = heroes[i]
local requiredForRelics = ''
if (hero.requiredForRelics or '') ~= '' then
local requiredForRelicsEntries = {}
for relic in string.gmatch(hero.requiredForRelics, '%s*([^,]+)') do
table.insert(requiredForRelicsEntries, p.itemLink(relic, nil))
end
requiredForRelics = table.concat(requiredForRelicsEntries, '</br>')
end
local rowColumns = {p.itemLink(hero.name, nil), requiredForRelics}
for r=1,#allRelics do
local benefitsFromRelic = ''
if hero.benefitsFromRelics ~= nil and string.find(hero.benefitsFromRelics, allRelics[r]) then
benefitsFromRelic = '✔'
end
table.insert(rowColumns, benefitsFromRelic)
end
table.insert(heroRows, '<td>'..table.concat(rowColumns, '</td><td>')..'</td>')
end
return '<table class="wikitable sortable stickyheader stickyfirstcol">'..
'<tr><th>'..table.concat(headerColumns, '</th><th>')..'</th></tr>'..
'<tr>'..table.concat(heroRows, '</tr><tr>')..'</tr></table>'
end
function p.getAllRelics()
-- return a table with all relic names
local tables = 'Relics'
local fields = 'name'
local args = {
orderBy = 'name'
}
local results = cargo.query( tables, fields, args )
local allRelics = {}
for r = 1, #results do
table.insert(allRelics, results[r].name)
end
return allRelics
end
function p.itemLink(link, name)
if link == nil or link == '' then
return ''
end
local linkPart = ' [['..link..']]'
local imageLink = ''
if name ~= nil then
if name == '' then
linkPart = ''
imageLink = '|link='..link
else
linkPart = ' [['..link..'|'..name..']]'
end
end
return '[[File:'..link..'.png|16x16px|class=itemlink|alt='..imageLink..']]'..linkPart
end
return p


