Advertisement
AKopyl

reactor

Mar 10th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.79 KB | None | 0 0
  1. require('paint_utils_fix')
  2. fixPaintUtils()
  3.  
  4. local version = '3.1'
  5. local W, H = term.getSize()
  6. local mon = peripheral.find('monitor')
  7. local monW, monH = mon.getSize()
  8.  
  9. function draw(f)
  10.     term.f()
  11.     mon.f()
  12. end
  13.  
  14. sides = {'top', 'bottom', 'left', 'right', 'front', 'back'}
  15.  
  16. local chamber = peripheral.find('ic2:reactor_chamber')
  17. local core = chamber.getReactorCore()
  18.  
  19. local heat_cutoff = 84
  20.  
  21. local ticker = 1
  22.  
  23. local nuke_img = paintutils.loadImage('reactor/nuke.nfp')
  24.  
  25. local timeout = os.startTimer(1)
  26.  
  27. local requirement = {}
  28.  
  29. requirement['temperature'] = {
  30.     active = true,
  31.     reverse = false,
  32.     name = 'temperature',
  33.     check = function() return reactor.heat/reactor.maxHeat*100 < heat_cutoff end
  34. }
  35.  
  36. for n = 1, #sides, 1 do
  37.     requirement[sides[n]] = {
  38.         active = false,
  39.         reverse = false,
  40.         name = sides[n],
  41.         check = function() return redstone.getInput(sides[n]) end
  42.     }
  43. end
  44.  
  45. while true do
  46.     local event = {os.pullEvent()}
  47.  
  48.     if event[1] == 'mouse_click' or event[1] == 'monitor_touch' then
  49.         if event[3] == math.floor(W/2-5) then
  50.             local y = 5
  51.             for req, content in pairs(requirement) do
  52.                 if event[4] == y then
  53.                     content.active = not content.active
  54.                 end
  55.                 y = y + 1
  56.             end
  57.         end
  58.         if event[3] == math.floor(W/2-3) then
  59.             local y = 5
  60.             for req, content in pairs(requirement) do
  61.                 if event[4] == y then
  62.                     content.reverse = not content.reverse
  63.                 end
  64.                 y = y + 1
  65.             end
  66.         end
  67.         if event[4] >= 13 and event[4] <= 14 then
  68.             if event[3] >=2 and event[3] <= W/2 then
  69.                 heat_cutoff = (event[3]-1)/(W/2-1)*100
  70.             end
  71.         end
  72.     elseif event[1] == 'mouse_scroll' then
  73.         if event[4] >= 13 and event[4] <= 14 then
  74.             if event[3] >=2 and event[3] <= W/2 then
  75.                 heat_cutoff = math.floor((heat_cutoff - 0.5*event[2])*2)/2
  76.             end
  77.         end
  78.     elseif event[1] == 'timer' then
  79.         ticker = ticker + 1
  80.         if ticker > 4 then
  81.             ticker = 0
  82.         end
  83.        
  84.         timeout = os.startTimer(1)
  85.     end
  86.  
  87.     reactor = core.getMetadata().reactor
  88.  
  89.     term.setBackgroundColor(colors.black)
  90.     term.clear()
  91.     term.setBackgroundColor(colors.lightGray)
  92.     term.setTextColor(colors.white)
  93.     for x = 1, W, 1 do
  94.         term.setCursorPos(x, 1)
  95.         term.write(' ')
  96.     end
  97.     term.setCursorPos(1, 1)
  98.     term.write('Reactor Manager v'..version)
  99.  
  100.     for n = 1, ticker, 1 do
  101.         term.setCursorPos(W-11+n, 1)
  102.         term.write('|')
  103.     end
  104.  
  105.     term.setBackgroundColor(colors.black)
  106.  
  107.     -- Tip
  108.     term.setCursorPos(1, H-1)
  109.     term.write('R - required')
  110.     term.setCursorPos(1, H)
  111.     term.write('F - fulfilled')
  112.    
  113.     term.setTextColor(colors.white)
  114.     term.setCursorPos(W/2-5, 3)
  115.     term.write('R')
  116.     term.setTextColor(colors.white)
  117.     term.setCursorPos(W/2-3, 3)
  118.     term.write('\172')
  119.     term.setCursorPos(W/2, 3)  
  120.     term.setTextColor(colors.lightGray)
  121.     term.write('F')
  122.  
  123.     local y = 5
  124.     for req, content in pairs(requirement) do
  125.         if y%2 == 0 then
  126.             term.setBackgroundColor(colors.black)
  127.         else
  128.             term.setBackgroundColor(colors.gray)
  129.         end
  130.         term.setCursorPos(2, y)
  131.         for n = 1, W/2, 1 do
  132.             term.write(' ')
  133.         end
  134.         term.setTextColor(colors.white)
  135.         term.setCursorPos(2, y)
  136.         term.write(req)
  137.         term.setCursorPos(W/2-5, y)
  138.         if content.active then
  139.             term.write('\7')
  140.         end
  141.         term.setCursorPos(W/2-3, y)
  142.         if content.reverse then
  143.             term.write('\238')
  144.         end
  145.         term.setCursorPos(W/2, y)
  146.         term.setTextColor(colors.lightGray)
  147.         if content.check() and not content.reverse or not content.check() and content.reverse then
  148.             term.write('\7')
  149.         end
  150.         y = y + 1
  151.     end
  152.  
  153.     --[[local y = 3
  154.     for n = 1, 54, 1 do
  155.         if core.getItemMeta(n) ~= nil and core.getItemMeta(n).name:find('fuel') then
  156.             term.setCursorPos(W/2, y)
  157.             term.write(math.floor(core.getItemMeta(n).durability*100)..'%')
  158.             y = y + 1
  159.         end
  160.     end]]
  161.  
  162.     for n = 1, W/2, 1 do
  163.         if n/(W/2)*100 <= heat_cutoff then
  164.             if math.floor(n/(W/2)*100) >= 85 then
  165.                 term.setBackgroundColor(colors.red)
  166.             elseif math.floor(n/(W/2)*100) >= 70 then
  167.                 term.setBackgroundColor(colors.orange)
  168.             elseif math.floor(n/(W/2)*100) >= 50 then
  169.                 term.setBackgroundColor(colors.yellow)
  170.             elseif math.floor(n/(W/2)*100) >= 40 then
  171.                 term.setBackgroundColor(colors.white)
  172.             else
  173.                 term.setBackgroundColor(colors.blue)
  174.             end
  175.             term.setCursorPos(1+n, 13)
  176.             term.write(' ')
  177.             term.setCursorPos(1+n, 14)
  178.             term.write(' ')
  179.         else
  180.             term.setBackgroundColor(colors.black)
  181.             term.setTextColor(colors.gray)
  182.             term.setCursorPos(1+n, 13)
  183.             term.write('\127')
  184.             term.setCursorPos(1+n, 14)
  185.             term.write('\127')
  186.         end
  187.     end
  188.     term.setBackgroundColor(colors.black)
  189.     term.setTextColor(colors.white)
  190.     term.setCursorPos(W/2+2-string.len(heat_cutoff..'%'), 15)
  191.     term.write(heat_cutoff..'%')
  192.    
  193.     paintutils.drawImage(nuke_img, W/2+5, 3)
  194.  
  195.     term.setBackgroundColor(colors.black)
  196.     term.setTextColor(colors.white)
  197.     term.setCursorPos(W/2+5, H-1)
  198.     term.write(math.floor(reactor.euOutput)..' EU/t')
  199.  
  200.     term.setCursorPos(W/2+6+string.len(math.floor(reactor.euOutput)..' EU/t'), H-1)
  201.     if math.floor(reactor.heat/reactor.maxHeat*100) >= 85 then
  202.         term.setTextColor(colors.red)
  203.     elseif math.floor(reactor.heat/reactor.maxHeat*100) >= 70 then
  204.         term.setTextColor(colors.orange)
  205.     elseif math.floor(reactor.heat/reactor.maxHeat*100) >= 50 then
  206.         term.setTextColor(colors.yellow)
  207.     elseif math.floor(reactor.heat/reactor.maxHeat*100) >= 40 then
  208.         term.setTextColor(colors.white)
  209.     else
  210.         term.setTextColor(colors.blue)
  211.     end
  212.     term.write(math.floor(reactor.heat/reactor.maxHeat*100)..'% heat')
  213.    
  214.     -- Core logic
  215.     local reactor_on = true
  216.     for req, content in pairs(requirement) do
  217.         if ((not content.check() and not content.reverse) or (content.check() and content.reverse)) and content.active then
  218.             reactor_on = false
  219.         end
  220.     end
  221.  
  222.     term.setBackgroundColor(colors.lightGray)
  223.     term.setTextColor(colors.white)
  224.     term.setCursorPos(W-4, 1)
  225.     term.write(tostring(reactor_on))
  226.     redstone.setOutput('top', reactor_on)
  227. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement