Advertisement
Guest User

startup

a guest
Dec 17th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.64 KB | None | 0 0
  1. reactor = peripheral.wrap("back")
  2. mon = peripheral.wrap("monitor_6")
  3. currentprod = 0
  4. mon.setTextScale(0.5)
  5. monX, monY = mon.getSize()
  6. function drawText(x, y, text, color, bg_color)
  7.   mon.setCursorPos(x, y)
  8.   mon.setTextColor(color)
  9.   mon.setBackgroundColor(bg_color)
  10.   mon.write(text)
  11.   mon.setBackgroundColor(colors.black)
  12. end
  13.  
  14. function save(datatosave)
  15.   ih = fs.open("productions.txt", "w")
  16.   ih.write(datatosave)
  17.   ih.close()
  18. end
  19.  
  20. function load(source)
  21.   if fs.exists(source) == true then
  22.     ih = fs.open(source, "r")
  23.     data = ih.readAll()
  24.     ih.close()
  25.    
  26.     return tostring(data)
  27.   end
  28. end
  29. highestprod = load("productions.txt")
  30.  
  31. function drawLine(x, y, width, height, color)
  32.   for yPos = y, y+height-1 do
  33.     mon.setBackgroundColor(color)
  34.     mon.setCursorPos(x, yPos)
  35.     mon.write(string.rep(" ", width))
  36.   end
  37. end
  38.  
  39. function drawProgress(x, y, width, height, minVal, maxVal, color_bg, color_bar)
  40.   drawLine(x, y, width, height, color_bg)
  41.   local barSize = math.floor((minVal/maxVal)*width)
  42.   drawLine(x, y, barSize, height, color_bar)
  43.   local text = math.floor((minVal/maxVal)*100).."%"
  44.   if barSize > monX/2+#text/2 then
  45.     drawText(monX/2, y+height/2, text, colors.black, color_bar)
  46.   elseif barSize > #text then
  47.     drawText((x+barSize)-string.len(tostring(text)), y+height/2, text, colors.black, color_bar)
  48.   else
  49.     drawText(monX/2, y+height/2, text, colors.black, color_bg)
  50.   end
  51.   --drawText(monX/2, y+height/2, tostring(text.."%"), colors.black, colors.red)
  52. end
  53.  
  54. function clearMon()
  55.   mon.clear()
  56.   mon.setBackgroundColor(colors.black)
  57. end
  58.  
  59. while true do
  60.   sleep(0.2)
  61.   clearMon()
  62.   if reactor.getActive() == true then
  63.     drawText((monX/2-string.len("   Online   ")/2), 1, "     Online     ", colors.black, colors.green)
  64.   end
  65.   if reactor.getActive() == false then
  66.     drawText((monX/2-string.len("     offline    ")/2), 1, "     Offline     ", colors.black, colors.red)
  67.   end
  68.   -- information --
  69.   local energy = reactor.getEnergyStored()
  70.   drawText(1, 2, "     Power       ", colors.black, colors.gray)
  71.   drawProgress(1, 3,monX, 1, energy, 10000000, colors.red, colors.green)
  72.  
  73.   -- draw production --
  74.   currentprod = reactor.getEnergyProducedLastTick()
  75.   if currentprod > tonumber(highestprod) then
  76.     highestprod = currentprod
  77.     save(highestprod)
  78.   end
  79.   drawText(1, 4, "Production:", colors.white, colors.black)
  80.   drawText(1, 5, tostring(math.floor(highestprod)).."RF/T", colors.white, colors.black)
  81.  
  82.   -- logic --
  83.   if reactor.getEnergyStored() == 10000000 then
  84.     reactor.setActive(false)
  85.   end
  86.   if reactor.getEnergyStored() <= 100000 then
  87.     reactor.setActive(true)
  88.   end
  89. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement