miezto

core&gate

Sep 30th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.88 KB | None | 0 0
  1. local core = peripheral.wrap("draconic_rf_storage_6")
  2. local gate = peripheral.wrap("flux_gate_39")
  3. local monitor = peripheral.wrap("back")
  4.  
  5. local mon, monX, monY
  6. monX, monY = monitor.getSize()
  7. mon = {}
  8. mon.monitor, mon.X, mon.Y = monitor, monX, monY
  9.  
  10. function clear(mon)
  11.     term.clear()
  12.     term.setCursorPos(1,1)
  13.     mon.monitor.setBackgroundColor(colors.black)
  14.     mon.monitor.clear()
  15.     mon.monitor.setCursorPos(1,1)
  16. end
  17.  
  18. function draw_text(mon, x, y, text, text_color, bg_color)
  19.     mon.monitor.setBackgroundColor(bg_color)
  20.     mon.monitor.setTextColor(text_color)
  21.     mon.monitor.setCursorPos(x,y)
  22.     mon.monitor.write(text)
  23. end
  24.  
  25. function draw_text_right(mon, offset, y, text, text_color, bg_color)
  26.     mon.monitor.setBackgroundColor(bg_color)
  27.     mon.monitor.setTextColor(text_color)
  28.     mon.monitor.setCursorPos(mon.X-string.len(tostring(text))-offset,y)
  29.     mon.monitor.write(text)
  30. end
  31.  
  32. function format_int(number)
  33.     if number == nil then number = 0 end
  34.     local i, j, minus, int, fraction = tostring(number):find('([-]?)(%d+)([.]?%d*)')
  35.     int = int:reverse():gsub("(%d%d%d)", "%1,")
  36.     return minus .. int:reverse():gsub("^,", "") .. fraction
  37. end
  38.  
  39. function buttons()
  40.     while true do
  41.         event, side, xPos, yPos = os.pullEvent("monitor_touch")
  42.         if yPos == 18 then
  43.             local cFlow = gate.getSignalLowFlow()
  44.             if xPos >= 2 and xPos <= 4 then cFlow = cFlow-10000
  45.             elseif xPos >= 6 and xPos <= 8 then cFlow = cFlow-100000
  46.             elseif xPos >= 10 and xPos <= 12 then cFlow = cFlow-1000000
  47.             elseif xPos >= 17 and xPos <= 19 then cFlow = cFlow+1000000
  48.             elseif xPos >= 21 and xPos <= 23 then cFlow = cFlow+100000
  49.             elseif xPos >= 25 and xPos <= 27 then cFlow = cFlow+10000
  50.             end
  51.         gate.setSignalLowFlow(cFlow)
  52.         end
  53.     end
  54. end
  55.  
  56. function drawButtons(y)
  57.     draw_text(mon, 2, y, "  <", colors.white, colors.gray)
  58.     draw_text(mon, 6, y, " <<", colors.white, colors.gray)
  59.     draw_text(mon, 10, y, "<<<", colors.white, colors.gray)
  60.     draw_text(mon, 17, y, ">>>", colors.white, colors.gray)
  61.     draw_text(mon, 21, y, ">> ", colors.white, colors.gray)
  62.     draw_text(mon, 25, y, ">  ", colors.white, colors.gray)
  63. end
  64.  
  65. local eMax
  66. local eNow
  67. local ePercent
  68. local eLast = 0
  69. local eFlow
  70.  
  71. function update()
  72.     while true do
  73.         clear(mon)
  74.  
  75.     -- energy core infos
  76.         eMax = core.getMaxEnergyStored()
  77.         eNow = core.getEnergyStored()
  78.         ePercent = (math.floor(eNow/eMax*10000))/100
  79.         eFlow = math.floor((eNow-eLast)/2)
  80.         eLast = eNow
  81.  
  82.     -- terminal display
  83.         print(" Capacity:  " .. eMax .. " rf")
  84.         print("   Energy:  " .. eNow .. " rf ... " .. ePercent .. " %")
  85.         print()
  86.         if (eFlow > 0) then
  87.             print("Avg. flow: +" .. eFlow .. " rf/t")
  88.         else
  89.             print("Avg. flow: " .. eFlow .. " rf/t")
  90.         end
  91.         print()
  92.         print("Flux gate flow: " .. gate.getSignalLowFlow())
  93.  
  94.     -- monitor output
  95.         draw_text(mon, 2, 2, "REACTOR SUPPLY ENERGY CORE", colors.red, colors.black)
  96.         draw_text(mon, 2, 4, "Energy core capacity:", colors.purple, colors.black)
  97.         draw_text_right(mon, 1, 4, "T7", colors.purple, colors.black)
  98.         draw_text_right(mon, 1, 5, format_int(eMax) .. " rf", colors.white, colors.black)
  99.         draw_text(mon, 2, 6, "Current capacity:", colors.blue, colors.black)
  100.         draw_text_right(mon, 1, 6, ePercent .. " %", colors.white, colors.black)
  101.         draw_text_right(mon, 1, 7, format_int(eNow) .. " rf", colors.white, colors.black)
  102.         draw_text(mon, 2, 9, "Flow:", colors.green, colors.black)
  103.         if (eFlow > 0) then
  104.             draw_text_right(mon, 1, 9, "+" .. format_int(eFlow) .. " rf/t", colors.white, colors.black)
  105.         else
  106.             draw_text_right(mon, 1, 9, format_int(eFlow) .. " rf/t", colors.white, colors.black)
  107.         end
  108.         draw_text(mon, 2, 14, "SUPPLY FOR UU-BRIDGE v2", colors.blue, colors.black)
  109.         draw_text(mon, 2, 16, "Flux gate flow: ", colors.yellow, colors.black)
  110.         draw_text_right(mon, 1, 17, format_int(gate.getSignalLowFlow()) .. " rf/t", colors.white, colors.black)
  111.         drawButtons(18)
  112.  
  113.         sleep(0.1)
  114.     end    
  115. end
  116.  
  117. parallel.waitForAny(buttons, update)
Add Comment
Please, Sign In to add comment