Пример #1
0
    def generate_songlist(self, recordkeys, game):
        i = 1
        for name, diff, mods in self.course.songs:
            if "*" in name: name, subtitle = "??????????", ""
            elif name[0] == _("BEST"):
                song = recordkeys.get(records.best(name[1], diff, game))
                if song:
                    subtitle = (song.info["subtitle"]
                                or "") + (_(" (Best #%d)") % name[1])
                    name = song.info["title"]
                else:
                    name = _("Player's Best Unavailable")
                    subtitle = _("(You need to play more songs!)")

            elif name[0] == _("WORST"):
                song = recordkeys.get(records.worst(name[1], diff, game))
                if song:
                    subtitle = (song.info["subtitle"]
                                or "") + (_(" (Worst #%d)") % name[1])
                    name = song.info["title"]
                else:
                    name = _("Player's Worst Unavailable")
                    subtitle = _("(You need to play more songs!)")

            elif name[0] == _("LIKES"):
                song = recordkeys.get(records.like(name[1], diff, game))
                if song:
                    subtitle = (song.info["subtitle"]
                                or "") + (" (Likes #%d)" % name[1])
                    name = song.info["title"]
                else:
                    name = _("Player's Likes Unavailable")
                    subtitle = _("(You need to play more songs!)")

            elif name[0] == _("DISLIKES"):
                song = recordkeys.get(records.dislike(name[1], diff, game))
                if song:
                    subtitle = ((song.info["subtitle"] or "") +
                                (_(" (Dislikes #%d)") % name[1]))
                    name = song.info["title"]
                else:
                    name = _("Player's Dislikes Unavailable")
                    subtitle = _("(You need to play more songs!)")

            else:
                name, subtitle = util.find_subtitle(name.split("/")[-1])

            if "." in diff: diff = "?"

            name = ("%d. " % i) + name
            self._songs.append([name, subtitle, diff])
            i += 1
Пример #2
0
  def generate_songlist(self, recordkeys, game):
    i = 1
    for name, diff, mods in self.course.songs:
      if "*" in name: name, subtitle = "??????????", ""
      elif name[0] == _("BEST"):
        song = recordkeys.get(records.best(name[1], diff, game))
        if song:
          subtitle = (song.info["subtitle"] or "") + (_(" (Best #%d)") % name[1])
          name = song.info["title"]
        else:
          name = _("Player's Best Unavailable")
          subtitle = _("(You need to play more songs!)")

      elif name[0] == _("WORST"):
        song = recordkeys.get(records.worst(name[1], diff, game))
        if song:
          subtitle = (song.info["subtitle"] or "") + (_(" (Worst #%d)") % name[1])
          name = song.info["title"]
        else:
          name = _("Player's Worst Unavailable")
          subtitle = _("(You need to play more songs!)")

      elif name[0] == _("LIKES"):
        song = recordkeys.get(records.like(name[1], diff, game))
        if song:
          subtitle = (song.info["subtitle"] or "") + (" (Likes #%d)" % name[1])
          name = song.info["title"]
        else:
          name = _("Player's Likes Unavailable")
          subtitle = _("(You need to play more songs!)")

      elif name[0] == _("DISLIKES"):
        song = recordkeys.get(records.dislike(name[1], diff, game))
        if song:
          subtitle = ((song.info["subtitle"] or "") +
                      (_(" (Dislikes #%d)") % name[1]))
          name = song.info["title"]
        else:
          name = _("Player's Dislikes Unavailable")
          subtitle = _("(You need to play more songs!)")

      else: name, subtitle = util.find_subtitle(name.split("/")[-1])

      if "." in diff: diff = "?"

      name = ("%d. " % i) + name
      self._songs.append([name, subtitle, diff])
      i += 1
Пример #3
0
  def next(self):
    # We're done.
    if self.index == len(self.songs): raise StopIteration
    name, diff, mods = self.songs[self.index]
    fullname = None

    a, b = 0, 0
    if isinstance(diff, list): pass
    elif diff.find("..") != -1: a, b = map(int, diff.split(".."))
    elif len(diff) < 3: a, b = int(diff), int(diff)
    if a or b: diff = range(a, b + 1)

    # Check for player's best/worst/likes/dislikes. There are stored
    # as a tuple of (type, number).
    if name[0] == _("BEST"):
      s = self.recordkeys.get(records.best(name[1], diff, self.gametype), None)
      if s:
        fullname = s.filename
        if isinstance(diff, list):
          diff = [d for d in diff if d in s.difficulty[self.gametype]][0]
    elif name[0] == _("WORST"):
      s = self.recordkeys.get(records.worst(name[1], diff, self.gametype),None)
      if s:
        fullname = s.filename
        if isinstance(diff, list):
          diff = [d for d in diff if d in s.difficulty[self.gametype]][0]
    elif name[0] == _("LIKES"):
      s = self.recordkeys.get(records.like(name[1], diff, self.gametype),None)
      if s:
        fullname = s.filename
        if isinstance(diff, list):
          diff = [d for d in diff if d in s.difficulty[self.gametype]][0]
    elif name[0] == _("DISLIKES"):
      s = self.recordkeys.get(records.dislike(name[1], diff, self.gametype),None)
      if s:
        fullname = s.filename
        if isinstance(diff, list):
          diff = [d for d in diff if d in s.difficulty[self.gametype]][0]
          
    elif name[-1] == "*": # A random song
      # First pull out all the songs that we might be acceptable.
      if "/" in name:
        # Random song from a specific mix.
        folder, dummy = name.split("/")
        folder = folder.lower()
        if folder in self.all_songs:
          songs = [s for s in self.all_songs[folder].values() if (s,diff) not in self.past_songs]
        else:
          error.ErrorMessage(self.screen, folder + _(" was not found."))
          raise StopIteration

      else:
        # Any random song.
        songs = []
        for v in self.all_songs.values(): songs.extend(v.values())

      songs = [s for s in songs if (s,diff) not in self.past_songs and self._find_difficulty(s, diff)]

      if len(songs) == 0:
        error.ErrorMessage(self.screen, _("No valid songs were found."))
        raise StopIteration
      else:
        song = random.choice(songs)
        diff = self._find_difficulty(song, diff)
        fullname = song.filename

    # Let's try to find the damned song.
    # Unfortunately, it can be given as just a title(+subtitle), or a
    # mix with a title. Or a filename. That's why we need the
    # all_songs hash.
    else:
      for path in mainconfig["songdir"].split(os.pathsep):
        fn = os.path.join(path, name)
        fn = os.path.expanduser(fn)
        if os.path.isfile(fn): fullname = fn
        elif os.path.isdir(fn):
          file_list = util.find(fn, ["*.sm", "*.dwi"])
          if len(file_list) != 0: fullname = file_list[0]
        if fullname: break

    if not fullname and len(name[0]) == 1: # Still haven't found it...
      folder, song = name.split("/")
      song = self.all_songs.get(folder.lower(), {}).get(song.lower())
      if song: fullname = song.filename

    if not fullname:
      if len(name[0]) > 1:
        name = _("Player's %s #%d") % (name[0].capitalize(), name[1])
      error.ErrorMessage(self.screen, name + _("was not found."))
      raise StopIteration

    self.index += 1
    self.past_songs.append((fullname,diff))
    return (fullname, [diff] * len(self.player_configs))
Пример #4
0
    def __next__(self):
        # We're done.
        if self.index == len(self.songs): raise StopIteration
        name, diff, mods = self.songs[self.index]
        fullname = None

        a, b = 0, 0
        if isinstance(diff, list): pass
        elif diff.find("..") != -1: a, b = list(map(int, diff.split("..")))
        elif len(diff) < 3: a, b = int(diff), int(diff)
        if a or b: diff = list(range(a, b + 1))

        # Check for player's best/worst/likes/dislikes. There are stored
        # as a tuple of (type, number).
        if name[0] == _("BEST"):
            s = self.recordkeys.get(records.best(name[1], diff, self.gametype),
                                    None)
            if s:
                fullname = s.filename
                if isinstance(diff, list):
                    diff = [
                        d for d in diff if d in s.difficulty[self.gametype]
                    ][0]
        elif name[0] == _("WORST"):
            s = self.recordkeys.get(
                records.worst(name[1], diff, self.gametype), None)
            if s:
                fullname = s.filename
                if isinstance(diff, list):
                    diff = [
                        d for d in diff if d in s.difficulty[self.gametype]
                    ][0]
        elif name[0] == _("LIKES"):
            s = self.recordkeys.get(records.like(name[1], diff, self.gametype),
                                    None)
            if s:
                fullname = s.filename
                if isinstance(diff, list):
                    diff = [
                        d for d in diff if d in s.difficulty[self.gametype]
                    ][0]
        elif name[0] == _("DISLIKES"):
            s = self.recordkeys.get(
                records.dislike(name[1], diff, self.gametype), None)
            if s:
                fullname = s.filename
                if isinstance(diff, list):
                    diff = [
                        d for d in diff if d in s.difficulty[self.gametype]
                    ][0]

        elif name[-1] == "*":  # A random song
            # First pull out all the songs that we might be acceptable.
            if "/" in name:
                # Random song from a specific mix.
                folder, dummy = name.split("/")
                folder = folder.lower()
                if folder in self.all_songs:
                    songs = [
                        s for s in list(self.all_songs[folder].values())
                        if (s, diff) not in self.past_songs
                    ]
                else:
                    error.ErrorMessage(self.screen,
                                       folder + _(" was not found."))
                    raise StopIteration

            else:
                # Any random song.
                songs = []
                for v in list(self.all_songs.values()):
                    songs.extend(list(v.values()))

            songs = [
                s for s in songs if (s, diff) not in self.past_songs
                and self._find_difficulty(s, diff)
            ]

            if len(songs) == 0:
                error.ErrorMessage(self.screen,
                                   _("No valid songs were found."))
                raise StopIteration
            else:
                song = random.choice(songs)
                diff = self._find_difficulty(song, diff)
                fullname = song.filename

        # Let's try to find the damned song.
        # Unfortunately, it can be given as just a title(+subtitle), or a
        # mix with a title. Or a filename. That's why we need the
        # all_songs hash.
        else:
            for path in mainconfig["songdir"].split(os.pathsep):
                fn = os.path.join(path, name)
                fn = os.path.expanduser(fn)
                if os.path.isfile(fn): fullname = fn
                elif os.path.isdir(fn):
                    file_list = util.find(fn, ["*.sm", "*.dwi"], 1)
                    if len(file_list) != 0: fullname = file_list[0]
                if fullname: break

        if not fullname and len(name[0]) == 1:  # Still haven't found it...
            folder, song = name.split("/")
            song = self.all_songs.get(folder.lower(), {}).get(song.lower())
            if song: fullname = song.filename

        if not fullname:
            if len(name[0]) > 1:
                name = _("Player's %s #%d") % (name[0].capitalize(), name[1])
            error.ErrorMessage(self.screen, name + _("was not found."))
            raise StopIteration

        self.index += 1
        self.past_songs.append((fullname, diff))
        return (fullname, [diff] * len(self.player_configs))