16,999
edits
(getThievingNavbox: Move from Module:Skills) |
(getFoodNavbox: Revise implementation to include all current and hopefully all future food) |
||
Line 58: | Line 58: | ||
function p.getFoodNavbox(frame) | function p.getFoodNavbox(frame) | ||
local | local foundIDs, cookedFood, harvestedFood, otherFood = {}, {}, {}, {} | ||
-- Hide Lemon cake | |||
for i, item in | foundIDs[1029] = true | ||
if | foundIDs[1061] = true | ||
-- Harvested food first | |||
for i, item in ipairs(ItemData.Items) do | |||
if item.grownItemID ~= nil then | |||
local grownItem = Items.getItemByID(item.grownItemID) | |||
if grownItem ~= nil and grownItem.canEat then | |||
table.insert(harvestedFood, { ["name"] = grownItem.name, ["order"] = item.farmingLevel }) | |||
foundIDs[grownItem.id] = true | |||
end | |||
end | end | ||
end | end | ||
-- Any cooked & other food | |||
for i, item in ipairs(ItemData.Items) do | |||
-- If an item can be eaten then it must be food | |||
if foundIDs[i - 1] == nil and item.canEat then | |||
if item.cookingCategory ~= nil then | |||
-- Item is cooked, such food items are split by category | |||
if cookedFood[item.cookingCategory + 1] == nil then | |||
cookedFood[item.cookingCategory + 1] = {} | |||
end | |||
local perfectName = nil | |||
if item.perfectItem ~= nil then | |||
local perfectItem = Items.getItemByID(item.perfectItem) | |||
if perfectItem ~= nil then | |||
perfectName = perfectItem.name | |||
foundIDs[item.perfectItem] = true | |||
end | |||
table.insert( | end | ||
table.insert(cookedFood[item.cookingCategory + 1], { ["name"] = item.name, ["order"] = item.cookingLevel, ["perfectName"] = perfectName }) | |||
else | else | ||
table.insert( | -- Item cannot be cooked or grown, but can be eaten | ||
table.insert(otherFood, { ["name"] = item.name, ["order"] = item.id }) | |||
end | |||
foundIDs[i - 1] = true | |||
end | |||
end | |||
-- Sort food lists | |||
local sortFunc = function(a, b) return (a.order == b.order and a.name < b.name) or a.order < b.order end | |||
for i, items in pairs(cookedFood) do | |||
table.sort(cookedFood[i], sortFunc) | |||
end | |||
table.sort(harvestedFood, sortFunc) | |||
table.sort(otherFood, sortFunc) | |||
-- Generate food lists for final output | |||
local cookingCatHeader = { | |||
Icons.Icon({'Normal Cooking Fire', 'Cooking Fire', type='upgrade', nolink=true}), | |||
Icons.Icon({'Basic Furnace', 'Furnace', type='upgrade', nolink=true}), | |||
Icons.Icon({'Basic Pot', 'Pot', type='upgrade', nolink=true}) | |||
} | |||
local getFoodList = function(foodTable) | |||
local listPart = {} | |||
for i, food in ipairs(foodTable) do | |||
local foodText = Icons.Icon({food.name, type='item'}) | |||
if food.perfectName ~= nil then | |||
foodText = Icons.Icon({food.perfectName, type='item', notext=true}) .. ' ' .. foodText | |||
end | |||
table.insert(listPart, foodText) | |||
end | end | ||
return table.concat(listPart, ' • ') | |||
end | end | ||
local resultPart = {} | |||
table.insert(resultPart, '{| class="wikitable mw-collapsible" style="margin:0 auto 10px; clear:both; width: 100%"') | |||
table.insert(resultPart, '\r\n|-\r\n!style="background-color:#275C87;color:#FFFFFF;" colspan="2"| [[File:Crab_(item).svg|25px|link=Food]] [[Food]]') | |||
table.insert(resultPart, '\r\n|-\r\n!colspan="2"| Cooked') | |||
for catID, foodTable in ipairs(cookedFood) do | |||
table.insert(resultPart, '\r\n|-\r\n!scope="row"| ' .. cookingCatHeader[catID]) | |||
table.insert(resultPart, '\r\n|style="text-align:center;"| ' .. getFoodList(foodTable)) | |||
end | end | ||
table.insert(resultPart, '\r\n|-\r\n!colspan="2"| Harvested') | |||
table.insert(resultPart, '\r\n|-\r\n|colspan="2" style="text-align:center;"| ' .. getFoodList(harvestedFood)) | |||
table.insert(resultPart, '\r\n|-\r\n!colspan="2"| Other') | |||
table.insert(resultPart, '\r\n|-\r\n|colspan="2" style="text-align:center;"| ' .. getFoodList(otherFood)) | |||
table.insert(resultPart, '\r\n|}') | |||
return table.concat(resultPart) | |||
end | end | ||