From: Christian Heller Date: Mon, 7 Dec 2020 02:48:42 +0000 (+0100) Subject: Overhaul MusicPlayer code. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/bar%20baz.html?a=commitdiff_plain;h=1b0d4f5fef925f2f7811fd32be1c773ab813c49e;p=plomrogue2 Overhaul MusicPlayer code. --- diff --git a/plomrogue/things.py b/plomrogue/things.py index 720adc0..c49b204 100644 --- a/plomrogue/things.py +++ b/plomrogue/things.py @@ -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,7 +218,7 @@ 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: @@ -225,7 +226,7 @@ class Thing_MusicPlayer(Thing): else: return ['paused'] 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']