PeachGaming

Messicrew's Signal Controller

Mar 26th, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.56 KB | None | 0 0
  1. --PeachMaster's Digital Signal Controller
  2. --Edit if you want
  3.  
  4. local bundledIO = peripheral.wrap("left")
  5. os.loadAPI("touchpoint")
  6. local redstoneOut = false
  7. t = touchpoint.new("monitor_8")
  8.  
  9. local function bundledOutputContains(color)
  10.     if bundledIO.testBundledOutput(colors.combine(bundledIO.getBundledOutput(), color)) then
  11.         return true
  12.     else
  13.         return false
  14.     end
  15. end
  16.  
  17. local function addBundledOutput(color)
  18.     bundledIO.setBundledOutput(colors.combine(bundledIO.getBundledOutput(), color))
  19. end
  20.  
  21. local function removeBundledOutput(color)
  22.     bundledIO.setBundledOutput(colors.subtract(bundledIO.getBundledOutput(), color))
  23. end
  24.  
  25. local function toggleRedstone()
  26. if redstoneOut == true then
  27.     redstone.setOutput("top", false)
  28.     redstoneOut = false
  29. else
  30.     redstone.setOutput("top", true)
  31.     redstoneOut = true
  32. end
  33.  
  34. end
  35.  
  36. local function toggleBundledOutput(color)
  37.     if bundledOutputContains(color) then
  38.         removeBundledOutput(color)
  39.     else
  40.         addBundledOutput(color)
  41.     end
  42.     local file = fs.open("status", "w")
  43.     file.write(bundledIO.getBundledOutput())
  44.     file.close()
  45. end
  46.  
  47. bundledIO.setBundledOutput(0)
  48.  
  49. local file = fs.open("status", "r")
  50.     bundledIO.setBundledOutput(tonumber(file.readAll()))
  51.     file.close()
  52.     toggleRedstone()
  53.     toggleRedstone()
  54.  
  55. t:add("Eastbound NS Track", function()
  56. toggleBundledOutput(colors.red)
  57. toggleRedstone()
  58. t:toggleButton("Eastbound NS Track")
  59.  
  60. end,2, 2, 22, 4, colors.red, colors.lightBlue)
  61.  
  62. t:add("Northbound NS Track", function()
  63. toggleBundledOutput(colors.yellow)
  64. toggleRedstone()
  65. t:toggleButton("Northbound NS Track")
  66.  
  67. end, 24, 2, 44, 4, colors.yellow, colors.lightBlue)
  68.  
  69. t:add("MCRR Jct. Track", function()
  70.     toggleBundledOutput(colors.orange)
  71.     toggleRedstone()
  72.     t:toggleButton("MCRR Jct. Track")
  73.      
  74. end, 46, 2, 56, 4, colors.orange, colors.lightBlue)
  75.    
  76. t:add("Johnson West Wye", function()
  77. toggleBundledOutput(colors.purple)
  78. toggleRedstone()
  79. t:toggleButton("Johnson West Wye")
  80.  
  81. end, 2, 6, 22, 8, colors.purple, colors.lightBlue)
  82.  
  83. t:add("Johnson North Wye", function()
  84.     toggleBundledOutput(colors.pink)
  85.     toggleRedstone()
  86.     t:toggleButton("Johnson North Wye")
  87.      
  88. end, 24, 6, 44, 8, colors.pink, colors.lightBlue)
  89.  
  90. t:add("SB Crossover NB", function()
  91.     toggleBundledOutput(colors.green)
  92.     toggleRedstone()
  93.     t:toggleButton("SB Crossover NB")
  94.      
  95. end, 2, 10, 22, 12, colors.green, colors.lightBlue)
  96.  
  97. t:add("SB Crossover SB", function()
  98.     toggleBundledOutput(colors.brown)
  99.     toggleRedstone()
  100.     t:toggleButton("SB Crossover SB")
  101.      
  102. end, 24, 10, 44, 12, colors.brown, colors.lightBlue)
  103.    
  104. t:add("TUS South Enterance", function()
  105.     toggleBundledOutput(colors.blue)
  106.     toggleRedstone()
  107.     t:toggleButton("TUS South Enterance")
  108.      
  109. end, 2, 14, 22, 16, colors.blue, colors.lightBlue)
  110.    
  111. t:add("TUS North Enterance", function()
  112.     toggleBundledOutput(colors.cyan)
  113.     toggleRedstone()
  114.     t:toggleButton("TUS North Enterance")
  115.      
  116. end, 24, 14, 44, 16, colors.cyan, colors.lightBlue)
  117.  
  118. t:add("North Crossover SB", function()
  119.     toggleBundledOutput(colors.lightGray)
  120.     toggleRedstone()
  121.     t:toggleButton("North Crossover SB")
  122.      
  123. end, 2, 18, 22, 20, colors.lightGray, colors.lightBlue)
  124.  
  125. t:add("North Crossover NB", function()
  126.     toggleBundledOutput(colors.gray)
  127.     toggleRedstone()
  128.     t:toggleButton("North Crossover NB")
  129.      
  130. end, 24, 18, 44, 20, colors.gray, colors.lightBlue)
  131.  
  132.  
  133.  
  134. t:draw()
  135.  
  136. print(bundledOutputContains(colors.red))
  137.  
  138.  
  139. t:run()
  140. print("Here?")
  141. if bundledOutputContains(colors.red) then
  142.     print("Red!")
  143.     t:toggleButton("Eastboound NS Track")
  144.     elseif bundledOutputContains(colors.yellow) then
  145.     t:toggleButton("Northbound NS Track")
  146.     elseif bundledOutputContains(colors.orange) then
  147.     t:toggleButton("MCRR Jct. Track")
  148.     elseif bundledOutputContains(colors.purple) then
  149.     t:toggleButton("Johnson West Wye")
  150.     elseif bundledOutputContains(colors.pink) then
  151.     t:toggleButton("Johnson North Wye")
  152.     elseif bundledOutputContains(colors.green) then
  153.     t:toggleButton("SB Crossover NB")
  154.     elseif bundledOutputContains(colors.brown) then
  155.     t:toggleButton("SB Crossover SB")
  156.     elseif bundledOutputContains(colors.blue) then
  157.     t:toggleButton("TUS South Enterance")
  158.     elseif bundledOutputContains(colors.cyan) then
  159.     t:toggleButton("TUS North Enterance")
  160.     elseif bundledOutputContains(colors.blue) then
  161.     t:toggleButton("North Crossover NB")
  162.     end
  163. event, p1, p2, p3, p4, p5 = t:handleEvents(os.pullEvent())
Advertisement
Add Comment
Please, Sign In to add comment