Advertisement
killer64

Untitled

Jan 13th, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 KB | None | 0 0
  1. local function wrap(name,w)
  2.     for k,v in pairs(peripheral.getNames()) do
  3.         if peripheral.getType(v)==name then
  4.             if w=="wireless" then
  5.                 if peripheral.call(v,"isWireless") then
  6.                     return peripheral.wrap(v)
  7.                 end
  8.             else
  9.                 return peripheral.wrap(v)
  10.             end
  11.         end
  12.     end
  13. end
  14. local server=...~="client"
  15. local ioc=wrap("tilespatialioport")
  16. local m=wrap("monitor")
  17. m.setTextScale(0.9)
  18. local modem=wrap("modem","wireless")
  19. modem.open(13005)
  20. local conf={
  21.     s={
  22.         "left",
  23.         "bottom",
  24.         "right",
  25.     },
  26.     n={
  27.         "main",
  28.         "wiiplay",
  29.         "lur",
  30.     },
  31. }
  32. local function materialize()
  33.     rs.setOutput("front",true)
  34.     sleep(0.2)
  35.     rs.setOutput("front",false)
  36. end
  37. local function update()
  38.     local i=ioc.getStackInSlot(2)
  39.     if i then
  40.         return ioc.swapStacks(1,2)
  41.     else
  42.         return true
  43.     end
  44. end
  45. local function tp(a,b)
  46.     if not server then
  47.         modem.transmit(13005,a,tostring(b))
  48.     else
  49.         update()
  50.         rs.setOutput(conf.s[a],true)
  51.         sleep(0.2)
  52.         materialize()
  53.         if not update() then
  54.             error("failed to dematerialize")
  55.         end
  56.         rs.setOutput(conf.s[a],false)
  57.         sleep(0.2)
  58.         rs.setOutput(conf.s[b],true)
  59.         sleep(0.2)
  60.         materialize()
  61.         rs.setOutput(conf.s[b],false)
  62.         if not update() then
  63.             error("failed to materialize")
  64.         end
  65.     end
  66. end
  67. local Mx,My=m.getSize()
  68. local Cx,Cy=math.ceil(Mx/2),math.ceil(My/2)
  69. local function rMain()
  70.     m.setBackgroundColor(colors.gray)
  71.     m.clear()
  72.     m.setBackgroundColor(colors.lightBlue)
  73.     m.setCursorPos(1,1)
  74.     m.clearLine()
  75.     m.setCursorPos(1,2)
  76.     m.clearLine()
  77.     m.setCursorPos(1,3)
  78.     m.clearLine()
  79.     m.setCursorPos(Cx-9,2)
  80.     m.setTextColor(colors.black)
  81.     m.write("teleporter control")
  82. end
  83. local pPos={}
  84. local sel1,sel2=0,0
  85. local function rPorts()
  86.     local cnt=#conf.n
  87.     local mul=Mx/(cnt+1)
  88.     m.setTextColor(colors.white)
  89.     for l1=1,cnt do
  90.         local s=mul*l1
  91.         local x=math.floor(s-2)
  92.         pPos[l1]=x
  93.         m.setCursorPos((x+3)-math.floor(#conf.n[l1]/2),4)
  94.         m.setBackgroundColor(colors.gray)
  95.         m.write(conf.n[l1])
  96.         for l2=-2,1 do
  97.             if sel1==l1 then
  98.                 m.setBackgroundColor(colors.lightBlue)
  99.             else
  100.                 m.setBackgroundColor(colors.red)
  101.             end
  102.             m.setCursorPos(x,8+l2)
  103.             m.write((" "):rep(5))
  104.             if sel1~=0 then
  105.                 if sel1==l1 then
  106.                     m.setBackgroundColor(colors.gray)
  107.                 elseif sel2==l1 then
  108.                     m.setBackgroundColor(colors.lightBlue)
  109.                 else
  110.                     m.setBackgroundColor(colors.red)
  111.                 end
  112.                 m.setCursorPos(x,16+l2)
  113.                 m.write((" "):rep(5))
  114.             end
  115.         end
  116.     end
  117.     if sel2~=0 then
  118.         m.setBackgroundColor(colors.green)
  119.     else
  120.         m.setBackgroundColor(colors.lightGray)
  121.     end
  122.     for l1=21,23 do
  123.         local s=pPos[1]
  124.         m.setCursorPos(s,l1)
  125.         m.write((" "):rep((pPos[#pPos]-s)+5))
  126.     end
  127.     m.setTextColor(colors.black)
  128.     m.setCursorPos(Cx-4,22)
  129.     m.write("teleport")
  130. end
  131. rMain()
  132. rPorts()
  133. while true do
  134.     local p={os.pullEvent()}
  135.     if p[1]=="monitor_touch" then
  136.         for l1=1,#conf.n do
  137.             if p[4]>5 and p[4]<10 and p[3]>pPos[l1]-1 and p[3]<pPos[l1]+6 then
  138.                 sel1=l1
  139.                 if sel1==sel2 then
  140.                     sel2=0
  141.                 end
  142.                 rPorts()
  143.             elseif p[4]>13 and p[4]<18 and p[3]>pPos[l1]-1 and p[3]<pPos[l1]+6 and l1~=sel1 then
  144.                 sel2=l1
  145.                 rPorts()
  146.             end
  147.         end
  148.         if sel2~=0 and p[4]>20 and p[4]<24 and
  149.             p[3]>pPos[1]-1 and
  150.             p[3]<(pPos[#pPos]-pPos[1])+6 then
  151.             m.setBackgroundColor(colors.gray)
  152.             m.clear()
  153.             tp(sel1,sel2)
  154.             rMain()
  155.             rPorts()
  156.         end
  157.     elseif server and p[1]=="modem_message" and p[3]==13005 then
  158.         tp(p[4],tonumber(p[5]))
  159.     end
  160. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement