2024-08-18 00:34:13 +00:00
|
|
|
local __BUNDLER_FILES = {}
|
|
|
|
local __DEFAULT_IMPORT = require
|
|
|
|
local require = function(path)
|
|
|
|
return __BUNDLER_FILES[path]() or __DEFAULT_IMPORT(path)
|
2024-08-17 23:08:11 +00:00
|
|
|
end
|
|
|
|
|
2024-08-18 00:34:13 +00:00
|
|
|
__BUNDLER_FILES["updater.lua"] = function ()
|
|
|
|
local utils = require("utils.lua")
|
|
|
|
local LAST_USED = os.time()
|
|
|
|
local function checkForUpdate()
|
|
|
|
local current_time = os.time()
|
|
|
|
local difference = math.abs(current_time - LAST_USED)
|
|
|
|
print("Checking for update... difference: " .. tostring(difference))
|
|
|
|
--its been considerable time since the keypad was interacted with
|
|
|
|
--therefore it's time to force an update down the users throat (microsoft moment)
|
|
|
|
if difference > .5 then
|
|
|
|
local update_code_request = http.get("https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/main/keypadOS.lua")
|
|
|
|
if update_code_request then
|
|
|
|
local update_code_text = update_code_request.readAll()
|
|
|
|
if update_code_text then
|
|
|
|
if string.find(update_code_text, "^local __BUNDLER_FILES = {}") then
|
|
|
|
--make backup
|
|
|
|
fs.copy("startup.lua","backup.lua")
|
|
|
|
--install update
|
|
|
|
local file = fs.open("startup.lua", "w")
|
|
|
|
file.write(update_code_text)
|
|
|
|
file.close()
|
|
|
|
os.reboot()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2024-08-17 23:08:11 +00:00
|
|
|
end
|
2024-08-18 00:34:13 +00:00
|
|
|
function UpdateChecker()
|
|
|
|
while true do
|
|
|
|
checkForUpdate()
|
|
|
|
sleep(1)
|
|
|
|
end
|
2024-08-17 23:08:11 +00:00
|
|
|
end
|
2024-08-18 00:34:13 +00:00
|
|
|
function GetBasalt()
|
|
|
|
if fs.exists("basalt.lua") then
|
|
|
|
utils.MonPrint("Basalt found!")
|
|
|
|
else
|
|
|
|
utils.MonPrint("Downloading basalt...")
|
|
|
|
local basalt_code = http.get("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/versions/latest.lua").readAll()
|
|
|
|
utils.MonPrint("Installing basalt...")
|
|
|
|
local file = fs.open("basalt.lua", "w")
|
|
|
|
if not file then
|
|
|
|
utils.MonPrint("failed to get basalt")
|
|
|
|
sleep(60)
|
|
|
|
os.reboot()
|
|
|
|
end
|
2024-08-18 00:36:52 +00:00
|
|
|
file.write(utils.Cast(basalt_code))
|
2024-08-18 00:34:13 +00:00
|
|
|
file.close()
|
|
|
|
utils.MonPrint("Rebooting...")
|
|
|
|
os.reboot()
|
|
|
|
end
|
2024-08-17 23:08:11 +00:00
|
|
|
end
|
|
|
|
return {
|
2024-08-18 00:34:13 +00:00
|
|
|
UpdateChecker,
|
|
|
|
GetBasalt
|
2024-08-17 23:08:11 +00:00
|
|
|
}
|
|
|
|
|
2024-08-18 00:34:13 +00:00
|
|
|
end -- FILE END: updater.lua --
|
2024-08-17 23:08:11 +00:00
|
|
|
|
2024-08-18 00:34:13 +00:00
|
|
|
__BUNDLER_FILES["config.lua"] = function ()
|
|
|
|
return {
|
|
|
|
correctPin = "42169"
|
|
|
|
}
|
2024-08-17 23:08:11 +00:00
|
|
|
|
2024-08-18 00:34:13 +00:00
|
|
|
end -- FILE END: config.lua --
|
|
|
|
|
|
|
|
__BUNDLER_FILES["ui.lua"] = function ()
|
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
|
|
|
--- @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)
|
2024-08-17 23:08:11 +00:00
|
|
|
if drive.isDiskPresent() then
|
2024-08-18 00:34:13 +00:00
|
|
|
if drive.getDiskLabel() == config.correctPin then
|
|
|
|
ui.pin = config.correctPin
|
2024-08-17 23:08:11 +00:00
|
|
|
drive:ejectDisk()
|
|
|
|
end
|
|
|
|
end
|
2024-08-18 00:34:13 +00:00
|
|
|
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)
|
2024-08-17 23:08:11 +00:00
|
|
|
end
|
2024-08-18 00:34:13 +00:00
|
|
|
--- @param ui Ui
|
|
|
|
local function resetEverything(ui)
|
|
|
|
sleep(2)
|
|
|
|
ui.pin = ""
|
|
|
|
ui.pinLabel:setText("")
|
|
|
|
redstone.setOutput("front", false)
|
|
|
|
ui.enterButton:setBackground(colors.blue)
|
2024-08-17 23:08:11 +00:00
|
|
|
end
|
2024-08-18 00:34:13 +00:00
|
|
|
--- @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
|
|
|
|
function InitUi()
|
|
|
|
local ui = {
|
|
|
|
resetEverything,
|
|
|
|
unlockDoor,
|
|
|
|
addToPin,
|
|
|
|
main = basalt.addMonitor(monitor),
|
|
|
|
}
|
|
|
|
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
|
|
|
|
local status, _ = pcall(function ()
|
|
|
|
parallel.waitForAll(basalt.autoUpdate, updater.updateChecker)
|
|
|
|
end)
|
|
|
|
if not status then
|
|
|
|
monitor.clear()
|
|
|
|
fs.delete("basalt.lua")
|
|
|
|
fs.delete("startup.lua")
|
|
|
|
fs.copy("backup.lua", "startup.lua")
|
|
|
|
os.reboot()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return {
|
|
|
|
InitUi,
|
|
|
|
}
|
2024-08-17 23:08:11 +00:00
|
|
|
|
2024-08-18 00:34:13 +00:00
|
|
|
end -- FILE END: ui.lua --
|
2024-08-17 23:08:11 +00:00
|
|
|
|
2024-08-18 00:34:13 +00:00
|
|
|
__BUNDLER_FILES["utils.lua"] = function ()
|
2024-08-18 00:39:01 +00:00
|
|
|
-- Type coersion for lsp
|
|
|
|
---@generic T
|
|
|
|
---@param object any
|
|
|
|
---@return T
|
|
|
|
function Cast(object)
|
|
|
|
return object
|
|
|
|
end
|
2024-08-18 00:34:13 +00:00
|
|
|
--- @type Monitor
|
|
|
|
local MONITOR = Cast(peripheral.find("monitor"))
|
|
|
|
local MONITOR_Y = 1
|
|
|
|
function MonPrint(text)
|
|
|
|
MONITOR.setCursorPos(1,MONITOR_Y)
|
|
|
|
MONITOR.write(text)
|
|
|
|
MONITOR_Y = MONITOR_Y + 1
|
|
|
|
end
|
|
|
|
function MonReset(scale)
|
|
|
|
MONITOR.clear()
|
|
|
|
MONITOR.setTextScale(scale)
|
|
|
|
end
|
|
|
|
return {
|
|
|
|
MonPrint,
|
|
|
|
MonReset,
|
|
|
|
Cast,
|
|
|
|
}
|
2024-08-17 23:08:11 +00:00
|
|
|
|
2024-08-18 00:34:13 +00:00
|
|
|
end -- FILE END: utils.lua --
|
|
|
|
|
|
|
|
__BUNDLER_FILES["main.lua"] = function ()
|
|
|
|
-- keycardOS "bootloader", has no access to basalt
|
|
|
|
-- intended for checking for updates, and automatically updating basalt if it is missing
|
|
|
|
local utils = require("utils.lua")
|
|
|
|
local updater = require("updater.lua")
|
|
|
|
local ui = require("ui.lua")
|
|
|
|
KEYPADOS_VERSION = "3.0"
|
|
|
|
function Main()
|
|
|
|
utils.MonPrint(0.5)
|
|
|
|
updater.getBasalt()
|
|
|
|
utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION)
|
|
|
|
utils.MonPrint(1)
|
|
|
|
ui.InitUi()
|
2024-08-17 23:08:11 +00:00
|
|
|
end
|
2024-08-18 00:34:13 +00:00
|
|
|
return {
|
|
|
|
Main
|
|
|
|
}
|
|
|
|
|
|
|
|
end -- FILE END: main.lua --
|
2024-08-17 23:08:11 +00:00
|
|
|
|
2024-08-18 00:34:13 +00:00
|
|
|
require("main.lua").Main()
|