home · contact · privacy
Add song deletion to MusicPlayer.
[plomrogue2] / plomrogue / things.py
index 720adc0ec64f0c432ec0f8e9ecbb3d5ecb29a413..31820541a7ad46a51a76b8a07bf2f412d3b39267 100644 (file)
@@ -170,7 +170,7 @@ class Thing_MusicPlayer(Thing):
     portable = True
     repeat = True
     next_song_start = datetime.datetime.now()
-    playlist_index = 0
+    playlist_index = -1
     playing = True
 
     def __init__(self, *args, **kwargs):
@@ -182,12 +182,13 @@ class Thing_MusicPlayer(Thing):
         if (not self.playing) or len(self.playlist) == 0:
             return
         if datetime.datetime.now() > self.next_song_start:
-            song_data = self.playlist[self.playlist_index]
             self.playlist_index += 1
             if self.playlist_index == len(self.playlist):
                 self.playlist_index = 0
                 if not self.repeat:
                     self.playing = False
+                    return
+            song_data = self.playlist[self.playlist_index]
             self.next_song_start = datetime.datetime.now() +\
                 datetime.timedelta(seconds=song_data[1])
             self.sound('MUSICPLAYER', song_data[0])
@@ -198,7 +199,7 @@ class Thing_MusicPlayer(Thing):
         if command == 'HELP':
             msg_lines += ['available commands:']
             msg_lines += ['HELP – show this help']
-            msg_lines += ['PLAY – toggle playback on/off']
+            msg_lines += ['ON/OFF – toggle playback on/off']
             msg_lines += ['REWIND – return to start of playlist']
             msg_lines += ['LIST – list programmed songs, durations']
             msg_lines += ['SKIP – to skip to next song']
@@ -217,15 +218,23 @@ class Thing_MusicPlayer(Thing):
                 msg_lines += ['%s %s:%s – %s' % (selector, minutes, seconds, entry[0])]
                 i += 1
             return msg_lines
-        elif command == 'PLAY':
+        elif command == 'ON/OFF':
             self.playing = False if self.playing else True
             self.game.changed = True
             if self.playing:
                 return ['playing']
             else:
                 return ['paused']
+        elif command == 'REMOVE':
+            if len(self.playlist) == 0:
+                return ['playlist already empty']
+            del self.playlist[max(0, self.playlist_index)]
+            self.playlist_index -= 1
+            if self.playlist_index < -1:
+                self.playlist_index = -1
+            return ['removed song']
         elif command == 'REWIND':
-            self.playlist_index = 0
+            self.playlist_index = -1
             self.next_song_start = datetime.datetime.now()
             self.game.changed = True
             return ['back at start of playlist']