Anonymous

Module:Navboxes: Difference between revisions

From Melvor Idle
Cleaned up Single Navbox functions; Added Expansion Icons; Separated Prayers and Unholy Prayers
(getSkillcapeNavbox: Add superior capes)
(Cleaned up Single Navbox functions; Added Expansion Icons; Separated Prayers and Unholy Prayers)
 
(7 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 63: Line 123:
function p.getFoodNavbox(frame)
function p.getFoodNavbox(frame)
local foundIDs, cookedFood, harvestedFood, otherFood = {}, {}, {}, {}
local foundIDs, cookedFood, harvestedFood, otherFood = {}, {}, {}, {}
 
-- Exclude unobtainable lemonade
foundIDs['melvorTotH:Lemonade_Full'] = true
-- Cooked food
-- Cooked food
for i, recipe in ipairs(SkillData.Cooking.recipes) do
for i, recipe in ipairs(SkillData.Cooking.recipes) do
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 82: Line 148:
if perfectItem ~= nil then
if perfectItem ~= nil then
perfectName = perfectItem.name
perfectName = perfectItem.name
foundIDs[recipe.perfectCookID] = true
end
end
end
end
Line 196: 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 339: Line 407:
end
end


function p.getFamiliarNavbox(frame)
function p.getFishingNavbox(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()
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
 
function p.getFishingNavbox()
local categoryHeader = {}
local categoryHeader = {}
local categoryItems = {}
local categoryItems = {}
Line 490: 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|}')
463

edits