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
|
||||||
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()
|
local function ensureChainsLoaded()
|
||||||
if not chainItemsByBaseId then
|
if not chainItemsByBaseId then
|
||||||
ensureWhitelistLoaded()
|
ensureWhitelistLoaded()
|
||||||
@@ -131,10 +153,14 @@ local function ensureChainsLoaded()
|
|||||||
|
|
||||||
if chain.base_id then
|
if chain.base_id then
|
||||||
for _, item in ipairs(chain.items or {}) do
|
for _, item in ipairs(chain.items or {}) do
|
||||||
|
local compressionLevel = getCompressionLevel(item.item_id, item.stage)
|
||||||
|
|
||||||
if item.stage == "item" then
|
if item.stage == "item" then
|
||||||
itemById[item.item_id] = {
|
itemById[item.item_id] = {
|
||||||
id = item.item_id,
|
id = item.item_id,
|
||||||
icon_nfp = item.icon_nfp_16x16,
|
icon_nfp = item.icon_nfp_16x16,
|
||||||
|
compression_level = compressionLevel,
|
||||||
|
compression_factor = 9 ^ compressionLevel,
|
||||||
}
|
}
|
||||||
allChainItemIds[#allChainItemIds + 1] = item.item_id
|
allChainItemIds[#allChainItemIds + 1] = item.item_id
|
||||||
else
|
else
|
||||||
@@ -142,24 +168,33 @@ local function ensureChainsLoaded()
|
|||||||
items[itemCount] = {
|
items[itemCount] = {
|
||||||
id = item.item_id,
|
id = item.item_id,
|
||||||
icon_nfp = item.icon_nfp_16x16,
|
icon_nfp = item.icon_nfp_16x16,
|
||||||
|
compression_level = compressionLevel,
|
||||||
|
compression_factor = 9 ^ compressionLevel,
|
||||||
}
|
}
|
||||||
itemById[item.item_id] = items[itemCount]
|
itemById[item.item_id] = items[itemCount]
|
||||||
allChainItemIds[#allChainItemIds + 1] = item.item_id
|
allChainItemIds[#allChainItemIds + 1] = item.item_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
local baseCompressionLevel = getCompressionLevel(baseId, "item")
|
||||||
|
|
||||||
itemById[baseId] = {
|
itemById[baseId] = {
|
||||||
id = baseId,
|
id = baseId,
|
||||||
icon_nfp = chain[2],
|
icon_nfp = chain[2],
|
||||||
|
compression_level = baseCompressionLevel,
|
||||||
|
compression_factor = 9 ^ baseCompressionLevel,
|
||||||
}
|
}
|
||||||
allChainItemIds[#allChainItemIds + 1] = baseId
|
allChainItemIds[#allChainItemIds + 1] = baseId
|
||||||
|
|
||||||
for i = 1, #(chain[3] or {}) do
|
for i = 1, #(chain[3] or {}) do
|
||||||
local compactItem = chain[3][i]
|
local compactItem = chain[3][i]
|
||||||
|
local compressionLevel = getCompressionLevel(compactItem[1], nil)
|
||||||
itemCount = itemCount + 1
|
itemCount = itemCount + 1
|
||||||
items[itemCount] = {
|
items[itemCount] = {
|
||||||
id = compactItem[1],
|
id = compactItem[1],
|
||||||
icon_nfp = compactItem[2],
|
icon_nfp = compactItem[2],
|
||||||
|
compression_level = compressionLevel,
|
||||||
|
compression_factor = 9 ^ compressionLevel,
|
||||||
}
|
}
|
||||||
itemById[compactItem[1]] = items[itemCount]
|
itemById[compactItem[1]] = items[itemCount]
|
||||||
allChainItemIds[#allChainItemIds + 1] = compactItem[1]
|
allChainItemIds[#allChainItemIds + 1] = compactItem[1]
|
||||||
@@ -410,6 +445,36 @@ local function hasGlobalItemCounts()
|
|||||||
return next(globalItemCounts) ~= nil
|
return next(globalItemCounts) ~= nil
|
||||||
end
|
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()
|
local function createGlobalCountRefreshJob()
|
||||||
ensureChainsLoaded()
|
ensureChainsLoaded()
|
||||||
|
|
||||||
@@ -981,10 +1046,10 @@ local function drawPage(base_id)
|
|||||||
return pageItems
|
return pageItems
|
||||||
end,
|
end,
|
||||||
getInitialCounts = function()
|
getInitialCounts = function()
|
||||||
return getGlobalItemCounts()
|
return getEquivalentLevelCounts(base_id, pageItems, getGlobalItemCounts())
|
||||||
end,
|
end,
|
||||||
getEntriesAndCountsFromCache = function(currentEntries)
|
getEntriesAndCountsFromCache = function(currentEntries)
|
||||||
return currentEntries, getGlobalItemCounts()
|
return currentEntries, getEquivalentLevelCounts(base_id, pageItems, getGlobalItemCounts())
|
||||||
end,
|
end,
|
||||||
getId = function(entry)
|
getId = function(entry)
|
||||||
return entry.id
|
return entry.id
|
||||||
|
|||||||
Reference in New Issue
Block a user