Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- WARNING! USE THE INSTALLER, DO NOT DOWNLOAD THIS ALONE! IT WONT WORK BY ITSELF.
- **********
- Installer
- **********
- In a CC Computer (Advanced only!):
- pastebin get pVyr7LjW installer
- From pastebin site:
- http://pastebin.com/pVyr7LjW
- **********
- Description
- **********
- This program ceates the config file for my Advanced Redstone Control (ARC) program. This
- program really isn't helpful if used by itself (But you can use it alone if you want I guess).
- To download it correctly, use the installer
- **********
- FAQ
- **********
- Q:What is this?
- A:See description
- Q:Im confused
- A:http://youtu.be/o_mzKx-7dS0
- Q:Auto-Update?
- A:Not yet, and not planned
- Q:Where do I report bugs?
- A:On it's Youtube video
- http://youtu.be/o_mzKx-7dS0
- **********
- Version
- **********
- |1.1.1| <-- This program
- Date: 9/12/2014
- Bug fixes:
- -Error message would be put over text when loading bad configs
- |1.1|
- Date: ??? (Forgot to record...)
- Changes:
- -When editing buttons, the old name is automatically put into the dialog box
- -Colors are displayed in order by value (finally :P)
- -Now displayes colors by multiplying by 2, not an internal table
- |1.0 (Release)|
- Date: 8/15/2014
- Date: mm/dd/yyyy
- -Makes configs for my ARC program!
- Bugs:
- -None so far
- -Altho side note this program is HUGE
- *Will simplify soon. Maybe.
- ]]
- --Variables--
- local version = "1.1.1"
- local cableSide
- local monitorName
- w,h = term.getSize()
- local problem = true
- local lastColor = 32768 --the color black
- --Functions--
- function clear() shell.run("clear") end
- function tc(...) term.setTextColor(tonumber(...)) end
- function bc(...) term.setBackgroundColor(...) end
- function tw(...) term.write(...) end
- function cp(...) term.setCursorPos(...) end
- function printC(text,y)
- if not y then
- error("printC:No Y value specified")
- end
- tLenght = #tostring(text)
- local sStart = math.ceil(w/2-tLenght/2)
- local sEnd = sStart + tLenght
- cp(sStart,y)
- tw(text)
- return sStart,sEnd
- end
- function isColor(color)
- for a,b in pairs(colors) do
- if b == tonumber(color) then
- return true
- end
- end
- return false
- end
- function isSide(side)
- for a,b in pairs(rs.getSides()) do
- if b == side then
- return true
- end
- end
- return false
- end
- function mainScreen(_text)
- bc(colors.white)
- clear()
- bc(colors.blue)
- cp(1,1)
- tw(string.rep(" ",w))
- tc(colors.orange)
- if _text then
- printC(_text,1)
- else
- printC("Advanced Redstone Control - Config Creator",1)
- end
- end
- function drawMain()
- problem = false
- clear()
- mainScreen()
- tc(colors.black)
- --monitor
- cp(2,3)
- bc(colors.white)
- tw("Monitor: ")
- tc(colors.white)
- if not monitorName then
- monitorName = "Not set"
- end
- if peripheral.getType(monitorName) ~= "monitor" then
- tc(colors.orange)
- else
- tc(colors.lime)
- end
- if monitorName == "Not set" then
- problem = true
- tc(colors.red)
- tw(monitorName)
- else
- tw(monitorName)
- end
- tw(" ")
- bc(colors.lightBlue)
- tc(colors.white)
- tw("Edit")
- --cable
- cp(2,5)
- bc(colors.white)
- tc(colors.black)
- tw("Bundled Cable: ")
- if not isSide(cableSide) or not cableSide then
- problem = true
- tc(colors.red)
- else
- tc(colors.lime)
- end
- if cableSide then
- tw(cableSide)
- else
- tw("Not set")
- end
- tw(" ")
- tc(colors.white)
- bc(colors.lightBlue)
- tw("Edit")
- --buttons
- cp(2,7)
- tc(colors.black)
- bc(colors.white)
- tw("Buttons: ")
- bc(colors.lightBlue)
- tc(colors.white)
- print("Edit")
- bc(colors.white)
- if #buttons < 1 then
- cp(2,8)
- tc(colors.red)
- tw("None")
- problem = true
- else
- for i = 1, #buttons do
- bc(colors.white)
- tw(" ")
- if i > h-9 then
- bc(colors.white)
- tc(colors.black)
- tw("Plus "..#buttons+1-i.." more")
- break
- end
- if not isColor(buttons[i]["color"]) then
- bc(colors.red)
- tc(colors.white)
- problem = true
- else
- bColor = buttons[i]["color"]
- if bColor == colors.white then
- bc(colors.lightGray)
- tc(colors.white)
- else
- bc(colors.white)
- tc(bColor)
- end
- end
- print(buttons[i]["name"])
- end
- end
- if problem then
- bc(colors.red)
- else
- bc(colors.lime)
- end
- tc(colors.white)
- cp(1,h)
- tw(string.rep(" ",w))
- printC("Save and Exit",h)
- end
- function scrollRead(x,y,maxX,insertText) --This basically scrolls but not very well
- if insertText then cInput = insertText cPos = #insertText+1 else cPos = 1 cInput = "" end
- term.setCursorBlink(true)
- while true do
- term.setCursorPos(x,y)
- term.write(string.rep(" ",maxX))
- term.setCursorPos(x,y)
- if string.len(cInput) > maxX-1 then
- term.write(string.sub(cInput,(maxX-1)*-1))
- else
- term.write(cInput)
- end
- if cPos > maxX-1 then
- term.setCursorPos(x+maxX-1,y)
- else
- term.setCursorPos(x+cPos-1,y)
- end
- event,p1 = os.pullEvent()
- if event == "char" then
- cInput = string.sub(cInput,1,cPos)..p1..string.sub(cInput,cPos+1)
- cPos = cPos+1
- elseif event == "key" then
- if p1 == keys.enter then
- break
- elseif p1 == keys.backspace then
- if cPos > 1 then
- cInput = string.sub(cInput,1,cPos-2)..string.sub(cInput,cPos)
- cPos = cPos - 1
- end
- elseif p1 == keys["end"] then
- cPos = string.len(cInput)+1
- end
- end
- end
- term.setCursorBlink(false)
- return cInput
- end
- function loadConfig()
- --Try to load existing config
- f = fs.open("/ARC/config","r")
- local tLines = {}
- local l = 0
- repeat
- l = l + 1
- tLines[l] = f.readLine()
- until tLines[l] == nil
- if tLines[1] ~= "This is the Advanced Redstone Control config file" or tLines[2] ~= "Do not change anything in it!" or tLines[3] ~= "Use the provided config editor" then
- f.close()
- return "File has incorrect formatting"
- end
- --Monitor
- monitorName = tLines[4]
- --Bundled cable
- if not isSide(tLines[5]) then
- f.close()
- return "Invalid side"
- end
- cableSide = tLines[5]
- --Load the buttons
- local equalPos
- if not tonumber(tLines[6]) then
- f.close()
- return "Incorrect formating"
- end
- buttons = {}
- for i = 1, tonumber(tLines[6]) do
- c = i+6
- equalPos = string.find(tLines[c],"=")
- if not equalPos then
- f.close()
- return "Problem with line "..c
- end
- bName = string.sub(tLines[c],1,equalPos-1)
- bColor = tonumber(string.sub(tLines[c],equalPos+1))
- buttons[i] = {}
- buttons[i]["name"] = bName
- buttons[i]["color"] = bColor
- buttons[i]["state"] = false
- end
- f.close()
- return false
- end
- function editMonitor()
- clear()
- mainScreen("Edit monitor...")
- tc(colors.black)
- bc(colors.white)
- printC("Current name:",3)
- if monitorName then
- printC(monitorName,4)
- else
- printC("Not set")
- end
- printC("Enter name/side:",6)
- printC("Monitor touching computer - use side",h-1)
- printC("Monitor connected by network cable - use name",h)
- tStart,tEnd = printC(string.rep(" ",20),7)
- while true do
- bc(colors.black)
- tc(colors.white)
- input = scrollRead(tStart,7,20)
- if string.find(input," ") then
- tc(colors.red)
- bc(colors.white)
- printC("Cannot contain spaces",8)
- elseif input ~= "" then
- break
- end
- end
- monitorName = input
- end
- function editCable()
- clear()
- mainScreen("Edit cable side...")
- tc(colors.black)
- bc(colors.white)
- printC("Current side:",3)
- if cableSide then
- printC(cableSide,4)
- else
- printC("Not set",4)
- end
- printC("Enter side:",6)
- tStart,tEnd = printC(string.rep(" ",10),7)
- while true do
- bc(colors.black)
- tc(colors.white)
- input = scrollRead(tStart,7,10)
- if not isSide(input) then
- tc(colors.red)
- bc(colors.white)
- printC("Not a side",8)
- printC("top, bottom, left, right, back, front",9)
- else
- break
- end
- end
- cableSide = input
- end
- function redrawButtonEdit()
- clear()
- mainScreen("Edit buttons...")
- cp(2,2)
- tc(colors.white)
- bc(colors.lightBlue)
- tw("Add")
- bc(colors.white)
- tw(" ")
- bc(colors.lime)
- tw("Done")
- tc(colors.black)
- bc(colors.white)
- printC("Buttons:",2)
- if #buttons > 0 then
- if #buttons >= h-3 then
- times = h-3
- bc(colors.white)
- tc(colors.red)
- printC("Max buttons reached",h)
- else
- times = #buttons
- end
- for i = 1, times do
- cp(2,i+2)
- if not isColor(buttons[i]["color"]) then
- bc(colors.red)
- tc(colors.white)
- else
- bColor = buttons[i]["color"]
- if bColor == colors.white then
- bc(colors.lightGray)
- tc(colors.white)
- else
- bc(colors.white)
- tc(bColor)
- end
- end
- tw(buttons[i]["name"])
- cp(w-12,i+2)
- tc(colors.white)
- bc(colors.lightBlue)
- tw("Edit")
- bc(colors.white)
- tw(" ")
- bc(colors.red)
- tw("Delete")
- end
- else
- tc(colors.red)
- bc(colors.white)
- printC("None",3)
- end
- end
- function editButtons()
- continue = true
- while continue do
- redrawButtonEdit()
- while true do
- event,p1,p2,p3 = os.pullEvent("mouse_click")
- if p3 == 2 then
- if p2 >= 2 and p2 <= 4 then --add
- if #buttons < h-3 then
- bc(colors.black)
- tc(colors.white)
- repeat
- input = scrollRead(2,#buttons+3,15)
- until input ~= ""
- cp(2,#buttons+3)
- local cColor = 1
- local colorPos = {}
- for i = 1, 20 do
- bc(cColor)
- tw(" ")
- colorPos[i] = cColor
- if cColor == lastColor then break end
- cColor = cColor*2
- end
- continue2 = true
- while continue2 do
- event,par1,par2,par3 = os.pullEvent("mouse_click")
- if par3 == #buttons+3 then
- if par2 >= 2 and par2 <= 18 then
- buttons[#buttons+1] = {}
- buttons[#buttons]["name"] = input
- buttons[#buttons]["color"] = colorPos[par2 - 1]
- continue2 = false
- redrawButtonEdit()
- end
- end
- end
- end
- elseif p2 >= 6 and p2 <= 9 then --Done
- continue = false
- break
- end
- elseif p3 > 2 and #buttons > 0 then
- if p3-2 <= #buttons then
- if p2 >= w-13 and p2 <= w-10 then --Edit
- bc(colors.black)
- tc(colors.white)
- repeat
- input = scrollRead(2,p3,15,buttons[p3-2]["name"])
- until input ~= ""
- cp(2,p3)
- local cColor = 1
- local colorPos = {}
- for i = 1, 20 do
- bc(cColor)
- tw(" ")
- colorPos[i] = cColor
- if cColor == lastColor then break end
- cColor = cColor*2
- end
- continue2 = true
- while continue2 do
- event,par1,par2,par3 = os.pullEvent("mouse_click")
- if par3 == p3 then
- if par2 >= 2 and par2 <= 18 then
- buttons[p3-2]["name"] = input
- buttons[p3-2]["color"] = colorPos[par2 - 1]
- continue2 = false
- redrawButtonEdit()
- end
- end
- end
- elseif p2 >= w-8 and p2 <= w-2 then --delete
- --For now thers no confirmation
- table.remove(buttons,p3-2)
- redrawButtonEdit()
- end
- end
- end
- end
- end
- end
- function save()
- cp(1,h)
- bc(colors.orange)
- tw(string.rep(" ",w))
- tc(colors.white)
- printC("Saving...",h)
- f = fs.open("/arc/config","w")
- if f then
- f.write("This is the Advanced Redstone Control config file\nDo not change anything in it!\nUse the provided config editor\n")
- f.write(monitorName.."\n")
- f.write(cableSide.."\n")
- f.write(#buttons.."\n")
- for i = 1, #buttons do
- f.write(buttons[i]["name"].."="..buttons[i]["color"].."\n")
- end
- cp(1,h)
- bc(colors.lime)
- tw(string.rep(" ",w))
- tc(colors.white)
- printC("Saved to /arc/config",h)
- sleep(2)
- else
- cp(1,1)
- bc(colors.orange)
- tw(string.rep(" ",w))
- tc(colors.white)
- printC("Cannot open config file",1)
- sleep(1)
- end
- f.close()
- end
- function main() --Having this as a function allows error catching
- pos = {}
- mainScreen()
- bc(colors.lime)
- tc(colors.black)
- pos["New"] = {}
- pos["New"]["start"],pos["New"]["end"] = printC("Create New...",6)
- fExists = fs.exists("/ARC/config")
- if fExists then
- bc(colors.lime)
- else
- bc(colors.lightGray)
- end
- pos["Load"] = {}
- pos["Load"]["start"],pos["Load"]["end"] = printC("Load Existing",8)
- tc(colors.lightGray)
- bc(colors.white)
- printC("Use ctrl+t to end the program",h-1)
- printC("However, changes are not saved",h)
- while true do
- event,p1,p2,p3 = os.pullEvent("mouse_click")
- if p3 == 6 and p2 >= pos["New"]["start"] and p2 <= pos["New"]["end"] then
- monitorSide = nil
- cableSide = nil
- buttons = {}
- break
- elseif p3 == 8 and p2 >= pos["Load"]["start"] and p2 <= pos["New"]["end"] and fExists then
- tError = loadConfig()
- if tError then
- bc(colors.white)
- tc(colors.red)
- printC(tError,h-3)
- printC("Cannot load",h-2)
- else
- break
- end
- end
- end
- continue3 = true
- while continue3 do
- drawMain()
- while true do
- event,p1,p2,p3 = os.pullEvent("mouse_click")
- if p3 == 3 then --Edit Monitor name
- editMonitor()
- break
- elseif p3 == 5 then --Edit bundled cable side
- editCable()
- break
- elseif p3 == 7 then --Edit buttons
- editButtons()
- break
- elseif p3 == h and not problem then
- save()
- continue3 = false
- break
- end
- end
- end
- end
- --Program--
- state,err = pcall(function() main() end)
- if err then
- if string.find(err,"Terminated") then
- term.setCursorBlink(false)
- cp(1,1)
- bc(colors.red)
- tc(colors.white)
- tw(string.rep(" ",w))
- printC("Terminated",1)
- sleep(2)
- printC("Click to clear screen",1)
- os.pullEvent()
- bc(colors.black)
- clear()
- elseif string.find(err,"end") then
- tc(colors.black)
- print("Ended")
- else
- tc(colors.black)
- print("CRITICAL ERROR:")
- print(err)
- for i = 1, #buttons do
- print(i..":")
- print(" Name:"..buttons[i]["name"])
- print(" Color:"..buttons[i]["color"])
- end
- end
- else
- bc(colors.black)
- tc(colors.white)
- clear()
- print("Sucesss. Type 'rc run' to run Advanced Redstone Control program")
- end
- --Cleanup
- if f then
- f.close()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement