Add whitelist capabilities
This commit is contained in:
+59
-24
@@ -32,6 +32,7 @@ local chainItemsByBaseId
|
|||||||
local baseItemIds
|
local baseItemIds
|
||||||
local itemById
|
local itemById
|
||||||
local defaultBaseId
|
local defaultBaseId
|
||||||
|
local whitelistLookup
|
||||||
local fallbackIcon = false
|
local fallbackIcon = false
|
||||||
local backButton = false
|
local backButton = false
|
||||||
local scrollUpButton = false
|
local scrollUpButton = false
|
||||||
@@ -40,8 +41,40 @@ local overviewScrollCurrentRow = 0
|
|||||||
local overviewScrollTargetRow = 0
|
local overviewScrollTargetRow = 0
|
||||||
local drawOverview
|
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()
|
local function ensureChainsLoaded()
|
||||||
if not chainItemsByBaseId then
|
if not chainItemsByBaseId then
|
||||||
|
ensureWhitelistLoaded()
|
||||||
|
|
||||||
local file = assert(fs.open("atc_chains.json", "r"))
|
local file = assert(fs.open("atc_chains.json", "r"))
|
||||||
local data = textutils.unserializeJSON(file.readAll())
|
local data = textutils.unserializeJSON(file.readAll())
|
||||||
file.close()
|
file.close()
|
||||||
@@ -53,32 +86,34 @@ local function ensureChainsLoaded()
|
|||||||
itemById = {}
|
itemById = {}
|
||||||
|
|
||||||
for _, chain in ipairs(data.chains) do
|
for _, chain in ipairs(data.chains) do
|
||||||
if not defaultBaseId then
|
if not whitelistLookup or whitelistLookup[chain.base_id] then
|
||||||
defaultBaseId = chain.base_id
|
if not defaultBaseId then
|
||||||
end
|
defaultBaseId = chain.base_id
|
||||||
|
|
||||||
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
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
|||||||
|
[
|
||||||
|
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user