Marlingaming

TestChamber Manager V1

Sep 10th, 2021 (edited)
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.67 KB | None | 0 0
  1. --this program is the first of many for use in CC Tweaked, to be used for Aperture Science.
  2. --the purpose of this program is to manage, oversee, and cleanup test chambers
  3. local TestingPhase = 0
  4. local DoorsState = {false,false}
  5. local TestID = 0
  6. local TestTopics = "n"
  7. local TrackNum = 0
  8. local TrackID = 0
  9. local LightState = true
  10. local ChamberLockdown = false
  11. local ModemSide = "side"
  12. local TrackProtocol = 0
  13. local StartTime = 0
  14. local EndTime = 0
  15. local ScheduledSubject = nil
  16. local PersonalServerID = nil
  17. local MonitorScript = nil
  18. start()
  19.  
  20. local function start()
  21. if fs.exists("TestingConfig") == false then
  22. TestSetup()
  23. else
  24. TestBoot()
  25. end
  26. end
  27.  
  28. local function TestBoot()
  29. local file = fs.open("TestingConfig","r")
  30. TestID = file.readLine(2)
  31. TrackID = file.readLine(3)
  32. TrackNum = file.readLine(4)
  33. TestTopics = file.readLine(5)
  34. LightState = file.readLine(6)
  35. ChamberLockdown = file.readLine(7)
  36. local DoorAmount = file.readLine(8)
  37. TrackProtocol = file.readLine(9)
  38. if DoorAmount > 2 then
  39. for i = 3, #DoorAmount do
  40. DoorState[i] = false
  41. end
  42. end
  43. DrawScreen("Boot")
  44. ChamberDirector()
  45. end
  46.  
  47. local function ChamberDirector()
  48. DoorManager()
  49. if ChamberLockdown == true then
  50. DrawScreen("Lockdown")
  51. LockdownManager()
  52. else
  53. if TestingPhase == 0 then
  54. DrawScreen("ChamberIdle")
  55. ChamberManager()
  56. elseif TestingPhase == -1 then
  57. DrawScreen("ChamberDisabled")
  58. ChamberManager()
  59. else
  60. GetTestList()
  61. DrawScreen("TestInProgress")
  62. TestManager()
  63. end
  64. end
  65. end
  66.  
  67. local function ChamberManager()
  68. local ChamberState = nil
  69. if TestingPhase == -1 then
  70. ChamberState = "Disabled"
  71. else
  72. ChamberState = "Idle"
  73. end
  74. term.setCursorPos(1,1)
  75. term.writeLine("-----CHAMBER--MANAGER-----")
  76. term.writeLine("ChamberState = "..ChamberState)
  77. if ChamberState == "Disabled" then
  78. term.writeLine("To Reactivate Chamber, please enter ADMIN CODE")
  79. elseif ChamberState == "Idle" then
  80. term.writeLine("Chamber is Ready for Testing, press E to Begin")
  81. end
  82. DirectiveReceiver()
  83. end
  84.  
  85. local function DoorManager()
  86. local Ports = {peripheral.find("redstoneIntegrator")}
  87. local integrator = Ports[1]
  88. if DoorState[1] ~= nil then
  89. integrator.setOutput("left",DoorState[1])
  90. end
  91. if DoorState[2] ~= nil then
  92. integrator.setOutput("front",DoorState[2])
  93. end
  94. if DoorState[3] ~= nil then
  95. integrator.setOutput("right",DoorState[3])
  96. end
  97. if DoorState[4] ~= nil then
  98. integrator.setOutput("back",DoorState[4])
  99. end
  100. end
  101.  
  102. local function DirectiveReceiver()
  103. rednet.open(ModemSide)
  104. repeat
  105. local id, message, protocol = rednet.receive()
  106. until protocol == TrackProtocol
  107. if message == "hey" then
  108. TestingPhase = 0
  109. elseif message == "Lockdown" then
  110. ChamberLockdown = true
  111. elseif message == "stop" then
  112. TestingPhase = 0
  113. elseif message == "start" then
  114. TestingPhase = 1
  115. end
  116. SaveConfig()
  117. sleep(5)
  118. ChamberDirector()
  119. end
  120.  
  121. local function LockdownManager()
  122. term.setCursorPos(1,1)
  123. term.writeLine("-----CHAMBER--UNDER--LOCKDOWN-----")
  124. term.writeLine("CAN ONLY BE TAKEN OUT OF LOCKDOWN BY TRACK DIRECTOR")
  125. sleep(5)
  126. DirectiveReceiver()
  127. end
  128.  
  129. local function TestManager()
  130. term.setCursorPos(3,3)
  131. local DefaultSize = term.getTextSize()
  132. term.setTextScale(5)
  133. term.write(TestID)
  134. term.setTextScale = DefaultSize
  135. local Monitor = peripheral.find("Monitor")
  136. Monitor.clear()
  137. Monitor.setBackground("white")
  138. Monitor.drawBox(1,1,MonitorWidth,MonitorHeight,colors.black)
  139. Monitor.drawFilledBox((MonitorWidth/2-5),2,(MonitorWidth/2+5),12,colors.gray)
  140. Monitor.drawBox((MonitorWidth/2-5),2,(MonitorWidth/2+5),12,colors.black)
  141. local DefaultSize = Monitor.getTextScale()
  142. Monitor.setTextScale(3)
  143. Monitor.setCursorPos((MonitorWidth/2)-5,5)
  144. Monitor.write("Chamber")
  145. Monitor.setCursorPos((MonitorWidth/2)-5,10)
  146. Monitor.write(TestID)
  147. Monitor.setTextScale(0.5)
  148. Monitor.setCursorPos(1,14)
  149. Monitor.writeLine(TestID.."-"..TrackNum)
  150. Monitor.setTextScale(DefaultSize)
  151. Monitor.setCursorPos(1,20)
  152. Monitor.writeLine("THIS TEST HAS THE FOLLOWING ITEMS")
  153. Monitor.writeLine("<This section is blank due to it still being developed>") --add section for the writing of the Test item Symbols
  154. Monitor.writeLine("Please Enter through the Door to begin")
  155. repeat
  156. local event, side = redstone.getInput()
  157. until side == "bottom"
  158. TestingPhase = 2
  159. StartTime = os.time()
  160. UpdateSubjectFile("Testing")
  161. repeat
  162. local event, side = redstone.getInput()
  163. until side == "bottom"
  164. EndTime = os.time()
  165. local SpentTime = EndTime - StartTime
  166. UpdateSubjectFile("Completed")
  167. FileResults()
  168. DirectiveReceiver()
  169. end
  170.  
  171. local function DrawScreen(Screen)
  172. term.clear()
  173. if MonitorScript ~= nil then
  174. if fs.exists("Test_Monitor") == false then
  175. shell.run("pastebin","get","QwYXnjvh","Test_Monitor")
  176. end
  177. shell.run("Test_Monitor",TestID,TrackNum,TestTopics,"1",Screen)
  178. elseif MonitorScript == nil then
  179. if Screen == "Boot" then
  180. term.setBackground("gray")
  181. term.setTextColor("yellow")
  182. elseif Screen == "Lockdown" then
  183. term.setBackground("red")
  184. term.setTextColor("white")
  185. elseif Screen == "TestInProgress" then
  186. term.setBackground("white")
  187. term.setTextColor("black")
  188. paintutils.drawFilledBox(2,2,49,18,colors.blue)
  189. paintutils.drawBox(2,2,49,18,colors.gray)
  190. paintutils.drawFilledBox(1,1,4,4,colors.white)
  191. paintutils.drawBox(1,1,4,4,colors.black)
  192. term.setCursorBlink(false)
  193. elseif Screen == "ChamberIdle" then
  194. term.setBackground("blue")
  195. term.setTextColor("white")
  196. elseif Screen == "ChamberDisabled" then
  197. term.setBackground("black")
  198. term.setTextColor("white")
  199. end
  200. end
  201.  
  202. local function UpdateSubjectFile(Action)
  203. rednet.open(ModemSide)
  204. rednet.send(PersonalServerID,"Test Update",1000)
  205. repeat
  206. local id, message = rednet.receive()
  207. until id == PersonalServerID
  208. rednet.send(PersonalServerID, ScheduledTestSubject, 1000)
  209. repeat
  210. local id, message = rednet.receive()
  211. until id == PersonalServerID and Message == "Found"
  212. rednet.send(PersonalServerID, TestID, 1000)
  213. repeat
  214. local id, message = rednet.receive()
  215. until id == PersonalServerID and Message == "y"
  216. rednet.send(PersonalServerID, Action, 1000)
  217. repeat
  218. local id, message = rednet.receive()
  219. until id == PersonalServerID and Message == "Updated"
  220. end
  221.  
  222. local function FileResults()
  223.  
  224. end
  225.  
  226. local function SaveConfig()
  227. local file = fs.open("TestingConfig","w")
  228. file.setCursorPos(1,1)
  229. file.writeLine("---DO-NOT-EDIT---")
  230. file.writeLine(TestID)
  231. file.writeLine(TrackID)
  232. file.writeLine(TrackNum)
  233. file.writeLine(TestTopics)
  234. file.writeLine(LightState)
  235. file.writeLine(ChamberLockdown)
  236. file.writeLine(#DoorState)
  237. file.writeLine(TrackProtocol)
  238. file.close()
  239. end
  240.  
  241. local function GetTestList()
  242. rednet.open(ModemSide)
  243. local id = rednet.lookup(1000,"Ap_PersonalData")
  244. rednet.send(id,TestID,1000)
  245. local ServerID = id
  246. repeat
  247. local id, message = rednet.receive()
  248. until id == ServerID
  249. ScheduledSubject = message
  250. PersonalServerID = ServerID
  251. end
  252.  
  253. local function TestSetup()
  254. print("TEST CHAMBER FIRST TIME SETUP")
  255. print("Please Enter TestChamber ID")
  256. local input = read()
  257. repeat local event, key = os.pullEvent("key") until key == keys.enter
  258. TestID = input
  259. input = nil
  260. print("ID SET TO = "..TestID)
  261. print("please now enter Track Num")
  262. input = read()
  263. repeat local event, key = os.pullEvent("key") until key == keys.enter
  264. TrackNum = input
  265. input = nil
  266. print("Test Track Num set to "..TrackNum)
  267. print("Please now enter Door Amount(2-4, first two doors are the entrance and exit doors)")
  268. input = read()
  269. repeat local event, key = os.pullEvent("key") until key == keys.enter
  270. print("Door Amount set to "..input)
  271. if input > 2 then
  272. for i = 3, #input do
  273. DoorState[3] = false
  274. i = i+1
  275. end
  276. end
  277. input = nil
  278. print("Almost done, just a few more things left to do")
  279. print("Please enter the number for the topics the test will have")
  280. print("1= Speed, 2= Temp Flight, 3= Hazardous")
  281. print("4= Turrets, 5= Mobs, 6= No Light")
  282. print("7= Void, 8= Live Animals, 9= Turtles")
  283. print("Press enter to confirm choices")
  284. while true do
  285. local event, key = os.pullEvent('key")
  286. if key == keys.one then
  287. TestTopics = TestTopics..1.." "
  288. elseif key == keys.two then
  289. TestTopics = TestTopics..2.." "
  290. elseif key == keys.three then
  291. TestTopics = TestTopics..3.." "
  292. elseif key == keys.four then
  293. TestTopics = TestTopics..4.." "
  294. elseif key == keys.five then
  295. TestTopics = TestTopics..5.." "
  296. elseif key == keys.six then
  297. TestTopics = TestTopics..6.." "
  298. elseif key == keys.seven then
  299. TestTopics = TestTopics..7.." "
  300. elseif key == keys.eigth then
  301. TestTopics = TestTopics..8.." "
  302. elseif key == keys.nine then
  303. TestTopics = TestTopics..9.." "
  304. elseif key == keys.enter then
  305. break
  306. end
  307. end
  308. print("Detected Topic IDs = "..TestTopics)
  309. rednet.broadcast(TrackNum,0)
  310. repeat
  311. local id, message, protocol = rednet.receive()
  312. until message == "Aperture"
  313. TrackProtocol = protocol
  314. print("Setup Complete, Saving Data...")
  315. local file = fs.open("TestingConfig","w")
  316. file.writeLine("---DO-NOT-EDIT---")
  317. file.writeLine(TestID)
  318. file.writeLine(TrackID)
  319. file.writeLine(TrackNum)
  320. file.writeLine(TestTopics)
  321. file.writeLine(LightState)
  322. file.writeLine(ChamberLockdown)
  323. file.writeLine(#DoorState)
  324. file.writeLine(TrackProtocol)
  325. file.close()
  326. print("Data Saved, restarting in 10 seconds")
  327. sleep(10)
  328. os.reboot
  329. end
Add Comment
Please, Sign In to add comment