Module:Navboxes: Difference between revisions

Cleaned up Single Navbox functions; Added Expansion Icons; Separated Prayers and Unholy Prayers
(Update for v1.1)
(Cleaned up Single Navbox functions; Added Expansion Icons; Separated Prayers and Unholy Prayers)
 
(10 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 18: Line 78:
for i, recipe in ipairs(SkillData.Farming.recipes) do
for i, recipe in ipairs(SkillData.Farming.recipes) do
local seed = Items.getItemByID(recipe.seedCost.id)
local seed = Items.getItemByID(recipe.seedCost.id)
local product = Items.getItemByID(recipe.productID)
local product = Items.getItemByID(recipe.productId)
local tier = recipe.categoryID
local tier = recipe.categoryID
if seedsTable[tier] == nil then
if seedsTable[tier] == nil then
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.itemID)
local cookedItem = Items.getItemByID(recipe.productID)
if cookedItem ~= nil then
if cookedItem ~= nil then
local catIdx = recipe.categoryID
local catIdx = recipe.categoryID
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 94: Line 159:
for i, recipe in ipairs(SkillData.Farming.recipes) do
for i, recipe in ipairs(SkillData.Farming.recipes) do
if not foundIDs[recipe.productID] then
if not foundIDs[recipe.productID] then
local product = Items.getItemByID(recipe.productID)
local product = Items.getItemByID(recipe.productId)
if product.healsFor ~= nil then
if product.healsFor ~= nil then
table.insert(harvestedFood, { ["name"] = product.name, ["order"] = recipe.level })
table.insert(harvestedFood, { ["name"] = product.name, ["order"] = recipe.level })
Line 127: Line 192:
local getFoodList = function(foodTable)
local getFoodList = function(foodTable)
local listPart = {}
local listPart = {}
for i, food in ipairs(foodTable) do
if type(foodTable) == 'table' then
local foodText = Icons.Icon({food.name, type='item'})
for i, food in ipairs(foodTable) do
if food.perfectName ~= nil then
local foodText = Icons.Icon({food.name, type='item'})
foodText = Icons.Icon({food.perfectName, type='item', notext=true}) .. ' ' .. foodText
if food.perfectName ~= nil then
foodText = Icons.Icon({food.perfectName, type='item', notext=true}) .. ' ' .. foodText
end
table.insert(listPart, foodText)
end
end
table.insert(listPart, foodText)
end
end
return table.concat(listPart, ' • ')
return table.concat(listPart, ' • ')
Line 170: Line 237:
local potFirstItem = Items.getItemByID(potData.potionIDs[1])
local potFirstItem = Items.getItemByID(potData.potionIDs[1])
local potName = string.gsub(potFirstItem.name, ' Potion [IV]+$', '')
local potName = string.gsub(potFirstItem.name, ' Potion [IV]+$', '')
table.insert(potList[potData.category], { ["name"] = potName, ["order"] = potData.level, ["img"] = potFirstItem.name })
table.insert(potList[potData.categoryID], { ["name"] = potName, ["order"] = potData.level, ["img"] = potFirstItem.name })
end
end


Line 194: 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 240: Line 310:
table.insert(resultPart, '\r\n!colspan="2"|' .. Icons.Icon({'Runes', type='item', img='Air Rune'}))
table.insert(resultPart, '\r\n!colspan="2"|' .. Icons.Icon({'Runes', type='item', img='Air Rune'}))
for i, catID in ipairs(categoryIDs) do
for i, catID in ipairs(categoryIDs) do
local category = GameData.getEntityByID(SkillData.Runecrafting.categories)
local category = GameData.getEntityByID(SkillData.Runecrafting.categories, catID)
if category ~= nil then
if category ~= nil then
table.sort(runeList[catID], function(a, b) return (a.order == b.order and a.name < b.name) or a.order < b.order end)
table.sort(runeList[catID], function(a, b) return (a.order == b.order and a.name < b.name) or a.order < b.order end)
Line 258: Line 328:


function p.getSkillcapeNavbox(frame)
function p.getSkillcapeNavbox(frame)
local capeList = Shop.getPurchases(function(purch) return purch.category == 'melvorD:Skillcapes' end)
local capeList = {
["Normal"] = Shop.getPurchases(function(purch) return purch.category == 'melvorD:Skillcapes' end),
["Superior"] = Shop.getPurchases(function(purch) return purch.category == 'melvorTotH:SuperiorSkillcapes' end)
}


local capeNames = {}
local capeNames = {}
for i, cape in ipairs(capeList) do
for catName, subList in pairs(capeList) do
if cape.contains ~= nil and cape.contains.items ~= nil then
for i, cape in ipairs(subList) do
local item = Items.getItemByID(cape.contains.items[1].id)
capeNames[cape.id] = Shop._getPurchaseName(cape)
if item ~= nil then
end
capeNames[cape.id] = item.name
table.sort(capeList[catName], function(a, b)
local costA, costB = Shop._getPurchaseSortValue(a), Shop._getPurchaseSortValue(b)
if costA == costB then
return capeNames[a.id] < capeNames[b.id]
else
return costA < costB
end
end
end
end)
end
end
table.sort(capeList, function(a, b)
if a.cost.gp == b.cost.gp then
return capeNames[a.id] < capeNames[b.id]
else
return a.cost.gp < b.cost.gp
end
end)


local capeText = {}
local capeText = {}
Line 285: Line 356:
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({'Skillcapes', type='item', img='Cape of Completion'}))
table.insert(resultPart, '\r\n!colspan="2"| ' .. Icons.Icon({'Skillcapes', type='item', img='Cape of Completion'}))
table.insert(resultPart, '\r\n|-\r\n|style="text-align:center;"|'..table.concat(capeText, ' • '))
for catName, subList in pairs(capeList) do
local capeText = {}
table.insert(resultPart, '\r\n|-\r\n!style="text-align:center;"| ' .. catName)
for i, cape in ipairs(subList) do
table.insert(capeText, Icons.Icon({capeNames[cape.id], type='item'}))
end
table.insert(resultPart, '\r\n|style="text-align:center;"| ' .. table.concat(capeText, ' • '))
end
table.insert(resultPart, '\r\n|}')
table.insert(resultPart, '\r\n|}')


Line 296: Line 374:
for i, spellBook in ipairs(Magic.spellBooks) do
for i, spellBook in ipairs(Magic.spellBooks) do
spellTable[spellBook.id] = {}
spellTable[spellBook.id] = {}
local spells = p.getSpellsBySpellBook(spellBook.id)
local spells = Magic.getSpellsBySpellBook(spellBook.id)
for j, spell in ipairs(spells) do
for j, spell in ipairs(spells) do
table.insert(spellTable[spellBook.id], { ["name"] = spell.name, ["order"] = spell.level })
table.insert(spellTable[spellBook.id], { ["name"] = spell.name, ["order"] = spell.level })
Line 329: 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 393: Line 424:
for j, fishID in ipairs(area.fishIDs) do
for j, fishID in ipairs(area.fishIDs) do
local fishItem = Items.getItemByID(fishID)
local fishItem = Items.getItemByID(fishID)
local recipe = GameData.getEntityByID(SkillData.Fishing.recipes, fishID)
local recipe = GameData.getEntityByID(SkillData.Fishing.fish, fishID)
if fishItem ~= nil and recipe ~= nil then
if fishItem ~= nil and recipe ~= nil then
addCatData(area.name, 'Fishing#Fishing Areas', fishItem.name, recipe.level)
addCatData(area.name, 'Fishing#Fishing Areas', fishItem.name, recipe.level)
Line 445: Line 476:
for i, recipe in ipairs(SkillData.Smithing.recipes) do
for i, recipe in ipairs(SkillData.Smithing.recipes) do
if recipe.categoryID == 'melvorD:Bars' then
if recipe.categoryID == 'melvorD:Bars' then
local item = Items.getItemByID(recipe.itemID)
local item = Items.getItemByID(recipe.productID)
if item ~= nil then
if item ~= nil then
local displayName = string.gsub(item.name, ' Bar$', '')
local displayName = string.gsub(item.name, ' Bar$', '')
Line 460: Line 491:
-- Compile list of ores
-- Compile list of ores
for i, recipe in ipairs(SkillData.Mining.rockData) do
for i, recipe in ipairs(SkillData.Mining.rockData) do
if barOreIDs[recipe.productID] then
if barOreIDs[recipe.productId] then
local item = Items.getItemByID(recipe.productID)
local item = Items.getItemByID(recipe.productId)
if item ~= nil then
if item ~= nil then
table.insert(categoryItems['Ores'], { ["name"] = item.name, ["display"] = recipe.name, ["order"] = recipe.level })
table.insert(categoryItems['Ores'], { ["name"] = item.name, ["display"] = recipe.name, ["order"] = recipe.level })
Line 480: 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