Guest User

startup

a guest
Jul 16th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.45 KB | None | 0 0
  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 updateScreen()
  42.   m.clear()
  43.   m.setCursorPos(1, 1)
  44.   for k, v in pairs(powerValues) do
  45.     m.write(v["Name"] ..": " ..v["Value"])
  46.     x, y = m.getCursorPos()
  47.     m.setCursorPos(1, y + 1)
  48.   end
  49. end
  50.  
  51. function updateValues()
  52.   tempValues = {}
  53.   tempValues[1] = {}
  54.   tempValues[1]["Name"] = "Energy"
  55.   tempValues[1]["Value"] = addCommas(cells()) .." / " ..addCommas(cellsMax())
  56.   tempValues[2] = {}
  57.   tempValues[2]["Name"] = "Reactor Buffer"
  58.   tempValues[2]["Value"] = addCommas(r.getEnergyStored())
  59.   tempValues[3] = {}
  60.   tempValues[3]["Name"] = "Fuel"
  61.   tempValues[3]["Value"] = r.getFuelAmount()
  62.   tempValues[4] = {}
  63.   tempValues[4]["Name"] = "Waste"
  64.   tempValues[4]["Value"] = r.getWasteAmount()
  65.   tempValues[5] = {}
  66.   tempValues[5]["Name"] = "RF/T"
  67.   tempValues[5]["Value"] = r.getEnergyProducedLastTick()
  68.   if powerValues ~= tempValues then
  69.     powerValues = tempValues
  70.     updateScreen()
  71.   end
  72. end
  73.  
  74. x, y = m.getSize()
  75.  
  76. if buttonState then
  77.   m.setBackgroundColor(colors.lime)
  78. else
  79.   m.setBackgroundColor(colors.red)
  80. end
  81.  
  82. for i = 1, x, 1 do
  83.   m.setCursorPos(i, y - 2)
  84.   m.write(" ")
  85. end
  86. start = (x / 2) - (string.len(buttonLabel) / 2)
  87. End = start + string.len(buttonLabel)
  88. counter = 1
  89. for i = 1, x, 1 do
  90.   m.setCursorPos(i, y - 1)
  91.   if i < start and i > End then
  92.     m.write(" ")
  93.   else
  94.     m.write(string.sub(buttonLabel, counter, counter))
  95.     counter = counter + 1
  96.   end
  97. end
  98. m.setBackgroundColor(colors.black)
  99. while true do
  100.   updateValues()
  101.   sleep(0.1)
  102. end
Advertisement
Add Comment
Please, Sign In to add comment