Advertisement
xiab

debugProgCharles

Feb 7th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.92 KB | None | 0 0
  1. --/////////////////////////////////////////////////
  2. --//--------- PROGRMAME COMPUTEUR CRAFT ---------//
  3. --//--------- ************************* ---------//
  4. --//----- AFFICHAGE DYNAMIQUE ET INTERACTIF -----//
  5. --//---- DE TUBINE ET REATEUR DE BIGREACTOR -----//
  6. --/////////////////////////////////////////////////
  7.  
  8. --Confguration
  9. rednet.open("left")
  10. local ecran=peripheral.wrap("top")
  11. local idTurbine = "MasterEnergie"
  12. local nbm = 8 --Nombre de turbin afficher
  13. local k=0
  14. local data={}
  15. local data100={}
  16. data[1]={}
  17. data[2]={}
  18. data[3]={}
  19. data[4]={}
  20. data[5]={}
  21. data[6]={}
  22. data[7]={}
  23. data[8]={}
  24. data[100]={}
  25. --parallel.waitForAll(Ecoute,Affichage,Tactille)
  26. --/////////////////////////////////////////////////
  27. --//----------------FUNCTION---------------------//
  28. --/////////////////////////////////////////////////
  29.  
  30. -- Function de recuperation des infos envoye en wifi
  31. function Ecoute()
  32.     while true do
  33.     local event, id, ID, TablData = os.pullEvent("rednet_message")     
  34.         if ID>=1 and  ID<=8 then
  35.             data[ID]["PCon"] = false
  36.             data[ID]=textutils.unserialize(TablData)
  37.             elseif ID==100 then
  38.             data100["PCon"] = false
  39.             data100=textutils.unserialize(TablData)
  40.         end
  41.     end
  42. end
  43.  
  44. -- Function du main d'affichage
  45. function Affichage()
  46.     Init()
  47.     while true do --main
  48.         k=k+1
  49.         AffichageTurbine()
  50.         AffichageReactor()
  51.         os.sleep(0.8)
  52.     end
  53. end
  54.  
  55. -- Tout est dans le nom
  56. function Tactile()
  57.     os.sleep(3)
  58.     local Mdata={}  
  59.     while true do
  60.         local e, bt, yp, xp = os.pullEvent("monitor_touch")
  61.         --Pour les turbines
  62.         local i=1
  63.         for i=1,nbm do
  64.             local x=1 y=1
  65.             if     i==1 then x=1  y=3
  66.             elseif i==2 then x=1  y=52
  67.             elseif i==3 then x=11 y=3
  68.             elseif i==4 then x=11 y=52
  69.             elseif i==5 then x=21 y=3
  70.             elseif i==6 then x=21 y=52
  71.             elseif i==7 then x=31 y=3
  72.             elseif i==8 then x=31 y=52
  73.             end
  74.             --activee desactiver
  75.             if yp>=y+6 and yp<=y+11  and xp>=x+2 and x<=x+5 then
  76.                 Mdata["numberTurbine"] = i
  77.                 Mdata["sInductor"] = data[i]["gInductor"]
  78.                 if data[i]["gActive"] == true then
  79.                     Mdata["sActive"]=false
  80.                 else
  81.                     Mdata["sActive"]=true
  82.                  --Mdata["sActive"] =~data[i]["gActive"]
  83.                  end
  84.             end
  85.             --engagement desengagement
  86.             if xp==x+1  and yp>=y+6  and yp<=y+12  then
  87.                 Mdata["numberTurbine"] = i
  88.                 Mdata["sActive"] = data[i]["gActive"]
  89.                 if data[i]["gInductor"] == true then
  90.                     Mdata["sInductor"]=false
  91.                 else
  92.                     Mdata["sInductor"]=true
  93.                           --Mdata["sInductor"] =~data[i]["gInductor"]
  94.                 end
  95.             end
  96.             --pour le reacteur
  97.             --activee desactiver
  98.             if yp>=25 and yp<=33  and xp>=10 and x<=28 then
  99.                 Mdata["numberTurbine"] = i
  100.                 if data[i]["gActive"] == true then
  101.                     Mdata["sActive"]=false
  102.                 else
  103.                     Mdata["sActive"]=true
  104.                     --Mdata["sActive"] = !data100["gActive"]
  105.                 end
  106.             end
  107.             rednet.broadcast(idTurbine,textutils.serialize(Mdata))
  108.             os.sleep(1)
  109.         end
  110.     end
  111. end
  112.  
  113.  
  114. -- Function d'inisialisation
  115. function Init()
  116.     local cpt=1
  117.    
  118.     windows = {} --pour les images
  119.     windows[1] = window.create(ecran, 9 , 3 , 5, 5, true)--Tubines
  120.     windows[2] = window.create(ecran, 58, 3 , 5, 5, true)
  121.     windows[3] = window.create(ecran, 9 , 13, 5, 5, true)
  122.     windows[4] = window.create(ecran, 58, 13, 5, 5, true)
  123.     windows[5] = window.create(ecran, 9 , 23, 5, 5, true)
  124.     windows[6] = window.create(ecran, 58, 23, 5, 5, true)
  125.     windows[7] = window.create(ecran, 9 , 33, 5, 5, true)
  126.     windows[8] = window.create(ecran, 58, 33, 5, 5, true)
  127.     windows[100] = window.create(ecran, 31, 10, 9, 18, true)--Reactor
  128.     windows[101] = window.create(ecran, 23, 2, 26, 6, true)--Titre
  129.    
  130.     --chargement
  131.     ecran.setBackgroundColor(colors.blue)
  132.     ecran.clear()
  133.     line(10 ,20,50 ,4, colors.black)
  134.     for cpt=1, 50 do
  135.         line(10 ,20 ,cpt,4, colors.green)
  136.         os.sleep(0.05)
  137.     end
  138.     os.sleep(0.5)
  139.     ecran.setBackgroundColor(colors.black)
  140.     ecran.clear()
  141.    
  142.     Titre = paintutils.loadImage("Titre")
  143.     windows[101].setBackgroundColor(colors.black)
  144.     windows[101].setTextColor(colors.black)
  145.     windows[101].clear()
  146.     term.redirect(windows[101])
  147.     paintutils.drawImage(Titre, 1, 1)
  148. end
  149.  
  150. -- Function d'affichage les donners des turbines
  151. function AffichageTurbine()
  152.     local turb
  153.     if k == 5 then k = 1 end --pour les images
  154.    
  155.     local i=1
  156.     for i=1,nbm do --data[1] a data[nbm]       
  157.         --chois de la position
  158.         local x=1 y=1
  159.         if     i==1 then x=1  y=3
  160.         elseif i==2 then x=1  y=52
  161.         elseif i==3 then x=11 y=3
  162.         elseif i==4 then x=11 y=52
  163.         elseif i==5 then x=21 y=3
  164.         elseif i==6 then x=21 y=52
  165.         elseif i==7 then x=31 y=3
  166.         elseif i==8 then x=31 y=52
  167.         end
  168.  
  169.         --Debut de l'affiche
  170.         ecran.setTextColor(colors.white)
  171.         ecran.setCursorPos(y+4,x)   --**--
  172.         ecran.write("Turbine "..i)
  173.        
  174.         if data[i]["PCon"] == true then
  175.             --L'activiter
  176.             if data[i]["gActive"] == true then
  177.                 turb = paintutils.loadImage("turb"..k)
  178.             else
  179.                 turb = paintutils.loadImage("turb0")
  180.             end
  181.             windows[i].setBackgroundColor(colors.black)
  182.             windows[i].setTextColor(colors.black)
  183.             windows[i].clear()
  184.             term.redirect(windows[i])
  185.             paintutils.drawImage(turb, 1, 1)
  186.  
  187.             --L'engagement
  188.             if data[i]["gInductor"]==true then
  189.                 ecran.setCursorPos(y+4,x+1)  
  190.                 ecran.setBackgroundColor(colors.black)
  191.                 ecran.write(" ")
  192.                 line(y+5 ,x+1 ,7 ,1, colors.blue)
  193.                 ecran.setCursorPos(y+5,x+1)
  194.                 ecran.write("Engager")
  195.                 ecran.setBackgroundColor(colors.black)
  196.                 ecran.write("   ")
  197.             else
  198.                 line(y+4 ,x+1 ,7 ,1, colors.red)
  199.                 ecran.setCursorPos(y+4,x+1)
  200.                 ecran.write("Desengager")
  201.                 ecran.setBackgroundColor(colors.black)
  202.             end
  203.  
  204.             ecran.setTextColor(colors.white)
  205.             ecran.setCursorPos(y+1,x+7)
  206.             ecran.write("Rotor: ")
  207.    
  208.             if data[i]["gSpeed"]<800 then
  209.                 ecran.setTextColor(colors.red)
  210.             elseif data[i]["gSpeed"]<1000 then
  211.                 ecran.setTextColor(colors.blue)
  212.             elseif data[i]["gSpeed"]<1700 then
  213.                 ecran.setTextColor(colors.red)
  214.             elseif data[i]["gSpeed"]<1900 then
  215.                 ecran.setTextColor(colors.blue)  
  216.             else
  217.                 ecran.setTextColor(colors.red)
  218.             end
  219.  
  220.             ecran.setCursorPos(y+8,x+7)
  221.             ecran.write(number_format(data[i]["gSpeed"]).." RPM     ")
  222.             ecran.setTextColor(colors.white)
  223.    
  224.             ecran.setCursorPos(y,x+8)
  225.             ecran.write("Prod : "..number_format(data[i]["gProductLastTick"]).." RF/t     ")
  226.            
  227.         else
  228.             --ecran.setCursorPos(y+4,x+4)
  229.             --ecran.write("PC åA5A9teint")
  230.             Titre = paintutils.loadImage("PCoff")
  231.             windows[i].setBackgroundColor(colors.black)
  232.             windows[i].setTextColor(colors.black)
  233.             windows[i].clear()
  234.             term.redirect(windows[i])
  235.             paintutils.drawImage(turb, 1, 1)
  236.         end
  237.     end
  238. end
  239.  
  240. --Function d'affichage des donners du reactor
  241. function AffichageReactor()
  242.     local reactor
  243.     local y=25 x=9
  244.     --Affichage de l'activiter
  245.     ecran.setCursorPos(y+7,x)
  246.     ecran.write("Reactor")
  247.     if data100["PCon"] == true then
  248.         if data100["gActive"]==true then
  249.             reactor = paintutils.loadImage("reactor")
  250.         else
  251.             reactor = paintutils.loadImage("reactoroff")
  252.         end
  253.         windows[100].setBackgroundColor(colors.black)
  254.         windows[100].setTextColor(colors.black)
  255.         windows[100].clear()
  256.         term.redirect(windows[100])
  257.         paintutils.drawImage(reactor, 1, 1)
  258.         ecran.setBackgroundColor(colors.black)
  259.        
  260.         --Affichage des donnes
  261.         ecran.setTextColor(colors.white)
  262.         ecran.setCursorPos(y,x+20) --le stock de yell en ingot
  263.         ecran.write("Fuel: "..number_format(data100["gFuelAmount"]).." yell  ")
  264.         ecran.setCursorPos(y+1,x+21)
  265.         ecran.write("Decher: "..number_format(data100["gWasteAmount"]).." cyanit  ")
  266.         ecran.setCursorPos(y+5,x+22) --le stock de yell en %
  267.         ecran.write("Stock: "..math.ceil(data100["gFuelAmount"]/data100["gFuelAmountMax"]*100).."%")
  268.         ecran.setCursorPos(y+1,x+23) --production en mb/t
  269.         ecran.write("Prod: "..number_format(data100["gHotFluidProducedLastTick"]).." mb/t   ")
  270.         ecran.setCursorPos(y,x+24) --comsomation de yell en mb
  271.         ecran.write("Conso: "..number_format(data100["gFuelConsumedLastTick"]))
  272.         ecran.setCursorPos(y+9,x+24)
  273.         ecran.write("mb/t de yell")
  274.         ecran.setCursorPos(y+4,x+25) --temperature en C
  275.         ecran.write("Temp: "..number_format(data100["gCasingtemperature"]).." C  ")
  276.         ecran.setCursorPos(y+4,x+26) --reactiviter %
  277.         ecran.write("Reacto: "..number_format(data100["gFuelReactivity"]).." %  ")
  278.     else
  279.         ecran.setCursorPos(y+4,x)
  280.         ecran.write("PC åA5A9teint")
  281.         --Titre = paintutils.loadImage("")
  282.         --windows[i].setBackgroundColor(colors.black)
  283.         --windows[i].setTextColor(colors.black)
  284.         --windows[i].clear()
  285.         --term.redirect(windows[i])
  286.         --paintutils.drawImage(turb, 1, 1)
  287.     end
  288.     --pour les erreurs
  289.     --Titre = paintutils.loadImage("")
  290.     --windows[i].setBackgroundColor(colors.black)
  291.     --windows[i].setTextColor(colors.black)
  292.     --windows[i].clear()
  293.     --term.redirect(windows[i])
  294.     --paintutils.drawImage(turb, 1, 1)
  295. end
  296.  
  297. -- Crestion de rectangle de couleur
  298. function line(x ,y ,long ,larg, color_font)
  299.     ecran.setBackgroundColor(color_font)
  300.     for yp=y, y+larg-1 do
  301.         ecran.setCursorPos(x,yp)
  302.         ecran.write(string.rep(" ", long))
  303.     end
  304. end
  305.  
  306. -- Bar de progresion
  307. function prog(x ,y ,long ,larg, valmin, valmax ,color_bar ,color_font)
  308.     line(x ,y ,long ,larg, color_font)
  309.     local bar = math.floor((valmin/valmax)*long)
  310.     line(x ,y ,bar ,larg, color_bar)
  311. end
  312.  
  313. -- Function pour transformer 9876543 en 9 876 543
  314. function number_format(n)
  315.   local test=mille(n)
  316.   if test.Mille==0 then
  317.     return math.floor(n)
  318.   else
  319.     test.Mille=mille(test.Mille)
  320.     if test.Mille.Mille==0 then
  321.       return test.Mille.Cent.." "..cent(test.Cent)
  322.     else
  323.       return test.Mille.Mille.." "..cent(test.Mille.Cent).." "..cent(test.Cent)
  324.     end
  325.   end
  326. end
  327.  
  328. -- Function pour etre sur d'avoir trois chiffre (99 devient 099, 9 devient 009)
  329. function cent(n)
  330.   n=math.floor(n)
  331.   if n>99 then
  332.     return n
  333.    elseif n>9 then
  334.     return "0"..n
  335.    else
  336.     return "00"..n
  337.    end
  338. end
  339.  
  340. -- Creer un objet avec les centaine d'un cotåA5A5A5A9 les millier de l'autre
  341. function mille(n)
  342.   if n<1000 then
  343.     return {Mille=0,Cent=n}
  344.   else
  345.     return {Mille=math.floor(n/1000),Cent=n%1000}
  346.   end
  347. end
  348. parallel.waitForAll(Ecoute,Affichage,Tactille)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement