annotate pytouhou/resource/loader.py @ 263:ac677dd0ffe0

Add support for reading from a directory instead of a PBG3 (for debugging purposes).
author Thibaut Girka <thib@sitedethib.com>
date Mon, 23 Jan 2012 01:40:07 +0100
parents 8fa660da5f0c
children dbb1a86c0235
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
231
c417bb6c98bf Search for 102h.exe in the game directory instead of the current directory.
Thibaut Girka <thib@sitedethib.com>
parents: 229
diff changeset
1 import os
262
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
2 from glob import glob
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
3 from itertools import chain
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
4 from io import BytesIO
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
5
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
6 from pytouhou.formats.pbg3 import PBG3
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
7 from pytouhou.formats.std import Stage
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
8 from pytouhou.formats.ecl import ECL
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
9 from pytouhou.formats.anm0 import Animations
133
2cad2e84a49e Add reading support for the MSG format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 97
diff changeset
10 from pytouhou.formats.msg import MSG
220
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 133
diff changeset
11 from pytouhou.formats.sht import SHT
229
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
12 from pytouhou.formats.exe import SHT as EoSDSHT
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
13
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
14
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
15 from pytouhou.resource.anmwrapper import AnmWrapper
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
16
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
17
263
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
18 class Directory(object):
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
19 def __init__(self, path):
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
20 self.path = path
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
21
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
22
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
23 def __enter__(self):
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
24 return self
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
25
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
26
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
27 def __exit__(self, type, value, traceback):
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
28 return False
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
29
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
30
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
31 def list_files(self):
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
32 file_list = []
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
33 for path in os.listdir(self.path):
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
34 if os.path.isfile(os.path.join(self.path, path)):
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
35 file_list.append(path)
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
36 return file_list
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
37
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
38
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
39 def extract(self, name):
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
40 with open(os.path.join(self.path, str(name)), 'rb') as file:
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
41 contents = file.read()
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
42 return contents
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
43
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
44
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
45
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
46 class ArchiveDescription(object):
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
47 _formats = {'PBG3': PBG3}
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
48
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
49 def __init__(self, path, format_class, file_list=None):
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
50 self.path = path
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
51 self.format_class = format_class
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
52 self.file_list = file_list or []
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
53
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
54
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
55 def open(self):
263
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
56 if self.format_class is Directory:
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
57 return self.format_class(self.path)
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
58
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
59 file = open(self.path, 'rb')
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
60 instance = self.format_class.read(file)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
61 return instance
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
62
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
63
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
64 @classmethod
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
65 def get_from_path(cls, path):
263
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
66 if os.path.isdir(path):
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
67 instance = Directory(path)
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
68 file_list = instance.list_files()
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
69 return cls(path, Directory, file_list)
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
70 with open(path, 'rb') as file:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
71 magic = file.read(4)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
72 file.seek(0)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
73 format_class = cls._formats[magic]
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
74 instance = format_class.read(file)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
75 file_list = instance.list_files()
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
76 return cls(path, format_class, file_list)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
77
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
78
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
79
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
80 class Loader(object):
231
c417bb6c98bf Search for 102h.exe in the game directory instead of the current directory.
Thibaut Girka <thib@sitedethib.com>
parents: 229
diff changeset
81 def __init__(self, game_dir=None):
262
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
82 self.exe = None
231
c417bb6c98bf Search for 102h.exe in the game directory instead of the current directory.
Thibaut Girka <thib@sitedethib.com>
parents: 229
diff changeset
83 self.game_dir = game_dir
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
84 self.known_files = {}
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
85 self.instanced_ecls = {}
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
86 self.instanced_anms = {}
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
87 self.instanced_stages = {}
133
2cad2e84a49e Add reading support for the MSG format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 97
diff changeset
88 self.instanced_msgs = {}
220
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 133
diff changeset
89 self.instanced_shts = {}
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
90
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
91
262
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
92 def scan_archives(self, paths_lists):
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
93 for paths in paths_lists:
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
94 def _expand_paths():
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
95 for path in paths.split(':'):
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
96 if self.game_dir and not os.path.isabs(path):
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
97 path = os.path.join(self.game_dir, path)
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
98 yield glob(path)
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
99 paths = list(chain(*_expand_paths()))
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
100 path = paths[0]
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
101 if os.path.splitext(path)[1] == '.exe':
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
102 self.exe = path
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
103 else:
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
104 archive_description = ArchiveDescription.get_from_path(path)
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
105 for name in archive_description.file_list:
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
106 self.known_files[name] = archive_description
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
107
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
108
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
109 def get_file_data(self, name):
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
110 with self.known_files[name].open() as archive:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
111 content = archive.extract(name)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
112 return content
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
113
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
114
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
115 def get_file(self, name):
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
116 with self.known_files[name].open() as archive:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
117 content = archive.extract(name)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
118 return BytesIO(content)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
119
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
120
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
121 def get_anm(self, name):
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
122 if name not in self.instanced_anms:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
123 file = self.get_file(name)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
124 self.instanced_anms[name] = Animations.read(file) #TODO: modular
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
125 return self.instanced_anms[name]
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
126
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
127
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
128 def get_stage(self, name):
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
129 if name not in self.instanced_stages:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
130 file = self.get_file(name)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
131 self.instanced_stages[name] = Stage.read(file) #TODO: modular
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
132 return self.instanced_stages[name]
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
133
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
134
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
135 def get_ecl(self, name):
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
136 if name not in self.instanced_ecls:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
137 file = self.get_file(name)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
138 self.instanced_ecls[name] = ECL.read(file) #TODO: modular
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
139 return self.instanced_ecls[name]
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
140
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
141
133
2cad2e84a49e Add reading support for the MSG format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 97
diff changeset
142 def get_msg(self, name):
2cad2e84a49e Add reading support for the MSG format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 97
diff changeset
143 if name not in self.instanced_msgs:
2cad2e84a49e Add reading support for the MSG format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 97
diff changeset
144 file = self.get_file(name)
2cad2e84a49e Add reading support for the MSG format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 97
diff changeset
145 self.instanced_msgs[name] = MSG.read(file) #TODO: modular
2cad2e84a49e Add reading support for the MSG format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 97
diff changeset
146 return self.instanced_msgs[name]
2cad2e84a49e Add reading support for the MSG format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 97
diff changeset
147
2cad2e84a49e Add reading support for the MSG format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 97
diff changeset
148
220
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 133
diff changeset
149 def get_sht(self, name):
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 133
diff changeset
150 if name not in self.instanced_shts:
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 133
diff changeset
151 file = self.get_file(name)
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 133
diff changeset
152 self.instanced_shts[name] = SHT.read(file) #TODO: modular
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 133
diff changeset
153 return self.instanced_shts[name]
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 133
diff changeset
154
0595315d3880 Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 133
diff changeset
155
262
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
156 def get_eosd_characters(self):
231
c417bb6c98bf Search for 102h.exe in the game directory instead of the current directory.
Thibaut Girka <thib@sitedethib.com>
parents: 229
diff changeset
157 #TODO: Move to pytouhou.games.eosd?
262
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
158 path = self.exe
231
c417bb6c98bf Search for 102h.exe in the game directory instead of the current directory.
Thibaut Girka <thib@sitedethib.com>
parents: 229
diff changeset
159 if self.game_dir and not os.path.isabs(path):
c417bb6c98bf Search for 102h.exe in the game directory instead of the current directory.
Thibaut Girka <thib@sitedethib.com>
parents: 229
diff changeset
160 path = os.path.join(self.game_dir, path)
c417bb6c98bf Search for 102h.exe in the game directory instead of the current directory.
Thibaut Girka <thib@sitedethib.com>
parents: 229
diff changeset
161 with open(path, 'rb') as file:
229
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
162 characters = EoSDSHT.read(file) #TODO: modular
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
163 return characters
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
164
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
165
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
166 def get_anm_wrapper(self, names):
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
167 return AnmWrapper(self.get_anm(name) for name in names)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
168
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
169
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
170 def get_anm_wrapper2(self, names):
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
171 anims = []
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
172 try:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
173 for name in names:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
174 anims.append(self.get_anm(name))
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
175 except KeyError:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
176 pass
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
177
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
178 return AnmWrapper(anims)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
179