Advertisement
Alakazard12

OC Monitor

Apr 21st, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.76 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local gpu = component.gpu
  4. local matrix = component.induction_matrix
  5. local me = component.aemultipart
  6.  
  7. local oWidth, oHeight = gpu.getResolution()
  8.  
  9. local width, height = 124, 40
  10. gpu.setResolution(width, height)
  11.  
  12. local gColor = 1
  13. local bColor = 2
  14. local tColor = 3
  15. local iColor = 4
  16.  
  17. gpu.setPaletteColor(1, 0x00FF00)
  18. gpu.setPaletteColor(2, 0xFF0000)
  19. gpu.setPaletteColor(3, 0xFFFFFF)
  20. gpu.setPaletteColor(4, 0x3366FF)
  21.  
  22. gpu.setPaletteColor(15, 0x333333)
  23. gpu.setBackground(15, true)
  24. gpu.fill(1, 1, width, height, " ")
  25.  
  26. --[[
  27. local item_names = {}
  28.  
  29. local original = {}
  30.  
  31. do
  32.   local items = me.getAvailableItems()
  33.  
  34.   for _, itemid in ipairs(items) do
  35.     local fp = itemid.fingerprint
  36.     original[fp.id .. "::" .. fp.dmg] = itemid.size
  37.   end
  38. end
  39. ]]
  40.  
  41. local function centerWrite(text, y)
  42.   local x = (width - text:len()) / 2
  43.   gpu.set(x, y, text)
  44. end
  45.  
  46. local function endWrite(text, y)
  47.   local x = width - text:len() + 1
  48.   gpu.set(x, y, text)
  49. end
  50.  
  51. local barY = math.floor(height / 2)
  52. local textY = barY - 2
  53. local infoY = barY + 2
  54.  
  55. local maxpower = matrix.getMaxEnergy()
  56.  
  57. local powerUnits = {"J", "KJ", "MJ", "GJ"}
  58.  
  59. local function formatPower(j) -- J?
  60.   -- local j = p * 2.5
  61.  
  62.   local unit = 1
  63.   for i = 1, #powerUnits - 1 do
  64.     if j > 1000 then
  65.       j = j / 1000
  66.       unit = unit + 1
  67.     else
  68.       break
  69.     end
  70.   end
  71.  
  72.   return string.format("%.2f %s", j, powerUnits[unit])
  73. end
  74.  
  75. local function refresh()
  76.   local power = matrix.getEnergyStored()
  77.   local input = matrix.getInput()
  78.   local output = matrix.getOutput()
  79.  
  80.   local tWidth = width - 4
  81.   local pWidth = math.ceil((power / maxpower) * tWidth)
  82.   local mWidth = tWidth - pWidth
  83.  
  84.   gpu.setBackground(1, true)
  85.   gpu.fill(3, barY, pWidth, 1, " ")
  86.   gpu.setBackground(2, true)
  87.   gpu.fill(3 + pWidth, barY, mWidth, 1, " ")
  88.  
  89.   gpu.setBackground(15, true)
  90.   gpu.setForeground(tColor, true)
  91.   centerWrite("Induction Matrix " .. formatPower(power) .. " / " .. formatPower(maxpower) .. " (" .. math.ceil(power / maxpower * 100) .. "%)", textY)
  92.   gpu.setForeground(iColor, true)
  93.   gpu.fill(1, infoY, width, 1, " ")
  94.   gpu.set(3, infoY, "Input: " .. formatPower(input) .. "/t")
  95.   endWrite("Output: " .. formatPower(output) .. "/t  ", infoY)
  96.  
  97.   --[[
  98.   local items = me.getAvailableItems()
  99.  
  100.   local removed = {}
  101.  
  102.   for _, itemid in ipairs(items) do
  103.  
  104.   end]]
  105. end
  106.  
  107. local suc, err = pcall(function()
  108.   while true do
  109.     local name = event.pull(2)
  110.     if name == "interrupted" then
  111.       break
  112.     end
  113.     refresh()
  114.   end
  115. end)
  116.  
  117. gpu.setBackground(0x000000)
  118. gpu.setForeground(0xFFFFFF)
  119.  
  120. gpu.setResolution(oWidth, oHeight)
  121. require("term").clear()
  122.  
  123. if not suc then
  124.   print("program forcefully interrupted")
  125. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement