From 6f61e9549b57c14c984b78085283d26940c8337a Mon Sep 17 00:00:00 2001 From: MCorange Date: Sun, 18 Aug 2024 02:08:11 +0300 Subject: [PATCH] UWU --- build.sh | 31 --------- keypadOS.lua | 182 +++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 8 +++ src/boot.lua | 34 +++------ src/utils.lua | 11 +++ x.py | 31 +++++++++ 6 files changed, 243 insertions(+), 54 deletions(-) delete mode 100644 build.sh create mode 100644 keypadOS.lua create mode 100644 pyproject.toml create mode 100644 src/utils.lua create mode 100755 x.py diff --git a/build.sh b/build.sh deleted file mode 100644 index 8b23394..0000000 --- a/build.sh +++ /dev/null @@ -1,31 +0,0 @@ -SRC_DIR="./src" -BUILD_DIR="./build" -OUTPUT_FILE="$BUILD_DIR/startup.lua" -BOOT_FILE="$SRC_DIR/boot.lua" -MAIN_FILE="$SRC_DIR/main.lua" - -mkdir -p "$BUILD_DIR" - -> "$OUTPUT_FILE" - - -if [ -e "$BOOT_FILE" ]; then - echo "-- File: boot.lua" >> "$OUTPUT_FILE" - cat "$BOOT_FILE" >> "$OUTPUT_FILE" - echo >> "$OUTPUT_FILE" -fi - -for file in "$SRC_DIR"/*.lua; do - if [ -e "$file" ] && [ "$(basename "$file")" != "boot.lua" ] && [ "$(basename "$file")" != "main.lua" ]; then - filename=$(basename "$file") - echo "-- File: $filename" >> "$OUTPUT_FILE" - cat "$file" >> "$OUTPUT_FILE" - echo >> "$OUTPUT_FILE" - fi -done - -if [ -e "$MAIN_FILE" ]; then - echo "-- File: main.lua" >> "$OUTPUT_FILE" - cat "$MAIN_FILE" >> "$OUTPUT_FILE" - echo >> "$OUTPUT_FILE" -fi diff --git a/keypadOS.lua b/keypadOS.lua new file mode 100644 index 0000000..dc14c8d --- /dev/null +++ b/keypadOS.lua @@ -0,0 +1,182 @@ + +-- FILE: src/boot.lua + +-- keycardOS "bootloader", has no access to basalt +-- intended for checking for updates, and automatically updating basalt if it is missing + +LAST_USED = os.time() + +local function checkForUpdate() + current_time = os.time() + 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 > 4 then + if difference > .5 then + --logic for updating + end + +end + +function updateChecker() + while true do + checkForUpdate() + sleep(1) + end +end + +local function getBasalt() + 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 + +KEYPADOS_VERSION = "3.0" +MONITOR = peripheral.find("monitor") + +local function boot() + mon_reset(0.5); + mPrint("keypadOS v" .. KEYPADOS_VERSION) + mon_reset(1); +end + +boot() + +local files = {} +local globalRequire = require -- Store default require reference +local require = function(path) -- Will return saved file or attempt default lua require + return files[path] or globalRequire(path) +end + +files["boot.lua"] = function(...) + local function boot() + mon_reset(0.5); + mPrint("keypadOS v" .. KEYPADOS_VERSION) + mon_reset(1); + end + + return { + boot + } +end + +-- FILE: src/init.lua + +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 = "" +-- FILE: src/config.lua + +correctPin = "42169" +-- FILE: src/unlock_door.lua + +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 +-- FILE: src/utils.lua + +MONITOR_Y = 1 +function mPrint(text) + MONITOR.setCursorPos(1,y) + MONITOR.write(text) + MONITOR_Y = MONITOR_Y + 1 +end + +function mon_reset(scale) + MONITOR.clear() + MONITOR.setTextScale(scale) +end + +-- FILE: src/main.lua + +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 + +parallel.waitForAll(basalt.autoUpdate, updateChecker) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5aa33de --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,8 @@ +[tool.pylint.'MESSAGES CONTROL'] +disable = [ + "unnecessary-semicolon", + "trailing-newlines", + "missing-docstring" +] + + diff --git a/src/boot.lua b/src/boot.lua index 31be6ae..da7a9ca 100644 --- a/src/boot.lua +++ b/src/boot.lua @@ -7,40 +7,23 @@ local function checkForUpdate() current_time = os.time() 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) + --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 > 4 then if difference > .5 then - --logic for updating - end end function updateChecker() - while true do checkForUpdate() sleep(1) end - end -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) - +local function getBasalt() if fs.exists("basalt.lua") then mPrint("Basalt found!") else @@ -53,10 +36,15 @@ local function boot() mPrint("Rebooting...") os.reboot() end +end - monitor.setTextScale(1) - monitor.clear() +KEYPADOS_VERSION = "3.0" +MONITOR = peripheral.find("monitor") +local function boot() + mon_reset(0.5); + mPrint("keypadOS v" .. KEYPADOS_VERSION) + mon_reset(1); end boot() diff --git a/src/utils.lua b/src/utils.lua new file mode 100644 index 0000000..f622f1e --- /dev/null +++ b/src/utils.lua @@ -0,0 +1,11 @@ +MONITOR_Y = 1 +function mPrint(text) + MONITOR.setCursorPos(1,y) + MONITOR.write(text) + MONITOR_Y = MONITOR_Y + 1 +end + +function mon_reset(scale) + MONITOR.clear() + MONITOR.setTextScale(scale) +end diff --git a/x.py b/x.py new file mode 100755 index 0000000..b2baa9e --- /dev/null +++ b/x.py @@ -0,0 +1,31 @@ +#!/usr/bin/python + +OUTPUT="keypadOS.lua"; +FILES= [ + "src/boot.lua", + "src/init.lua", + "src/config.lua", + "src/unlock_door.lua", + "src/utils.lua", + "src/main.lua", +] + +def read_file(p: str) -> str: + buf = ""; + with open(p, "r", encoding="utf-8") as f: + buf = f"\n-- FILE: {p}\n\n" + f.read(); + return buf; + + +def main(): + buf = ""; + for file in FILES: + print(f"=== FILE: {file}"); + buf += read_file(file); + with open(OUTPUT, "w", encoding="utf-8") as f: + f.write(buf); + print("DONE"); + +if __name__ == "__main__": + main(); +