Add whitelist capabilities
This commit is contained in:
@@ -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,6 +86,7 @@ local function ensureChainsLoaded()
|
|||||||
itemById = {}
|
itemById = {}
|
||||||
|
|
||||||
for _, chain in ipairs(data.chains) do
|
for _, chain in ipairs(data.chains) do
|
||||||
|
if not whitelistLookup or whitelistLookup[chain.base_id] then
|
||||||
if not defaultBaseId then
|
if not defaultBaseId then
|
||||||
defaultBaseId = chain.base_id
|
defaultBaseId = chain.base_id
|
||||||
end
|
end
|
||||||
@@ -81,6 +115,7 @@ local function ensureChainsLoaded()
|
|||||||
chainItemsByBaseId[chain.base_id] = items
|
chainItemsByBaseId[chain.base_id] = items
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getPageItems(base_id)
|
local function getPageItems(base_id)
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
|||||||
|
[
|
||||||
|
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user