Advertisement
Rnen10

DraconicEvolution Power Monitor Display

Jul 19th, 2020 (edited)
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Made by Rnen10
  2. -- If problems/questions feel free to contact me
  3. -- https://twitter.com/Rnen10
  4. -- rnen. (Evan#7181)  on discord
  5.  
  6. -- Program for displaying DraconicEvolution powercore as a percentage on a monitor.
  7.  
  8. -- =============VARIABLES===================
  9.  
  10. --Variable for when job is done
  11. local done = false
  12.  
  13. print("Displaying power levels on screen")
  14.  
  15. local power = peripheral.wrap("left")
  16. local mon = peripheral.wrap("monitor_1")
  17.  
  18. local monw, monh = mon.getSize()
  19. monw = monw + 1
  20.  
  21. -- ============VARIABLES END================
  22.  
  23. -- ============FUNCTIONS====================
  24. local function CalcScreenTextPos(Str)
  25.     local length = (math.ceil(monw / 2) - (math.floor(string.len(Str) / 2)))
  26.     if (length < 1) or (length >= (monw - 1)) then
  27.         return 1
  28.     else
  29.         return length
  30.     end
  31. end
  32.  
  33. local function NewLine(Str)
  34.     power = peripheral.wrap("left")
  35.     mon = peripheral.wrap("monitor_1")
  36.    
  37.     mon.clear()
  38.    
  39.     local barLength = monw
  40.     local tempPercentage = 0
  41.    
  42.     local str1 = "Energy Core"
  43.     mon.setCursorPos(CalcScreenTextPos(str1),1)
  44.     mon.write(str1)
  45.  
  46.     --local fuelStr = "[Current Fuel %"..(math.floor()).."]"
  47.     --mon.setCursorPos(CalcScreenTextPos(fuelStr),5)
  48.     --mon.write(fuelStr)
  49.     mon.setCursorPos(1,3)
  50.     barLength = power.getEnergyStored() / power.getMaxEnergyStored() * monw
  51.     if barLength > monw then barLength = monw end
  52.     if mon.isColor() then
  53.       mon.setBackgroundColor(colors.green)
  54.     else
  55.       mon.setBackgroundColor(colors.white)
  56.     end
  57.     for i =1,(barLength) do
  58.       mon.write(" ")
  59.     end
  60.     if barLength < (monw + 1)  then
  61.         if mon.isColor() then mon.setBackgroundColor(colors.red) else mon.setBackgroundColor(colors.gray) end
  62.         local remainingBarLength = (monw - barLength)
  63.         for i =1,(remainingBarLength) do
  64.           mon.write(" ")
  65.         end
  66.     end
  67.     mon.setBackgroundColor(colors.black)
  68.    
  69.     local str2 = "% "..tostring(math.floor((power.getEnergyStored() / power.getMaxEnergyStored()) * 10000) / 100)
  70.     mon.setCursorPos(CalcScreenTextPos(str2),5)
  71.     mon.write(str2)
  72. end
  73.  
  74.  
  75. -- ===========STARTUP SEQUENCE==========
  76.  
  77. -- ===========STARTUP SEQUENCE END======
  78.  
  79. -- ===========MAIN LOOP=================
  80. while not done do
  81.     NewLine("t")
  82.     sleep(1)
  83.   while not rs.getInput("back") do
  84.     sleep(8)
  85.   end  
  86. end
  87. -- ================Main Loop End=========================
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement