Advertisement
lokin135

EU logger

Nov 25th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | None | 0 0
  1. local com = require('component')
  2. local term = require("term")
  3. local gpu = com.gpu
  4. local background = 0x161a1e
  5. local foreground = 0xf5f5f5
  6. local timeSleep = 2
  7. local components = {"mfe","chargepad_mfe","mfsu","chargepad_mfsu"}
  8. local totalEU
  9. local growth
  10. local mf
  11. local graph = {
  12.  [1]={
  13.   ["EU"] = 0,
  14.   ["y"] = 1,
  15.   ["color"] = 0xb32821,
  16.   ["colorShadow"] = 0x591410
  17.  }
  18. }
  19.  
  20. local function componentTest()
  21.  local noComponent = true
  22.  for i=1,#components do
  23.   if com.isAvailable(components[i]) then
  24.    noComponent = false
  25.    mf = com[components[i]]
  26.   end
  27.  end
  28.  if noComponent then
  29.   print("Не подключен энергохранитель через адаптер!")
  30.   os.exit()
  31.  end
  32. end
  33.  
  34. local function init()
  35.  componentTest()
  36.  totalEU = mf.getCapacity()
  37.  gpu.setResolution(80,40)
  38.  gpu.setBackground(background)
  39.  gpu.setForeground(foreground)
  40.  term.clear()
  41. end
  42.  
  43. local function drawBar()
  44.  gpu.fill(1,1,80,1," ")
  45.  gpu.set(1,1,"Хранится EU: "..graph[#graph].EU.." из "..totalEU.." | Прирост: "..growth)
  46.  gpu.set(70,1,"by lokin135")
  47.  gpu.fill(1,2,80,1,"_")
  48. end
  49.  
  50. local function drawGraph()
  51.  for i=1,#graph do
  52.   gpu.setBackground(background)
  53.   gpu.fill(i,3,1,(40-graph[i].y)-3," ")
  54.   gpu.setForeground(graph[i].color)
  55.   gpu.setBackground(graph[i].color)
  56.   gpu.set(i,(40-graph[i].y),"X")
  57.   gpu.setForeground(graph[i].colorShadow)
  58.   gpu.setBackground(graph[i].colorShadow)
  59.   gpu.fill(i,(40-graph[i].y)+1,1,40,"X")
  60.  end
  61.  gpu.setForeground(foreground)
  62.  gpu.setBackground(background)
  63. end
  64.  
  65. local function calculGraph()
  66.  local EUNow = mf.getStored()
  67.  local nextGraph = graph
  68.  growth = EUNow - graph[#graph].EU
  69.  local nextY = math.ceil((EUNow / totalEU) * 40)
  70.  nextGraph[#graph+1] = {}
  71.  if not (#graph <= 80) then
  72.   table.remove(graph,1)
  73.  end
  74.  if nextY > 37 then
  75.   nextGraph[#graph].y = 37
  76.  else if nextY < 2 then
  77.   nextGraph[#graph].y = 1
  78.  else
  79.   nextGraph[#graph].y = nextY
  80.  end
  81.  end
  82.  nextGraph[#graph].EU = EUNow
  83.  if growth > 1024 then
  84.   nextGraph[#graph].color = 0x27a327
  85.   nextGraph[#graph].colorShadow = 0x145214
  86.   else if growth < -1024 then
  87.    nextGraph[#graph].color = 0xb32821
  88.    nextGraph[#graph].colorShadow = 0x591410
  89.   else
  90.    nextGraph[#graph].color = 0x007dff
  91.    nextGraph[#graph].colorShadow = 0x004a99
  92.   end
  93.  end
  94. end
  95.  
  96. init()
  97. while true do
  98.  calculGraph()
  99.  drawBar()
  100.  os.sleep(timeSleep)
  101.  drawGraph()
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement