Advertisement
sshikamaru

envoi.lua

Dec 9th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.98 KB | None | 0 0
  1. --Liste des require
  2. local computer = require("computer")
  3. local component = require("component")
  4. local term = require("term")
  5. local math = require("math")
  6. local event = require("event")
  7. local string = require("string")
  8. local unicode = require("unicode")
  9. local colors = require("colors")
  10. local sides = require("sides")
  11. local serialization = require("serialization")
  12.  
  13. --Récupération du matériel
  14. local screen = component.get("6502","screen")
  15. local gpu = component.gpu
  16. local valve = component.ffs_valve
  17. local modem = component.modem
  18.  
  19. --Ouverture des ports
  20. modem.open(1001)
  21.  
  22. --Résolution
  23. gpu.bind(screen)
  24. gpu.setResolution(63,35)
  25.  
  26. --Définitions des variables
  27. local i = 0
  28.  
  29. --Fonctions
  30. local function loadbar(x,y,width,cur,text,bg)
  31.   local raw = " " .. text ..string.rep(" ", width - unicode.len(text) - 2) .. " "
  32.   local oldbg = gpu.setBackground(bg)
  33.   local oldfg = gpu.setForeground(0xFFFFFF - bg)
  34.   gpu.set(x,y,unicode.sub(raw,1,cur))
  35.   gpu.setBackground(oldbg)
  36.   gpu.setForeground(oldfg)
  37.   gpu.set(x+cur,y,unicode.sub(raw,cur+1,width))
  38. end
  39.  
  40. local function afftemp(x,y,length)
  41.   local amount = valve.getFluidAmount() / 1000
  42.   local capacity = valve.getFluidCapacity() / 1000
  43.   local pct = amount / capacity
  44.   local cur = math.floor(pct * length)
  45.   local color = 0x00FFFF
  46.   local textfrac = string.format("%.02f / %s", amount, capacity)
  47.   local textpct = string.format("%.02f%%", pct*100)
  48.   local text = textfrac .. string.rep(" ", length - string.len(textfrac) - string.len(textpct) - 2) .. textpct
  49.   local dir = ""
  50.   loadbar(x,y,length,cur,dir,color)
  51.   loadbar(x,y+1,length,cur,dir,color)
  52.   loadbar(x,y+2,length,cur,text,color)
  53. end
  54.  
  55. local function send()
  56.   local tableau_valeur ={}
  57.   local amount = valve.getFluidAmount() / 1000
  58.   local capacity = valve.getFluidCapacity() / 1000
  59.   local value = amount / capacity
  60.   tableau_valeur[1] = amount
  61.   tableau_valeur[2] = capacity
  62.   tableau_valeur[3] = value
  63.   local table_s = serialization.serialize(tableau_valeur)
  64.   modem.broadcast(1001, table_s)
  65.   i = i + 1
  66.   if i > 9 then
  67.     i = 0
  68.   end
  69.   gpu.set(2,15,string.format("%s", i))
  70.   gpu.set(2,16,table_s)
  71. end
  72.  
  73. --Trame de fond
  74.  gpu.set(1,1,"╔═════════════════════════════════════════════════════════════╗")
  75.  gpu.set(1,2,"║                                                             ║")
  76.  gpu.set(1,3,"║                                                             ║")
  77.  gpu.set(1,4,"║                                                             ║")
  78.  gpu.set(1,5,"║                                                             ║")
  79.  gpu.set(1,6,"║                                                             ║")
  80.  gpu.set(1,7,"║                                                             ║")
  81.  gpu.set(1,8,"║                                                             ║")
  82.  gpu.set(1,9,"║                                                             ║")
  83. gpu.set(1,10,"║                                                             ║")
  84. gpu.set(1,11,"║                                                             ║")
  85. gpu.set(1,12,"║                                                             ║")
  86. gpu.set(1,13,"║                                                             ║")
  87. gpu.set(1,14,"║                                                             ║")
  88. gpu.set(1,15,"║                                                             ║")
  89. gpu.set(1,16,"║                                                             ║")
  90. gpu.set(1,17,"║                                                             ║")
  91. gpu.set(1,18,"║                                                             ║")
  92. gpu.set(1,19,"║                                                             ║")
  93. gpu.set(1,20,"║                                                             ║")
  94. gpu.set(1,21,"║                                                             ║")
  95. gpu.set(1,22,"║                                                             ║")
  96. gpu.set(1,23,"║                                                             ║")
  97. gpu.set(1,24,"║                                                             ║")
  98. gpu.set(1,25,"║                                                             ║")
  99. gpu.set(1,26,"║                                                             ║")
  100. gpu.set(1,27,"║                                                             ║")
  101. gpu.set(1,28,"║                                                             ║")
  102. gpu.set(1,29,"║                                                             ║")
  103. gpu.set(1,30,"║                                                             ║")
  104. gpu.set(1,31,"║                                                             ║")
  105. gpu.set(1,32,"║                                                             ║")
  106. gpu.set(1,33,"║                                                             ║")
  107. gpu.set(1,34,"║                                                             ║")
  108. gpu.set(1,35,"╚═════════════════════════════════════════════════════════════╝")
  109.  
  110. local function drawbars()
  111.   afftemp(2,7,61)
  112.   send()
  113. end
  114.  
  115. local function onTouch(_,address,x,y,_,pseudo)
  116.   gpu.set(2,2,"X      : "..string.format("% 3s",x))
  117.   gpu.set(2,3,"Y      : "..string.format("% 3s",y))
  118.   gpu.set(2,4,"Pseudo : "..pseudo)
  119.  
  120.   if x~=1 and y~=1 then
  121.  
  122.   elseif x==1 and y==1 then
  123.     computer.pushSignal("quit")
  124.     gpu.fill(1,1,63,35," ")
  125.     term.setCursor(1,1)
  126.     return false
  127.   end
  128. end
  129.  
  130. local function onTimer(_,timer)
  131.   drawbars()
  132.   return true
  133. end
  134.  
  135. event.listen("touch",onTouch)
  136. local timer = event.timer(1,onTimer,math.huge)
  137. event.pull("quit")
  138. event.cancel(timer)
  139. event.ignore("touch",onTouch)
  140. gpu.fill(1,1,63,35," ")
  141. gpu.setResolution(160,50)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement