Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Requires
- local term = require("term")
- local component = require("component")
- local computer = require("computer")
- local math = require("math")
- local event = require("event")
- local string = require("string")
- local unicode = require("unicode")
- local os = require("os")
- local fs = require('filesystem')
- local gpu = component.gpu
- gpu.setResolution(101,50)
- --récupération des turbines
- local i = 0
- local bit_marche = {}
- local bit_engage = {}
- local tableau_bits = {bit_marche, bit_engage}
- local tableau_turbine = {}
- for address,componentType in pairs(component.list("br_turbine")) do
- i = i + 1
- tableau_turbine[i] = component.proxy(address)
- bit_marche[i] = tableau_turbine[i].getActive()
- bit_engage[i] = tableau_turbine[i].getInductorEngaged()
- end
- --Variables
- --Functions
- local function setColor(bg,fg)
- gpu.setBackground(bg)
- gpu.setForeground(fg)
- end
- local function unitrf(qty)
- if 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 loadbar(x,y,width,cur,text,bg,fg)
- local raw = " " .. text ..string.rep(" ", width - unicode.len(text) - 2) .. " "
- local oldbg = gpu.setBackground(bg)
- local oldfg = gpu.setForeground(fg)
- 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 bar_horizontale(x,y,length,val,valmax,texte,color1,color2,rfmb)
- local pct = val/valmax
- local cur = math.floor(pct * length)
- local textfrac = texte..string.format(" : %04d / %04d "..rfmb, 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,color1,color2)
- end
- local function bar_horizontalerf(x,y,length,val,valmax,texte,color1,color2)
- local pct = val/valmax
- local cur = math.floor(pct * length)
- local textfrac = texte.." : "..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,color1,color2)
- end
- local function marche(x,y,etat)
- if etat == true then
- setColor(0x0, 0x00FF00)
- gpu.set(x,y,"MARCHE")
- else
- setColor(0x0, 0xFF0000)
- gpu.set(x,y," ARRÊT")
- end
- setColor(0x0, 0xFFFFFF)
- end
- local function active(x,y,etat)
- if etat == true then
- setColor(0x00FF00, 0x0)
- gpu.set(x,y," Activée ")
- else
- setColor(0xFF0000, 0x0)
- gpu.set(x,y,"Désactivée")
- end
- setColor(0x0, 0xFFFFFF)
- end
- local function engage(x,y,etat)
- if etat == false then
- setColor(0x0000FF, 0x00FFFF)
- gpu.set(x,y,"Désengagé")
- else
- setColor(0x00FFFF, 0x0000FF)
- gpu.set(x,y," Engagé ")
- end
- setColor(0x0, 0xFFFFFF)
- end
- local function turbine(x,y,tableau,n)
- tableau.setActive(bit_marche[n])
- tableau.setInductorEngaged(bit_engage[n])
- marche(x+1,y,bit_marche[n])
- active(x+21,y,tableau.getActive())
- gpu.set(x+19,y,tostring(n))
- engage(x+38,y,tableau.getInductorEngaged())
- gpu.set(x+4,y+1,string.format("%04s",tableau.getFluidFlowRate()))
- gpu.set(x+36,y+1,unitrf(tableau.getEnergyProducedLastTick()))
- bar_horizontale(x,y+3,49,tableau.getInputAmount(),tableau.getFluidAmountMax(),"Vapeur",0x8F8F8F,0xFFFF00,"mB/t")
- bar_horizontale(x,y+4,49,tableau.getRotorSpeed(),2200,"Vitesse du rotor",0xff9127,0xFFFFFF-0xff9127,"tr/min")
- bar_horizontalerf(x,y+5,49,tableau.getEnergyStored(),1000000,"Energie",0x00FFFF,0xFF0000)
- end
- local function control()
- local vx
- local vy
- local nturbine = 0
- for nturbine = 1, 8 do
- if math.floor(nturbine/2)*2 ~= nturbine then
- vx = 2
- vy = (nturbine - 2) * 3.5 + 7.5
- else
- vx = 52
- vy = (nturbine - 2) * 3.5 + 4
- end
- turbine(vx,vy,tableau_turbine[nturbine],nturbine)
- end
- end
- local function command(tableau,n)
- if tableau_bits[tableau][n] == true then
- tableau_bits[tableau][n] = false
- elseif tableau_bits[tableau][n] == false then
- tableau_bits[tableau][n] = true
- end
- end
- --trace
- term.clear()
- gpu.set(1,1,"╔═══════════════════════════════════════════════════════════════════════════════════════════════════╗")
- gpu.set(1,2,"║ ║")
- gpu.set(1,3,"╠═════════════════════════════════════════════════╦═════════════════════════════════════════════════╣")
- gpu.set(1,4,"║ marche Turbine n°X désactivée Rotor désengagé ║ marche Turbine n°X désactivée Rotor désengagé ║")
- gpu.set(1,5,"║ Qe XXXX mB / Production énergie : XX.XXX Krf/t ║ Qe XXXX mB / Production énergie : XX.XXX Krf/t ║")
- gpu.set(1,6,"╟-------------------------------------------------╫-------------------------------------------------╢")
- gpu.set(1,7,"║ Rotor Speed ║ Rotor Speed ║")
- gpu.set(1,8,"║ Steam ║ Steam ║")
- gpu.set(1,9,"║ Energy ║ Energy ║")
- gpu.set(1,10,"╠═════════════════════════════════════════════════╬═════════════════════════════════════════════════╣")
- gpu.set(1,11,"║ marche Turbine n°X désactivée Rotor désengagé ║ marche Turbine n°X désactivée Rotor désengagé ║")
- gpu.set(1,12,"║ Qe XXXX mB / Production énergie : XX.XXX Krf/t ║ Qe XXXX mB / Production énergie : XX.XXX Krf/t ║")
- gpu.set(1,13,"╟-------------------------------------------------╫-------------------------------------------------╢")
- gpu.set(1,14,"║ Rotor Speed ║ Rotor Speed ║")
- gpu.set(1,15,"║ Steam ║ Steam ║")
- gpu.set(1,16,"║ Energy ║ Energy ║")
- gpu.set(1,17,"╠═════════════════════════════════════════════════╬═════════════════════════════════════════════════╣")
- gpu.set(1,18,"║ marche Turbine n°X désactivée Rotor désengagé ║ marche Turbine n°X désactivée Rotor désengagé ║")
- gpu.set(1,19,"║ Qe XXXX mB / Production énergie : XX.XXX Krf/t ║ Qe XXXX mB / Production énergie : XX.XXX Krf/t ║")
- gpu.set(1,20,"╟-------------------------------------------------╫-------------------------------------------------╢")
- gpu.set(1,21,"║ Rotor Speed ║ Rotor Speed ║")
- gpu.set(1,22,"║ Steam ║ Steam ║")
- gpu.set(1,23,"║ Energy ║ Energy ║")
- gpu.set(1,24,"╠═════════════════════════════════════════════════╬═════════════════════════════════════════════════╣")
- gpu.set(1,25,"║ marche Turbine n°X désactivée Rotor désengagé ║ marche Turbine n°X désactivée Rotor désengagé ║")
- gpu.set(1,26,"║ Qe XXXX mB / Production énergie : XX.XXX Krf/t ║ Qe XXXX mB / Production énergie : XX.XXX Krf/t ║")
- gpu.set(1,27,"╟-------------------------------------------------╫-------------------------------------------------╢")
- gpu.set(1,28,"║ Rotor Speed ║ Rotor Speed ║")
- gpu.set(1,29,"║ Steam ║ Steam ║")
- gpu.set(1,30,"║ Energy ║ Energy ║")
- gpu.set(1,31,"╠═════════════════════════════════════════════════╬═════════════════════════════════════════════════╣")
- gpu.set(1,32,"║ ║ ║")
- gpu.set(1,33,"║ ║ ║")
- 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,"║ ║ ║")
- 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,"║ ║ ║")
- gpu.set(1,48,"║ ║ ║")
- gpu.set(1,49,"║ ║ ║")
- gpu.set(1,50,"╚═════════════════════════════════════════════════╩═════════════════════════════════════════════════╝")
- --Main
- 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
- elseif x>2 and x<9 and (y==4 or y==11 or y==18 or y==25) then
- local n = ((y - 7.5) / 3.5) + 2
- command(1,n)
- elseif x>52 and x<59 and (y==4 or y==11 or y==18 or y==25) then
- local n = ((y - 4) / 3.5) + 2
- command(1,n)
- elseif x>39 and x<49 and (y==4 or y==11 or y==18 or y==25) then
- local n = ((y - 7.5) / 3.5) + 2
- command(2,n)
- elseif x>89 and x<99 and (y==4 or y==11 or y==18 or y==25) then
- local n = ((y - 4) / 3.5) + 2
- command(2,n)
- elseif 1 == 0 then
- end
- end
- local function onTimer(_,timer)
- control()
- return true
- end
- event.listen("touch",onTouch)
- local timer = event.timer(0,onTimer,math.huge)
- event.pull("quit")
- event.cancel(timer)
- event.ignore("touch",onTouch)
- component.gpu.setResolution(160,50)
- 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