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 Created page with "local p = {} local cargo = mw.ext.cargo function p.Main( frame ) local allRelics = p.getAllRelics() local tables = 'units' local fields = 'name, requiredForRelic, benefitsFromRelics' local args = { orderBy = 'name' } local units = cargo.query( tables, fields, args ) local headerColumns = {'Units', 'Unlocks'} for i=1,#allRelics do table.insert(headerColumns, p.itemLink(allRelics[i], nil)) end local unitRows = {} for i = 1, #units do local unit = uni..." |
imported>Cadaei casing |
||
| Line 5: | Line 5: | ||
local allRelics = p.getAllRelics() | local allRelics = p.getAllRelics() | ||
local tables = ' | local tables = 'Units' | ||
local fields = 'name, requiredForRelic, benefitsFromRelics' | local fields = 'name, requiredForRelic, benefitsFromRelics' | ||
local args = { | local args = { | ||
| Line 39: | Line 39: | ||
function p.getAllRelics() | function p.getAllRelics() | ||
-- return a table with all relic names | -- return a table with all relic names | ||
local tables = ' | local tables = 'Relics' | ||
local fields = 'name' | local fields = 'name' | ||
local args = { | local args = { | ||
Revision as of 00:39, 8 November 2023
Displays a table of units and the relics they benefit from.
{{#invoke:UnitsRelicsTable|Main}}
Lua error: Error: No field named "requiredForRelic" found for any of the specified database tables..
local p = {}
local cargo = mw.ext.cargo
function p.Main( frame )
local allRelics = p.getAllRelics()
local tables = 'Units'
local fields = 'name, requiredForRelic, benefitsFromRelics'
local args = {
orderBy = 'name'
}
local units = cargo.query( tables, fields, args )
local headerColumns = {'Units', 'Unlocks'}
for i=1,#allRelics do
table.insert(headerColumns, p.itemLink(allRelics[i], nil))
end
local unitRows = {}
for i = 1, #units do
local unit = units[i]
local rowColumns = {p.itemLink(unit.name, nil), p.itemLink(unit.requiredForRelic, nil)}
for r=1,#allRelics do
local benefitsFromRelic = ''
if string.find(unit.benefitsFromRelics, allRelics[r]) then
benefitsFromRelic = '✔'
end
table.insert(rowColumns, benefitsFromRelic)
end
table.insert(unitRows, '<td>'..table.concat(rowColumns, '</td><td>')..'</td>')
end
return '<table class="wikitable sortable">'..
'<tr><th>'..table.concat(headerColumns, '</th><th>')..'</th></tr>'..
'<tr>'..table.concat(unitRows, '</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)
local linkPart = link
if name ~= nil then
linkPart = link..'|'..name
end
return '[[File:'..link..'|16x16px|class=itemlink|alt=]] [['..linkPart..']]'
end
return p


