Advertisement
SoulofSorrow

redirectToGlasses

Sep 18th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.89 KB | None | 0 0
  1. local colourToHex = {
  2.     [colours.white] = 0xffffff,
  3.     [colours.orange] = 0xffa500,
  4.     [colours.magenta] = 0xff00ff,
  5.     [colours.lightBlue] = 0xadd8e6,
  6.     [colours.yellow] = 0xffff00,
  7.     [colours.lime] = 0xbfff00,
  8.     [colours.pink] = 0xffc0cb,
  9.     [colours.grey] = 0x808080,
  10.     [colours.lightGrey] = 0xd3d3d3,
  11.     [colours.cyan] = 0x00ffff,
  12.     [colours.purple] = 0x800080,
  13.     [colours.blue] = 0x0000ff,
  14.     [colours.brown] = 0xa52a2a,
  15.     [colours.green] = 0x00ff00,
  16.     [colours.red] = 0xff0000,
  17.     [colours.black] = 0x000000,
  18. }
  19.  
  20. local hexValues = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"}
  21. local hexToColour = {}
  22. for i = 1, 16 do
  23.     hexToColour[hexValues[i]] = 2^(i-1)
  24. end
  25.  
  26. local charOffset = {
  27.     [ 33 ] = 2, [ 39 ] = 2, [ 40 ] = 1, [ 41 ] = 1, [ 42 ] = 1, [ 44 ] = 2, [ 46 ] = 2, [ 58 ] = 2, [ 59 ] = 2,
  28.     [ 60 ] = 1, [ 62 ] = 1, [ 73 ] = 1, [ 91 ] = 1, [ 93 ] = 1, [ 96 ] = 2, [ 102 ] = 1, [ 105 ] = 2, [ 107 ] = 1,
  29.     [ 108 ] = 2, [ 116 ] = 1, [ 123 ] = 1, [ 124 ] = 2, [ 125 ] = 1,
  30. }
  31.  
  32. local function newRedirect(surface, xOffset, yOffset, width, height)
  33.     local redirect = {
  34.         surface = surface,
  35.         xOffset = xOffset, yOffset = yOffset, zOffset = 1,
  36.         width = 0, height = 0,
  37.         map = {},
  38.         clickCatcher = {
  39.             ID = false,
  40.             object = false,
  41.         },
  42.         cursor = {
  43.             xPos = 1,
  44.             yPos = 1,
  45.             blink = false,
  46.             object = false,
  47.         },
  48.         textColour = colours.white,
  49.         backgroundColour = colours.black,
  50.         isDrawn = false,
  51.         isVisible = true,
  52.         hasChanged = false,
  53.         opacity = 1,
  54.     }
  55.    
  56.     local function drawClickCatcher()
  57.         local clickCatcherObject = redirect.surface.addBox(redirect.xOffset, redirect.yOffset, redirect.width*6, redirect.height*9, 0x000000, 0)
  58.         clickCatcherObject.setScreenAnchor("MIDDLE", "MIDDLE")
  59.         clickCatcherObject.setVisible(redirect.isVisible)
  60.         clickCatcherObject.setZ(redirect.zOffset + 3)
  61.         redirect.clickCatcher.ID = clickCatcherObject.getId()
  62.         redirect.clickCatcher.object = clickCatcherObject
  63.     end
  64.    
  65.     local function drawText(xPos, yPos, text, textColour)
  66.         local textObject = redirect.surface.addText((xPos-1)*6 + redirect.xOffset + (charOffset[string.byte(text)] or 0), (yPos-1)*9 + redirect.yOffset, text, colourToHex[textColour])
  67.         textObject.setScreenAnchor("MIDDLE", "MIDDLE")
  68.         textObject.setVisible(redirect.isVisible)
  69.         textObject.setZ(redirect.zOffset + 1)
  70.         return textObject
  71.     end
  72.    
  73.     local function drawBackground(xPos, yPos, backgroundColour)
  74.         local backgroundObject = redirect.surface.addBox((xPos-1)*6 + redirect.xOffset, (yPos-1)*9 + redirect.yOffset, 6, 9, colourToHex[backgroundColour], redirect.opacity)
  75.         backgroundObject.setScreenAnchor("MIDDLE", "MIDDLE")
  76.         backgroundObject.setVisible(redirect.isVisible)
  77.         backgroundObject.setZ(redirect.zOffset)
  78.         return backgroundObject
  79.     end
  80.    
  81.     local function drawCursor()
  82.         local cursorObject = redirect.surface.addText((redirect.cursor.xPos-1)*6 + redirect.xOffset + (charOffset[string.byte("_")] or 0), (redirect.cursor.yPos-1)*9 + redirect.yOffset, "_", colourToHex[redirect.textColour])
  83.         cursorObject.setScreenAnchor("MIDDLE", "MIDDLE")
  84.         cursorObject.setVisible((redirect.isVisible and redirect.cursor.blink and (redirect.map[redirect.cursor.yPos] and redirect.map[redirect.cursor.yPos][redirect.cursor.xPos]) and true) or false)
  85.         cursorObject.setZ(redirect.zOffset + 2)
  86.         return cursorObject
  87.     end
  88.    
  89.     local function createCoord(xPos, yPos, text, textColour, backgroundColour)
  90.         local coord = {
  91.             data = {
  92.                 text = text,
  93.                 textColour = textColour,
  94.                 backgroundColour = backgroundColour,
  95.             },
  96.             text = false,
  97.             background = false,
  98.         }
  99.         if redirect.isDrawn then
  100.             coord.text = drawText(xPos, yPos, text, textColour)
  101.             coord.background = drawBackground(xPos, yPos, backgroundColour)
  102.         end
  103.         return coord
  104.     end
  105.    
  106.     local function updateCoord(xPos, yPos, text, textColour, backgroundColour)
  107.         local coord = redirect.map[yPos] and redirect.map[yPos][xPos]
  108.         if coord then
  109.             local coordData = coord.data
  110.             if coordData.text ~= text or coordData.textColour ~= textColour or coordData.backgroundColour ~= backgroundColour then
  111.                 coordData.text = text
  112.                 coordData.textColour = textColour
  113.                 coordData.backgroundColour = backgroundColour
  114.                 if redirect.isDrawn then
  115.                     coord.text.setText(text)
  116.                     coord.text.setColor(colourToHex[textColour])
  117.                     coord.text.setX((xPos-1)*6 + redirect.xOffset + (charOffset[string.byte(text)] or 0))
  118.                     coord.background.setColor(colourToHex[backgroundColour])
  119.                     redirect.hasChanged = true
  120.                 end
  121.             end
  122.         end
  123.     end
  124.    
  125.     local function updateCursor()
  126.         if redirect.isDrawn then
  127.             local cursor = redirect.cursor.object
  128.             if cursor then
  129.                 cursor.setX((redirect.cursor.xPos-1)*6 + redirect.xOffset + (charOffset[string.byte("_")] or 0))
  130.                 cursor.setY((redirect.cursor.yPos-1)*9 + redirect.yOffset)
  131.                 cursor.setZ(redirect.zOffset + 2)
  132.                 cursor.setVisible((redirect.isVisible and redirect.cursor.blink and (redirect.map[redirect.cursor.yPos] and redirect.map[redirect.cursor.yPos][redirect.cursor.xPos]) and true) or false)
  133.                 cursor.setColor(colourToHex[redirect.textColour])
  134.             end
  135.         end
  136.     end
  137.    
  138.     redirect.getDrawn = function()
  139.         return redirect.isDrawn
  140.     end
  141.     redirect.setDrawn = function(isDrawn)
  142.         if type(isDrawn) == "boolean" and redirect.isDrawn ~= isDrawn then
  143.             if isDrawn == true then
  144.                 for yPos, line in ipairs(redirect.map) do
  145.                     for xPos, coord in ipairs(line) do
  146.                         coord.text = drawText(xPos, yPos, coord.data.text, coord.data.textColour)
  147.                         coord.background = drawBackground(xPos, yPos, coord.data.backgroundColour)
  148.                     end
  149.                 end
  150.                 drawClickCatcher()
  151.                 redirect.cursor.object = drawCursor()
  152.             else
  153.                 for yPos, line in ipairs(redirect.map) do
  154.                     for xPos, coord in ipairs(line) do
  155.                         coord.text.delete()
  156.                         coord.background.delete()
  157.                         coord.text = false
  158.                         coord.background = false
  159.                     end
  160.                 end
  161.                 redirect.cursor.object.delete()
  162.                 redirect.cursor.object = false
  163.                 redirect.clickCatcher.ID = false
  164.                 redirect.clickCatcher.object.delete()
  165.                 redirect.clickCatcher.object = false
  166.             end
  167.             redirect.isDrawn = isDrawn
  168.             redirect.hasChanged = true
  169.             return true
  170.         end
  171.         return false
  172.     end
  173.    
  174.     redirect.getVisible = function()
  175.         return redirect.isVisible
  176.     end
  177.     redirect.setVisible = function(isVisible)
  178.         if type(isVisible) == "boolean" and redirect.isVisible ~= isVisible then
  179.             if redirect.isDrawn then
  180.                 for yPos, line in ipairs(redirect.map) do
  181.                     for xPos, coord in ipairs(line) do
  182.                         coord.text.setVisible(isVisible)
  183.                         coord.background.setVisible(isVisible)
  184.                     end
  185.                 end
  186.                 redirect.clickCatcher.object.setVisible(isVisible)
  187.                 redirect.cursor.object.setVisible(isVisible and redirect.cursor.blink)
  188.                 redirect.hasChanged = true
  189.             end
  190.             redirect.isVisible = isVisible
  191.             return true
  192.         end
  193.         return false
  194.     end
  195.    
  196.     redirect.getOpacity = function()
  197.         return redirect.opacity
  198.     end
  199.     redirect.setOpacity = function(opacity)
  200.         if type(opacity) == "number" and opacity >= 0 and opacity <= 1 then
  201.             if redirect.isDrawn then
  202.                 for yPos, line in ipairs(redirect.map) do
  203.                     for xPos, coord in ipairs(line) do
  204.                         coord.background.setOpacity(opacity)
  205.                     end
  206.                 end
  207.                 redirect.hasChanged = true
  208.             end
  209.             redirect.opacity = opacity
  210.             return true
  211.         end
  212.         return false
  213.     end
  214.    
  215.     redirect.getSurface = function()
  216.         return redirect.surface
  217.     end
  218.     redirect.setSurface = function(surface, redraw)
  219.         redirect.surface = surface
  220.         if redraw == true and redirect.isDrawn then
  221.             redirect.setDrawn(false)
  222.             redirect.setDrawn(true)
  223.         end
  224.     end
  225.    
  226.     redirect.getOffset = function()
  227.         return redirect.xOffset, redirect.yOffset
  228.     end
  229.     redirect.setOffset = function(xOffset, yOffset, zOffset)
  230.         redirect.xOffset = math.floor(tonumber(xOffset) or redirect.xOffset)
  231.         redirect.yOffset = math.floor(tonumber(yOffset) or redirect.yOffset)
  232.         redirect.zOffset = math.min(250, math.max(1, math.floor(tonumber(xOffset) or redirect.xOffset)))
  233.         if redirect.isDrawn then
  234.             for yPos, line in ipairs(redirect.map) do
  235.                 for xPos, coord in ipairs(line) do
  236.                     coord.text.setX((xPos-1)*6 + redirect.xOffset + (charOffset[string.byte(coord.data.text)] or 0))
  237.                     coord.text.setY((yPos-1)*9 + redirect.yOffset)
  238.                     coord.text.setZ(redirect.zOffset + 1)
  239.  
  240.                     coord.background.setX((xPos-1)*6 + redirect.xOffset)
  241.                     coord.background.setY((yPos-1)*9 + redirect.yOffset)
  242.                     coord.background.setZ(redirect.zOffset)
  243.                 end
  244.             end
  245.             redirect.clickCatcher.object.setX(redirect.xOffset)
  246.             redirect.clickCatcher.object.setY(redirect.yOffset)
  247.             redirect.clickCatcher.object.setZ(redirect.zOffset + 3)
  248.             updateCursor()
  249.             redirect.hasChanged = true
  250.         end
  251.         return true
  252.     end
  253.    
  254.     redirect.getSize = function()
  255.         return redirect.width, redirect.height
  256.     end
  257.     redirect.setSize = function(width, height)
  258.         for yPos = 1, math.max(height, redirect.height) do
  259.             redirect.map[yPos] = redirect.map[yPos] or {}
  260.             for xPos = 1, math.max(width, redirect.width) do
  261.                 if xPos <= width and yPos <= height then
  262.                     if not redirect.map[yPos][xPos] then
  263.                         redirect.map[yPos][xPos] = createCoord(xPos, yPos, " ", redirect.textColour, redirect.backgroundColour)
  264.                     end
  265.                 else
  266.                     if redirect.map[yPos][xPos] then
  267.                         local coord = redirect.map[yPos][xPos]
  268.                         if coord.text then
  269.                             coord.text.delete()
  270.                         end
  271.                         if coord.background then
  272.                             coord.background.delete()
  273.                         end
  274.                         if coord.clickCatcher then
  275.                             redirect.clickCatchers[coord.clickCatcher.getId()] = nil
  276.                             coord.clickCatcher.delete()
  277.                         end
  278.                         redirect.map[yPos][xPos] = nil
  279.                     end
  280.                 end
  281.             end
  282.         end
  283.         if redirect.isDrawn then
  284.             redirect.clickCatcher.object.delete()
  285.             drawClickCatcher()
  286.         end
  287.         updateCursor()
  288.         redirect.hasChanged = true
  289.         redirect.width, redirect.height = width, height
  290.     end
  291.    
  292.     redirect.getClick = function(objectID, xPos, yPos)
  293.         if objectID == redirect.clickCatcher.ID then
  294.             return math.ceil(xPos/6), math.ceil(yPos/9)
  295.         else
  296.             return false, false
  297.         end
  298.     end
  299.        
  300.     local term = {
  301.         write = function(text)
  302.             local textType = type(text)
  303.             if textType == "string" or textType == "number" then
  304.                 local text = string.gsub(text, "%c", " ")
  305.                 local length = string.len(text)
  306.                 if length > 0 then
  307.                     if redirect.map[redirect.cursor.yPos] then
  308.                         for xPos = 1, length do
  309.                             updateCoord(xPos - 1 + redirect.cursor.xPos, redirect.cursor.yPos, string.sub(text, xPos, xPos), redirect.textColour, redirect.backgroundColour)
  310.                         end
  311.                     end
  312.                     redirect.cursor.xPos = redirect.cursor.xPos + length
  313.                     updateCursor()
  314.                 end
  315.             end
  316.         end,
  317.         blit = function(text, textColour, backgroundColour)
  318.             if type(text) ~= "string" or type(textColour) ~= "string" or type(backgroundColour) ~= "string" then
  319.                 error("Expected string, string, string", 2)
  320.             end
  321.             if #text ~= #textColour or #text ~= #backgroundColour then
  322.                 error("Arguments must be the same length", 2)
  323.             end
  324.             local text = string.gsub(text, "%c", " ")
  325.             local length = string.len(text)
  326.             if length > 0 then
  327.                 if redirect.map[redirect.cursor.yPos] then
  328.                     for xPos = 1, length do
  329.                         updateCoord(xPos - 1 + redirect.cursor.xPos, redirect.cursor.yPos, string.sub(text, xPos, xPos), hexToColour[string.sub(textColour, xPos, xPos)] or redirect.textColour, hexToColour[string.sub(backgroundColour, xPos, xPos)]or redirect.backgroundColour)
  330.                     end
  331.                 end
  332.                 redirect.cursor.xPos = redirect.cursor.xPos + length
  333.                 updateCursor()
  334.             end
  335.         end,
  336.         clear = function()
  337.             for yPos = 1, redirect.height do
  338.                 for xPos = 1, redirect.width do
  339.                     updateCoord(xPos, yPos, " ", redirect.textColour, redirect.backgroundColour)
  340.                 end
  341.             end
  342.         end,
  343.         clearLine = function()
  344.             if redirect.map[redirect.cursor.yPos] then
  345.                 for xPos = 1, redirect.width do
  346.                     updateCoord(xPos, redirect.cursor.yPos, " ", redirect.textColour, redirect.backgroundColour)
  347.                 end
  348.             end
  349.         end,
  350.         getCursorPos = function()
  351.             return redirect.cursor.xPos, redirect.cursor.yPos
  352.         end,
  353.         setCursorPos = function(xPos, yPos)
  354.             redirect.cursor.xPos = math.floor(tonumber(xPos) or redirect.cursor.xPos)
  355.             redirect.cursor.yPos = math.floor(tonumber(yPos) or redirect.cursor.yPos)
  356.             updateCursor()
  357.         end,
  358.         setCursorBlink = function(blink)
  359.             if type(blink) == "boolean" then
  360.                 redirect.cursor.blink = blink
  361.                 updateCursor()
  362.             end
  363.         end,
  364.         isColour = function()
  365.             return true
  366.         end,
  367.         getSize = function()
  368.             return redirect.width, redirect.height
  369.         end,
  370.         scroll = function(noOfLines)
  371.             local n = math.floor(tonumber(noOfLines) or 0)
  372.             if n ~= 0 and redirect.height > 0 then
  373.                 for yPos = (n > 0 and 1) or redirect.height, (n < 0 and 1) or redirect.height, n/math.abs(n) do
  374.                     for xPos = 1, redirect.width do
  375.                         if redirect.map[yPos + n] then
  376.                             local coord = redirect.map[yPos + n][xPos].data
  377.                             updateCoord(xPos, yPos, coord.text, coord.textColour, coord.backgroundColour)
  378.                         else
  379.                             updateCoord(xPos, yPos, " ", redirect.textColour, redirect.backgroundColour)
  380.                         end
  381.                     end
  382.                 end
  383.             end
  384.         end,
  385.         setTextColour = function(colour)
  386.             local colour = tonumber(colour)
  387.             if colourToHex[colour] then
  388.                 redirect.textColour = colour
  389.                 updateCursor()
  390.             end
  391.         end,
  392.         getTextColour = function()
  393.             return redirect.textColour
  394.         end,
  395.         setBackgroundColour = function(colour)
  396.             local colour = tonumber(colour)
  397.             if colourToHex[colour] then
  398.                 redirect.backgroundColour = colour
  399.                 updateCursor()
  400.             end
  401.         end,
  402.         getBackgroundColour = function()
  403.             return redirect.backgroundColour
  404.         end,
  405.     }
  406.     term.isColor = term.isColour
  407.     term.setTextColor = term.setTextColour
  408.     term.getTextColor = term.getTextColour
  409.     term.setBackgroundColor = term.setBackgroundColour
  410.     term.getBackgroundColor = term.getBackgroundColour
  411.    
  412.     redirect.term = term
  413.    
  414.     redirect.setSize(width, height)
  415.    
  416.     return redirect
  417. end
  418.  
  419. local function printUsage()
  420.     print("redirectToGlass: <(string) programPath> <(string) username> <(string) bridgeSide>")
  421. end
  422.  
  423. local tArgs = {...}
  424. local programPath, username, bridgeSide = tArgs[1], tArgs[2], tArgs[3]
  425.  
  426. if type(programPath) ~= "string" then
  427.     printError("programPath must be of type: string")
  428.     printUsage()
  429.     return
  430. elseif not fs.exists(programPath) or fs.isDir(programPath) then
  431.     printError("File not found: "..programPath)
  432.     printUsage()
  433.     return
  434. end
  435.  
  436. if type(username) ~= "string" then
  437.     printError("username must be of type: string")
  438.     printUsage()
  439.     return
  440. end
  441.  
  442. local bridge
  443. if type(bridgeSide) ~= "string" then
  444.     printError("bridgeSide must be of type: string")
  445.     printUsage()
  446.     return
  447. else
  448.     local peripheralType = peripheral.getType(bridgeSide)
  449.     if peripheralType == "openperipheral_bridge" then
  450.         bridge = peripheral.wrap(bridgeSide)
  451.     else
  452.         printError("terminal glasses bridge not found on side: "..bridgeSide)
  453.         printUsage()
  454.         return
  455.     end
  456. end
  457.  
  458. local playerSurface = false
  459. while not playerSurface do
  460.     local players = bridge.getUsers()
  461.     for _, playerData in ipairs(players) do
  462.         if playerData.name == username then
  463.             playerSurface = bridge.getSurfaceByName(username)
  464.             playerSurface.clear()
  465.             break
  466.         end
  467.     end
  468.     if not playerSurface then
  469.         os.pullEvent("glasses_attach")
  470.     end
  471. end
  472.  
  473. local width, height = 51, 19
  474. local xOffset, yOffset = -(math.floor(width*6/2)), -(math.floor(height*9/2))
  475. local redirect = newRedirect(playerSurface, xOffset, yOffset, width, height)
  476. redirect.setOpacity(1)
  477. redirect.setVisible(false)
  478. redirect.setDrawn(true)
  479.  
  480. local ignoredEvents = {
  481.     key = true,
  482.     key_up = true,
  483.     mouse_click = true,
  484.     mouse_drag = true,
  485.     mouse_scroll = true,
  486.     mouse_up = true,
  487.     term_resize = true,
  488. }
  489.  
  490. local prevTerm = term.current()
  491. local fnFile, err = loadfile(programPath)
  492. if fnFile then
  493.     local tEnv = {}
  494.     setmetatable( tEnv, { __index = _G } )
  495.     setfenv( fnFile, tEnv )
  496.     local thread = coroutine.create(fnFile)
  497.    
  498.     local running, filter = true, nil
  499.     local function resumeThread(event)
  500.         if not filter or event[1] == filter or event[1] == "terminate" then
  501.             filter = nil
  502.             local ok, passback = coroutine.resume(thread, unpack(event))
  503.             if not ok then
  504.                 running = false
  505.                 term.redirect(prevTerm)
  506.                 printError(passback)
  507.             elseif coroutine.status(thread) == "dead" then
  508.                 running = false
  509.             else
  510.                 filter = passback
  511.             end
  512.         end
  513.     end
  514.    
  515.     term.redirect(redirect.term)
  516.    
  517.     local event, resume = {}, true
  518.     local lastClickX, lastClickY = false, false
  519.     while running do
  520.         if resume and not ignoredEvents[event[1]] then
  521.             resumeThread(event)
  522.         end
  523.         if redirect.hasChanged then
  524.             bridge.sync()
  525.             redirect.hasChanged = false
  526.         end
  527.         if running then
  528.             event, resume = {coroutine.yield()}, true
  529.             if event[1] == "glasses_key_down" then
  530.                 resumeThread({"key", event[5]})
  531.                 if #string.gsub(event[6], "%c", "") > 0 then
  532.                     resumeThread({"char", event[6]})
  533.                 end
  534.                 resume = false
  535.             elseif event[1] == "glasses_key_up" then
  536.                 resumeThread({"key_up", event[5]})
  537.                 resume = false
  538.             elseif event[1] == "glasses_component_mouse_down" then
  539.                 local xPos, yPos = redirect.getClick(event[5], event[7], event[8])
  540.                 if xPos and yPos then
  541.                     resumeThread({"mouse_click", event[9] + 1, xPos, yPos})
  542.                     lastClickX, lastClickY = xPos, yPos
  543.                 end
  544.                 resume = false
  545.             elseif event[1] == "glasses_component_mouse_up" then
  546.                 local xPos, yPos = redirect.getClick(event[5], event[7], event[8])
  547.                 if xPos and yPos then
  548.                     resumeThread({"mouse_up", event[9] + 1, xPos, yPos})
  549.                     lastClickX, lastClickY = false, false
  550.                 end
  551.                 resume = false
  552.             elseif event[1] == "glasses_mouse_up" then
  553.                 if lastClickX and lastClickY then
  554.                     resumeThread({"mouse_up", event[5] + 1, lastClickX, lastClickY})
  555.                     lastClickX, lastClickY = false, false
  556.                 end
  557.                 resume = false
  558.             elseif event[1] == "glasses_component_mouse_wheel" then
  559.                 local xPos, yPos = redirect.getClick(event[5], event[7], event[8])
  560.                 if xPos and yPos then
  561.                     resumeThread({"mouse_scroll", -event[9]/math.abs(event[9]), xPos, yPos})
  562.                 end
  563.                 resume = false
  564.             elseif event[1] == "glasses_attach" and event[3] == username and not playerSurface then
  565.                 for _, playerData in ipairs(bridge.getUsers()) do
  566.                     if playerData.name == username then
  567.                         playerSurface = bridge.getSurfaceByName(username)
  568.                         redirect.setSurface(playerSurface)
  569.                         redirect.setDrawn(true)
  570.                         break
  571.                     end
  572.                 end
  573.                 resume = false
  574.             elseif event[1] == "glasses_detach" and event[3] == username and playerSurface then
  575.                 redirect.setDrawn(false)
  576.                 playerSurface = false
  577.                 resume = false
  578.             elseif event[1] == "glasses_capture" and event[3] == username then
  579.                 local capture = bridge.getCaptureControl(event[4])
  580.                 capture.setKeyRepeat(true)
  581.                 capture.setBackground(0x000000)
  582.                 redirect.setVisible(true)
  583.                 resume = false
  584.             elseif event[1] == "glasses_release" and event[3] == username then
  585.                 redirect.setVisible(false)
  586.                 resume = false
  587.             end
  588.         end
  589.     end
  590. else
  591.     printError(err)
  592.     os.pullEvent("key")
  593. end
  594.  
  595. if playerSurface then
  596.     playerSurface.clear()
  597.     bridge.sync()
  598. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement