Module:Equipment/Recommended: Difference between revisions
From Melvor Idle
m (custom synergy table test) |
mNo edit summary |
||
Line 108: | Line 108: | ||
function p.synergy(frame) | function p.synergy(frame) | ||
local args = frame.args -- frame | local args = frame:getParent().args | ||
mw.logObject(args) | -- local args = frame.args | ||
-- mw.logObject(args) | |||
local left_summon = slots[13] | local left_summon = slots[13] | ||
local right_summon = slots[14] | local right_summon = slots[14] |
Revision as of 02:00, 10 May 2022
Documentation for this module may be created at Module:Equipment/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 slots = {
{ placement = 1, name = 'helm', icon = 'Slot_head', txt = 'Helmet', link = 'Equipment#Helmets' },
{ placement = 2, name = 'body', icon = 'Slot_chest', txt = 'Platebody', link = 'Equipment#Platebodies' },
{ placement = 3, name = 'legs', icon = 'Slot_legs', txt = 'Platelegs', link = 'Equipment#Platelegs' },
{ placement = 4, name = 'boots', icon = 'Slot_feet', txt = 'Boots', link = 'Equipment#Boots' },
{ placement = 5, name = 'gloves', icon = 'Slot_hands', txt = 'Gloves', link = 'Equipment#Gloves' },
{ placement = 6, name = 'cape', icon = 'Slot_back', txt = 'Cape', link = 'Equipment#Capes' },
{ placement = 7, name = 'neck', icon = 'Slot_neck', txt = 'Amulet', link = 'Equipment#Amulets' },
{ placement = 8, name = 'ring', icon = 'Slot_ring', txt = 'Ring', link = 'Equipment#Rings' },
{ placement = 9, name = 'weapon', icon = 'Slot_weapon', txt = 'Weapon', link = 'Equipment#Weapons' },
{ placement = 10, name = 'shield', icon = 'Slot_shield', txt = 'Offhand', link = 'Equipment#Offhand' },
{ placement = 11, name = 'ammo', icon = 'Slot_ammo', txt = 'Quiver', link = 'Equipment#Ammunition' },
{ placement = 12, name = 'passive', icon = 'Slot_passive', txt = 'Passive', link = 'Combat Passive Slot' },
{ placement = 13, name = 'familiar1', icon = 'Slot_summon', txt = 'Familiar Left', link = 'Summoning' },
{ placement = 14, name = 'familiar2', icon = 'Slot_summon', txt = 'Familiar Right', link = 'Summoning' },
{ placement = 99, name = 'notes', icon = '', txt = "Notes", link = nil }
}
function p.main(frame)
local args = frame:getParent().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 = 5
-- Have to sort this table or else the order is messed up when you use it
table.sort(slots, function(a, b) return a.placement < b.placement end)
local function make_row(slot, data, compact)
local tr = mw.html.create('tr')
local sloticon = tr:tag('td')
sloticon:wikitext(string.format('[[File:%s.png|%s|link=%s|36px]]', slot.icon, slot.txt, slot.link))
if compact then
sloticon:attr('style', 'padding-bottom: 4px;')
end
for _, v in ipairs(data) do
local itemicon = icons.Icon({v, img=v, type='item'})
local gearname = tr:tag('td'):wikitext(itemicon)
if compact then
gearname: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, slots, 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 equipment for %s', args.setname))
end
local compact = true
if args.noheader == nil then
compact = false
parent:addClass('wikitable')
parent:tag('tr')
:tag('th'):wikitext('Slot'):done()
:tag('th'):attr('colspan', greatest_row_size):wikitext('Item (most effective → least effective)'):done()
end
for _, v in next, slots, nil do
local row_data = {}
for i = 1, number_of_possible_choices, 1 do
local gear = args[v.name .. i]
if gear and params.has_content(gear) then
table.insert(row_data, gear)
end
end
if #row_data > 0 or args.showall then
parent:node(make_row(v, row_data, compact))
end
end
return tostring(parent)
end
function p.synergy(frame)
local args = frame:getParent().args
-- local args = frame.args
-- mw.logObject(args)
local left_summon = slots[13]
local right_summon = slots[14]
local summon_icon = string.format('[[File:%s.png|Summon|36px]]', right_summon.icon)
local notes = slots[15]
local number_of_possible_choices = 5
local rows = {}
local header_row = {}
table.insert(header_row, summon_icon .. ' Left')
table.insert(header_row, summon_icon .. ' Right')
table.insert(rows, '{| class="mediawiki"')
table.insert(rows, '! ' .. table.concat(header_row, '\r\n! '))
local function make_gear_cell(name)
if name then
return '| ' .. icons.Icon({name, img=name, type='item'})
else
return '| ' .. summon_icon
end
end
-- first we create tables for left and right side making sure left[i] and right[i] correspond
-- could generate the rows in one go, but eh
local lefties = {}
local righties = {}
local notes = {}
local number_rows = 0
for i = 1, number_of_possible_choices, 1 do
local left = args[left_summon.name .. i]
table.insert(lefties, make_gear_cell(left))
local right = args[right_summon.name .. i]
table.insert(righties, make_gear_cell(right))
local note = args['notes' .. i]
table.insert(notes, make_gear_cell(note))
if left or right or note then
number_rows = number_rows + 1
end
end
-- then we create all the rows by formatting them
for i = 1, number_rows, 1 do
local row = {}
table.insert(row, lefties[i])
table.insert(row, righties[i])
table.insert(row, notes[i])
table.insert(rows, table.concat(row, "\r\n"))
end
return table.concat(rows, '\r\n|-\r\n')..'\r\n|}'
end
function p.test()
return p.synergy({ args = { familiar11 = 'Crow',
familiar21 = 'Devil',
familiar12 = 'Crow',
familiar22 = 'Octopus',
familiar13 = 'Crow',
familiar23 = 'Bear'
}} )
end
return p