Upload files to "src"

This commit is contained in:
xomf 2024-08-17 21:29:47 +00:00
parent db0c18c9c5
commit ea616b55cc
5 changed files with 124 additions and 0 deletions

36
src/boot.lua Normal file
View File

@ -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()

1
src/config.lua Normal file
View File

@ -0,0 +1 @@
correctPin = "42169"

8
src/init.lua Normal file
View File

@ -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 = ""

30
src/main.lua Normal file
View File

@ -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()

49
src/unlock_door.lua Normal file
View File

@ -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