Module:Navboxes: Difference between revisions

Cleaned up Single Navbox functions; Added Expansion Icons; Separated Prayers and Unholy Prayers
(getLogNavbox: Adjust style, previously was inadequately spaced away from other navboxes)
(Cleaned up Single Navbox functions; Added Expansion Icons; Separated Prayers and Unholy Prayers)
 
Line 11: Line 11:
local Shop = require('Module:Shop')
local Shop = require('Module:Shop')
local Pets = require('Module:Pets')
local Pets = require('Module:Pets')
local Prayer = require('Module:Prayer')
-- Generates a table with a single category which has an Item and it's Icon
-- array is the list of items that will be added to the table
-- iconType is the item's icon type
-- headerData is the text displayed at the top of the generated table
-- productID is the proper capitalization of the productID property -_-
function p.buildSingleNavboxTable(array, iconType, headerData, productID)
-- Generate Table contents
table.sort(array, function(a, b) return a.level < b.level end)
local iconArray = {}
for i, item in ipairs(array) do
if productID ~= nil then
item = Items.getItemByID(item[productID])
end
table.insert(iconArray, Icons.Icon({item.name, type=iconType, expicon=Icons.getExpansionIcon(item.id)}))
end
-- Generate navbox table
local resultTable = mw.html.create('table')
-- Table classes & styles
resultTable
:addClass('wikitable')
:addClass('navigation-not-searchable')
:css('text-align', 'center')
:css('clear', 'both')
:css('width', '100%')
-- Header row
:tag('tr')
:tag('th')
:css('background-color', '#275C87')
:css('color', '#FFFFFF')
:wikitext(Icons.Icon(headerData))
:done()
:done()
-- Content, list of logs
:tag('tr')
:tag('td')
:wikitext(table.concat(iconArray, ' • '))
:done()
:done()
:done()
return tostring(resultTable)
end
function p.getLogNavbox(frame)
local trees = Shared.shallowClone(SkillData.Woodcutting.trees)
return p.buildSingleNavboxTable(trees, 'item', {'Woodcutting', 'Logs', type='skill', section='Logs'}, 'productId')
end
function p.getFamiliarNavbox(frame)
local familiars = Shared.shallowClone(SkillData.Summoning.recipes)
return p.buildSingleNavboxTable(familiars, 'item', {'Summoning', 'Summoning Familiars', type='skill', section='Summoning_Tablets'}, 'productID')
end
function p.getThievingNavbox(frame)
local npcs = Shared.shallowClone(SkillData.Thieving.npcs)
return p.buildSingleNavboxTable(npcs, 'thieving', {'Thieving', 'Thieving Targets', type='skill', section='Thieving_Targets'})
end


function p.getFarmingNavbox(frame)
function p.getFarmingNavbox(frame)
Line 202: Line 261:


function p.getPrayerNavbox(frame)
function p.getPrayerNavbox(frame)
local prayerList = {}
local prayerList = {
for i, prayer in ipairs(GameData.rawData.prayers) do
["Prayers"] = Prayer.getPrayers(function(prayer) return prayer.isUnholy == nil end),
table.insert(prayerList, { ["name"] = prayer.name, ["order"] = prayer.level })
["Unholy Prayers"] = Prayer.getPrayers(function(prayer) return prayer.isUnholy end)
end
}
table.sort(prayerList, function(a, b)
if a.order == b.order then
return a.name < b.name
else
return a.order < b.order
end
end)
 
local prayerListText = {}
for i, prayer in ipairs(prayerList) do
table.insert(prayerListText, Icons.Icon({ prayer.name, type='prayer' }))
end


local resultPart = {}
local resultPart = {}
table.insert(resultPart, '{| class="wikitable navigation-not-searchable" style="margin:auto; clear:both; width: 100%"')
table.insert(resultPart, '{| class="wikitable navigation-not-searchable" style="margin:auto; clear:both; width: 100%"')
table.insert(resultPart, '\r\n!'..Icons.Icon({'Prayer', 'Prayers', type='skill'}))
table.insert(resultPart, '\r\n!colspan=2|' .. Icons.Icon({'Prayer', 'Prayers', type='skill'}))
table.insert(resultPart, '\r\n|-\r\n|style="text-align:center;"| ' .. table.concat(prayerListText, ' • '))
for catName, subList in pairs(prayerList) do
table.sort(subList, function(a, b)
if a.level == b.level then
return a.name < b.name
else
return a.level < b.level
end
end)
local prayerText = {}
table.insert(resultPart, '\r\n|-\r\n!style="text-align:center;"| ' .. catName)
for i, prayer in ipairs(subList) do
table.insert(prayerText, Icons.Icon({prayer.name, type='prayer', expicon = Icons.getExpansionIcon(prayer.id)}))
end
table.insert(resultPart, '\r\n|style="text-align:center;"| ' .. table.concat(prayerText, ' • '))
end
table.insert(resultPart, '\r\n|}')
table.insert(resultPart, '\r\n|}')
return table.concat(resultPart)
return table.concat(resultPart)
end
end
Line 343: Line 405:


return table.concat(resultPart)
return table.concat(resultPart)
end
function p.getFamiliarNavbox(frame)
local familiarList = {}
for i, recipe in ipairs(SkillData.Summoning.recipes) do
local item = Items.getItemByID(recipe.productID)
if item ~= nil then
table.insert(familiarList, { ["name"] = item.name, ["order"] = recipe.level })
end
end
table.sort(familiarList, function(a, b) return a.order < b.order end)
local resultPart = {}
table.insert(resultPart, '{| class="wikitable navigation-not-searchable" style="margin:auto; clear:both; width: 100%"')
table.insert(resultPart, '\r\n!colspan=2|' .. Icons.Icon({'Summoning', 'Summoning Familiars', type='skill'}))
local iconArray = {}
for i, fam in ipairs(familiarList) do
table.insert(iconArray, Icons.Icon({fam.name, type='item'}))
end
table.insert(resultPart, '\r\n|-\r\n|style="text-align:center;"|'..table.concat(iconArray, ' • '))
table.insert(resultPart, '\r\n|}')
return table.concat(resultPart)
end
function p.getThievingNavbox(frame)
local returnPart = {}
-- Create table header
table.insert(returnPart, '{| class="wikitable navigation-not-searchable" style="text-align:center; clear:both; margin:auto; margin-bottom:1em;"')
table.insert(returnPart, '|-\r\n!' .. Icons.Icon({'Thieving', 'Thieving Targets', type='skill'}))
table.insert(returnPart, '|-\r\n|')
local npcData = {}
for i, npc in ipairs(SkillData.Thieving.npcs) do
table.insert(npcData, {["level"] = npc.level, ["name"] = npc.name})
end
table.sort(npcData, function(a, b) return a.level < b.level end)
local npcList = {}
-- Create row for each NPC
for i, npc in ipairs(npcData) do
table.insert(npcList, Icons.Icon({npc.name, type='thieving'}))
end
table.insert(returnPart, table.concat(npcList, ' • '))
table.insert(returnPart, '|}')
return table.concat(returnPart, '\r\n')
end
end


Line 451: Line 466:


return table.concat(resultPart)
return table.concat(resultPart)
end
function p.getLogNavbox(frame)
-- Generate navbox content
local trees = Shared.shallowClone(SkillData.Woodcutting.trees)
table.sort(trees, function(a, b) return a.level < b.level end)
local contentPart = {}
for i, tree in ipairs(trees) do
local log = Items.getItemByID(tree.productId)
if log ~= nil then
table.insert(contentPart, Icons.Icon({log.name, type='item'}))
end
end
-- Generate navbox table
local resultTable = mw.html.create('table')
-- Table classes & styles
resultTable
:addClass('wikitable')
:addClass('navigation-not-searchable')
:css('text-align', 'center')
:css('clear', 'both')
:css('width', '100%')
-- Header row
:tag('tr')
:tag('th')
:css('background-color', '#275C87')
:css('color', '#FFFFFF')
:wikitext(Icons.Icon({'Woodcutting', 'Logs', type='skill', section='Logs'}))
:done()
:done()
-- Content, list of logs
:tag('tr')
:tag('td')
:wikitext(table.concat(contentPart, ' • '))
:done()
:done()
:done()
return tostring(resultTable)
end
end


457

edits