Maxstripe

TrackerGlasses

Nov 6th, 2015
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- This program sets up the environment needed to run
  2. -- the TrackerGlass program zEtx48ni written by
  3. -- MorgosMaci
  4.  
  5. function validateSide(side)
  6.   if side == "top" then
  7.     return true
  8.   end
  9.   if side == "bottom" then
  10.     return true
  11.   end
  12.   if side == "left" then
  13.     return true
  14.   end
  15.   if side == "right" then
  16.     return true
  17.   end
  18.   if side == "front" then
  19.     return true
  20.   end
  21.   if side == "back" then
  22.     return true
  23.   end
  24.   return false
  25. end
  26.  
  27. function tableLength(t)
  28.   local count = 0
  29.   for _ in pairs(t) do count = count + 1 end
  30.   return count
  31. end
  32.  
  33. function clampX(x)
  34.   if not x then
  35.     x = 0
  36.   end
  37.   if x < -4530 then
  38.     x = -4530
  39.   end
  40.   if x > 6235 then
  41.     x = 6235
  42.   end
  43.   return x
  44. end
  45.  
  46. function clampY(y)
  47.   if not y then
  48.     y = 0
  49.   end
  50.   if y < 5 then
  51.     y = 5
  52.   end
  53.   if y > 255 then
  54.     y = 255
  55.   end
  56.   return y
  57. end
  58.  
  59. function clampZ(z)
  60.   if not z then
  61.     z = 0
  62.   end
  63.   if z < -4330 then
  64.     z = -4330
  65.   end
  66.   if z > 6275 then
  67.     z = 6275
  68.   end
  69.   return z
  70. end
  71.  
  72. function writeColor(mon, text, fgColor, bgColor)
  73.   if (mon.isColor()) then
  74.     if fgColor then
  75.       mon.setTextColor(fgColor)
  76.     end
  77.     if bgColor then
  78.       mon.setBackgroundColor(bgColor)
  79.     end
  80.   end
  81.   mon.write(text)
  82.   if (mon.isColor()) then
  83.     mon.setTextColor(colors.white)
  84.     mon.setBackgroundColor(colors.black)
  85.   end
  86. end
  87.  
  88. function getDevice(search)
  89.   local plist = peripheral.getNames()
  90.   local i, name
  91.   for i, name in pairs(plist) do
  92.     if string.find(peripheral.getType(name), search) then
  93.       return peripheral.wrap(name)
  94.     end
  95.   end
  96.   if search == monitor then
  97.     return term
  98.   else
  99.     return nil
  100.   end
  101. end
  102.  
  103. term.clear()
  104. term.setCursorPos(1, 1)
  105. term.write("Setting up TrackerGlass by MorgosMaci")
  106. term.setCursorPos(1, 3)
  107. term.write("Checking hardware configuration...")
  108. fatal = false
  109. term.setCursorPos(1, 4)
  110. term.write("Checking for monitor: ")
  111. mon = getDevice("monitor")
  112. term.setCursorPos(23, 4)
  113. if mon then
  114.   mon.setTextScale(0.5)
  115.   mw, mh = mon.getSize()
  116.   if mh < 30 or mw < 65 then
  117.     writeColor(term, "Monitor must be atleast 4x3.", colors.red)
  118.     fatal = true
  119.   elseif not mon.isColor() then
  120.     writeColor(term, "Color preferred.", colors.yellow)
  121.   else
  122.     writeColor(term, "Good.", colors.green)
  123.   end
  124. else
  125.     writeColor(term, "Monitor not found.", colors.red)
  126.     fatal = true
  127. end
  128. term.setCursorPos(1, 5)
  129. term.write("Checking for bridge: ")
  130. d = getDevice("glassesbridge")
  131. term.setCursorPos(22, 5)
  132. if d then
  133.     writeColor(term, "Good.", colors.green)
  134. else
  135.     writeColor(term, "Glasses bridge not found.", colors.red)
  136.     fatal = true
  137. end
  138. term.setCursorPos(1, 6)
  139. term.write("Checking for ME Interface: ")
  140. d = getDevice("me_interface")
  141. term.setCursorPos(28, 6)
  142. if d then
  143.     writeColor(term, "Good.", colors.green)
  144. else
  145.     writeColor(term, "Not found.", colors.yellow)
  146. end
  147. term.setCursorPos(1, 7)
  148. term.write("Checking for drive: ")
  149. term.setCursorPos(21, 7)
  150. basedir = "/"
  151. if fs.isDir("/disk") then
  152.   if fs.getFreeSpace("/disk") < 100000 then
  153.     writeColor(term, "Too small.", colors.yellow)
  154.   else
  155.     writeColor(term, "Good.", colors.green)
  156.     basedir = "/disk/"
  157.   end
  158. else
  159.   writeColor(term, "Not found.", colors.yellow)
  160. end
  161.  
  162. term.setCursorPos(1, 9)
  163.  
  164. if fatal then
  165.   writeColor(term, "Invalid hardware setup.", colors.red)
  166.   print("\nTerminating.\n")
  167.   return
  168. end
  169.  
  170. print("Hardware is sufficient.\n")
  171. print("Review any warnings and press enter to start.")
  172. read()
  173.  
  174. term.clear()
  175. term.setCursorPos(1, 1)
  176. print("Setting up "..basedir.."settings/default.settings\n")
  177. defaultSettings = {}
  178. -- Setup the default spawn and world filter.
  179. defaultSettings.worldFilter = "world"
  180. defaultSettings.hereSpawn = vector.new(910, 65, 1035)
  181. -- Setup the default location of the tracking window.
  182. defaultSettings.trackLoc = {x=1, y=1}
  183. -- Setup the default location of the output window.
  184. defaultSettings.outputLoc = {x=400, y=40, l=40}
  185. defaultSettings.privUsers = {}
  186. while tableLength(defaultSettings.privUsers) < 1 do
  187.   print("Enter admin users seperated by a space.")
  188.   users = read()
  189.   for user in string.gmatch(users, "[^%s]+") do
  190.     defaultSettings.privUsers[user] = true
  191.   end
  192. end
  193. print("Enter X coordinate of your base.")
  194. local x = clampX(tonumber(read()))
  195. print("Enter Y coordinate of your base.")
  196. local y = clampY(tonumber(read()))
  197. print("Enter Z coordinate of your base.")
  198. local z = clampZ(tonumber(read()))
  199. defaultSettings.hereDefault = vector.new(x, y, z)
  200.  
  201. d = getDevice("me_interface")
  202. if d then
  203.   defaultSettings.MESide = ""
  204.   while not validateSide(defaultSettings.MESide) do
  205.     print("Enter the side of the ME interface for the\ndelivery chest. (Default top)")
  206.     defaultSettings.MESide = read()
  207.     if defaultSettings.MESide == "" then
  208.       defaultSettings.MESide = "top"
  209.     end
  210.   end
  211. else
  212.   defaultSettings.MESide = "top"
  213. end
  214.  
  215. term.clear()
  216. term.setCursorPos(1, 1)
  217. print("Creating "..basedir.."settings")
  218. fs.makeDir(basedir.."settings")
  219. print("Writing "..basedir.."settings/default.settings\n")
  220. local fh = fs.open(basedir.."settings/default.settings", "w")
  221. if fh then
  222.   fh.write(textutils.serialize(defaultSettings))
  223.   fh.close()
  224. else
  225.   print("Error creating the default settings file.")
  226.   return
  227. end
  228. fs.delete(basedir.."tg")
  229. print("Writing startup file...")
  230. fh = fs.open(basedir.."startup", "w")
  231. if fh then
  232.   fh.write("main = \""..basedir.."tg\"\n")
  233.   fh.write("if fs.exists(main) then\n")
  234.   fh.write("  os.run({}, main)\n")
  235.   fh.write("end\n")
  236.   fh.close()
  237. else
  238.   Print("Error creating the startup file.")
  239.   return
  240. end
  241. print("Downloading the main program to "..basedir.."tg...")
  242. success = shell.run("pastebin", "get", "zEtx48ni", basedir.."tg")
  243. if not success then
  244.   print("Error downloading from pastebin zEtx48ni.")
  245.   return
  246. end
  247. print("Press enter to reboot.")
  248. read()
  249. os.reboot()
Add Comment
Please, Sign In to add comment