diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..bff2d76 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1 @@ +*.iml diff --git a/README.md b/README.md index 2045a47..53e9229 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,45 @@ -# Reactor-and-Turbine-control-program -This is my Reactor- and Turbine control program for ComputerCraft and BigReactors +# Reactor and Turbine control program +***Description:*** + +This is my Reactor- and Turbine control program for ComputerCraft and BigReactors. +The following list shows the features of the program: +- Control up to 32 Turbines (per Reactor) +- Supports multiple languages (currently English and German) +- Automatic and manual Control of Reactor and attached Turbines +- Energy-based automatic Control + - Switches Reactor and Turbines on/off if energy level is low/high + - Supports multiple Energy Storage typesm like Capacitorbanks (EnderIO), Energy Core (Draconic Evolution), etc. +- Large option menu + - Change Background and Text Color + - Set energy level for activating/deactivating the reactor + - Set Reactor Steam Output Level + +## How To Install +- Set up a Computer, connect all parts (Reactor, Energy Storage, Turbines) with ***Wired Modems*** +- ***Activate*** all modems +- Type in the following into the computer: + + ``` + pastebin get HMtbgkwt git + git + ``` + +- Then follow the install instructions + +## Have a look at my Update Videos on YouTube +- Current version (2.4): + - https://www.youtube.com/watch?v=UnPru3xhrjo (English) + - https://www.youtube.com/watch?v=XNlsU0tSHOc&t=1s (German) + + +## Do you want to help me developing the program? +- Use my beta versions! +- Report bugs and send me suggestions for new features + +## + + +### *Have fun! Thanks for using my program!* + + + diff --git a/turbineControl_v2/src/beta.ver b/turbineControl_v2/src/beta.ver new file mode 100644 index 0000000..b7031eb --- /dev/null +++ b/turbineControl_v2/src/beta.ver @@ -0,0 +1 @@ +2.5-beta \ No newline at end of file diff --git a/turbineControl_v2/src/changelog/changelogDE.txt b/turbineControl_v2/src/changelog/changelogDE.txt index 2b8f78a..7073608 100644 --- a/turbineControl_v2/src/changelog/changelogDE.txt +++ b/turbineControl_v2/src/changelog/changelogDE.txt @@ -1,7 +1,22 @@ **************************************************************** -- Reaktor- und Turbinenprogramm von Thor_s_Crafter -- -- Komplettes Changelog -- --- Aktuelle Version: 2.4 -- +-- Aktuelle Version: 2.5 -- +**************************************************************** +Version 2.5 +- Automatische Updates implementiert +- Git Downloader & Installer Updates +- Readme in Github aktualisiert +- Optionen Reworks +- Energiespeicher werden nun anhand der Methode + getEnergyStored() erkannt +- Bugfixes: + > Anzeigebugs + > Event Handling Fixes + > Buttons + > Hauptmenue Bugs + > Start Bugs + > Eine Menge Code-Cleanups **************************************************************** Version 2.4 - Github Downloader hinzugefuegt (ersetzt installerUpdate) diff --git a/turbineControl_v2/src/changelog/changelogEn.txt b/turbineControl_v2/src/changelog/changelogEn.txt index f583604..873ba48 100644 --- a/turbineControl_v2/src/changelog/changelogEn.txt +++ b/turbineControl_v2/src/changelog/changelogEn.txt @@ -1,7 +1,22 @@ **************************************************************** -- Reactor- und Turbine control by Thor_s_Crafter -- -- Complete Changelog -- --- Current Version: 2.4 -- +-- Current Version: 2.5 -- +**************************************************************** +Version 2.5 +- Reimplemented automatic updates +- Git Downloader & Installer Updates +- Updated Readme in Github +- Option Reworks +- Energy Storage is now being detected by the function + getEnergyStored() +- Bugfixes: + > Visual Bugfixes + > Event Handling Fixes + > Buttons + > Hauptmenu Bugs + > Start Bugs + > Lots of Code-Cleanups **************************************************************** Version 2.4 - Added Github Downloader (replaces installerUpdate) diff --git a/turbineControl_v2/src/config/options.txt b/turbineControl_v2/src/config/options.txt index 15e9147..172fb6c 100644 --- a/turbineControl_v2/src/config/options.txt +++ b/turbineControl_v2/src/config/options.txt @@ -1,27 +1,15 @@ - -version -2.4 -rodLevel -0 -backgroundColor -128 -textColor -1 -reactorOffAt -90 -reactorOnAt -50 -mainMenu -true -autoUpdate -false -lang -de -mode -auto -program -turbine -turbineTargetSpeed -1820 -turbineTargetSteam -2000 \ No newline at end of file +{ + mainMenu = true, + rodLevel = 0, + targetSpeed = 2000, + overallMode = "auto", + reactorOffAt = 80, + backgroundColor = 128, + reactorOnAt = 50, + targetSteam = 2000, + turbineTargetSpeed = 1820, + version = "2.5-beta04", + textColor = 1, + program = "turbine", + lang = "de", +} diff --git a/turbineControl_v2/src/config/touchpoint.lua b/turbineControl_v2/src/config/touchpoint.lua index 403d0a6..c272549 100644 --- a/turbineControl_v2/src/config/touchpoint.lua +++ b/turbineControl_v2/src/config/touchpoint.lua @@ -1,25 +1,15 @@ -- Reaktor- and Turbinen control by Thor_s_Crafter -- --- Version 2.4 -- +-- Version 2.5 -- -- Touchpoint API by Lyqyd - Slightly changed -- -local backgroundColor -local textColor +local file = fs.open("/reactor-turbine-program/config/options.txt","r") +local list = file.readAll() +file.close() -function loadOptions() - local optionList = {} - local file = fs.open("/reactor-turbine-program/config/options.txt","r") - local listElement = file.readLine() - while listElement do - table.insert(optionList,listElement) - listElement = file.readLine() - end - file.close() - - backgroundColor = tonumber(optionList[7]) - textColor = tonumber(optionList[9]) -end - -loadOptions() +--Insert Elements and assign values +optionList = textutils.unserialise(list) +backgroundColor = tonumber(optionList["backgroundColor"]) +textColor = tonumber(optionList["textColor"]) local function setupLabel(buttonLen, minY, maxY, name) local labelTable = {} @@ -50,8 +40,8 @@ end local Button = { draw = function(self) local old = term.redirect(self.mon) - term.setTextColor(textColor) - term.setBackgroundColor(backgroundColor) + term.setTextColor(tonumber(textColor)) + term.setBackgroundColor(tonumber(backgroundColor)) term.clear() for name, buttonData in pairs(self.buttonList) do if buttonData.active then diff --git a/turbineControl_v2/src/install/github_downloader.lua b/turbineControl_v2/src/install/github_downloader.lua index 1ee7bae..161b6e4 100644 --- a/turbineControl_v2/src/install/github_downloader.lua +++ b/turbineControl_v2/src/install/github_downloader.lua @@ -1,8 +1,11 @@ -- Reactor- und Turbine control by Thor_s_Crafter -- --- Betaversion downloader (GitHub) -- +-- Init Program Downloader (GitHub) -- + + +--===== Local variables ===== --Release or beta version? -local selectInstaller = "release" +local selectInstaller = "" --Branch & Relative paths to the url and path local installLang = "" @@ -35,26 +38,31 @@ function selectBranch() if installLang == "de" then print("Welche Version soll geladen werden?") print("Verfuegbar:") - print("1) master (Realeases)") - print("2) build-2.4.2 (Betatestversion)") + print("1) master (Releases)") + print("2) beta (Betaversionen)") term.write("Eingabe (1-2): ") elseif installLang == "en" then print("Which version should be downloaded?") print("Available:") print("1) master (Realeases)") - print("2) build-2.4.2 (Betaversion)") + print("2) beta (Betaversions)") term.write("Input (1-2): ") end local input = read() - if input == "1" then branch = "master" - elseif input == "2" then branch = "build-2.4.2" + if input == "1" then + branch = "master" + relUrl = "https://raw.githubusercontent.com/ThorsCrafter/Reactor-and-Turbine-control-program/"..branch.."/turbineControl_v2/src/" + releaseVersion() + elseif input == "2" then + branch = "beta" + relUrl = "https://raw.githubusercontent.com/ThorsCrafter/Reactor-and-Turbine-control-program/"..branch.."/turbineControl_v2/src/" + betaVersion() else if installLang == "de" then print("Ungueltige Eingabe!") elseif installLang == "en" then print("Invalid input!") end sleep(2) selectBranch() end - relUrl = "https://raw.githubusercontent.com/ThorsCrafter/Reactor-and-Turbine-control-program/"..branch.."/turbineControl_v2/src/" end --Removes old installations @@ -80,7 +88,7 @@ function getURL(path) local gotUrl = http.get(relUrl..path) if gotUrl == nil then clearTerm() - error("File not found! Please check, if the branch is correct!") + error("File not found! Please check!\nFailed at "..relUrl..path) else return gotUrl.readAll() end @@ -125,9 +133,6 @@ function clearTerm() end function releaseVersion() - --Set branch (relUrl) to "master" - relUrl = "https://raw.githubusercontent.com/ThorsCrafter/Reactor-and-Turbine-control-program/master/turbineControl_v2/src/" - removeAll() --Downloads the installer if installLang == "de" then @@ -139,7 +144,6 @@ function releaseVersion() end function betaVersion() - selectBranch() removeAll() getFiles() print("Done!") @@ -149,12 +153,5 @@ end --Run selectLanguage() -if selectInstaller == "beta" then - betaVersion() -elseif selectInstaller == "release" then - releaseVersion() -else - error("Enter a release version! (\"beta\"/\"release\") in line 5!") -end - +selectBranch() os.reboot() \ No newline at end of file diff --git a/turbineControl_v2/src/install/installer.lua b/turbineControl_v2/src/install/installer.lua index 501082a..6e32234 100644 --- a/turbineControl_v2/src/install/installer.lua +++ b/turbineControl_v2/src/install/installer.lua @@ -1,11 +1,48 @@ -- Reactor- und Turbine control by Thor_s_Crafter -- --- Version 2.4 -- +-- Version 2.5 -- -- Installer (Deutsch) -- ---Variables -local relUrl = "https://raw.githubusercontent.com/ThorsCrafter/Reactor-and-Turbine-control-program/master/turbineControl_v2/src/" ---Functions +--===== Local Variables ===== + +local arg = {... } +local update +local branch = "" + +--Program arguments for updates +if #arg == 0 then + + --No update + update = false + +elseif #arg == 2 then + + if arg[1] == "update" then + + --Update! + update = true + + --Select update branch + if arg[2] == "release" then branch = "release" + elseif arg[2] == "beta" then branch = "beta" + else + error("Invalid 2nd argument!") + end + + else + error("Invalid 1st argument!") + end + +else + error("0 or 2 arguments required!") +end + +--Url for file downloads +local relUrl = "https://raw.githubusercontent.com/ThorsCrafter/Reactor-and-Turbine-control-program/"..branch.."/turbineControl_v2/src/" + + +--===== Functions ===== + --Writes the files to the computer function writeFile(url,path) local file = fs.open("/reactor-turbine-program/"..path,"w") @@ -18,17 +55,14 @@ function getURL(path) local gotUrl = http.get(relUrl..path) if gotUrl == nil then clearTerm() - error("File not found! Please check, if the branch is correct!") + error("File not found! Please check!\nFailed at "..relUrl..path) else return gotUrl.readAll() end end ---Update? -if fs.exists("/reactor-turbine-program/program/turbineControl.lua") then - update = true -else update = false -end + +--===== Run installation ===== --First time installation if not update then @@ -105,10 +139,13 @@ if not update then sleep(1) end --update + + term.clear() term.setCursorPos(1,1) print("Checke und loesche vorhandene Programme...") + --Removes old files if fs.exists("/reactor-turbine-program/program/") then shell.run("rm /reactor-turbine-program/") @@ -117,27 +154,32 @@ end --Download all program parts print("Lade neue Programmteile...") print("Getting new files...") + --Changelog term.write("Downloading Changelog files...") writeFile(getURL("changelog/changelogDE.txt"),"changelog/changelogDE.txt") writeFile(getURL("changelog/changelogEn.txt"),"changelog/changelogDE.txt") print(" Done.") + --Config term.write("Config files...") writeFile(getURL("config/input.lua"),"config/input.lua") writeFile(getURL("config/options.txt"),"config/options.txt") writeFile(getURL("config/touchpoint.lua"),"config/touchpoint.lua") print(" Done.") + --Install term.write("Install files...") writeFile(getURL("install/installer.lua"),"install/installer.lua") print(" Done.") + --Program term.write("Program files...") writeFile(getURL("program/editOptions.lua"),"program/editOptions.lua") writeFile(getURL("program/reactorControl.lua"),"program/reactorControl.lua") writeFile(getURL("program/turbineControl.lua"),"program/turbineControl.lua") print(" Done.") + --Start term.write("Start files...") writeFile(getURL("start/menu.lua"),"start/menu.lua") diff --git a/turbineControl_v2/src/install/installerEn.lua b/turbineControl_v2/src/install/installerEn.lua index 3753da2..f285da5 100644 --- a/turbineControl_v2/src/install/installerEn.lua +++ b/turbineControl_v2/src/install/installerEn.lua @@ -1,5 +1,5 @@ -- Reactor- und Turbine control by Thor_s_Crafter -- --- Version 2.4 -- +-- Version 2.5 -- -- Installer (English) -- --Variables diff --git a/turbineControl_v2/src/program/editOptions.lua b/turbineControl_v2/src/program/editOptions.lua index d8aeffa..14f4566 100644 --- a/turbineControl_v2/src/program/editOptions.lua +++ b/turbineControl_v2/src/program/editOptions.lua @@ -1,5 +1,5 @@ -- Reactor- und Turbine control by Thor_s_Crafter -- --- Version 2.4 -- +-- Version 2.5 -- -- Options menu -- --Loads the touchpoint and input APIs @@ -22,7 +22,7 @@ local touch2 = touchpoint.new(touchpointLocation) local touch3 = touchpoint.new(touchpointLocation) local touch4 = touchpoint.new(touchpointLocation) local currPage = touchpoint.new(touchpointLocation) -local currFunct = mainMenu +local currFunct = backToMainMenu --Save the changes and reopen the options menu function saveConfigFile() @@ -84,7 +84,7 @@ function createAllButtons() touch2:add("Gruen",function() setColor(8192) end,50,17,63,17) touch2:add("Rot",function() setColor(16384) end,35,19,48,19) touch2:add("Schwarz",function() setColor(32768) end,50,19,63,19) - touch2:add("Zurueck",mainMenu,3,8,19,8) + touch2:add("Zurueck",backToMainMenu,3,8,19,8) --+/- buttons (1-100) touch3:add("-1",function() setOnOffAt("-",1) end,3,8,6,8) @@ -93,7 +93,7 @@ function createAllButtons() touch3:add("+1", function() setOnOffAt("+",1) end,3,10,6,10) touch3:add("+10",function() setOnOffAt("+",10) end,8,10,12,10) touch3:add("+100",function() setOnOffAt("+",100) end,14,10,19,10) - touch3:add("Zurueck",mainMenu,3,13,19,13) + touch3:add("Zurueck",backToMainMenu,3,13,19,13) --+/- buttons (1-1000) touch4:add("-1",function() setOnOffAt("-",1) end,3,8,6,8) @@ -104,7 +104,7 @@ function createAllButtons() touch4:add("+10",function() setOnOffAt("+",10) end,8,10,12,10) touch4:add("+100",function() setOnOffAt("+",100) end,14,10,19,10) touch4:add("+1000",function() setOnOffAt("+",1000) end,21,10,28,10) - touch4:add("Zurueck",mainMenu,3,13,19,13) + touch4:add("Zurueck",backToMainMenu,3,13,19,13) --English buttons elseif lang == "en" then @@ -137,7 +137,7 @@ function createAllButtons() touch2:add("Green",function() setColor(8192) end,50,17,63,17) touch2:add("Red",function() setColor(16384) end,35,19,48,19) touch2:add("Black",function() setColor(32768) end,50,19,63,19) - touch2:add("Back",mainMenu,3,8,19,8) + touch2:add("Back",backToMainMenu,3,8,19,8) --+/- buttons (1-100) touch3:add("-1",function() setOnOffAt("-",1) end,3,8,6,8) @@ -146,7 +146,7 @@ function createAllButtons() touch3:add("+1", function() setOnOffAt("+",1) end,3,10,6,10) touch3:add("+10",function() setOnOffAt("+",10) end,8,10,12,10) touch3:add("+100",function() setOnOffAt("+",100) end,14,10,19,10) - touch3:add("Back",mainMenu,3,13,19,13) + touch3:add("Back",backToMainMenu,3,13,19,13) --+/- buttons (1-1000) touch4:add("-1",function() setOnOffAt("-",1) end,3,8,6,8) @@ -157,18 +157,18 @@ function createAllButtons() touch4:add("+10",function() setOnOffAt("+",10) end,8,10,12,10) touch4:add("+100",function() setOnOffAt("+",100) end,14,10,19,10) touch4:add("+1000",function() setOnOffAt("+",1000) end,21,10,28,10) - touch4:add("Back",mainMenu,3,13,19,13) + touch4:add("Back",backToMainMenu,3,13,19,13) end end --Display the overwiew -function mainMenu() +function backToMainMenu() mon.clear() currPage=touch1 currPage:draw() mon.setCursorPos(2,2) - mon.setTextColor(tonumber(optionList[9])) - mon.setBackgroundColor(tonumber(optionList[7])) + mon.setTextColor(tonumber(optionList["textColor"])) + mon.setBackgroundColor(tonumber(optionList["backgroundColor"])) mon.setCursorPos(4,2) if lang == "de" then @@ -179,9 +179,9 @@ function mainMenu() --Set text of all the options mon.setCursorPos(24,4) - local col = printColor(tonumber(optionList[7])) + local col = printColor(tonumber(optionList["backgroundColor"])) local col2 = printColor(backgroundColor) - if tonumber(optionList[7]) ~= backgroundColor then + if tonumber(optionList["backgroundColor"]) ~= backgroundColor then if lang == "de" then mon.write("Hintergrundfarbe: "..col.." -> "..col2.." ") elseif lang == "en" then @@ -196,9 +196,9 @@ function mainMenu() end mon.setCursorPos(24,6) - local col3 = printColor(tonumber(optionList[9])) + local col3 = printColor(tonumber(optionList["textColor"])) local col4 = printColor(textColor) - if tonumber(optionList[9]) ~= textColor then + if tonumber(optionList["textColor"]) ~= textColor then if lang == "de" then mon.write("Textfarbe: "..col3.." -> "..col4.." ") elseif lang == "en" then @@ -213,11 +213,11 @@ function mainMenu() end mon.setCursorPos(24,8) - if math.floor(tonumber(optionList[11])) ~= math.floor(reactorOffAt) then + if math.floor(tonumber(optionList["reactorOffAt"])) ~= math.floor(reactorOffAt) then if lang == "de" then - mon.write("Reaktor aus bei ueber "..math.floor(tonumber(optionList[11])).."% -> "..math.floor(reactorOffAt).."% ") + mon.write("Reaktor aus bei ueber "..math.floor(tonumber(optionList["reactorOffAt"])).."% -> "..math.floor(reactorOffAt).."% ") elseif lang == "en" then - mon.write("Reactor off above "..math.floor(tonumber(optionList[11])).."% -> "..math.floor(reactorOffAt).."% ") + mon.write("Reactor off above "..math.floor(tonumber(optionList["reactorOffAt"])).."% -> "..math.floor(reactorOffAt).."% ") end else if lang == "de" then @@ -228,11 +228,11 @@ function mainMenu() end mon.setCursorPos(24,10) - if math.floor(tonumber(optionList[13])) ~= math.floor(reactorOnAt) then + if math.floor(tonumber(optionList["reactorOnAt"])) ~= math.floor(reactorOnAt) then if lang == "de" then - mon.write("Reaktor an bei unter "..math.floor(tonumber(optionList[13])).."% -> "..math.floor(reactorOnAt).."% ") + mon.write("Reaktor an bei unter "..math.floor(tonumber(optionList["reactorOnAt"])).."% -> "..math.floor(reactorOnAt).."% ") elseif lang == "en" then - mon.write("Reactor on below "..math.floor(tonumber(optionList[13])).."% -> "..math.floor(reactorOnAt).."% ") + mon.write("Reactor on below "..math.floor(tonumber(optionList["reactorOnAt"])).."% -> "..math.floor(reactorOnAt).."% ") end else @@ -244,11 +244,11 @@ function mainMenu() end mon.setCursorPos(24,12) - if tonumber(optionList[25]) ~= turbineTargetSpeed then + if tonumber(optionList["turbineTargetSpeed"]) ~= turbineTargetSpeed then if lang == "de" then - mon.write("Turbinen Max. Speed: "..(input.formatNumber(math.floor(tonumber(optionList[25])))).." -> "..(input.formatNumber(turbineTargetSpeed)).."RPM ") + mon.write("Turbinen Max. Speed: "..(input.formatNumber(math.floor(tonumber(optionList["turbineTargetSpeed"])))).." -> "..(input.formatNumber(turbineTargetSpeed)).."RPM ") elseif lang == "en" then - mon.write("Turbines Max. Speed: "..(input.formatNumberComma(math.floor(tonumber(optionList[25])))).." -> "..(input.formatNumberComma(turbineTargetSpeed)).."RPM ") + mon.write("Turbines Max. Speed: "..(input.formatNumberComma(math.floor(tonumber(optionList["turbineTargetSpeed"])))).." -> "..(input.formatNumberComma(turbineTargetSpeed)).."RPM ") end else @@ -260,11 +260,11 @@ function mainMenu() end mon.setCursorPos(24,14) - if tonumber(optionList[27]) ~= targetSteam then + if tonumber(optionList["targetSteam"]) ~= targetSteam then if lang == "de" then - mon.write("Turbinen Steam-Input: "..(input.formatNumber(math.floor(tonumber(optionList[27])))).." -> "..(input.formatNumber(targetSteam)).."mb/t ") + mon.write("Turbinen Steam-Input: "..(input.formatNumber(math.floor(tonumber(optionList["targetSteam"])))).." -> "..(input.formatNumber(targetSteam)).."mb/t ") elseif lang == "en" then - mon.write("Turbines Steam Input: "..(input.formatNumberComma(math.floor(tonumber(optionList[27])))).." -> "..(input.formatNumberComma(targetSteam)).."mb/t ") + mon.write("Turbines Steam Input: "..(input.formatNumberComma(math.floor(tonumber(optionList["targetSteam"])))).." -> "..(input.formatNumberComma(targetSteam)).."mb/t ") end else @@ -281,7 +281,7 @@ function mainMenu() elseif lang == "en" then mon.write("Config available: ") end - if math.floor(tonumber(optionList[5])) ~= math.floor(rodLevel) then + if math.floor(tonumber(optionList["rodLevel"])) ~= math.floor(rodLevel) then if lang == "de" then mon.write("ja -> nein") elseif lang == "en" then @@ -302,7 +302,7 @@ function mainMenu() end end end - getClick(mainMenu) + getClick(backToMainMenu) end --Function for setting the background color @@ -535,7 +535,7 @@ end function resetConfig() rodLevel = 0 targetSteam = 2000 - mainMenu() + backToMainMenu() end --Check for click events @@ -553,4 +553,4 @@ end --Run mon.clear() createAllButtons() -mainMenu() \ No newline at end of file +backToMainMenu() \ No newline at end of file diff --git a/turbineControl_v2/src/program/reactorControl.lua b/turbineControl_v2/src/program/reactorControl.lua index 999e03e..cf726f9 100644 --- a/turbineControl_v2/src/program/reactorControl.lua +++ b/turbineControl_v2/src/program/reactorControl.lua @@ -1,5 +1,5 @@ -- Reactor- und Turbine control by Thor_s_Crafter -- --- Version 2.4 -- +-- Version 2.5 -- -- Reactor control -- --Loads the touchpoint and input APIs diff --git a/turbineControl_v2/src/program/turbineControl.lua b/turbineControl_v2/src/program/turbineControl.lua index 28c1321..66e78bd 100644 --- a/turbineControl_v2/src/program/turbineControl.lua +++ b/turbineControl_v2/src/program/turbineControl.lua @@ -1,5 +1,5 @@ -- Reactor- und Turbine control by Thor_s_Crafter -- --- Version 2.4 -- +-- Version 2.5 -- -- Turbine control -- --Loads the touchpoint API @@ -91,7 +91,7 @@ function startAutoMode() --Init SpeedTables initSpeedTable() while not allAtTargetSpeed() do - getToTargetSpeed() + getToTargetSpeed() sleep(1) term.setCursorPos(1, 2) for i = 0, amountTurbines, 1 do @@ -104,16 +104,24 @@ function startAutoMode() mon.setCursorPos(1, (i + 3)) if i >= 16 then mon.setCursorPos(28, (i - 16 + 3)) end if lang == "de" then - mon.write("Turbine " .. (i + 1) .. ": " .. (input.formatNumber(math.floor(tSpeed))) .. " RPM") + if (i + 1) < 10 then + mon.write("Turbine 0" .. (i + 1) .. ": " .. (input.formatNumber(math.floor(tSpeed))) .. " RPM") + else + mon.write("Turbine " .. (i + 1) .. ": " .. (input.formatNumber(math.floor(tSpeed))) .. " RPM") + end elseif lang == "en" then - mon.write("Turbine " .. (i + 1) .. ": " .. (input.formatNumberComma(math.floor(tSpeed))) .. " RPM") + if (i + 1) < 10 then + mon.write("Turbine 0" .. (i + 1) .. ": " .. (input.formatNumberComma(math.floor(tSpeed))) .. " RPM") + else + mon.write("Turbine " .. (i + 1) .. ": " .. (input.formatNumberComma(math.floor(tSpeed))) .. " RPM") + end end if tSpeed > turbineTargetSpeed then mon.setTextColor(colors.green) - mon.write(" OK ") + mon.write(" OK ") else mon.setTextColor(colors.red) - mon.write(" ...") + mon.write(" ... ") end end end @@ -139,9 +147,7 @@ function startAutoMode() printStatsAuto(0) --run - while true do - clickEvent() - end + clickEvent() end --Init manual mode @@ -162,9 +168,7 @@ function startManualMode() printStatsMan(0) --run - while true do - clickEvent() - end + clickEvent() end --Checks if all required peripherals are attached @@ -541,7 +545,6 @@ function checkEnergyLevel() allTurbinesOff() r.setActive(false) end - print("end while") --Level < user setting (default: 50%) elseif getEnergyPer() < reactorOnAt then @@ -572,7 +575,7 @@ end --Sets the tables for checking the current turbineSpeeds function initSpeedTable() - for i=0, amountTurbines do + for i = 0, amountTurbines do lastSpeed[i] = 0 currSpeed[i] = 0 speedFailCounter[i] = 0 @@ -598,41 +601,41 @@ function getToTargetSpeed() end - --Not working yet - Needs reworking --- --Write speed to the currSpeed table --- currSpeed[i] = tspeed --- --- --Check turbine speed progression --- if currSpeed[i] < lastSpeed[i]-50 then --- --- print(speedFailCounter) --- --- --Return error message --- if speedFailCounter[i] >= 3 then --- mon.setBackgroundColor(colors.black) --- mon.clear() --- mon.setTextColor(colors.red) --- mon.setCursorPos(1, 1) --- if lang == "de" then --- mon.write("Turbinen koennen nicht auf Speed gebracht werden!") --- mon.setCursorPos(1,2) --- mon.write("Bitte den Steam-Input pruefen!") --- error("Turbinen koennen nicht auf Speed gebracht werden!") --- elseif lang == "en" then --- mon.write("Turbines can't get to speed!") --- mon.setCursorPos(1,2) --- mon.write("Please check your Steam-Input!") --- error("Turbines can't get to speed!") --- end --- --- --increase speedFailCounter --- else --- speedFailCounter[i] = speedFailCounter[i] + 1 --- end --- end --- --- --Write speed to the lastSpeed table --- lastSpeed[i] = tspeed + --Not working yet - Needs reworking + -- --Write speed to the currSpeed table + -- currSpeed[i] = tspeed + -- + -- --Check turbine speed progression + -- if currSpeed[i] < lastSpeed[i]-50 then + -- + -- print(speedFailCounter) + -- + -- --Return error message + -- if speedFailCounter[i] >= 3 then + -- mon.setBackgroundColor(colors.black) + -- mon.clear() + -- mon.setTextColor(colors.red) + -- mon.setCursorPos(1, 1) + -- if lang == "de" then + -- mon.write("Turbinen koennen nicht auf Speed gebracht werden!") + -- mon.setCursorPos(1,2) + -- mon.write("Bitte den Steam-Input pruefen!") + -- error("Turbinen koennen nicht auf Speed gebracht werden!") + -- elseif lang == "en" then + -- mon.write("Turbines can't get to speed!") + -- mon.setCursorPos(1,2) + -- mon.write("Please check your Steam-Input!") + -- error("Turbines can't get to speed!") + -- end + -- + -- --increase speedFailCounter + -- else + -- speedFailCounter[i] = speedFailCounter[i] + 1 + -- end + -- end + -- + -- --Write speed to the lastSpeed table + -- lastSpeed[i] = tspeed end end @@ -765,25 +768,32 @@ end --Checks for events (timer/clicks) function clickEvent() - --refresh screen - if overallMode == "auto" then - printStatsAuto(currStat) - checkEnergyLevel() - elseif overallMode == "manual" then - printStatsMan(currStat) - end + while true do - --timer - local time = os.startTimer(0.5) + --refresh screen + if overallMode == "auto" then + checkEnergyLevel() + elseif overallMode == "manual" then + printStatsMan(currStat) + end - --gets the event - local event, but = page:handleEvents(os.pullEvent()) - print(event) + --timer + local timer1 = os.startTimer(1) - --execute a buttons function if clicked - if event == "button_click" then - page:flash(but) - page.buttonList[but].func() + while true do + --gets the event + local event, p1 = page:handleEvents(os.pullEvent()) + print(event..", "..p1) + + --execute a buttons function if clicked + if event == "button_click" then + page:flash(p1) + page.buttonList[p1].func() + break + elseif event == "timer" and p1 == timer1 then + break + end + end end end @@ -1013,7 +1023,7 @@ function printStatsMan(turbine) --Other status informations if lang == "de" then mon.setCursorPos(2, 5) - mon.write("RF-Produktion: " .. (input.formatNumber(math.floor(rfGen))) .. " RF/t ") + mon.write("RF-Produktion: " .. (input.formatNumber(math.floor(rfGen))) .. " RF/t ") mon.setCursorPos(2, 7) local fuelCons = tostring(r.getFuelConsumedLastTick()) local fuelCons2 = string.sub(fuelCons, 0, 4) diff --git a/turbineControl_v2/src/release.ver b/turbineControl_v2/src/release.ver new file mode 100644 index 0000000..05d0dc7 --- /dev/null +++ b/turbineControl_v2/src/release.ver @@ -0,0 +1 @@ +2.5-release \ No newline at end of file diff --git a/turbineControl_v2/src/start/menu.lua b/turbineControl_v2/src/start/menu.lua index f86b7b3..5391704 100644 --- a/turbineControl_v2/src/start/menu.lua +++ b/turbineControl_v2/src/start/menu.lua @@ -1,8 +1,8 @@ -- Reaktor- und Turbinenprogramm von Thor_s_Crafter -- --- Version 2.3 -- +-- Version 2.5 -- -- Hauptmenue -- ---Lädt die Touchpoint API (von Lyqyd) +--Loads the Touchpoint API (by Lyqyd) shell.run("cp /reactor-turbine-program/config/touchpoint.lua /touchpoint") os.loadAPI("touchpoint") shell.run("rm touchpoint") @@ -14,12 +14,10 @@ local page = touchpoint.new(touchpointLocation) local startOn = {} local startOff = {} ---Erstellt die Buttons im Hauptmenü +--Erstellt die Buttons im Hauptmenu function createButtons() - page:add("Deutsch",nil,39,15,49,15) - page:add("English",nil,39,17,49,17) - - page:add("Update",updateManual,39,11,49,11) + page:add("Deutsch",nil,39,11,49,11) + page:add("English",nil,39,13,49,13) --In Deutsch if lang == "de" then @@ -32,8 +30,8 @@ function createButtons() page:add("Programm beenden",exit,3,18,20,18) page:add("Neu starten",reboot,3,20,20,20) page:add("menuOn",nil,39,7,49,7) - startOn = {" Ein ",label = "menuOn"} - startOff = {" Aus ",label = "menuOn"} + startOn = {" Ein ",label = "menuOn"} + startOff = {" Aus ",label = "menuOn"} page:toggleButton("Deutsch") --Programm if program == "turbine" then @@ -60,7 +58,7 @@ function createButtons() page:add("Reboot",restart,3,20,20,20) page:add("menuOn",nil,39,7,49,7) startOn = {" On ",label = "menuOn"} - startOff = {" Off ",label = "menuOn"} + startOff = {" Off ",label = "menuOn"} page:toggleButton("English") --Programm if program == "turbine" then @@ -77,7 +75,7 @@ function createButtons() end --Aktiv, wenn mainMenu an ist - if mainMenu == "true" then + if mainMenu then page:rename("menuOn",startOn,true) page:toggleButton("menuOn") else @@ -99,11 +97,6 @@ function exit() shell.completeProgram("/reactor-turbine-program/start/menu.lua") end -function updateManual() - shell.run("/reactor-turbine-program/install/installer.lua") - os.reboot() -end - function switchProgram(currBut) if program == "turbine" and currBut == "Reactor" then program = "reactor" @@ -165,12 +158,12 @@ local function getClick(funct) if event == "button_click" then if but == "menuOn" then print("menuOn") - if mainMenu == "false" then - mainMenu = "true" + if not mainMenu then + mainMenu = true saveOptionFile() page:rename("menuOn",startOn,true) - elseif mainMenu == "true" then - mainMenu = "false" + elseif mainMenu then + mainMenu = false saveOptionFile() page:rename("menuOn",startOff,true) end @@ -263,7 +256,7 @@ function displayMenu() mon.write("-- Hauptmenue --") mon.setCursorPos(39,5) mon.write("Hauptmenue zeigen: ") - mon.setCursorPos(39,13) + mon.setCursorPos(39,9) mon.write("Sprache: ") mon.setCursorPos(3,7) mon.write("Programm: ") @@ -275,7 +268,7 @@ function displayMenu() mon.write("-- Main Menu --") mon.setCursorPos(39,5) mon.write("Show this screen on startup: ") - mon.setCursorPos(39,13) + mon.setCursorPos(39,9) mon.write("Language: ") mon.setCursorPos(3,7) mon.write("Program: ") @@ -283,8 +276,7 @@ function displayMenu() mon.write("Mode:") end - mon.setCursorPos(39,9) - mon.write("Update:") + getClick(displayMenu) end diff --git a/turbineControl_v2/src/start/start.lua b/turbineControl_v2/src/start/start.lua index 8bf3444..ce2edad 100644 --- a/turbineControl_v2/src/start/start.lua +++ b/turbineControl_v2/src/start/start.lua @@ -1,8 +1,9 @@ --- Reactor- und Turbine control by Thor_s_Crafter -- --- Version 2.4 -- +-- Reactor- and Turbine control by Thor_s_Crafter -- +-- Version 2.5 -- -- Start program -- ---Global variables +--========== Global variables for all program parts ========== + --All options optionList = {} version = 0 @@ -12,7 +13,6 @@ textColor = 0 reactorOffAt = 0 reactorOnAt = 0 mainMenu = "" -autoUpdate = "" --deprecated lang = "" overallMode = "" program = "" @@ -20,112 +20,263 @@ turbineTargetSpeed = 0 targetSteam = 0 --Peripherals mon = "" --Monitor -r = "" -v = "" -t = {} - +r = "" --Reactor +v = "" --Energy Storage +t = {} --Turbines +--Total count of all turbines amountTurbines = 0 ---Touchpoint +--TouchpointLocation (same as the monitor) touchpointLocation = {} ---Global functions ---Loads the options.txt file + +--========== Global functions for all program parts ========== + + +--===== Functions for loading and saving the options ===== + +--Loads the options.txt file and adds values to the global variables function loadOptionFile() - --Read the file + --Loads the file local file = fs.open("/reactor-turbine-program/config/options.txt","r") - local listElement = file.readLine() - while listElement do - table.insert(optionList,listElement) - listElement = file.readLine() - end + local list = file.readAll() file.close() - --Assign values - version = optionList[3] - rodLevel = tonumber(optionList[5]) - backgroundColor = tonumber(optionList[7]) - textColor = tonumber(optionList[9]) - reactorOffAt = tonumber(optionList[11]) - reactorOnAt = tonumber(optionList[13]) - mainMenu = optionList[15] - autoUpdate = optionList[17] --deprecated - lang = optionList[19] - overallMode = optionList[21] - program = optionList[23] - turbineTargetSpeed = tonumber(optionList[25]) - targetSteam = tonumber(optionList[27]) + --Insert Elements and assign values + optionList = textutils.unserialise(list) + + --Assign values to variables + version = optionList["version"] + rodLevel = optionList["rodLevel"] + backgroundColor = tonumber(optionList["backgroundColor"]) + textColor = tonumber(optionList["textColor"]) + reactorOffAt = optionList["reactorOffAt"] + reactorOnAt = optionList["reactorOnAt"] + mainMenu = optionList["mainMenu"] + lang = optionList["lang"] + overallMode = optionList["overallMode"] + program = optionList["program"] + turbineTargetSpeed = optionList["turbineTargetSpeed"] + targetSteam = optionList["targetSteam"] +end + +--Refreshes the options list +function refreshOptionList() + optionList["version"] = version + optionList["rodLevel"] = rodLevel + optionList["backgroundColor"] = backgroundColor + optionList["textColor"] = textColor + optionList["reactorOffAt"] = reactorOffAt + optionList["reactorOnAt"] = reactorOnAt + optionList["mainMenu"] = mainMenu + optionList["lang"] = lang + optionList["overallMode"] = overallMode + optionList["program"] = program + optionList["turbineTargetSpeed"] = turbineTargetSpeed + optionList["targetSteam"] = targetSteam end --Saves all data basck to the options.txt file function saveOptionFile() - --Aktualisieren + --Refresh option list refreshOptionList() - --Daten in die Datei schreiben + --Serialise the table + local list = textutils.serialise(optionList) + --Save optionList to the config file local file = fs.open("/reactor-turbine-program/config/options.txt","w") - for i=1,#optionList+1,1 do - file.writeLine(optionList[i]) - end + file.writeLine(list) file.close() print("Saved.") end ---Refreshes th options list -function refreshOptionList() - optionList[3] = version - optionList[5] = rodLevel - optionList[7] = backgroundColor - optionList[9] = textColor - optionList[11] = reactorOffAt - optionList[13] = reactorOnAt - optionList[15] = mainMenu - optionList[17] = autoUpdate - optionList[19] = lang - optionList[21] = overallMode - optionList[23] = program - optionList[25] = turbineTargetSpeed - optionList[27] = targetSteam + +--===== Automatic update detection ===== + +--Check for updates +function checkUpdates() + + --Check current branch (release or beta) + local currBranch = "" + local tmpString = string.sub(version,5,5) + if tmpString == "" or tmpString == nil then + currBranch = "master" + elseif tmpString == "b" then + currBranch = "beta" + end + + --Get Remote version file + downloadFile("https://raw.githubusercontent.com/ThorsCrafter/Reactor-and-Turbine-control-program/"..currBranch.."/turbineControl_v2/src/",currBranch..".ver") + + --Compare local and remote version + local file = fs.open(currBranch..".ver","r") + local remoteVer = file.readLine() + file.close() + + print("remoteVer: "..remoteVer) + print("localVer: "..version) + print("Update? -> "..tostring(remoteVer > version)) + + --Update if available + if remoteVer > version then + print("Update...") + sleep(2) + doUpdate(remoteVer,currBranch) + end + + --Remove remote version file + shell.run("rm "..currBranch..".ver") +end + + +function doUpdate(toVer,branch) + + --Set the monitor up + local x,y = mon.getSize() + mon.setBackgroundColor(colors.black) + mon.clear() + + local x1 = x/2-15 + local y1 = y/2-4 + local x2 = x/2 + local y2 = y/2 + + --Draw Box + mon.setBackgroundColor(colors.gray) + mon.setTextColor(colors.gray) + mon.setCursorPos(x1,y1) + for i=1,8 do + mon.setCursorPos(x1,y1+i-1) + mon.write(" ") --30 chars + end + + --Print update message + mon.setTextColor(colors.white) + + if lang == "de" then + + mon.setCursorPos(x2-9,y1+1) + mon.write("Update verfuegbar!") --18 chars + + mon.setCursorPos(x2-(math.ceil(string.len(toVer)/2)),y1+3) + mon.write(toVer) + + mon.setCursorPos(x2-8,y1+5) + mon.write("Zum installieren") --16 chars + + mon.setCursorPos(x2-12,y1+6) + mon.write("in den Computer schauen") --23 chars + + elseif lang == "en" then + + mon.setCursorPos(x2-9,y1+1) + mon.write("Update available!") --17 chars + + mon.setCursorPos(x2-(math.ceil(string.len(toVer)/2)),y1+3) + mon.write(toVer) + + mon.setCursorPos(x2-8,y1+5) + mon.write("To install look") --15 chars + + mon.setCursorPos(x2-12,y1+6) + mon.write("at the computer terminal") --24 chars + end + + --Print install instructions to the terminal + term.clear() + term.setCursorPos(1,1) + local tx,ty = term.getSize() + + if lang == "de" then + print("Soll das Update installiert werden (j/n)?") + term.write("Eingabe: ") + elseif lang == "en" then + print("Do you want to install the update (y/n)?") + term.write("Input: ") + end + + --Run Counter for installation skipping + local count = 10 + local out = false + + term.setCursorPos(tx/2-5,ty) + term.write(" -- 10 -- ") + + while true do + + local timer1 = os.startTimer(1) + + while true do + + local event, p1 = os.pullEvent() + + if event == "key" then + + if p1 == 36 or p1 == 21 then + shell.run("/reactor-turbine-program/install/installer.lua update "..branch) + out = true + break + end + + elseif event == "timer" and p1 == timer1 then + + count = count - 1 + term.setCursorPos(tx/2-5,ty) + term.write(" -- 0"..count.." -- ") + break + end + end + + if out then break end + + if count == 0 then + term.clear() + term.setCursorPos(1,1) + break + end + end end ---Initializing all attached peripherals +--Download Files (For Remote version file) +function downloadFile(relUrl,path) + local gotUrl = http.get(relUrl..path) + if gotUrl == nil then + term.clear() + error("File not found! Please check!\nFailed at "..relUrl..path) + else + url = gotUrl.readAll() + end + + local file = fs.open(path,"w") + file.write(url) + file.close() +end + + +--===== Initialization of all peripherals ===== + function initPeripherals() - --Get all peripherals - local peripheralList = peripheral.getNames() - for i = 1, #peripheralList do - --Turbinen - if peripheral.getType(peripheralList[i]) == "BigReactors-Turbine" then - t[amountTurbines] = peripheral.wrap(peripheralList[i]) - amountTurbines = amountTurbines + 1 - end - --Reactor - if peripheral.getType(peripheralList[i]) == "BigReactors-Reactor" then - r = peripheral.wrap(peripheralList[i]) - end - --Monitor & Touchpoint - if peripheral.getType(peripheralList[i]) == "monitor" then - mon = peripheral.wrap(peripheralList[i]) - touchpointLocation = peripheralList[i] - end - --Capacitorbank / Energycell / Energy Core - if peripheral.getType(peripheralList[i]) == "tile_blockcapacitorbank_name" then - v = peripheral.wrap(peripheralList[i]) - elseif peripheral.getType(peripheralList[i]) == "capacitor_bank" then - v = peripheral.wrap(peripheralList[i]) - elseif peripheral.getType(peripheralList[i]) == "tile_thermalexpansion_cell_basic_name" then - v = peripheral.wrap(peripheralList[i]) - elseif peripheral.getType(peripheralList[i]) == "tile_thermalexpansion_cell_hardened_name" then - v = peripheral.wrap(peripheralList[i]) - elseif peripheral.getType(peripheralList[i]) == "tile_thermalexpansion_cell_reinforced_name" then - v = peripheral.wrap(peripheralList[i]) - elseif peripheral.getType(peripheralList[i]) == "tile_thermalexpansion_cell_resonant_name" then - v = peripheral.wrap(peripheralList[i]) - elseif peripheral.getType(peripheralList[i]) == "cofh_thermal_expansion_energycell" then - v = peripheralList.wrap(peripheralList[i]) - elseif peripheral.getType(peripheralList[i]) == "draconic_rf_storage" then - v = peripheral.wrap(peripheralList[i]) - elseif peripheral.getType(peripheralList[i]) == "powered_tile" then - v = peripheral.wrap(peripheralList[i]) - end - end + --Get all peripherals + local peripheralList = peripheral.getNames() + for i = 1, #peripheralList do + --Turbines + if peripheral.getType(peripheralList[i]) == "BigReactors-Turbine" then + t[amountTurbines] = peripheral.wrap(peripheralList[i]) + amountTurbines = amountTurbines + 1 + --Reactor + elseif peripheral.getType(peripheralList[i]) == "BigReactors-Reactor" then + r = peripheral.wrap(peripheralList[i]) + --Monitor & Touchpoint + elseif peripheral.getType(peripheralList[i]) == "monitor" then + mon = peripheral.wrap(peripheralList[i]) + touchpointLocation = peripheralList[i] + --Capacitorbank / Energycell / Energy Core + else + local tmp = peripheral.wrap(peripheralList[i]) + local stat,err = pcall(function() tmp.getEnergyStored() end) + if stat then + v = tmp + end + end + end --Check for errors term.clear() @@ -133,9 +284,9 @@ function initPeripherals() --No Monitor if mon == "" then if lang == "de" then - error("Monitor nicht gefunden! Bitte pruefen und den Computer neu starten (Strg+R gedrueckt halten)") + error("Monitor nicht gefunden!\nBitte pruefen und den Computer neu starten (Strg+R gedrueckt halten)") elseif lang == "en" then - error("Monitor not found! Please check and reboot the computer (Press and hold Ctrl+R)") + error("Monitor not found!\nPlease check and reboot the computer (Press and hold Ctrl+R)") end end --Monitor clear @@ -147,55 +298,48 @@ function initPeripherals() local monX,monY = mon.getSize() if monX < 71 or monY < 26 then if lang == "de" then - mon.write("Monitor zu klein. Bitte min. 7 breit und 4 hoch bauen und den Computer neu starten (Strg+R gedrueckt halten)") - error("Monitor zu klein. Bitte min. 7 breit und 4 hoch bauen und den Computer neu starten (Strg+R gedrueckt halten)") + mon.write("Monitor zu klein.\nBitte min. 7 breit und 4 hoch bauen und den Computer neu starten\n(Strg+R gedrueckt halten)") + error("Monitor zu klein.\nBitte min. 7 breit und 4 hoch bauen und den Computer neu starten\n(Strg+R gedrueckt halten)") elseif lang == "en" then - mon.write("Monitor too small. Must be at least 7 in length and 4 in height. Please check and reboot the computer (Press and hold Ctrl+R)") - error("Monitor too small. Must be at least 7 in length and 4 in height. Please check and reboot the computer (Press and hold Ctrl+R)") + mon.write("Monitor too small\n Must be at least 7 in length and 4 in height.\nPlease check and reboot the computer (Press and hold Ctrl+R)") + error("Monitor too small.\nMust be at least 7 in length and 4 in height.\nPlease check and reboot the computer (Press and hold Ctrl+R)") end end amountTurbines = amountTurbines - 1 end ---Restarts the computer + +--===== Shutdown and restart the computer ===== + function restart() - refreshOptionList() saveOptionFile() mon.clear() mon.setCursorPos(38,8) - mon.write("Reboot...") - if autoUpdate == true then - shell.run("/reactor-turbine-program/install/installerUpdate.lua") - else - os.reboot() - end + mon.write("Rebooting...") + os.reboot() end ---Start the program + +--=========== Run the program ========== + +--Load the option file and initialize the peripherals loadOptionFile() initPeripherals() +checkUpdates() ---Deprecated ---if autoUpdate == "true" then --- shell.run("/reactor-turbine-program/install/installerUpdate.lua") ---end - -if mainMenu == "true" then +--Run program or main menu, based on the settings +if mainMenu then shell.run("/reactor-turbine-program/start/menu.lua") shell.completeProgram("/reactor-turbine-program/start/start.lua") -elseif mainMenu == "false" then - if program == "turbine" then - shell.run("/reactor-turbine-program/program/turbineControl.lua") - elseif program == "reactor" then - shell.run("/reactor-turbine-program/program/reactorControl.lua") - end +else + if program == "turbine" then + shell.run("/reactor-turbine-program/program/turbineControl.lua") + elseif program == "reactor" then + shell.run("/reactor-turbine-program/program/reactorControl.lua") + end shell.completeProgram("/reactor-turbine-program/start/start.lua") +end + ---Deprecated? ---else --- mainMenu = "true" --- saveOptionFile() --- shell.run("/reactor-turbine-program/start/menu.lua") --- shell.completeProgram("/reactor-turbine-program/start/start.lua") -end \ No newline at end of file +--========== END OF THE START.LUA FILE ========== \ No newline at end of file