Neekow

NUP v0.0

Apr 10th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.68 KB | None | 0 0
  1. --- couleurs ---
  2.   --- couleurs des cadres ---
  3.     couleurCadreBase = colors.blue
  4.     couleurCadrePassword = colors.lime
  5.   --- couleurs des boutons password ---
  6.     couleurButtonPassNum = colors.gray
  7.     couleurButtonPassVal = colors.lime
  8.     couleurButtonPassCor = colors.red
  9.   --- couleurs des titres page principale ---
  10.     couleurTitrePage = colors.lightGray
  11.     couleurCarPage = colors.lightGray
  12.     couleurCarVar = colors.gray
  13.  
  14. --- initialisation fonctions ---
  15.   --- fonction peripherals --
  16.     mon = nil
  17.     monSide = nil
  18.     reader = nil
  19.     readerSide = nil
  20.     card = nil
  21.   --- fonction page principale ---  
  22.     PagePrin = nil
  23.   --- fonction barre nucleaire ---
  24.     timeb = 10000
  25.   --- fonction barre storage ---
  26.     Stor1 = 0
  27.     Stor2 = 0
  28.  
  29. --- fonctions ---
  30.  
  31. function peripherals()
  32.   for i, side in pairs(rs.getSides()) do
  33.     if peripheral.getType(side) == "monitor" then
  34.       mon = peripheral.wrap(side)
  35.       monSide = side    
  36.     end
  37.     if peripheral.getType(side) == "nuclearReader" then
  38.       reader = peripheral.wrap(side)
  39.       readerSide = side
  40.     end
  41.     if reader ~= nil then
  42.       uid,state,title,data= reader.get(1)
  43.       if data == nil then
  44.         sleep(1)
  45.         peripherals()
  46.       else  
  47.         for i,j in pairs(data) do
  48.           if i == "liquidMeta" then card = 0 end
  49.           if i == "heat" then card = 1 end
  50.           if i == "energyL" then card = 2 end
  51.         end
  52.       end
  53.     end
  54.   end  
  55. end
  56.  
  57.  
  58. function cadreBase()
  59.   local cadreBase = {
  60.     ' _______  _______ ',
  61.     '|       ||       |',
  62.     '|   ____||____   |',
  63.     '|  |          |  |',
  64.     '|  |__________|  |',
  65.     '|  |          |  |',
  66.     '|  |          |  |',
  67.     '|  |          |  |',
  68.     '|  |          |  |',
  69.     '|  |____  ____|  |',
  70.     '|  |    ||    |  |',
  71.     '|__|____||____|__|'}
  72.  
  73.  
  74.   for i = 1, #cadreBase do
  75.            mon.setTextColor(couleurCadreBase)
  76.            mon.setCursorPos(1,i)
  77.            mon.write(cadreBase[i])
  78. end
  79. end
  80.  
  81. function cadrePassword()
  82.   local x = 0
  83.   local cadrePassord = {
  84.   '| || || || |',
  85.   '|_||_||_||_|',
  86.   '| || || || |',
  87.   '|_||_||_||_|',
  88.    '  | || | ',
  89.    ' _|_||_|_',
  90.    '|   ||   |',
  91.    '|___||___|'}
  92.  
  93.  
  94. for i = 1, #cadrePassword do
  95.          if i<5 then x = 0 else x = 1 end
  96.          mon.setTextColor(couleurPassword)
  97.          mon.setCursorPos(4+x,i+3)
  98.          mon.write(cadrePassword[i])
  99. end
  100.  mon.setCursorPos(9,12)
  101.  mon.setTextColor(couleurCadreBase)
  102.  mon.write("__")
  103. end
  104.  
  105. function buttonPassword()
  106. -- numButton, name, PosX, PosY, Couleur, Xmax
  107. buttonsPassword={
  108. {1 ,"1"   ,5  ,4  ,couleurButtonPassNum ,5 },
  109. {2 ,"2"   ,8  ,4  ,couleurButtonPassNum ,8 },
  110. {3 ,"3"   ,11 ,4  ,couleurButtonPassNum ,11},
  111. {4 ,"4"   ,14 ,4  ,couleurButtonPassNum ,14},
  112. {5 ,"5"   ,5  ,6  ,couleurButtonPassNum ,5 },
  113. {6 ,"6"   ,8  ,6  ,couleurButtonPassNum ,8 },
  114. {7 ,"7"   ,11 ,6  ,couleurButtonPassNum ,11},
  115. {8 ,"8"   ,14 ,6  ,couleurButtonPassNum ,14},
  116. {9 ,"9"   ,8  ,8  ,couleurButtonPassNum ,8 },
  117. {10,"0"   ,11 ,8  ,couleurButtonPassNum ,11},
  118. {11,"Val" ,6  ,10 ,couleurButtonPassVal ,8 },
  119. {12,"Cor" ,11 ,10 ,couleurButtonPassCor ,13}}
  120.  
  121. for n,buttonP in ipairs(buttonsPassword) do
  122. mon.setCursorPos(buttonP[3],buttonP[4])
  123. mon.setTextColor(buttonP[5])
  124. -----------------------------------------------------------------------mettre le changement "Cor">"Ret" si le pin == nil
  125. mon.write(buttonP[2])
  126. end
  127. end
  128.  
  129. function buttonPagePrin()
  130.   datas()
  131.   if card == 2 then
  132.     datas()
  133.     if tonumber(tostring(data["maxStorageL"])) == 10000000 then
  134.       typestorage = "   MFSu   "
  135.       storageOutput = "   512    "
  136.     end
  137.     if tonumber(tostring(data["maxStorageL"])) == 600000 then
  138.       typestorage = "   MFE    "
  139.       storageOutput = "   128    "
  140.     end
  141.     if tonumber(tostring(data["maxStorageL"])) == 40000 then
  142.       typestorage = " Bat Box  "
  143.       storageOutput = "    32    "
  144.     end
  145.   else
  146.     typestorage = "  "
  147.     storageOutput = "  "
  148.   end
  149.  
  150.  
  151.  
  152. -- nameTank, nameReactor, nameStorage PosX, PosY, couleur
  153. buttonsPagePrin={
  154.   {"Flux","Time","Flux",5,2,couleurTitrePage},
  155.   {"Tank","Heat","Amps",11,2,couleurTitrePage},
  156.   {title,title,title,5,4,couleurTitrePage},
  157.   {"   Type   "," Max Heat ","   Type   ",5,6,couleurCarPage},
  158.   {typetank,"   "..maxHeat,typestorage,5,7,couleurCarVar},
  159.   {" Capacity ","  Output  ","  Output  ",5,8,couleurCarPage},
  160.   {capaTank,"    "..output,storageOutput,5,9,couleurCarVar}
  161. }
  162.  
  163.  
  164. for n,buttonPage in ipairs(buttonsPagePrin) do
  165. mon.setCursorPos(buttonPage[4],buttonPage[5])
  166. mon.setTextColor(buttonPage[6])
  167. mon.write(buttonPage[1+card])
  168. end
  169. end
  170.  
  171. function datas()
  172.  uid, state, title, data = reader.get(1)
  173.   if state== "OK" then
  174.     if card == 0 then
  175.       liquideMeta = tostring(data["liquidMeta"])
  176.       capacity = tostring(data["capacity"])
  177.       liquidId = tostring(data["liquidId"])
  178.       amount = tostring(data["amount"])
  179.      
  180.       heat = 0
  181.       isSteam = 0
  182.       reactorPoweredB = 0
  183.       maxHeat = 0
  184.       timeLeft = 0
  185.       output = 0
  186.       maxAdmissibleHeat = 0    
  187.      
  188.       energyL = 0
  189.       maxStorageL = 0  
  190.     end
  191.     if card == 1 then
  192.       liquideMeta = 0
  193.       capacity = 0
  194.       liquidId = 0
  195.       amount = 0  
  196.    
  197.       heat = tostring(data["heat"])
  198.       isSteam = tostring(data["isSteam"])
  199.       reactorPoweredB = tostring(data["reactorPoweredB"])
  200.       maxHeat = tostring(data["maxHeat"])
  201.       timeLeft = tostring(data["timeLeft"])
  202.       output = tostring(data["output"])
  203.       maxAdmissibleHeat = (maxHeat/100*40)
  204.      
  205.       energyL = 0
  206.       maxStorageL = 0  
  207.    
  208.     end
  209.     if card == 2 then
  210.       liquideMeta = 0
  211.       capacity = 0
  212.       liquidId = 0
  213.       amount = 0  
  214.    
  215.       heat = 0
  216.       isSteam = 0
  217.       reactorPoweredB = 0
  218.       maxHeat = 0
  219.       timeLeft = 0
  220.       output = 0
  221.       maxAdmissibleHeat = 0
  222.    
  223.       energyL = tostring(data["energyL"])
  224.       maxStorageL = tostring(data["maxStorageL"])    
  225.     end
  226.   else
  227.     peripherals()
  228.   end
  229. end
  230.  
  231. --- fonctions barres --
  232.  
  233. function Barres()
  234.   if card == 0 then print("tralala")
  235.   end
  236.   if card == 1 then
  237.    barreTime()
  238.    barreHeat()
  239.   end
  240.   if card == 2 then print("tralala")
  241.   barreStorage()
  242.   barreStorageFlux()
  243.   end
  244. end
  245.  
  246. function barreTime()
  247.   if tonumber(timeLeft) > 0 then
  248.     for i = 1,20 do
  249.       if  100*timeLeft/timeb > math.abs(i-21)*5 then
  250.         mon.setCursorPos(2,math.ceil(i/2)+1)
  251.         mon.setTextColor(colors.lime)
  252.         mon.setBackgroundColor(colors.lime)
  253.         mon.write("##")
  254.       else
  255.         if  100*timeLeft/timeb < math.abs(i-21)*5 and 100*timeLeft/timeb > math.abs(i-20)*5 then
  256.           mon.setCursorPos(2,math.ceil(i/2)+1)
  257.           mon.setTextColor(colors.green)
  258.           mon.setBackgroundColor(colors.green)
  259.           mon.write("##")
  260.         else
  261.           mon.setCursorPos(2,math.ceil(i/2)+1)
  262.           mon.setTextColor(colors.black)
  263.           mon.setBackgroundColor(colors.black)
  264.           mon.write("  ")
  265.         end
  266.       end
  267.     end
  268.   end
  269.   mon.setBackgroundColor(colors.black)
  270. end
  271.  
  272. function barreHeat()
  273.   for i = 1,20 do
  274.     if math.abs(i-21)*maxAdmissibleHeat/20 < tonumber(heat) and math.abs(i-22)*maxAdmissibleHeat/20 > tonumber(heat) then
  275.       mon.setCursorPos(16,math.ceil(i/2)+1)
  276.       mon.setTextColor(colors.orange)
  277.       mon.setBackgroundColor(colors.orange)
  278.       mon.write("##")
  279.     else
  280.       if  math.abs(i-21)*maxAdmissibleHeat/20 < tonumber(heat) and math.abs(i-22)*maxAdmissibleHeat/20 < tonumber(heat) then
  281.         mon.setCursorPos(16,math.ceil(i/2)+1)
  282.         mon.setTextColor(colors.red)
  283.         mon.setBackgroundColor(colors.red)
  284.         mon.write("##")
  285.       else
  286.         mon.setCursorPos(16,math.ceil(i/2)+1)
  287.         mon.setTextColor(colors.black)
  288.         mon.setBackgroundColor(colors.black)
  289.         mon.write("  ")
  290.       end
  291.     end
  292.   end
  293.   mon.setBackgroundColor(colors.black)
  294. end
  295.  
  296. function barreStorage()
  297.   for i = 1,20 do
  298.     if  energyL/maxStorageL*100 > math.abs(i-21)*5 and energyL/maxStorageL*100 < math.abs(i-22)*5 then
  299.       mon.setCursorPos(16,math.ceil(i/2)+1)
  300.       mon.setTextColor(colors.lightBlue)
  301.       mon.setBackgroundColor(colors.lightBlue)
  302.       mon.write("##")
  303.     else
  304.       if energyL/maxStorageL*100 >= math.abs(i-21)*5 and energyL/maxStorageL*100 >= math.abs(i-22)*5 then
  305.         mon.setCursorPos(16,math.ceil(i/2)+1)
  306.         mon.setTextColor(colors.cyan)
  307.         mon.setBackgroundColor(colors.cyan)
  308.         mon.write("##")
  309.       else
  310.         mon.setCursorPos(16,math.ceil(i/2)+1)
  311.         mon.setTextColor(colors.black)
  312.         mon.setBackgroundColor(colors.black)
  313.         mon.write("  ")
  314.       end
  315.     end
  316.   end
  317.   mon.setBackgroundColor(colors.black)
  318. end
  319.  
  320. function barreStorageFlux()
  321.   if tonumber(maxStorageL) == 10000000 then storOutput = 512 end
  322.   if tonumber(maxStorageL) == 600000 then storOutput = 128 end
  323.   if tonumber(maxStorageL) == 40000 then storOutput = 32 end
  324.  
  325.   Stor2 = tonumber(energyL)
  326.   PercStor = (Stor2-Stor1)/20
  327.   PercStorOutput = ((PercStor/storOutput)*100)
  328.  
  329. --- flux positif
  330.   for i = 1,10 do
  331.     if PercStorOutput > 0 and PercStorOutput > math.abs(i-11)*10 and PercStorOutput < math.abs(i-12)*10 then
  332.       mon.setCursorPos(2,math.ceil(i/2)+1)
  333.       mon.setTextColor(colors.lime)
  334.       mon.setBackgroundColor(colors.lime)
  335.       mon.write("##")
  336.     else
  337.       if PercStorOutput > 0 and PercStorOutput > math.abs(i-11)*10 and PercStorOutput > math.abs(i-12)*10 then
  338.         mon.setCursorPos(2,math.ceil(i/2)+1)
  339.         mon.setTextColor(colors.green)
  340.         mon.setBackgroundColor(colors.green)
  341.         mon.write("##")
  342.       else
  343.         mon.setCursorPos(2,math.ceil(i/2)+1)
  344.         mon.setTextColor(colors.black)
  345.         mon.setBackgroundColor(colors.black)
  346.         mon.write("  ")
  347.       end
  348.     end
  349.   end
  350. --- flux negatif
  351.   for i = 1,10 do
  352.     if PercStorOutput < 0 and math.abs(PercStorOutput) > i*10 and math.abs(PercStorOutput) < (i+1)*10 then
  353.       mon.setCursorPos(2,math.ceil(i/2)+6)
  354.       mon.setTextColor(colors.orange)
  355.       mon.setBackgroundColor(colors.orange)
  356.       mon.write("##")
  357.     else
  358.       if PercStorOutput < 0 and math.abs(PercStorOutput) > i*10 and math.abs(PercStorOutput) > (i+1)*10 then
  359.         mon.setCursorPos(2,math.ceil(i/2)+6)
  360.         mon.setTextColor(colors.red)
  361.         mon.setBackgroundColor(colors.red)
  362.         mon.write("##")
  363.       else
  364.         mon.setCursorPos(2,math.ceil(i/2)+6)
  365.         mon.setTextColor(colors.black)
  366.         mon.setBackgroundColor(colors.black)
  367.         mon.write("  ")
  368.       end
  369.     end
  370.   end
  371.   mon.setBackgroundColor(colors.black)
  372.   Stor1 = Stor2
  373. end
  374.  
  375. --- Programme ---
  376.  
  377. peripherals()
  378. cadreBase()
  379.  while true do
  380.    peripherals()
  381.    datas()
  382.    buttonPagePrin()
  383.    Barres()
  384.    sleep(1)
  385.  end
Advertisement
Add Comment
Please, Sign In to add comment