diff --git a/keypadOS.lua b/keypadOS.lua index 5b8f4a1..6f15fdd 100644 --- a/keypadOS.lua +++ b/keypadOS.lua @@ -11,6 +11,7 @@ end rawset(__BUNDLER_FILES, "updater.lua", function () local utils = require("utils.lua") local LAST_USED = os.time() + local mod = {} local function checkForUpdate() local current_time = os.time() local difference = math.abs(current_time - LAST_USED) @@ -35,13 +36,13 @@ rawset(__BUNDLER_FILES, "updater.lua", function () end end end - function UpdateChecker() + function mod.UpdateChecker() while true do checkForUpdate() sleep(1) end end - function GetBasalt() + function mod.GetBasalt() if fs.exists("basalt.lua") then utils.MonPrint("Basalt found!") else @@ -60,10 +61,7 @@ rawset(__BUNDLER_FILES, "updater.lua", function () os.reboot() end end - return { - UpdateChecker, - GetBasalt - } + return mod end) -- FILE END: updater.lua -- @@ -83,6 +81,7 @@ rawset(__BUNDLER_FILES, "ui.lua", function () local monitor = utils.Cast(peripheral.find("monitor")) --- @type drive local drive = utils.Cast(peripheral.find("drive")) + local mod = {} --- @class Ui --- @field pin string --- @field main any @@ -134,7 +133,7 @@ rawset(__BUNDLER_FILES, "ui.lua", function () ui.pin = ui.pin .. tostring(i) ui.pinLabel:setText(ui.pin) end - function InitUi() + function mod.InitUi() local ui = { resetEverything, unlockDoor, @@ -180,37 +179,32 @@ rawset(__BUNDLER_FILES, "ui.lua", function () os.reboot() end end - return { - InitUi, - } + return mod end) -- FILE END: ui.lua -- rawset(__BUNDLER_FILES, "utils.lua", function () + local utils = {} -- Type coersion for lsp ---@generic T ---@param object any ---@return T - function Cast(object) + function utils.Cast(object) return object end --- @type Monitor local MONITOR = Cast(peripheral.find("monitor")) local MONITOR_Y = 1 - function MonPrint(text) + function utils.MonPrint(text) MONITOR.setCursorPos(1,MONITOR_Y) MONITOR.write(text) MONITOR_Y = MONITOR_Y + 1 end - function MonReset(scale) + function utils.MonReset(scale) MONITOR.clear() MONITOR.setTextScale(scale) end - return { - MonPrint, - MonReset, - Cast, - } + return utils; end) -- FILE END: utils.lua -- @@ -220,17 +214,16 @@ rawset(__BUNDLER_FILES, "main.lua", function () local utils = require("utils.lua") local updater = require("updater.lua") local ui = require("ui.lua") + local main = {} KEYPADOS_VERSION = "3.0" - function Main() + function main.Main() utils.MonPrint(0.5) updater.getBasalt() utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION) utils.MonPrint(1) ui.InitUi() end - return { - Main - } + return main end) -- FILE END: main.lua -- diff --git a/src/main.lua b/src/main.lua index 116e8cd..4cd207e 100644 --- a/src/main.lua +++ b/src/main.lua @@ -4,11 +4,12 @@ local utils = require("utils.lua") local updater = require("updater.lua") local ui = require("ui.lua") +local main = {} KEYPADOS_VERSION = "3.0" -function Main() +function main.Main() utils.MonPrint(0.5) updater.getBasalt() utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION) @@ -17,7 +18,5 @@ function Main() end -return { - Main -} +return main diff --git a/src/ui.lua b/src/ui.lua index 9950f46..e03693c 100644 --- a/src/ui.lua +++ b/src/ui.lua @@ -7,6 +7,8 @@ local monitor = utils.Cast(peripheral.find("monitor")) --- @type drive local drive = utils.Cast(peripheral.find("drive")) +local mod = {} + --- @class Ui --- @field pin string --- @field main any @@ -66,7 +68,7 @@ local function addToPin(ui, i) ui.pinLabel:setText(ui.pin) end -function InitUi() +function mod.InitUi() local ui = { resetEverything, unlockDoor, @@ -120,6 +122,4 @@ function InitUi() end end -return { - InitUi, -} +return mod diff --git a/src/updater.lua b/src/updater.lua index 8221381..3d5357c 100644 --- a/src/updater.lua +++ b/src/updater.lua @@ -2,6 +2,8 @@ local utils = require("utils.lua") local LAST_USED = os.time() +local mod = {} + local function checkForUpdate() local current_time = os.time() local difference = math.abs(current_time - LAST_USED) @@ -28,14 +30,14 @@ local function checkForUpdate() end end -function UpdateChecker() +function mod.UpdateChecker() while true do checkForUpdate() sleep(1) end end -function GetBasalt() +function mod.GetBasalt() if fs.exists("basalt.lua") then utils.MonPrint("Basalt found!") else @@ -58,7 +60,4 @@ function GetBasalt() end end -return { - UpdateChecker, - GetBasalt -} +return mod diff --git a/src/utils.lua b/src/utils.lua index 41479fb..79a8767 100644 --- a/src/utils.lua +++ b/src/utils.lua @@ -1,8 +1,10 @@ +local utils = {} + -- Type coersion for lsp ---@generic T ---@param object any ---@return T -function Cast(object) +function utils.Cast(object) return object end @@ -10,19 +12,15 @@ end --- @type Monitor local MONITOR = Cast(peripheral.find("monitor")) local MONITOR_Y = 1 -function MonPrint(text) +function utils.MonPrint(text) MONITOR.setCursorPos(1,MONITOR_Y) MONITOR.write(text) MONITOR_Y = MONITOR_Y + 1 end -function MonReset(scale) +function utils.MonReset(scale) MONITOR.clear() MONITOR.setTextScale(scale) end -return { - MonPrint, - MonReset, - Cast, -} +return utils;