zed_com

Авто показ добавленых компонентов

Jul 20th, 2015
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. --назвать файл autorun.lua
  2. event=require("event")
  3. component=require("component")
  4. gpu=component.gpu
  5. term=require("term")
  6. function printAddedCom()
  7.     oldColor=gpu.getForeground()
  8.     gpu.setForeground(3394611)
  9.     len=string.len(com)+16
  10.     W, H=gpu.getResolution()
  11.     gpu.fill(W-len, 1, W, 1, "-")
  12.     gpu.set(W-len, 2, "----Найден "..com.."-----")
  13.     gpu.set(W-len, 3, "--- Компонент добавлен---")
  14.     gpu.set(W-len, 4, "--В значение "..com.." --")
  15.     oldCursorPosx, oldCursorPosy=term.getCursor()
  16.     term.setCursor(W-len, 5)
  17.     for i=1, len do
  18.         io.write("-")
  19.     end
  20.     term.setCursor(oldCursorPosx, oldCursorPosy)
  21.     gpu.setForeground(oldColor)
  22. end
  23. function getTheTerrain()
  24.     _G.line={}
  25.     len=string.len(com)+16
  26.     W, H=gpu.getResolution()
  27.     for y=1, 5 do
  28.         linetmp=""
  29.         for x=W-len, W do
  30.             symbol=gpu.get(x, y)
  31.             linetmp=linetmp..symbol
  32.         end
  33.         line[y]=linetmp
  34.     end
  35. end
  36. function restoreTerrain()
  37.     len=string.len(com)+16
  38.     W, H=gpu.getResolution()
  39.     gpu.set(W-len, 1, line[1])
  40.     gpu.set(W-len, 2, line[2])
  41.     gpu.set(W-len, 3, line[3])
  42.     gpu.set(W-len, 4, line[4])
  43.     gpu.set(W-len, 5, line[5])
  44. end
  45. function getNewCom(_, address, comName)
  46.     _G.com=comName
  47.     getTheTerrain()
  48.     printAddedCom()
  49.     _G[comName]=component[comName]
  50.     event.timer(3, restoreTerrain)
  51. end
  52. event.listen("component_added", getNewCom)
Advertisement
Add Comment
Please, Sign In to add comment