Tawok

Untitled

Apr 17th, 2022 (edited)
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --decalrations
  2.  
  3. monitor = peripheral.find("monitor") or error("no monitor")
  4. chest = peripheral.find("ironchest:gold_chest") or error("no chest")
  5. width, height = monitor.getSize()
  6. itemsMax = 0    
  7. --index : height/2 pour travailler au milieu du monitor
  8. index = height/2
  9.  
  10. --Methodes
  11.     --#initScreen
  12.         --Pour initialiser le monitor
  13. function initScreen()
  14.     monitor.setTextColor(colors.white)
  15.     monitor.setBackgroundColor(colors.gray)
  16.     monitor.clear()
  17.     monitor.setTextScale(0.5)
  18.     monitor.setBackgroundColor(colors.black)
  19.     monitor.setCursorPos(1,index-1)
  20.     monitor.clearLine()
  21.     monitor.setCursorPos(1,index+1)
  22.     monitor.clearLine()
  23.     monitor.setBackgroundColor(colors.gray)
  24. end
  25.     --#Count
  26.         --Pour conter le nombre total d'items dans le chest
  27. function Count(chest)
  28.     --recuperation de la liste pour eviter les problemes de nullPointer
  29.     local list = {}
  30.     list = chest.list()
  31.     size = chest.size()
  32.     local cpt=0
  33.         for i=1, size, 1 do
  34.             if list[i]~=nil then
  35.                 --increase cpt only if not null
  36.                 cpt=cpt+list[i].count
  37.             end
  38.         end
  39.     return cpt  
  40. end
  41.     --#ProgressBar  
  42.         --Pour afficher la barre de progression
  43. function ProgressBar(chest)
  44.     --items : current number of items in chest
  45.     local items = Count(chest)
  46.     --itemMax : nombre d'items deposes
  47.     local tmp = Count(chest)
  48.         --si des items ont etes ajoutes
  49.     if tmp>itemsMax then
  50.         itemsMax=tmp
  51.         --sinon c'est que ca decroit, rien ne change
  52.     end
  53.    
  54.     monitor.setCursorPos(1,index)
  55.     --status percent in decimal
  56.     local status = 1-(items/itemsMax)  
  57.     local percent = math.floor(status*100).."%"
  58.    
  59.     --index pour savoir quand couper la progress barre
  60.     local index = width*status
  61.    
  62.     --affichage terminal des infos donnees
  63.     print("====")
  64.     print(("    MaxItems: %d\nCurrentItems: %d"):format(itemsMax,items))
  65.     print("     Status: "..percent)
  66.     print(("Width: %d // percent proportion: %d"):format(width, index))
  67.            
  68.     --partie ok de la progress bar
  69.     for i=1, index, 1 do
  70.         monitor.blit(" ","5","5")
  71.     end
  72.    
  73.    
  74. end
  75.  
  76.  
  77. --main
  78. print(("w%d;h%d"):format(width,height))
  79.  
  80. while true do
  81.     initScreen()
  82.     monitor.setCursorPos(1,1)
  83.     monitor.write("Advancement")
  84.     if Count(chest)==0 then
  85.         print("No items in chest")
  86.         itemsMax = 0
  87.         else
  88.             ProgressBar(chest)
  89.         --Refresh every 1 second
  90.         os.sleep(1)
  91.         --remettre la backgroundcolor a grey car lors du clear
  92.         --le monitor fill avec la derniere info de color (cf docu)
  93.         monitor.setBackgroundColor(colors.gray)
  94.     end
  95. end
Add Comment
Please, Sign In to add comment