Add whitelist capabilities

This commit is contained in:
Max
2026-06-01 13:43:18 +02:00
parent 14961629f2
commit 8d9abc8cb2
3 changed files with 62 additions and 27718 deletions
+59 -24
View File
@@ -32,6 +32,7 @@ local chainItemsByBaseId
local baseItemIds
local itemById
local defaultBaseId
local whitelistLookup
local fallbackIcon = false
local backButton = false
local scrollUpButton = false
@@ -40,8 +41,40 @@ local overviewScrollCurrentRow = 0
local overviewScrollTargetRow = 0
local drawOverview
local function ensureWhitelistLoaded()
if whitelistLookup ~= nil then
return
end
if not fs.exists("whitelist.json") then
whitelistLookup = false
return
end
local file = assert(fs.open("whitelist.json", "r"))
local data = textutils.unserializeJSON(file.readAll())
file.close()
assert(type(data) == "table", "Invalid whitelist.json data")
if #data == 0 then
whitelistLookup = false
return
end
whitelistLookup = {}
for i = 1, #data do
local baseId = data[i]
assert(type(baseId) == "string", "Invalid whitelist.json entry")
whitelistLookup[baseId] = true
end
end
local function ensureChainsLoaded()
if not chainItemsByBaseId then
ensureWhitelistLoaded()
local file = assert(fs.open("atc_chains.json", "r"))
local data = textutils.unserializeJSON(file.readAll())
file.close()
@@ -53,32 +86,34 @@ local function ensureChainsLoaded()
itemById = {}
for _, chain in ipairs(data.chains) do
if not defaultBaseId then
defaultBaseId = chain.base_id
end
baseItemIds[#baseItemIds + 1] = chain.base_id
local items = {}
local itemCount = 0
for _, item in ipairs(chain.items or {}) do
if item.stage == "item" then
itemById[item.item_id] = {
id = item.item_id,
icon_nfp = item.icon_nfp_16x16,
}
else
itemCount = itemCount + 1
items[itemCount] = {
id = item.item_id,
icon_nfp = item.icon_nfp_16x16,
}
itemById[item.item_id] = items[itemCount]
if not whitelistLookup or whitelistLookup[chain.base_id] then
if not defaultBaseId then
defaultBaseId = chain.base_id
end
end
chainItemsByBaseId[chain.base_id] = items
baseItemIds[#baseItemIds + 1] = chain.base_id
local items = {}
local itemCount = 0
for _, item in ipairs(chain.items or {}) do
if item.stage == "item" then
itemById[item.item_id] = {
id = item.item_id,
icon_nfp = item.icon_nfp_16x16,
}
else
itemCount = itemCount + 1
items[itemCount] = {
id = item.item_id,
icon_nfp = item.icon_nfp_16x16,
}
itemById[item.item_id] = items[itemCount]
end
end
chainItemsByBaseId[chain.base_id] = items
end
end
end
end
File diff suppressed because one or more lines are too long
+3
View File
@@ -0,0 +1,3 @@
[
]