2024-08-18 00:36:52 +00:00
|
|
|
local utils = require("utils.lua")
|
2024-08-18 00:34:13 +00:00
|
|
|
local basalt = require("basalt")
|
|
|
|
local config = require("config.lua")
|
|
|
|
local updater = require("updater.lua")
|
|
|
|
--- @type Monitor
|
2024-08-18 00:36:52 +00:00
|
|
|
local monitor = utils.Cast(peripheral.find("monitor"))
|
2024-08-18 00:34:13 +00:00
|
|
|
--- @type drive
|
2024-08-18 00:36:52 +00:00
|
|
|
local drive = utils.Cast(peripheral.find("drive"))
|
2024-08-18 00:34:13 +00:00
|
|
|
|
2024-08-18 01:34:08 +00:00
|
|
|
local mod = {}
|
|
|
|
|
2024-08-18 00:34:13 +00:00
|
|
|
--- @class Ui
|
|
|
|
--- @field pin string
|
|
|
|
--- @field main any
|
|
|
|
--- @field pinLabel any
|
|
|
|
--- @field enterButton any
|
|
|
|
--- @field resetEverything function
|
|
|
|
--- @field unlockDoor function
|
|
|
|
--- @field addToPin function
|
|
|
|
|
|
|
|
--- @param ui Ui
|
|
|
|
local function unlockDoor(ui)
|
|
|
|
if drive.isDiskPresent() then
|
|
|
|
if drive.getDiskLabel() == config.correctPin then
|
|
|
|
ui.pin = config.correctPin
|
|
|
|
drive:ejectDisk()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
basalt.debug("test")
|
|
|
|
if ui.pin == config.correctPin then
|
|
|
|
ui.enterButton:setBackground(colors.green)
|
|
|
|
ui.pinLabel:setText("Welcome")
|
|
|
|
redstone.setOutput("front", true)
|
|
|
|
|
|
|
|
if drive.isDiskPresent() then
|
|
|
|
if drive.getDiskLabel() == nil then
|
|
|
|
drive.setDiskLabel(config.correctPin)
|
|
|
|
ui.pinLabel:setText("Crd set")
|
|
|
|
drive:ejectDisk()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
ui.pinLabel:setText("Wrong")
|
|
|
|
ui.enterButton:setBackground(colors.red)
|
|
|
|
end
|
|
|
|
ui.main:addThread()
|
|
|
|
:start(ui.resetEverything)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- @param ui Ui
|
|
|
|
local function resetEverything(ui)
|
|
|
|
sleep(2)
|
|
|
|
ui.pin = ""
|
|
|
|
ui.pinLabel:setText("")
|
|
|
|
redstone.setOutput("front", false)
|
|
|
|
ui.enterButton:setBackground(colors.blue)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- @param ui Ui
|
|
|
|
local function addToPin(ui, i)
|
|
|
|
|
|
|
|
if #ui.pin >= 5 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
ui.pin = ui.pin .. tostring(i)
|
|
|
|
ui.pinLabel:setText(ui.pin)
|
|
|
|
end
|
|
|
|
|
2024-08-18 01:34:08 +00:00
|
|
|
function mod.InitUi()
|
2024-08-18 00:34:13 +00:00
|
|
|
local ui = {
|
|
|
|
resetEverything,
|
|
|
|
unlockDoor,
|
|
|
|
addToPin,
|
2024-08-18 01:40:57 +00:00
|
|
|
main = basalt.addMonitor(),
|
2024-08-18 00:34:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui.main:setMonitor(monitor)
|
|
|
|
ui.pinLabel = ui.main:addLabel()
|
|
|
|
:setText("")
|
|
|
|
:setFontSize(1)
|
|
|
|
|
|
|
|
ui.enterButton = ui.main:addButton()
|
|
|
|
:setText(">>>>")
|
|
|
|
:setBackground(colors.blue)
|
|
|
|
:setPosition(6,3)
|
|
|
|
:setSize(1.5,3.2)
|
|
|
|
:onClick(function()
|
|
|
|
unlockDoor(ui)
|
|
|
|
end)
|
|
|
|
|
|
|
|
local btnX = 1
|
|
|
|
local btnY = 3
|
|
|
|
|
|
|
|
for i = 1, 9 do
|
|
|
|
ui.main:addButton()
|
|
|
|
:setPosition(btnX, btnY)
|
|
|
|
:setText(tostring(i))
|
|
|
|
:setSize(2,1)
|
|
|
|
:onClick(function()
|
|
|
|
addToPin(ui, i)
|
|
|
|
end)
|
|
|
|
btnX = btnX + 2
|
|
|
|
if btnX >= 6 then
|
|
|
|
btnY = btnY + 1
|
|
|
|
btnX = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2024-08-18 01:50:23 +00:00
|
|
|
local status, err = pcall(function ()
|
2024-08-18 01:52:11 +00:00
|
|
|
parallel.waitForAll(basalt.autoUpdate, updater.UpdateChecker)
|
2024-08-18 00:34:13 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
if not status then
|
2024-08-18 01:50:23 +00:00
|
|
|
print("Error detected: " .. err)
|
2024-08-18 00:34:13 +00:00
|
|
|
monitor.clear()
|
|
|
|
fs.delete("basalt.lua")
|
|
|
|
fs.delete("startup.lua")
|
|
|
|
fs.copy("backup.lua", "startup.lua")
|
2024-08-18 01:54:28 +00:00
|
|
|
os.exit()
|
|
|
|
-- os.reboot()
|
2024-08-18 00:34:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-08-18 01:34:08 +00:00
|
|
|
return mod
|