17,101
edits
(Restore getPotionNavbox after unintended removal) |
(getFarmingNavbox: Revise implementation, ensure all seeds and the grown result of all seeds is included) |
||
Line 12: | Line 12: | ||
function p.getFarmingNavbox(frame) | function p.getFarmingNavbox(frame) | ||
local | local resultPart = {} | ||
local | local seedsTable = {} | ||
local | local produceTable = {} | ||
for i, item in | for i, item in ipairs(ItemData.Items) do | ||
if item. | if item.farmingLevel ~= nil then | ||
local tier = item.tier | |||
if seedsTable[tier] == nil then | |||
-- Initialise tier tables | |||
seedsTable[tier] = {} | |||
produceTable[tier] = {} | |||
end | |||
if item.grownItemID ~= nil then | |||
local grownItem = Items.getItemByID(item.grownItemID) | |||
if grownItem ~= nil then | |||
table.insert( | table.insert(produceTable[tier], { ["name"] = grownItem.name, ["level"] = item.farmingLevel }) | ||
end | |||
end | |||
table.insert(seedsTable[tier], { ["name"] = item.name, ["level"] = item.farmingLevel }) | |||
end | end | ||
end | end | ||
return | -- Generate output table | ||
table.insert(resultPart, '{| class="wikitable mw-collapsible" style="margin:auto; clear:both; width: 100%"') | |||
table.insert(resultPart, '\r\n!colspan="2" style="padding-left:64px;"|' .. Icons.Icon({'Farming', type='skill'})) | |||
local getItemList = function(itemTable) | |||
local listPart = {} | |||
for i, item in ipairs(itemTable) do | |||
table.insert(listPart, Icons.Icon({item.name, type='item'})) | |||
end | |||
return table.concat(listPart, ' • ') | |||
end | |||
local sortFunc = function(a, b) return (a.level == b.level and a.name < b.name) or a.level < b.level end | |||
-- Determine tier list & order in which tiers will be listed in output | |||
local tierList = {} | |||
for tier, seeds in pairs(seedsTable) do | |||
table.insert(tierList, tier) | |||
end | |||
table.sort(tierList, function(a, b) return a < b end) | |||
-- Generate table section for each tier | |||
for i, tier in pairs(tierList) do | |||
-- Sort tables by Farming level order | |||
table.sort(seedsTable[tier], sortFunc) | |||
table.sort(produceTable[tier], sortFunc) | |||
table.insert(resultPart, '\r\n|-\r\n!colspan="2"| ' .. tier .. 's') | |||
table.insert(resultPart, '\r\n|-\r\n!scope="row"| Seeds') | |||
table.insert(resultPart, '\r\n|style="text-align:center;"| ' .. getItemList(seedsTable[tier])) | |||
table.insert(resultPart, '\r\n|-\r\n!scope="row"| Produce') | |||
table.insert(resultPart, '\r\n|style="text-align:center;"| ' .. getItemList(produceTable[tier])) | |||
end | |||
table.insert(resultPart, '\r\n|}') | |||
return table.concat(resultPart) | |||
end | end | ||