Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Script by Savage_Me55iah of CraftAU.com.au and Nuqube.co--
- local scriptName, version, pastebinCode = "CODE_EMBED_EXPERIMENTAL", "v0.4", "5y35NCBX"
- --Other Savage_Me55iah scripts @ http://pastebin.com/u/Savage_Me55iah
- --INSTRUCTIONS ON USE--
- --Instruction video on http://youtube.com/savagemessiah5
- --Contact Savage_Me55iah @ CraftAU.com.au or Nuqube.co or http://www.computercraft.info/forums2/ with suggestions/fixes/bugs
- -- CHANGELOG --
- --V1.0 -
- -- Limited monitors supported
- -- SETUP --
- local debugLevel, debugTime = 0, 0.1
- local tArgs = {...}
- local update_request = tArgs[1]
- local logTable = {}
- if (os.getComputerLabel() or true) then os.setComputerLabel(scriptName.."-"..math.random(1000, 9999)) end
- local consoleWriteF = nil
- function console(param_text, param_logLevel)
- local result, text, logLevel, functionName = false, param_text, param_logLevel or 0, "console"
- if tostring(consoleWriteF) ~= "nil" then
- result = consoleWriteF(text, logLevel)
- else
- table.insert(logTable, {["text"] = text, ["logLevel"] = logLevel, ["time"] = os.day() .. ": " .. textutils.formatTime(os.time(), true)})
- print(text)
- result = true
- end
- if debugLevel >= 1 then sleep(debugTime) end
- return result
- end
- -----------------------------------------------------------------------------------------------------------
- -- UPDATER SETUP -- EMBEDED --
- -----------------------------------------------------------------------------------------------------------
- function update(script_name, pastebincode)
- console("UPDATING") shell.run("pastebin get "..pastebincode.." update")
- if fs.exists("update") then
- fs.delete(script_name) fs.copy("update", script_name) fs.delete("update") console("UPDATE SUCCESS")
- else
- console("UPDATE FAILED")
- end
- sleep(2) os.reboot()
- end
- if tostring(update_request) == "update" then update(shell.getRunningProgram(), pastebinCode) end
- console("marker - update setup complete")
- -----------------------------------------------------------------------------------------------------------
- -- DUMMY FUNCTIONS -- EMBEDED -- THIS ALLOWS ME TO WRITE MY FUNCTIONS EVERYWHERE, NOT JUST IN LINEAR ORDER
- -----------------------------------------------------------------------------------------------------------
- -- VARIABLE MANIPULATION FUNCTIONS
- function Debug(...) local results = false if tostring(DebugF) ~= "nil" then results = DebugF(...) else console("error: dummy function fail: Debug") end return results end
- function insertBS(...) local results = false if tostring(insertBSF) ~= "nil" then results = insertBSF(...) else console("error: dummy function fail: insertBS") end return results end
- function value(...) local results = false if tostring(valueF) ~= "nil" then results = valueF(...) else console("error: dummy function fail: value") end return results end
- function booleanCheck(...) local results = false if tostring(booleanCheckF) ~= "nil" then results = booleanCheckF(...) else console("error: dummy function fail: booleanCheck") end return results end
- function massAndBooleanCheck(...) local results = false if tostring(massAndBooleanCheckF) ~= "nil" then results = massAndBooleanCheckF(...) else console("error: dummy function fail: massAndBooleanCheck") end return results end
- function massOrBooleanCheck(...) local results = false if tostring(massOrBooleanCheckF) ~= "nil" then results = massOrBooleanCheckF(...) else console("error: dummy function fail: massOrBooleanCheck") end return results end
- function multiOrCompare(...) local results = false if tostring(multiOrCompareF) ~= "nil" then results = multiOrCompareF(...) else console("error: dummy function fail: multiOrCompare") end return results end
- function multiAndCompare(...) local results = false if tostring(multiAndCompareF) ~= "nil" then results = multiAndCompareF(...) else console("error: dummy function fail: multiAndCompare") end return results end
- function stringCombine(...) local results = false if tostring(stringCombineF) ~= "nil" then results = stringCombineF(...) else console("error: dummy function fail: stringCombine") end return results end
- function variableCheck(...) local results = false if tostring(variableCheckF) ~= "nil" then results = variableCheckF(...) else console("error: dummy function fail: variableCheck") end return results end
- function quickChoice(...) local results = false if tostring(quickChoiceF) ~= "nil" then results = quickChoiceF(...) else console("error: dummy function fail: quickChoice") end return results end
- function tolerance(...) local results = false if tostring(toleranceF) ~= "nil" then results = toleranceF(...) else console("error: dummy function fail: tolerance") end return results end
- -- PERIPHERAL/WINDOW MANIPULATION FUNCTIONS
- function peripheralFindType(...) local results = false if tostring(peripheralFindTypeF) ~= "nil" then results = peripheralFindTypeF(...) else console("error: dummy function fail: peripheralFindType") end return results end
- function monitorSetScale(...) local results = false if tostring(monitorSetScaleF) ~= "nil" then results = monitorSetScaleF(...) else console("error: dummy function fail: monitorSetScale") end return results end
- function monitorDetect(...) local results = false if tostring(monitorDetectF) ~= "nil" then results = monitorDetectF(...) else console("error: dummy function fail: monitorDetect") end return results end
- function stdWindowsCreate(...) local results = false if tostring(stdWindowsCreateF) ~= "nil" then results = stdWindowsCreateF(...) else console("error: dummy function fail: stdWindowsCreate") end return results end
- function addStdWindow(...) local results = false if tostring(addStdWindowF) ~= "nil" then results = addStdWindowF(...) else console("error: dummy function fail: addStdWindow") end return results end
- function switchWindow(...) local results = false if tostring(switchWindowF) ~= "nil" then results = switchWindowF(...) else console("error: dummy function fail: switchWindow") end return results end
- function activeWindow(...) local results = false if tostring(activeWindowF) ~= "nil" then results = activeWindowF(...) else console("error: dummy function fail: activeWindow") end return results end
- function resizeWindow(...) local results = false if tostring(resizeWindowF) ~= "nil" then results = resizeWindowF(...) else console("error: dummy function fail: resizeWindow") end return results end
- function clearWindow(...) local results = false if tostring(clearWindowF) ~= "nil" then results = clearWindowF(...) else console("error: dummy function fail: clearWindow") end return results end
- --
- function selectColor(...) local results = false if tostring(selectColorF) ~= "nil" then results = selectColorF(...) else console("error: dummy function fail: selectColor") end return results end
- function screenWrite(...) local results = false if tostring(screenWriteF) ~= "nil" then results = screenWriteF(...) else console("error: dummy function fail: screenWrite") end return results end
- function windowWrite(...) local results = false if tostring(windowWriteF) ~= "nil" then results = windowWriteF(...) else console("error: dummy function fail: windowWrite") end return results end
- function backgroundColor(...) local results = false if tostring(backgroundColorF) ~= "nil" then results = backgroundColorF(...) else console("error: dummy function fail: backgroundColor") end return results end
- -- TABLE MANIPULATION FUNCTIONS
- function loadTable(...) local results = false if tostring(loadTableF) ~= "nil" then results = loadTableF(...) else console("error: dummy function fail: loadTable") end return results end
- function saveTable(...) local results = false if tostring(saveTableF) ~= "nil" then results = saveTableF(...) else console("error: dummy function fail: saveTable") end return results end
- -- LOGGING FUNCTIONS
- function logSetup(...) local results = false if tostring(logSetupF) ~= "nil" then results = logSetupF(...) else console("error: dummy function fail: logSetup") end return results end
- -- BUTTON MANIPULATION FUNCTIONS
- function generateButton(...) local results = false if tostring(generateButtonF) ~= "nil" then results = generateButtonF(...) else console("error: dummy function fail: generateButton") end return results end
- function stdPulse(...) local results = false if tostring(stdPulseF) ~= "nil" then results = stdPulseF(...) else console("error: dummy function fail: stdPulse") end return results end
- function stdToggle(...) local results = false if tostring(stdToggleF) ~= "nil" then results = stdToggleF(...) else console("error: dummy function fail: stdToggle") end return results end
- function monitorToggle(...) local results = false if tostring(monitorToggleF) ~= "nil" then results = monitorToggleF(...) else console("error: dummy function fail: monitorToggle") end return results end
- function dataChange(...) local results = false if tostring(dataChangeF) ~= "nil" then results = dataChangeF(...) else console("error: dummy function fail: dataChange") end return results end
- function addButton(...) local results = false if tostring(addButtonF) ~= "nil" then results = addButtonF(...) else console("error: dummy function fail: addButton") end return results end
- function monitorListApply(...) local results = false if tostring(monitorListApplyF) ~= "nil" then results = monitorListApplyF(...) else console("error: dummy function fail: monitorListApply") end return results end
- function addMonitorListButtons(...) local results = false if tostring(addMonitorListButtonsF) ~= "nil" then results = addMonitorListButtonsF(...) else console("error: dummy function fail: addMonitorListButtons") end return results end
- function generateWindowButtons(...) local results = false if tostring(generateWindowButtonsF) ~= "nil" then results = generateWindowButtonsF(...) else console("error: dummy function fail: generateWindowButtons") end return results end
- function generateAllButtons(...) local results = false if tostring(generateAllButtonsF) ~= "nil" then results = generateAllButtonsF(...) else console("error: dummy function fail: generateAllButtons") end return results end
- function updateButton(...) local results = false if tostring(updateButtonF) ~= "nil" then results = updateButtonF(...) else console("error: dummy function fail: updateButton") end return results end
- function startupScript(...) local results = false if tostring(startupScriptF) ~= "nil" then results = startupScriptF(...) else console("error: dummy function fail: startupScript") end return results end
- function monitorListWindow(...) local results = false if tostring(monitorListWindowF) ~= "nil" then results = monitorListWindowF(...) else console("error: dummy function fail: monitorListWindow") end return results end
- function restart(...) local results = false if tostring(restartF) ~= "nil" then results = restartF(...) else console("error: dummy function fail: restart") end return results end
- function terminate(...) local results = false if tostring(terminateF) ~= "nil" then results = terminateF(...) else console("error: dummy function fail: terminate") end return results end
- function stdButtons(...) local results = false if tostring(stdButtonsF) ~= "nil" then results = stdButtonsF(...) else console("error: dummy function fail: stdButtons") end return results end
- function topBarScroll(...) local results = false if tostring(topBarScrollF) ~= "nil" then results = topBarScrollF(...) else console("error: dummy function fail: topBarScroll") end return results end
- function topBarChange(...) local results = false if tostring(topBarChangeF) ~= "nil" then results = topBarChangeF(...) else console("error: dummy function fail: topBarChange") end return results end
- function topBarButtons(...) local results = false if tostring(topBarButtonsF) ~= "nil" then results = topBarButtonsF(...) else console("error: dummy function fail: topBarButtons") end return results end
- function buttonScan(...) local results = false if tostring(buttonScanF) ~= "nil" then results = buttonScanF(...) else console("error: dummy function fail: buttonScan") end return results end
- --
- function eventFilter(...) local results = false if tostring(eventFilterF) ~= "nil" then results = eventFilterF(...) else console("error: dummy function fail: eventFilter") end return results end
- function insertWindow(...) local results = false if tostring(insertWindowF) ~= "nil" then results = insertWindowF(...) else console("error: dummy function fail: insertWindow") end return results end
- function messageWindow(...) local results = false if tostring(messageWindowF) ~= "nil" then results = messageWindowF(...) else console("error: dummy function fail: messageWindow") end return results end
- function peripheralListRegisterSingle(...) local results = false if tostring(peripheralListRegisterSingleF) ~= "nil" then results = peripheralListRegisterSingleF(...) else console("error: dummy function fail: peripheralListRegisterSingle") end return results end
- function peripheralListRegisterMulti(...) local results = false if tostring(peripheralListRegisterMultiF) ~= "nil" then results = peripheralListRegisterMultiF(...) else console("error: dummy function fail: peripheralListRegisterMulti") end return results end
- function peripheralListAdd(...) local results = false if tostring(peripheralListAddF) ~= "nil" then results = peripheralListAddF(...) else console("error: dummy function fail: peripheralListAdd") end return results end
- function peripheralFind(...) local results = false if tostring(peripheralFindF) ~= "nil" then results = peripheralFindF(...) else console("error: dummy function fail: peripheralFind") end return results end
- console("marker - dummy functions setup complete")
- -----------------------------------------------------------------------------------------------------------
- -- PRELIMENARY FUNCTIONS -- EMBEDED --
- -----------------------------------------------------------------------------------------------------------
- function DebugF(lvl, ...) if (debugLevel == 2 and lvl ~= "basic") or debugLevel > 2 then console(...) end return true end
- -- BACKSLASH WAS MESSING WITH MY SCRIPT EDITOR
- function insertBSF()
- local result = "\\"
- return result
- end
- -- value structure
- -- example = {["value"], ["type"], ["nil"], ["incr"], ["max"], ["min"], ["result"]}
- function valueF(param_prev, param_value, param_incr, param_max, param_min)
- local result, functionName = {false, {}}, "valueF"
- Debug("basic", "debug: "..functionName)
- result[2] = quickChoice(multiAndCompare(false, booleanCheck(param_prev)[1], booleanCheck(param_prev)[2])[2], {["value"] = false, ["type"] = "nil", ["nil"] = true, ["increment"] = "nil", ["max"] = "nil", ["min"] = "nil", ["result"] = false}, param_prev)[2]
- if booleanCheck(result[2])[1] then
- result[2]["value"] = booleanCheck(param_value)[2]
- result[2]["type"] = type(param_value)
- result[2]["nil"] = false
- result[2]["incr"] = param_incr or result[2]["incr"] or "nil"
- result[2]["max"] = param_max or result[2]["max"] or "nil"
- result[2]["min"] = param_min or result[2]["min"] or "nil"
- result[1], result[2]["result"] = true, true
- end
- Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function booleanCheckF(params)
- local result, functionName = {[1] = false, [2] = nil}, "booleanCheckF"
- if tostring(params) ~= "nil" then
- result = {true, params}
- else
- result = {false, false}
- end
- return result
- end
- function massAndBooleanCheckF(...)
- local list, result, functionName = {...}, {false, true}, "massAndBooleanCheckF"
- Debug("basic", "debug: "..functionName)
- for a,b in pairs(list) do result[2] = quickChoice(b, result[2], false)[2] end result[1] = true
- Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function massOrBooleanCheckF(...)
- local list, result, functionName = {...}, {false, false}, "massOrBooleanCheckF"
- Debug("basic", "debug: "..functionName)
- for a,b in pairs(list) do result[2] = quickChoice(b, true, result[2])[2] end result[1] = true
- Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function multiOrCompareF(param_arg, ...)
- local list, result, functionName = {...}, {false, false}, "multiOrCompareF"
- Debug("basic", "debug: "..functionName)
- for a,b in pairs(list) do result[2] = quickChoice((booleanCheck(param_arg)[2] == booleanCheck(b)[2]), true, result[2])[2] end
- result[1] = true
- Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function multiAndCompareF(param_arg, ...)
- local list, result, functionName = {...}, {false, true}, "multiAndCompareF"
- Debug("basic", "debug: "..functionName)
- for a,b in pairs(list) do result[2] = quickChoice((booleanCheck(param_arg)[2] == booleanCheck(b)[2]), result[2], false)[2] end
- result[1] = true
- Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function stringCombineF(param_space, ...)
- local tempList, stringList, result, functionName = {...}, {}, {false, nil}, "stringCombineF"
- Debug("basic", "debug: "..functionName)
- if booleanCheck(type(param_space))[2] == "boolean" then
- for a,b in pairs(tempList) do
- if booleanCheck(type(b))[2] == "table" then
- for c,d in pairs(tempList[a]) do table.insert(stringList, d) end
- else
- if booleanCheck(b)[1] then table.insert(stringList, tostring(b)) end
- end
- end
- for a,b in pairs(stringList) do
- if type(b) ~= "table" then
- if param_space then
- result[2] = quickChoice(booleanCheck(result[2])[1], tostring(result[2]).." "..tostring(b), tostring(b))[2]
- else
- result[2] = quickChoice(booleanCheck(result[2])[1], tostring(result[2])..tostring(b), tostring(b))[2]
- end
- end
- end
- result[1] = true
- else
- console("error: variable in func "..functionName.." incorrect, expected: table")
- end
- Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function variableCheckF(param_functionName, param_type, param_variable)
- local result, errorMsg, variableMsg, functionName, tempTable = {false, false}, ":", ":", "variableCheckF", {}
- Debug("basic", "debug: "..functionName)
- if multiAndCompare("table", type(param_type), type(param_variable))[2] then
- for a,b in pairs(param_variable) do
- tempTable[a], errorMsg = false, ":"
- for c,d in pairs(param_type) do
- if massAndBooleanCheck(booleanCheck(b)[1], booleanCheck(d)[1])[2] then
- tempTable[a], variableMsg, errorMsg = quickChoice((d == type(b)), true, tempTable[a])[2], stringCombine(true, {variableMsg, b})[2], stringCombine(true, {errorMsg, d})[2]
- end
- end
- end
- result[2] = true
- for a,b in pairs(tempTable) do result = {true, quickChoice(tempTable[a], tempTable[a], false)[2]} end
- else
- console(stringCombine(true, "error: variable in func", functionName, "incorrect, expected: table")[2])
- end
- if not result[2] then console(stringCombine(true, "error: variable in func", param_functionName, "incorrect, expected:", errorMsg, "got", variableMsg)[2]) end
- Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function quickChoiceF(param_boolean, param_true, param_false)
- local result, functionName = {false, false}, "quickChoiceF"
- Debug("basic", "debug: "..functionName)
- if booleanCheck(type(param_boolean))[2] == "boolean" then
- if booleanCheck(param_boolean)[2] == true then result = {true, param_true} else result = {true, param_false} end
- else
- result = {false, param_false}
- end
- Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function toleranceF(param_target, param_value, param_tolerancePositive, param_toleranceNegative)
- local result, functionName = {false, false}, "toleranceF"
- Debug("basic", "debug: "..functionName)
- if variableCheck(functionName, {"number"}, {param_target, param_value})[2] then
- local tolerancePositive, toleranceNegative = param_tolerancePositive or 0, param_toleranceNegative or 0
- tolerancePositive, toleranceNegative = param_target + tolerancePositive, param_target + toleranceNegative
- result = {true, quickChoice(massAndBooleanCheck((param_value <= tolerancePositive), (param_value >= toleranceNegative))[2], true, false)[2]}
- end
- Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- -- modems = peripheralFindF("method", "modem", "wireless") .. returns a table of all peripherals of the same type --
- function peripheralFindF(param_mode, param_variable, modem_type)
- local functionName, peripheralList, result, modem_type = "peripheralFindF", peripheral.getNames() or false, {false, {}}, modem_type or false
- Debug("basic", "debug: "..functionName)
- if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_mode})[2], variableCheck(functionName, {"table"}, {param_variable})[2], peripheralList ~= false)[2] then
- console(stringCombine(true, "finding peripherals:-", param_mode, param_variable, modem_type)[2])
- for a,b in pairs(peripheralList) do
- if param_mode == "type" then
- local testType = peripheral.getType(b)
- for c,d in pairs(param_variable) do
- if testType == tostring(d) then
- if tostring(modem_type) == "false" then
- table.insert(result[2], b) result[1] = true
- else
- local Peripheral = peripheral.wrap(b)
- local wireless = booleanCheck(Peripheral.isWireless())[2]
- if modem_type == "wireless" and wireless then table.insert(result[2], b) result[1] = true
- elseif modem_type == "modem" and not wireless then table.insert(result[2], b) result[1] = true
- end end end end
- elseif param_mode == "method" then
- local tempList, methodTest = peripheral.getMethods(b), true
- for c,d in pairs(tempList) do
- methodTest = true
- for e,f in pairs(param_variable) do
- methodTest = quickChoice(d == f, methodTest, false)[2]
- end
- if methodTest then table.insert(result[2], b) result[1] = true end
- end end
- end end
- if not result[1] then result[2] = false console(stringCombine(true, "error:- cannot find peripheral:-", param_mode, param_variable)[2], 1) else console("peripheral find success") end
- Debug("basic", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- console("marker - preliminary functions setup complete")
- -----------------------------------------------------------------------------------------------------------
- -- SAVE/LOAD FUNCTIONS -- EMBEDED --
- -----------------------------------------------------------------------------------------------------------
- -- users = loadTable("users", "datastore") .. returns table from an external/previously saved table, directory not required --
- function loadTableF(param_tableName, param_directory)
- local location, result, functionName = param_tableName, {false, false}, "loadTableF"
- Debug("secondary", "debug: "..functionName)
- if variableCheck(functionName, {"string"}, {param_tableName})[2] then
- if booleanCheck(param_directory)[1] then
- if variableCheck(functionName, {"string"}, {param_directory})[2] then
- location = quickChoice(booleanCheck(fs.isDir(param_directory))[2], param_directory..insertBS()..param_tableName, location)[2]
- end
- end
- if fs.exists(location) then
- local filehandler = fs.open(location, 'r')
- result = {true, textutils.unserialize(filehandler.readAll())}
- filehandler.close()
- end
- if not result[1] then console(stringCombine(true, "error:", location)[2]) end
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- -- saveTable("users", users, "datastore") .. returns boolean, saves table into a file, directory not required --
- function saveTableF(param_tableName, param_table, param_directory)
- local location, result, functionName = param_tableName, {false, false}, "saveTableF"
- Debug("secondary", "debug: "..functionName)
- if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_tableName})[2], variableCheck(functionName, {"table"}, {param_table})[2])[2] then
- if booleanCheck(param_directory)[1] ~= false then
- if variableCheck(functionName, {"string"}, {param_directory})[2] then
- if booleanCheck(fs.isDir(param_directory))[2] ~= true then
- fs.makeDir(tostring(param_directory))
- end
- location = param_directory..insertBS()..param_tableName
- end
- end
- local filehandler = fs.open(location, 'w')
- result = {true, filehandler.write(textutils.serialize(param_table))}
- filehandler.close()
- if not result[1] then console(stringCombine(true, "error:", location)[2]) end
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- console("marker - load/save setup complete")
- -----------------------------------------------------------------------------------------------------------
- -- WINDOWS SETUP -- EMBEDED --
- -----------------------------------------------------------------------------------------------------------
- local termX, termY = term.getSize()
- varList = {
- ["monitorList"] = {},
- ["stdWindows"] = {},
- ["currentWindow"] = {["term"] = "console", ["monitor"] = "console"},
- ["buttons"] = {},
- ["stdWindowsData"] = {}
- }
- function monitorSetScaleF()
- local result, functionName = {false, nil}, "monitorSetScaleF"
- Debug("secondary", "debug: "..functionName)
- for a,b in pairs(varList["monitorList"]) do
- if varList["monitorList"][a]["active"] then
- console("setting monitor scales")
- local tempMonitor, scale = peripheral.wrap(varList["monitorList"][a]["name"]), 5
- tempMonitor.setTextScale(scale)
- local monX, monY = tempMonitor.getSize()
- while massOrBooleanCheck(tolerance(termX, monX, -1, -termX)[2], tolerance(termY, monY, -1, -termY)[2])[2] and scale ~= 0.5 do
- scale = scale - 0.2
- tempMonitor.setTextScale(scale)
- monX, monY = tempMonitor.getSize()
- result[1] = true
- end
- console(stringCombine(true, "completed monitor scale:",b,scale)[2])
- end
- end
- console("completed all monitor scaling")
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function monitorDetectF()
- local tempListA, result, functionName = quickChoice(fs.exists("dataStore"..insertBS().."monitorList"), loadTable("monitorList", "dataStore")[2], varList["monitorList"])[2], {false, nil}, "monitorDetectF"
- Debug("secondary", "debug: "..functionName)
- varList["monitorList"] = {}
- local tempListB = peripheralFind("type", {"monitor"})
- if tempListB[1] then
- for a,b in pairs(tempListB[2]) do
- varList["monitorList"][a] = {["name"] = b, ["active"] = false}
- end
- if booleanCheck(tempListA[1])[1] then
- for a,b in pairs(tempListA) do
- for c,d in pairs(varList["monitorList"]) do
- varList["monitorList"][c]["active"] = quickChoice((varList["monitorList"][c]["name"] == tempListA[a]["name"]), tempListA[a]["active"], varList["monitorList"][c]["active"])[2]
- end end end end
- monitorSetScale()
- saveTable("monitorList", varList["monitorList"], "dataStore")
- varList["monitorList"]["terminal"] = {["name"] = term.native(), ["active"] = true}
- result[1] = true
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function stdWindowsCreateF()
- local currentTerm, result, functionName = term.current(), {false, nil}, "stdWindowsCreateF"
- Debug("secondary", "debug: "..functionName)
- term.redirect(term.native())
- console("creating windows")
- for c,d in pairs(varList["stdWindowsData"]) do
- for a,b in pairs(varList["monitorList"]) do
- if varList["monitorList"][a]["active"] then
- local TLX, TLY, XL, YL = varList["stdWindowsData"][c]["TLX"], varList["stdWindowsData"][c]["TLY"], varList["stdWindowsData"][c]["XL"], varList["stdWindowsData"][c]["YL"]
- varList["stdWindows"][c] = quickChoice(booleanCheck(varList["stdWindows"][c])[1], booleanCheck(varList["stdWindows"][c])[2], {})[2]
- if varList["monitorList"][a]["name"] ~= term.native() then
- if booleanCheck(varList["stdWindows"][c][varList["monitorList"][a]["name"]])[1] == false then
- local tempWrap = peripheral.wrap(varList["monitorList"][a]["name"])
- varList["stdWindows"][c][varList["monitorList"][a]["name"]] = {}
- varList["stdWindows"][c][varList["monitorList"][a]["name"]][1] = window.create(tempWrap, TLX, TLY, XL, YL, false)
- varList["stdWindows"][c][varList["monitorList"][a]["name"]][2] = window.create(varList["stdWindows"][c][varList["monitorList"][a]["name"]][1], (1 - (TLX - 1)), (1 - (TLY - 1)), termX, termY, true)
- result[1] = true
- end
- else
- if booleanCheck(varList["stdWindows"][c]["term"])[1] == false then
- varList["stdWindows"][c]["term"] = {}
- varList["stdWindows"][c]["term"][1] = window.create(term.native(), TLX, TLY, XL, YL, false)
- varList["stdWindows"][c]["term"][2] = window.create(varList["stdWindows"][c]["term"][1], (1 - (TLX - 1)), (1 - (TLY - 1)), termX, termY, true)
- result[1] = true
- end
- end
- else
- if booleanCheck(varList["stdWindows"][c])[1] then if booleanCheck(varList["stdWindows"][c][varList["monitorList"][a]["name"]])[1] then varList["stdWindows"][c][varList["monitorList"][a]["name"]] = nil end end
- end
- end
- activeWindow("both", c, false)
- console(stringCombine(true, "creating window", c, "completed")[2])
- term.redirect(currentTerm)
- end
- console("creating windows completed")
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function addStdWindowF(param_name, param_TLX, param_TLY, param_XL, param_YL, param_topBar)
- local result, functionName = {false, nil}, "addStdWindowF"
- Debug("secondary", "debug: "..functionName)
- if massAndBooleanCheck(variableCheck("addStdWindowF", {"string"}, {param_name})[2], variableCheck("addStdWindowF", {"number"}, {param_TLX, param_TLY, param_XL, param_YL})[2], variableCheck("addStdWindowF", {"boolean"}, {param_topBar})[2])[2] then
- if booleanCheck(varList["stdWindowsData"][param_name])[1] == false then
- varList["stdWindowsData"][param_name] = {["TLX"] = param_TLX, ["TLY"] = param_TLY, ["XL"] = param_XL, ["YL"] = param_YL, ["topBar"] = param_topBar}
- console("adding std window: "..param_name)
- result[1] = true
- end
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function activeWindowF(param_screen, param_window, param_boolean)
- local result, functionName = {false, nil}, "activeWindowF"
- Debug("secondary", "debug: "..functionName)
- if variableCheck(functionName, {"string"}, {param_screen, param_window})[2] then
- local screen = quickChoice(multiOrCompare(param_screen, "monitor", "monitor_touch")[2], "monitor", "both")[2]
- screen = quickChoice(multiOrCompare(param_screen, "term", "mouse_click")[2], "term", screen)[2]
- if booleanCheck(varList["stdWindows"][param_window])[1] then
- local tempTable = varList["stdWindows"][param_window]
- if screen == "both" then
- for a,b in pairs(tempTable) do
- local posX, posY = tempTable[a][1].getPosition()
- if massAndBooleanCheck((param_boolean == true), (posX < 0))[2] then
- resizeWindow(a, param_window, (posX + termX), posY)
- elseif massAndBooleanCheck((param_boolean == false), (posX > 0))[2] then
- resizeWindow(a, param_window, (posX - termX), posY)
- end
- tempTable[a][1].setVisible(param_boolean) tempTable[a][2].setVisible(param_boolean)
- end
- elseif screen == "term" then
- local posX, posY = tempTable["term"][1].getPosition()
- if massAndBooleanCheck((param_boolean == true), (posX < 0))[2] then
- resizeWindow("term", param_window, (posX + termX), posY)
- elseif massAndBooleanCheck((param_boolean == false), (posX >= 0))[2] then
- resizeWindow("term", param_window, (posX - termX), posY)
- end
- tempTable["term"][1].setVisible(param_boolean) tempTable["term"][2].setVisible(param_boolean)
- elseif screen == "monitor" then
- for a,b in pairs(tempTable) do
- if a ~= "term" then
- local posX, posY = tempTable[a][1].getPosition()
- if massAndBooleanCheck((param_boolean == true), (posX < 0))[2] then
- resizeWindow(a, param_window, (posX + termX), posY)
- elseif massAndBooleanCheck((param_boolean == false), (posX > 0))[2] then
- resizeWindow(a, param_window, (posX - termX), posY)
- end
- tempTable[a][1].setVisible(param_boolean) tempTable[a][2].setVisible(param_boolean)
- end end end end end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function switchWindowF(param_screen, param_window)
- local result, functionName, screen = {true, nil}, "switchWindowF", param_screen
- Debug("secondary", "debug: "..functionName)
- if variableCheck(functionName, {"string"}, {screen, param_window})[2] then
- screen = quickChoice(multiOrCompare(param_screen, "monitor", "monitor_touch")[2], "monitor", "both")[2]
- screen = quickChoice(multiOrCompare(param_screen, "term", "mouse_click")[2], "term", screen)[2]
- if booleanCheck(varList["stdWindows"][param_window])[1] then
- local currWindow = nil
- if screen == "both" then
- result[1] = quickChoice(activeWindow(screen, varList["currentWindow"]["monitor"], false)[2], result[1], false)[2]
- result[1] = quickChoice(activeWindow(screen, varList["currentWindow"]["term"], false)[2], result[1], false)[2]
- varList["currentWindow"] = {["term"] = param_window, ["monitor"] = param_window}
- result[1] = quickChoice(activeWindow(screen, varList["currentWindow"]["monitor"], true)[2], result[1], false)[2]
- result[1] = quickChoice(activeWindow(screen, varList["currentWindow"]["term"], true)[2], result[1], false)[2]
- else
- result[1] = quickChoice(activeWindow(screen, varList["currentWindow"][screen], false)[2], result[1], false)[2]
- varList["currentWindow"][screen] = param_window
- result[1] = quickChoice(activeWindow(screen, varList["currentWindow"][screen], true)[2], result[1], false)[2]
- end end end
- if not result[1] then console(stringCombine(true, "error: failed to switch window:", screen, param_window)[2], 2) end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function resizeWindowF(param_screen, param_window, param_x, param_y, param_x2, param_y2)
- local result, functionName = {false, false}, "resizeWindowF"
- Debug("secondary", "debug: "..functionName)
- if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_window, param_screen})[2], variableCheck(functionName, {"number"}, {param_x, param_y})[2])[2] then
- local tempTable = varList["stdWindows"][param_window][param_screen]
- local pos = {tempTable[2].getPosition()}
- if variableCheck(functionName, {"number"}, {param_x2, param_y2})[2] then
- tempTable[1].reposition(param_x, param_y, param_x2, param_y2)
- else
- tempTable[1].reposition(param_x, param_y)
- end
- tempTable[2].reposition(pos[1], pos[2]) result[1] = true
- tempTable[1].redraw() tempTable[2].redraw()
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function clearWindowF(param_window)
- local result, functionName = {false, nil}, "clearWindowF"
- Debug("secondary", "debug: "..functionName)
- if variableCheck(functionName, {"string"}, {param_window})[2] then
- for a,b in pairs(varList["stdWindows"][param_window]) do varList["stdWindows"][param_window][a][2].clear() end result[1] = true
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- addStdWindow("main", 1, 2, termX, termY - 1, true)
- addStdWindow("settings", 1, 2, termX, termY - 1, true)
- addStdWindow("control", 1, 2, termX, termY - 1, true)
- addStdWindow("console", 1, 2, termX, termY - 1, true)
- addStdWindow("monitorList", 1, 2, termX, termY - 1, false)
- addStdWindow("message", (termX / 2) - 10, (termX / 2) - 2, 20, 5, false)
- addStdWindow("scroll<", 1, 1, 3, 1, false, false)
- addStdWindow("topBar", 3, 1, (termX - 6), 1, false)
- addStdWindow("scroll>", (termX - 3), 1, 3, 1, false)
- monitorDetect()
- stdWindowsCreate()
- activeWindow("both", "console", true)
- activeWindow("both", "topBar", true)
- activeWindow("both", "scroll<", true)
- activeWindow("both", "scroll>", true)
- activeWindow("both", "console", true)
- console("marker - terminal windows setup complete")
- -----------------------------------------------------------------------------------------------------------
- -- CONSOLE/LOGS SETUP -- EMBEDED --
- -----------------------------------------------------------------------------------------------------------
- varList["logs"] = {["dir"] = "LOGS"}
- varList["logs"] = {
- ["dir"] = varList["logs"]["dir"],
- ["curr"] = varList["logs"]["dir"]..insertBS()..scriptName.."_CURRENT",
- ["prev"] = varList["logs"]["dir"]..insertBS()..scriptName.."_PREVIOUS",
- ["tableLoc"] = scriptName.."_LOGTABLE"
- }
- varList["logs"]["fileName"] = varList["logs"]["curr"]..insertBS()..scriptName.."_"..os.day().."_"..os.time()
- function consoleWriteF(param_text, param_error)
- local result, text, attachN, attachE, fileHandler, logLevel, functionName = {false, nil}, param_text:upper(), ">", "--", fs.open(varList["logs"]["fileName"], 'a'), "0", "consoleWriteF"
- if booleanCheck(param_error)[1] then
- if "number" == type(booleanCheck(param_error)[2]) then text, logLevel = attachE..param_error.." "..text, param_error else text = attachE..text end
- else
- text = attachN..text
- end
- fileHandler.writeLine(text) fileHandler.close()
- table.insert(logTable, {["text"] = text, ["logLevel"] = logLevel, ["time"] = os.day() .. ": " .. textutils.formatTime(os.time(), true)})
- local filehandler = fs.open(varList["logs"]["tableLoc"], 'w')
- filehandler.write(textutils.serialize(logTable))
- filehandler.close()
- local currentTerm = term.current()
- for a,b in pairs(varList["stdWindows"]["console"]) do term.redirect(varList["stdWindows"]["console"][a][2]) print(text) end
- term.redirect(currentTerm)
- result[1] = true
- return result
- end
- function logSetupF()
- local result, functionName = {false, nil}, "logSetupF"
- Debug("secondary", "debug: "..functionName)
- if fs.exists(varList["logs"]["dir"]) then
- local list = fs.list(varList["logs"]["curr"])
- if booleanCheck(list[1])[1] then
- if fs.exists(varList["logs"]["prev"]..insertBS()..list[1]) then fs.delete(varList["logs"]["prev"]..insertBS()..list[1]) end
- fs.copy(varList["logs"]["curr"]..insertBS()..list[1], varList["logs"]["prev"]..insertBS()..list[1])
- fs.delete(varList["logs"]["curr"]..insertBS()..list[1])
- end
- result[1] = true
- else
- fs.makeDir(varList["logs"]["dir"]) fs.makeDir(varList["logs"]["curr"]) fs.makeDir(varList["logs"]["prev"])
- result[1] = true
- end
- local fileHandler = fs.open(varList["logs"]["fileName"], 'a')
- for a,b in pairs(logTable) do fileHandler.writeLine(logTable[a]["text"], logTable[a]["logLevel"]) end
- fileHandler.close()
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- logSetup()
- console("marker - console/logs setup complete")
- -----------------------------------------------------------------------------------------------------------
- -- WRITING FUNCTIONS -- EMBEDED --
- -----------------------------------------------------------------------------------------------------------
- function selectColorF(param_screenLoc, param_screen, param_textColor, param_backColor)
- local result, textColor, backColor, functionName = {false, nil}, param_textColor or colors.white, param_backColor or colors.black, "selectColorF"
- local screen = quickChoice(param_screenLoc ~= "term", varList["stdWindows"][param_screenLoc][param_screen][2], term)[2]
- Debug("secondary", "debug: "..functionName)
- if not booleanCheck(screen.isColor())[2] then
- backColor, textColor = quickChoice((backColor ~= colors.black), colors.white, colors.black)[2], quickChoice((backColor ~= colors.black), colors.black, colors.white)[2]
- end
- result[1] = massAndBooleanCheck(screen.setTextColor(textColor), screen.setBackgroundColor(backColor))[2]
- result[2] = quickChoice(massOrBooleanCheck(screen.getBackgroundColor() ~= backColor, screen.getTextColor() ~= textColor)[2], false, true)[2]
- if not result[1] then console(stringCombine(true, "error: failed setTextColor or setBackgroundColor:", param_textColor, param_backColor)[2], 2) end
- if not result[2] then console(stringCombine(true, "error: failed to choose wanted colors")[2], 1) end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- -- screenWrite(term.native(), "hello world":upper(), 5, 3, colors.red, colors.black) -- Writes to a single specified window
- function screenWriteF(param_screenLoc, param_screen, param_text, param_x, param_y, param_textColor, param_backColor)
- local screen, result, functionName = varList["stdWindows"][param_screenLoc][param_screen][2], {false, nil}, "screenWriteF"
- Debug("secondary", "debug: "..functionName)
- if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_text})[2], variableCheck(functionName, {"number"}, {param_x, param_y})[2])[2] then
- result[1] = true
- screen.setCursorPos(param_x, param_y)
- result[1] = quickChoice(selectColor(param_screenLoc, param_screen, param_textColor, param_backColor)[1], result[1], false)[2]
- screen.write(param_text)
- result[1] = quickChoice(selectColor(param_screenLoc, param_screen)[1], result[1], false)[2]
- screen.redraw() varList["stdWindows"][param_screenLoc][param_screen][1].redraw()
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- -- windowWrite("console", "hello world":upper(), 5, 3, colors.red, colors.black) -- Writes to all windows of the same type
- function windowWriteF(param_window, param_text, param_x, param_y, param_textColor, param_backColor)
- local result, functionName = {false, nil}, "windowWriteF"
- Debug("secondary", "debug: "..functionName)
- if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_window, param_text})[2], variableCheck(functionName, {"number"}, {param_x, param_y})[2])[2] then
- result[1] = true
- for a,b in pairs(varList["stdWindows"][param_window]) do result[1] = quickChoice(screenWrite(param_window, a, param_text, param_x, param_y, param_textColor, param_backColor)[1], result[1], false)[2] end
- end
- if not result[1] then console(stringCombine(true, "error: failed windowWrite():", param_window, param_text)[2], 2) end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function backgroundColorF(param_window, param_x, param_y, param_length, param_height, param_backColor)
- local result, functionName, text, y = {false, nil}, "backgroundColorF", nil, param_y
- Debug("secondary", "debug: "..functionName)
- if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_window})[2], variableCheck(functionName, {"number"}, {param_x, param_y, param_length, param_height})[2])[2] then
- for num=1,param_length do text = quickChoice(booleanCheck(text)[1], text.." ", " ")[2] end
- for num=1,param_height do windowWrite(param_window, text, param_x, y, colors.white, param_backColor) y = y + 1 end
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- console("marker - text functions setup complete")
- -----------------------------------------------------------------------------------------------------------
- -- BUTTON FUNCTIONS -- EMBEDED --
- -----------------------------------------------------------------------------------------------------------
- varList["buttons"], varList["buttonTimer"], varList["redstoneTimer"] = {}, {}, {}
- function generateButtonF(param_button, param_window)
- local result, functionName = {false, nil}, "generateButtonF"
- Debug("secondary", "debug: "..functionName)
- if variableCheck(functionName, {"string"}, {param_button, param_window})[2] then
- local tempTable, window = varList["buttons"][param_window], param_window
- tempTable = quickChoice(booleanCheck(tempTable[param_button])[1], booleanCheck(tempTable[param_button])[2], false)[2]
- if type(tempTable) == "table" then
- console(stringCombine(true, "command - generateButton():", param_button, param_window)[2])
- if window == "topBar" then tempTable["active"] = quickChoice(multiOrCompare(param_button, varList["currentWindow"]["term"], varList["currentWindow"]["monitor"])[2], true, false)[2] end
- local backColor = quickChoice(tempTable["active"], colors.green, colors.red)[2]
- result[1] = windowWrite(window, tempTable["displayName"]:upper(), tempTable["loc"]["x"], tempTable["loc"]["y"], colors.white, backColor)[1]
- end
- end
- if not result[1] then console(stringCombine(true, "error: failed generateButton():", param_button, param_window)[2], 2) end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function stdPulseF(param_name, param_window)
- local name, window, result, functionName = booleanCheck(param_name)[2], booleanCheck(param_window)[2], {false, nil}, "stdPulseF"
- Debug("secondary", "debug: "..functionName)
- if variableCheck(functionName, {"string"}, {name, window})[2] then
- local tempTable = varList["buttons"][window][name]
- if not tempTable["active"] then
- varList["buttonTimer"][os.startTimer(tempTable["timer"])], result[1] = {["name"] = name, ["window"] = window}, true
- end
- varList["buttons"][window][name]["active"] = not tempTable["active"]
- os.queueEvent("buttonRedraw", name, window)
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function stdToggleF(param_name, param_window)
- local result, name, window, functionName = {false, nil}, booleanCheck(param_name)[2], booleanCheck(param_window)[2], "stdToggleF"
- Debug("secondary", "debug: "..functionName)
- if variableCheck(functionName, {"string"}, {name, window})[2] then
- local tempTable = varList["buttons"][window][name]
- if booleanCheck(varList["settings"][tostring(tempTable["act"]["args"])])[1] then varList["settings"][tempTable["act"]["args"]] = quickChoice(varList["settings"][tempTable["act"]["args"]], false, true)[2] end
- varList["buttons"][window][name]["active"] = not tempTable["active"]
- os.queueEvent("buttonRedraw", name, window)
- result[1] = true
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function monitorToggleF(param_name, param_window)
- local result, functionName = {false, nil}, "monitorToggleF"
- Debug("secondary", "debug: "..functionName)
- if variableCheck(functionName, {"string"}, {param_name, param_window})[2] then
- varList["monitorList"][param_name]["active"] = quickChoice(varList["monitorList"][param_name]["active"], false, true)[2]
- varList["buttons"]["monitorList"][param_name]["active"] = varList["monitorList"][param_name]["active"]
- os.queueEvent("buttonRedraw", param_name, param_window)
- result[1] = true
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function dataChangeF(param_name, param_window)
- local result, name, window, functionName = {false, nil}, booleanCheck(param_name)[2], booleanCheck(param_window)[2], "dataChangeF"
- Debug("secondary", "debug: "..functionName)
- if variableCheck(functionName, {"string"}, {name, window})[2] then
- local tempTable = varList["buttons"][window][name]
- local tempVar = quickChoice(booleanCheck(varList["settings"][tempTable["originalName"]])[1], varList["settings"][tempTable["originalName"]], false)[2]
- if massAndBooleanCheck((tempTable["args"] == "insert"), (type(varList["settings"]["originalName"]) == "string"))[2] then
- os.queueEvent("insertWindow", param_name, param_window)
- result[1] = true
- elseif tempTable["args"] == "<" then
- result[1], varList["settings"][tempTable["originalName"]] = true, quickChoice((type(tempVar) == "boolean"), not tempVar, tempVar)[2]
- result[1], varList["settings"][tempTable["originalName"]] = true, quickChoice((type(tempVar) == "number"), tempVar - 1, tempVar)[2]
- elseif tempTable["args"] == ">" then
- result[1], varList["settings"][tempTable["originalName"]] = true, quickChoice((type(tempVar) == "boolean"), not tempVar, tempVar)[2]
- result[1], varList["settings"][tempTable["originalName"]] = true, quickChoice((type(tempVar) == "number"), tempVar + 1, tempVar)[2]
- end
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- --addButtonF(param_name, param_window, param_buttonType, param_active, {param_x, param_y}, {param_action, param_args}, param_time, {param_redstone, param_dir, param_invert}, param_displayname)
- function addButtonF(param_name, param_window, param_buttonType, param_active, param_location, param_action, param_time, param_redstone, param_displayname)
- local result, active, functionName, display = {false, nil}, booleanCheck(param_active)[2], "addButtonF", quickChoice((tostring(param_displayName) ~= "nil"), param_displayName, param_name)[2]
- Debug("secondary", "debug: "..functionName)
- if massAndBooleanCheck(
- variableCheck(functionName, {"string"}, {param_window, param_name, param_buttonType})[2],
- variableCheck(functionName, {"number"}, param_location)[2]
- -- variableCheck(functionName, {"boolean"}, {param_redstone[1], param_redstone[3]})[2],
- -- multiOrCompare(param_redstone[2], "left", "right", "top", "bottom", "front", "back", "up", "down")[2]
- )[2] then
- local length, param_x, param_y = string.len(" "..param_name.." "), param_location[1], param_location[2]
- if not booleanCheck(varList["buttons"][param_window])[1] then varList["buttons"][param_window] = {} end
- if param_buttonType == "toggle" then
- local action, args, Time = quickChoice(booleanCheck(param_action[1])[1], param_action[1], stdToggle)[2], booleanCheck(param_action[2])[2], quickChoice(variableCheck(functionName, {"number"}, {booleanCheck(param_time)[2]})[2], booleanCheck(param_time)[2], 0.1)[2]
- varList["buttons"][param_window][param_name] = {
- ["displayName"] = " "..display.." ",
- ["buttonType"] = "toggle",
- ["act"] = {["act"] = action, ["args"] = args, ["togAct"] = action, ["togArgs"] = args},
- ["active"] = active,
- ["orig_active"] = active,
- ["loc"] = {["x"] = param_x, ["origX"] = param_x, ["y"] = param_y, ["length"] = length},
- ["originalName"] = param_name,
- ["timer"] = Time,
- ["redstone"] = {["redstone"] = param_redstone[1] or false, ["dir"] = booleanCheck(param_redstone[2])[2], ["invert"] = param_redstone[3] or false}
- }
- result[1] = true
- elseif param_buttonType == "increment" then
- varList["buttons"][param_window][param_name.."_decrease"] = {
- ["displayName"] = "< ",
- ["buttonType"] = "increment",
- ["act"] = {["act"] = dataChange, ["args"] = "<", ["togAct"] = dataChange, ["togArgs"] = "<"},
- ["active"] = active,
- ["orig_active"] = active,
- ["loc"] = {["x"] = param_x, ["origX"] = param_x, ["y"] = param_y, ["length"] = 2},
- ["originalName"] = param_name,
- ["timer"] = Time,
- ["redstone"] = {["redstone"] = param_redstone[1] or false, ["dir"] = booleanCheck(param_redstone[2])[2], ["invert"] = param_redstone[3] or false}
- }
- varList["buttons"][param_window][param_name.."_insert"] = {
- ["displayName"] = " "..display.." ",
- ["buttonType"] = "increment",
- ["act"] = {["act"] = dataChange, ["args"] = "insert", ["togAct"] = dataChange, ["togArgs"] = "insert"},
- ["active"] = active,
- ["orig_active"] = active,
- ["loc"] = {["x"] = param_x + 2, ["origX"] = param_x + 2, ["y"] = param_y, ["length"] = length},
- ["originalName"] = param_name,
- ["timer"] = Time,
- ["redstone"] = {["redstone"] = param_redstone[1] or false, ["dir"] = booleanCheck(param_redstone[2])[2], ["invert"] = param_redstone[3] or false}
- }
- varList["buttons"][param_window][param_name.."_increase"] = {
- ["displayName"] = " >",
- ["buttonType"] = "increment",
- ["act"] = {["act"] = dataChange, ["args"] = ">", ["togAct"] = dataChange, ["togArgs"] = ">"},
- ["active"] = active,
- ["orig_active"] = active,
- ["loc"] = {["x"] = param_x + 2 + length, ["origX"] = param_x + 2 + length, ["y"] = param_y, ["length"] = 2},
- ["originalName"] = param_name,
- ["timer"] = Time,
- ["redstone"] = {["redstone"] = param_redstone[1] or false, ["dir"] = booleanCheck(param_redstone[2])[2], ["invert"] = param_redstone[3] or false}
- }
- result[1] = true
- elseif param_buttonType == "insert" then
- varList["buttons"][param_window][param_name] = {
- ["displayName"] = " "..display.." ",
- ["buttonType"] = "insert",
- ["act"] = {["act"] = dataChange, ["args"] = "insert", ["togAct"] = dataChange, ["togArgs"] = "insert"},
- ["active"] = active,
- ["orig_active"] = active,
- ["loc"] = {["x"] = param_x, ["origX"] = param_x, ["y"] = param_y, ["length"] = length},
- ["originalName"] = param_name,
- ["timer"] = Time,
- ["redstone"] = {["redstone"] = param_redstone[1] or false, ["dir"] = booleanCheck(param_redstone[2])[2], ["invert"] = param_redstone[3] or false}
- }
- result[1] = true
- elseif param_buttonType == "pulse" then
- local action, args, Time = quickChoice(booleanCheck(param_action)[1], booleanCheck(param_action)[2], stdPulse)[2], booleanCheck(param_args)[2], quickChoice(variableCheck(functionName, {"number"}, {booleanCheck(param_time)[2]})[2], booleanCheck(param_time)[2], 0.1)[2]
- varList["buttons"][param_window][param_name] = {
- ["displayName"] = " "..display.." ",
- ["buttonType"] = "pulse",
- ["act"] = {["act"] = action, ["args"] = args, ["togAct"] = action, ["togArgs"] = args},
- ["active"] = active,
- ["orig_active"] = active,
- ["loc"] = {["x"] = param_x, ["origX"] = param_x, ["y"] = param_y, ["length"] = length},
- ["originalName"] = param_name,
- ["timer"] = Time,
- ["redstone"] = {["redstone"] = param_redstone[1] or false, ["dir"] = booleanCheck(param_redstone[2])[2], ["invert"] = param_redstone[3] or false}
- }
- result[1] = true
- end
- end
- if not result[1] then console(stringCombine(true, "error: failed to add button:", param_name, param_window, param_buttonType, param_x, param_y, param_action, param_args, param_actionTog, param_argTog)[2]) end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function monitorListApplyF(param_name, param_window)
- local result, functionName = {false, nil}, "monitorListApplyF"
- Debug("secondary", "debug: "..functionName)
- if variableCheck(functionName, {"string"}, {param_name, param_window}) then
- monitorSetScale()
- stdWindowsCreate()
- generateAllButtons()
- switchWindow("term", "control")
- result[1] = true
- end
- if not result[1] then console(stringCombine(true, "error: failed to generate window:", window)[2], 2) end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function addMonitorListButtonsF()
- varList["buttons"]["monitorList"] = {}
- local result, loc_x, loc_y, functionName = {false, nil}, 2, 2, "addMonitorListButtonsF"
- Debug("secondary", "debug: "..functionName)
- result[1] = addButton("apply", "monitorList", "pulse", false, {loc_x, loc_y}, {monitorListApply, "apply"}, "nil", {nil, nil, nil}, "apply")[1]
- for a,b in pairs(varList["monitorList"]) do
- if a ~= "terminal" then
- loc_y = loc_y + 2
- result[1] = quickChoice(addButton(varList["monitorList"][a]["name"], "monitorList", "toggle", varList["monitorList"][a]["active"], {loc_x, loc_y}, {monitorToggle, varList["monitorList"][a]["name"]}, nil, {nil, nil, nil}, varList["monitorList"][a]["name"])[1], result[1], false)[2]
- end end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function generateWindowButtonsF(param_window)
- local result, window, functionName = {true, nil}, nil, "generateWindowButtonsF"
- if variableCheck(functionName, {"string"}, {param_window})[2] then
- window = quickChoice(booleanCheck(varList["buttons"][param_window])[1], param_window, "update")[2]
- else
- window = "update"
- end
- console(stringCombine(true, "command - start generateWindowButtons():", param_window)[2])
- if window ~= "update" then
- for a,b in pairs(varList["buttons"][window]) do result[1] = quickChoice(generateButton(a, window)[1], result[1], false)[2] end
- else
- for a,b in pairs(varList["buttons"][varList["currentWindow"]["term"]]) do result[1] = quickChoice(generateButton(a, varList["currentWindow"]["term"])[1], result[1], false)[2] end
- for a,b in pairs(varList["buttons"][varList["currentWindow"]["monitor"]]) do result[1] = quickChoice(generateButton(a, varList["currentWindow"]["monitor"])[1], result[1], false)[2] end
- end
- if not result[1] then console(stringCombine(true, "error: failed to generate window:", window)[2], 2) end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function generateAllButtonsF()
- local result, functionName = {true, nil}, "generateAllButtonsF"
- console("command - start generateAllButtons()")
- for a,b in pairs(varList["buttons"]) do result[1] = quickChoice(generateWindowButtons(a)[1], result[1], false)[2] end
- if not result[1] then console("error: failed @ generateAllButtonsF", 2) end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function updateButtonF(...)
- local result, functionName = {false, false}, "updateButtonF"
- os.queueEvent("update")
- stdPulse(...)
- result = {true, true}
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function startupScriptF(param_name, param_window)
- local functionName, result, outputFile = "startupScriptF", {false, false}, io.open("startup", "w")
- local startupWrite = {
- "if fs.exists(\"startupTrue\") then\n",
- " sleep(0.5)\n",
- " shell.run(\"",
- shell.getRunningProgram(),
- "\")\n",
- "end"
- }
- stdToggle(param_name, param_window)
- if varList["buttons"][param_window][param_name]["active"] then
- local outputFile = io.open("startup", "w")
- result[2] = true
- for a,b in pairs(startupWrite) do result[2] = quickChoice(outputFile:write(b), result[2], false)[2] end
- outputFile:close()
- fs.makeDir("startupTrue")
- if tonumber(os.version()) >= 1.78 then settings.set("shell.allow_startup", true) end
- else
- result[2] = true
- result[2] = quickChoice(fs.delete("startup"), result[2], false)[2]
- result[2] = quickChoice(fs.delete("startupTrue"), result[2], false)[2]
- end
- if result[2] then result[1] = true end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function monitorListWindowF(param_name, param_window)
- local functionName, result = "monitorListWindowF", {false, false}
- stdPulse(param_name, param_window)
- switchWindow("term", "monitorList")
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function restartF(param_name, param_window)
- local functionName, result = "restartF", {false, false}
- stdPulse(param_name, param_window)
- os.queueEvent("restart")
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function terminateF(param_name, param_window)
- local functionName, result = "terminateF", {false, false}
- stdPulse(param_name, param_window)
- os.queueEvent("terminate")
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- --addButtonF(param_name, param_window, param_buttonType, param_active, {param_x, param_y}, {param_action, param_args}, param_time, {param_redstone, param_dir, param_invert}, param_displayname)
- function stdButtonsF()
- local result, functionName = {false, false}, "stdButtonsF"
- addMonitorListButtons()
- result[2] = quickChoice(addButton("update", "control", "pulse", false, {2, 3}, {updateButton, "nil"}, 5, {nil, nil, nil}, "update")[2], true, false)[2]
- result[2] = quickChoice(addButton("startup", "control", "toggle", fs.exists("startup"), {2, 5}, {startupScript, "nil"}, 5, {nil, nil, nil}, "update")[2], result[2], false)[2]
- result[2] = quickChoice(addButton("monitor list", "control", "pulse", false, {2, 7}, {monitorListWindowF, "nil"}, 5, {nil, nil, nil}, "monitor list")[2], result[2], false)[2]
- result[2] = quickChoice(addButton("restart", "control", "pulse", false, {2, 9}, {restart, "nil"}, 5, {nil, nil, nil}, "restart")[2], result[2], false)[2]
- result[2] = quickChoice(addButton("terminate", "control", "pulse", false, {2, 11}, {terminate, "nil"}, 5, {nil, nil, nil}, "terminate")[2], result[2], false)[2]
- result[1] = quickChoice(result[2], true, false)[2]
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- stdButtons()
- console("marker - button functions setup complete")
- -----------------------------------------------------------------------------------------------------------
- -- TOPBAR SETUP -- EMBEDED --
- -----------------------------------------------------------------------------------------------------------
- --local scroll, topBarLength = 0, 0
- varList["scroll"], varList["topBarLength"] = 1, 0
- function topBarScrollF(param_arg)
- local arg, result, functionName = booleanCheck(param_arg)[2], {false, nil}, "topBarScrollF"
- if variableCheck(functionName, {"string"}, {arg})[2] then
- if massAndBooleanCheck((arg == ">"), (varList["topBarLength"] > ((-1 * varList["scroll"]) + termX - 6)))[2] then
- varList["scroll"] = varList["scroll"] - 10
- elseif massAndBooleanCheck((arg == "<"), (varList["scroll"] ~= 1))[2] then
- varList["scroll"] = varList["scroll"] + 10
- end
- local tempList = varList["buttons"]["topBar"]
- for a,b in pairs(varList["buttons"]["topBar"]) do varList["buttons"]["topBar"][a]["loc"]["x"] = quickChoice((varList["scroll"] < -5), (tempList[a]["loc"]["origX"] - varList["scroll"]), tempList[a]["loc"]["origX"])[2] end
- result[1] = true
- end
- clearWindow("topBar")
- generateWindowButtons("topBar")
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function topBarChangeF(param_screen, param_window)
- local screen, result, functionName = quickChoice((param_screen == "monitor_touch"), "monitor", "term")[2], {false, nil}, "topBarChangeF"
- if variableCheck(functionName, {"string"}, {param_screen, param_window})[2] then
- result = switchWindow(param_screen, param_window)
- generateWindowButtons("topBar")
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function topBarButtonsF()
- local result, functionName, x, offset = {false, false}, "topBarButtonsF", 1, string.len(" < ")
- result[2] = quickChoice(addButton("<", "scroll<", "pulse", false, {1, 1}, {topBarScroll, "<"}, 5, {nil, nil, nil}, "scroll<"), true, false)[2]
- result[2] = quickChoice(addButton(">", "scroll>", "pulse", false, {termX - 3, 1}, {topBarScroll, ">"}, 5, {nil, nil, nil}, "scroll>"), result[2], false)[2]
- for a,b in pairs(varList["stdWindowsData"]) do
- if varList["stdWindowsData"][a]["topBar"] then
- result[2] = quickChoice(addButton(a, "topBar", "toggle", false, {offset, 1}, {topBarChange, a}, 5, {nil, nil, nil}, a), result[2], false)[2]
- offset = offset + string.len(" "..a.." ")
- end
- end
- result[1] = result[2]
- varList["topBarLength"] = offset
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function buttonScanF(param_screen, param_X, param_Y)
- local result, screen, functionName, tempTable = {false, false}, param_screen, "buttonScanF", {}
- if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_screen})[2], variableCheck(functionName, {"number"}, {param_X, param_Y})[2])[2] then
- if param_Y == 1 then
- if tolerance(varList["buttons"]["scroll>"][">"]["loc"]["x"], param_X, varList["buttons"]["scroll>"][">"]["loc"]["length"], 0)[2] or tolerance(varList["buttons"]["scroll<"]["<"]["loc"]["x"], param_X, varList["buttons"]["scroll<"]["<"]["loc"]["length"], 0)[2] then
- console("scrolls selected")
- if tolerance(varList["buttons"]["scroll<"]["<"]["loc"]["x"], param_X, varList["buttons"]["scroll<"]["<"]["loc"]["length"], 0)[2] then
- result[2] = topBarScroll("<")[1]
- elseif tolerance(varList["buttons"]["scroll>"][">"]["loc"]["x"], param_X, varList["buttons"]["scroll>"][">"]["loc"]["length"], 0)[2] then
- result[2] = topBarScroll(">")[1]
- end
- else
- console("switch windows selected")
- for a,b in pairs(varList["buttons"]["topBar"]) do
- tempTable = varList["buttons"]["topBar"][a]
- result[2] = quickChoice(massAndBooleanCheck((tempTable["loc"]["y"] == param_Y), tolerance(tempTable["loc"]["x"], param_X, tempTable["loc"]["length"], 0)[2])[2], a, result[2])[2]
- end
- if result[2] ~= false then varList["buttons"]["topBar"][result[2]]["act"]["act"](screen, result[2]) console(stringCombine(false, "-", result[2], "-")[2]) end
- end
- else
- console("buttons selected")
- screen = quickChoice(multiOrCompare(param_screen, "monitor", "monitor_touch")[2], "monitor", screen)[2]
- screen = quickChoice(multiOrCompare(param_screen, "term", "mouse_click")[2], "term", screen)[2]
- console(screen)
- if booleanCheck(varList["buttons"][varList["currentWindow"][screen]])[1] then
- for a,b in pairs(varList["buttons"][varList["currentWindow"][screen]]) do
- tempTable = varList["buttons"][varList["currentWindow"][screen]][a]
- result[2] = quickChoice(massAndBooleanCheck((tempTable["loc"]["y"] == param_Y), tolerance(tempTable["loc"]["x"], param_X, tempTable["loc"]["length"], 0)[2])[2], a, result[2])[2]
- end
- end
- if result[2] ~= false then console(stringCombine(true, "Button found:", result[2], screen)[2]) varList["buttons"][varList["currentWindow"][screen]][result[2]]["act"]["act"](result[2], varList["currentWindow"][screen]) end
- end
- end
- if result[2] ~= false then result[1] = true end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- topBarButtons()
- generateAllButtons()
- console("Marker - topBar functions setup complete")
- -----------------------------------------------------------------------------------------------------------
- -- SECONDARY FUNCTIONS -- EMBEDED --
- -----------------------------------------------------------------------------------------------------------
- -- event = eventFilter("timer", "monitor_touch", "mouse_click", "key", "etc") .. returns a table only when the event matches the arg --
- function eventFilterF(...)
- local tempList, whitelist, result, text, functionName, blacklisted = {...}, {}, {false, false}, "eventFilter:", "eventFilterF", {"eventFilter Blacklisted:"}
- for a,b in pairs(tempList) do whitelist[b] = true end
- while not result[1] do
- result[2] = {os.pullEvent()}
- if booleanCheck(whitelist[result[2][1]])[2] == false then
- table.insert(blacklisted, result[2][1])
- Debug(stringCombine(true, "debug", functionName, "blacklist:", result[2])[2])
- else
- result[1] = true
- end
- end
- console(stringCombine(true, text, result[2])[2])
- console(stringCombine(true, blacklisted)[2])
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function insertWindowF(param_name, param_window)
- local result, functionName, active, event, text, writing, upperCase, shiftKey, capsLock, currWindow = {false, false}, "insertWindowF", true, nil, {}, false, false, false, false, varlist["currentWindow"]["term"]
- if variableCheck(functionName, {"string"}, {param_name, param_window})[2] then
- clearWindow("message")
- backgroundColor("message", 1, 1, termX, termY, colors.blue)
- switchWindow("term", "message")
- local tempTable = varList["buttons"][param_window][param_name]
- local tempVar = quickChoice(booleanCheck(varList["settings"][tempTable["originalName"]])[1], varList["settings"][tempTable["originalName"]], false)[2]
- resultType = type(tempVar) == "boolean"
- windowWrite("message", "ENTER VARIABLE:", (termX / 2) - 9, (termY / 2) - 1, colors.white, colors.blue)
- writing = true
- while writing do
- event = eventFilter("char", "key")[2]
- if event[1] == "char" then
- table.insert(text, event[2])
- elseif keys.getName(event[2]) == "enter" then
- writing = false
- elseif keys.getName(event[2]) == "backspace" then
- if booleanCheck(text[1])[1] then text[table.maxn(text)] = nil end
- end
- backgroundColor("message", 1, (termX / 2) + 1, termX, 1, colors.blue)
- windowWrite("message", stringCombine(false, text)[2], (termX / 2) - 9, (termY / 2) + 1, colors.white, colors.blue)
- end
- text = quickChoice(booleanCheck(text[1])[1], stringCombine(false, text)[2], nil)[2]
- if massAndBooleanCheck(resultType == "boolean", multiAndCompare(tostring(text):lower(), "true", "false", "t", "f", "1", "0", "+", "-")[2])[2] then
- result = {true, quickChoice(multiAndCompare(text:lower(), "true", "t", "1", "+")[2], true, false)[2]}
- elseif massAndBooleanCheck(resultType == "number", booleanCheck(tonumber(text))[1])[2] then
- result = {true, tonumber(text)}
- elseif resultType == "string" and booleanCheck(text)[1] then
- result = {true, text}
- end
- if result[1] then
- varList["settings"][tempTable["originalName"]] = result[2]
- else
- os.queueEvent("messageWindow", stringCombine(true, "Error:", resultType, "expected")[2], 2)
- end
- switchWindow("term", currWindow)
- clearWindow("message")
- backgroundColor("message", 1, 1, termX, termY, colors.blue)
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function messageWindowF(param_event, param_text, param_currWindowTerm, param_currWindowMon)
- local result, functionName = {false, false}, "messageWindowF"
- if variableCheck(functionName, {"string"}, {param_event, param_text})[2] then
- if param_event == "messageWindow" then
- clearWindow("message") backgroundColor("message", 1, 1, termX, termY, colors.blue)
- windowWrite("message", param_text, ((termX / 2) - (string.len(param_text) / 2)), (termY / 2), colors.white, colors.blue)
- switchWindow("both", "message")
- elseif param_event == "timer" then
- switchWindow("term", param_currWindowTerm) switchWindow("monitor", param_currWindowMon)
- clearWindow("message") backgroundColor("message", 1, 1, termX, termY, colors.blue)
- end
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function peripheralListRegisterSingleF(param_listName)
- local result, functionName, tempList = {false, false}, "peripheralListRegisterSingleF", false
- if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_listName})[2], booleanCheck(varList["peripheralList"][param_listName])[1])[2] then
- varList["peripheralList"][param_listName]["peripherals"] = {}
- for a,b in pairs(varList["peripheralList"][param_listName]["mode"]) do
- tempList = peripheralFind(b, varList["peripheralList"][param_listName]["variables"][a])[2]
- if booleanCheck(tempList)[2] ~= false then
- for c,d in pairs(tempList) do
- local duplicate = false
- for e,f in pairs(varList["peripheralList"][param_listName]["peripherals"]) do duplicate = quickChoice(d == f, true, duplicate)[2] end
- if not duplicate then table.insert(varList["peripheralList"][param_listName]["peripherals"], d) result[1] = true end
- end
- end end
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function peripheralListRegisterMultiF()
- local result, functionName = {false, false}, "peripheralListRegisterMultiF"
- for a,b in pairs(varList["peripheralList"]) do
- peripheralListRegisterSingle(a) result[1] = true
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- function peripheralListAddF(param_tableName, param_mode, param_variable)
- local result, functionName = {false, false}, "peripheralListAddF"
- if massAndBooleanCheck(variableCheck(functionName, {"string"}, {param_tableName, param_mode})[2], variableCheck(functionName, {"table"}, {param_variable})[2], multiOrCompare(param_mode, "type", "method")[2])[2] then
- varList["peripheralList"] = quickChoice(booleanCheck(varList["peripheralList"])[1], varList["peripheralList"], {})[2]
- varList["peripheralList"][param_tableName] = quickChoice(booleanCheck(varList["peripheralList"][param_tableName])[1], varList["peripheralList"][param_tableName], {["peripherals"] = {}, ["mode"] = {}, ["variables"] = {}})[2]
- table.insert(varList["peripheralList"][param_tableName]["mode"], param_mode)
- table.insert(varList["peripheralList"][param_tableName]["variables"], param_variable)
- peripheralListRegisterSingle(param_tableName)
- end
- Debug("secondary", "debug: "..functionName.." returned "..tostring(result[1]))
- return result
- end
- console("Marker - SECONDARY FUNCTIONS functions setup complete")
- -----------------------------------------------------------------------------------------------------------
- -- COROUTINE FUNCTIONS -- EMBEDED --
- -----------------------------------------------------------------------------------------------------------
- coroutineControl = {["function"] = {}, ["driver"] = {}, ["coroutine"] = {}}
- do
- coroutineControl["function"]["yielder"] = function()
- sleep(0.5)
- os.queueEvent("start")
- return
- end
- coroutineControl["function"]["resize"] = function()
- local event, x = nil, 0
- while true do
- event = eventFilter("monitor_resize")[2]
- x = x + 1
- console("clearing resize"..x)
- end end
- coroutineControl["function"]["buttonScan"] = function()
- local event = nil
- while true do
- event = eventFilter("monitor_touch", "mouse_click")[2]
- buttonScan(event[1], event[3], event[4])
- end end
- coroutineControl["function"]["buttonRedraw"] = function()
- local event = nil
- while true do
- event = eventFilter("buttonRedraw")[2]
- generateButton(event[2], event[3])
- end end
- coroutineControl["function"]["buttonReset"] = function()
- local event, tempTable = nil, nil
- while true do
- event = eventFilter("timer")[2]
- tempTable = booleanCheck(varList["buttonTimer"][event[2]])[2]
- if tempTable ~= false then
- varList["buttons"][tempTable["window"]][tempTable["name"]]["act"]["act"](tempTable["name"], tempTable["window"])
- varList["buttonTimer"][event[2]] = nil
- end end end
- coroutineControl["function"]["redstoneControl"] = function()
- local event = nil
- while true do
- event = eventFilter("timer", "redstone", "monitor_touch", "mouse_click")[2]
- if booleanCheck(varList["redstoneTimer"][event[2]])[2] ~= false then
- generateButton(varList["redstoneTimer"][event[2]]["name"], varList["redstoneTimer"][event[2]]["window"])
- varList["redstoneTimer"][event[2]] = false
- end end end
- coroutineControl["function"]["osControl"] = function()
- local event = nil
- while true do
- event = eventFilter("update", "restart", "terminate")[2]
- if event[1] == "update" then
- update(shell.getRunningProgram(), pastebinCode)
- elseif event[1] == "restart" then
- os.reboot()
- elseif event[1] == "terminate" then
- fs.delete("startupTrue")
- os.reboot()
- end
- end end
- coroutineControl["function"]["peripherialControl"] = function()
- local event = nil
- while true do
- event = eventFilter("peripheral", "peripheral_detach")[2]
- peripheralListRegisterMultiF()
- end end
- coroutineControl["function"]["insertWindow"] = function()
- local event = nil
- while true do
- event = eventFilter("insertWindow")[2]
- insertWindow(event[2], event[3])
- end end
- coroutineControl["function"]["messageWindow"] = function()
- local event, timer, currWindowTerm, currWindowMon = nil, nil, nil, nil
- while true do
- event = eventFilter("messageWindow", "timer")[2]
- currWindowTerm = quickChoice(varList["currentWindow"]["term"] ~= "message", varList["currentWindow"]["term"], currWindowTerm)[2]
- currWindowMon = quickChoice(varList["currentWindow"]["monitor"] ~= "message", varList["currentWindow"]["monitor"], currWindowMon)[2]
- timer = quickChoice(event[1] == "message", os.startTimer(event[3]), timer)[2]
- if massAndBooleanCheck(event[1] == "timer", timer == event[2])[2] or event[1] == "message" then messageWindow(event[1], event[2], currWindowTerm, currWindowMon) end
- end end
- coroutineControl["function"]["save"] = function()
- local event = nil
- while true do
- event = os.pullEvent()
- tempTable = booleanCheck(varList["buttonTimer"][event[2]])[2]
- if tempTable ~= false then
- varList["buttons"][tempTable["window"]][tempTable["name"]]["act"]["act"](tempTable["name"], tempTable["window"])
- varList["buttonTimer"][event[2]] = nil
- end end end
- end
- -----------------------------------------------------------------------------------------------------------
- -- COROUTINE COROUTINES -- EMBEDED --
- -----------------------------------------------------------------------------------------------------------
- for a,b in pairs(coroutineControl["function"]) do coroutineControl["coroutine"][a] = coroutine.create(b) end
- -----------------------------------------------------------------------------------------------------------
- -- COROUTINE DRIVERS -- EMBEDED --
- -----------------------------------------------------------------------------------------------------------
- for a,b in pairs(coroutineControl["coroutine"]) do
- coroutineControl["driver"][a] = function() -- coroutine driver in parallel
- local r, tFilter, eventData = b, nil, {}
- while true do
- if r then
- if tFilter == nil or tFilter == eventData[1] or eventData[1] == "terminate" then
- local ok, param = coroutine.resume( r, unpack(eventData) )
- if not ok then error( param ) else tFilter = param end
- if coroutine.status( r ) == "dead" or eventData[1] == "terminate" then
- r, event = nil, "terminate"
- return
- end end end
- eventData = { os.pullEventRaw() }
- end end
- end
- -----------------------------------------------------------------------------------------------------------
- -- MAIN PROGRAM -- PROGRAM -- INSERT CUSTOM PROGRAM HERE --
- -----------------------------------------------------------------------------------------------------------
- -----------------------------------------------------------------------------------------------------------
- -- COROUTINE -- PROGRAM --
- -----------------------------------------------------------------------------------------------------------
- -----------------------------------------------------------------------------------------------------------
- -- COROUTINE DRIVERS -- EMBEDED --
- -----------------------------------------------------------------------------------------------------------
- -----------------------------------------------------------------------------------------------------------
- -- END -- EMBEDED --
- -----------------------------------------------------------------------------------------------------------
- parallel.waitForAll(coroutineControl["driver"]["yielder"],
- coroutineControl["driver"]["resize"],
- coroutineControl["driver"]["buttonScan"],
- coroutineControl["driver"]["buttonRedraw"],
- coroutineControl["driver"]["buttonReset"],
- coroutineControl["driver"]["redstoneControl"],
- coroutineControl["driver"]["osControl"],
- coroutineControl["driver"]["peripherialControl"],
- coroutineControl["driver"]["insertWindow"],
- -- coroutineControl["driver"]["messageWindow"],
- coroutineControl["driver"]["save"]
- )
Advertisement
Add Comment
Please, Sign In to add comment