From 3c570c9682f7b10ce3a730868a42efd547c57109 Mon Sep 17 00:00:00 2001 From: Moonlit Productions Date: Thu, 1 Jan 2026 22:28:00 -0500 Subject: [PATCH] Add installer/updater --- handlers.lua | 5 +++ install.lua | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++ startup.lua | 2 +- 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 install.lua diff --git a/handlers.lua b/handlers.lua index 762fbf1..f4416a0 100644 --- a/handlers.lua +++ b/handlers.lua @@ -104,6 +104,11 @@ function handlers.handleDisconnectButton(eventType, side, x, y) return nil end + -- Only process if stargate is actually connected + if not gate.isStargateConnected() then + return nil + end + -- Check if clicking disconnect button (bottom-right corner) if y >= 17 and y <= 19 and x >= 20 and x <= 28 then gate.disconnectStargate() diff --git a/install.lua b/install.lua new file mode 100644 index 0000000..d42ec9f --- /dev/null +++ b/install.lua @@ -0,0 +1,107 @@ +--[[ + Stargate Control System - Installer + Downloads and installs all necessary files from the git repository +]] + +local baseUrl = "https://git.munebase.dev/Munelit/StargateControl/raw/branch/master/" + +local files = { + -- Core files (always download) + "startup.lua", + "addresses.lua", + "utils.lua", + "display.lua", + "events.lua", + "handlers.lua", + + -- Config file (only download if doesn't exist) + config = "config.lua" +} + +local function downloadFile(filename, url) + print("Downloading " .. filename .. "...") + + -- Delete existing file first (to ensure clean update) + if fs.exists(filename) then + fs.delete(filename) + end + + local response = http.get(url) + + if response then + local content = response.readAll() + response.close() + + local file = fs.open(filename, "w") + if file then + file.write(content) + file.close() + print(" [OK] " .. filename) + return true + else + print(" [FAIL] Could not write " .. filename) + return false + end + else + print(" [FAIL] Could not download " .. filename) + return false + end +end + +print("========================================") +print(" Stargate Control System Installer") +print("========================================") +print("") + +-- Check if HTTP is enabled +if not http then + print("ERROR: HTTP is not enabled!") + print("Please enable it in the ComputerCraft config.") + return +end + +local success = 0 +local failed = 0 + +-- Download core files +for _, filename in ipairs(files) do + local url = baseUrl .. filename + if downloadFile(filename, url) then + success = success + 1 + else + failed = failed + 1 + end +end + +-- Download config file only if it doesn't exist +if fs.exists("config.lua") then + print("Config file already exists - skipping") + print(" [SKIP] config.lua") +else + local url = baseUrl .. "config.lua" + if downloadFile("config.lua", url) then + success = success + 1 + else + failed = failed + 1 + end +end + +print("") +print("========================================") +print("Installation complete!") +print(" Success: " .. success) +print(" Failed: " .. failed) +print("========================================") +print("") + +if failed > 0 then + print("WARNING: Some files failed to download.") + print("Please check your internet connection and try again.") +else + print("All files downloaded successfully!") + print("") + print("To start the program, run: startup") + print("") + print("Note: You may need to configure config.lua") + print("with your specific settings before running.") +end diff --git a/startup.lua b/startup.lua index 6c5a825..7cd5a55 100644 --- a/startup.lua +++ b/startup.lua @@ -516,7 +516,7 @@ local function selectGateFromList() break end end - + -- Check back button (x: 23-28, y: 17-19) if not dialing and sely >= 17 and sely <= 19 and selx >= 23 and selx <= 28 then selecting = false