Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function findPeripheral( kind )
- for _,v in pairs( rs.getSides() ) do
- if peripheral.getType( v ) == kind then
- return v
- end
- end
- return nil
- end
- local monitor -- empty variable waiting for peripheral.wrap
- local monitorSide = findPeripheral( "monitor" )
- local sizeX, sizeY = term.getSize() -- get the pixel size of the screen ( currently the computers screen )
- if not monitorSide then
- print( "No monitor found! :(")
- error() -- exit the program here
- else
- monitor = peripheral.wrap(monitorSide)
- end
- local function cwrite( msg, y )
- local w, h = term.getSize() -- get the pixel size of the current screen
- term.setCursorPos( w/2-#msg/2+1, y or h/2 ) -- set the cursor position so the supplied text will be in the middle of the screen
- write( msg ) -- draw the message
- end
- local function cline( y, col )
- term.setCursorPos(1,y)
- term.setBackgroundColor( col )
- term.clearLine()
- term.setBackgroundColor( colors.black )
- end
- local activeLines = {
- approch = "Train Approching",
- leaving = "Train Leaving",
- here = "Train Arrived",
- }
- local function drawScreen()
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor( colors.white )
- local w, h = term.getSize()
- cline( 1, colors.gray )
- cwrite("\[Pitsea Station\]",1)
- local rsInput = rs.getBundledInput("bottom")
- term.setTextColor( colors.white )
- cline( 3, colors.red )
- cwrite("Platform 1",3)
- cwrite("No Trains",5)
- if colors.test( rsInput, colors.blue ) then
- term.setTextColor( colors.lime )
- cwrite( activeLines.here, 5)
- end
- if colors.test( rsInput, colors.lime ) then
- term.setTextColor( colors.blue )
- cwrite( activeLines.approch, 5)
- end
- if colors.test( rsInput, colors.orange ) then
- term.setTextColor( colors.red )
- cwrite( activeLines.leaving, 5)
- end
- term.setTextColor( colors.white )
- cline( h/2+2, colors.blue )
- cwrite("Platform 2",h/2+2)
- cwrite("No Trains", h/2+4)
- if colors.test( rsInput, colors.red ) then
- term.setTextColor( colors.lime )
- cwrite( activeLines.here, h/2+4)
- end
- if colors.test( rsInput, colors.black ) then
- term.setTextColor( colors.blue )
- cwrite( activeLines.approch, h/2+4)
- end
- if colors.test( rsInput, colors.white ) then
- term.setTextColor( colors.red )
- cwrite( activeLines.leaving, h/2+4)
- end
- end
- term.clear() -- clear the terminal screen
- cwrite( "Monitor has focus" ) -- print in the middle of the screen that the monitor has control
- term.redirect( monitor ) -- give control of term functions to the monitor object meaning term. print and write will all show on the monitor
- local refresh = os.startTimer( 1 ) -- this starts a timer that takes 1 second to complete, used for refreshing ( its better than sleep but requires event loops )
- while true do
- drawScreen() -- call the function that will draw the screen
- os.pullEvent( "timer" ) -- the program will wait here until the timer finishes
- refresh = os.startTimer( 1 ) -- restart the refresh timer
- end
- term.restore() -- give term control back to the computer screen
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement