4,683
edits
(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 = { | ||
["Prayers"] = Prayer.getPrayers(function(prayer) return prayer.isUnholy == nil end), | |||
["Unholy Prayers"] = Prayer.getPrayers(function(prayer) return prayer.isUnholy 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( | 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 | end | ||
Line 451: | Line 466: | ||
return table.concat(resultPart) | return table.concat(resultPart) | ||
end | end | ||