--BundleWorks
--Date created: 1/13/12
--Version: 1.1
--Author: FuzzyPurp
--Info: Built as a standalone, now part of Redworks.

--[[ BundleWorks is a program to tell the computer which redpower wire to activate / deactivate.
 
 colors such as: supports all 16 colors: red, yellow, 
 green, blue, orange, gray purple, white pink, gray, 
 lightbue, lightgray, magenta, cyan, brown, black.
 
 reset: turns all the wires off.
 all: turns all the wires on.
 quit: quits the program, and shutdown.
 
 Important: Bundleworks assumes you have the regular 
 bundled cable, connected to the back of the computer for output. And the extension of color wire you choose.]]

 
 --Functions
function clear()
term.clear()
term.setCursorPos(1,1)
end
function clear2()
term.clear()
term.setCursorPos(1,5)
end
function light(color)
if color=="red" then
return colors.red,1
end
if color=="white" then
return colors.white,2
end
if color=="blue" then
return colors.blue,3
end
if color=="green" then
return colors.green,4
end
if color=="pink" then
return colors.pink,5
end
if color=="orange" then
return colors.orange,6
end
if color=="magenta" then
return colors.magenta,7
end
if color=="lightblue" then
return 8,8
end
if color=="yellow" then
return colors.yellow,9
end
if color=="lime" then
return colors.lime,10
end
if color=="gray" then
return colors.gray,11
end
if color=="quit" then
clear2()
print ("Thank you for using FuzzyPurp's BundleWorks!\n\nHave a colorful day : )")
sleep(2)
os.shutdown()
end
if color=="lightgray" then
return 256,12
end
if color=="cyan" then
return colors.cyan,13
end
if color=="purple" then
return colors.purple,14
end
if color=="brown" then
return colors.brown,15
end
if color=="black" then
return colors.black,16
end
if color=="reset" then
return (rs.getBundledOutput("back")*(-1))
end
if color=="all" then
return (65535)
end
return 0
end

---More Fire!!
l={}
for i=1, 16 do
l[i]=0
end

clear()
while true do
term.setCursorPos(16,1)
print"-BundleWorks- 1.1"
redworks.showWindow(1,8,49,6,"-Choice of Color-","White| Orange| Magenta| LightBlue| Yellow| Lime| Pink| Gray| LightGray| Cyan| Purple| Blue| Brown| Green| Yellow| Black|   All|")
term.setCursorPos(1,17)
print("Type 'quit' to close, 'reset' all wires Off.")
term.setCursorPos(1,3)
write("Toggle which Colored Wire? ")
term.setCursorPos(28,3)

a=read()
num,place=light(a,l)
if num==rs.getBundledOutput("back")*(-1)  then
rs.setBundledOutput("back", 0)
clear2()
print("All Colored Wires are now OFF!")

for i=1, 16 do
l[i]=0
end
else
if num==65535 then
rs.setBundledOutput("back", 65535)
clear2()
print("All Colored Wires are now ON!")
for i=1, 16 do
l[i]=1
end
else

if num~=0 then
if l[place]==0 then
l[place]=1
else
l[place]=0
end
if l[place]==0 then
rs.setBundledOutput("back", rs.getBundledOutput("back")-num)
clear2()
print("Output for Wire: ".. string.upper(a) .." is now OFF.")
print(newline)
else
rs.setBundledOutput("back", rs.getBundledOutput("back")+num)
clear2()
print("Output for Wire: ".. string.upper(a) .." is now ON.")
print(newline)
end
else
clear2()
write("Nonsense. Please choose the available.")
print(newline)
end
end
end
end