Advertisement
guitarplayer616

CookBackup2

May 26th, 2015
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.89 KB | None | 0 0
  1. local tArgs = { ... }
  2. local events = {}
  3. local exist = true
  4. local record = false
  5. local tab = {}
  6. local fa1 = 0
  7. if #tArgs < 1 then
  8.   print("Usage: cook <recipe>")
  9.   return
  10. end
  11. function cookwrite(string,x,y,txtcol,bakcol)
  12.   if txtcol then
  13.     term.setTextColor(txtcol)
  14.   end
  15.   if bakcol then
  16.     term.setBackgroundColor(bakcol)
  17.   end
  18.   if x and y then
  19.     term.setCursorPos(x, y)
  20.   end
  21.   write(string)
  22.   term.setTextColor(colors.white)
  23.   term.setBackgroundColor(colors.black)
  24. end
  25. local w,h = term.getSize()
  26. term.setBackgroundColor(colors.black)
  27. term.clear()
  28. term.setCursorPos(1,1)
  29.  
  30. function drawCentered(str,height)
  31.   term.setCursorPos((w/2-(#str/2)),height)
  32.   print(str)
  33. end
  34.  
  35. fs.makeDir("RecipeList/"..tArgs[1])
  36.  
  37. --[[if fs.isDir("RecipeList/"..tArgs[1]) then
  38.   term.setTextColor(colors.red)
  39.   textutils.slowPrint("Recipe Already Exists")
  40.   term.setTextColor(colors.white)
  41.   error()
  42. else]]--
  43. fs.makeDir("RecipeList/"..tArgs[1])
  44. --end
  45.  
  46.  
  47.  
  48.  
  49. --[[local input = read()
  50. if string.lower(input) == "craft" then
  51.   print("Please put crafting recipe in turtle inventory")
  52.   textutils.slowPrint("Press any key to continue...")
  53.   read()
  54. else
  55.   print("fail")
  56.   return
  57. end]]--
  58.  
  59. local craftingGrid = {1,2,3,5,6,7,9,10,11}
  60.  
  61. function run()
  62.   while true do
  63.     drawCentered("Recipe: "..tArgs[1],1)
  64.     print(string.rep("-",w))
  65.     print("  Step 1 - Craft or Smelt?")
  66.     if not record and exist then
  67.       cookwrite("+",2,4)
  68.     elseif record and exist then
  69.       cookwrite(" ",2,4)
  70.       cookwrite("+",2,5)
  71.     else
  72.       cookwrite(" ",2,4)
  73.       cookwrite(" ",2,5)
  74.     end
  75.     events = {os.pullEvent()}
  76.  
  77.     if events[1] == "mouse_click" and events[3] > 11 and events[3] < 17 and events[4] == 3 then
  78.       cookwrite(" Record \n",4,4,colors.white,colors.red)
  79.       record = true
  80.     end
  81.  
  82.     if record and events[1] == "mouse_click" and events[2] == 1 and events[3] > 3 and events[3] < 10 and events[4] == 4 then
  83.       cookwrite(" Record \n",4,4,colors.white,colors.green)
  84.       for i,v in ipairs(craftingGrid) do
  85.         turtle.select(v)
  86.         local data = turtle.getItemDetail()
  87.         if data then
  88.           tab[v] = data.name
  89.         end
  90.       end
  91.       fa1 = fs.open("RecipeList/"..tArgs[1].."/path1","a")
  92.       fa1.write(textutils.serialize(tab))
  93.       fa1.close()
  94.       cookwrite(" Record \n",4,4,colors.white,colors.red)
  95.     end
  96.  
  97.     if record and events[1] == "mouse_click" and events[2] == 2 and events[3] > 3 and events[3] < 10 and events[4] == 4 then
  98.       cookwrite(" Record \n",4,4,colors.white,colors.red)
  99.     end
  100.  
  101.     if record and events[1] == "mouse_click" and events[2] == 1 and events[3] == 2 and (events[4] == 5 or events[4] == 4) then
  102.       cookwrite("Step 2 - Craft or Smelt?",3,6)
  103.       exist = false
  104.     end  
  105.  
  106.     if events[1] == "mouse_click" and events[3] > 11 and events[3] < 17 and events[4] == 6 then
  107.       cookwrite(" Record \n",4,7,colors.white,colors.red)
  108.       record2 = true
  109.     end
  110.  
  111.     if record2 and events[1] == "mouse_click" and events[2] == 1 and events[3] > 3 and events[3] < 10 and events[4] == 7 then
  112.       cookwrite(" Record \n",4,7,colors.white,colors.green)
  113.       for i,v in ipairs(craftingGrid) do
  114.         turtle.select(v)
  115.         local data = turtle.getItemDetail()
  116.         if data then
  117.           tab[i] = data.name
  118.         end
  119.       end
  120.       local fa2 = fs.open("RecipeList/"..tArgs[1].."/path2","a")
  121.       fa2.write(textutils.serialize(tab))
  122.       fa2.close()
  123.       cookwrite(" Record \n",4,7,colors.white,colors.red)
  124.     end
  125.  
  126.     if record and events[1] == "mouse_click" and events[2] == 2 and events[3] > 3 and events[3] < 10 and events[4] == 7 then
  127.       cookwrite(" Record \n",4,7,colors.white,colors.red)
  128.     end
  129.     local cdx,cdy = term.getCursorPos()
  130.     term.setCursorPos(1,h-#events)
  131.     for i=1,#events do
  132.       print(events[i].."        ")
  133.     end
  134.     term.setCursorPos(cdx,cdy)
  135.   end
  136. end
  137. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement