Mercurial > touhou
changeset 262:8fa660da5f0c
Automatically search data files using different names.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Mon, 23 Jan 2012 00:58:03 +0100 |
parents | 2876c267be00 |
children | ac677dd0ffe0 |
files | eosd pytouhou/games/eosd.py pytouhou/resource/loader.py |
diffstat | 3 files changed, 28 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/eosd +++ b/eosd @@ -41,6 +41,7 @@ def main(path, stage_num, rank, characte prng = None resource_loader = Loader(path) + resource_loader.scan_archives(data) game = EoSDGame(resource_loader, [PlayerState(character=character)], stage_num, rank, 16, prng=prng) @@ -56,9 +57,14 @@ def main(path, stage_num, rank, characte runner.start() +default_data = ('CM.DAT:th06*_CM.DAT:*CM.DAT:*cm.dat', + 'ST.DAT:th6*ST.DAT:*ST.DAT:*st.dat', + '102h.exe:102*.exe:東方紅魔郷.exe:*.exe') + + parser = argparse.ArgumentParser(description='Libre reimplementation of the Touhou 6 engine.') -parser.add_argument('data', metavar='DAT', default=('CM.DAT', 'ST.DAT'), nargs='*', help='Game’s .DAT data files') +parser.add_argument('data', metavar='DAT', default=default_data, nargs='*', help='Game’s data files') parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.') parser.add_argument('-s', '--stage', metavar='STAGE', type=int, required=True, help='Stage, 1 to 7 (Extra).') parser.add_argument('-r', '--rank', metavar='RANK', type=int, default=0, help='Rank, from 0 (Easy, default) to 3 (Lunatic).')
--- a/pytouhou/games/eosd.py +++ b/pytouhou/games/eosd.py @@ -49,7 +49,7 @@ class EoSDGame(Game): ItemType(etama3, 5, 12), #1up ItemType(etama3, 6, 13)] #Star - characters = resource_loader.get_eosd_characters('102h.exe') + characters = resource_loader.get_eosd_characters() players = [EoSDPlayer(state, self, resource_loader, characters[state.character]) for state in player_states] Game.__init__(self, resource_loader, players, stage, rank, difficulty,
--- a/pytouhou/resource/loader.py +++ b/pytouhou/resource/loader.py @@ -1,4 +1,6 @@ import os +from glob import glob +from itertools import chain from io import BytesIO from pytouhou.formats.pbg3 import PBG3 @@ -42,6 +44,7 @@ class ArchiveDescription(object): class Loader(object): def __init__(self, game_dir=None): + self.exe = None self.game_dir = game_dir self.known_files = {} self.instanced_ecls = {} @@ -51,13 +54,21 @@ class Loader(object): self.instanced_shts = {} - def scan_archives(self, paths): - for path in paths: - if self.game_dir and not os.path.isabs(path): - path = os.path.join(self.game_dir, path) - archive_description = ArchiveDescription.get_from_path(path) - for name in archive_description.file_list: - self.known_files[name] = archive_description + def scan_archives(self, paths_lists): + for paths in paths_lists: + def _expand_paths(): + for path in paths.split(':'): + if self.game_dir and not os.path.isabs(path): + path = os.path.join(self.game_dir, path) + yield glob(path) + paths = list(chain(*_expand_paths())) + path = paths[0] + if os.path.splitext(path)[1] == '.exe': + self.exe = path + else: + archive_description = ArchiveDescription.get_from_path(path) + for name in archive_description.file_list: + self.known_files[name] = archive_description def get_file_data(self, name): @@ -107,8 +118,9 @@ class Loader(object): return self.instanced_shts[name] - def get_eosd_characters(self, path): + def get_eosd_characters(self): #TODO: Move to pytouhou.games.eosd? + path = self.exe if self.game_dir and not os.path.isabs(path): path = os.path.join(self.game_dir, path) with open(path, 'rb') as file: