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")
- print("Requires... ok")
- os.sleep(0,5)
- --Définitions des variables
- local init = 0 --valeur avant initialisation
- local table_fermenter = {name_oc="fermenter",name=" Fermenteur ",item=" Cannes à sucre",item_color=0xb4f6a3,product=" Ethanol ",product_color=0xcccaa5}
- local table_squeezer = {name_oc="squeezer",name=" Extracteur ",item="Graines de melon",item_color=0xdf9891,product="Huile de plante",product_color=0x6a6837}
- local table_generale = {table_fermenter,table_squeezer}
- local tableau_envoi = {}
- local tableau_mode_auto = {1,1} -- mode_item,mode_produit / 1 = OFF / 2 = Auto / 3 = ON
- local tableau_old_mode_auto = {3,3} -- mode_item,mode_produit / 1 = OFF / 2 = Auto / 3 = ON
- local tableau_etat_sortie = {false,false,false} -- 1 = item / 2 = produit / 3 = alim_elec
- local tableau_old_etat_sortie = {true,true,true} -- 1 = item / 2 = produit / 3 = alim_elec
- local tableau_bit = {{false,true},{true,false}} -- 1 = item / 2 = produit
- local ntable = 0
- local arg = {...}
- local groupement_machine = tonumber(arg[1])
- local nb_machine = tonumber(arg[2])
- local nom_machine = tostring(arg[3])
- local machine
- local noir = 0x000000
- local blanc = 0xFFFFFF
- local rouge = 0xFF0000
- local vert = 0x00FF00
- local orange = 0xFFFA000
- local i = 0
- local j = 0
- local Idcodes
- local top = sides.top
- local volume = 0
- local volume_max = 0
- local old_volume = 50000000000
- local stock_item = 0
- local item_max = 0
- local old_item = 50000000000
- local niveau_mini = 7
- local niveau_maxi = 93
- print("Initialisation variables... ok")
- os.sleep(0,5)
- --Récupération du matériel
- local screen = component.getPrimary("screen")
- local gpu = component.gpu
- gpu.setResolution(60,30)
- local modem = component.modem
- local rs = component.redstone
- local port_modem = 10001
- local pompe = component.immersiveengineering_fluidpump
- if nom_machine == "f" then
- ntable = 1
- machine = component.proxy(component.get("","ie_fermenter"))
- elseif nom_machine == "s" then
- ntable = 2
- machine = component.proxy(component.get("","ie_squeezer"))
- end
- print("Récupération materiel... ok")
- os.sleep(0,5)
- --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(blanc - 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
- function niveau_sens(amount,old_amount)
- if old_amount < amount then
- return "►"
- elseif old_amount > amount then
- return "◄"
- elseif old_amount == amount then
- return "="
- end
- end
- local function barre_verticale(x,y,hauteur,largeur,amount,capacity,old,color,text1,text2,text3)
- local k = 0
- 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(color,blanc-color)
- elseif k > cur then
- setColor(noir,blanc)
- end
- gpu.set(x,vy,dir)
- if k == hauteur - 11 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy,string.format(" %06.02f%% ",(amount/capacity)*100)) --Pourcentage
- elseif k == hauteur - 10 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy," Pourcentage")
- elseif k == hauteur - 8 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy,text1)
- elseif k == hauteur - 7 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy," Valeur Maximale")
- elseif k == hauteur - 5 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy,text2)
- elseif k == hauteur - 4 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy," Valeur actuelle")
- elseif k == hauteur - 1 then
- gpu.set(x,vy,dir)
- gpu.set(x,vy,text3)
- end
- setColor(noir,blanc)
- end
- end
- local function double_barre(x,y,hauteur,largeur)
- local inv1 = 0
- local inv2 = 0
- item_max = 64*9
- for i = 1, 9 do
- if machine.getInputStack(i) == nil then
- inv2 = 0
- else
- inv2 = tonumber(machine.getInputStack(i).size)
- end
- inv1 = inv1 + inv2
- end
- stock_item = inv1
- if old_item == stock_item then
- else
- barre_verticale(x,y,hauteur,largeur,stock_item,item_max,old_item,table_generale[ntable].item_color,string.format(" Quantité % 3d",item_max),string.format(" % 3d",stock_item).." "..niveau_sens(stock_item,old_item),table_generale[ntable].item)
- end
- local volume1
- local volume2
- volume_max = 12000 + 4000
- if pompe.getTankInfo(1)[1].contents == nil then
- volume1 = 0
- else
- volume1 = pompe.getTankInfo(1)[1].contents.amount
- end
- if machine.getFluid().amount == nil then
- volume2 = 0
- else
- volume2 = machine.getFluid().amount
- end
- volume = volume1 + volume2
- if old_volume == volume then
- else
- barre_verticale(x+1+largeur,y,hauteur,largeur,volume,volume_max,old_volume,table_generale[ntable].product_color," "..unitmb(volume_max)," "..unitmb(volume).." "..niveau_sens(volume,old_volume),table_generale[ntable].product)
- end
- old_volume = volume
- old_item = stock_item
- end
- local function on_auto_off(x,y,n)
- if tableau_mode_auto[n] == 1 then
- setColor(rouge, noir)
- gpu.set(x+4,y," OFF ")
- setColor(noir, orange)
- gpu.set(x+3,y+1,"Auto")
- setColor(noir, vert)
- gpu.set(x,y," ON ")
- elseif tableau_mode_auto[n] == 2 then
- setColor(noir, rouge)
- gpu.set(x+4,y," OFF ")
- setColor(orange, noir)
- gpu.set(x+3,y+1,"Auto")
- setColor(noir, vert)
- gpu.set(x,y," ON ")
- elseif tableau_mode_auto[n] == 3 then
- setColor(noir, rouge)
- gpu.set(x+4,y," OFF ")
- setColor(noir, orange)
- gpu.set(x+3,y+1,"Auto")
- setColor(vert, noir)
- gpu.set(x,y," ON ")
- end
- setColor(noir, blanc)
- end
- local function on_off(x,y,n)
- if tableau_etat_sortie[n] == false then
- setColor(rouge, noir)
- gpu.set(x+4,y," OFF ")
- setColor(noir, vert)
- gpu.set(x,y," ON ")
- rs.setBundledOutput(top,n-1,255)
- elseif tableau_etat_sortie[n] == true then
- setColor(noir, rouge)
- gpu.set(x+4,y," OFF ")
- setColor(vert, noir)
- gpu.set(x,y," ON ")
- rs.setBundledOutput(top,n-1,0)
- end
- setColor(noir, blanc)
- end
- local function etat_vanne(x,y,n)
- if tableau_mode_auto[n] == 1 then
- setColor(noir, rouge)
- gpu.set(x,y,"Fermée ")
- elseif tableau_mode_auto[n] == 2 then
- setColor(noir, orange)
- gpu.set(x,y," Auto ")
- elseif tableau_mode_auto[n] == 3 then
- setColor(noir, vert)
- gpu.set(x,y,"Ouverte")
- end
- setColor(noir, blanc)
- end
- local function vanne(x,y,n)
- if tableau_etat_sortie[n] == false then
- setColor(noir,rouge)
- gpu.set(x,y+0," ║ ")
- gpu.set(x,y+1," ║ ")
- gpu.set(x,y+2," ║ ")
- rs.setBundledOutput(top,n-1,255)
- elseif tableau_etat_sortie[n] == true then
- setColor(noir,vert)
- gpu.set(x,y+0," ")
- gpu.set(x,y+1,"═════")
- gpu.set(x,y+2," ")
- rs.setBundledOutput(top,n-1,0)
- end
- setColor(noir,blanc)
- end
- local function fonction_auto(amount,capacity,x,y,ty,n)
- local pct = amount/capacity
- if tableau_mode_auto[n] == 1 then
- tableau_etat_sortie[n] = false
- elseif tableau_mode_auto[n] == 2 then
- if pct*100 > niveau_maxi then
- tableau_etat_sortie[n] = tableau_bit[n][1]
- elseif pct*100 < niveau_mini then
- tableau_etat_sortie[n] = tableau_bit[n][2]
- end
- elseif tableau_mode_auto[n] == 3 then
- tableau_etat_sortie[n] = true
- end
- if tableau_old_mode_auto[n] == tableau_mode_auto[n] then
- else
- etat_vanne(x-1,y+ty,n)
- end
- if tableau_old_etat_sortie[n] == tableau_etat_sortie[n] then
- else
- vanne(x,y,n)
- end
- if init == 1 then
- tableau_old_etat_sortie[n] = tableau_etat_sortie[n]
- tableau_old_mode_auto[n] = tableau_mode_auto[n]
- end
- end
- local function send(port)
- tableau_envoi[1] = groupement_machine --groupe de machine n°
- tableau_envoi[2] = ntable --type de machine -- 1 : fermenter / 2 : squeezer
- tableau_envoi[3] = nb_machine --n° machine
- tableau_envoi[4] = volume --volume produit
- tableau_envoi[5] = volume_max --voluùme max produit
- tableau_envoi[6] = stock_item --Quantité item
- tableau_envoi[7] = item_max --quantité max item
- tableau_envoi[8] = tableau_etat_sortie[1] --etat sortie item
- tableau_envoi[9] = tableau_etat_sortie[2] --etat sortie produit
- tableau_envoi[10] = tableau_etat_sortie[3] --etat sortie elec
- local table_s = serialization.serialize(tableau_envoi)
- local IDcodes = "machine"
- 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(2+j,29,text)
- end
- print("Fonctions... ok")
- os.sleep(0,5)
- print("Initialisation programme...")
- os.sleep(1)
- --Trame de fond
- gpu.set(1,1,[[╔══════════════════════════════════════════════════════════╗]])
- gpu.set(1,2,[[║ ║]])
- gpu.set(1,3,[[╠════════════════════════════════════════════════╦═════════╣]])
- gpu.set(1,4,[[║ ║ Vanne ║]])
- gpu.set(1,5,[[║ ║ ║ Energie ║]])
- gpu.set(1,6,[[║ ╔═════ ║ ══════════< ║ ON OFF ║]])
- gpu.set(1,7,[[║ ║ ║ ║ ║]])
- gpu.set(1,8,[[║ ║ ╠═════════╣]])
- gpu.set(1,9,[[║ ┌─────────╨────────┬──────────────────┐ ║ Vanne ║]])
- gpu.set(1,10,[[║ │ Objet │ Produit │ ║Composant║]])
- gpu.set(1,11,[[║ │ │ │ ║ ON OFF ║]])
- gpu.set(1,12,[[║ │ │ │ ║ Auto ║]])
- gpu.set(1,13,[[║ │ │ │ ╠═════════╣]])
- gpu.set(1,14,[[║ │ │ │ ║ Vanne ║]])
- gpu.set(1,15,[[║ │ │ │ ║ Produit ║]])
- gpu.set(1,16,[[║ │ │ │ ║ ON OFF ║]])
- gpu.set(1,17,[[║ │ │ │ ║ Auto ║]])
- gpu.set(1,18,[[║ │ │ │ ╠═════════╣]])
- gpu.set(1,19,[[║ │ │ │ ║ ║]])
- 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,[[║ ║ ║ ║]])
- gpu.set(1,28,[[╠════════════════════════════════════════════════╣ ║]])
- gpu.set(1,29,[[║ ║ ║]])
- gpu.set(1,30,[[╚════════════════════════════════════════════════╩═════════╝]])
- fonction_auto(stock_item,item_max,23,5,3,1)
- fonction_auto(volume,volume_max,20,25,-1,2)
- on_off(51,6,3)
- on_auto_off(51,11,1)
- on_auto_off(51,16,2)
- init = 1
- 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.." "..pseudo.." / X : "..string.format("% 3s",x).." / Y : "..string.format("% 3s",y))
- if x~=1 and y~=1 then
- if y==6 then
- if x>50 and x<55 then
- if tableau_etat_sortie[3] == false then
- tableau_etat_sortie[3] = true
- end
- elseif x>54 and x<60 then
- if tableau_etat_sortie[3] == true then
- tableau_etat_sortie[3] = false
- end
- end
- on_off(51,6,3)
- elseif x>50 and x<60 and y>10 and y<13 then
- if x>50 and x<55 and y==11 then
- if tableau_mode_auto[1] ~= 3 then
- tableau_mode_auto[1] = 3
- end
- elseif x>54 and x<60 and y==11 then
- if tableau_mode_auto[1] ~= 1 then
- tableau_mode_auto[1] = 1
- end
- elseif x>53 and x<58 and y==12 then
- if tableau_mode_auto[1] ~= 2 then
- tableau_mode_auto[1] = 2
- end
- end
- on_auto_off(51,11,1)
- elseif x>50 and x<60 and y>15 and y<18 then
- if x>50 and x<55 and y==16 then
- if tableau_mode_auto[2] ~= 3 then
- tableau_mode_auto[2] = 3
- end
- elseif x>54 and x<60 and y==16 then
- if tableau_mode_auto[2] ~= 1 then
- tableau_mode_auto[2] = 1
- end
- elseif x>53 and x<58 and y==17 then
- if tableau_mode_auto[2] ~= 2 then
- tableau_mode_auto[2] = 2
- end
- end
- on_auto_off(51,16,2)
- end
- 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)
- double_barre(8,10,13,18)
- fonction_auto(stock_item,item_max,23,5,3,1)
- fonction_auto(volume,volume_max,20,25,-1,2)
- send(port_modem)
- return true
- end
- event.listen("touch",onTouch)
- local timer = event.timer(.1,onTimer,math.huge)
- event.pull("quit")
- event.cancel(timer)
- rs.setBundledOutput(top,0,255)
- rs.setBundledOutput(top,1,255)
- rs.setBundledOutput(top,2,255)
- event.ignore("touch",onTouch)
- gpu.fill(1,1,160,50," ")
- gpu.setResolution(160,40)
- --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