Advertisement
tontondubled

EnergyStorageDraconic

Aug 22nd, 2019
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 KB | None | 0 0
  1. local component = require("component")
  2.  
  3. local gpu = component.gpu                      
  4. local term = require("term")
  5.  
  6. local energyCore = component.draconic_rf_storage
  7. local maxEnergy = energyCore.getMaxEnergyStored()
  8.  
  9. local function niveau()                        
  10.     production = energyCore.getTransferPerTick()
  11.     energy = energyCore.getEnergyStored()  
  12.     pct = (energy * 100) / maxEnergy  
  13. end
  14.  
  15.  
  16. local function miseEnPage()                     -- Valeur en gRf
  17.   ken = (energy/1000000000000)
  18.   kprod = (production/1000000000)
  19. end
  20.  
  21. local function affiche()                        -- Valeurs Bruts
  22.   gpu.setBackground(0xffffff)
  23.   gpu.setForeground(0x023f63)
  24.  
  25.   gpu.set(5,5,"Production :"..production.." RF/t")
  26.   gpu.set(5,6,"Energie       :"..energy.." RF")
  27.   gpu.set(5,7,"Energy en pct :"..pct.." %")
  28.  
  29.   gpu.setBackground(0x000000)
  30.   gpu.setForeground(0xffffff)
  31. end
  32.  
  33.  
  34.  
  35. local function affiche2()                       -- Valeurs Final
  36.   gpu.setBackground(0xffffff)
  37.   gpu.setForeground(0x000000)
  38.  
  39.   gpu.set(5,13,string.format("Production    : %2.2f gRF/t",kprod))
  40.   gpu.set(5,14,string.format("Energie       : %5.2f tRF",ken))
  41.   gpu.set(5,15,string.format("Energy en pct : %3.2f",pct).." %")
  42.  
  43.    
  44.     local fond_barre = 0xdcdcdc
  45.     local barre = 0x21af0e
  46.    
  47.     if pct <= 50 then barre = 0xc81515 else barre = 0x21af0e end
  48.    
  49.     bar_h(5,17,38,pct,2,barre,fond_barre)
  50.  
  51.  
  52.   gpu.setBackground(0x000000)
  53.   gpu.setForeground(0xffffff)
  54. end
  55.  
  56. local function bloc(a,b,l,h,titre,couleur)              -- Bloc syntax
  57.   gpu.setBackground(couleur)
  58.   gpu.setForeground(0xffffff)
  59.  
  60.   gpu.fill(a,b,l,1," ")                                 -- Barre de titre
  61.   gpu.set((a+1),b,titre)                                -- Affichage du titre  
  62.  
  63.   gpu.setBackground(0xffffff)
  64.   gpu.fill(a,(b+1),l,h," ")                             -- Font de boite
  65. end
  66.  
  67.     function bar_h(bar_x,bar_y,bar_l,pos,ep,color,fond)     -- Barre horizontal syntax
  68.         local m = (bar_l/100)                       -- Rapport pct / position
  69.         local f = math.floor(pos*m)                 -- Calcul de la valeur de position ou f = valeur de barre
  70.        
  71.         gpu.setBackground(color)                    -- Couleur barre
  72.         gpu.fill(bar_x,bar_y,f,ep," ")              -- Barre progressive
  73.        
  74.         gpu.setBackground(fond)                 -- Couleur font de barre
  75.         gpu.fill((bar_x+f),bar_y,(bar_l-f),ep," ")  -- Font de barre
  76.    
  77.     end
  78.         --gpu.setBackground(0xf0f0f0)
  79.         --gpu.setForeground(0x222222)                   -- Indication des valeurs de test
  80.         --gpu.set(bar_x,(bar_y+1+ep),titre.." :"..string.format(" %3.2f",pos))
  81.     -- end
  82.  
  83. term.clear()
  84.  
  85. bloc(4,3,40,5,"Valeurs Brut",0x023f63)                  -- Bloc d'affichage
  86. bloc(4,11,40,8,"Valeurs Formatés",0xe9e300)
  87.  
  88.  
  89. while true do                                   -- Boucle infinie
  90.  
  91.     niveau()                                                 -- Valeurs boule draco
  92.     miseEnPage()  
  93.     affiche()
  94.     affiche2()  
  95.    
  96.     os.sleep(1)                                             -- Pause d'une seconde
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement