Advertisement
Sanwi

OC: Spawner Controller

Mar 2nd, 2015
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. local component = require("component")
  2. local colors = require("colors")
  3. local event = require("event")
  4. local button = require("C/b")
  5. local term = require("term")
  6.  
  7. local function findComps(type)
  8. local comps = {}
  9. local compNames = {}
  10.  
  11. for cAddress,cType in component.list(type) do
  12. -- Insert proxy methods table into comps table
  13. table.insert(comps, component.proxy(cAddress))
  14. -- Insert component type into compNames table
  15. table.insert(compNames, cType)
  16. end
  17. return comps, compNames
  18. end
  19.  
  20. local function toggleMachine(cButton, argsT)
  21. local cbutton = button.toggle(cButton)
  22.  
  23. local str = 0
  24. if argsT.alt then
  25. if cButton.state then str = 0 else str = 250 end
  26. else
  27. if cButton.state then str = 250 else str = 0 end
  28. end
  29.  
  30. rs.setBundledOutput(argsT.side, argsT.machineList[cButton.label], str) -- side, color, strength
  31. return cbutton
  32. end
  33.  
  34. local function reboot(cButton, argsT)
  35. if not computer then computer = require("computer") end
  36. computer.shutdown(true)
  37. end
  38.  
  39. local function setAllChannels(side, state)
  40. local strength = 0
  41. if state then strength = 250 end
  42.  
  43. for i=0, 15 do
  44. rs.setBundledOutput(side, i, strength)
  45. end
  46. end
  47.  
  48. local machineList =
  49. {
  50. Witch = colors.white,
  51. Maze_Slime = colors.orange,
  52. Enderman = colors.magenta,
  53. Blue_Slime = colors.lightblue,
  54. Blaze = colors.yellow,
  55. Cow = colors.lime,
  56. }
  57.  
  58. -- Button properties
  59. local buttonList = {}
  60. local action = toggleMachine
  61. local actionArgT = {side=5, machineList=machineList}
  62. local width = 30
  63. local height = 7
  64. local padding = "1:0:0:1"
  65. local col = "0x00AA00:0xAA0000"
  66.  
  67.  
  68. -- Buttons are rendered in the order they are generated in
  69. -- Since tables are not ordered, machineList buttons will not be in order on the screen
  70.  
  71. -- Generate machine toggle buttons from machineList
  72. for k,v in pairs(machineList) do
  73. table.insert(buttonList, button.newButton(buttonList, k, action, actionArgT, width, height, padding, col, false))
  74. end
  75.  
  76. -- Alternate button generation list for special buttons
  77. local cMList = { Slaughterhouse = colors.red, Grinders = colors.green, Killer_Joe = colors.black, MFR_1 = colors.brown, MFR_2 = colors.blue, }
  78.  
  79. -- MFR
  80. table.insert(buttonList, button.newButton(buttonList, "MFR_1", toggleMachine, {side=0, buttonList=buttonList, machineList=cMList, alt=true}, width, height, padding, "0x00AA00:0xAA00AA", false))
  81. table.insert(buttonList, button.newButton(buttonList, "MFR_2", toggleMachine, {side=0, buttonList=buttonList, machineList=cMList, alt=true}, width, height, padding, "0x00AA00:0xAA00AA", false))
  82.  
  83. -- Slaughterhouse control
  84. table.insert(buttonList, button.newButton(buttonList, "Slaughterhouse", toggleMachine, {side=0, buttonList=buttonList, machineList=cMList, alt=true}, width, height, padding, "0x00AA00:0xAA00AA", false))
  85.  
  86. -- Main grinder control
  87. table.insert(buttonList, button.newButton(buttonList, "Grinders", toggleMachine, {side=0, buttonList=buttonList, machineList=cMList, alt=true}, width, height, padding, "0x00AA00:0xAA00AA", true))
  88.  
  89. -- Killer Joe control
  90. table.insert(buttonList, button.newButton(buttonList, "Killer_Joe", toggleMachine, {side=0, buttonList=buttonList, machineList=cMList, alt=true}, width, height, padding, "0x00AA00:0xAA00AA", true))
  91.  
  92. -- Reboot button
  93. table.insert(buttonList, button.newButton(buttonList, "REBOOT", reboot, {}, width, height, padding, "0x5555FF:0x5555FF", false))
  94.  
  95. -- Retrieve redstone component
  96. comps, compNames = findComps("redstone")
  97. rs = comps[1]
  98.  
  99. -- Default states for these buttons
  100. rs.setBundledOutput(actionArgT.side, cMList.Slaughterhouse, 250)
  101. rs.setBundledOutput(actionArgT.side, cMList.MFR_1, 250)
  102. rs.setBundledOutput(actionArgT.side, cMList.MFR_2, 250)
  103.  
  104. button.renderAll(buttonList)
  105. while true do
  106. local x, y
  107. if event then
  108. _, _, x, y = event.pull("touch")
  109. else
  110. xMax,xMin,yMax,yMin = os.pullEvent("monitor_touch")
  111. end
  112.  
  113. local buttonList, pressed, onButton = button.checkTouch(buttonList, x, y)
  114. if onButton then button.render(pressed) else button.renderAll(buttonList) end
  115. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement