Bydon

Untitled

Jul 16th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. m = peripheral.wrap("monitor_2")
  2. r = peripheral.wrap("back")
  3. c1 = peripheral.wrap("tile_thermalexpansion_cell_hardened_name_2")
  4. c2 = peripheral.wrap("tile_thermalexpansion_cell_hardened_name_3")
  5. c3 = peripheral.wrap("tile_thermalexpansion_cell_hardened_name_4")
  6. --capacitors = 4
  7.  
  8. buttonState = r.getActive()
  9. buttonLabel = ""
  10. if buttonState then
  11.   buttonLabel = "Active"
  12. else
  13.   buttonLabel = "Inactive"
  14. end
  15.  
  16. powerValues = {}
  17.  
  18. function cells()
  19.   return c1.getEnergyStored() + c2.getEnergyStored() + c3.getEnergyStored()
  20. end
  21.  
  22. function cellsMax()
  23.   return c1.getMaxEnergyStored() + c2.getMaxEnergyStored() + c3.getMaxEnergyStored()
  24. end
  25.  
  26. function addCommas(int)
  27.   str = tostring(int)
  28.   newStr = ""
  29.   counter = 1
  30.   for i = string.len(str), 1, -1 do
  31.     if counter %3 == 0 then
  32.       newStr = "," ..string.sub(str, i, i) ..newStr
  33.     else
  34.       newStr = string.sub(str, i, i) ..newStr
  35.     end
  36.     counter = counter + 1
  37.   end
  38.   return newStr
  39. end
  40.  
  41. function addButton()
  42. x, y = m.getSize()
  43.  
  44. if buttonState then
  45.   m.setBackgroundColor(colors.lime)
  46. else
  47.   m.setBackgroundColor(colors.red)
  48. end
  49.  
  50. for i = 1, x, 1 do
  51.   m.setCursorPos(i, y - 2)
  52.   m.write(" ")
  53. end
  54. start = (x / 2) - (string.len(buttonLabel) / 2)
  55. End = start + string.len(buttonLabel)
  56. counter = 1
  57. for i = 1, x, 1 do
  58.   m.setCursorPos(i, y - 1)
  59.   if i < start and i > End then
  60.     m.write(" ")
  61.   else
  62.     m.write(string.sub(buttonLabel, counter, counter))
  63.     counter = counter + 1
  64.   end
  65. end
  66. m.setBackgroundColor(colors.black)
  67. end
  68. function updateScreen()
  69.   m.clear()
  70.   m.setCursorPos(1, 1)
  71.   for k, v in pairs(powerValues) do
  72.     m.write(v["Name"] ..": " ..v["Value"])
  73.     x, y = m.getCursorPos()
  74.     m.setCursorPos(1, y + 1)
  75.   end
  76. end
  77.  
  78. function updateValues()
  79.   tempValues = {}
  80.   tempValues[1] = {}
  81.   tempValues[1]["Name"] = "Energy"
  82.   tempValues[1]["Value"] = addCommas(cells()) .." / " ..addCommas(cellsMax())
  83.   tempValues[2] = {}
  84.   tempValues[2]["Name"] = "Reactor Buffer"
  85.   tempValues[2]["Value"] = addCommas(r.getEnergyStored())
  86.   tempValues[3] = {}
  87.   tempValues[3]["Name"] = "Fuel"
  88.   tempValues[3]["Value"] = r.getFuelAmount()
  89.   tempValues[4] = {}
  90.   tempValues[4]["Name"] = "Waste"
  91.   tempValues[4]["Value"] = r.getWasteAmount()
  92.   tempValues[5] = {}
  93.   tempValues[5]["Name"] = "RF/T"
  94.   tempValues[5]["Value"] = r.getEnergyProducedLastTick()
  95.   if powerValues ~= tempValues then
  96.     powerValues = tempValues
  97.     updateScreen()
  98.   end
  99. end
  100.  
  101. while true do
  102.   updateValues()
  103.   sleep(0.1)
  104. end
Advertisement
Add Comment
Please, Sign In to add comment