Advertisement
DOGGYWOOF

Untitled

Jun 18th, 2024
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.53 KB | None | 0 0
  1. -- Function to draw the exit option
  2. local function drawExitOption()
  3. term.setCursorPos(1, 1)
  4. term.setBackgroundColor(colors.black)
  5. term.setTextColor(colors.white)
  6. term.write("X")
  7. term.setBackgroundColor(colors.black)
  8. end
  9.  
  10. -- Function to clear the screen with a black background
  11. local function clearScreen()
  12. term.setBackgroundColor(colors.black)
  13. term.setTextColor(colors.white)
  14. term.clear()
  15. term.setCursorPos(1, 1)
  16. end
  17.  
  18. local function getDiskID()
  19. local drive = peripheral.wrap("bottom")
  20. if drive and peripheral.getType("bottom") == "drive" then
  21. if drive.isDiskPresent() then
  22. local diskID = drive.getDiskID()
  23. return diskID
  24. else
  25. return nil, "No disk present in the drive."
  26. end
  27. else
  28. return nil, "No drive found at the bottom."
  29. end
  30. end
  31.  
  32. local function listCards()
  33. clearScreen()
  34. drawExitOption()
  35. local cardDir = "/disk/Cards/"
  36. local files = fs.list(cardDir)
  37. if #files > 0 then
  38. print("Cards in /disk/Cards:")
  39. for _, file in ipairs(files) do
  40. print("- " .. file)
  41. end
  42. else
  43. print("No cards found in /disk/Cards.")
  44. end
  45.  
  46. while true do
  47. local event, button, x, y = os.pullEvent("mouse_click")
  48. if x == 1 and y == 1 then
  49. return
  50. end
  51. end
  52. end
  53.  
  54. local function linkCard()
  55. clearScreen()
  56. drawExitOption()
  57. print("Link Card:")
  58. print("1. Insert Card to Link")
  59. print("2. Enter Card ID")
  60. print("0. Back to Main Menu")
  61.  
  62. while true do
  63. local event, button, x, y = os.pullEvent("mouse_click")
  64. if x == 1 and y == 1 then
  65. return
  66. end
  67.  
  68. if event == "char" then
  69. local choice = tonumber(button)
  70. if choice == 1 then
  71. clearScreen()
  72. drawExitOption()
  73. print("Insert a disk to link or click cancel:")
  74. while true do
  75. local diskID, errorMsg = getDiskID()
  76. if diskID then
  77. local cardFileName = "/disk/Cards/" .. diskID .. ".ID"
  78. local file = fs.open(cardFileName, "w")
  79. file.close()
  80. print("Card linked successfully.")
  81. sleep(2)
  82. local drive = peripheral.wrap("bottom")
  83. drive.ejectDisk()
  84. return
  85. elseif x == 1 and y == 1 then
  86. return
  87. else
  88. print(errorMsg)
  89. sleep(2)
  90. return
  91. end
  92. end
  93. elseif choice == 2 then
  94. clearScreen()
  95. drawExitOption()
  96. print("Enter the card ID:")
  97. local cardID = read()
  98. local cardFileName = "/disk/Cards/" .. cardID .. ".ID"
  99. local file = fs.open(cardFileName, "w")
  100. file.close()
  101. print("Card linked successfully.")
  102. sleep(2)
  103. return
  104. elseif choice == 0 then
  105. return
  106. else
  107. print("Invalid choice. Please enter 1, 2, or 0.")
  108. end
  109. end
  110. end
  111. end
  112.  
  113. local function unlinkCard()
  114. clearScreen()
  115. drawExitOption()
  116. print("Unlink Card:")
  117. print("1. Insert Card to Unlink")
  118. print("2. Enter Card ID")
  119. print("0. Back to Main Menu")
  120.  
  121. while true do
  122. local event, button, x, y = os.pullEvent("mouse_click")
  123. if x == 1 and y == 1 then
  124. return
  125. end
  126.  
  127. if event == "char" then
  128. local choice = tonumber(button)
  129. if choice == 1 then
  130. clearScreen()
  131. drawExitOption()
  132. print("Insert a disk to unlink or click cancel:")
  133. while true do
  134. local diskID, errorMsg = getDiskID()
  135. if diskID then
  136. local cardFileName = "/disk/Cards/" .. diskID .. ".ID"
  137. if fs.exists(cardFileName) then
  138. fs.delete(cardFileName)
  139. print("Card unlinked successfully.")
  140. else
  141. print("No matching card found to unlink.")
  142. end
  143. sleep(2)
  144. local drive = peripheral.wrap("bottom")
  145. drive.ejectDisk()
  146. return
  147. elseif x == 1 and y == 1 then
  148. return
  149. else
  150. print(errorMsg)
  151. sleep(2)
  152. return
  153. end
  154. end
  155. elseif choice == 2 then
  156. clearScreen()
  157. drawExitOption()
  158. print("Enter the card ID:")
  159. local cardID = read()
  160. local cardFileName = "/disk/Cards/" .. cardID .. ".ID"
  161. if fs.exists(cardFileName) then
  162. fs.delete(cardFileName)
  163. print("Card unlinked successfully.")
  164. else
  165. print("No matching card found to unlink.")
  166. end
  167. sleep(2)
  168. return
  169. elseif choice == 0 then
  170. return
  171. else
  172. print("Invalid choice. Please enter 1, 2, or 0.")
  173. end
  174. end
  175. end
  176. end
  177.  
  178. local function mainMenu()
  179. clearScreen()
  180. drawExitOption()
  181. print("Main Menu:")
  182. print("1. List Cards")
  183. print("2. Link Card")
  184. print("3. Unlink Card")
  185. print("0. Exit")
  186.  
  187. while true do
  188. local event, button, x, y = os.pullEvent("mouse_click")
  189. if x == 1 and y == 1 then
  190. os.reboot()
  191. end
  192.  
  193. if event == "char" then
  194. local choice = tonumber(button)
  195. if choice == 1 then
  196. listCards()
  197. mainMenu()
  198. elseif choice == 2 then
  199. linkCard()
  200. mainMenu()
  201. elseif choice == 3 then
  202. unlinkCard()
  203. mainMenu()
  204. elseif choice == 0 then
  205. os.reboot()
  206. else
  207. print("Invalid choice. Please enter 1, 2, 3, or 0.")
  208. end
  209. end
  210. end
  211. end
  212.  
  213. mainMenu()
  214.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement