Advertisement
ben_mkiv

wirelessRedstoneClient.lua

Apr 21st, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.81 KB | None | 0 0
  1. require ("package").loaded.borders = nil
  2. require ("package").loaded.hazeUI = nil
  3. require ("package").loaded.wirelessRedstone = nil
  4. require ("package").loaded.wirelessRedstoneGUI = nil
  5.  
  6.  
  7. component = require("component")
  8. sides = require("sides")
  9.  
  10. require("wirelessRedstoneGUI")
  11.  
  12. configFile = "/etc/wirelessRedstone.conf"
  13.  
  14. titleBar = gui:addButton(1, 1, 80, 1, "wireless redstone", "all", 0x282828, 0xFFB000, "left")
  15.  
  16. statusBar = gui:addButton(1, 25, 80, 1, "starting...", "all", 0x282828, 0xFFB000, "left")
  17.  
  18. gui.gpu.setResolution(80,25)
  19. gui:drawScreen("all")
  20. gui:setElement({index = titleBar, cb = "drawMain"})
  21.  
  22.  
  23. io.write("waking up clients... ")
  24. wakeup()
  25. print("done.")
  26.  
  27. config = loadConfig(configFile)
  28.  
  29. if not config.outputs then
  30.     config.outputs = {}
  31. end
  32.  
  33. if not config.entityDetector then
  34.     config.entityDetector = {}
  35.     config.entityDetector.side = sides.top
  36. end
  37.  
  38. if not config.grinder then
  39.     config.grinder = {}
  40.     config.grinder.side = sides.west
  41. end
  42.  
  43. grinderButton = false
  44.  
  45. function toggleGrinder()
  46.     local rs = component.redstone
  47.     local label = "grinder (?)"
  48.     local backgroundColor = 0xFFB000
  49.     if rs.getOutput(config.grinder.side) > 0 then
  50.         config.grinder.status = rs.setOutput(config.grinder.side, 0)
  51.         backgroundColor = 0x4E4E4E
  52.         label = "grinder (enable)"
  53.         status("grinder disabled", 2)
  54.     else
  55.         config.grinder.status = rs.setOutput(config.grinder.side, 15)
  56.         label = "grinder (disable)"
  57.         status("grinder enabled", 2)
  58.     end
  59.  
  60.     gui:setElement({ index = grinderButton, text = label, bg = backgroundColor })
  61.     gui:drawElement(gui.els[grinderButton])
  62. end
  63.  
  64. function gui:drawMain()
  65.     self:flushElements(true)
  66.     --self:setElement({index = titleBar, text = "wireless redstone"})
  67.     self:addButton(59, 3, 20, 2, "add output", "main", 0x282828, 0xFFB000, "left", addOutput)
  68.  
  69.     self:addButton(59, 6, 20, 2, "turn off (all)", "main", 0x282828, 0xFFB000, "left", turnOffAll)
  70.  
  71.     grinderButton = self:addButton(59, 9, 20, 2, "grinder (?)", "main", 0x282828, 0x4E4E4E, "left", toggleGrinder)
  72.  
  73.     for i=1,#config.outputs do
  74.         local bg = 0xFF841A
  75.  
  76.         if i%2 == 0 then bg = 0xFFB000 end
  77.  
  78.         local bIndex1 = self:addButton(2, 2+i, 40, 1, config.outputs[i].name, "main", 0x282828, bg, "left")
  79.  
  80.         local bIndex2 = self:addButton(42, 2+i, 5, 1, getStatusText(i), "main", 0x282828, bg, "center")
  81.         self:setElement({ index = bIndex1, cb = toggleOutputGUI, cb_parm = { output = i, button = bIndex2} })
  82.         self:setElement({ index = bIndex2, cb = toggleOutputGUI, cb_parm = { output = i, button = bIndex2} })
  83.  
  84.     end
  85.  
  86.     self:drawScreen("main")
  87. end
  88.  
  89. getDevices()
  90. getStatus()
  91.  
  92. gui:drawMain()
  93.  
  94. status("")
  95. event.listen("touch", touchEventHandler)
  96.  
  97. event.pull("interrupted")
  98.  
  99. closeTool()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement