Module:Obstacles/Recommended: Difference between revisions

From Melvor Idle
m (images)
m (forgor)
Line 31: Line 31:
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(slot, data, compact)
local function make_row(tier, data, compact)
local tr = mw.html.create('tr')
local tr = mw.html.create('tr')
local tiericon = tr:tag('td')
local tiericon = tr:tag('td')
tiericon:wikitext( icons.Icon({slot.txt, img=slot.icon, type='skill'}) )
tiericon:wikitext( icons.Icon({tier.txt, img=tier.icon, type='skill'}) )
sloticon:wikitext(string.format('[[File:%s.svg|%s|link=%s|36px]]', slot.icon .. ' (Skill)', slot.txt, slot.link))
if compact then
if compact then
sloticon:attr('style', 'padding-bottom: 4px;')
tiericon:attr('style', 'padding-bottom: 4px;')
end
end
for _, v in ipairs(data) do
for _, v in ipairs(data) do

Revision as of 19:07, 25 January 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 = 'Agility#Obstacle 1' },
	{ tier = 2, name = 'obs2', icon = 'Agility', txt = 'II', link = 'Agility#Obstacle 2' },
	{ tier = 3, name = 'obs3', icon = 'Agility', txt = 'III', link = 'Agility#Obstacle 3' },
	{ tier = 4, name = 'obs4', icon = 'Agility', txt = 'IV', link = 'Agility#Obstacle 4' },
	{ tier = 5, name = 'obs5', icon = 'Agility', txt = 'V', link = 'Agility#Obstacle 5' },
	{ tier = 6, name = 'obs6', icon = 'Agility', txt = 'VI', link = 'Agility#Obstacle 6' },
	{ tier = 7, name = 'obs7', icon = 'Agility', txt = 'VII', link = 'Agility#Obstacle 7' },
	{ tier = 8, name = 'obs8', icon = 'Agility', txt = 'VIII', link = 'Agility#Obstacle 8' },
	{ tier = 9, name = 'obs9', icon = 'Agility', txt = 'IX', link = 'Agility#Obstacle 9' },
	{ tier = 10, name = 'obs10', icon = 'Agility', txt = 'X', link = 'Agility#Obstacle 10' },
	{ tier = 11, name = 'pillar', icon = 'Agility', txt = 'Pillar', link = 'Agility#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.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