Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Liste des require
- local computer = require("computer")
- local component = require("component")
- local term = require("term")
- local math = require("math")
- local event = require("event")
- local string = require("string")
- local unicode = require("unicode")
- local colors = require("colors")
- local sides = require("sides")
- local serialization = require("serialization")
- --Définitions des variables
- local noir = 0x000000
- local blanc = 0xFFFFFF
- local rouge = 0xFF0000
- local vert = 0x00FF00
- local bg_plant_oil = 0x6a6837
- local fg_plant_oil = 0xFFFFFF - bg_plant_oil
- local color_tampon = 0x8cf600
- local i = 0
- local volume
- local volume_max
- local old_amount = {0,0,0}
- local old_tank = 0
- local arg = {...}
- local nb_squeezer = tonumber(arg[1])
- local Idcodes
- local top = sides.top
- local table_value = {false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false}
- local value_tampon = 0
- local amount = {0,0,0}
- local inv_squeezer = {0,0,0}
- local j = 0
- local tableau_valeur = {}
- --Récupération du matériel
- local screen = component.getPrimary("screen")
- local gpu = component.gpu
- gpu.setResolution(75,60)
- local modem = component.modem
- local rs = component.redstone
- local port_modem = 10001
- local tank = component.getPrimary("thermalexpansion_tank")
- local chest = component.diamond
- local squeezer1 = component.proxy(component.get("","ie_squeezer"))
- local squeezer2 = component.proxy(component.get("","ie_squeezer"))
- local squeezer3 = component.proxy(component.get("","ie_squeezer"))
- local squeezer = {squeezer1,squeezer2,squeezer3}
- --Fonctions
- local function setColor(bg,fg)
- gpu.setBackground(bg)
- gpu.setForeground(fg)
- end
- local function unitmb(qty)
- if qty >= 1000000000 then
- return string.format("%.02f MB",qty/10000000)
- elseif qty >=1000000 then
- return string.format("%.02f KB",qty/1000000)
- elseif qty >=1000 then
- return string.format("%.02f B ",qty/1000)
- else
- return string.format("%d mB",qty)
- end
- end
- local function loadbar(x,y,width,cur,text,bg)
- local raw = " " .. text ..string.rep(" ", width - unicode.len(text) - 2) .. " "
- local oldbg = gpu.setBackground(bg)
- local oldfg = gpu.setForeground(0xFFFFFF - bg)
- gpu.set(x,y,unicode.sub(raw,1,cur))
- gpu.setBackground(oldbg)
- gpu.setForeground(oldfg)
- gpu.set(x+cur,y,unicode.sub(raw,cur+1,width))
- end
- local function affbar(x,y,length)
- local capacity = tank.getTankInfo()[1].capacity
- local amount
- local text1
- if tank.getTankInfo()[1].contents == nil then
- amount = 0
- text1 = " Stock tampon : " .. "Vide"
- else
- amount = tank.getTankInfo()[1].contents.amount
- text1 = " Stock tampon : " .. tank.getTankInfo()[1].contents.rawName
- end
- tableau_valeur[10] = amount
- tableau_valeur[11] = capacity
- local pct = amount / capacity
- local cur = math.floor(pct * length)
- local textfrac = string.format("%s / %s", unitmb(amount), unitmb(capacity))
- local textpct = string.format("%.02f%%", pct*100)
- local text2
- if old_tank > amount then
- text2 = " ◄ "
- elseif old_tank < amount then
- text2 = " ► "
- elseif old_tank == amount then
- text2 = " = "
- end
- local text3 = textfrac .. string.rep(" ", length - string.len(textfrac) - string.len(textpct) - 2) .. textpct
- loadbar(x,y,length,cur,text1,bg_plant_oil)
- loadbar(x,y+1,length,cur,text2,bg_plant_oil)
- loadbar(x,y+2,length,cur,text3,bg_plant_oil)
- old_tank = amount
- end
- local function barre_verticale(x,y,hauteur,largeur,amount,capacity,n)
- local inv1 = 0
- local inv2 = 0
- local entete = " Squeezer n°"..n
- for i = 1, 9 do
- if squeezer[n].getInputStack(i) == nil then
- inv2 = 0
- else
- inv2 = tonumber(squeezer[n].getInputStack(i).size)
- end
- inv1 = inv1 + inv2
- end
- inv_squeezer[n] = inv1
- local k = 0
- local text
- if old_amount[n] < amount then
- text = " ► "
- elseif old_amount[n] > amount then
- text = " ◄ "
- elseif old_amount[n] == amount then
- text = " = "
- end
- local cur = math.floor((amount / capacity) * hauteur)
- local dir = string.rep(" ",largeur)
- for k = 1, hauteur do
- local vy = y + hauteur - k
- if k <= cur then
- setColor(bg_plant_oil,fg_plant_oil)
- elseif k > cur then
- setColor(noir,blanc)
- end
- gpu.set(x,vy,dir)
- if k == 1 then
- gpu.set(x,vy,dir)
- elseif k == hauteur - 22 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy,string.format(" % 6.02f%%",inv1*100/(64*9)))
- elseif k == hauteur - 21 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy,string.format(" Quantité % 3d",inv1))
- elseif k == hauteur - 20 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy,"Graine de melon")
- elseif k == hauteur - 10 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy,string.format(" Cur %06.02f%% ",(amount/capacity)*100))
- elseif k == hauteur - 8 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy," Max "..unitmb(capacity))
- elseif k == hauteur - 6 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy," Etat :"..text)
- elseif k == hauteur - 5 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy," Cur "..unitmb(amount))
- elseif k == hauteur - 1 then
- gpu.set(x,vy,entete)
- end
- setColor(noir,blanc)
- end
- end
- local function process(x,y,hauteur,largeur,n)
- local capacity = 12000
- if squeezer[n].getFluid().amount == nil then
- amount[n] = 0
- else
- amount[n] = squeezer[n].getFluid().amount
- end
- barre_verticale(x,y,hauteur,largeur,amount[n],capacity,n)
- old_amount[n] = amount[n]
- end
- local function process_x3(x,y,hauteur,largeur)
- process(x,y,hauteur,largeur,1)
- process(x+16,y,hauteur,largeur,2)
- process(x+32,y,hauteur,largeur,3)
- end
- local function tampon(x,y,largeur)
- value_tampon = 0
- local inv = 0
- local capacity = 108*64
- for i = 1, 108 do
- if chest.getStackInSlot(i) == nil then
- inv = 0
- else
- inv = chest.getStackInSlot(i).qty
- end
- value_tampon = value_tampon + inv
- end
- local pct = value_tampon / capacity
- local cur = math.floor(pct * largeur)
- local text1 = " "..string.format("%s / %s", value_tampon, capacity)
- local text2 = " "..string.format("% 6.02f%%", pct*100)
- loadbar(x,y,largeur,cur,text1,color_tampon)
- loadbar(x,y+1,largeur,cur,text2,color_tampon)
- end
- local function vanne(x,y,tx,ty,n)
- if tx > x-1 and tx < x+5 and ty > y-1 and ty < y+3 then
- if table_value[n] == false then
- table_value[n] = true
- elseif table_value[n] == true then
- table_value[n] = false
- end
- end
- if table_value[n] == true then
- setColor(noir,vert)
- gpu.set(x+2,y+1,"║")
- gpu.set(x,y+2," ║ ")
- gpu.set(x+2,y+3,"║")
- rs.setBundledOutput(top,n-1,0)
- elseif table_value[n] == false then
- setColor(noir,rouge)
- gpu.set(x+2,y+1," ")
- gpu.set(x,y+2,"═════")
- gpu.set(x+2,y+3," ")
- rs.setBundledOutput(top,n-1,255)
- end
- setColor(noir,blanc)
- end
- local function on_off(x,y,tx,ty,n)
- if tx > x-1 and tx < x+5 and ty == y then
- if table_value[n] == false then
- table_value[n] = true
- elseif table_value[n] == true then
- table_value[n] = false
- end
- end
- if table_value[n] == true then
- text = " ON "
- color = vert
- rs.setBundledOutput(top,n-1,0)
- elseif table_value[n] == false then
- text = " OFF "
- color = rouge
- rs.setBundledOutput(top,n-1,255)
- end
- setColor(color,noir)
- gpu.set(x,y,text)
- setColor(noir,blanc)
- end
- local function send(port)
- tableau_valeur[1] = nb_squeezer --n° squeezer
- tableau_valeur[2] = amount[1] --Quantité squeezer 1
- tableau_valeur[3] = amount[2] --Quantité squeezer 2
- tableau_valeur[4] = amount[3] --Quantité squeezer 3
- tableau_valeur[5] = 12000 --quantité max squeezer
- tableau_valeur[6] = inv_squeezer[1] --Inventaire squeezer 1
- tableau_valeur[7] = inv_squeezer[2] --Inventaire squeezer 2
- tableau_valeur[8] = inv_squeezer[3] --Inventaire squeezer 3
- tableau_valeur[9] = 9*64 --Inventaire max squeezer
- tableau_valeur[12] = value_tampon --tampon
- tableau_valeur[13] = 108*64 --tampon max
- local table_s = serialization.serialize(tableau_valeur)
- local IDcodes = "squeezer"
- modem.broadcast(port,IDcodes,table_s)
- local texte_vide = ""
- j = j + 1
- if j > 9 then
- j = 0
- texte_vide = " "
- end
- local text = " Envoi n°"..string.format("%s", j+1).." Confirmé"..texte_vide
- gpu.set(34+j,54,text)
- end
- --Trame de fond
- gpu.set(1,1,[[╔═════════════════════════════════════════════════════════════════════════╗]])
- gpu.set(1,2,[[║ ║]])
- gpu.set(1,3,[[╠═════════════════════════════════════════════════════════════════════════╣]])
- gpu.set(1,4,[[║ _________________________________________ ║]])
- gpu.set(1,5,[[║ / \ ║]])
- gpu.set(1,6,[[║ / COLONNE DE PRESSES-JUS N° \ ║]])
- gpu.set(1,7,[[║ /_____________________________________________\ ║]])
- gpu.set(1,8,[[║ │ │ │ │ ║]])
- gpu.set(1,9,[[║ │ │ │ │ ║]])
- gpu.set(1,10,[[║ │ │ │ │ ║]])
- gpu.set(1,11,[[║ │ │ │ │ ║]])
- gpu.set(1,12,[[║ │ │ │ │ ║]])
- gpu.set(1,13,[[║ │ │ │ │ ║]])
- gpu.set(1,14,[[║ │ │ │ │ ║]])
- gpu.set(1,15,[[║ │ │ │ │ ║]])
- gpu.set(1,16,[[║ │ │ │ │ Alimentation Générale ║]])
- gpu.set(1,17,[[║ │ │ │ │ Energie : ■OFF■ ║]])
- gpu.set(1,18,[[║ │ │ │ │ Produit : ■OFF■ ║]])
- gpu.set(1,19,[[║ │ │ │ │ Tampon : ■OFF■ ║]])
- gpu.set(1,20,[[║ │ │ │ │ ║]])
- gpu.set(1,21,[[║ │ │ │ │ ║]])
- gpu.set(1,22,[[║ │ │ │ │ ║]])
- gpu.set(1,23,[[║ │ │ │ │ ║]])
- gpu.set(1,24,[[║ │ │ │ │ ║]])
- gpu.set(1,25,[[║ │ │ │ │ ║]])
- gpu.set(1,26,[[║ │ │ │ │ ║]])
- gpu.set(1,27,[[║ │ │ │ │ ╔══< Alimentation ║]])
- gpu.set(1,28,[[║ │ │ │ │ ║ ║]])
- gpu.set(1,29,[[║ │ │ │ │ ║]])
- gpu.set(1,30,[[║ │ │ │ │ ═════ ║]])
- gpu.set(1,31,[[║ │ │ │ │ ║]])
- gpu.set(1,32,[[║ │ │ │ │ ┌─╨─────────────┐ ║]])
- gpu.set(1,33,[[║ │ │ │ │ │ Stock Tampon │ ║]])
- gpu.set(1,34,[[║ │ │ │ │ │ │ ║]])
- gpu.set(1,35,[[║ │ │ │ │ │ │ ║]])
- gpu.set(1,36,[[║ │ │ │ │ │ │ ║]])
- gpu.set(1,37,[[║ │ │ │ │ └───────╥───────┘ ║]])
- gpu.set(1,38,[[║ │ │ │ │ ║ ║]])
- gpu.set(1,39,[[║ ├───────────────┼───────────────┼───────────────┤ ║]])
- gpu.set(1,40,[[║ │ Alimentation │ Alimentation │ Alimentation │ ═════ ║]])
- gpu.set(1,41,[[║ │ Energie : OFF │ Energie : OFF │ Energie : OFF │ ║]])
- gpu.set(1,42,[[║ │ Produit : OFF │ Produit : OFF │ Produit : OFF ╞═══════════╝ ║]])
- gpu.set(1,43,[[║ │ Pompe : OFF │ Pompe : OFF │ Pompe : OFF │ ║]])
- gpu.set(1,44,[[║ ├───────────────┴───────────────┴───────────────┤ ║]])
- gpu.set(1,45,[[║ │ │ ║]])
- gpu.set(1,46,[[║ │ │ ║]])
- gpu.set(1,47,[[║ │ │ ║]])
- gpu.set(1,48,[[║ └────────────────────────╥──────────────────────┘ ║]])
- gpu.set(1,49,[[║ ║ ║]])
- gpu.set(1,50,[[║ ║]])
- gpu.set(1,51,[[║ ═════ ║]])
- gpu.set(1,52,[[║ ║]])
- gpu.set(1,53,[[║ ║ ║]])
- gpu.set(1,54,[[║ /¯¯║¯¯\ ║]])
- gpu.set(1,55,[[║ /¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ ║]])
- gpu.set(1,56,[[║ │ Cuve Plant Oil Générale │ ║]])
- gpu.set(1,57,[[║ │ │ ║]])
- gpu.set(1,58,[[║ │ │ ║]])
- gpu.set(1,59,[[║ \___________________________________________________________________/ ║]])
- gpu.set(1,60,[[╚═════════════════════════════════════════════════════════════════════════╝]])
- local function affbouton(x,y)
- on_off(14,41,x,y,1)
- on_off(14,42,x,y,2)
- on_off(14,43,x,y,3)
- on_off(30,41,x,y,4)
- on_off(30,42,x,y,5)
- on_off(30,43,x,y,6)
- on_off(46,41,x,y,7)
- on_off(46,42,x,y,8)
- on_off(46,43,x,y,9)
- on_off(66,17,x,y,10)
- on_off(66,18,x,y,11)
- on_off(66,19,x,y,12)
- vanne(55,28,x,y,13)
- vanne(61,38,x,y,14)
- vanne(26,49,x,y,14)
- end
- affbouton(2,2)
- gpu.set(40,6,tostring(nb_squeezer))
- local function onTouch(_,address,x,y,clic,pseudo)
- local tclic
- if clic == 0 then
- tclic = "Clic gauche"
- elseif clic == 1 then
- tclic = "Clic droit"
- else
- tclic = "Clic inconnu"
- end
- gpu.set(4,2,tclic.." de la part de "..pseudo.." / X : "..string.format("% 3s",x).." / Y : "..string.format("% 3s",y))
- if x~=1 and y~=1 then
- elseif x==1 and y==1 then
- computer.pushSignal("quit")
- gpu.fill(1,1,160,50," ")
- term.setCursor(1,1)
- return false
- end
- end
- local function onTimer(_,timer)
- process_x3(4,9,30,15)
- affbar(4,45,47)
- tampon(56,34,15)
- send(port_modem)
- return true
- end
- event.listen("touch",onTouch)
- local timer = event.timer(.1,onTimer,math.huge)
- event.pull("quit")
- event.cancel(timer)
- event.ignore("touch",onTouch)
- gpu.fill(1,1,160,50," ")
- gpu.setResolution(160,50)
- --Créé par sshikamaru. Vous avez le droit de l'utiliser mais pas de le distribuer.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement