Advertisement
bldng1

Untitled

May 27th, 2024 (edited)
780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.14 KB | None | 0 0
  1. function reactorSearch()
  2.    local names = peripheral.getNames()
  3.    local i, name
  4.    for i, name in pairs(names) do
  5.       if peripheral.getType(name) == "BiggerReactors_Reactor" then
  6.          return peripheral.wrap(name)
  7.       else
  8.          --return null
  9.       end
  10.    end
  11. end
  12. function monitorSearch()
  13.    local names = peripheral.getNames()
  14.    local i, name
  15.    for i, name in pairs(names) do
  16.       if peripheral.getType(name) == "monitor" then
  17.         test = name
  18.          return peripheral.wrap(name)
  19.       else
  20.          --return null
  21.       end
  22.    end
  23. end
  24. m=monitorSearch()
  25. reactor=reactorSearch()
  26. function clear()
  27.    m.setBackgroundColor(colors.black)
  28.    m.clear()
  29.    m.setCursorPos(1,1)
  30.  end
  31.  
  32.  --display text on computer's terminal screen
  33.  function draw_text_term(x, y, text, text_color, bg_color)
  34.    term.setTextColor(text_color)
  35.    term.setBackgroundColor(bg_color)
  36.    term.setCursorPos(x,y)
  37.    write(text)
  38.  end
  39.  
  40.  --display text text on monitor, "mon" peripheral
  41.  function draw_text(x, y, text, text_color, bg_color)
  42.    m.setBackgroundColor(bg_color)
  43.    m.setTextColor(text_color)
  44.    m.setCursorPos(x,y)
  45.    m.write(text)
  46.  end
  47.  
  48.  --draw line on computer terminal
  49.  function draw_line(x, y, length, color)
  50.    m.setBackgroundColor(color)
  51.    m.setCursorPos(x,y)
  52.    m.write(string.rep(" ", length))
  53.  end
  54.  
  55.  --draw line on computer terminal
  56.  function draw_line_term(x, y, length, color)
  57.      term.setBackgroundColor(color)
  58.      term.setCursorPos(x,y)
  59.      term.write(string.rep(" ", length))
  60.  end
  61.  
  62.  --create progress bar
  63.  --draws two overlapping lines
  64.  --background line of bg_color
  65.  --main line of bar_color as a percentage of minVal/maxVal
  66.  function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
  67.    draw_line(x, y, length, bg_color) --backgoround bar
  68.    local barSize = math.floor((minVal/maxVal) * length)
  69.    draw_line(x, y, barSize, bar_color) --progress so far
  70.  end
  71.  
  72.  --same as above but on the computer terminal
  73.  function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
  74.    draw_line_term(x, y, length, bg_color) --backgoround bar
  75.    local barSize = math.floor((minVal/maxVal) * length)
  76.    draw_line_term(x, y, barSize, bar_color)  --progress so far
  77.  end
  78.  
  79.  --create button on monitor
  80.  function button(x, y, length, text, txt_color, bg_color)
  81.    draw_line(x, y, length, bg_color)
  82.    draw_text((x+2), y, text, txt_color, bg_color)
  83.    if clicked and mx>=x-1 and mx<=x+length+1 and my>=y-1 and my<=y+1 then
  84.       return true
  85.    end
  86.    return false
  87.  end
  88.  
  89. function getEnergy()
  90.    if reactor.battery() ~= null then
  91.       return reactor.battery().stored()/reactor.battery().capacity()
  92.    end
  93.    return 0
  94. end
  95.  
  96. function setControlrod(p)
  97.    reactor.setAllControlRodLevels(p)
  98. end
  99. function getControlrod()
  100.    return reactor.getControlRod(0).level()
  101. end
  102. function producing()
  103.    if reactor.battery() ~= null then
  104.       return reactor.battery().producedLastTick()/1000;
  105.    end
  106.    return 0
  107. end
  108. function fuel()
  109.    if reactor.fuelTank() ~= null then
  110.       return reactor.fuelTank().burnedLastTick()
  111.    end
  112.    return 0
  113. end
  114. function round(num,s)
  115.    return math.floor((num*(10^s))+0.5)/(10^s)
  116. end
  117. clicked=false
  118. mx=0
  119. my=0
  120. function handletouch()
  121.    clicked=false
  122.    mx=0
  123.    my=0
  124.    local event, button, x, y = os.pullEvent("monitor_touch")
  125.    clicked=true
  126.    mx=x
  127.    my=y
  128. end
  129.  
  130. function timeout()
  131.    sleep(1)
  132. end
  133.  
  134. function update()
  135.    clear()
  136.    local autocolor=colors.black
  137.    local overdrivecolor=colors.black
  138.  
  139.    if mode=="AUTO" then
  140.       autocolor=colors.green
  141.       local reactoron=getEnergy()*getEnergy()
  142.       setControlrod(reactoron*100)
  143.    elseif mode=="OVERDRIVE" then
  144.       overdrivecolor=colors.green
  145.       setControlrod(0)
  146.    end
  147.  
  148.    draw_text(3,2,"Reactor Control",colors.yellow,colors.black)
  149.    draw_text(3,3,mode.." Mode",colors.white,colors.black)
  150.    if reactor.active() then
  151.       draw_text(3,4,"Status: ONLINE",colors.green, colors.black)
  152.    else
  153.       draw_text(3,4,"Status: OFFLINE",colors.red, colors.black)
  154.    end
  155.    local energy=round(getEnergy()*100,2)
  156.    draw_text(3,5,"Current Energy:",colors.white, colors.black)
  157.    progress_bar(3,6,20,energy,100,colors.green, colors.white)
  158.    draw_text(24,6,energy.."",colors.white, colors.black)
  159.  
  160.    local rod=round(getControlrod(),2)
  161.    draw_text(3,7,"ControlRods:",colors.white, colors.black)
  162.    progress_bar(3,8,20,rod,100,colors.yellow, colors.white)
  163.    draw_text(24,8,rod.."",colors.white, colors.black)
  164.    
  165.    draw_text(3,10,"Energy: "..round(producing(),2).." KRF/T",colors.white, colors.black)
  166.    draw_text(3,11,"Fuel Consumption: "..round(fuel(),2).." MB/T",colors.white, colors.black)
  167.    draw_text(3,12,"Efficienty: "..math.floor(producing()/fuel()).." KRF/MB",colors.white, colors.black)
  168.    
  169.    if button(3,15,6,"AUTO",autocolor,colors.lightGray) then
  170.       mode="AUTO"
  171.       clicked=false
  172.       update()
  173.    end
  174.    if button(25,15,6,"OVERDRIVE",overdrivecolor,colors.lightGray) then
  175.       mode="OVERDRIVE"
  176.       clicked=false
  177.       update()
  178.    end
  179. end
  180.  
  181. clear()
  182. mode="AUTO"
  183. while true do
  184.    parallel.waitForAny(timeout,handletouch)
  185.    clear()
  186.    update()
  187.    --sleep(0.5)
  188. end
  189.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement