Module:Obstacles/Recommended: Difference between revisions
From Melvor Idle
m (icon) |
m (forgot the txt) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 8: | Line 8: | ||
local tiers = { | local tiers = { | ||
{ tier = 1, name = 'obs1', icon = 'Agility', txt = 'I', link = ' | { tier = 1, name = 'obs1', icon = 'Agility', txt = 'I', link = 'Obstacle 1' }, | ||
{ tier = 2, name = 'obs2', icon = 'Agility', txt = 'II', link = ' | { tier = 2, name = 'obs2', icon = 'Agility', txt = 'II', link = 'Obstacle 2' }, | ||
{ tier = 3, name = 'obs3', icon = 'Agility', txt = 'III', link = ' | { tier = 3, name = 'obs3', icon = 'Agility', txt = 'III', link = 'Obstacle 3' }, | ||
{ tier = 4, name = 'obs4', icon = 'Agility', txt = 'IV', link = ' | { tier = 4, name = 'obs4', icon = 'Agility', txt = 'IV', link = 'Obstacle 4' }, | ||
{ tier = 5, name = 'obs5', icon = 'Agility', txt = 'V', link = ' | { tier = 5, name = 'obs5', icon = 'Agility', txt = 'V', link = 'Obstacle 5' }, | ||
{ tier = 6, name = 'obs6', icon = 'Agility', txt = 'VI', link = ' | { tier = 6, name = 'obs6', icon = 'Agility', txt = 'VI', link = 'Obstacle 6' }, | ||
{ tier = 7, name = 'obs7', icon = 'Agility', txt = 'VII', link = ' | { tier = 7, name = 'obs7', icon = 'Agility', txt = 'VII', link = 'Obstacle 7' }, | ||
{ tier = 8, name = 'obs8', icon = 'Agility', txt = 'VIII', link = ' | { tier = 8, name = 'obs8', icon = 'Agility', txt = 'VIII', link = 'Obstacle 8' }, | ||
{ tier = 9, name = 'obs9', icon = 'Agility', txt = 'IX', link = ' | { tier = 9, name = 'obs9', icon = 'Agility', txt = 'IX', link = 'Obstacle 9' }, | ||
{ tier = 10, name = 'obs10', icon = 'Agility', txt = 'X', link = ' | { tier = 10, name = 'obs10', icon = 'Agility', txt = 'X', link = 'Obstacle 10' }, | ||
{ tier = 11, name = 'pillar', icon = 'Agility', txt = 'Pillar', link = 'Agility | { tier = 11, name = 'obs11', icon = 'Agility', txt = 'XI', link = 'Obstacle 11' }, | ||
{ tier = 12, name = 'obs12', icon = 'Agility', txt = 'XII', link = 'Obstacle 12' }, | |||
{ tier = 13, name = 'obs13', icon = 'Agility', txt = 'XIII', link = 'Obstacle 13' }, | |||
{ tier = 14, name = 'obs14', icon = 'Agility', txt = 'XIV', link = 'Obstacle 14' }, | |||
{ tier = 15, name = 'obs15', icon = 'Agility', txt = 'XV', link = 'Obstacle 15' }, | |||
{ tier = 98, name = 'pillar', icon = 'Agility', txt = 'Pillar', link = 'Passive Pillars' }, | |||
{ tier = 99, name = 'epillar', icon = 'Agility', txt = 'Elite Pillar', link = 'Passive Pillars' }, | |||
} | } | ||
Line 31: | Line 37: | ||
table.sort(tiers, function(a, b) return a.tier < b.tier end) | table.sort(tiers, function(a, b) return a.tier < b.tier end) | ||
local function make_row( | local function make_row(tier, data, compact) | ||
local tr = mw.html.create('tr') | local tr = mw.html.create('tr') | ||
local | local tiericon = tr:tag('td') | ||
tiericon:wikitext( icons.Icon({tier.link, tier.txt, img=tier.icon, type='skill'}) ) | |||
if compact then | if compact then | ||
tiericon:attr('style', 'padding-bottom: 4px;') | |||
end | end | ||
for _, v in ipairs(data) do | for _, v in ipairs(data) do |
Latest revision as of 09:48, 28 October 2022
Documentation for this module may be created at Module:Obstacles/Recommended/doc
-- Copied from: https://oldschool.runescape.wiki/w/Module:Recommended Equipment
-- Released under: https://creativecommons.org/licenses/by-nc-sa/3.0/
local p = {}
local params = require('Module:Shared/Paramtest')
local icons = require("Module:Icons")
local tiers = {
{ tier = 1, name = 'obs1', icon = 'Agility', txt = 'I', link = 'Obstacle 1' },
{ tier = 2, name = 'obs2', icon = 'Agility', txt = 'II', link = 'Obstacle 2' },
{ tier = 3, name = 'obs3', icon = 'Agility', txt = 'III', link = 'Obstacle 3' },
{ tier = 4, name = 'obs4', icon = 'Agility', txt = 'IV', link = 'Obstacle 4' },
{ tier = 5, name = 'obs5', icon = 'Agility', txt = 'V', link = 'Obstacle 5' },
{ tier = 6, name = 'obs6', icon = 'Agility', txt = 'VI', link = 'Obstacle 6' },
{ tier = 7, name = 'obs7', icon = 'Agility', txt = 'VII', link = 'Obstacle 7' },
{ tier = 8, name = 'obs8', icon = 'Agility', txt = 'VIII', link = 'Obstacle 8' },
{ tier = 9, name = 'obs9', icon = 'Agility', txt = 'IX', link = 'Obstacle 9' },
{ tier = 10, name = 'obs10', icon = 'Agility', txt = 'X', link = 'Obstacle 10' },
{ tier = 11, name = 'obs11', icon = 'Agility', txt = 'XI', link = 'Obstacle 11' },
{ tier = 12, name = 'obs12', icon = 'Agility', txt = 'XII', link = 'Obstacle 12' },
{ tier = 13, name = 'obs13', icon = 'Agility', txt = 'XIII', link = 'Obstacle 13' },
{ tier = 14, name = 'obs14', icon = 'Agility', txt = 'XIV', link = 'Obstacle 14' },
{ tier = 15, name = 'obs15', icon = 'Agility', txt = 'XV', link = 'Obstacle 15' },
{ tier = 98, name = 'pillar', icon = 'Agility', txt = 'Pillar', link = 'Passive Pillars' },
{ tier = 99, name = 'epillar', icon = 'Agility', txt = 'Elite Pillar', link = 'Passive Pillars' },
}
function p.main(frame)
local args = frame:getParent().args
-- local args = frame.args
-- Dynamic colspan and N/A generation value
local greatest_row_size = 0
-- Number of choices each slot can have
local number_of_possible_choices = 6
-- Have to sort this table or else the order is messed up when you use it
table.sort(tiers, function(a, b) return a.tier < b.tier end)
local function make_row(tier, data, compact)
local tr = mw.html.create('tr')
local tiericon = tr:tag('td')
tiericon:wikitext( icons.Icon({tier.link, tier.txt, img=tier.icon, type='skill'}) )
if compact then
tiericon:attr('style', 'padding-bottom: 4px;')
end
for _, v in ipairs(data) do
local obstaclename = tr:tag('td'):wikitext(string.format('[[Agility#%s|%s]]', v, v))
if compact then
obstaclename:attr('style', 'padding-left: 12px;')
end
end
-- If the data size is smaller than GRS, then we need to fill up the remaining td's with N/As
if #data < greatest_row_size then
local difference = greatest_row_size - #data
tr:tag('td'):attr('colspan', difference):attr("class", ".dimmed")
end
return tr
end
-- Find the greatest row count
for _, v in next, tiers, nil do
local grs = 0
for i = 1, number_of_possible_choices, 1 do
local check = args[v.name .. i]
if check and params.has_content(check) then
grs = grs + 1
end
end
if greatest_row_size < grs then
greatest_row_size = grs
end
end
local parent = mw.html.create('table')
-- If setname is passed in, apply it above the table
if args.setname and params.has_content(args.setname) then
parent:tag('caption'):wikitext(string.format('Recommended obstacles for %s', args.setname))
end
local compact = true
if args.noheader == nil then
compact = false
parent:addClass('wikitable')
parent:tag('tr')
:tag('th'):wikitext('Obstacle'):done()
:tag('th'):attr('colspan', greatest_row_size):wikitext('Pillar (most effective → least effective)'):done()
end
for _, v in next, tiers, nil do
local row_data = {}
for i = 1, number_of_possible_choices, 1 do
local obstacle = args[v.name .. i]
if obstacle and params.has_content(obstacle) then
table.insert(row_data, obstacle)
end
end
if #row_data > 0 or args.showall then
parent:node(make_row(v, row_data, compact))
end
end
return tostring(parent)
end
return p