Advertisement
demon012

ComputerCraft Jukebox

Jul 18th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.90 KB | None | 0 0
  1. -- Todo
  2. -- - Finish writing and testing jukebox!
  3. -- my libraries
  4. -- check dir exists, if not make it
  5. if not fs.exists("/libs") then--{{{
  6.     fs.makeDir("/libs")
  7. end--}}}
  8.  
  9. function update_lib(pastebin_id, dest_path)--{{{
  10.     if fs.exists(dest_path) then
  11.         fs.delete(dest_path)
  12.     end
  13.     shell.run("pastebin get " .. pastebin_id  .. " " .. dest_path)
  14.     os.loadAPI(dest_path)
  15. end--}}}
  16.  
  17. --update_lib("qUpykFN4", "libs/ccmisc")
  18. --update_lib("n1S2GpfD", "libs/sorterAPI")
  19. os.loadAPI("/libs/sorterAPI")
  20.  
  21. -- clear library spam
  22. --term.setCursorPos(1,1)
  23. --term.clear()
  24. -- end my libraries
  25.  
  26. Track = {
  27.     title = nil,
  28.     length = nil,
  29.     uuid = nil,
  30. }
  31.  
  32. Jukebox = {
  33.     sorter = peripheral.wrap("interactiveSorter_1"),
  34.     drive = peripheral.wrap("drive_0"),
  35.     chestSide = 1,
  36.     driveSide = 0,
  37.     tracks = {},
  38.     tracksName = {},
  39.     tracksUUID = {},
  40. }
  41.  
  42. function Jukebox:getTracksAvailable()
  43.     local chestTracks = self.sorter.list(self.chestSide)
  44.     local driveTracks = self.sorter.list(self.driveSide)
  45.  
  46.     print(textutils.serialize(chestTracks))
  47.  
  48.     --for uuid,count in pairs(chestTracks) do
  49.     --    if tracksUUID[uuid] = nil then
  50.     --        local track = Track
  51.     --        track.uuid = uuid
  52.     --        -- find track name
  53.     --        track.name =
  54.     --        --
  55.  
  56.     --        tracksUUID[uuid] = track
  57.     --    end
  58.     --end
  59. end
  60.  
  61. function Jukebox:identifyTrack(uuid)
  62. end
  63.  
  64. function Jukebox:findTrackLength(uuid)
  65.     -- load the track
  66.     -- set 1 second timer and play the track
  67.     -- if trackTime event then is track still playing?
  68.     -- if true then increment track length by 1 second and start another 1 second timer.
  69.     -- else don't start a new timer and stop finding track length.
  70. end
  71.  
  72. function Jukebox:loadDisk(wanted_uuid)
  73.     if self.drive.isDiskPresent() then
  74.         -- remove disk
  75.         for uuid, count in pairs(self.sorter.list(self.driveSide)) do
  76.             self.sorter.extract(self.driveSide, uuid, self.chestSide, count)
  77.         end
  78.     end
  79.  
  80.     -- load requested disk
  81.     self.sorter.extract(self.chestSide, wanted_uuid, self.driveSide, 1)
  82. end
  83.  
  84. function Jukebox:playing()
  85.     -- is the jukebox playing something?
  86.     return self.playing
  87. end
  88.  
  89. function Jukebox:play(track)
  90.     if track == nil then
  91.         self:randomTrack()
  92.     end
  93.  
  94.     if self.drive.isDiskPresent() then
  95.         if self.drive.hasAudio() then
  96.             self.drive.playAudio()
  97.         end
  98.     end
  99.  
  100.  
  101.     self.playing = true
  102. end
  103.  
  104. function Jukebox:randomTrack()
  105. end
  106.  
  107. function Jukebox:stop()
  108.     self.drive.stopAudio()
  109. end
  110.  
  111. function Jukebox:nextTrack()
  112. end
  113.  
  114. function Jukebox:previousTrack()
  115. end
  116.  
  117. function Jukebox:currentTrack()
  118.     if self.drive.isDiskPresent() and self.drive.hasAudio() then
  119.         return self.drive.getAudioTitle()
  120.     else
  121.         return nil
  122.     end
  123. end
  124.  
  125. --jukebox = Jukebox
  126. --jukebox:getTracksAvailable()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement