Advertisement
Fasstaff

Command

Mar 12th, 2025 (edited)
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local Reactor = peripheral.wrap( "back" )
  2.  
  3. local mon = peripheral.wrap( "left" )
  4. mon.setTextScale( .5 )
  5.  
  6. local Manu, Auto = 1, 0
  7.  
  8. xOn1, yOn1, xOn2, yOn2 = 3, 8, 9, 10
  9. xOff1, yOff1, xOff2, yOff2 = 11, 8, 17, 10
  10.  
  11. function newLine(nbr)
  12.     xPos, yPos = mon.getCursorPos()
  13.     mon.setCursorPos( 1,( yPos + nbr ) )
  14. end
  15.  
  16. function round(val, decimal)
  17.   if (decimal) then
  18.     return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
  19.   else
  20.     return math.floor(val+0.5)
  21.   end
  22. end
  23.  
  24. function drawOn()
  25.     local previousTerm = term.current()
  26.     term.redirect( mon )
  27.         term.setBackgroundColour( colors.black )
  28.  
  29.         local xOn1, yOn1, xOn2, yOn2 = 2, 8, 25, 10
  30.         local xOff1, yOff1, xOff2, yOff2 = 27, 8, 52, 10
  31.  
  32.         local x1_txt = 12
  33.         local x2_txt = 38
  34.  
  35.         paintutils.drawFilledBox( xOn1, yOn1, xOn2, yOn2, colors.lime )
  36.         term.setCursorPos( x1_txt, 9 )
  37.         term.write( "START" )
  38.  
  39.         paintutils.drawFilledBox( xOff1, yOff1, xOff2, yOff2, colors.red )
  40.         term.setCursorPos( x2_txt, 9 )
  41.         term.write( "STOP" )
  42.  
  43.         term.setBackgroundColour( colors.black )
  44.     term.redirect( previousTerm )
  45. end
  46.  
  47. function drawOff()
  48.     local previousTerm = term.current()
  49.     term.redirect( mon )
  50.         term.setBackgroundColour( colors.black )
  51.  
  52.         local xOn1, yOn1, xOn2, yOn2 = 2, 8, 25, 10
  53.         local xOff1, yOff1, xOff2, yOff2 = 27, 8, 52, 10
  54.  
  55.         local x1_txt = 12
  56.         local x2_txt = 38
  57.  
  58.         paintutils.drawFilledBox( xOn1, yOn1, xOn2, yOn2, colors.red )
  59.         term.setCursorPos( x1_txt, 9 )
  60.         term.write( "START" )
  61.  
  62.         paintutils.drawFilledBox( xOff1, yOff1, xOff2, yOff2, colors.lime )
  63.         term.setCursorPos( x2_txt, 9 )
  64.         term.write( "STOP" )
  65.  
  66.         term.setBackgroundColour( colors.black )
  67.     term.redirect( previousTerm )
  68. end
  69.  
  70. function drawMenu()
  71.     local previousTerm = term.current()
  72.     term.redirect( mon )
  73.         term.setBackgroundColour( colors.black )
  74.  
  75.         paintutils.drawFilledBox( 2, 2, 13, 4, colors.lime )
  76.         term.setCursorPos( 3, 3 )
  77.         term.write( "Reacteur 1" )
  78.  
  79.         paintutils.drawFilledBox( 15, 2, 26, 4, colors.red )
  80.         term.setCursorPos( 16, 3 )
  81.         term.write( "Reacteur 2" )
  82.  
  83.         paintutils.drawFilledBox( 28, 2, 39, 4, colors.red )
  84.         term.setCursorPos( 29, 3 )
  85.         term.write( "Reacteur 3" )
  86.  
  87.         paintutils.drawFilledBox( 41, 2, 52, 4, colors.red )
  88.         term.setCursorPos( 42, 3 )
  89.         term.write( "Reacteur 4" )
  90.  
  91.         paintutils.drawFilledBox( 1, 6, 54, 6, colors.gray )
  92.         paintutils.drawFilledBox( 54, 1, 54, 38, colors.gray )
  93.  
  94.         paintutils.drawFilledBox( 56, 2, 99, 4, colors.blue )
  95.         term.setCursorPos( 75, 3 )
  96.         term.write( "Général" )
  97.  
  98.         paintutils.drawFilledBox( 56, 6, 76, 8, colors.cyan )
  99.         term.setCursorPos( 64, 7 )
  100.         term.write( "Auto" )
  101.  
  102.         paintutils.drawFilledBox( 79, 6, 99, 8, colors.cyan )
  103.         term.setCursorPos( 87, 7 )
  104.         term.write( "Manu" )
  105.  
  106.         term.setBackgroundColour( colors.black )
  107.     term.redirect( previousTerm )
  108. end
  109.  
  110. function drawRed()
  111.     local X1 = {2, 15, 28, 41, 42}
  112.     local X2 = {13, 26, 39, 42}
  113.     local T = {3, 16, 29, 42}
  114.     for i=1, 4, 1
  115.     do
  116.         local previousTerm = term.current()
  117.         term.redirect( mon )
  118.             term.setBackgroundColour( colors.black )
  119.             paintutils.drawFilledBox( X1[i], 2, X2[i], 4, colors.red )
  120.             term.setCursorPos( T[i], 3 )
  121.             term.write( "Reacteur "..i )
  122.             term.setBackgroundColour( colors.black )
  123.         term.redirect( previousTerm )
  124.     end
  125. end
  126.  
  127. function drawColor(x1, x2, y1, y2, txt_x, txt_y, txt, couleur)
  128.     local previousTerm = term.current()
  129.     term.redirect( mon )
  130.         term.setBackgroundColour( colors.black )
  131.         paintutils.drawFilledBox( x1, y1, x2, y2, couleur )
  132.         term.setCursorPos( txt_x, txt_y )
  133.         term.write( txt )
  134.         term.setBackgroundColour( colors.black )
  135.     term.redirect( previousTerm )
  136. end
  137.  
  138. function drawActiveReac(idReac, txt)
  139.     drawRed()
  140.     if idReac == Reactor1 then
  141.        
  142.         local x1, x2, y1, y2, txt_x, txt_y, txt, couleur = 2, 13, 2, 4, 3, 3, "Reacteur 1", colors.lime
  143.         drawColor(x1, x2, y1, y2, txt_x, txt_y, txt, couleur)
  144.  
  145.     elseif idReac == Reactor2 then
  146.        
  147.         local x1, x2, y1, y2, txt_x, txt_y, txt, couleur = 15, 26,2, 4, 16, 3, "Reacteur 2", colors.lime
  148.         drawColor(x1, x2, y1, y2, txt_x, txt_y, txt, couleur)
  149.  
  150.     elseif idReac == Reactor3 then
  151.        
  152.         local x1, x2, y1, y2, txt_x, txt_y, txt, couleur = 28, 39, 2, 4, 29, 3, "Reacteur 3", colors.lime
  153.         drawColor(x1, x2, y1, y2, txt_x, txt_y, txt, couleur)
  154.  
  155.     elseif idReac == Reactor4 then
  156.        
  157.         local x1, x2, y1, y2, txt_x, txt_y, txt, couleur = 41, 52, 2, 4, 42, 3, "Reacteur 4", colors.lime
  158.         drawColor(x1, x2, y1, y2, txt_x, txt_y, txt, couleur)
  159.     end
  160. end
  161.  
  162. function drawMode()
  163.     if Auto == 1 and Manu == 0 then
  164.  
  165.         local x1, x2, y1, y2, txt_x, txt_y, txt, couleur = 56, 76, 6, 8, 64, 7, "Auto", colors.lightBlue
  166.         drawColor(x1, x2, y1, y2, txt_x, txt_y, txt, couleur)
  167.        
  168.         local x1, x2, y1, y2, txt_x, txt_y, txt, couleur = 79, 99, 6, 8, 87, 7, "Manu", colors.cyan
  169.         drawColor(x1, x2, y1, y2, txt_x, txt_y, txt, couleur)
  170.  
  171.     elseif Auto == 0 and Manu == 1 then
  172.  
  173.         local x1, x2, y1, y2, txt_x, txt_y, txt, couleur = 56, 76, 6, 8, 64, 7, "Auto", colors.cyan
  174.         drawColor(x1, x2, y1, y2, txt_x, txt_y, txt, couleur)
  175.        
  176.         local x1, x2, y1, y2, txt_x, txt_y, txt, couleur = 79, 99, 6, 8, 87, 7, "Manu", colors.lightBlue
  177.         drawColor(x1, x2, y1, y2, txt_x, txt_y, txt, couleur)
  178.     end
  179. end
  180.  
  181. function infosGenerales()
  182.     local prod1 = Reactor1.battery().producedLastTick()
  183.     local prod2 = Reactor2.battery().producedLastTick()
  184.     local total = prod1 + prod2
  185.  
  186.     local battery1 = Reactor1.battery().stored()
  187.     local capa1 = Reactor1.battery().capacity()
  188.  
  189.     local battery2 = Reactor2.battery().stored()
  190.     local capa2 = Reactor2.battery().capacity()
  191.  
  192.     local chargeBatt = round( ( (battery1 + battery2) / (capa1 + capa2) )* 100, 2)
  193.  
  194.     local conso = round( Reactor1.fuelTank().burnedLastTick() + Reactor2.fuelTank().burnedLastTick(), 2)
  195.  
  196.     mon.setCursorPos( 56, 10 )
  197.     mon.write ( "Production Réacteur n°1 : " .. prod1 .. " RF/t      " )
  198.     mon.setCursorPos( 56, 12 )
  199.     mon.write ( "Production Réacteur n°2 : " .. prod2 .. " RF/t    " )
  200.     mon.setCursorPos( 56, 14 )
  201.     mon.write ( "Production totale : " .. total .. " RF/t         " )
  202.     mon.setCursorPos( 56, 16 )
  203.     mon.write ( "Batterie totale : " .. chargeBatt .. " %         " )
  204.     mon.setCursorPos( 56, 18 )
  205.     mon.write ("Consommation totale : " .. conso .. " mb/t             ")
  206. end
  207.  
  208. function Infos_Reac(idReac)
  209.  
  210.     viewedReac = idReac
  211.     if viewedReac.active() then
  212.         status = "On"
  213.         drawOn()
  214.     else
  215.         status = "Off"
  216.         drawOff()
  217.     end
  218.  
  219.     local prod = viewedReac.battery().producedLastTick()
  220.     local temp = round(viewedReac.fuelTemperature(), 2)
  221.     local battery = viewedReac.battery().stored()
  222.     local capa = viewedReac.battery().capacity()
  223.     local chargeBatt = round(battery / capa * 100, 2)
  224.     local conso = round(viewedReac.fuelTank().burnedLastTick(), 2)
  225.  
  226.     mon.setCursorPos( 1, 12 )
  227.     mon.write ("Production : " .. prod .. " RF/t             ")
  228.     newLine(2)
  229.     mon.write ("Température : " .. temp .. " °K             ")
  230.     newLine(2)
  231.     mon.write ("Batterie : " .. battery .. " RF ( "..chargeBatt.." % )             ")
  232.     newLine(2)
  233.     mon.write ("Consommation : " .. conso .. " mb/t             ")
  234. end
  235.  
  236. function infos()
  237.    
  238.     infosGenerales()
  239.     Infos_Reac(viewedReac)
  240.     sleep( 0.1 )
  241. end
  242.  
  243. function modeAuto(idReac)
  244.  
  245.     local battery = idReac.battery().stored()
  246.     local capa = idReac.battery().capacity()
  247.     local chargeBatt = round(battery / capa * 100, 2)
  248.     if Auto == 1 and Manu == 0 then
  249.         if chargeBatt >= 99 then
  250.             idReac.setActive(false)
  251.         elseif chargeBatt <= 15 then
  252.             idReac.setActive(true)
  253.         end
  254.     end
  255. end
  256.  
  257. function testClic()
  258.  
  259.     local event, side, cx, cy = os.pullEvent()
  260.  
  261.     if event == "monitor_touch" then
  262.  
  263.         if cy >= 2 and cy <= 4 then
  264.             if cx >= 2 and cx <= 13 then
  265.                 drawActiveReac(Reactor1)
  266.                 Infos_Reac(Reactor1)
  267.  
  268.             elseif cx >= 15 and cx <= 26 then
  269.                 drawActiveReac(Reactor2)
  270.                 Infos_Reac(Reactor2)
  271.             end
  272.  
  273.         elseif cy >= 8 and cy <= 10 then
  274.             if cx >= 2 and cx <= 25 then
  275.                 drawOn()
  276.                 viewedReac.setActive(true)
  277.  
  278.             elseif cx >= 27 and cx <= 52 then
  279.                 drawOff()
  280.                 viewedReac.setActive(false)
  281.             end
  282.  
  283.         elseif cy >= 6 and cy <= 8 then
  284.             if cx >= 56 and cx <= 76 then
  285.                 Manu = 0
  286.                 Auto = 1
  287.                 drawMode()
  288.  
  289.             elseif cx >= 79 and cx <= 99 then
  290.                 Manu = 1
  291.                 Auto = 0
  292.                 drawMode()
  293.             end
  294.         end
  295.     end
  296. end
  297.  
  298. mon.setTextColor(colors.white)
  299. mon.setBackgroundColor(colors.black)
  300.  
  301. mon.clear()
  302. drawMenu()
  303. viewedReac = Reactor1
  304.  
  305. while true do
  306.  
  307.     parallel.waitForAny( infos, testClic )
  308.  
  309. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement