Advertisement
Guest User

overseer

a guest
Apr 22nd, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.96 KB | None | 0 0
  1. --[[In the Beginning:
  2. Perform first time Setup saving all Data needed inside the Data folder
  3. Get amount of files inside Turtles directory using fs.list()
  4.  
  5. Next Step:
  6. Create Heading of Table
  7. Print out all current Data saved in Turtles Directory
  8. Draw lines using paintutensils
  9.  
  10. wait for a rednet.receive then edit or create new File
  11. Repeat Next Step:
  12. ]]
  13.     --VARIABLES
  14.    
  15. local computerPeripherallsFile = "computerPeripheralls"     --name of the File to save the Type of Computer
  16. local x,y = term.getSize()                                  --Size of the screen
  17. local highlighted = 1
  18. local line
  19. local file
  20.  
  21.     --TABLES
  22.    
  23. local computerPeripheralls = {}                             --Table to save the Data inside the computerPeripherallsFile
  24. local turtleDataFiles = {}
  25. local calculation = {}
  26. local decoded = {}
  27.    
  28.     --FUNCTION
  29.  
  30.     --TERM FUNCTIONS
  31. function resetScreen()
  32.     term.clear()
  33.     term.setCursorPos(1,1)
  34. end
  35.  
  36.     --MENU
  37. function writeChoices()                         --writes the choices down made for the menu
  38.     for i=1,#choices do
  39.         if i == highlighted then
  40.             term.setCursorPos(((x/2)-(("<| "..choices[i].." |>"):len()/2)),i + 2)
  41.             term.clearLine()
  42.             term.write("<| "..choices[i].." |>")
  43.         else
  44.             term.setCursorPos(((x/2)-(choices[i]:len()/2)),i + 2)
  45.             term.clearLine()
  46.             term.write(choices[i])
  47.         end
  48.     end
  49. end
  50.  
  51. function menuSelection()                        --waits for key input and changes the highlighted menuElemnt
  52.     while true do
  53.         writeChoices()
  54.         local event, key = os.pullEvent( "key" )
  55.         if key == keys.down then
  56.             highlighted = highlighted + 1
  57.         end
  58.         if key == keys.up then
  59.             highlighted = highlighted - 1
  60.         end
  61.         if key == keys.enter then
  62.             chosenOne = choices[highlighted]
  63.             break
  64.         end
  65.         if highlighted == 0 then
  66.             highlighted = #choices
  67.         end
  68.         if highlighted == #choices + 1 then
  69.             highlighted = 1
  70.         end
  71.     end
  72. end
  73.  
  74. function Menu()                                 --Creates a menu
  75.     term.clear()
  76.     term.setCursorPos(math.ceil((x/2)-(stringQuestionAsked:len()/2)),1)
  77.     term.write(stringQuestionAsked)
  78.     menuSelection()
  79. end
  80.  
  81.  
  82.     --LOAD
  83. function load(fileName,arrayName)               --Loading data that is inside File
  84.     file = fs.open("Data/"..fileName,"r") -- Open a file for reading.
  85.     line = file.readLine() -- This function reads the next line in the file, until the end.
  86.     repeat -- Start a loop which will read lines into a table until no lines are left.
  87.         table.insert(arrayName,line) -- Puts the value of the current line into the table we have.
  88.         line = file.readLine() -- read the next line
  89.     until line == nil -- readLine() returns nil when the end of the file is reached.
  90.     file.close() -- Close up the file ready for use again.
  91. end
  92.  
  93.     --CREATE FILE
  94. function createFile(File)                       --Function that is used for the sole purpose of creating a file without editing it
  95.     local file = fs.open("Data/"..File,"a")
  96.     file.close()
  97. end
  98.     --Big Table
  99. function bigTable(yCoordinate)
  100.         computerPeripheralls = {}
  101.         load(computerPeripherallsFile,computerPeripheralls)
  102.        
  103.     if computerPeripheralls[3] ~= 1 then
  104.         local monitor = peripheral.wrap(computerPeripheralls[3])
  105.         local x,y = monitor.getSize()
  106.         monitor.setTextScale(1)
  107.         monitor.clear()
  108.         local maxColumnLen = x/#decoded
  109.         for i = 1, #decoded do
  110.             local thisColumStarts = x / #decoded * (i-1) + 1
  111.             monitor.setCursorPos( thisColumStarts + ( (maxColumnLen-#decoded[i])/2), yCoordinate )
  112.             monitor.write(decoded[i])
  113.         end
  114.         for i = 1, #decoded do
  115.             local thisColumStarts = x / #decoded * (i-1) + 1
  116.             monitor.setCursorPos( thisColumStarts + ( (maxColumnLen-#decoded[i])/2), yCoordinate )
  117.             monitor.write(decoded[i])
  118.         end
  119.     else
  120.         local x,y = term.getSize()
  121.         term.setTextScale(1)
  122.         clear()
  123.         local maxColumnLen = x/#decoded
  124.         for i = 1, #decoded do
  125.             local thisColumStarts = x / #decoded * (i-1) + 1
  126.             term.setCursorPos( thisColumStarts + ( (maxColumnLen-#decoded[i])/2), 1 )
  127.             term.write(decoded[i])
  128.         end
  129.     end
  130.    
  131. end
  132.  
  133.     --CODE
  134.     --FIRST TIME SETUP
  135.    
  136. fs.makeDir("Data") 
  137. fs.makeDir("Turtles")  
  138. createFile(computerPeripherallsFile)
  139.  
  140. computerPeripheralls = {}
  141. load(computerPeripherallsFile,computerPeripheralls)
  142. if computerPeripheralls[1] == nil then
  143.     stringQuestionAsked = "This is a?"
  144.     choices = {"Computer","Computer with Monitor","PocketComputer"}
  145.     Menu()
  146.     table.insert(computerPeripheralls,1,chosenOne)
  147.     if computerPeripheralls[1] ~= "PocketComputer" then
  148.         stringQuestionAsked = "Wireless Modem your Perspective?"
  149.         choices = {"left","right","front","back","bottom","top"}
  150.         Menu()
  151.         table.insert(computerPeripheralls,2,chosenOne)
  152.         if computerPeripheralls[1] == "Computer with Monitor" then
  153.             stringQuestionAsked = "Where is the Monitor?"
  154.             choices = {"left","right","front","back","bottom","top"}
  155.             Menu()
  156.             table.insert(computerPeripheralls,3,chosenOne)
  157.         end
  158.     end
  159.     if computerPeripheralls[2] == nil then
  160.         table.insert(computerPeripheralls,2,"1")
  161.         table.insert(computerPeripheralls,3,"1")
  162.     end
  163.     if computerPeripheralls[3] == nil then
  164.         table.insert(computerPeripheralls,3,"1")
  165.     end
  166.     local file = fs.open("Data/"..computerPeripherallsFile,"w")
  167.         for i=1,#computerPeripheralls,1 do
  168.             file.writeLine(computerPeripheralls[i])
  169.         end
  170.     file.close()
  171. end
  172.  
  173. computerPeripheralls = {}
  174. load(computerPeripherallsFile,computerPeripheralls)
  175. if computerPeripheralls[1] ~= "PocketComputer" then
  176.     rednet.open(computerPeripheralls[2])
  177.     if computerPeripheralls[1] == "Computer with Monitor" then
  178.         local monitor = peripheral.wrap(computerPeripheralls[3])
  179.     end
  180. end
  181.  
  182. turtleDataFiles = fs.list("Turtles/")
  183. for n=1,#turtleDataFiles,1 do
  184.     file = fs.open("Turtles/"..turtleDataFiles[n],"r") -- Open a file for reading.
  185.     line = file.readLine() -- This function reads the next line in the file, until the end.
  186.     repeat -- Start a loop which will read lines into a table until no lines are left.
  187.         table.insert(decoded,line) -- Puts the value of the current line into the table we have.
  188.         line = file.readLine() -- read the next line
  189.     until line == nil -- readLine() returns nil when the end of the file is reached.
  190.     file.close() -- Close up the file ready for use again.
  191.     bigTable(n)
  192. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement