From ea616b55cc9274914a90234de0b54b0640cb7584 Mon Sep 17 00:00:00 2001 From: xomf Date: Sat, 17 Aug 2024 21:29:47 +0000 Subject: [PATCH] Upload files to "src" --- src/boot.lua | 36 +++++++++++++++++++++++++++++++++ src/config.lua | 1 + src/init.lua | 8 ++++++++ src/main.lua | 30 +++++++++++++++++++++++++++ src/unlock_door.lua | 49 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 124 insertions(+) create mode 100644 src/boot.lua create mode 100644 src/config.lua create mode 100644 src/init.lua create mode 100644 src/main.lua create mode 100644 src/unlock_door.lua diff --git a/src/boot.lua b/src/boot.lua new file mode 100644 index 0000000..71c4997 --- /dev/null +++ b/src/boot.lua @@ -0,0 +1,36 @@ +-- keycardOS "bootloader", has no access to basalt +-- intended for checking for updates, and automatically updating basalt if it is missing + + +local function boot() + KEYPADOS_VERSION = "3.0" + + monitor = peripheral.find("monitor") + monitor.clear() + monitor.setTextScale(0.5) + y = 1 + + function mPrint(text) + monitor.setCursorPos(1,y) + monitor.write(text) + y = y + 1 + end + + mPrint("keypadOS v" .. KEYPADOS_VERSION) + + if fs.exists("basalt.lua") then + mPrint("Basalt found!") + else + mPrint("Download basalt...") + basalt_code = http.get("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/versions/latest.lua").readAll() + mPrint("Install basalt...") + local file = fs.open("basalt.lua", "w") + file.write(basalt_code) + file.close() + mPrint("Rebooting...") + os.reboot() + end + +end + +boot() diff --git a/src/config.lua b/src/config.lua new file mode 100644 index 0000000..78fd0cc --- /dev/null +++ b/src/config.lua @@ -0,0 +1 @@ +correctPin = "42169" \ No newline at end of file diff --git a/src/init.lua b/src/init.lua new file mode 100644 index 0000000..78023a2 --- /dev/null +++ b/src/init.lua @@ -0,0 +1,8 @@ +local basalt = require("basalt") +local monitor = peripheral.find("monitor") +local drive = peripheral.find("drive") +local main = basalt.addMonitor() +main:setMonitor(monitor) +btnX = 1 +btnY = 3 +pin = "" \ No newline at end of file diff --git a/src/main.lua b/src/main.lua new file mode 100644 index 0000000..5cad487 --- /dev/null +++ b/src/main.lua @@ -0,0 +1,30 @@ +pinLabel = main:addLabel() + :setText("") + :setFontSize(1) + +enterButton = main:addButton() + :setText(">>>>") + :setBackground(colors.blue) + :setPosition(6,3) + :setSize(1.5,3.2) + :onClick(unlockDoor) + +for i = 1, 9 do + local button = main:addButton() + :setPosition(btnX,btnY) + :setText(tostring(i)) + :setSize(2,1) + :onClick( + function() + addToPin(i) + end) + btnX = btnX + 2 + + if btnX >= 6 then + btnY = btnY + 1 + btnX = 1 + end + +end + +basalt.autoUpdate() diff --git a/src/unlock_door.lua b/src/unlock_door.lua new file mode 100644 index 0000000..acb6839 --- /dev/null +++ b/src/unlock_door.lua @@ -0,0 +1,49 @@ +function unlockDoor() + + if drive.isDiskPresent() then + if drive.getDiskLabel() == correctPin then + pin = correctPin + drive:ejectDisk() + end + end + + basalt.debug("test") + if pin == correctPin then + enterButton:setBackground(colors.green) + pinLabel:setText("Welcome") + redstone.setOutput("front", true) + + if drive.isDiskPresent() then + if drive.getDiskLabel() == nil then + drive.setDiskLabel(correctPin) + pinLabel:setText("Crd set") + drive:ejectDisk() + end + end + + else + pinLabel:setText("Wrong") + enterButton:setBackground(colors.red) + end + local thread = main:addThread() + :start(resetEverything) + +end + +function resetEverything() + sleep(2) + pin = "" + pinLabel:setText("") + redstone.setOutput("front", false) + enterButton:setBackground(colors.blue) +end + +function addToPin(i) + + if #pin >= 5 then + return + end + + pin = pin .. tostring(i) + pinLabel:setText(pin) +end \ No newline at end of file