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: Difference between revisions
From Super Fantasy Kingdom Official Wiki
imported>Cadaei m Cadaei moved page Module:UnitsRelicsTable to Module:HeroesRelicsTable without leaving a redirect: renamed ingame |
imported>Cadaei unit->hero |
||
| Line 5: | Line 5: | ||
local allRelics = p.getAllRelics() | local allRelics = p.getAllRelics() | ||
local tables = ' | local tables = 'Heroes' | ||
local fields = 'name, requiredForRelics, benefitsFromRelics' | local fields = 'name, requiredForRelics, benefitsFromRelics' | ||
local args = { | local args = { | ||
orderBy = 'name' | orderBy = 'name' | ||
} | } | ||
local | local heroes = cargo.query( tables, fields, args ) | ||
local headerColumns = {' | local headerColumns = {'Heroes', 'Unlocks'} | ||
for i=1,#allRelics do | for i=1,#allRelics do | ||
table.insert(headerColumns, p.itemLink(allRelics[i], '')) | table.insert(headerColumns, p.itemLink(allRelics[i], '')) | ||
end | end | ||
local | local heroRows = {} | ||
for i = 1, # | for i = 1, #heroes do | ||
local | local hero = heroes[i] | ||
local requiredForRelics = '' | local requiredForRelics = '' | ||
if ( | if (hero.requiredForRelics or '') ~= '' then | ||
local requiredForRelicsEntries = {} | local requiredForRelicsEntries = {} | ||
for relic in string.gmatch( | for relic in string.gmatch(hero.requiredForRelics, '%s*([^,]+)') do | ||
table.insert(requiredForRelicsEntries, p.itemLink(relic, nil)) | table.insert(requiredForRelicsEntries, p.itemLink(relic, nil)) | ||
end | end | ||
| Line 29: | Line 29: | ||
end | end | ||
local rowColumns = {p.itemLink( | local rowColumns = {p.itemLink(hero.name, nil), requiredForRelics} | ||
for r=1,#allRelics do | for r=1,#allRelics do | ||
local benefitsFromRelic = '' | local benefitsFromRelic = '' | ||
if | if hero.benefitsFromRelics ~= nil and string.find(hero.benefitsFromRelics, allRelics[r]) then | ||
benefitsFromRelic = '✔' | benefitsFromRelic = '✔' | ||
end | end | ||
| Line 38: | Line 38: | ||
end | end | ||
table.insert( | table.insert(heroRows, '<td>'..table.concat(rowColumns, '</td><td>')..'</td>') | ||
end | end | ||
return '<table class="wikitable sortable stickyheader stickyfirstcol">'.. | return '<table class="wikitable sortable stickyheader stickyfirstcol">'.. | ||
'<tr><th>'..table.concat(headerColumns, '</th><th>')..'</th></tr>'.. | '<tr><th>'..table.concat(headerColumns, '</th><th>')..'</th></tr>'.. | ||
'<tr>'..table.concat( | '<tr>'..table.concat(heroRows, '</tr><tr>')..'</tr></table>' | ||
end | end | ||
Revision as of 00:02, 14 November 2023
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


