Advertisement
Shaka01

turtleControl_PocketComputer

May 4th, 2023
892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.10 KB | None | 0 0
  1. if not fs.exists("API") then
  2.     shell.run("pastebin", "get", "EzkfU5ZM", "API")
  3. end
  4. if not fs.exists("basalt.lua") then
  5.     shell.run("wget", "run", "http://basalt.madefor.cc/install.lua", "packed")
  6.     -- shell.run("pastebin", "run", "ESs1mg7P")
  7.     -- wget run http://basalt.madefor.cc/install.lua packed
  8.     -- pastebin run ESs1mg7P
  9. end
  10.  
  11. basalt = require("basalt")
  12. shaka = require("API")
  13. term.setCursorBlink(false)
  14. startLocation = true
  15.  
  16. local turtleSides = {"Front", "Back", "Top", "Bottom", "Left", "Right"}
  17.  
  18.  
  19. turtleID = 43 -- remove this !!!!!!!!!!!
  20.  
  21.  
  22. local function findTransporter()
  23.     shaka.clearScreen()
  24.     local main = basalt.createFrame()
  25.     shaka.changeColors(colors.black, colors.yellow)
  26.     print("Waiting for connection..")
  27.     local id, msg = rednet.receive("transporterPing")
  28.     if id then
  29.         turtleID = id
  30.         rednet.send(id, "you're not alone", "transporterAnswer")
  31.     end
  32. end
  33.  
  34. -- Function to send movement orders via Rednet
  35. local function sendMovementOrder(orderName)
  36.     rednet.send(turtleID, orderName, "recordRemote")  -- Send the order via Rednet
  37. end
  38.  
  39. local function recordInventory()
  40.     local direction = nil
  41.     local dropDirection = nil
  42.     local turtleCommand = nil
  43.     local selectedItem = nil
  44.     local itemSelection = 0
  45.     local amount = nil
  46.     shaka.changeColors(colors.black, colors.white)
  47.     term.clear()
  48.     term.setCursorPos(1, 1)
  49.     shaka.changeColors(colors.gray, colors.yellow)
  50.     term.clearLine()
  51.     shaka.centerText("Drop or take items?", 1)
  52.     shaka.changeColors(colors.black, colors.white)
  53.     shaka.nextLine()
  54.     shaka.nextLine()
  55.     local savedX, savedY = term.getCursorPos()
  56.     print("1. Drop")
  57.     print("2. Take")
  58.  
  59.     while true do
  60.         local event, answer = os.pullEvent("key")
  61.         os.pullEvent("key_up")
  62.         if answer == keys.one then
  63.             term.setCursorPos(1, 1)
  64.             shaka.changeColors(colors.gray, colors.yellow)
  65.             term.clearLine()
  66.             shaka.centerText("Choose drop mode")
  67.             shaka.changeColors(colors.black, colors.white)
  68.             term.setCursorPos(savedX, savedY)
  69.             term.clearLine()
  70.             print("1. Drop all items")
  71.             print("2. Filter dropped items")
  72.             while true do
  73.                 local event, dropAnswer = os.pullEvent("key")
  74.                 os.pullEvent("key_up")
  75.                 if dropAnswer == keys.one then
  76.                     direction = "drop"
  77.                     break
  78.                 elseif dropAnswer == keys.two then
  79.                     direction = "dropFiltered"
  80.                     break
  81.                 end
  82.             end
  83.             shaka.clearScreen()
  84.             shaka.changeColors(colors.gray, colors.yellow)
  85.             term.clearLine()
  86.             shaka.centerText("Drop items where?")
  87.             shaka.changeColors(colors.black, colors.white)
  88.             term.setCursorPos(savedX, savedY)
  89.             break
  90.         elseif answer == keys.two then
  91.             shaka.clearScreen()
  92.             shaka.changeColors(colors.gray, colors.yellow)
  93.             term.clearLine()
  94.             shaka.centerText("Take from where?")
  95.             shaka.nextLine()
  96.             shaka.nextLine()
  97.             shaka.changeColors(colors.black, colors.white)
  98.             direction = "suck"
  99.             break
  100.         end
  101.     end
  102.  
  103.  
  104.     local _, frontY = term.getCursorPos()
  105.     print("1. Front")
  106.     local _, upY = term.getCursorPos()
  107.     print("2. Up")
  108.     local _, downY = term.getCursorPos()
  109.     print("3. Down")
  110.    
  111.     while true do
  112.    
  113.         local event, dropDirection, isHeld = os.pullEvent("key")
  114.         os.pullEvent("key_up")
  115.         if dropDirection == keys.one then
  116.             turtleCommand = "front"
  117.             local x, y = term.getCursorPos()
  118.             term.setCursorPos(1, frontY)
  119.             term.clearLine()
  120.             shaka.changeColors(colors.green, colors.black)
  121.             print("1. Front")
  122.             term.setCursorPos(x, y)
  123.             break
  124.         elseif dropDirection == keys.two then
  125.             turtleCommand = "up"
  126.             local x, y = term.getCursorPos()
  127.             term.setCursorPos(1, upY)
  128.             term.clearLine()
  129.             shaka.changeColors(colors.green, colors.black)
  130.             print("2. Up")
  131.             term.setCursorPos(x, y)
  132.             break
  133.         elseif dropDirection == keys.three then
  134.             turtleCommand = "down"
  135.             local x, y = term.getCursorPos()
  136.             term.setCursorPos(1, downY)
  137.             term.clearLine()
  138.             shaka.changeColors(colors.green, colors.black)
  139.             print("3. Down")
  140.             term.setCursorPos(x, y)
  141.             break
  142.         end
  143.        
  144.     end
  145.    
  146.     if direction == "dropFiltered" then
  147.         repeat
  148.             shaka.clearScreen()
  149.             shaka.changeColors(colors.gray, colors.yellow)
  150.             term.clearLine()
  151.             shaka.centerText("Which item?")
  152.             shaka.nextLine()
  153.             shaka.nextLine()
  154.             shaka.changeColors(colors.black, colors.white)
  155.             sendMovementOrder("showAvailable")
  156.             sender, msg = rednet.receive("showAvailableItems", 2)
  157.             if msg then
  158.                 msg = textutils.unserialize(msg)
  159.                 if msg[1] ~= nil then
  160.                     for k, v in pairs(msg) do
  161.                         print(k..". "..v)
  162.                     end
  163.                 else
  164.                     print("Place item into turtle inventory and hit enter.")
  165.                 end
  166.             else
  167.                 shaka.changeColors(colors.red, colors.black)
  168.                 print("Lost connection! Restarting.")
  169.                 sleep(2)
  170.                 os.reboot()
  171.             end
  172.             shaka.nextLine()
  173.             local x, y = term.getCursorPos()
  174.             local maxX, maxY = term.getSize()
  175.             term.setCursorPos(1, maxY - 3)
  176.             shaka.changeColors(colors.black, colors.gray)
  177.             print("Enter without entry to refresh turtle inventory")
  178.             term.setCursorPos(x, y)
  179.             shaka.changeColors(colors.black, colors.white)
  180.             itemSelection = tonumber(read())
  181.         until itemSelection ~= nil
  182.         for k, v in pairs(msg) do
  183.             if itemSelection == k then
  184.                 selectedItem = v
  185.             end
  186.         end
  187.     end
  188.    
  189.     if direction ~= "drop" then
  190.         shaka.changeColors(colors.gray, colors.yellow)
  191.         shaka.nextLine()
  192.         term.clearLine()
  193.         shaka.centerText("Amount?")
  194.         shaka.nextLine()
  195.         shaka.changeColors(colors.black, colors.white)
  196.         print("No entry for as many as possible\n")
  197.        
  198.         amount = read()
  199.     end
  200.    
  201.     if amount == nil or amount == "" then
  202.         amount = "all"
  203.     end
  204.    
  205.     if selectedItem == nil then
  206.         selectedItem = "nada"
  207.     end
  208.    
  209.     if turtleCommand then
  210.     shaka.changeColors(colors.gray, colors.green)
  211.     print("\nSaved!")
  212.     sleep(1)
  213.     end
  214.     sendMovementOrder(direction.." "..turtleCommand.." "..amount.." "..selectedItem)
  215. end
  216.  
  217. local function switchRedstone()
  218.     local dir = nil
  219.     local state = nil
  220.     local pulseTime = 0
  221.     term.clear()
  222.     term.setCursorPos(1,1)
  223.     shaka.changeColors(colors.gray, colors.yellow)
  224.     term.clearLine()
  225.    
  226.     shaka.centerText("Change rs on which side?")
  227.     shaka.changeColors(colors.black, colors.white)
  228.     shaka.nextLine()
  229.     shaka.nextLine()
  230.         print("  ^   Front - W")
  231.         print("<   > Left/Right - A/D")
  232.         print("  v   Back - S\n")
  233.         print("Space: Top")
  234.         print("Shift: Bottom\n")
  235.     while true do
  236.         local event, selection = os.pullEvent("key")
  237.         os.pullEvent("key_up")
  238.         if selection == keys.space then
  239.             dir = "top"
  240.             break
  241.         elseif selection == keys.leftShift then
  242.             dir = "bottom"
  243.             break
  244.         elseif selection == keys.a then
  245.             dir = "left"
  246.             break
  247.         elseif selection == keys.d then
  248.             dir = "right"
  249.             break
  250.         elseif selection == keys.w then
  251.             dir = "front"
  252.             break
  253.         elseif selection == keys.s then
  254.             dir = "back"
  255.             break
  256.         end
  257.     end
  258.     shaka.changeColors(colors.black, colors.green)
  259.     print("Selected:", dir)
  260.     shaka.nextLine()
  261.     shaka.changeColors(colors.gray, colors.yellow)
  262.     term.clearLine()
  263.     print("Operation?\n")
  264.     shaka.changeColors(colors.black, colors.white)
  265.     local x, y = term.getCursorPos()
  266.     print("1. On")
  267.     print("2. Off")
  268.     print("3. Pulse on -> off")
  269.     shaka.changeColors(colors.black, colors.yellow)
  270.     while true do
  271.         local event, selection = os.pullEvent("key")
  272.         os.pullEvent("key_up")
  273.         if selection == keys.one then
  274.             state = "on"
  275.             break
  276.         elseif selection == keys.two then
  277.             state = "off"
  278.             break
  279.         elseif selection == keys.three then
  280.             state = "pulse"
  281.             for i = 0, 3 do
  282.             term.setCursorPos(x, y + i)
  283.             term.clearLine()
  284.             end
  285.             term.setCursorPos(x, y)
  286.             shaka.changeColors(colors.black, colors.white)
  287.             print("Pulse for how long?\n")
  288.             pulseTime = read()
  289.             break
  290.         end
  291.     end
  292.     print("Selected:", state)
  293.     sendMovementOrder("redstone " ..dir.. " " ..state.." "..pulseTime)
  294.     sleep(1)
  295. end
  296.  
  297. local function addSleep()
  298.     shaka.clearScreen()
  299.     shaka.changeColors(colors.black, colors.yellow)
  300.     print("How many seconds?\n")
  301.     sleep(0.3)
  302.     local sleepTime = read()
  303.     sendMovementOrder("sleep " ..sleepTime)
  304.     print("\nSuccess!")
  305.     sleep(1)
  306. end
  307.  
  308. local function genericMenu(title, optionsTable, listBoolean, keepScreenBoolean)
  309.     local selection = nil
  310.     local dir = nil
  311.     if keepScreenBoolean ~= true then
  312.         shaka.clearScreen()
  313.     else
  314.         shaka.nextLine()
  315.         shaka.nextLine()
  316.     end
  317.     shaka.changeColors(colors.gray, colors.yellow)
  318.     term.clearLine()
  319.     shaka.centerText(title)
  320.     local xPos, yPos = term.getCursorPos()
  321.     term.setCursorPos(1, yPos + 2)
  322.     if listBoolean then
  323.         shaka.changeColors(colors.black, colors.white)
  324.         for i = 1, #optionsTable do
  325.             print(i..") "..optionsTable[i])
  326.         end
  327.         while true do
  328.             local event, choice = os.pullEvent("key")
  329.             os.pullEvent("key_up")
  330.             if choice == keys.one then
  331.                 selection = 1
  332.                 break
  333.             elseif choice == keys.two then
  334.                 selection = 2
  335.                 break
  336.             elseif choice == keys.three then
  337.                 selection = 3
  338.                 break
  339.             elseif choice == keys.four then
  340.                 selection = 4
  341.                 break
  342.             elseif choice == keys.five then
  343.                 selection = 5
  344.                 break
  345.             elseif choice == keys.six then
  346.                 selection = 6
  347.                 break
  348.             end
  349.         end
  350.         term.setCursorPos(1, selection + yPos + 1)
  351.         shaka.changeColors(colors.green, colors.yellow)
  352.         if optionsTable[selection] then
  353.         print(selection..") " ..optionsTable[selection])
  354.         end
  355.     else
  356.         shaka.changeColors(colors.black, colors.white)
  357.         print("  ^   Front - W")
  358.         print("<   > Left/Right - A/D")
  359.         print("  v   Back - S\n")
  360.         print("Space: Top")
  361.         print("Shift: Bottom\n")
  362.         while true do
  363.             event, selection = os.pullEvent("key")
  364.             os.pullEvent("key_up")
  365.             if selection == keys.space then
  366.                 selection = "top"
  367.                 break
  368.             elseif selection == keys.leftShift then
  369.                 selection = "bottom"
  370.                 break
  371.             elseif selection == keys.a then
  372.                 selection = "left"
  373.                 break
  374.             elseif selection == keys.d then
  375.                 selection = "right"
  376.                 break
  377.             elseif selection == keys.w then
  378.                 selection = "front"
  379.                 break
  380.             elseif selection == keys.s then
  381.                 selection = "back"
  382.                 break
  383.             end
  384.         end
  385.         shaka.changeColors(colors.black, colors.green)
  386.         print("Selected:", selection)
  387.     end
  388.     sleep(0.5)
  389.     return selection or nil
  390. end
  391.  
  392. local function redstoneTrigger()
  393.     local chosenSide = genericMenu("Wait for RS on which side?", turtleSides)
  394.     local state = genericMenu("Trigger when on or off?", {"on", "off"}, true)
  395.     sendMovementOrder("redstoneTrigger "..chosenSide.." "..state) --side string, state number[1=on, 2=off]
  396.     -- print("redstoneTrigger "..chosenSide.." "..state)
  397.     -- sleep(3)
  398. end
  399.  
  400. local function betterMenu(tableName, menuTitle)
  401.     local selection = nil
  402.     local xterm, yterm = term.getSize()
  403.     local main = basalt.createFrame()
  404.     local confirmButton = main:addButton()
  405.     local list = main:addList()
  406.     local label = main:addButton()
  407.     local divider = main:addPane()
  408.    
  409.     main
  410.     :setBackground(colors.black)
  411.     :show()
  412.    
  413.     local x, y = main:getSize()
  414.  
  415.     for k, v in pairs(tableName) do
  416.         list:addItem(v)
  417.     end
  418.    
  419.    
  420.     local function showStuff()
  421.         local index = list:getItemIndex()
  422.         local name = list:getItem(index).text
  423.         confirmButton:setText(name)
  424.         return name
  425.     end
  426.    
  427.     local function finalSelect()
  428.         confirmButton:setBackground(colors.green)
  429.         main:hide()
  430.         term.clear()
  431.         term.setCursorPos(1,1)
  432.         selection = showStuff()
  433.         basalt.stop()
  434.         print(selection)
  435.         return selection
  436.     end
  437.    
  438.     local function keyControl(self, event, key)
  439.         key = keys.getName(key)
  440.         local pos = list:getItemIndex()
  441.         if key == "up" then
  442.             if pos == 1 then
  443.                 return false
  444.             else
  445.                 list:selectItem(pos - 1)
  446.             end
  447.         elseif key == "down" then
  448.             if pos == list:getItemCount() then
  449.                 return
  450.             else
  451.                 list:selectItem(pos + 1)
  452.             end
  453.         elseif key == "enter" then
  454.             finalSelect()
  455.         end
  456.         showStuff()
  457.     end
  458.  
  459.     label
  460.         :setPosition(1, 1)
  461.         :setSize(x, 1)
  462.         :setText(menuTitle)
  463.         :setBackground(colors.green)
  464.         :setForeground(colors.black)
  465.    
  466.     divider
  467.         :setPosition(1, 2)
  468.         :setSize(x, 1)
  469.         :setBackground(colors.gray)
  470.    
  471.     confirmButton
  472.         :setPosition(1, y)
  473.         :setSize(x, 1)
  474.         :setBackground(colors.lightGray)
  475.         :setText("Click selection")
  476.         :onClick(finalSelect)
  477.        
  478.    
  479.     list
  480.         :setSize(x, y - 3)
  481.         :setBackground(colors.gray)
  482.         :setPosition(1, 3)
  483.         :show()
  484.         :setFocus()
  485.         :onClickUp(showStuff)
  486.         :setScrollable(true)
  487.         :onKey(keyControl)
  488.         :setSelectionColor(colors.black, colors.lime)
  489. end
  490.  
  491. local function blockTrigger()
  492.     local sideTable = {"front", "up", "down"}
  493.     local chosenSide = genericMenu("Block on which side?", sideTable, true)
  494.     chosenSide = sideTable[chosenSide]
  495.     sendMovementOrder("blockInformation "..chosenSide)
  496.     local sender, msg = rednet.receive("blockAnswer")
  497.     local item = betterMenu(msg, "Please choose data:")
  498.  
  499.     if item then
  500.         sendMovementOrder("blockTrigger " ..chosenSide.." ".. item)
  501.     else
  502.         print("nope")
  503.         sleep(3)
  504.     end
  505. end
  506.  
  507. function getLimiter(bool)
  508.     local aboveOrBelow = nil
  509.     if bool then
  510.         aboveOrBelow = genericMenu("Trigger above or below?", {"Above", "Below"}, true, false)
  511.     else
  512.         aboveOrBelow = genericMenu("Trigger above or below?", {"Above", "Below"}, true, true)
  513.     end
  514.     if aboveOrBelow == 1 then
  515.         aboveOrBelow = "above"
  516.     elseif aboveOrBelow == 2 then
  517.         aboveOrBelow = "below"
  518.     end
  519.     return aboveOrBelow
  520. end
  521.        
  522. local function inventoryTrigger()
  523.     local chosenSide = genericMenu("Inventory on which side?")
  524.     local inventoryAction = genericMenu("Which inventory trigger?", {"Count of specific item", "Total fill percentage"}, true, true)
  525.     sendMovementOrder("displayExternal")
  526.     local sender = rednet.receive("sideQuestion")
  527.     rednet.send(sender, chosenSide, "sideAnswer")
  528.    
  529.     if tonumber(inventoryAction) == 1 then
  530.         local sender, itemTable = rednet.receive("items_Available")
  531.         itemTable = textutils.unserialize(itemTable)
  532.         local prettyTable = {}
  533.         for k, v in pairs(itemTable) do
  534.             prettyTable[k] = shaka.prettyName(itemTable[k])
  535.         end
  536.         shaka.clearScreen()
  537.         local chosenItem = genericMenu("Which item?", prettyTable, true)
  538.         limiter = getLimiter()
  539.         shaka.nextLine()
  540.         shaka.changeColors(colors.gray, colors.yellow)
  541.         term.clearLine()
  542.         print("Item count to trigger on?")
  543.         shaka.changeColors(colors.black, colors.white)
  544.         shaka.nextLine()
  545.         local countAnswer = tonumber(read())
  546.         shaka.clearScreen()
  547.         shaka.changeColors(colors.black, colors.green)
  548.         print("Success!")
  549.         shaka.changeColors(colors.black, colors.white)
  550.         print("\nSide:", chosenSide)
  551.         print("\nItem:", itemTable[chosenItem])
  552.         print("\nTrigger: "..limiter.." "..countAnswer)
  553.         sendMovementOrder("inventoryTrigger " ..chosenSide.. " " ..itemTable[chosenItem].." "..limiter.." "..countAnswer)
  554.        
  555.         shaka.changeColors(colors.black, colors.gray)
  556.         print("\nPress any key to continue..")
  557.         os.pullEvent("key")
  558.     else
  559.         shaka.clearScreen()
  560.         limiter = getLimiter(true)
  561.         shaka.nextLine()
  562.         shaka.nextLine()
  563.         shaka.changeColors(colors.gray, colors.yellow)
  564.         term.clearLine()
  565.         print("Which percentage?")
  566.         local percentage = read()
  567.         print("inventoryTrigger " ..chosenSide.. " fillPercent "..limiter.." "..percentage)
  568.         sendMovementOrder("inventoryTrigger " ..chosenSide.. " fillPercent "..limiter.." "..percentage)
  569.     end
  570. end
  571.  
  572. local function triggerMenu()
  573.     shaka.clearScreen()
  574.     local options = {"Redstone", "Block", "Inventory"}
  575.     shaka.changeColors(colors.gray, colors.yellow)
  576.     term.clearLine()
  577.     shaka.centerText("Trigger on which event?\n")
  578.     term.setCursorPos(1, 3)
  579.     local startY = 3
  580.     shaka.changeColors(colors.black, colors.white)
  581.  
  582.   -- display the menu options
  583.   for i=1,#options do
  584.     print(i..") "..options[i])
  585.   end
  586.  
  587.   shaka.nextLine()
  588.   -- get user input
  589.   local a, b = term.getCursorPos()
  590.   term.write("Select an option")
  591.   while true do
  592.     local event, choice = os.pullEvent("key")
  593.     os.pullEvent("key_up")
  594.     if choice == keys.one then
  595.         term.setCursorPos(1, startY)
  596.         shaka.changeColors(colors.green, colors.yellow)
  597.         term.clearLine()
  598.         print("1) " ..options[1])
  599.         term.setCursorPos(a, b)
  600.         shaka.changeColors(colors.black, colors.green)
  601.         term.clearLine()
  602.         print("Selected "..options[1])
  603.         sleep(1)
  604.         redstoneTrigger()
  605.         return choice
  606.     elseif choice == keys.two then
  607.         term.setCursorPos(1, startY + 1)
  608.         shaka.changeColors(colors.green, colors.yellow)
  609.         term.clearLine()
  610.         print("2) " ..options[2])
  611.         term.setCursorPos(a, b)
  612.         shaka.changeColors(colors.black, colors.green)
  613.         term.clearLine()
  614.         print("Selected "..options[2])
  615.         sleep(1)
  616.         blockTrigger()
  617.         return choice
  618.     elseif choice == keys.three then
  619.         term.setCursorPos(1, startY + 2)
  620.         shaka.changeColors(colors.green, colors.yellow)
  621.         term.clearLine()
  622.         print("3) " ..options[3])
  623.         term.setCursorPos(a, b)
  624.         shaka.changeColors(colors.black, colors.green)
  625.         term.clearLine()
  626.         print("Selected "..options[3])
  627.         sleep(1)
  628.         inventoryTrigger()
  629.         return choice
  630.     end
  631.     term.setCursorPos(a, b + 2)
  632.     term.write("Invalid option. Try again.")
  633.     sleep(1)
  634.     term.clearLine()
  635.   end
  636. end
  637.  
  638. local function main()
  639.     shaka.clearScreen()
  640.     -- Display movement options
  641.     shaka.changeColors(colors.gray, colors.black)
  642.     term.clearLine()
  643.  
  644.     -- Display title
  645.    
  646.     print("Turtle Movement Options:\n")
  647.     shaka.changeColors(colors.black, colors.green)
  648.     -- Display movement options with arrows
  649.     print("  ^   Forward - W")
  650.     print("<   > Left/Right - A/D")
  651.     print("  v   Backward - S\n")
  652.     print("Space: Up")
  653.     print("Shift: Down\n")
  654.  
  655.     -- Display other options
  656.     shaka.changeColors(colors.black, colors.yellow)
  657.     print("I    Inventory Action")
  658.     print("R    Redstone Action")
  659.     print("F    Sleep Action")
  660.     print("T    Wait for Trigger\n")
  661.     term.setTextColor(colors.orange)
  662.     print("Q    Undo last move")
  663.     _, XLoc = term.getCursorPos()
  664.     term.clearLine()
  665.     print("X    Finish recording\n")
  666.  
  667.     while true do
  668.         -- Get user input
  669.         local event, key = os.pullEvent("key")
  670.         if key == keys.w then
  671.                 sendMovementOrder("forward")
  672.             elseif key == keys.a then
  673.                 sendMovementOrder("left")
  674.             elseif key == keys.s then
  675.                 sendMovementOrder("back")
  676.             elseif key == keys.d then
  677.                 sendMovementOrder("right")
  678.             elseif key == keys.space then
  679.                 sendMovementOrder("up")
  680.             elseif key == keys.leftShift then
  681.                 sendMovementOrder("down")
  682.             elseif key == keys.i then
  683.                 recordInventory()
  684.                 main()
  685.                 break
  686.             elseif key == keys.x then
  687.                 sendMovementOrder("allDone")
  688.                 local sender, msg = rednet.receive("remoteEnd")
  689.                 if msg == "yep" then
  690.                     shaka.clearScreen()
  691.                     textutils.slowPrint("Finished recording..")
  692.                     sleep(1)
  693.                     break
  694.                 elseif msg == "nope" then
  695.                     rednet.send(sender, "y", "remoteEnd")
  696.                     local turtle_id, reply = rednet.receive("arrivedAtStart")
  697.                     local x, y = term.getCursorPos()
  698.                     term.setCursorPos(1, XLoc)
  699.                     term.clearLine()
  700.                     shaka.changeColors(colors.black, colors.orange)
  701.                     print("X    Finish recording\n")
  702.                     term.setCursorPos(x, y)
  703.                 end
  704.             elseif key == keys.q then
  705.                 sendMovementOrder("delete")
  706.                 sender, msg = rednet.receive("instructionDeleteConfirm", 2)
  707.                 shaka.changeColors(colors.black, colors.red)
  708.                 if msg then
  709.                     local x, y = term.getCursorPos()
  710.                     local _, maxY = term.getSize()
  711.                     term.setCursorPos(1, maxY - 1)
  712.                     term.clearLine()
  713.                     if msg == "start" then
  714.                         term.write("Back at start")
  715.                     else
  716.                         term.write("Deleted: "..msg)
  717.                     end
  718.                     sleep(1)
  719.                     term.clearLine()
  720.                     term.setCursorPos(x, y)
  721.                 else
  722.                     print("Failure")
  723.                 end
  724.             elseif key == keys.r then
  725.                 switchRedstone()
  726.                 main()
  727.                 break
  728.             elseif key == keys.f then
  729.                 addSleep()
  730.                 main()
  731.                 break
  732.             elseif key == keys.t then
  733.                 triggerMenu()
  734.                 main()
  735.                 break
  736.         end
  737.     end
  738. end
  739.  
  740. local function positionUpdate()
  741.     while true do
  742.         local sender, msg = rednet.receive("positionUpdate")
  743.         if msg == "start" then
  744.             local x, y = term.getCursorPos()
  745.             term.setCursorPos(1, XLoc)
  746.             term.clearLine()
  747.             shaka.changeColors(colors.black, colors.orange)
  748.             print("X    Finish recording\n")
  749.             term.setCursorPos(x, y)
  750.         else
  751.             local x, y = term.getCursorPos()
  752.             term.setCursorPos(1, XLoc)
  753.             term.clearLine()
  754.             shaka.changeColors(colors.black, colors.orange)
  755.             print("X    Go to start\n")
  756.             term.setCursorPos(x, y)
  757.         end
  758.     end
  759. end
  760.  
  761. -- local function turtleControls()
  762.     -- local normalBG = colors.green
  763.     -- local clickedBG = colors.yellow
  764.     -- local main = basalt.createFrame()
  765.     -- local joypad = main:addFrame()
  766.         -- :setBackground(colors.black)
  767.         -- :setSize(5, 3)
  768.         -- :setPosition(4, 3)
  769.         -- :setFocus()
  770.         -- :setBorder(colors.blue)
  771.        
  772.     -- local arrows = {buttonForward, buttonBack, buttonLeft, buttonRight}
  773.     -- local function forward()
  774.         -- sendMovementOrder("forward")
  775.     -- end
  776.    
  777.     -- local function back()
  778.         -- sendMovementOrder("back")
  779.     -- end
  780.    
  781.    
  782.     -- local arrowButtons = {
  783.         -- joypad:addButton():setText("^")
  784.         -- :setPosition(3, 1)
  785.         -- :onClick(forward)
  786.         -- :onKey(keyColorPressed)
  787.         -- :onKeyUp(keyColorNormal)
  788.         -- ,
  789.         -- joypad:addButton():setText("v")
  790.         -- :setPosition(3, 3)
  791.         -- :onClick(back)
  792.         -- ,
  793.         -- joypad:addButton():setText("<")
  794.         -- :setPosition(1, 2)
  795.         -- ,
  796.         -- joypad:addButton():setText(">")
  797.         -- :setPosition(5, 2)
  798.     -- }
  799.    
  800.     -- local function keyColorNormal(self, event, key)
  801.             -- basalt.debug("up")
  802.             -- for k, v in pairs(arrowButtons) do
  803.                 -- v:setBackground(normalBG)
  804.             -- end
  805.             -- arrowButtons[1]:setBackground(normalBG)
  806.     -- end
  807.    
  808.     -- local function keyColorPressed(self, event, key)
  809.         -- if (key == keys.w) then
  810.             -- basalt.debug("yo")
  811.             -- arrowButtons[1]:setBackground(clickedBG)
  812.         -- elseif key == keys.a then
  813.             -- arrowButtons[3]:setBackground(clickedBG)
  814.         -- elseif key == keys.s then
  815.             -- arrowButtons[2]:setBackground(clickedBG)
  816.         -- elseif key == keys.d then
  817.             -- arrowButtons[4]:setBackground(clickedBG)
  818.         -- end
  819.     -- end 
  820.     -- joypad
  821.     -- :onKey(keyColorPressed)
  822.     -- :onKeyUp(keyColorNormal)
  823.    
  824.     -- for k, v in pairs(arrowButtons) do
  825.         -- local function normalColor()
  826.             -- v:setBackground(normalBG)
  827.         -- end
  828.         -- normalColor()
  829.         -- local function clickColor()
  830.             -- v:setBackground(clickedBG)
  831.             -- basalt.debug("Button "..k)
  832.         -- end
  833.         -- v:setSize(1,1)
  834.         -- v:onClick(clickColor)
  835.         -- v:onRelease(normalColor)
  836.     -- end 
  837.    
  838. -- end
  839.  
  840.  
  841.  
  842. -- turtleControls()
  843.  
  844.  
  845. local args = { ... }
  846.  
  847. if args[1] == "1" then
  848.     blockTrigger()
  849. else
  850. findTransporter()
  851.  
  852. -- while true do
  853. parallel.waitForAny(main, positionUpdate)
  854. end
  855. -- end
  856. -- main()
  857. -- print(triggerMenu())
  858. -- os.reboot()
  859. basalt.autoUpdate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement