Advertisement
JoeZwet

HRZN Staff Server Display Script v0.1

Sep 21st, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.95 KB | None | 0 0
  1. -- HRZN Staff Server Display v0.1
  2. --  _    _   _____    ______  _   _
  3. -- | |  | | |  __ \  |___  / | \ | |
  4. -- | |__| | | |__) |    / /  |  \| |
  5. -- |  __  | |  _  /    / /   | . ` |
  6. -- | |  | | | | \ \   / /__  | |\  |
  7. -- |_|  |_| |_|  \_\ /_____| |_| \_|
  8. --                                  
  9. --      https://hrznstudio.com
  10.  
  11. -- Script by JoeZwet
  12.  
  13. -- CONFIG (c_mod_var)
  14.  
  15. local c_global_display_time = 10 -- Seconds
  16.  
  17. local c_ae2_1k_count = 12
  18. local c_ae2_4k_count = 1
  19. local c_ae2_16k_count = 0
  20. local c_ae2_64k_count = 0
  21. local c_ec2_256k_count = 0
  22. local c_ec2_1024k_count = 0
  23. local c_ec2_4096k_count = 0
  24. local c_ec2_16384k_count = 0
  25.  
  26. -- General Init
  27. local bRunning = true
  28. local monitor = peripheral.find("monitor")
  29. local g_tabs = {"ME", "GC"}
  30. local g_w, g_h = term.getSize()
  31. term.setBackgroundColor(colors.black)
  32. term.clear()
  33. print("Press `q` to exit.")
  34. term.redirect(monitor)
  35. term.clear()
  36.  
  37.  
  38. -- AE2 Init
  39. local ae2_cell = (c_ae2_1k_count * 1024) + (c_ae2_4k_count * 4096) + (c_ae2_16k_count * 16384) + (c_ae2_64k_count * 65536) + (c_ec2_256k_count * 262144) + (c_ec2_1024k_count * 1048576) + (c_ec2_4096k_count * 4194304) + (c_ec2_16384k_count * 16777216)
  40. local ae2_bridge = peripheral.find("meBridge")
  41. local ae2_kilo = 1024
  42. local ae2_units = {"B", "KiB", "MiB", "GiB", "TiB"}
  43.  
  44.  
  45. -- Display functions
  46. function ae2_draw_line( text, amount )
  47.     local magnitude = math.floor(math.log(amount) / math.log(ae2_kilo))
  48.     local str = tostring(amount / ae2_kilo ^ magnitude):match("^(%d+%.?%d?%d?)%d*0*$") .. ae2_units[magnitude + 1]
  49.     return str
  50. end
  51.  
  52.  
  53. function draw_text( x, y, text, color, bg )
  54.     term.setCursorPos( x, y )
  55.     term.setTextColor( color )
  56.     term.setBackgroundColor( bg )
  57.     term.write(text)
  58. end
  59.  
  60. function d_ae2()
  61.     local totalSize = 0
  62.  
  63.     for number, item in pairs(ae2_bridge.listItems()) do
  64.         totalSize = totalSize + item.amount
  65.         totalSize2 = number
  66.     end
  67.  
  68.     draw_text(2, 5, "HDD: "..ae2_cell, colors.white, colors.black)
  69.     draw_text(2, 6, "Byte Used: "..totalSize, colors.white, colors.black)
  70.     draw_text(2, 7, "Type: "..totalSize2*513, colors.white, colors.black)
  71. end
  72.  
  73. function draw_border( index )
  74.     term.setCursorPos(1,1)
  75.     term.setBackgroundColor(colors.yellow)
  76.     for pos, data in ipairs(g_tabs) do
  77.         if pos == index + 1 then
  78.             term.setBackgroundColor(colors.gray)
  79.             term.setTextColor(colors.yellow)
  80.         else
  81.             term.setBackgroundColor(colors.yellow)
  82.             term.setTextColor(colors.gray)
  83.         end
  84.         term.write(" "..data.." ")
  85.     end
  86.     for i=term.getCursorPos(),g_w do
  87.         term.setBackgroundColor(colors.yellow)
  88.         term.write(" ")
  89.     end
  90.     term.setBackgroundColor(colors.black)
  91. end
  92.  
  93. function update( index )
  94.     draw_border( index )
  95.     if index == 0 then
  96.         draw_text(2, 6, "Coded add", colors.white, colors.black)
  97.         draw_text(2, 7, "PeripheralsPlusOne", colors.white, colors.black)
  98.     elseif index == 1 then
  99.         draw_text(2, 6, "Joe finish", colors.white, colors.black)
  100.         draw_text(2, 7, "GC CC bridge", colors.white, colors.black)
  101.     end
  102. end
  103.  
  104. -- Main Loop
  105. local m_pages = 2
  106. local m_index = 0
  107. local m_loop = 0
  108.  
  109. update( 0 )
  110. local m_timer = os.startTimer(c_global_display_time)
  111. local m_timer_update = os.startTimer(1)
  112. while bRunning do
  113.     local event, p1 = os.pullEvent()
  114.     if event == "monitor_touch" or (event == "timer" and p1 == m_timer) then
  115.         m_index = m_index + 1
  116.         if m_index >= m_pages then m_index = 0 end
  117.         m_timer = os.startTimer(c_global_display_time)
  118.         term.clear()
  119.     elseif event == "timer" and p1 == m_timer_update and m_index == 0 then
  120.         update( m_index )
  121.     elseif event == "monitor_resize" then
  122.         local w, h = term.getSize()
  123.         g_w = w
  124.         g_h = h
  125.     elseif event == "key" and p1 == 16 then
  126.         bRunning = false
  127.     end
  128.     update( m_index )
  129. end
  130. term.setBackgroundColor(colors.black)
  131. term.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement