Anonymous

Module:Skills: Difference between revisions

From Melvor Idle
Remove tables in favour of manual ones
(Remove function for manual table.)
(Remove tables in favour of manual ones)
Line 587: Line 587:


     return tostring(tableHtml)
     return tostring(tableHtml)
end
function p.getAncientRelicsTable(frame)
local args = (type(frame) == 'table' and frame.args ~= nil and frame.args) or frame
local skillName, isAbyssalArg = args[1], args.abyssal
local skillID = nil
if skillName ~= nil and skillName ~= '' then
skillID = Constants.getSkillID(skillName)
if skillID == nil then
return Shared.printError('Failed to find a skill ID for ' .. skillName)
end
end
local isAbyssal = nil
if isAbyssalArg ~= nil and isAbyssalArg ~= '' then
if not Shared.contains({'TRUE', 'FALSE'}, string.upper(isAbyssalArg)) then
return Shared.printError('Invalid value for parameter "abyssal", must be either "true" or "false"')
else
isAbyssal = string.upper(isAbyssalArg) == 'TRUE'
end
end
local resultPart = {}
table.insert(resultPart, '{| class="wikitable sortable stickyHeader lighttable"')
table.insert(resultPart, '\n|-class="headerRow-0"')
table.insert(resultPart, '\n|-\n!colspan="2"|Skill\n!Relic\n!Modifiers')
local relics = GameData.getEntities('ancientRelics',
function(relic)
local abyssalCheck = true
if isAbyssal ~= nil then
local relicNS, relicLocalID = Shared.getLocalID(relic.id)
local isRelicAbyssal = string.match(relicLocalID, '^Abyssal') ~= nil
abyssalCheck = (isAbyssal and isRelicAbyssal) or (not isAbyssal and not isRelicAbyssal)
end
return (skillID == nil or relic.skillID == skillID) and abyssalCheck
end)
table.sort(relics,
function (a, b)
local skillNameA, skillNameB = Constants.getSkillName(a.skillID), Constants.getSkillName(b.skillID)
if skillNameA == skillNameB then
-- Order by numbers at the end of relic IDs
-- Relics have a 'number' property, but this appears to contain duplicates
return string.sub(a.id, string.len(a.id)) < string.sub(b.id, string.len(b.id))
else
return skillNameA < skillNameB
end
end)
local function appendSkillRows(resultTable, rowTable, relicCount, skillID)
local skillName = Constants.getSkillName(skillID)
table.insert(resultTable, '\n|-\n|rowspan="' .. relicCount .. '"| ' .. Icons.Icon({skillName, type='skill', notext=true}))
table.insert(resultTable, '\n|rowspan="' .. relicCount .. '"| ' .. Icons.Icon({skillName, type='skill', noicon=true}))
table.insert(resultTable, table.concat(rowTable))
end
local skillRelicCount, currentSkillID, tablePart = 0, nil, {}
for i, relic in ipairs(relics) do
if currentSkillID == nil then
currentSkillID = relic.skillID
elseif relic.skillID ~= currentSkillID then
appendSkillRows(resultPart, tablePart, skillRelicCount, currentSkillID)
tablePart = {}
currentSkillID = relic.skillID
skillRelicCount = 0
end
skillRelicCount = skillRelicCount + 1
if skillRelicCount > 1 then
table.insert(tablePart, '\n|-')
end
table.insert(tablePart, '\n| ' .. skillRelicCount .. '\n| ' .. Modifiers.getModifiersText(relic.modifiers))
end
appendSkillRows(resultPart, tablePart, skillRelicCount, currentSkillID)
table.insert(resultPart, '\n|}')
return table.concat(resultPart)
end
function p.getLesserRelicsTable(frame)
local lesserRelics = {}
-- Iterate over each skill with a global rare drop then check
-- if the skill has a Lesser Relic drop
for skillLocalID, skill in pairs(SkillData) do
if skill.rareDrops ~= nil then
for i, drops in pairs(skill.rareDrops) do
if string.match(drops.itemID, '_Lesser_Relic') then
table.insert(lesserRelics, Items.getItemByID(drops.itemID))
end
end
end
end
table.sort(lesserRelics, function(a, b) return a.name < b.name end)
-- Create the Table
local resultTable = mw.html.create('table')
resultTable:addClass('wikitable sortable')
resultTable:tag('tr'):addClass('headerRow-0')
:tag('th'):wikitext('Icon')
:tag('th'):wikitext('Lesser Relic')
:tag('th'):wikitext('Modifiers')
for _, relic in ipairs(lesserRelics) do
local tr = mw.html.create('tr')
tr:tag('td'):wikitext(Icons.Icon({relic.name, type='item', notext=true}))
tr:tag('td'):wikitext(Icons.Icon({relic.name, type='item', noicon=true}))
tr:tag('td'):wikitext(Modifiers.getModifiersText(relic.modifiers))
resultTable:node(tr)
end
return resultTable
end
end


return p
return p
2,874

edits