463
edits
(getFoodNavbox: Exclude unobtainable item) |
(Cleaned up Single Navbox functions; Added Expansion Icons; Separated Prayers and Unholy Prayers) |
||
(6 intermediate revisions by one other user not shown) | |||
Line 10: | Line 10: | ||
local Magic = require('Module:Magic') | local Magic = require('Module:Magic') | ||
local Shop = require('Module:Shop') | local Shop = require('Module:Shop') | ||
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 71: | Line 131: | ||
if not foundIDs[recipe.productID] then | if not foundIDs[recipe.productID] then | ||
foundIDs[recipe.productID] = true | foundIDs[recipe.productID] = true | ||
if recipe.perfectCookID ~= nil then | |||
foundIDs[recipe.perfectCookID] = true | |||
end | |||
if recipe.noMastery == nil then | if recipe.noMastery == nil then | ||
local cookedItem = Items.getItemByID(recipe.productID) | local cookedItem = Items.getItemByID(recipe.productID) | ||
Line 85: | Line 148: | ||
if perfectItem ~= nil then | if perfectItem ~= nil then | ||
perfectName = perfectItem.name | perfectName = perfectItem.name | ||
end | end | ||
end | end | ||
Line 199: | 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 342: | Line 407: | ||
end | end | ||
function p. | function p.getFishingNavbox(frame) | ||
local categoryHeader = {} | local categoryHeader = {} | ||
local categoryItems = {} | local categoryItems = {} | ||
Line 493: | Line 511: | ||
end | end | ||
table.insert(resultPart, '\r\n|-\r\n! ' .. cat .. '\r\n|style="text-align:center;"| ' .. table.concat(listPart, ' • ')) | table.insert(resultPart, '\r\n|-\r\n! ' .. cat .. '\r\n|style="text-align:center;"| ' .. table.concat(listPart, ' • ')) | ||
end | |||
table.insert(resultPart, '\r\n|}') | |||
return table.concat(resultPart) | |||
end | |||
function p.getPetNavbox(frame) | |||
local resultPart = {} | |||
table.insert(resultPart, '{| class="wikitable navigation-not-searchable" style="margin:auto; text-align:center; clear:both; width: 100%"') | |||
table.insert(resultPart, '\r\n|-\r\n!colspan="2"|[[Pets]]') | |||
local petListOrder = { 'skill', 'boss', 'other' } | |||
local petList = { | |||
["skill"] = {}, | |||
["boss"] = {}, | |||
["other"] = {} | |||
} | |||
for i, petData in ipairs(GameData.rawData.pets) do | |||
local source = Pets._getPetSource(petData) | |||
local listCat = 'other' | |||
if type(source) == 'table' and source.type ~= nil then | |||
if source.type == 'skill' then | |||
listCat = 'skill' | |||
elseif source.type == 'dungeon' then | |||
listCat = 'boss' | |||
else | |||
listCat = 'other' | |||
end | |||
end | |||
table.insert(petList[listCat], petData.name) | |||
end | |||
local getIconList = | |||
function(pets) | |||
local result = {} | |||
for i, pet in ipairs(pets) do | |||
table.insert(result, Icons.Icon({pet, type='pet'})) | |||
end | |||
return table.concat(result, ' • ') | |||
end | |||
for i, catName in ipairs(petListOrder) do | |||
local catData = petList[catName] | |||
table.sort(catData, function(a, b) return a < b end) | |||
table.insert(resultPart, '\r\n|-\r\n!' .. Shared.titleCase(catName) .. ' Pets\r\n|' .. getIconList(catData)) | |||
end | end | ||
table.insert(resultPart, '\r\n|}') | table.insert(resultPart, '\r\n|}') |
edits