Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --this program is the first of many for use in CC Tweaked, to be used for Aperture Science.
- --the purpose of this program is to manage, oversee, and cleanup test chambers
- local TestingPhase = 0
- local DoorsState = {false,false}
- local TestID = 0
- local TestTopics = "n"
- local TrackNum = 0
- local TrackID = 0
- local LightState = true
- local ChamberLockdown = false
- local ModemSide = "side"
- local TrackProtocol = 0
- local StartTime = 0
- local EndTime = 0
- local ScheduledSubject = nil
- local PersonalServerID = nil
- local MonitorScript = nil
- start()
- local function start()
- if fs.exists("TestingConfig") == false then
- TestSetup()
- else
- TestBoot()
- end
- end
- local function TestBoot()
- local file = fs.open("TestingConfig","r")
- TestID = file.readLine(2)
- TrackID = file.readLine(3)
- TrackNum = file.readLine(4)
- TestTopics = file.readLine(5)
- LightState = file.readLine(6)
- ChamberLockdown = file.readLine(7)
- local DoorAmount = file.readLine(8)
- TrackProtocol = file.readLine(9)
- if DoorAmount > 2 then
- for i = 3, #DoorAmount do
- DoorState[i] = false
- end
- end
- DrawScreen("Boot")
- ChamberDirector()
- end
- local function ChamberDirector()
- DoorManager()
- if ChamberLockdown == true then
- DrawScreen("Lockdown")
- LockdownManager()
- else
- if TestingPhase == 0 then
- DrawScreen("ChamberIdle")
- ChamberManager()
- elseif TestingPhase == -1 then
- DrawScreen("ChamberDisabled")
- ChamberManager()
- else
- GetTestList()
- DrawScreen("TestInProgress")
- TestManager()
- end
- end
- end
- local function ChamberManager()
- local ChamberState = nil
- if TestingPhase == -1 then
- ChamberState = "Disabled"
- else
- ChamberState = "Idle"
- end
- term.setCursorPos(1,1)
- term.writeLine("-----CHAMBER--MANAGER-----")
- term.writeLine("ChamberState = "..ChamberState)
- if ChamberState == "Disabled" then
- term.writeLine("To Reactivate Chamber, please enter ADMIN CODE")
- elseif ChamberState == "Idle" then
- term.writeLine("Chamber is Ready for Testing, press E to Begin")
- end
- DirectiveReceiver()
- end
- local function DoorManager()
- local Ports = {peripheral.find("redstoneIntegrator")}
- local integrator = Ports[1]
- if DoorState[1] ~= nil then
- integrator.setOutput("left",DoorState[1])
- end
- if DoorState[2] ~= nil then
- integrator.setOutput("front",DoorState[2])
- end
- if DoorState[3] ~= nil then
- integrator.setOutput("right",DoorState[3])
- end
- if DoorState[4] ~= nil then
- integrator.setOutput("back",DoorState[4])
- end
- end
- local function DirectiveReceiver()
- rednet.open(ModemSide)
- repeat
- local id, message, protocol = rednet.receive()
- until protocol == TrackProtocol
- if message == "hey" then
- TestingPhase = 0
- elseif message == "Lockdown" then
- ChamberLockdown = true
- elseif message == "stop" then
- TestingPhase = 0
- elseif message == "start" then
- TestingPhase = 1
- end
- SaveConfig()
- sleep(5)
- ChamberDirector()
- end
- local function LockdownManager()
- term.setCursorPos(1,1)
- term.writeLine("-----CHAMBER--UNDER--LOCKDOWN-----")
- term.writeLine("CAN ONLY BE TAKEN OUT OF LOCKDOWN BY TRACK DIRECTOR")
- sleep(5)
- DirectiveReceiver()
- end
- local function TestManager()
- term.setCursorPos(3,3)
- local DefaultSize = term.getTextSize()
- term.setTextScale(5)
- term.write(TestID)
- term.setTextScale = DefaultSize
- local Monitor = peripheral.find("Monitor")
- Monitor.clear()
- Monitor.setBackground("white")
- Monitor.drawBox(1,1,MonitorWidth,MonitorHeight,colors.black)
- Monitor.drawFilledBox((MonitorWidth/2-5),2,(MonitorWidth/2+5),12,colors.gray)
- Monitor.drawBox((MonitorWidth/2-5),2,(MonitorWidth/2+5),12,colors.black)
- local DefaultSize = Monitor.getTextScale()
- Monitor.setTextScale(3)
- Monitor.setCursorPos((MonitorWidth/2)-5,5)
- Monitor.write("Chamber")
- Monitor.setCursorPos((MonitorWidth/2)-5,10)
- Monitor.write(TestID)
- Monitor.setTextScale(0.5)
- Monitor.setCursorPos(1,14)
- Monitor.writeLine(TestID.."-"..TrackNum)
- Monitor.setTextScale(DefaultSize)
- Monitor.setCursorPos(1,20)
- Monitor.writeLine("THIS TEST HAS THE FOLLOWING ITEMS")
- Monitor.writeLine("<This section is blank due to it still being developed>") --add section for the writing of the Test item Symbols
- Monitor.writeLine("Please Enter through the Door to begin")
- repeat
- local event, side = redstone.getInput()
- until side == "bottom"
- TestingPhase = 2
- StartTime = os.time()
- UpdateSubjectFile("Testing")
- repeat
- local event, side = redstone.getInput()
- until side == "bottom"
- EndTime = os.time()
- local SpentTime = EndTime - StartTime
- UpdateSubjectFile("Completed")
- FileResults()
- DirectiveReceiver()
- end
- local function DrawScreen(Screen)
- term.clear()
- if MonitorScript ~= nil then
- if fs.exists("Test_Monitor") == false then
- shell.run("pastebin","get","QwYXnjvh","Test_Monitor")
- end
- shell.run("Test_Monitor",TestID,TrackNum,TestTopics,"1",Screen)
- elseif MonitorScript == nil then
- if Screen == "Boot" then
- term.setBackground("gray")
- term.setTextColor("yellow")
- elseif Screen == "Lockdown" then
- term.setBackground("red")
- term.setTextColor("white")
- elseif Screen == "TestInProgress" then
- term.setBackground("white")
- term.setTextColor("black")
- paintutils.drawFilledBox(2,2,49,18,colors.blue)
- paintutils.drawBox(2,2,49,18,colors.gray)
- paintutils.drawFilledBox(1,1,4,4,colors.white)
- paintutils.drawBox(1,1,4,4,colors.black)
- term.setCursorBlink(false)
- elseif Screen == "ChamberIdle" then
- term.setBackground("blue")
- term.setTextColor("white")
- elseif Screen == "ChamberDisabled" then
- term.setBackground("black")
- term.setTextColor("white")
- end
- end
- local function UpdateSubjectFile(Action)
- rednet.open(ModemSide)
- rednet.send(PersonalServerID,"Test Update",1000)
- repeat
- local id, message = rednet.receive()
- until id == PersonalServerID
- rednet.send(PersonalServerID, ScheduledTestSubject, 1000)
- repeat
- local id, message = rednet.receive()
- until id == PersonalServerID and Message == "Found"
- rednet.send(PersonalServerID, TestID, 1000)
- repeat
- local id, message = rednet.receive()
- until id == PersonalServerID and Message == "y"
- rednet.send(PersonalServerID, Action, 1000)
- repeat
- local id, message = rednet.receive()
- until id == PersonalServerID and Message == "Updated"
- end
- local function FileResults()
- end
- local function SaveConfig()
- local file = fs.open("TestingConfig","w")
- file.setCursorPos(1,1)
- file.writeLine("---DO-NOT-EDIT---")
- file.writeLine(TestID)
- file.writeLine(TrackID)
- file.writeLine(TrackNum)
- file.writeLine(TestTopics)
- file.writeLine(LightState)
- file.writeLine(ChamberLockdown)
- file.writeLine(#DoorState)
- file.writeLine(TrackProtocol)
- file.close()
- end
- local function GetTestList()
- rednet.open(ModemSide)
- local id = rednet.lookup(1000,"Ap_PersonalData")
- rednet.send(id,TestID,1000)
- local ServerID = id
- repeat
- local id, message = rednet.receive()
- until id == ServerID
- ScheduledSubject = message
- PersonalServerID = ServerID
- end
- local function TestSetup()
- print("TEST CHAMBER FIRST TIME SETUP")
- print("Please Enter TestChamber ID")
- local input = read()
- repeat local event, key = os.pullEvent("key") until key == keys.enter
- TestID = input
- input = nil
- print("ID SET TO = "..TestID)
- print("please now enter Track Num")
- input = read()
- repeat local event, key = os.pullEvent("key") until key == keys.enter
- TrackNum = input
- input = nil
- print("Test Track Num set to "..TrackNum)
- print("Please now enter Door Amount(2-4, first two doors are the entrance and exit doors)")
- input = read()
- repeat local event, key = os.pullEvent("key") until key == keys.enter
- print("Door Amount set to "..input)
- if input > 2 then
- for i = 3, #input do
- DoorState[3] = false
- i = i+1
- end
- end
- input = nil
- print("Almost done, just a few more things left to do")
- print("Please enter the number for the topics the test will have")
- print("1= Speed, 2= Temp Flight, 3= Hazardous")
- print("4= Turrets, 5= Mobs, 6= No Light")
- print("7= Void, 8= Live Animals, 9= Turtles")
- print("Press enter to confirm choices")
- while true do
- local event, key = os.pullEvent('key")
- if key == keys.one then
- TestTopics = TestTopics..1.." "
- elseif key == keys.two then
- TestTopics = TestTopics..2.." "
- elseif key == keys.three then
- TestTopics = TestTopics..3.." "
- elseif key == keys.four then
- TestTopics = TestTopics..4.." "
- elseif key == keys.five then
- TestTopics = TestTopics..5.." "
- elseif key == keys.six then
- TestTopics = TestTopics..6.." "
- elseif key == keys.seven then
- TestTopics = TestTopics..7.." "
- elseif key == keys.eigth then
- TestTopics = TestTopics..8.." "
- elseif key == keys.nine then
- TestTopics = TestTopics..9.." "
- elseif key == keys.enter then
- break
- end
- end
- print("Detected Topic IDs = "..TestTopics)
- rednet.broadcast(TrackNum,0)
- repeat
- local id, message, protocol = rednet.receive()
- until message == "Aperture"
- TrackProtocol = protocol
- print("Setup Complete, Saving Data...")
- local file = fs.open("TestingConfig","w")
- file.writeLine("---DO-NOT-EDIT---")
- file.writeLine(TestID)
- file.writeLine(TrackID)
- file.writeLine(TrackNum)
- file.writeLine(TestTopics)
- file.writeLine(LightState)
- file.writeLine(ChamberLockdown)
- file.writeLine(#DoorState)
- file.writeLine(TrackProtocol)
- file.close()
- print("Data Saved, restarting in 10 seconds")
- sleep(10)
- os.reboot
- end
Add Comment
Please, Sign In to add comment