Module:Navboxes: Difference between revisions

getFarmingNavbox: Consistency of formatting with header row; getOreBarNavbox: Initial implementation
(Exclude navbox contents from search index)
(getFarmingNavbox: Consistency of formatting with header row; getOreBarNavbox: Initial implementation)
Line 38: Line 38:
-- Generate output table
-- Generate output table
table.insert(resultPart, '{| class="wikitable mw-collapsible navigation-not-searchable" style="margin:auto; clear:both; width: 100%"')
table.insert(resultPart, '{| class="wikitable mw-collapsible navigation-not-searchable" style="margin:auto; clear:both; width: 100%"')
table.insert(resultPart, '\r\n!colspan="2" style="padding-left:64px;"|' .. Icons.Icon({'Farming', type='skill'}))
table.insert(resultPart, '\r\n!style="background-color:#275C87;color:#FFFFFF;padding-left:64px;" colspan="2"|' .. Icons.Icon({'Farming', type='skill'}))


local getItemList = function(itemTable)
local getItemList = function(itemTable)
Line 452: Line 452:
table.insert(resultPart, '\r\n|}')
table.insert(resultPart, '\r\n|}')


return table.concat(resultPart)
end
function p.getOreBarNavbox(frame)
local categoryList = { 'Ores', 'Bars' }
local categoryItems = { ["Ores"] = {}, ["Bars"] = {} }
local barOreIDs = {}
-- Compile list of bars
-- Also compile a list of ores used to create these bars, used to filter out non-bar ores later
for i, recipe in ipairs(SkillData.Smithing.Recipes) do
if recipe.category == 0 then
-- Category 0 = Bars
local item = Items.getItemByID(recipe.itemID)
if item ~= nil then
local displayName = string.gsub(item.name, ' Bar$', '')
table.insert(categoryItems['Bars'], { ["name"] = item.name, ["display"] = displayName, ["order"] = recipe.level })
end
-- Add to barOreIDs list
for j, costDef in ipairs(recipe.itemCosts) do
if barOreIDs[costDef.id] == nil then
barOreIDs[costDef.id] = true
end
end
end
end
-- Compile list of ores
for i, recipe in ipairs(SkillData.Mining.Rocks) do
if barOreIDs[recipe.oreID] then
local item = Items.getItemByID(recipe.oreID)
if item ~= nil then
table.insert(categoryItems['Ores'], { ["name"] = item.name, ["display"] = recipe.name, ["order"] = recipe.levelRequired })
end
end
end
local resultPart = {}
-- Generate navbox header
table.insert(resultPart, '{| class="wikitable mw-collapsible navigation-not-searchable" style="margin:auto; clear:both; width: 100%"')
table.insert(resultPart, '\r\n|-\r\n!style="background-color:#275C87;color:#FFFFFF;padding-left:64px;" colspan="2" | ' .. '<b>Ores & Bars</b>')
-- Generate navbox content
for i, cat in ipairs(categoryList) do
table.sort(categoryItems[cat], function(a, b) return (a.order == b.order and a.display < b.display) or a.order < b.order end)
local listPart = {}
for j, listItem in ipairs(categoryItems[cat]) do
table.insert(listPart, Icons.Icon({ listItem.name, listItem.display, type = 'item' }))
end
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)
return table.concat(resultPart)
end
end


return p
return p