Advertisement
fbMarcel

AirLockControl-MainPC-v1.1

Feb 26th, 2021 (edited)
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.44 KB | None | 0 0
  1. --[[
  2. AirLock Control - Main PC (Touchscreen)
  3. version 1.1
  4. pastebin: F1zKxNT5
  5. ]]
  6.  
  7. -- all IDs
  8. local screen1 = 14
  9. local screen2 = 12
  10. local door1 = 17
  11. local door2 = 18
  12. local screenMain = 15
  13. local dispenser = 19
  14.  
  15. -- rednet messages
  16. local msgactivate = "activate"
  17. local msgopen = "open"
  18. local msgclose = "close"
  19. local msginuse = "inuse"
  20. local msgdone = "done"
  21. local msgreset = "reset"
  22. local msgdis = "dispense"
  23.  
  24. -- switching variables
  25. local screenIn
  26. local screenOut
  27. local doorIn
  28. local doorOut
  29. local option
  30.  
  31. -- setup
  32. rednet.open("back")
  33. term.setCursorBlink(false)
  34.  
  35. -- screen write functions
  36. -- show waiting screen
  37. function screenwait()
  38.   term.setBackgroundColor(colors.pink)
  39.   term.clear()
  40.   term.setTextColor(colors.black)
  41.   term.setCursorPos(1,3)
  42.   write("WAITING")
  43.   term.setTextColor(colors.white)
  44.   term.setCursorPos(2,5)
  45.   write("open")
  46.   term.setCursorPos(1,1)
  47. end
  48. -- show close button
  49. function screenclose()
  50.   term.setBackgroundColor(colors.red)
  51.   term.clear()
  52.   term.setTextColor(colors.white)
  53.   term.setCursorPos(2,3)
  54.   write("CLOSE")
  55.   term.setCursorPos(1,1)
  56. end
  57. -- indicator closing
  58. function indclose()
  59.   term.setBackgroundColor(colors.red)
  60.   term.setTextColor(colors.white)
  61.   term.setCursorPos(1,5)
  62.   write("closing")
  63.   term.setCursorPos(1,1)
  64. end
  65. -- show heal button
  66. function screenheal()
  67.   term.setBackgroundColor(colors.cyan)
  68.   term.clear()
  69.   term.setTextColor(colors.black)
  70.   term.setCursorPos(2,2)
  71.   write("HEAL?")
  72.   term.setBackgroundColor(colors.green)
  73.   term.setTextColor(colors.white)
  74.   paintutils.drawFilledBox(1,4,3,5)
  75.   term.setCursorPos(2,5)
  76.   write("Y")
  77.   term.setBackgroundColor(colors.red)
  78.   paintutils.drawFilledBox(5,4,7,5)
  79.   term.setCursorPos(6,5)
  80.   write("N")
  81.   term.setCursorPos(1,1)
  82. end
  83. -- indicator healing
  84. function indheal()
  85.   term.setBackgroundColor(colors.cyan)
  86.   term.clear()
  87.   term.setTextColor(colors.black)
  88.   term.setCursorPos(1,3)
  89.   write("HEALING")
  90.   term.setCursorPos(1,1)
  91. end
  92. -- show door choice
  93. function screendoors()
  94.   term.setBackgroundColor(colors.brown)
  95.   term.clear()
  96.   term.setTextColor(colors.white)
  97.   term.setCursorPos(2,1)
  98.   write("WHICH")
  99.   term.setCursorPos(2,2)
  100.   write("DOOR?")
  101.   term.setBackgroundColor(colors.lightGray)
  102.   term.setTextColor(colors.black)
  103.   paintutils.drawFilledBox(1,4,3,5)
  104.   paintutils.drawFilledBox(5,4,7,5)
  105.   term.setCursorPos(2,4)
  106.   write("<")
  107.   term.setCursorPos(6,4)
  108.   write(">")
  109.   term.setCursorPos(1,1)
  110. end
  111. -- show open button
  112. function screenopen()
  113.   term.setBackgroundColor(colors.green)
  114.   term.clear()
  115.   term.setTextColor(colors.white)
  116.   term.setCursorPos(2,3)
  117.   write("OPEN")
  118.   term.setCursorPos(1,1)
  119. end
  120. -- indicator opening
  121. function indopen()
  122.   term.setBackgroundColor(colors.green)
  123.   term.setTextColor(colors.white)
  124.   term.setCursorPos(1,5)
  125.   write("opening")
  126.   term.setCursorPos(1,1)
  127. end
  128. -- clear screen
  129. function screenclear()
  130.   term.setBackgroundColor(colors.black)
  131.   term.setTextColor(colors.white)
  132.   term.clear()
  133.   term.setCursorPos(1,1)
  134. end
  135.  
  136. -- parallel functions
  137. -- touchscreen input
  138. function waitTouch()
  139.   while true do
  140.     local event, par, x, y = os.pullEvent()
  141.     if event == "mouse_click" then
  142.       if y>=1 and y<=5 then
  143.         option = "touch"
  144.         break
  145.       end
  146.     end
  147.   end
  148. end
  149. -- rednet input
  150. function waitRednet()
  151.   while true do
  152.     local senderid, message = rednet.receive()
  153.     if message == msgactivate then
  154.       option = "rednet"
  155.       if senderid == screen1 then
  156.         screenIn = screen1
  157.         screenOut = screen2
  158.         doorIn = door1
  159.         doorOut = door2
  160.       elseif senderid == screen2 then
  161.         screenIn = screen2
  162.         screenOut = screen1
  163.         doorIn = door2
  164.         doorOut = door1
  165.       end
  166.       break
  167.     end
  168.   end
  169. end
  170.  
  171. -- main program
  172. while true do
  173.   screenclear()
  174.   sleep(0.1)
  175.   screenwait()
  176.   parallel.waitForAny(waitTouch,waitRednet)
  177.   if option == "touch" then
  178.     -- open door options
  179.     rednet.send(12,msginuse)
  180.     sleep(0.1)
  181.     rednet.send(14,msginuse)
  182.     sleep(0.1)
  183.     screendoors()
  184.     while true do
  185.       local event2, par2, x2, y2 = os.pullEvent()
  186.       if event2 == "mouse_click" then
  187.         if x2>=1 and x2<=3 and y2>=4 and y2<=5 then
  188.           -- left door (1)
  189.           rednet.send(17,msgopen)
  190.           sleep(0.1)
  191.           rednet.send(14,msgdone)
  192.           sleep(0.1)
  193.           break
  194.         elseif x2>=5 and x2<=7 and y2>=4 and y2<=5 then
  195.           -- right door (2)
  196.           rednet.send(18,msgopen)
  197.           sleep(0.1)
  198.           rednet.send(12,msgdone)
  199.           sleep(0.1)
  200.           break
  201.         end
  202.       end
  203.     end
  204.   elseif option == "rednet" then
  205.     -- start airlock
  206.     if screenOut == 14 then
  207.       rednet.send(14,msginuse)
  208.     elseif screenOut == 12 then
  209.       rednet.send(12,msginuse)
  210.     end
  211.     sleep(0.1)
  212.     screenclose()
  213.     while true do
  214.       local event3, par3, x3, y3 = os.pullEvent()
  215.       if event3 == "mouse_click" then
  216.         if y3>=1 and y3<=5 then
  217.           indclose()
  218.           if doorIn == 17 then
  219.             rednet.send(17,msgclose)
  220.           elseif doorIn == 18 then
  221.             rednet.send(18,msgclose)
  222.           end
  223.           sleep(0.1)
  224.           if screenIn == 14 then
  225.             rednet.send(14,msginuse)
  226.           elseif screenIn == 12 then
  227.             rednet.send(12,msginuse)
  228.           end
  229.           sleep(0.1)
  230.           break
  231.         end
  232.       end
  233.     end
  234.     screenheal()
  235.     while true do
  236.       local event4, par4, x4, y4 = os.pullEvent()
  237.       if event4 == "mouse_click" then
  238.         if x4>=1 and x4<=3 and y4>=4 and y4<=5 then
  239.           -- heal
  240.           indheal()
  241.           rednet.send(19,msgdis)
  242.           sleep(0.1)
  243.           break
  244.         elseif x4>=5 and x4<=7 and y4>=4 and y4<=5 then
  245.           -- don't heal
  246.           break
  247.         end
  248.       end
  249.     end
  250.     screenopen()
  251.     while true do
  252.       local event5, par5, x5, y5 = os.pullEvent()
  253.       if event5 == "mouse_click" then
  254.         if y5>=1 and y5<=5 then
  255.           indopen()
  256.           if doorOut == 17 then
  257.             rednet.send(17,msgopen)
  258.           elseif doorOut == 18 then
  259.             rednet.send(18,msgopen)
  260.           end
  261.           sleep(0.1)
  262.           if screenOut == 14 then
  263.             rednet.send(14,msgdone)
  264.           elseif screenOut == 12 then
  265.             rednet.send(12,msgdone)
  266.           end
  267.           sleep(0.1)
  268.           break
  269.         end
  270.       end
  271.     end
  272.   else
  273.     error("fbM-l.251: invalid option")
  274.   end
  275.   sleep(0.1)
  276. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement