Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Video : https://youtu.be/mG_4e6uEOy0
- -- Une ligne par machine {Nom="NOM AFFICHER",Id=XX}
- -- XX remplacer par le numero unique choisi sur les autre ordi à id
- -- oublier pas la virgule sauf sur la dernier ligne
- local config={
- {Nom="Reactor",Id=100},
- {Nom="Turbine 1",Id=0},
- {Nom="Turbine 2",Id=1},
- {Nom="Turbine 3",Id=2}
- }
- local modem=peripheral.wrap("bottom")
- local ecran=peripheral.wrap("top")
- local data={}
- -- Initialisation
- for i=1,#config do
- -- Creation de data de base
- data[config[i].Id]="non"
- -- Calcul de la posion a l'ecran
- if i%2==1 then
- config[i].X=1
- else
- config[i].X=21
- end
- config[i].Y=1+((math.ceil(i/2)-1)*6)
- config[i].w1=window.create(ecran, config[i].X, config[i].Y, 20, 2)
- config[i].w1.setTextColor(colors.white)
- config[i].w3=window.create(ecran, config[i].X, config[i].Y+2, 20, 2)
- config[i].w3.setTextColor(colors.white)
- config[i].w4=window.create(ecran, config[i].X, config[i].Y+3, 20, 1)
- config[i].w4.setTextColor(colors.white)
- config[i].w5=window.create(ecran, config[i].X, config[i].Y+4, 20, 1)
- config[i].w5.setTextColor(colors.white)
- config[i].w6=window.create(ecran, config[i].X, config[i].Y+5, 20, 1)
- config[i].w6.setBackgroundColor(colors.black)
- -- ouverture pour ecouter les info
- modem.open(config[i].Id)
- end
- -- function pour transformer 9876543 en 9 876 543
- function number_format(n)
- local test=mille(n)
- if test.Mille==0 then
- return math.floor(n)
- else
- test.Mille=mille(test.Mille)
- if test.Mille.Mille==0 then
- return test.Mille.Cent.." "..cent(test.Cent)
- else
- return test.Mille.Mille.." "..cent(test.Mille.Cent).." "..cent(test.Cent)
- end
- end
- end
- -- function pour etre sur d'avoir trois chiffre (99 devient 099, 9 devient 009)
- function cent(n)
- n=math.floor(n)
- if n>99 then
- return n
- elseif n>9 then
- return "0"..n
- else
- return "00"..n
- end
- end
- -- creer un objet avec les centaines d'un coté les millier de l'autre
- function mille(n)
- if n<1000 then
- return {Mille=0,Cent=n}
- else
- return {Mille=math.floor(n/1000),Cent=n%1000}
- end
- end
- -- function de recuperation des infos envoye en wifi
- function ecoute()
- while true do
- local e, ms, sc, rp, msg, sd = os.pullEvent("modem_message")
- data[sc]=textutils.unserialize(msg)
- --print(msg)
- end
- end
- local couleurFond
- -- affichage de l ecran
- function affiche()
- ecran.setBackgroundColor(colors.black)
- while true do
- ecran.clear()
- -- boucle sur chaque machine enregistre
- for i=1,#config do
- -- secu si rien recu
- if data[config[i].Id]=="non" then
- couleurFond=colors.red
- else
- -- on change la couleur si actif
- if data[config[i].Id].active then
- couleurFond=colors.green
- else
- couleurFond=colors.red
- end
- if data[config[i].Id].type=="turbine" then
- --config[i].w4.setBackgroundColor(couleurFond)
- --config[i].w5.setBackgroundColor(couleurFond)
- else
- --config[i].w3.setBackgroundColor(couleurFond)
- --config[i].w5.setBackgroundColor(couleurFond)
- end
- end
- config[i].w1.setBackgroundColor(couleurFond)
- --config[i].w6.setBackgroundColor(couleurFond)
- --config[i].w6.setTextColor(couleurFond)
- config[i].w1.clear()
- config[i].w1.setCursorPos(1,1)
- config[i].w1.write(" "..config[i].Nom)
- config[i].w1.setCursorPos(1,2)
- -- secu si rien recu
- if data[config[i].Id]=="non" then
- config[i].w1.write(" Aucune info")
- --config[i].w3.setBackgroundColor(couleurFond)
- --config[i].w3.write(" ")
- --config[i].w4.setBackgroundColor(couleurFond)
- --config[i].w4.write(" ")
- --config[i].w5.setBackgroundColor(couleurFond)
- --config[i].w5.write(" ")
- else
- -- affiche active ou non
- if data[config[i].Id].active then
- config[i].w1.write(" Active")
- else
- config[i].w1.write(" Desactive")
- end
- config[i].w3.clear()
- config[i].w3.setCursorPos(1,1)
- -- affichage en fonction du type de machine (turbine ou reactor)
- if data[config[i].Id].type=="turbine" then
- -- couleur en fonction de la vitesse
- -- bleu optimum
- -- rouge non
- if data[config[i].Id].speed<800 then
- config[i].w3.setBackgroundColor(colors.red)
- elseif data[config[i].Id].speed<1000 then
- config[i].w3.setBackgroundColor(colors.blue)
- elseif data[config[i].Id].speed<1700 then
- config[i].w3.setBackgroundColor(colors.red)
- elseif data[config[i].Id].speed<1900 then
- config[i].w3.setBackgroundColor(colors.blue)
- else
- config[i].w3.setBackgroundColor(colors.red)
- end
- config[i].w3.write(" Rotor : ")
- -- Affichage des autres infos
- config[i].w3.write(number_format(data[config[i].Id].speed))
- config[i].w4.clear()
- config[i].w4.setCursorPos(1,1)
- config[i].w4.write(" Prod : "..number_format(data[config[i].Id].prod))
- config[i].w5.clear()
- config[i].w5.setCursorPos(1,1)
- config[i].w5.write(" Buffer : "..number_format(data[config[i].Id].buff))
- config[i].w6.clear()
- else
- config[i].w3.write(" Fuel : "..number_format(data[config[i].Id].fuel/1000).." yell")
- config[i].w4.clear()
- config[i].w4.setCursorPos(1,1)
- -- couleur si pas 100% fuel
- local pourc=math.ceil(data[config[i].Id].fuel/data[config[i].Id].fuelMax*100)
- if pourc<100 then
- config[i].w4.setBackgroundColor(colors.red)
- else
- config[i].w4.setBackgroundColor(colors.blue)
- end
- config[i].w4.write(" Stock : ")
- config[i].w4.write(pourc.."%")
- config[i].w5.clear()
- config[i].w5.setCursorPos(1,1)
- config[i].w5.write(" Prod : "..number_format(data[config[i].Id].prod))
- end
- end
- config[i].w6.write("XXXXXXXXXXXXXXXXXXXXXX")
- end
- os.sleep(1)
- end
- end
- -- ecoute du click
- function click()
- while true do
- local e, bt, xp, yp = os.pullEvent("monitor_touch")
- local sortie=-1
- -- calcul en fonction x/y de la clique de la machine
- local i=((math.ceil(yp/6)*2)-1)+(math.ceil(xp/20)-1)
- -- on verifie si y a une machine
- if config[i] then
- sortie=50+config[i].Id
- else
- print("pas de config "..i)
- end
- -- si trouve on envoi l'ordre
- if sortie==-1 then
- else
- print(sortie)
- modem.transmit(sortie,sortie-50,"c")
- end
- end
- end
- parallel.waitForAll(ecoute,affiche,click)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement