le_Fish

cowFarmButtonComputer

Aug 2nd, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.52 KB | None | 0 0
  1. if fs.exists("touchpoint") then
  2.     os.loadAPI("touchpoint")
  3. else
  4.     shell.run("pastebin", "get", "pFHeia96>", "touchpoint>")
  5.     os.loadAPI("touchpoint")
  6. end
  7.  
  8. if not os.getComputerLabel() then
  9.     write "Set a label for this computer: "
  10.     os.setComputerLabel(read())
  11. end
  12.  
  13. local t = touchpoint.new("left")
  14. local disabled = false
  15. local f1, f2, f3, f4 = true, true, true, true
  16. local level_name = ""
  17.  
  18. if fs.exists("buttonSetter") then
  19.     rednet.open("top")
  20.     print("A crash occured")
  21.     print("Reading home position")
  22.     local h = fs.open("buttonSetter", "r")
  23.     f1 = h.readLine() == "true"
  24.     f2 = h.readLine() == "true"
  25.     f3 = h.readLine() == "true"
  26.     f4 = h.readLine() == "true"
  27.     disabled = h.readLine() == "true"
  28.     level_name = tonumber(h.readLine())
  29.     h.close()
  30.  
  31.     if (disabled == true) then
  32.         t:add("Disabled", nil, 20, 2, 29, 4, colors.lightGray, colors.lightBlue)
  33.         t:add("Farm 1", nil, 1, 2, 8, 4, colors.red, colors.lime)
  34.         t:add("Farm 2", nil, 10, 2, 18, 4, colors.red, colors.lime)
  35.         t:add("Farm 3", nil, 1, 6, 8, 8, colors.red, colors.lime)
  36.         t:add("Farm 4", nil, 10, 6, 18, 8, colors.red, colors.lime)
  37.         rs.setOutput("front", false)
  38.         rs.setOutput("right", false)
  39.         rs.setOutput("back", false)
  40.         rs.setOutput("bottom", false)
  41.     else
  42.         if (f1 == true) then
  43.             t:add("Farm 1", nil, 1, 2, 8, 4, colors.lime, colors.red)
  44.         else
  45.             t:add("Farm 1", nil, 1, 2, 8, 4, colors.red, colors.lime)
  46.         end
  47.         if (f2 == true) then
  48.             t:add("Farm 2", nil, 10, 2, 18, 4, colors.lime, colors.red)
  49.         else
  50.             t:add("Farm 2", nil, 10, 2, 18, 4, colors.red, colors.lime)
  51.         end
  52.         if (f3 == true) then
  53.             t:add("Farm 3", nil, 1, 6, 8, 8, colors.lime, colors.red)
  54.         else
  55.             t:add("Farm 3", nil, 1, 6, 8, 8, colors.red, colors.lime)
  56.         end
  57.         if (f4 == true) then
  58.             t:add("Farm 4", nil, 10, 6, 18, 8, colors.lime, colors.red)
  59.         else
  60.             t:add("Farm 4", nil, 10, 6, 18, 8, colors.red, colors.lime)
  61.         end
  62.         t:add("Enabled", nil, 20, 2, 29, 4, colors.lightGray, colors.lightBlue)
  63.         rs.setOutput("front", f1)
  64.         rs.setOutput("right", f2)
  65.         rs.setOutput("back", f3)
  66.         rs.setOutput("bottom", f4)
  67.     end
  68. else
  69.     if fs.exists("startup") then
  70.         fs.delete("startup")
  71.         local h = fs.open("startup", "w")
  72.         h.writeLine("sleep(1)")
  73.         h.writeLine("shell.run('" .. shell.getRunningProgram() .. "')")
  74.         h.close()
  75.     else
  76.         local h = fs.open("startup", "w")
  77.         h.writeLine("sleep(1)")
  78.         h.writeLine("shell.run('" .. shell.getRunningProgram() .. "')")
  79.         h.close()
  80.     end
  81.  
  82.     term.write("Fill nivau of the farm: ")
  83.     level_name = tonumber(read())
  84.     print(" ")
  85.  
  86.     local h = fs.open("buttonSetter", "w")
  87.     h.writeLine(f1) --front (f1)
  88.     h.writeLine(f2) --right (f2)
  89.     h.writeLine(f3) --back (f3)
  90.     h.writeLine(f4) --bottom (f4)
  91.     h.writeLine(disabled) --disabled
  92.     h.writeLine(level_name)
  93.     h.close()
  94.  
  95.     rs.setOutput("front", true)
  96.     rs.setOutput("right", true)
  97.     rs.setOutput("back", true)
  98.     rs.setOutput("bottom", true)
  99.  
  100.     t:add("Farm 1", nil, 1, 2, 8, 4, colors.lime, colors.red)
  101.     t:add("Farm 2", nil, 10, 2, 18, 4, colors.lime, colors.red)
  102.     t:add("Farm 3", nil, 1, 6, 8, 8, colors.lime, colors.red)
  103.     t:add("Farm 4", nil, 10, 6, 18, 8, colors.lime, colors.red)
  104.  
  105.     t:add("Enabled", nil, 20, 2, 29, 4, colors.lightGray, colors.lightBlue)
  106. end
  107.  
  108. local labelTable = {
  109.     "Level: " .. tostring(level_name),
  110.     label = "level_name"
  111. }
  112. t:add(labelTable, nil, 1, 11, 18, 12, colors.lightGray, colors.lightBlue)
  113.  
  114. t:draw()
  115.  
  116. function saveButtons()
  117.     local h = fs.open("buttonSetter", "w")
  118.     h.writeLine(f1) --bottom (f1)
  119.     h.writeLine(f2) --right (f2)
  120.     h.writeLine(f3) --back (f3)
  121.     h.writeLine(f4) --front (f4)
  122.     h.writeLine(disabled) --disabled
  123.     h.writeLine(level_name)
  124.     h.close()
  125. end
  126.  
  127. while true do
  128.     local event, p1, p2, p3 = t:handleEvents(os.pullEvent())
  129.     if event == "button_click" then
  130.         if (p1 == "Farm 1") and (disabled == false) then
  131.             t:toggleButton(p1)
  132.             rs.setOutput("front", not rs.getOutput("front"))
  133.             f1 = rs.getOutput("front")
  134.         elseif (p1 == "Farm 2") and (disabled == false) then
  135.             t:toggleButton(p1)
  136.             rs.setOutput("right", not rs.getOutput("right"))
  137.             f2 = rs.getOutput("right")
  138.         elseif (p1 == "Farm 3") and (disabled == false) then
  139.             t:toggleButton(p1)
  140.             rs.setOutput("back", not rs.getOutput("back"))
  141.             f3 = rs.getOutput("back")
  142.         elseif (p1 == "Farm 4") and (disabled == false) then
  143.             t:toggleButton(p1)
  144.             rs.setOutput("bottom", not rs.getOutput("bottom"))
  145.             f4 = rs.getOutput("bottom")
  146.         elseif (p1 == "Disabled") then
  147.             t:flash(p1)
  148.             t:rename("Disabled", "Enabled")
  149.             disabled = false
  150.             if (f1 == true) then
  151.                 rs.setOutput("front", true)
  152.                 t:toggleButton("Farm 1")
  153.             end
  154.             if (f2 == true) then
  155.                 rs.setOutput("right", true)
  156.                 t:toggleButton("Farm 2")
  157.             end
  158.             if (f3 == true) then
  159.                 rs.setOutput("back", true)
  160.                 t:toggleButton("Farm 3")
  161.             end
  162.             if (f4 == true) then
  163.                 rs.setOutput("bottom", true)
  164.                 t:toggleButton("Farm 4")
  165.             end
  166.         elseif (p1 == "Enabled") then
  167.             t:flash(p1)
  168.             t:rename("Enabled", "Disabled")
  169.             disabled = true
  170.             if (f1 == true) then
  171.                 t:toggleButton("Farm 1")
  172.             end
  173.             if (f2 == true) then
  174.                 t:toggleButton("Farm 2")
  175.             end
  176.             if (f3 == true) then
  177.                 t:toggleButton("Farm 3")
  178.             end
  179.             if (f4 == true) then
  180.                 t:toggleButton("Farm 4")
  181.             end
  182.             rs.setOutput("front", false)
  183.             rs.setOutput("right", false)
  184.             rs.setOutput("back", false)
  185.             rs.setOutput("bottom", false)
  186.         end
  187.         saveButtons()
  188.     elseif p2 ~= nil then
  189.         if (string.find(p2, level_name) and string.find(p2, "enable") and disabled == true) then
  190.             t:rename("Disabled", "Enabled")
  191.             disabled = false
  192.             rs.setOutput("front", true)
  193.             t:toggleButton("Farm 1")
  194.             rs.setOutput("right", true)
  195.             t:toggleButton("Farm 2")
  196.             rs.setOutput("back", true)
  197.             t:toggleButton("Farm 3")
  198.             rs.setOutput("bottom", true)
  199.             t:toggleButton("Farm 4")
  200.         elseif (string.find(p2, level_name) and string.find(p2, "disable") and disabled == false) then
  201.             t:rename("Enabled", "Disabled")
  202.             disabled = true
  203.             if (f1 == true) then
  204.                 t:toggleButton("Farm 1")
  205.             end
  206.             if (f2 == true) then
  207.                 t:toggleButton("Farm 2")
  208.             end
  209.             if (f3 == true) then
  210.                 t:toggleButton("Farm 3")
  211.             end
  212.             if (f4 == true) then
  213.                 t:toggleButton("Farm 4")
  214.             end
  215.             rs.setOutput("front", false)
  216.             rs.setOutput("right", false)
  217.             rs.setOutput("back", false)
  218.             rs.setOutput("bottom", false)
  219.         end
  220.     end
  221. end
Add Comment
Please, Sign In to add comment