Beispiel #1
0
def main():
  print "pydance", VERSION, "<*****@*****.**> - irc.freenode.net/#pyddr"

  if mainconfig["usepsyco"]:
    try:
      import psyco
      print _("Psyco optimizing compiler found. Using psyco.full().")
      psyco.full()
    except ImportError: print _("W: Psyco optimizing compiler not found.")

  # default settings for play_and_quit.
  mode = "SINGLE"
  difficulty = "BASIC"
  test_file = None
  for opt, arg in getopt(sys.argv[1:],
                         "hvf:d:m:", ["help", "version", "filename=",
                                      "difficulty=", "mode="])[0]:
    if opt in ["-h", _("--help")]: print_help()
    elif opt in ["-v", _("--version")]: print_version()
    elif opt in ["-f", _("--filename")]: test_file = arg
    elif opt in ["-m", _("--mode")]: mode = arg
    elif opt in ["-d", _("--difficulty")]: difficulty = arg

  if test_file: play_and_quit(test_file, mode, difficulty)

  song_list = {}
  course_list = []
  for dir in mainconfig["songdir"].split(os.pathsep):
    print _("Searching for songs in"), dir
    song_list.update(util.find_songs(dir, ['*.dance', '*.sm', '*.dwi', '*/song.*']))
  for dir in mainconfig["coursedir"].split(os.pathsep):
    print _("Searching for courses in"), dir
    course_list.extend(util.find(dir, ['*.crs']))

  screen = set_display_mode()
  
  pygame.display.set_caption("pydance " + VERSION)
  pygame.mouse.set_visible(False)
  try:
    if os.path.exists("/usr/share/pixmaps/pydance.png"):
      icon = pygame.image.load("/usr/share/pixmaps/pydance.png")
    else: icon = pygame.image.load(os.path.join(pydance_path, "icon.png"))
    pygame.display.set_icon(icon)
  except: pass

  music.load(os.path.join(sound_path, "menu.ogg"))
  music.play(4, 0.0)

  songs = load_files(screen, song_list.values(), _("songs"), SongItem, (False,))

  # Construct the song and record dictionaries for courses. These are
  # necessary because courses identify songs by title and mix, rather
  # than filename. The recordkey dictionary is needed for player's
  # picks courses.
  song_dict = {}
  record_dict = {}
  for song in songs:
    mix = song.info["mix"].lower()
    title = song.info["title"].lower()
    if song.info["subtitle"]: title += " " + song.info["subtitle"].lower()
    if not song_dict.has_key(mix): song_dict[mix] = {}
    song_dict[mix][title] = song
    record_dict[song.info["recordkey"]] = song

  crs = load_files(screen, [course_list], _("courses"), courses.CourseFile,
                   (song_dict, record_dict))
  crs.extend(courses.make_players(song_dict, record_dict))
  records.verify(record_dict)

  # Let the GC clean these up if it needs to.
  song_list = None
  course_list = None
  record_dict = None
  pad.empty()

  if len(songs) < 1:
    ErrorMessage(screen,
                 (_("You don't have any songs or step files. Check out "
                  "http://icculus.org/pyddr/get.php#songs "
                  "and download some free ones. "
                  "If you already have some, make sure they're in ")) +
                 mainconfig["songdir"])
    raise SystemExit(_("You don't have any songs. Check http://icculus.org/pyddr/get.php#songs ."))

  menudriver.do(screen, (songs, crs, screen))

  # Clean up shit.
  music.stop()
  pygame.quit()
  mainconfig.write(os.path.join(rc_path, "pydance.cfg"))
  # FIXME -- is this option a good idea?
  if mainconfig["saveinput"]: pad.write(os.path.join(rc_path, "input.cfg"))
  records.write()
Beispiel #2
0
def main():
  print("pydance", VERSION, "<*****@*****.**> - irc.freenode.net/#pyddr")

  if mainconfig["usepsyco"]:
    try:
      import psyco
      print(_("Psyco optimizing compiler found. Using psyco.full()."))
      psyco.full()
    except ImportError: print(_("W: Psyco optimizing compiler not found."))

  # default settings for play_and_quit.
  mode = "SINGLE"
  difficulty = "BASIC"
  test_file = None
  for opt, arg in getopt(sys.argv[1:],
                         "hvf:d:m:", ["help", "version", "filename=",
                                      "difficulty=", "mode="])[0]:
    if opt in ["-h", _("--help")]: print_help()
    elif opt in ["-v", _("--version")]: print_version()
    elif opt in ["-f", _("--filename")]: test_file = arg
    elif opt in ["-m", _("--mode")]: mode = arg
    elif opt in ["-d", _("--difficulty")]: difficulty = arg

  if test_file: play_and_quit(test_file, mode, difficulty)

  song_list = []
  course_list = []
  for dir in mainconfig["songdir"].split(os.pathsep):
    print(_("Searching for songs in"), dir)

    # The order of patterns is significant. Deduplication will remove songs that
    # match a later pattern if they are in the same directory as a song with the
    # same basename but a different extension that matches an earlier pattern.
    # E.g. many ZIP files contain both .sm and .dwi. The .dwi will be ignored in
    # this case.
    song_list.extend(util.find(dir, ['*.dance', '*.sm', '*.dwi', '*/song.*'], 1))
  for dir in mainconfig["coursedir"].split(os.pathsep):
    print(_("Searching for courses in"), dir)
    course_list.extend(util.find(dir, ['*.crs'], 0))

  screen = set_display_mode()
  
  pygame.display.set_caption("pydance " + VERSION)
  pygame.mouse.set_visible(False)
  try:
    if os.path.exists("/usr/share/pixmaps/pydance.png"):
      icon = pygame.image.load("/usr/share/pixmaps/pydance.png")
    else: icon = pygame.image.load(os.path.join(pydance_path, "icon.png"))
    pygame.display.set_icon(icon)
  except: pass

  music.load(os.path.join(sound_path, "menu.ogg"))
  music.play(4, 0.0)

  songs = load_files(screen, song_list, _("songs"), SongItem, (False,))

  # Construct the song and record dictionaries for courses. These are
  # necessary because courses identify songs by title and mix, rather
  # than filename. The recordkey dictionary is needed for player's
  # picks courses.
  song_dict = {}
  record_dict = {}
  for song in songs:
    mix = song.info["mix"].lower()
    title = song.info["title"].lower()
    if song.info["subtitle"]: title += " " + song.info["subtitle"].lower()
    if mix not in song_dict: song_dict[mix] = {}
    song_dict[mix][title] = song
    record_dict[song.info["recordkey"]] = song

  crs = load_files(screen, course_list, _("courses"), courses.CourseFile,
                   (song_dict, record_dict))
  crs.extend(courses.make_players(song_dict, record_dict))
  records.verify(record_dict)

  # Let the GC clean these up if it needs to.
  song_list = None
  course_list = None
  record_dict = None
  ui.ui.clear()

  if len(songs) < 1:
    ErrorMessage(screen,
                 (_("You don't have any songs or step files. Check out "
                  "http://icculus.org/pyddr/get.php#songs "
                  "and download some free ones. "
                  "If you already have some, make sure they're in ")) +
                 mainconfig["songdir"])
    raise SystemExit(_("You don't have any songs. Check http://icculus.org/pyddr/get.php#songs ."))

  menudriver.do(screen, (songs, crs, screen))

  # Clean up shit.
  music.stop()
  pygame.quit()
  mainconfig.update(game_config)
  mainconfig.update(player_config)
  mainconfig.write(os.path.join(rc_path, "pydance.cfg"))
  records.write()