changeset 231:c417bb6c98bf

Search for 102h.exe in the game directory instead of the current directory.
author Thibaut Girka <thib@sitedethib.com>
date Fri, 30 Dec 2011 19:17:55 +0100
parents 1c24a6d93c1b
children 8843e26f80c3
files eosd pcb pytouhou/games/eosd.py pytouhou/resource/loader.py
diffstat 4 files changed, 14 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/eosd
+++ b/eosd
@@ -40,9 +40,8 @@ def main(path, stage_num, rank, characte
     else:
         prng = None
 
-    resource_loader = Loader()
-    resource_loader.scan_archives(os.path.join(path, name)
-                                    for name in data)
+    resource_loader = Loader(path)
+    resource_loader.scan_archives(data)
     game = EoSDGame(resource_loader, [PlayerState(character=character)], stage_num, rank, 16,
                     prng=prng)
 
--- a/pcb
+++ b/pcb
@@ -27,9 +27,8 @@ from pytouhou.game.player import PlayerS
 
 
 def main(path, stage_num, rank, character, data):
-    resource_loader = Loader()
-    resource_loader.scan_archives(os.path.join(path, name)
-                                    for name in data)
+    resource_loader = Loader(path)
+    resource_loader.scan_archives(data)
     game = PCBGame(resource_loader, [PlayerState(character=character)], stage_num, rank, 16)
 
     # Load stage data
--- a/pytouhou/games/eosd.py
+++ b/pytouhou/games/eosd.py
@@ -52,10 +52,8 @@ class EoSDGame(Game):
 
         characters = resource_loader.get_eosd_characters('102h.exe')
 
-        #eosd_characters = [ReimuA, ReimuB, MarisaA, MarisaB]
         players = []
         for player in player_states:
-            #players.append(eosd_characters[player.character](player, self, resource_loader))
             players.append(EoSDPlayer(player, self, resource_loader, sht=characters[player.character]))
 
         Game.__init__(self, resource_loader, players, stage, rank, difficulty,
--- a/pytouhou/resource/loader.py
+++ b/pytouhou/resource/loader.py
@@ -1,3 +1,4 @@
+import os
 from io import BytesIO
 
 from pytouhou.formats.pbg3 import PBG3
@@ -40,7 +41,8 @@ class ArchiveDescription(object):
 
 
 class Loader(object):
-    def __init__(self):
+    def __init__(self, game_dir=None):
+        self.game_dir = game_dir
         self.known_files = {}
         self.instanced_ecls = {}
         self.instanced_anms = {}
@@ -51,6 +53,8 @@ class Loader(object):
 
     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
@@ -103,8 +107,11 @@ class Loader(object):
         return self.instanced_shts[name]
 
 
-    def get_eosd_characters(self, name):
-        with open(name, 'rb') as file:
+    def get_eosd_characters(self, path):
+        #TODO: Move to pytouhou.games.eosd?
+        if self.game_dir and not os.path.isabs(path):
+            path = os.path.join(self.game_dir, path)
+        with open(path, 'rb') as file:
             characters = EoSDSHT.read(file) #TODO: modular
         return characters