Advertisement
Guest User

turtle.lua

a guest
Jul 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.08 KB | None | 0 0
  1. --[[
  2.     Turtle Tracking Program
  3.     by brad lmoah
  4. --]]
  5.  
  6. os.loadAPI("button")
  7.  
  8. local w, h = term.getSize()
  9. local termC = term.current()
  10. local turtles = {} -- table of windows
  11. local protocol = "KurwaTurtleUnsecurev1.0"
  12.  
  13.  
  14.  
  15. function initScreen()
  16.     -- init bg
  17.     --term.setBackgroundColor(colors.blue)
  18.     paintutils.drawFilledBox(0,0,w,h,colors.cyan)
  19.     paintutils.drawFilledBox(0,0,w,1,colors.blue)
  20.     paintutils.drawFilledBox(0,2,w,2,colors.lightGray)
  21.     term.setBackgroundColor(colors.blue)
  22.     term.setTextColor(colors.white)
  23.     term.setCursorPos(1,1)
  24.     term.write("Turtle-Trac 2")
  25.    
  26.     local width = w/2-1
  27.     local col2pos = width + 3
  28.    
  29.     term.setBackgroundColor(colors.lightGray)
  30.     local menuTabs = {"File","Edit","Turtle","Help"}
  31.     local p = 1
  32.     for i=1,#menuTabs do
  33.         term.setCursorPos(p,2)
  34.         term.write(menuTabs[i])
  35.         p = p + string.len(menuTabs[i]) + 2
  36.     end
  37.    
  38.     -- to do - loop initialisation
  39.     turtles[1] = window.create(termC,2,3,w/2-1,5,true)
  40.     turtles[2] = window.create(termC,2,9,w/2-1,5,true)
  41.     turtles[3] = window.create(termC,2,15,w/2-1,5,true)
  42.    
  43.     turtles[4] = window.create(termC,col2pos,3,w/2-1,5,true)
  44.     turtles[5] = window.create(termC,col2pos,9,w/2-1,5,true)
  45.     turtles[6] = window.create(termC,col2pos,15,w/2-1,5,true)
  46.    
  47.     for k,v in pairs(turtles) do
  48.         term.redirect(v)
  49.         local tW,tH = term.getSize()
  50.         paintutils.drawFilledBox(0,0,w,h,colors.lightBlue)
  51.         paintutils.drawFilledBox(1,1,w,1,colors.blue)
  52.         local posInit = vector.new(0,0,0)
  53.         updateText("N/A","N/A",posInit)
  54.         term.setCursorPos(tW,1)
  55.         term.setBackgroundColor(colors.red)
  56.         term.write("X")
  57.         term.setCursorPos(tW-1,1)
  58.         term.setBackgroundColor(colors.orange)
  59.         term.write("#")
  60.     end
  61. end
  62.  
  63. function updateText(name,status,pos)
  64.     term.setBackgroundColor(colors.blue)
  65.     term.setTextColor(colors.white)
  66.     term.setCursorPos(1,1)
  67.     term.write(" "..name.." ")
  68.     term.setBackgroundColor(colors.lightBlue)
  69.     term.setCursorPos(1,3)
  70.     term.write(" "..status.."          ")
  71.     term.setCursorPos(1,4)
  72.     term.write(" "..pos.x..","..pos.y..","..pos.z.."          ")
  73. end
  74.  
  75. -- to do replace with protocols instead
  76. -- of hard coded id
  77. function updateScreen(id,msg)
  78.     if id == 42 then
  79.         term.redirect(turtles[1])
  80.         updateText(msg[1],msg[2],msg[3])
  81.     elseif id == 77 then
  82.         term.redirect(turtles[4])
  83.         updateText(msg[1],msg[2],msg[3])
  84.     elseif id == 79 then
  85.         term.redirect(turtles[2])
  86.         updateText(msg[1],msg[2],msg[3])
  87.     elseif id == 80 then
  88.         term.redirect(turtles[5])
  89.         updateText(msg[1],msg[2],msg[3])
  90.     elseif id == 81 then
  91.         term.redirect(turtles[3])
  92.         updateText(msg[1],msg[2],msg[3])
  93.     elseif id == 82 then
  94.         term.redirect(turtles[6])
  95.         updateText(msg[1],msg[2],msg[3])
  96.     end
  97.     term.redirect(termC)
  98. end
  99.    
  100. initScreen()
  101. rednet.open("top")
  102. while true do
  103.    local id,msg = rednet.receive(protocol)
  104.    updateScreen(id,msg)  
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement