Implement the page now showing equivalent item counts for all compression levels
This commit is contained in:
+67
-2
@@ -95,6 +95,28 @@ local function ensureWhitelistLoaded()
|
||||
end
|
||||
end
|
||||
|
||||
local function getCompressionLevel(itemId, stage)
|
||||
if stage == "item" then
|
||||
return 0
|
||||
end
|
||||
|
||||
if type(stage) == "string" then
|
||||
local level = tonumber(stage:match("^(%d+)x$"))
|
||||
if level then
|
||||
return level
|
||||
end
|
||||
end
|
||||
|
||||
if type(itemId) == "string" then
|
||||
local level = tonumber(itemId:match("_(%d+)x$"))
|
||||
if level then
|
||||
return level
|
||||
end
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
local function ensureChainsLoaded()
|
||||
if not chainItemsByBaseId then
|
||||
ensureWhitelistLoaded()
|
||||
@@ -131,10 +153,14 @@ local function ensureChainsLoaded()
|
||||
|
||||
if chain.base_id then
|
||||
for _, item in ipairs(chain.items or {}) do
|
||||
local compressionLevel = getCompressionLevel(item.item_id, item.stage)
|
||||
|
||||
if item.stage == "item" then
|
||||
itemById[item.item_id] = {
|
||||
id = item.item_id,
|
||||
icon_nfp = item.icon_nfp_16x16,
|
||||
compression_level = compressionLevel,
|
||||
compression_factor = 9 ^ compressionLevel,
|
||||
}
|
||||
allChainItemIds[#allChainItemIds + 1] = item.item_id
|
||||
else
|
||||
@@ -142,24 +168,33 @@ local function ensureChainsLoaded()
|
||||
items[itemCount] = {
|
||||
id = item.item_id,
|
||||
icon_nfp = item.icon_nfp_16x16,
|
||||
compression_level = compressionLevel,
|
||||
compression_factor = 9 ^ compressionLevel,
|
||||
}
|
||||
itemById[item.item_id] = items[itemCount]
|
||||
allChainItemIds[#allChainItemIds + 1] = item.item_id
|
||||
end
|
||||
end
|
||||
else
|
||||
local baseCompressionLevel = getCompressionLevel(baseId, "item")
|
||||
|
||||
itemById[baseId] = {
|
||||
id = baseId,
|
||||
icon_nfp = chain[2],
|
||||
compression_level = baseCompressionLevel,
|
||||
compression_factor = 9 ^ baseCompressionLevel,
|
||||
}
|
||||
allChainItemIds[#allChainItemIds + 1] = baseId
|
||||
|
||||
for i = 1, #(chain[3] or {}) do
|
||||
local compactItem = chain[3][i]
|
||||
local compressionLevel = getCompressionLevel(compactItem[1], nil)
|
||||
itemCount = itemCount + 1
|
||||
items[itemCount] = {
|
||||
id = compactItem[1],
|
||||
icon_nfp = compactItem[2],
|
||||
compression_level = compressionLevel,
|
||||
compression_factor = 9 ^ compressionLevel,
|
||||
}
|
||||
itemById[compactItem[1]] = items[itemCount]
|
||||
allChainItemIds[#allChainItemIds + 1] = compactItem[1]
|
||||
@@ -410,6 +445,36 @@ local function hasGlobalItemCounts()
|
||||
return next(globalItemCounts) ~= nil
|
||||
end
|
||||
|
||||
local function getBaseEquivalentCount(baseId, itemCounts)
|
||||
local total = 0
|
||||
local baseItem = getItemById(baseId)
|
||||
local pageItems = getPageItems(baseId)
|
||||
|
||||
if baseItem then
|
||||
total = total + (tonumber(itemCounts[baseId]) or 0) * (baseItem.compression_factor or 1)
|
||||
end
|
||||
|
||||
for i = 1, #pageItems do
|
||||
local item = pageItems[i]
|
||||
total = total + (tonumber(itemCounts[item.id]) or 0) * (item.compression_factor or 1)
|
||||
end
|
||||
|
||||
return total
|
||||
end
|
||||
|
||||
local function getEquivalentLevelCounts(baseId, pageItems, itemCounts)
|
||||
local equivalentCounts = {}
|
||||
local baseEquivalentCount = getBaseEquivalentCount(baseId, itemCounts)
|
||||
|
||||
for i = 1, #pageItems do
|
||||
local item = pageItems[i]
|
||||
local factor = item.compression_factor or 1
|
||||
equivalentCounts[item.id] = math.floor(baseEquivalentCount / factor)
|
||||
end
|
||||
|
||||
return equivalentCounts
|
||||
end
|
||||
|
||||
local function createGlobalCountRefreshJob()
|
||||
ensureChainsLoaded()
|
||||
|
||||
@@ -981,10 +1046,10 @@ local function drawPage(base_id)
|
||||
return pageItems
|
||||
end,
|
||||
getInitialCounts = function()
|
||||
return getGlobalItemCounts()
|
||||
return getEquivalentLevelCounts(base_id, pageItems, getGlobalItemCounts())
|
||||
end,
|
||||
getEntriesAndCountsFromCache = function(currentEntries)
|
||||
return currentEntries, getGlobalItemCounts()
|
||||
return currentEntries, getEquivalentLevelCounts(base_id, pageItems, getGlobalItemCounts())
|
||||
end,
|
||||
getId = function(entry)
|
||||
return entry.id
|
||||
|
||||
Reference in New Issue
Block a user