Module:Relic Table
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Relic Table/doc
local cargo = mw.ext.cargo
local p = {}
function p.relicsTable(frame)
-- Query the Cargo table
local chanceType = frame.args[1]
local relics = cargo.query(
'relics',
'Relic_ID, Relic_Name, Relic_Description, Relic_Type, Relic_Ability_Name, Relic_Ability_Description, Relic_Type_Chance_Level_1, Relic_Ability_Level_1, Relic_Ability_Value_1, Relic_Type_Chance_Level_5, Relic_Ability_Level_5, Relic_Ability_Value_5, Relic_Type_Chance_Level_10, Relic_Ability_Level_10, Relic_Ability_Value_10',
{ where = 'Relic_Type = "'.. chanceType ..'"', orderBy = 'Relic_Name'}
)
-- Function to replace commas with newlines and center the text
local function formatValue(value)
return string.format('<div style="text-align: center;">%s</div>', (value or ''):gsub(',', '<br>'))
end
-- Function to format the ability description
local function formatDescription(description)
return string.format('<div style="max-width: 400px; word-wrap: break-word;">%s</div>', description or '')
end
-- Start building the table
local html = {}
if chanceType == "chance_after_each_kill" or chanceType == "chance_when_attacking" or chanceType == "chance_when_casting" or chanceType == "chance_when_striking" or chanceType == "chance_when_struck" then
table.insert(html, '<table class="wikitable" style="min-width: 800px;">')
table.insert(html, '<tr>')
table.insert(html, '<th>Name</th>')
table.insert(html, '<th>Ability Name</th>')
table.insert(html, '<th>Ability Description</th>')
table.insert(html, '<th>Chance Level 1</th>')
table.insert(html, '<th>Value Level 1</th>')
table.insert(html, '<th>Chance Level 5</th>')
table.insert(html, '<th>Value Level 5</th>')
table.insert(html, '<th>Chance Level 10</th>')
table.insert(html, '<th>Value Level 10</th>')
table.insert(html, '</tr>')
-- Populate the table with data
for _, relic in ipairs(relics) do
local relic_name_cell = string.format(
'<div style="text-align: center;">[[%s]]<br>[[File:Relics_%s.png|center|link=%s|30x30px]]</div>',
relic['Relic_Name'] or '',
relic['Relic_Name'] or '',
relic['Relic_Name'] or ''
)
table.insert(html, string.format(
'<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
relic_name_cell,
relic['Relic_Ability_Name'] or '',
formatDescription(relic['Relic_Ability_Description']),
formatValue(relic['Relic_Type_Chance_Level_1']),
formatValue(relic['Relic_Ability_Value_1']),
formatValue(relic['Relic_Type_Chance_Level_5']),
formatValue(relic['Relic_Ability_Value_5']),
formatValue(relic['Relic_Type_Chance_Level_10']),
formatValue(relic['Relic_Ability_Value_10'])
))
end
elseif chanceType == "follower" or chanceType == "passive" or chanceType == "orbit" then
table.insert(html, '<table class="wikitable" style="min-width: 800px;">')
table.insert(html, '<tr>')
table.insert(html, '<th>Name</th>')
table.insert(html, '<th>Ability Name</th>')
table.insert(html, '<th>Value Level 1</th>')
table.insert(html, '<th>Value Level 5</th>')
table.insert(html, '<th>Value Level 10</th>')
table.insert(html, '</tr>')
-- Populate the table with data
for _, relic in ipairs(relics) do
local relic_name_cell = string.format(
'<div style="text-align: center;">[[%s]]<br>[[File:Relics_%s.png|center|link=%s|30x30px]]</div>',
relic['Relic_Name'] or '',
relic['Relic_Name'] or '',
relic['Relic_Name'] or ''
)
table.insert(html, string.format(
'<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
relic_name_cell,
relic['Relic_Ability_Name'] or '',
formatValue(relic['Relic_Ability_Value_1']),
formatValue(relic['Relic_Ability_Value_5']),
formatValue(relic['Relic_Ability_Value_10'])
))
end
elseif chanceType == "grants_ability" then
table.insert(html, '<table class="wikitable" style="min-width: 800px;">')
table.insert(html, '<tr>')
table.insert(html, '<th>Name</th>')
table.insert(html, '<th>Ability Name</th>')
table.insert(html, '<th>Ability Description</th>')
table.insert(html, '<th>Value Level 1</th>')
table.insert(html, '<th>Value Level 5</th>')
table.insert(html, '<th>Value Level 10</th>')
table.insert(html, '</tr>')
-- Populate the table with data
for _, relic in ipairs(relics) do
local relic_name_cell = string.format(
'<div style="text-align: center;">[[%s]]<br>[[File:Relics_%s.png|center|link=%s|30x30px]]</div>',
relic['Relic_Name'] or '',
relic['Relic_Name'] or '',
relic['Relic_Name'] or ''
)
table.insert(html, string.format(
'<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
relic_name_cell,
relic['Relic_Ability_Name'] or '',
formatDescription(relic['Relic_Ability_Description']),
formatValue(relic['Relic_Ability_Value_1']),
formatValue(relic['Relic_Ability_Value_5']),
formatValue(relic['Relic_Ability_Value_10'])
))
end
end
table.insert(html, '</table>')
return table.concat(html)
end
return p