Spiker985

FTB - Modular Task Manager

Oct 7th, 2013
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.59 KB | None | 0 0
  1. --Edit
  2. local rulesFile = "rules"
  3. local rulesEnabled = false
  4. local notifyEnabled = true
  5. local header = "Challenges"
  6. local completedFile = "completed"
  7. local challengeFile = "challenges"
  8. local mon = peripheral.wrap("right")
  9. local autoSyncChallengeName = ""    --Should be the same as your challengeFile
  10. local autoSyncChallengeCode = ""    --Pastebin code, leave blank if not in use
  11. --Edit
  12.  
  13. --This program was setup to use 12 advanced monitors in a 3 x 4 pattern
  14. --"challengeFile" is a file containing the "challenges/task' for a person to do
  15. --"completedFile" is a file containing true/false answers to whether or not a "challenge/task" has been completed
  16. --"mon" is the side the monitor is in comparison to the computer
  17. --"notify" is a true/false value to enable notifications of when the "Rules" button is disabled
  18. --"rules" is a true/false value to enable the "Rules" button
  19. --"rulesFile" is a file containing the "rules" for a person to follow
  20. --****1-9 = MAX 34 CHARACTERS INCLUDING SPACES****
  21. --****10-99 = MAX 33 CHARACTERS INCLUDING SPACES****
  22. --****100-224 = MAX 32 CHARACTERS INCLUDING SPACES****
  23. --Button API will be downloaded on program run, ignore the line below
  24. --If you do not already have it, the "Button" API pastebin code is S8x0K3ui -> Command: pastebin get S8x0k3ui button *HTTP API MUST BE ENABLED IN CC CONFIG*
  25. --THE MAX CHARACTERS ONE "RULES" LINE CAN HAVE IS 34
  26. --The max number of pages is 16, aka 224 "Challenges"
  27.  
  28. --Don't mess with anything below this unless you know what are you are doing
  29. local pages = 1
  30. local rules = {}
  31. local pageNum = 1
  32. local numRules = 0
  33. local challenges = {}
  34. local numChallenges = 0
  35. local completedChallenges = {}
  36. local rule = io.open(rulesFile, "r")
  37. local chal = io.open(challengeFile, "r")
  38. local comp = io.open(completedFile, "r")
  39.  
  40. term.clear()
  41. term.setCursorPos(1,1)
  42. mon.clear()
  43.  
  44. function APILoader(apiName, apiPastebin)
  45.   os.unloadAPI(apiName)
  46.   if fs.exists(apiName) then
  47.     os.loadAPI(apiName)
  48.   else
  49.     shell.run("pastebin","get",apiPastebin,apiName)
  50.     os.loadAPI(apiName)
  51.   end
  52. end
  53.  
  54. function pastebinDownloader(apiName, apiPastebin)
  55.   if fs.exists(apiName) then
  56.     shell.run("delete", apiname)
  57.     shell.run("pastebin","get",apiPastebin,apiName)
  58.   else
  59.     shell.run("pastebin","get",apiPastebin,apiName)
  60.   end
  61. end
  62.  
  63. function autoSync()
  64.   if autoSyncChallengeCode ~= "" then
  65.     pastebinDownloader(autoSyncChallengeName, autoSyncChallengeCode)
  66.   end
  67. end
  68.  
  69. function checkFilesExist()
  70.   if fs.exists(rulesFile) == false then
  71.     file = fs.open(rulesFile, "w")
  72.     file.close()
  73.   end
  74.   if (fs.exists(completedFile) == false) then
  75.     file = fs.open(completedFile, "w")
  76.     file.close()
  77.   end
  78.   if (fs.exists(challengeFile) == false) then
  79.     file = fs.open(challengeFile, "w")
  80.     file.close()
  81.   end
  82. end
  83.  
  84. function heading()
  85.   button.heading(header..":")
  86. end
  87.  
  88. function setupButtons()
  89.   button.setTable("Prev", prevPage, false, "", 1, 6, 18, 20)
  90.   button.setTable("Next", nextPage, false, "", 33, 39, 18, 20)
  91.   setupRules()
  92.   button.screen()
  93. end
  94.  
  95. function setupPages()
  96.   mon.clear()
  97.   button.clearTable()
  98.   heading()
  99.  
  100.   for i = 1,numChallenges do
  101.     if 14 * i >= numChallenges then
  102.       pages = i
  103.       break
  104.     end
  105.   end
  106.  
  107.   if pageNum == 1 then
  108.     button.clearTable()
  109.     for i = 1,14 do
  110.       button.label(2, 2+i, i..") ")
  111.     end
  112.     for j = 1,14 do
  113.       if challenges[j] == nil then
  114.         challenges[j] = ""
  115.       end
  116.       if j <= 9 then
  117.         x1 = 5
  118.         x2 = string.len(challenges[j]) + 4
  119.       end
  120.       if j >= 10 then
  121.         x1 = 6
  122.         x2 = string.len(challenges[j]) + 5
  123.       end
  124.       y = 2 + j
  125.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  126.     end
  127.   end
  128.   if pageNum == 2 then
  129.     button.clearTable()
  130.     for i = 15,28 do
  131.       button.label(2, -12+i, i..") ")
  132.     end
  133.     for j = 15,28 do
  134.       if challenges[j] == nil then
  135.         challenges[j] = ""
  136.       end
  137.       x1 = 6
  138.       x2 = string.len(challenges[j]) + 5
  139.       y = -12 + j
  140.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  141.     end
  142.   end
  143.   if pageNum == 3 then
  144.     button.clearTable()
  145.     for i = 29,42 do
  146.       button.label(2, -26+i, i..") ")
  147.     end
  148.     for j = 29,42 do
  149.       if challenges[j] == nil then
  150.         challenges[j] = ""
  151.       end
  152.       x1 = 6
  153.       x2 = string.len(challenges[j]) + 5
  154.       y = -26 + j
  155.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  156.     end
  157.   end
  158.   if pageNum == 4 then
  159.     button.clearTable()
  160.     for i = 43,56 do
  161.       button.label(2, -40+i, i..") ")
  162.     end
  163.     for j = 43,56 do
  164.       if challenges[j] == nil then
  165.         challenges[j] = ""
  166.       end
  167.       x1 = 6
  168.       x2 = string.len(challenges[j]) + 5
  169.       y = -40 + j
  170.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  171.     end
  172.   end
  173.   if pageNum == 5 then
  174.     button.clearTable()
  175.     for i = 57, 70 do
  176.       button.label(2, -54+i, i..") ")
  177.     end
  178.     for j = 57, 70 do
  179.       if challenges[j] == nil then
  180.         challenges[j] = ""
  181.       end
  182.       x1 = 6
  183.       x2 = string.len(challenges[j]) + 5
  184.       y = -54 + j
  185.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  186.     end
  187.   end
  188.   if pageNum == 6 then
  189.     button.clearTable()
  190.     for i = 71, 84 do
  191.       button.label(2, -68+i, i..") ")
  192.     end
  193.     for j = 71, 84 do
  194.       if challenges[j] == nil then
  195.         challenges[j] = ""
  196.       end
  197.       x1 = 6
  198.       x2 = string.len(challenges[j]) + 5
  199.       y = -68 + j
  200.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  201.     end
  202.   end
  203.   if pageNum == 7 then
  204.     button.clearTable()
  205.     for i = 85, 98 do
  206.       button.label(2, -82+i, i..") ")
  207.     end
  208.     for j = 85, 98 do
  209.       if challenges[j] == nil then
  210.         challenges[j] = ""
  211.       end
  212.       x1 = 6
  213.       x2 = string.len(challenges[j]) + 5
  214.       y = -82 + j
  215.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  216.     end
  217.   end
  218.   if pageNum == 8 then
  219.     button.clearTable()
  220.     for i = 99, 112 do
  221.       button.label(2, -96+i, i..") ")
  222.     end
  223.     for j = 99, 112 do
  224.       if challenges[j] == nil then
  225.         challenges[j] = ""
  226.       end
  227.       if j <= 99 then
  228.         x1 = 6
  229.         x2 = string.len(challenges[j]) + 5
  230.       end
  231.       if j >= 100 then
  232.         x1 = 7
  233.         x2 = string.len(challenges[j]) + 6
  234.       end
  235.       y = -96 + j
  236.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  237.     end
  238.   end
  239.   if pageNum == 9 then
  240.     button.clearTable()
  241.     for i = 113, 126 do
  242.       button.label(2, -110+i, i..") ")
  243.     end
  244.     for j = 113, 126 do
  245.       if challenges[j] == nil then
  246.         challenges[j] = ""
  247.       end
  248.       x1 = 7
  249.       x2 = string.len(challenges[j]) + 6
  250.       y = -110 + j
  251.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  252.     end
  253.   end
  254.   if pageNum == 10 then
  255.     button.clearTable()
  256.     for i = 127, 140 do
  257.       button.label(2, -124+i, i..") ")
  258.     end
  259.     for j = 127, 140 do
  260.       if challenges[j] == nil then
  261.         challenges[j] = ""
  262.       end
  263.       x1 = 7
  264.       x2 = string.len(challenges[j]) + 6
  265.       y = -124 + j
  266.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  267.     end
  268.   end
  269.   if pageNum == 11 then
  270.     button.clearTable()
  271.     for i = 141, 154 do
  272.       button.label(2, -138+i, i..") ")
  273.     end
  274.     for j = 141, 154 do
  275.       if challenges[j] == nil then
  276.         challenges[j] = ""
  277.       end
  278.       x1 = 7
  279.       x2 = string.len(challenges[j]) + 6
  280.       y = -138 + j
  281.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  282.     end
  283.   end
  284.   if pageNum == 12 then
  285.     button.clearTable()
  286.     for i = 155, 168 do
  287.       button.label(2, -152+i, i..") ")
  288.     end
  289.     for j = 155, 168 do
  290.       if challenges[j] == nil then
  291.         challenges[j] = ""
  292.       end
  293.       x1 = 7
  294.       x2 = string.len(challenges[j]) + 6
  295.       y = -152 + j
  296.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  297.     end
  298.   end
  299.   if pageNum == 13 then
  300.     button.clearTable()
  301.     for i = 169, 182 do
  302.       button.label(2, -166+i, i..") ")
  303.     end
  304.     for j = 169, 182 do
  305.       if challenges[j] == nil then
  306.         challenges[j] = ""
  307.       end
  308.       x1 = 7
  309.       x2 = string.len(challenges[j]) + 6
  310.       y = -166 + j
  311.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  312.     end
  313.   end
  314.   if pageNum == 14 then
  315.     button.clearTable()
  316.     for i = 183, 196 do
  317.       button.label(2, -180+i, i..") ")
  318.     end
  319.     for j = 183, 196 do
  320.       if challenges[j] == nil then
  321.         challenges[j] = ""
  322.       end
  323.       x1 = 7
  324.       x2 = string.len(challenges[j]) + 6
  325.       y = -180 + j
  326.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  327.     end
  328.   end
  329.   if pageNum == 15 then
  330.     button.clearTable()
  331.     for i = 197, 210 do
  332.       button.label(2, -194+i, i..") ")
  333.     end
  334.     for j = 197, 210 do
  335.       if challenges[j] == nil then
  336.         challenges[j] = ""
  337.       end
  338.       x1 = 7
  339.       x2 = string.len(challenges[j]) + 6
  340.       y = -194 + j
  341.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  342.     end
  343.   end
  344.   if pageNum == 16 then
  345.     button.clearTable()
  346.     for i = 211, 224 do
  347.       button.label(2, -208+i, i..") ")
  348.     end
  349.     for j = 211, 224 do
  350.       if challenges[j] == nil then
  351.         challenges[j] = ""
  352.       end
  353.       x1 = 7
  354.       x2 = string.len(challenges[j]) + 6
  355.       y = -208 + j
  356.       button.setTable(challenges[j], completeChallenge, completedChallenges[j], "", x1, x2, y, y)
  357.     end
  358.   end
  359.   button.label(15, 19, "Page "..pageNum.." of "..pages)
  360.   setupButtons()
  361. end
  362.  
  363. function setupRules()
  364.   if rulesEnabled == true then
  365.     button.setTable("Rules", displayRules, false, 32, 39, 1, 1)
  366.   else if notifyEnabled == true then
  367.     print("Rules button not enabled! Enable it within the program")
  368.   end
  369.   end
  370.   for line in rule:lines() do
  371.     numRules = numRules + 1
  372.     rules[numRules] = line
  373.   end
  374. end
  375.  
  376. function displayRules()
  377.   mon.clear()
  378.   button.clearTable()
  379.   button.heading("Rules:")
  380.   button.setTable(header, setupPages, false, "", 39-string.len(header), 39, 1, 1)
  381.   for i = 1,numRules do
  382.     button.label(2, 2+i, i..") ")
  383.   end
  384.   for i = 1,numRules do
  385.     button.label(5, 2+i, rules[i])
  386.   end
  387.   button.screen()
  388. end
  389.  
  390. function checkChallenges()
  391.   for line in chal:lines() do
  392.     numChallenges = numChallenges + 1
  393.     challenges[numChallenges] = line
  394.   end
  395.   file = fs.open(completedFile, "r")
  396.   for i = 1,224 do
  397.     completedChallenges[i] = file.readLine()
  398.   end
  399. end
  400.  
  401. function completeChallenge()
  402.   for i = 1,14 do --page 1
  403.     if i <= 9 then
  404.       if x >= 5 and x <= string.len(challenges[i]) + 4 and y == 2 + i then
  405.         completedChallenges[i] = true
  406.       end
  407.     end
  408.     if i > 9 then
  409.       if x >= 6 and x <= string.len(challenges[i]) + 5 and y == 2 + i then
  410.         completedChallenges[i] = true
  411.       end
  412.     end
  413.   end
  414.   for i = 15,28 do --page 2
  415.     if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -12 + i then
  416.       completedChallenges[i] = true
  417.     end
  418.   end
  419.   for i = 29,42 do --page 3
  420.     if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -26 + i then
  421.       completedChallenges[i] = true
  422.     end
  423.   end
  424.   for i = 43,56 do --page 4
  425.     if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -40 + i then
  426.       completedChallenges[i] = true
  427.     end
  428.   end
  429.   for i = 57, 70 do --page 5
  430.     if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -54 + i then
  431.       completedChallenges[i] = true
  432.     end
  433.   end
  434.   for i = 71, 84 do --page 6
  435.     if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -68 + i then
  436.       completedChallenges[i] = true
  437.     end
  438.   end
  439.   for i = 85, 98 do --page 7
  440.     if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -82 + i then
  441.       completedChallenges[i] = true
  442.     end
  443.   end
  444.   for i = 99, 112 do --page 8
  445.     if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -96 + i then
  446.       completedChallenges[i] = true
  447.     end
  448.   end
  449.   for i = 113, 126 do --page 9
  450.     if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -110 + i then
  451.       completedChallenges[i] = true
  452.     end
  453.   end
  454.   for i = 127, 140 do --page 10
  455.     if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -124 + i then
  456.       completedChallenges[i] = true
  457.     end
  458.   end
  459.   for i = 141, 154 do --page 11
  460.     if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -138 + i then
  461.       completedChallenges[i] = true
  462.     end
  463.   end
  464.   for i = 155, 168 do --page 12
  465.     if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -152 + i then
  466.       completedChallenges[i] = true
  467.     end
  468.   end
  469.   for i = 169, 182 do --page 13
  470.     if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -166 + i then
  471.       completedChallenges[i] = true
  472.     end
  473.   end
  474.   for i = 183, 196 do --page 14
  475.     if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -180 + i then
  476.       completedChallenges[i] = true
  477.     end
  478.   end
  479.   for i = 197, 210 do --page 15
  480.     if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -194 + i then
  481.       completedChallenges[i] = true
  482.     end
  483.   end
  484.   for i = 211, 224 do --page 16
  485.     if x >= 6 and x <= string.len(challenges[i]) + 5 and y == -208 + i then
  486.       completedChallenges[i] = true
  487.     end
  488.   end
  489.   setupPages()
  490.   file = fs.open(completedFile, "w")
  491.   for name, chal in ipairs(completedChallenges) do
  492.     file.writeLine(tostring(chal))
  493.   end
  494.   file.close()
  495. end
  496.  
  497. function convertCompletedChallenges()
  498.     for i = 1,numChallenges do
  499.       if completedChallenges[i] == "true" then
  500.         completedChallenges[i] = true
  501.       else if completedChallenges[i] == "false" then
  502.         completedChallenges[i] = false
  503.       end
  504.       end
  505.     end
  506. end
  507.  
  508. function nextPage()
  509.   if pageNum + 1 <= pages then
  510.     pageNum = pageNum + 1
  511.   end
  512.   setupPages()
  513.   button.flash("Next")
  514. end
  515.  
  516. function prevPage()
  517.   if pageNum - 1 >= 1 then
  518.     pageNum = pageNum - 1
  519.   end
  520.     setupPages()
  521.     button.flash("Prev")
  522. end
  523.  
  524. function checkpress()
  525.   event, side, x, y = os.pullEventRaw("monitor_touch")
  526.   button.checkxy(x,y)
  527. end
  528.  
  529. APILoader("button","S8x0K3ui")
  530. checkFilesExist()
  531. autoSync()
  532. checkChallenges()
  533. convertCompletedChallenges()
  534. heading()
  535. setupPages()
  536.  
  537. while true do
  538.   checkpress()
  539. end
Advertisement
Add Comment
Please, Sign In to add comment