JackMacWindows

diskclick.lua

Sep 24th, 2020 (edited)
899
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local speaker = peripheral.find "speaker"
  2. if not speaker then printError("No speaker attached") return end
  3. local oldFS = fs
  4. local lastfile = nil
  5. local clicksRemaining = 0
  6.  
  7. _G.fs = {
  8.     isDriveRoot = fs.isDriveRoot,
  9.     combine = fs.combine,
  10.     complete = fs.complete,
  11.     getDir = fs.getDir,
  12.     getName = fs.getName,
  13.     getCapacity = fs.getCapacity,
  14.     getDrive = fs.getDrive
  15. }
  16.  
  17. local function click(n)
  18.     clicksRemaining = math.min(clicksRemaining + n, 10)
  19. end
  20.  
  21. local function fn(name, n)
  22.     _G.fs[name] = function(path, ...)
  23.         if lastfile ~= path then
  24.             click(n)
  25.             lastfile = path
  26.         end
  27.         return oldFS[name](path, ...)
  28.     end
  29. end
  30.  
  31. fn("attributes", 1)
  32. fn("isReadOnly", 1)
  33. fn("move", 2)
  34. fn("getSize", 1)
  35. fn("getFreeSpace", 1)
  36. fn("makeDir", 1)
  37. fn("list", 3)
  38. fn("isDir", 1)
  39. fn("exists", 1)
  40. fn("delete", 1)
  41. fn("open", 2)
  42.  
  43. function _G.fs.copy(src, dest)
  44.     click(math.min(math.ceil(oldFS.getSize(src) / 4096), 8))
  45.     lastfile = nil
  46.     return oldFS.copy(src, dest)
  47. end
  48.  
  49. function _G.fs.find(wildcard)
  50.     click(select("#", wildcard:match("(%*)")))
  51.     lastfile = nil
  52.     return oldFS.find(wildcard)
  53. end
  54.  
  55. if turtle then
  56.     local oldTurtle = turtle
  57.     _G.turtle = setmetatable({}, {__index = oldTurtle})
  58.     local function wrap(name)
  59.         _G.turtle[name] = function()
  60.             speaker.playNote("snare", 1, 0)
  61.             return oldTurtle[name]()
  62.         end
  63.     end
  64.     wrap "forward"
  65.     wrap "back"
  66.     wrap "up"
  67.     wrap "down"
  68.     wrap "turnLeft"
  69.     wrap "turnRight"
  70. end
  71.  
  72. speaker.playNote("bit", 1, 24)
  73.  
  74. parallel.waitForAny(function()
  75.     while true do
  76.         if clicksRemaining > 0 then
  77.             speaker.playNote("hat", 0.5, 18)
  78.             clicksRemaining = clicksRemaining - 1
  79.         end
  80.         sleep(0.025)
  81.     end
  82. end, function() shell.run("shell") end)
RAW Paste Data