Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Requires
- 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 side = require("sides")
- local serialization = require("serialization")
- --Récupération des composants
- local screen = component.getPrimary("screen")
- local gpu = component.gpu
- local rs1 = component.proxy(component.get("5C48","redstone"))
- local rs2 = component.proxy(component.get("6531","redstone"))
- gpu.setResolution(91,50)
- local modem = component.modem
- --Variables
- local i = 0
- local tableau_general = {}
- local bit_diesel = {}
- --Ouverture des ports
- modem.open(10001)
- modem.open(10003)
- --Fonctions
- local function setColor(bg,fg)
- gpu.setBackground(bg)
- gpu.setForeground(fg)
- end
- local function unitrf(qty)
- if qty >= 1000000000000000 or qty <= -1000000000000000 then
- return string.format("%.03f PRF/t",qty/1000000000000000)
- elseif qty >= 1000000000000 or qty <= -1000000000000 then
- return string.format("%.03f TRF/t",qty/1000000000000)
- elseif qty >=1000000000 or qty <= -1000000000 then
- return string.format("%.03f GRF/t",qty/1000000000)
- elseif qty >=1000000 or qty <= -1000000 then
- return string.format("%.03f MRF/t",qty/1000000)
- elseif qty >=1000 or qty <= -1000 then
- return string.format("%.03f kRF/t",qty/1000)
- else
- return string.format("%.03f RF/t ",qty)
- end
- end
- local function barre_verticale(x,y,hauteur,largeur,valeur,valmax)
- local k = 0
- local cur = math.floor((valeur / valmax) * hauteur)
- local dir = string.rep(" ",largeur)
- for k = 1, hauteur do
- local vy = y + hauteur - k
- if k <= cur then
- setColor(0x00FF00,0x0000FF)
- elseif k > cur then
- setColor(0x000000,0xFFFFFF)
- end
- gpu.set(x,vy,dir)
- setColor(0x000000,0xFFFFFF)
- end
- end
- local function loadbar(x,y,longueur,valeur,text,bg,fg)
- local raw = " " .. text ..string.rep(" ", longueur - unicode.len(text) - 2) .. " "
- local oldbg = gpu.setBackground(bg)
- local oldfg = gpu.setForeground(fg)
- gpu.set(x,y,unicode.sub(raw,1,valeur))
- gpu.setBackground(oldbg)
- gpu.setForeground(oldfg)
- gpu.set(x+valeur,y,unicode.sub(raw,valeur+1,longueur))
- end
- local function affenergie(x,y,length,tableau)
- local amount = tableau[1]
- local capacity = tableau[2]
- local pct = tableau[3]
- local entree = tableau[4]
- local sortie = tableau[5]
- local delta = tableau[6]
- local color = 0x00FFFF
- local color2 = 0xFF0000
- local cur = math.floor(pct * length)
- local textfrac = string.format("%s / %s", unitrf(amount), unitrf(capacity))
- local textpct = string.format("%.02f%%", pct*100)
- local text1 = " ENERGIE DANS LA BATTERIE MEKANISM " .. tableau[7]
- local text2 = "I: " .. unitrf(entree) .. " O: " .. unitrf(sortie) .. " D: " .. unitrf(delta)
- local text3 = textfrac .. string.rep(" ", length - string.len(textfrac) - string.len(textpct) - 2) .. textpct
- loadbar(x,y,length,cur,text1,color,color2)
- loadbar(x,y+1,length,cur,text2,color,color2)
- loadbar(x,y+2,length,cur,text3,color,color2)
- end
- local function bar_bank(x,y,length,val,valmax)
- local pct = val/valmax
- local color = 0xafa50d
- local color2 = 0x0000FF
- local cur = math.floor(pct * length)
- local textfrac = unitrf(val) .. " / " .. unitrf(valmax)
- local textpct = string.format("%.02f%%", pct*100)
- local text = textfrac .. string.rep(" ", length - string.len(textfrac) - string.len(textpct) - 2) .. textpct
- loadbar(x,y,length,cur,text,color,color2)
- end
- local function bar_fuel(x,y,length,val,valmax)
- local pct = val/valmax
- local color = 0x0aFF0a
- local color2 = 0xFFFFFF - 0xafa50d
- local cur = math.floor(pct * length)
- local textfrac = string.format("Fuel : %s mB/ %s mB", val, valmax)
- local textpct = string.format("%.02f%%", pct*100)
- local text = textfrac .. string.rep(" ", length - string.len(textfrac) - string.len(textpct) - 2) .. textpct
- loadbar(x,y,length,cur,text,color,color2)
- end
- local function onoff(x,y,etat)
- if etat == true then
- setColor(0x00FF00, 0x0)
- gpu.set(x,y," ON ")
- else
- setColor(0xFF0000, 0x0)
- gpu.set(x,y," OFF")
- end
- setColor(0x0, 0xFFFFFF)
- end
- local function connect(x,y,etat)
- if etat == false then
- setColor(0x0000FF, 0x00FFFF)
- gpu.set(x,y,"Déconnecté")
- else
- setColor(0x00FFFF, 0x0000FF)
- gpu.set(x,y," Connecté ")
- end
- setColor(0x0, 0xFFFFFF)
- end
- local function mode(x,y,etat)
- if etat == 1 then
- setColor(0x0, 0xFF0000)
- gpu.set(x,y,"MARCHE")
- elseif etat == 2 then
- setColor(0x0, 0xFFFA000)
- gpu.set(x,y," AUTO ")
- elseif etat == 3 then
- setColor(0x0, 0xFF0000)
- gpu.set(x,y," STOP ")
- end
- setColor(0x0, 0xFFFFFF)
- end
- local function diesel(x,y,tableau)
- gpu.set(x+10,y,string.format("%02s",tableau[1]))
- onoff(x+18,y,tableau[2])
- connect(x+31,y,tableau[3])
- gpu.set(x+16,y+1,string.format("%07.3s",tableau[4]))
- mode(x+35,y+1,tableau[5])
- bar_fuel(x,y+2,44,tableau[6],tableau[7])
- bar_bank(x,y+3,44,tableau[8],tableau[9])
- end
- local function smoke()
- if bit_diesel[1] = true or bit_diesel[2] = true or bit_diesel[3] = true or bit_diesel[4] = true or bit_diesel[9] = true or bit_diesel[10] = true or bit_diesel[11] = true or bit_diesel[12] = true then
- rs1.setOutput(side.top,15)
- else
- rs1.setOutput(side.top,0)
- end
- if bit_diesel[5] = true or bit_diesel[6] = true or bit_diesel[7] = true or bit_diesel[8] = true or bit_diesel[13] = true or bit_diesel[14] = true or bit_diesel[15] = true or bit_diesel[16] = true then
- rs1.setOutput(side.top,15)
- else
- rs1.setOutput(side.top,0)
- end
- end
- --trame
- gpu.set(1,1,"╔═════════════════════════════════════════════════════════════════════════════════════════╗")
- gpu.set(1,2,"║ ║")
- gpu.set(1,3,"╠════════════════════════════════════════════╦════════════════════════════════════════════╣")
- gpu.set(1,4,"║ Diesel n° -- XX -- déconnecté ║ Diesel n° -- XX -- déconnecté ║")
- gpu.set(1,5,"║ Déclenchement 000.000% -- Mode : marche ║ Déclenchement 000.000% -- Mode : marche ║")
- gpu.set(1,6,"║ fuel : 8000mB / 8000mB 100.00% ║ fuel : 8000mB / 8000mB 100.00% ║")
- gpu.set(1,7,"║ XXX.XXX mrf/t / XXX.XXX mrf/t 100.00% ║ ║")
- gpu.set(1,8,"╠════════════════════════════════════════════╬════════════════════════════════════════════╣")
- gpu.set(1,9,"║ Diesel n° -- XX -- déconnecté ║ Diesel n° -- XX -- déconnecté ║")
- gpu.set(1,10,"║ Déclenchement 000.000% -- Mode : marche ║ Déclenchement 000.000% -- Mode : marche ║")
- gpu.set(1,11,"║ ║ ║")
- gpu.set(1,12,"║ ║ ║")
- gpu.set(1,13,"╠════════════════════════════════════════════╬════════════════════════════════════════════╣")
- gpu.set(1,14,"║ Diesel n° -- XX -- déconnecté ║ Diesel n° -- XX -- déconnecté ║")
- gpu.set(1,15,"║ Déclenchement 000.000% -- Mode : marche ║ Déclenchement 000.000% -- Mode : marche ║")
- gpu.set(1,16,"║ ║ ║")
- gpu.set(1,17,"║ ║ ║")
- gpu.set(1,18,"╠════════════════════════════════════════════╬════════════════════════════════════════════╣")
- gpu.set(1,19,"║ Diesel n° -- XX -- déconnecté ║ Diesel n° -- XX -- déconnecté ║")
- gpu.set(1,20,"║ Déclenchement 000.000% -- Mode : marche ║ Déclenchement 000.000% -- Mode : marche ║")
- gpu.set(1,21,"║ ║ ║")
- gpu.set(1,22,"║ ║ ║")
- gpu.set(1,23,"╠════════════════════════════════════════════╬════════════════════════════════════════════╣")
- gpu.set(1,24,"║ Diesel n° -- XX -- déconnecté ║ Diesel n° -- XX -- déconnecté ║")
- gpu.set(1,25,"║ Déclenchement 000.000% -- Mode : marche ║ Déclenchement 000.000% -- Mode : marche ║")
- gpu.set(1,26,"║ ║ ║")
- gpu.set(1,27,"║ ║ ║")
- gpu.set(1,28,"╠════════════════════════════════════════════╬════════════════════════════════════════════╣")
- gpu.set(1,29,"║ Diesel n° -- XX -- déconnecté ║ Diesel n° -- XX -- déconnecté ║")
- gpu.set(1,30,"║ Déclenchement 000.000% -- Mode : marche ║ Déclenchement 000.000% -- Mode : marche ║")
- gpu.set(1,31,"║ ║ ║")
- gpu.set(1,32,"║ ║ ║")
- gpu.set(1,33,"╠════════════════════════════════════════════╬════════════════════════════════════════════╣")
- gpu.set(1,34,"║ Diesel n° -- XX -- déconnecté ║ Diesel n° -- XX -- déconnecté ║")
- gpu.set(1,35,"║ Déclenchement 000.000% -- Mode : marche ║ Déclenchement 000.000% -- Mode : marche ║")
- gpu.set(1,36,"║ ║ ║")
- gpu.set(1,37,"║ ║ ║")
- gpu.set(1,38,"╠════════════════════════════════════════════╬════════════════════════════════════════════╣")
- gpu.set(1,39,"║ Diesel n° -- XX -- déconnecté ║ Diesel n° -- XX -- déconnecté ║")
- gpu.set(1,40,"║ Déclenchement 000.000% -- Mode : marche ║ Déclenchement 000.000% -- Mode : marche ║")
- gpu.set(1,41,"║ ║ ║")
- gpu.set(1,42,"║ ║ ║")
- gpu.set(1,43,"╠════════════════════════════════════════════╩════════════════════════════════════════════╣")
- gpu.set(1,44,"╠═════════════════════════════════════════════════════════════════════════════════════════╣")
- gpu.set(1,45,"║ ║")
- gpu.set(1,46,"╠═════════════════════════════════════════════════════════════════════════════════════════╣")
- gpu.set(1,47,"║bargraph energie ║")
- gpu.set(1,48,"║ ║")
- gpu.set(1,49,"║ ║")
- gpu.set(1,50,"╚═════════════════════════════════════════════════════════════════════════════════════════╝")
- local function onModem(_,_,from,port,_,IDcodes,message)
- local texte_vide = ""
- i = i + 1
- if i > 45 then
- i = 0
- texte_vide = " "
- end
- local texte_port = " Réception n°" .. i+1 .. " / port n°".. port .. texte_vide
- gpu.set(i+2,45,texte_port)
- if port == 10026 then
- gpu.set(1,4,tostring(port))
- end
- if port == 10001 then
- value_receive = serialization.unserialize(message)
- affenergie(2,47,89,value_receive)
- elseif port == 10003 then
- local vx
- local vy
- for vdiesel = 1, 16 do
- ndiesel = "diesel " .. vdiesel
- if IDcodes == ndiesel then
- value_receive = serialization.unserialize(message)
- tableau_general[vdiesel] = value_receive
- bit_diesel[vdiesel] = tableau_general[2]
- if (math.floor(vdiesel/2)*2 ~= vdiesel) then
- vx = 2
- vy = 4 + (vdiesel - 1) * 2.5
- else
- vx = 47
- vy = 4 + (vdiesel - 2) * 2.5
- end
- diesel(vx,vy,tableau_general[vdiesel])
- end
- end
- end
- smoke()
- end
- local function onTouch(event,adress,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(2,2," "..tclic.." de la part de "..pseudo.." / X : "..string.format("% 3s",x).." / Y : "..string.format("% 3s",y))
- if x==1 and y==1 then
- computer.pushSignal("quit")
- term.setCursor(1,1)
- return false
- end
- end
- event.listen("touch",onTouch)
- event.listen("modem_message",onModem)
- event.pull("quit")
- event.ignore("touch",onTouch)
- event.ignore("modem_message",onModem)
- component.gpu.setResolution(160,50)
- --Fermeture des ports
- modem.close(10001)
- modem.close(10003)
- term.clear()
- --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