Guest User

Untitled

a guest
Apr 22nd, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.76 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 paintutils nope cause paintutils buggy as fuck
  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. local senderID, message, protocol
  21.  
  22. --TABLES
  23.  
  24. local computerPeripheralls = {} --Table to save the Data inside the computerPeripherallsFile
  25. local turtleDataFiles = {}
  26. local calculation = {}
  27. local decoded = {}
  28.  
  29. --FUNCTION
  30.  
  31. --TERM FUNCTIONS
  32. function resetScreen()
  33. term.clear()
  34. term.setCursorPos(1,1)
  35. end
  36.  
  37. --MENU
  38. function writeChoices() --writes the choices down made for the menu
  39. for i=1,#choices do
  40. if i == highlighted then
  41. term.setCursorPos(((x/2)-(("<| "..choices[i].." |>"):len()/2)),i + 2)
  42. term.clearLine()
  43. term.write("<| "..choices[i].." |>")
  44. else
  45. term.setCursorPos(((x/2)-(choices[i]:len()/2)),i + 2)
  46. term.clearLine()
  47. term.write(choices[i])
  48. end
  49. end
  50. end
  51.  
  52. function menuSelection() --waits for key input and changes the highlighted menuElemnt
  53. while true do
  54. writeChoices()
  55. local event, key = os.pullEvent( "key" )
  56. if key == keys.down then
  57. highlighted = highlighted + 1
  58. end
  59. if key == keys.up then
  60. highlighted = highlighted - 1
  61. end
  62. if key == keys.enter then
  63. chosenOne = choices[highlighted]
  64. break
  65. end
  66. if highlighted == 0 then
  67. highlighted = #choices
  68. end
  69. if highlighted == #choices + 1 then
  70. highlighted = 1
  71. end
  72. end
  73. end
  74.  
  75. function Menu() --Creates a menu
  76. term.clear()
  77. term.setCursorPos(math.ceil((x/2)-(stringQuestionAsked:len()/2)),1)
  78. term.write(stringQuestionAsked)
  79. menuSelection()
  80. end
  81.  
  82.  
  83. --LOAD
  84. function load(fileName,arrayName) --Loading data that is inside File
  85. file = fs.open("Data/"..fileName,"r") -- Open a file for reading.
  86. line = file.readLine() -- This function reads the next line in the file, until the end.
  87. repeat -- Start a loop which will read lines into a table until no lines are left.
  88. table.insert(arrayName,line) -- Puts the value of the current line into the table we have.
  89. line = file.readLine() -- read the next line
  90. until line == nil -- readLine() returns nil when the end of the file is reached.
  91. file.close() -- Close up the file ready for use again.
  92. end
  93.  
  94.  
  95. function decode(text)
  96. local newString = {}
  97. for n=1,#text,1 do
  98. if string.sub(text,n,n) == "%" then
  99. table.insert(newString,n)
  100. end
  101. end
  102. for n=1,#newString,1 do
  103. if n-1 == 0 then
  104. table.insert(decoded,string.sub(text,1,newString[n]-1))
  105. else
  106. table.insert(decoded,string.sub(text,newString[n-1]+1,newString[n]-1))
  107. end
  108. end
  109. for n=1,#decoded,1 do
  110. print(decoded[n])
  111. end
  112. end
  113.  
  114. --CREATE FILE
  115. function createFile(File) --Function that is used for the sole purpose of creating a file without editing it
  116. local file = fs.open("Data/"..File,"a")
  117. file.close()
  118. end
  119. --Big Table
  120. function bigTable(yCoordinate)
  121. computerPeripheralls = {}
  122. load(computerPeripherallsFile,computerPeripheralls)
  123.  
  124. if computerPeripheralls[3] ~= 1 then
  125. local monitor = peripheral.wrap(computerPeripheralls[3])
  126. local x,y = monitor.getSize()
  127. monitor.setTextScale(0.85)
  128. local maxColumnLen = x/#decoded
  129. for i = 1, #decoded do
  130. local thisColumStarts = x / #decoded * (i-1) + 1
  131. monitor.setCursorPos( thisColumStarts + ( (maxColumnLen-#decoded[i])/2), yCoordinate )
  132. monitor.write(decoded[i])
  133. end
  134. else
  135. table.remove(decoded,5)
  136. table.remove(decoded,6)
  137. term.setTextScale(0.85)
  138. local x,y = term.getSize()
  139. clear()
  140. local maxColumnLen = x/#decoded
  141. for i = 1, #decoded do
  142. local thisColumStarts = x / #decoded * (i-1) + 1
  143. term.setCursorPos( thisColumStarts + ( (maxColumnLen-#decoded[i])/2), yCoordinate )
  144. term.write(decoded[i])
  145. end
  146. end
  147. decoded = {}
  148. end
  149.  
  150. --CODE
  151. --FIRST TIME SETUP
  152.  
  153. fs.makeDir("Data")
  154. fs.makeDir("Turtles")
  155. createFile(computerPeripherallsFile)
  156.  
  157. computerPeripheralls = {}
  158. load(computerPeripherallsFile,computerPeripheralls)
  159. if computerPeripheralls[1] == nil then
  160. stringQuestionAsked = "This is a?"
  161. choices = {"Computer","Computer with Monitor","PocketComputer"}
  162. Menu()
  163. table.insert(computerPeripheralls,1,chosenOne)
  164. if computerPeripheralls[1] ~= "PocketComputer" then
  165. stringQuestionAsked = "Wireless Modem your Perspective?"
  166. choices = {"left","right","front","back","bottom","top"}
  167. Menu()
  168. table.insert(computerPeripheralls,2,chosenOne)
  169. if computerPeripheralls[1] == "Computer with Monitor" then
  170. stringQuestionAsked = "Where is the Monitor?"
  171. choices = {"left","right","front","back","bottom","top"}
  172. Menu()
  173. table.insert(computerPeripheralls,3,chosenOne)
  174. end
  175. end
  176. if computerPeripheralls[2] == nil then
  177. table.insert(computerPeripheralls,2,"1")
  178. table.insert(computerPeripheralls,3,"1")
  179. end
  180. if computerPeripheralls[3] == nil then
  181. table.insert(computerPeripheralls,3,"1")
  182. end
  183. local file = fs.open("Data/"..computerPeripherallsFile,"w")
  184. for i=1,#computerPeripheralls,1 do
  185. file.writeLine(computerPeripheralls[i])
  186. end
  187. file.close()
  188. end
  189.  
  190. computerPeripheralls = {}
  191. load(computerPeripherallsFile,computerPeripheralls)
  192. if computerPeripheralls[1] ~= "PocketComputer" then
  193. rednet.open(computerPeripheralls[2])
  194. if computerPeripheralls[1] == "Computer with Monitor" then
  195. local monitor = peripheral.wrap(computerPeripheralls[3])
  196. monitor.clear()
  197. else
  198. clear()
  199. end
  200. else
  201. clear()
  202. end
  203.  
  204.  
  205. -- CODE
  206. while true do
  207. decoded = {"IDs","X","Z","Holes","Tracked Blocks"," "}
  208. bigTable(1)
  209. turtleDataFiles = fs.list("Turtles/")
  210. for n=1,#turtleDataFiles,1 do
  211. print(turtleDataFiles[n])
  212. file = fs.open("Turtles/"..turtleDataFiles[n],"r") -- Open a file for reading.
  213. line = file.readLine() -- This function reads the next line in the file, until the end.
  214. repeat -- Start a loop which will read lines into a table until no lines are left.
  215. table.insert(decoded,line) -- Puts the value of the current line into the table we have.
  216. line = file.readLine() -- read the next line
  217. until line == nil -- readLine() returns nil when the end of the file is reached.
  218. file.close() -- Close up the file ready for use again.
  219. bigTable(n+1)
  220. end
  221. print("wait")
  222. senderID, message, protocol = rednet.receive()
  223. decoded = {}
  224. decode(message)
  225. table.insert(decoded[1].." "..senderID)
  226. table.remove(decoded,2)
  227. local file = fs.open("Data/"..senderID,"w")
  228. for i=1,#decoded,1 do
  229. file.writeLine(decoded[i])
  230. end
  231. file.close()
  232. end
Advertisement
Add Comment
Please, Sign In to add comment