Rolcam

[WIP] Computercraft rednet (MFR) cable manager

Jun 21st, 2021 (edited)
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.78 KB | None | 0 0
  1. side = "back"
  2. mon = peripheral.wrap("monitor_12")
  3. rs.setBundledOutput(side, 0)
  4. -- Variables - Don't touch please
  5. colWhite = 0
  6. colWhiteData = " "
  7. colOrange = 0
  8. colOrangeData = " "
  9. colMagenta = 0
  10. colMagentaData = " "
  11. colLightBlue = 0
  12. colLightBlueData = " "
  13. colYellow = 0
  14. colYellowData = " "
  15. colLime = 0
  16. colLimeData = " "
  17. colPink = 0
  18. colPinkData = " "
  19. colGray = 0
  20. colGrayData = " "
  21. colLightGray = 0
  22. colLightGrayData = " "
  23. colCyan = 0
  24. colCyanData = " "
  25. colPurple = 0
  26. colPurpleData = " "
  27.  
  28. -- Generates a new data file (All bands are off by default)
  29. function generateColList()
  30.     col = fs.open("colList", "w")
  31.     col.writeLine("Rednet Color Band List")
  32.     col.close()
  33.     col = fs.open("colList", "a")
  34.     col.writeLine("White: Off")
  35.     col.writeLine("Orange: Off")
  36.     col.writeLine("Magenta: Off")
  37.     col.writeLine("Light Blue: Off")
  38.     col.writeLine("Yellow: Off")
  39.     col.writeLine("Lime: Off")
  40.     col.writeLine("Pink: Off")
  41.     col.writeLine("Gray: Off")
  42.     col.writeLine("Light Gray: Off")
  43.     col.writeLine("Cyan: Off")
  44.     col.writeLine("Purple: Off")
  45.     col.close()
  46. end
  47.  
  48. -- Updates the data file
  49. function updateColList()
  50.     col = fs.open("colList", "w")
  51.     col.writeLine("Rednet Color Band List")
  52.     col.close()
  53.     col = fs.open("colList", "a")
  54.     col.writeLine(colWhiteData)
  55.     col.writeLine(colOrangeData)
  56.     col.writeLine(colMagentaData)
  57.     col.writeLine(colLightBlueData)
  58.     col.writeLine(colYellowData)
  59.     col.writeLine(colLimeData)
  60.     col.writeLine(colPinkData)
  61.     col.writeLine(colGrayData)
  62.     col.writeLine(colLightGrayData)
  63.     col.writeLine(colCyanData)
  64.     col.writeLine(colPurpleData)
  65.     col.close()
  66. end
  67.  
  68. -- Prints the data file to a monitor (also sets the variables)
  69. function printData()
  70.     term.redirect(mon)
  71.     term.clear()
  72.     term.setCursorPos(1,1)
  73.     term.setTextColor(colors.white)
  74.     col = fs.open("colList", "r")
  75.     print(col.readLine())
  76.     term.setCursorPos(1,3)
  77.     colWhiteData = col.readLine()
  78.     term.setTextColor(colors.white)
  79.     write("White: ")
  80.     if colWhiteData == "White: Off" then
  81.         term.setTextColor(colors.red)
  82.         colWhite = 0
  83.         write("Off")
  84.     else
  85.         term.setTextColor(colors.green)
  86.         colWhite = colors.white
  87.         write("On")
  88.     end
  89.     term.setCursorPos(1,4)
  90.     colOrangeData = col.readLine()
  91.     term.setTextColor(colors.orange)
  92.     write("Orange: ")
  93.     if colOrangeData == "Orange: Off" then
  94.         term.setTextColor(colors.red)
  95.         colOrange = 0
  96.         write("Off")
  97.     else
  98.         term.setTextColor(colors.green)
  99.         colOrange = colors.orange
  100.         write("On")
  101.     end
  102.     term.setCursorPos(1,5)
  103.     colMagentaData = col.readLine()
  104.     term.setTextColor(colors.magenta)
  105.     write("Magenta: ")
  106.     if colMagentaData == "Magenta: Off" then
  107.         term.setTextColor(colors.red)
  108.         colMagenta = 0
  109.         write("Off")
  110.     else
  111.         term.setTextColor(colors.green)
  112.         colMagenta = colors.magenta
  113.         write("On")
  114.     end
  115.     term.setCursorPos(1,6)
  116.     colLightBlueData = col.readLine()
  117.     term.setTextColor(colors.lightBlue)
  118.     write("Light Blue: ")
  119.     if colLightBlueData == "Light Blue: Off" then
  120.         term.setTextColor(colors.red)
  121.         colLightBlue = 0
  122.         write("Off")
  123.     else
  124.         term.setTextColor(colors.green)
  125.         colLightBlue = colors.lightBlue
  126.         write("On")
  127.     end
  128.     term.setCursorPos(1,7)
  129.     colYellowData = col.readLine()
  130.     term.setTextColor(colors.yellow)
  131.     write("Yellow: ")
  132.     if colYellowData == "Yellow: Off" then
  133.         term.setTextColor(colors.red)
  134.         colYellow = 0
  135.         write("Off")
  136.     else
  137.         term.setTextColor(colors.green)
  138.         colYellow = colors.Yellow
  139.         write("On")
  140.     end
  141.     term.setCursorPos(1,8)
  142.     colLimeData = col.readLine()
  143.     term.setTextColor(colors.lime)
  144.     write("Lime: ")
  145.     if colLimeData == "Lime: Off" then
  146.         term.setTextColor(colors.red)
  147.         colLime = 0
  148.         write("Off")
  149.     else
  150.         term.setTextColor(colors.green)
  151.         colLime = colors.lime
  152.         write("On")
  153.     end
  154.     term.setCursorPos(1,9)
  155.     colPinkData = col.readLine()
  156.     term.setTextColor(colors.pink)
  157.     write("Pink: ")
  158.     if colPinkData == "Pink: Off" then
  159.         term.setTextColor(colors.red)
  160.         colPink = 0
  161.         write("Off")
  162.     else
  163.         term.setTextColor(colors.green)
  164.         colPink = colors.pink
  165.         write("On")
  166.     end
  167.     term.setCursorPos(1,10)
  168.     colGrayData = col.readLine()
  169.     term.setBackgroundColor(colors.lightGray)
  170.     term.setTextColor(colors.gray)  
  171.     write("Gray:")
  172.     term.setBackgroundColor(colors.black)
  173.     write(" ")
  174.     if colGrayData == "Gray: Off" then
  175.         term.setTextColor(colors.red)
  176.         colGray = 0
  177.         write("Off")
  178.     else
  179.         term.setTextColor(colors.green)
  180.         colGray = colors.gray
  181.         write("On")
  182.     end
  183.     term.setCursorPos(1,11)
  184.     colLightGrayData = col.readLine()
  185.     term.setTextColor(colors.lightGray)
  186.     write("Light Gray: ")
  187.     if colLightGrayData == "Light Gray: Off" then
  188.         term.setTextColor(colors.red)
  189.         colLightGray = 0
  190.         write("Off")
  191.     else
  192.         term.setTextColor(colors.green)
  193.         colLightGray = colors.lightGray
  194.         write("On")
  195.     end
  196.      term.setCursorPos(1,12)
  197.     colCyanData = col.readLine()
  198.     term.setTextColor(colors.cyan)
  199.     write("Cyan: ")
  200.     if colCyanData == "Cyan: Off" then
  201.         term.setTextColor(colors.red)
  202.         colCyan = 0
  203.         write("Off")
  204.     else
  205.         term.setTextColor(colors.green)
  206.         colCyan = colors.cyan
  207.         write("On")
  208.     end
  209.     term.setCursorPos(1,13)
  210.     colPurpleData = col.readLine()
  211.     term.setTextColor(colors.purple)
  212.     write("Purple: ")
  213.     if colPurpleData == "Purple: Off" then
  214.         term.setTextColor(colors.red)
  215.         colPurple = 0
  216.         write("Off")
  217.     else
  218.         term.setTextColor(colors.green)
  219.         colPurple = colors.purple
  220.         write("On")
  221.     end
  222.     col.close()
  223.     term.restore()
  224. end
  225.  
  226. -- Generates a data file if one isn't present
  227. if not fs.exists("colList") then
  228.     generateColList()
  229.     print("Color List Generated")
  230.     sleep(2)
  231. end
  232.  
  233. -- Main Program
  234. while true do
  235.     printData()
  236.     term.clear()
  237.     term.setCursorPos(1,1)
  238.     term.setTextColor(colors.yellow)
  239.     if colors.combine(colWhite,colOrange,colMagenta,colLightBlue,colYellow,colLime,colPink) == 0 then
  240.         rs.setBundledOutput(side, 0)
  241.     else
  242.         rs.setBundledOutput(side, colors.combine(colWhite,colOrange,colMagenta,colLightBlue,colYellow,colLime,colPink))
  243.     end
  244.     print("Please enter the band color you wish to toggle")
  245.     print("See monitor for rednet color band list")
  246.     print("type \"off\" to turn all bands off or \"on\" to turn them all on")
  247.     input = read()
  248.     if input == "white" or input == "White" then
  249.         if colWhiteData == "White: Off" then
  250.             colWhiteData = "White: On"
  251.             print("White Band Toggled On")
  252.         else
  253.             colWhiteData = "White: Off"
  254.             print("White Band Toggled Off")
  255.         end
  256.         sleep(2)
  257.         updateColList()
  258.         printData()
  259.     elseif input == "orange" or input == "Orange" then
  260.         if colOrangeData == "Orange: Off" then
  261.             colOrangeData = "Orange: On"
  262.             print("Orange Band Toggled On")
  263.         else
  264.             colOrangeData = "Orange: Off"
  265.             print("Orange Band Toggled Off")
  266.         end
  267.         sleep(2)
  268.         updateColList()
  269.         printData()
  270.     elseif input == "magenta" or input == "Magenta" then
  271.         if colMagentaData == "Magenta: Off" then
  272.             colMagentaData = "Magenta: On"
  273.             print("Magenta Band Toggled On")
  274.         else
  275.             colMagentaData = "Magenta: Off"
  276.             print("Magenta Band Toggled Off")
  277.         end
  278.         sleep(2)
  279.         updateColList()
  280.         printData()
  281.     elseif input == "lightblue" or input == "LightBlue" or input == "light blue" or input == "Light Blue" then
  282.         if colLightBlueData == "Light Blue: Off" then
  283.             colLightBlueData = "Light Blue: On"
  284.             print("Light Blue Band Toggled On")
  285.         else
  286.             colLightBlueData = "Light Blue: Off"
  287.             print("Light Blue Band Toggled Off")
  288.         end
  289.         sleep(2)
  290.         updateColList()
  291.         printData()
  292.     elseif input == "yellow" or input == "Yellow" then
  293.         if colYellowData == "Yellow: Off" then
  294.             colYellowData = "Yellow: On"
  295.             print("Yellow Band Toggled On")
  296.         else
  297.             colYellowData = "Yellow: Off"
  298.             print("Yellow Blue Band Toggled Off")
  299.         end
  300.         sleep(2)
  301.         updateColList()
  302.         printData()
  303.     elseif input == "lime" or input == "Lime" then
  304.         if colLimeData == "Lime: Off" then
  305.             colLimeData = "Lime: On"
  306.             print("Lime Band Toggled On")
  307.         else
  308.             colLimeData = "Lime: Off"
  309.             print("Lime Band Toggled Off")
  310.         end
  311.         sleep(2)
  312.         updateColList()
  313.         printData()
  314.     elseif input == "pink" or input == "Pink" then
  315.         if colPinkData == "Pink: Off" then
  316.             colPinkData = "Pink: On"
  317.             print("Pink Band Toggled On")
  318.         else
  319.             colPinkData = "Pink: Off"
  320.             print("Pink Band Toggled Off")
  321.         end
  322.         sleep(2)
  323.         updateColList()
  324.         printData()
  325.     elseif input == "gray" or input == "Gray" then
  326.         if colGrayData == "Gray: Off" then
  327.             colGrayData = "Gray: On"
  328.             print("Gray Band Toggled On")
  329.         else
  330.             colGrayData = "Gray: Off"
  331.             print("Gray Band Toggled Off")
  332.         end
  333.         sleep(2)
  334.         updateColList()
  335.         printData()
  336.     elseif input == "lightgray" or input == "LightGray" or input == "light gray" or input == "Light Gray" then
  337.         if colLightGrayData == "Light Gray: Off" then
  338.             colLightGrayData = "Light Gray: On"
  339.             print("Light Gray Band Toggled On")
  340.         else
  341.             colLightGrayData = "Light Gray: Off"
  342.             print("Light Gray Band Toggled Off")
  343.         end
  344.         sleep(2)
  345.         updateColList()
  346.         printData()
  347.     elseif input == "cyan" or input == "Cyan" then
  348.         if colCyanData == "Cyan: Off" then
  349.             colCyanData = "Cyan: On"
  350.             print("Cyan Band Toggled On")
  351.         else
  352.             colCyanData = "Cyan: Off"
  353.             print("Cyan Band Toggled Off")
  354.         end
  355.         sleep(2)
  356.         updateColList()
  357.         printData()
  358.     elseif input == "purple" or input == "Purple" then
  359.         if colPurpleData == "Purple: Off" then
  360.             colPurpleData = "Purple: On"
  361.             print("Purple Band Toggled On")
  362.         else
  363.             colPurpleData = "Purple: Off"
  364.             print("Purple Band Toggled Off")
  365.         end
  366.         sleep(2)
  367.         updateColList()
  368.         printData()
  369.     elseif input == "on" or input == "On" then
  370.         colWhiteData = "White: On"
  371.         colOrangeData = "Orange: On"
  372.         colMagentaData = "Magenta: On"
  373.         colLightBlueData = "Light Blue: On"
  374.         colYellowData = "Yellow: On"
  375.         colLimeData = "Lime: On"
  376.         colPinkData = "Pink: On"
  377.         colGrayData = "Gray: On"
  378.         colLightGrayData = "Light Gray: On"
  379.         colCyanData = "Cyan: On"
  380.         colPurpleData = "Purple: On"
  381.         print("All bands toggled on")
  382.         sleep(2)
  383.         updateColList()
  384.         printData()
  385.     elseif input == "off" or input == "Off" then
  386.         colWhiteData = "White: Off"
  387.         colOrangeData = "Orange: Off"
  388.         colMagentaData = "Magenta: Off"
  389.         colLightBlueData = "Light Blue: Off"
  390.         colYellowData = "Yellow: Off"
  391.         colLimeData = "Lime: Off"
  392.         colPinkData = "Pink: Off"
  393.         colGrayData = "Gray: Off"
  394.         colLightGrayData = "Light Gray: Off"
  395.         colCyanData = "Cyan: Off"
  396.         colPurpleData = "Purple: Off"
  397.         print("All bands toggled off")
  398.         sleep(2)
  399.         updateColList()
  400.         printData()
  401.     else
  402.         term.setTextColor(colors.red)
  403.         print("Invalid Selection")
  404.         sleep(2)
  405.     end
  406. end
Add Comment
Please, Sign In to add comment