Advertisement
Plazter

[Draconic Evolution] PowerMonitoring

Mar 14th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.26 KB | None | 0 0
  1. component = require("component")
  2. sides = require("sides")
  3. term = require("term")
  4. gpu = component.gpu
  5.  
  6. if component.draconic_rf_storage ~= nil then
  7.   draco = component.draconic_rf_storage
  8.   print("Core Found, Wrapped!")
  9.   os.sleep(1)
  10.   else
  11.   print("Core not found..")
  12.   os.sleep(1)
  13. end
  14.  
  15. colors = { black = 0x000000, white = 0xf8f8ff, blue = 0x0000ff, lightGray = 0xd9d9d9, red = 0xff0000,
  16.             purple = 0x9b30ff, carrot = 0xffa500, magenta = 0xcd00cd, lightBlue = 0x87cefa, yellow = 0xffff00,
  17.             lime = 0x32cd32, pink = 0xffc0cb, gray = 0x696969, brown = 0x8b4500, green = 0x006400, cyan = 0x008b8b,
  18.             olive = 0x6b8e23, gold = 0x8b6914, orangered = 0xdb4e02, diamond = 0x0fa7c7,crimson = 0xaf002a,fuchsia = 0xfd3f92,
  19.             folly = 0xff004f, frenchBlue = 0x0072bb, lilac = 0x86608e, flax = 0xeedc82, darkGray = 0x563c5c,
  20.             englishGreen = 0x1b4d3e, eggplant = 0x614051, deepPink  = 0xff1493, ruby = 0x843f5b, orange = 0xf5c71a,
  21.             lemon = 0xffd300, darkBlue = 0x002e63, bitterLime = 0xbfff00
  22.             }
  23. -------------------------
  24.  
  25. --Vars --
  26.   Border_bg = colors.white
  27.   Default_bg = colors.gray
  28.   text_col = colors.white
  29.   Tier = nil
  30. ---------
  31.  
  32. -- Resolution --
  33. gpu.setResolution(54,7)
  34.  
  35. -------------------------
  36. -- Functions --
  37. function guiBorders(x,y,len,height,str)
  38.   gpu.setBackground(Border_bg)
  39.   gpu.fill(x,y,len,height,str)
  40.   gpu.setBackground(Default_bg)
  41. end
  42.  
  43. function GUI()
  44.   gpu.setBackground(Default_bg)
  45.   term.clear()
  46.   w,  h = gpu.getResolution()
  47.   guiBorders(1,1,w,1," ")
  48.     for i = 1,h do
  49.      guiBorders(1,i,1,1," ")
  50.      guiBorders(w,i,1,1," ")
  51.     end
  52.   guiBorders(1,h,w,1," ")
  53.   gpu.setForeground(text_col)
  54. end
  55.  
  56. function Center(y,text)
  57.     w, h = gpu.getResolution()
  58.     term.setCursor((w-string.len(text))/2+1, y)
  59.     term.write(text)
  60. end
  61.  
  62. function comma_value(n) -- credit http://richard.warburton.it
  63.   local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
  64.   return left..(num:reverse():gsub('(%d%d%d)','%1.'):reverse())..right
  65. end
  66.  
  67. function Disp()
  68.   Center(2,"POWER STORAGE")
  69.   cut = string.len(tostring(current))
  70.   gpu.set(3,3,"Stored....: ")
  71.   Center(4,"     "..comma_value(string.format("%.i",current)) .." / ".. tier .." RF  ("..string.format("%.3f",             
  72.   tostring((current/cap)*100)) .."%)")
  73. end
  74.  
  75. GUI()
  76.  
  77. while true do
  78.   current = draco.getEnergyStored()
  79.     if draco.getMaxEnergyStored() > 2140000000000 then
  80.       tier = tostring("∞")
  81.     else
  82.      tier = comma_value(tostring(draco.getMaxEnergyStored()))
  83.     end
  84.  
  85.   cap = draco.getMaxEnergyStored()
  86.   currentP = math.floor(current/cap*100)
  87.   capP = math.floor(cap/cap*100)
  88.   Disp()
  89.   -- Update the Use --
  90.     gpu.set(3,5, "Usage.....: ")
  91.     OldCurrent = current
  92.     os.sleep(1)
  93.     Center(6,"                             ")
  94.     Current = draco.getEnergyStored()
  95.       if Current > OldCurrent then
  96.         gpu.setForeground(colors.lime)
  97.         Center(6,"+"..comma_value(string.format("%.f", ((Current-OldCurrent)/20))).. " RF/t ")
  98.         gpu.setForeground(text_col)
  99.       elseif Current < OldCurrent then
  100.         gpu.setForeground(colors.red)
  101.         Center(6,"  "..comma_value(string.format("%.f",((Current-OldCurrent)/20))) .. " RF/t ")
  102.         gpu.setForeground(text_col)
  103.       end
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement