Advertisement
Plazter

Base Control

Oct 1st, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.26 KB | None | 0 0
  1. component = require("component")
  2. term = require("term")
  3. gpu = component.gpu
  4. event = require("event")
  5. sides = require("sides")
  6. computer = require("computer")
  7. os = require("os")
  8. draco = component.draconic_rf_storage
  9. screen = component.screen
  10. keyboard = require("keyboard")
  11. shell = require("shell")
  12.  
  13. ---------- Redstone Signals -----
  14.  
  15. VoidMiner = component.proxy(component.get("d9eb04c1-7556-4a56-a8c5-ee5cf1116d1a"))
  16. AE = component.proxy(component.get("d9ecdcd0-b816-4da2-a6ad-3428e60955ea"))
  17. ResourceMiner = component.proxy(component.get("d9eb04c1-7556-4a56-a8c5-ee5cf1116d1a")) --b9222075-1f93-4bed-ac1a-c2901f6582f7"))
  18.  
  19. ---------- TABLES -----------
  20. colors = { black = 0x000000, white = 0xf8f8ff, blue = 0x0000ff, lightGray = 0xd9d9d9, red = 0xff0000,
  21. purple = 0x9b30ff, carrot = 0xffa500, magenta = 0xcd00cd, lightBlue = 0x87cefa, yellow = 0xffff00,
  22. lime = 0x32cd32, pink = 0xffc0cb, gray = 0x696969, brown = 0x8b4500, green = 0x006400, cyan = 0x008b8b,
  23. olive = 0x6b8e23, gold = 0x8b6914, orangered = 0xdb4e02, diamond = 0x0fa7c7,crimson = 0xaf002a,fuchsia = 0xfd3f92,
  24. folly = 0xff004f, frenchBlue = 0x0072bb, lilac = 0x86608e, flax = 0xeedc82, darkGray = 0x563c5c,
  25. englishGreen = 0x1b4d3e, eggplant = 0x614051, deepPink  = 0xff1493, ruby = 0x843f5b, orange = 0xf5c71a,
  26. lemon = 0xffd300, darkBlue = 0x002e63, bitterLime = 0xbfff00 } --doesn't this look very fucking fancy :3
  27.  
  28. ------- VARIABLES -------------
  29.  
  30. Border_bg = colors.diamond
  31. Default_bg = colors.gray
  32. text_col = colors.blue
  33. status_col = colors.black
  34. barBack = colors.black
  35. barFill = colors.white
  36. header = colors.orange
  37. Applied = true
  38. VoidMine = true
  39. Resource = true
  40.  
  41. --Side = sides.east
  42.  
  43. -------- FUNCTIONS --------------
  44.  
  45. args, options = shell.parse(...)
  46.  
  47. function guiBorders(x,y,len,height,str) -- BORDER FUNC FOR GUI
  48.   gpu.setBackground(Border_bg)
  49.   gpu.fill(x,y,len,height,str)
  50.   gpu.setBackground(Default_bg)
  51. end
  52.  
  53. function init()
  54.   fileWrite("/etc/output.log", getTime() .. ": " .. "Base Control initialized", false)
  55.   screen.setTouchModeInverted(true)
  56.   prevApplied = nil
  57.   prevVoidMine = nil
  58.   prevResource = nil
  59.   if options.c then
  60.     os.execute("/home/ClearLog.lua")
  61.   end
  62. end
  63.  
  64. function getTime()
  65.   internet = require("component").internet
  66.   page = internet.request("http://worldclockapi.com/api/jsonp/cet/now?callback=mycallback")
  67.   repeat
  68.   file = page.read()
  69.   until file ~= ""
  70.   a,b = file:find("%d+%-%d+%-%d..%d+:%d+")
  71.   c = file:sub(a, b):find("T")
  72.   time = "[" .. file:sub(a, a + c - 2) .. " " .. file:sub(a + c, b) .. "]"
  73.   return time
  74. end
  75.  
  76. function fileWrite(fileLocation, str, isOverwrite)
  77.   if isOverwrite==true then mode = "w" else mode = "a" end
  78.   f = io.open(tostring(fileLocation),mode)
  79.   f:write(tostring(str).."\n")
  80.   f:close()
  81. end
  82.  
  83. function GUI() -- SETS THE GUI LAYOUT (GRAPHICAL USER INTERFACE)
  84.   gpu.setBackground(Default_bg)
  85.   term.clear()
  86.   w,  h = gpu.getResolution()
  87.   guiBorders(1,1,w,1," ")
  88.   guiBorders(1,5,w,1," ")
  89.     for i = 1,h do
  90.       guiBorders(1,i,1,1," ")
  91.       guiBorders(w,i,1,1," ")
  92.     end
  93.     for i = 5,h do
  94.       --guiBorders(7,i,1,5," ")
  95.     end
  96.   for i = 5,h do
  97.     --guiBorders(w-6, i,1,5," ")
  98.   end
  99.   guiBorders(1,h,w,1," ")
  100.   gpu.setForeground(header)
  101.   Center(3,"--[[ Base Control ]]--")
  102. end
  103.  
  104. function comma_value(n) -- credit http://richard.warburton.it
  105.   local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
  106.   return left..(num:reverse():gsub('(%d%d%d)','%1.'):reverse())..right
  107. end
  108.  
  109.  
  110. function Center(y, text)
  111.   w, h = gpu.getResolution()
  112.   term.setCursor((w-string.len(text))/2+1, y)
  113.   term.write(text)
  114. end
  115.  
  116. function addButton(x, y, col,text)
  117.   leng = string.len(text)
  118.   gpu.setBackground(col)
  119.   gpu.fill(x, y, (leng + 2), 3," ")
  120.   gpu.setForeground(status_col)
  121.   gpu.set(x+1, y+1, text)
  122.   gpu.setBackground(Default_bg)
  123. end
  124.  
  125. function infoUpdate(y, text) -- Text for function UPDATE
  126.   w, h = gpu.getResolution()
  127.   place = (w-string.len(text))-2
  128.   gpu.set(place, y, text)
  129. end
  130.  
  131. function detect(player)
  132.   if Applied == true then
  133.     addButton(10,10, colors.lime, "Applied Energistics")
  134.     if prevApplied == false and player ~= nil then
  135.       fileWrite("/etc/output.log", getTime() .. ": " .. player .. " enabled Applied", false)
  136.       AE.setOutput(sides.north, 15)
  137.     end
  138.     prevApplied = Applied
  139.   elseif Applied == false then
  140.     addButton(10,10, colors.red  ,"Applied Energistics")
  141.     if prevApplied == true and player ~= nil then
  142.       fileWrite("/etc/output.log", getTime() .. ": " .. player .. " disabled Applied", false)
  143.       AE.setOutput(sides.north, 0)
  144.     end
  145.     prevApplied = Applied
  146.   end
  147.  
  148.   if VoidMine == true then
  149.     addButton(10, 15, colors.lime,"Void Miner         ")
  150.     if prevVoidMine == false and player ~= nil then
  151.       fileWrite("/etc/output.log", getTime() .. ": " .. player .. " enabled Void Miner", false)
  152.       VoidMiner.setOutput(sides.north, 0)
  153.     end
  154.     prevVoidMine = VoidMine
  155.   elseif VoidMine == false then
  156.     addButton(10,15, colors.red, "Void Miner         ")
  157.     if prevVoidMine == true and player ~= nil then
  158.       fileWrite("/etc/output.log", getTime() .. ": " .. player .. " disabled Void Miner", false)
  159.       VoidMiner.setOutput(sides.north, 15)
  160.     end
  161.     prevVoidMine = VoidMine
  162.   end
  163.  
  164.   if Resource == true then
  165.     addButton(10,20, colors.lime, "Resource Miner     ")
  166.     if prevResource == false and player ~= nil then
  167.       fileWrite("/etc/output.log", getTime() .. ": " .. player .. " enabled Resource", false)
  168.       ResourceMiner.setOutput(sides.east, 0)
  169.     end
  170.     prevResource = Resource
  171.   elseif Resource == false then
  172.     addButton(10,20, colors.red, "Resource Miner     ")
  173.     if prevResource == true and player ~= nil then
  174.       fileWrite("/etc/output.log", getTime() .. ": " .. player .. " disabled Resource", false)
  175.       ResourceMiner.setOutput(sides.east, 15)
  176.     end
  177.     prevResource = Resource
  178.   end
  179. end
  180.  
  181. function Toggle()
  182.     if x >= 10 and x <= 28 and y >= 10 and y <= 13 then
  183.       if Applied == true then
  184.         Applied = false
  185.     elseif Applied == false then
  186.         Applied = true
  187.        
  188.       end
  189.     end
  190.  
  191.     if x >= 10 and x <= 28 and y >= 15 and y <= 17 then
  192.       if VoidMine == true then
  193.         VoidMine = false
  194.       elseif VoidMine == false then
  195.         VoidMine = true
  196.       end
  197.     end -- Void
  198.    
  199.     if x >= 10 and x <= 28 and y>= 20 and y <= 23 then
  200.       if Resource == true then
  201.         Resource = false
  202.         elseif Resource == false then
  203.         Resource = true
  204.       end
  205.     end   -- Resource
  206. end
  207.  
  208. function powerDisp()
  209.   cap = draco.getMaxEnergyStored()
  210.   capP = math.floor(cap/cap*100)
  211.  
  212.   infoUpdate(6, "Power:                                       ")
  213.   --[[if draco.getMaxEnergyStored() > 2140000000000 then
  214.       cap = tostring("∞")
  215.     else
  216.       cap = comma_value(tostring(draco.getMaxEnergyStored()))
  217.     end
  218.   --]]
  219.   infoUpdate(7, comma_value(string.format("%.i",current)) .." / ".. comma_value(string.format("%.f", (cap))).." RF  ")
  220.  
  221.   infoUpdate(8, "Usage:                                       ")
  222.  
  223.   OldCurrent = current
  224.  
  225.   Current = draco.getEnergyStored()
  226.  
  227.   if Current > OldCurrent then
  228.     gpu.setForeground(colors.lime)
  229.     infoUpdate(9,"      +"..comma_value(string.format("%.f", ((Current-OldCurrent)/20))).. " RF/t    ")
  230.     gpu.setForeground(colors.white)
  231.   elseif Current < OldCurrent then
  232.     gpu.setForeground(colors.red)
  233.     infoUpdate(9,"       "..comma_value(string.format("%.f",((Current-OldCurrent)/20))) .. " RF/t   ")
  234.     gpu.setForeground(colors.white)
  235.   end
  236. end
  237.  
  238. gpu.setResolution(150,30)
  239. init()
  240. GUI()
  241.  
  242. while true do
  243.   current = draco.getEnergyStored()
  244.   OldCurrent = current
  245.   startTime = computer.uptime()
  246.  
  247.   _,_,x,y,_,player = event.pull(1,"touch")
  248.  
  249.   if x~=nil and y~= nil then
  250.     Toggle()
  251.   end
  252.   detect(player)
  253.  
  254.   gpu.setForeground(colors.white)
  255.   powerDisp()
  256.   if keyboard.isControlDown() then break end
  257.  
  258.   while computer.uptime() < startTime + 1 do
  259.     os.sleep(0.05)
  260.   end
  261. end
  262. gpu.setForeground(0xffffff)
  263. gpu.setBackground(0x000000)
  264. gpu.setResolution(gpu.maxResolution())
  265. term.clear()
  266. screen.setTouchModeInverted(false)
  267. print("You've terminated Base Control")
  268. _, _, _, _, player = event.pull("key_up")
  269. fileWrite("/etc/output.log", getTime() .. ": " .. player .." terminated Base Control", false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement