comparison pytouhou/resource/loader.py @ 413:6d7dbcb31d95

Let the gc do its work, don’t keep useless references.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 12 Jun 2013 18:32:35 +0200
parents 65453340ae95
children 40d5f3083ebc
comparison
equal deleted inserted replaced
412:5fe6cd6ceb48 413:6d7dbcb31d95
101 class Loader(object): 101 class Loader(object):
102 def __init__(self, game_dir=None): 102 def __init__(self, game_dir=None):
103 self.exe_files = [] 103 self.exe_files = []
104 self.game_dir = game_dir 104 self.game_dir = game_dir
105 self.known_files = {} 105 self.known_files = {}
106 self.instanced_ecls = {} 106 self.instanced_anms = {} #TODO: remove it someday.
107 self.instanced_anms = {}
108 self.instanced_stages = {}
109 self.instanced_msgs = {}
110 self.instanced_shts = {}
111 self.instanced_tracks = {}
112 self.instanced_fmts = {}
113 107
114 108
115 def scan_archives(self, paths_lists): 109 def scan_archives(self, paths_lists):
116 for paths in paths_lists: 110 for paths in paths_lists:
117 def _expand_paths(): 111 def _expand_paths():
149 self.instanced_anms[name] = ANM0.read(file) #TODO: modular 143 self.instanced_anms[name] = ANM0.read(file) #TODO: modular
150 return self.instanced_anms[name] 144 return self.instanced_anms[name]
151 145
152 146
153 def get_stage(self, name): 147 def get_stage(self, name):
154 if name not in self.instanced_stages: 148 file = self.get_file(name)
155 file = self.get_file(name) 149 return Stage.read(file) #TODO: modular
156 self.instanced_stages[name] = Stage.read(file) #TODO: modular
157 return self.instanced_stages[name]
158 150
159 151
160 def get_ecl(self, name): 152 def get_ecl(self, name):
161 if name not in self.instanced_ecls: 153 file = self.get_file(name)
162 file = self.get_file(name) 154 return ECL.read(file) #TODO: modular
163 self.instanced_ecls[name] = ECL.read(file) #TODO: modular
164 return self.instanced_ecls[name]
165 155
166 156
167 def get_msg(self, name): 157 def get_msg(self, name):
168 if name not in self.instanced_msgs: 158 file = self.get_file(name)
169 file = self.get_file(name) 159 return MSG.read(file) #TODO: modular
170 self.instanced_msgs[name] = MSG.read(file) #TODO: modular
171 return self.instanced_msgs[name]
172 160
173 161
174 def get_sht(self, name): 162 def get_sht(self, name):
175 if name not in self.instanced_shts: 163 file = self.get_file(name)
176 file = self.get_file(name) 164 return SHT.read(file) #TODO: modular
177 self.instanced_shts[name] = SHT.read(file) #TODO: modular
178 return self.instanced_shts[name]
179 165
180 166
181 def get_eosd_characters(self): 167 def get_eosd_characters(self):
182 #TODO: Move to pytouhou.games.eosd? 168 #TODO: Move to pytouhou.games.eosd?
183 for path in self.exe_files: 169 for path in self.exe_files:
190 logger.error("Required game exe not found!") 176 logger.error("Required game exe not found!")
191 177
192 178
193 def get_track(self, name): 179 def get_track(self, name):
194 posname = name.replace('bgm/', '').replace('.mid', '.pos') 180 posname = name.replace('bgm/', '').replace('.mid', '.pos')
195 if name not in self.instanced_tracks: 181 file = self.get_file(posname)
196 file = self.get_file(posname) 182 return Track.read(file) #TODO: modular
197 self.instanced_tracks[name] = Track.read(file) #TODO: modular
198 return self.instanced_tracks[name]
199 183
200 184
201 def get_fmt(self, name): 185 def get_fmt(self, name):
202 if name not in self.instanced_fmts: 186 file = self.get_file(name)
203 file = self.get_file(name) 187 return FMT.read(file) #TODO: modular
204 self.instanced_fmts[name] = FMT.read(file) #TODO: modular
205 return self.instanced_fmts[name]
206 188
207 189
208 def get_anm_wrapper(self, names, offsets=None): 190 def get_anm_wrapper(self, names, offsets=None):
209 """Create an AnmWrapper for ANM files “names”. 191 """Create an AnmWrapper for ANM files “names”.
210 192