annotate pytouhou/resource/loader.py @ 772:7492d384d122 default tip

Rust: Add a Glide renderer (2D only for now) This is an experiment for a Rust renderer, iterating over the Python data using pyo3. It requires --feature=glide to be passed to cargo build, doesn’t support NPOT textures, text rendering, the background, or even msg faces, some of that may come in a future changeset.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 05 Sep 2022 17:53:36 +0200
parents 79c3f782dd41
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
285
2100276c289d Document some AnmWrapper related functions.
Thibaut Girka <thib@sitedethib.com>
parents: 282
diff changeset
1 # -*- encoding: utf-8 -*-
2100276c289d Document some AnmWrapper related functions.
Thibaut Girka <thib@sitedethib.com>
parents: 282
diff changeset
2 ##
2100276c289d Document some AnmWrapper related functions.
Thibaut Girka <thib@sitedethib.com>
parents: 282
diff changeset
3 ## Copyright (C) 2012 Thibaut Girka <thib@sitedethib.com>
2100276c289d Document some AnmWrapper related functions.
Thibaut Girka <thib@sitedethib.com>
parents: 282
diff changeset
4 ##
2100276c289d Document some AnmWrapper related functions.
Thibaut Girka <thib@sitedethib.com>
parents: 282
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
2100276c289d Document some AnmWrapper related functions.
Thibaut Girka <thib@sitedethib.com>
parents: 282
diff changeset
6 ## it under the terms of the GNU General Public License as published
2100276c289d Document some AnmWrapper related functions.
Thibaut Girka <thib@sitedethib.com>
parents: 282
diff changeset
7 ## by the Free Software Foundation; version 3 only.
2100276c289d Document some AnmWrapper related functions.
Thibaut Girka <thib@sitedethib.com>
parents: 282
diff changeset
8 ##
2100276c289d Document some AnmWrapper related functions.
Thibaut Girka <thib@sitedethib.com>
parents: 282
diff changeset
9 ## This program is distributed in the hope that it will be useful,
2100276c289d Document some AnmWrapper related functions.
Thibaut Girka <thib@sitedethib.com>
parents: 282
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
2100276c289d Document some AnmWrapper related functions.
Thibaut Girka <thib@sitedethib.com>
parents: 282
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2100276c289d Document some AnmWrapper related functions.
Thibaut Girka <thib@sitedethib.com>
parents: 282
diff changeset
12 ## GNU General Public License for more details.
2100276c289d Document some AnmWrapper related functions.
Thibaut Girka <thib@sitedethib.com>
parents: 282
diff changeset
13 ##
2100276c289d Document some AnmWrapper related functions.
Thibaut Girka <thib@sitedethib.com>
parents: 282
diff changeset
14
231
c417bb6c98bf Search for 102h.exe in the game directory instead of the current directory.
Thibaut Girka <thib@sitedethib.com>
parents: 229
diff changeset
15 import os
262
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
16 from glob import glob
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
17 from itertools import chain
771
79c3f782dd41 Python: Replace the PBG3 loader with Rust’s
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 764
diff changeset
18 from io import BytesIO
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
19
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 413
diff changeset
20 from pytouhou.formats import WrongFormatError
771
79c3f782dd41 Python: Replace the PBG3 loader with Rust’s
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 764
diff changeset
21 from libtouhou import PBG3
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
22 from pytouhou.formats.std import Stage
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
23 from pytouhou.formats.ecl import ECL
282
dbb1a86c0235 Rename Animations to ANM0 and prepare AnmWrapper for dialogs and interface.
Thibaut Girka <thib@sitedethib.com>
parents: 263
diff changeset
24 from pytouhou.formats.anm0 import ANM0
133
2cad2e84a49e Add reading support for the MSG format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 97
diff changeset
25 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
26 from pytouhou.formats.sht import SHT
298
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
27 from pytouhou.formats.exe import SHT as EoSDSHT, InvalidExeException
321
61adb5453e46 Implement music playback.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 298
diff changeset
28 from pytouhou.formats.music import Track
325
cddfd3cb4797 Add music support for >PCB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 321
diff changeset
29 from pytouhou.formats.fmt import FMT
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
30
298
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
31 from pytouhou.utils.helpers import get_logger
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
32
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
33 logger = get_logger(__name__)
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
34
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
35
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
36
615
d1f0bb0b7a17 Don’t inherit explicitely from object, we are not on Python 2.7 anymore. :)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
37 class Directory:
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
38 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
39 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
40
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
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 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
43 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
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
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
46 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
47 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
48
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
49
771
79c3f782dd41 Python: Replace the PBG3 loader with Rust’s
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 764
diff changeset
50 @property
79c3f782dd41 Python: Replace the PBG3 loader with Rust’s
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 764
diff changeset
51 def file_list(self):
79c3f782dd41 Python: Replace the PBG3 loader with Rust’s
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 764
diff changeset
52 return self.list_files()
79c3f782dd41 Python: Replace the PBG3 loader with Rust’s
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 764
diff changeset
53
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
54 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
55 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
56 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
57 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
58 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
59 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
60
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
61
536
6b76c9ba3975 Make archives return files by default, instead of bytes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 504
diff changeset
62 def get_file(self, name):
6b76c9ba3975 Make archives return files by default, instead of bytes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 504
diff changeset
63 return open(os.path.join(self.path, str(name)), 'rb')
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
64
ac677dd0ffe0 Add support for reading from a directory instead of a PBG3 (for debugging purposes).
Thibaut Girka <thib@sitedethib.com>
parents: 262
diff changeset
65
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
615
d1f0bb0b7a17 Don’t inherit explicitely from object, we are not on Python 2.7 anymore. :)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
67 class ArchiveDescription:
590
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 536
diff changeset
68 _formats = {b'PBG3': PBG3}
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
69
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
70 @classmethod
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
71 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
72 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
73 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
74 file_list = instance.list_files()
771
79c3f782dd41 Python: Replace the PBG3 loader with Rust’s
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 764
diff changeset
75 return instance
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
76 with open(path, 'rb') as file:
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
77 magic = file.read(4)
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
78 format_class = cls._formats[magic]
771
79c3f782dd41 Python: Replace the PBG3 loader with Rust’s
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 764
diff changeset
79 return format_class.from_filename(path)
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
80
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
81
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
82
615
d1f0bb0b7a17 Don’t inherit explicitely from object, we are not on Python 2.7 anymore. :)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
83 class Loader:
231
c417bb6c98bf Search for 102h.exe in the game directory instead of the current directory.
Thibaut Girka <thib@sitedethib.com>
parents: 229
diff changeset
84 def __init__(self, game_dir=None):
298
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
85 self.exe_files = []
231
c417bb6c98bf Search for 102h.exe in the game directory instead of the current directory.
Thibaut Girka <thib@sitedethib.com>
parents: 229
diff changeset
86 self.game_dir = game_dir
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
87 self.known_files = {}
504
69c73023f7a0 Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 430
diff changeset
88 self.instanced_anms = {} # Cache for the textures.
69c73023f7a0 Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 430
diff changeset
89 self.loaded_anms = [] # For the double loading warnings.
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():
297
a09ac4650e0d Fix relative path handling and os-specific path separators.
Thibaut Girka <thib@sitedethib.com>
parents: 285
diff changeset
95 for path in paths.split(os.path.pathsep):
262
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()))
338
65453340ae95 Print an error when all the needed files aren’t present.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 325
diff changeset
100 if not paths:
65453340ae95 Print an error when all the needed files aren’t present.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 325
diff changeset
101 raise IOError
262
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
102 path = paths[0]
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
103 if os.path.splitext(path)[1] == '.exe':
298
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
104 self.exe_files.extend(paths)
262
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
105 else:
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
106 archive_description = ArchiveDescription.get_from_path(path)
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
107 for name in archive_description.file_list:
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
108 self.known_files[name] = archive_description
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
109
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
110
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
111 def get_file(self, name):
771
79c3f782dd41 Python: Replace the PBG3 loader with Rust’s
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 764
diff changeset
112 archive = self.known_files[name]
79c3f782dd41 Python: Replace the PBG3 loader with Rust’s
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 764
diff changeset
113 file = archive.get_file(name)
79c3f782dd41 Python: Replace the PBG3 loader with Rust’s
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 764
diff changeset
114 if isinstance(file, bytes):
79c3f782dd41 Python: Replace the PBG3 loader with Rust’s
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 764
diff changeset
115 return BytesIO(file)
79c3f782dd41 Python: Replace the PBG3 loader with Rust’s
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 764
diff changeset
116 return file
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
117
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
118
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
119 def get_anm(self, name):
504
69c73023f7a0 Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 430
diff changeset
120 if name in self.loaded_anms:
764
d18c0bf11138 Python: Use logger.warning() as logger.warn() is deprecated
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 615
diff changeset
121 logger.warning('ANM0 %s already loaded', name)
504
69c73023f7a0 Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 430
diff changeset
122 file = self.get_file(name)
69c73023f7a0 Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 430
diff changeset
123 anm = ANM0.read(file)
69c73023f7a0 Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 430
diff changeset
124 self.instanced_anms[name] = anm
69c73023f7a0 Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 430
diff changeset
125 self.loaded_anms.append(name)
69c73023f7a0 Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 430
diff changeset
126 return anm
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
127
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
128
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
129 def get_stage(self, name):
413
6d7dbcb31d95 Let the gc do its work, don’t keep useless references.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 338
diff changeset
130 file = self.get_file(name)
6d7dbcb31d95 Let the gc do its work, don’t keep useless references.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 338
diff changeset
131 return Stage.read(file) #TODO: modular
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
132
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
133
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
134 def get_ecl(self, name):
413
6d7dbcb31d95 Let the gc do its work, don’t keep useless references.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 338
diff changeset
135 file = self.get_file(name)
6d7dbcb31d95 Let the gc do its work, don’t keep useless references.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 338
diff changeset
136 return ECL.read(file) #TODO: modular
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
137
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
138
133
2cad2e84a49e Add reading support for the MSG format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 97
diff changeset
139 def get_msg(self, name):
413
6d7dbcb31d95 Let the gc do its work, don’t keep useless references.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 338
diff changeset
140 file = self.get_file(name)
6d7dbcb31d95 Let the gc do its work, don’t keep useless references.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 338
diff changeset
141 return MSG.read(file) #TODO: modular
133
2cad2e84a49e Add reading support for the MSG format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 97
diff changeset
142
2cad2e84a49e Add reading support for the MSG format.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 97
diff changeset
143
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
144 def get_sht(self, name):
413
6d7dbcb31d95 Let the gc do its work, don’t keep useless references.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 338
diff changeset
145 file = self.get_file(name)
6d7dbcb31d95 Let the gc do its work, don’t keep useless references.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 338
diff changeset
146 return SHT.read(file) #TODO: modular
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
147
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
148
262
8fa660da5f0c Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents: 231
diff changeset
149 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
150 #TODO: Move to pytouhou.games.eosd?
298
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
151 for path in self.exe_files:
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
152 try:
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
153 with open(path, 'rb') as file:
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
154 characters = EoSDSHT.read(file)
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
155 return characters
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
156 except InvalidExeException:
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
157 pass
92a6fd2632f1 Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents: 297
diff changeset
158 logger.error("Required game exe not found!")
229
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
159
5afc75f71fed Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 220
diff changeset
160
321
61adb5453e46 Implement music playback.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 298
diff changeset
161 def get_track(self, name):
61adb5453e46 Implement music playback.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 298
diff changeset
162 posname = name.replace('bgm/', '').replace('.mid', '.pos')
413
6d7dbcb31d95 Let the gc do its work, don’t keep useless references.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 338
diff changeset
163 file = self.get_file(posname)
6d7dbcb31d95 Let the gc do its work, don’t keep useless references.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 338
diff changeset
164 return Track.read(file) #TODO: modular
321
61adb5453e46 Implement music playback.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 298
diff changeset
165
61adb5453e46 Implement music playback.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 298
diff changeset
166
325
cddfd3cb4797 Add music support for >PCB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 321
diff changeset
167 def get_fmt(self, name):
413
6d7dbcb31d95 Let the gc do its work, don’t keep useless references.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 338
diff changeset
168 file = self.get_file(name)
6d7dbcb31d95 Let the gc do its work, don’t keep useless references.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 338
diff changeset
169 return FMT.read(file) #TODO: modular
325
cddfd3cb4797 Add music support for >PCB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 321
diff changeset
170
cddfd3cb4797 Add music support for >PCB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 321
diff changeset
171
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
172 def get_single_anm(self, name):
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
173 """Hack for EoSD, since it doesn’t support multi-entries ANMs."""
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
174 anm = self.get_anm(name)
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
175 assert len(anm) == 1
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
176 return anm[0]
97
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
177
ac2e5e1c2c3c Refactor \o/
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
178
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
179 def get_multi_anm(self, names):
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
180 """Hack for EoSD, since it doesn’t support multi-entries ANMs."""
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
181 return sum((self.get_anm(name) for name in names), [])