Advertisement
Guest User

reactor2

a guest
Jan 29th, 2021
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.05 KB | None | 0 0
  1. local term = require('term')
  2. local component = require('component')
  3. local event = require("event")
  4. local serialize = require("serialization").serialize
  5. local unserialize = require("serialization").unserialize
  6. local gpu = component.gpu
  7. local tunnel = component.tunnel
  8.  
  9. buttons = {
  10. button1 = {x=3, y=7, reactor_n = 'reactor1', color = 0xff0000},
  11. button2 = {x=19, y=7, reactor_n = 'reactor2', color = 0xff0000},
  12. button3 = {x=35, y=7, reactor_n = 'reactor3', color = 0xff0000},
  13. button4 = {x=3, y=15, reactor_n = 'reactor4', color = 0xff0000},
  14. button5 = {x=19, y=15, reactor_n = 'reactor5', color = 0xff0000},
  15. button6 = {x=35, y=15, reactor_n = 'reactor6', color = 0xff0000},
  16. button7 = {x=3, y=23, reactor_n = 'reactor7', color = 0xff0000},
  17. button8 = {x=19, y=23, reactor_n = 'reactor8', color = 0xff0000},
  18. button9 = {x=35, y=23, reactor_n = 'reactor9', color = 0xff0000}
  19. }
  20.  
  21. function take_data1()
  22.     local mess = {event.pull('modem_message')}
  23.     if mess[1] then
  24.         tbl = unserialize(mess[6])
  25.     end
  26. end
  27.  
  28. function take_data()
  29.     local mess = {event.pull(0.1,'modem_message')}
  30.     if mess[1] then
  31.         tbl = unserialize(mess[6])
  32.     end
  33. end
  34.  
  35. function send_data()
  36.     message = serialize(tbl)
  37.     tunnel.send(message)
  38. end
  39.  
  40. function drawScreen()
  41.     gpu.set(1,1,'Status: '..tbl.reactors.reactor1.status+tbl.reactors.reactor2.status+tbl.reactors.reactor3.status+tbl.reactors.reactor4.status+tbl.reactors.reactor5.status+tbl.reactors.reactor6.status+tbl.reactors.reactor7.status+tbl.reactors.reactor8.status+tbl.reactors.reactor9.status..'/9')
  42.     gpu.set(1,3,'EU-Total: '..tbl.reactors.reactor1.EU_generate+tbl.reactors.reactor2.EU_generate+tbl.reactors.reactor3.EU_generate+tbl.reactors.reactor4.EU_generate+tbl.reactors.reactor5.EU_generate+tbl.reactors.reactor6.EU_generate+tbl.reactors.reactor7.EU_generate+tbl.reactors.reactor8.EU_generate+tbl.reactors.reactor9.EU_generate..' EU/T')
  43.     gpu.set(1,5,'UU-Matter: '..tbl.tank.count_fluid..' Mb')
  44. end
  45.  
  46. function drawButton()
  47.   for k,v in pairs(buttons)do
  48.     if tbl['reactors'][v.reactor_n]['status'] == 1 then
  49.         v.color = 0x1eff00
  50.     elseif tbl['reactors'][v.reactor_n]['status'] == 0 then
  51.         v.color = 0xff0000
  52.     end
  53.     gpu.setBackground(v.color)
  54.     gpu.fill(v.x,v.y,10,5,' ')
  55.     gpu.setForeground(0x000000)
  56.     gpu.set(v.x+1,v.y+3,'Heat:'..tbl['reactors'][v.reactor_n]['heat'])
  57.     gpu.set(v.x+1,v.y+1,'EU:'..tbl['reactors'][v.reactor_n]['EU_generate'])
  58.     gpu.setForeground(0xffffff)
  59.   end
  60.   gpu.setBackground(0x000000)
  61. end
  62.  
  63. function searchButton()
  64.     local table ={event.pull(0.1,"touch")}
  65.     if table [1] then
  66.     local x, y = table[3], table[4]
  67.     for k,v in pairs(buttons) do
  68.       if x >= v.x and x < v.x + 10+2 and y >= v.y and y < v.y + 5 then
  69.         if tbl['reactors'][v.reactor_n]['status'] == 0 then
  70.           tbl['reactors'][v.reactor_n]['status'] = 1
  71.         elseif tbl['reactors'][v.reactor_n]['status'] == 1 then
  72.           tbl['reactors'][v.reactor_n]['status'] = 0
  73.         end
  74.       end
  75.     end
  76.     send_data()
  77.     end
  78. end
  79.  
  80. term.clear()
  81.  
  82.  
  83. take_data1()
  84. drawButton()
  85.  
  86. while true do
  87. take_data()
  88. drawScreen()
  89. searchButton()
  90. drawButton()
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement