Mercurial > touhou
annotate pytouhou/resource/loader.py @ 788:f56b10812b77
Remove leftover MSG import
This should have been part of a30ce01b9154.
| author | Link Mauve <linkmauve@linkmauve.fr> |
|---|---|
| date | Sun, 04 Jan 2026 11:47:06 +0100 |
| parents | ec1e06402a97 |
| children |
| 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 |
|
778
816e1f01d650
Partially replace the Loader with a Rust one
Link Mauve <linkmauve@linkmauve.fr>
parents:
771
diff
changeset
|
15 from libtouhou import Loader as RustLoader |
| 97 | 16 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
|
17 from pytouhou.formats.anm0 import ANM0 |
|
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
|
18 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
|
19 from pytouhou.formats.exe import SHT as EoSDSHT, InvalidExeException |
|
325
cddfd3cb4797
Add music support for >PCB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
20 from pytouhou.formats.fmt import FMT |
| 97 | 21 |
|
298
92a6fd2632f1
Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents:
297
diff
changeset
|
22 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
|
23 |
|
92a6fd2632f1
Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents:
297
diff
changeset
|
24 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
|
25 |
|
92a6fd2632f1
Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents:
297
diff
changeset
|
26 |
| 97 | 27 |
|
778
816e1f01d650
Partially replace the Loader with a Rust one
Link Mauve <linkmauve@linkmauve.fr>
parents:
771
diff
changeset
|
28 class Loader(RustLoader): |
|
231
c417bb6c98bf
Search for 102h.exe in the game directory instead of the current directory.
Thibaut Girka <thib@sitedethib.com>
parents:
229
diff
changeset
|
29 def __init__(self, game_dir=None): |
|
504
69c73023f7a0
Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
30 self.instanced_anms = {} # Cache for the textures. |
|
69c73023f7a0
Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
31 self.loaded_anms = [] # For the double loading warnings. |
| 97 | 32 |
| 33 | |
| 34 def get_anm(self, name): | |
|
504
69c73023f7a0
Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
35 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
|
36 logger.warning('ANM0 %s already loaded', name) |
|
504
69c73023f7a0
Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
37 file = self.get_file(name) |
|
69c73023f7a0
Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
38 anm = ANM0.read(file) |
|
69c73023f7a0
Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
39 self.instanced_anms[name] = anm |
|
69c73023f7a0
Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
40 self.loaded_anms.append(name) |
|
69c73023f7a0
Make ANM garbage collectable.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
41 return anm |
| 97 | 42 |
| 43 | |
| 44 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
|
45 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
|
46 return ECL.read(file) #TODO: modular |
| 97 | 47 |
| 48 | |
|
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
|
49 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
|
50 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
|
51 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
|
52 |
|
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
|
53 |
|
262
8fa660da5f0c
Automatically search data files using different names.
Thibaut Girka <thib@sitedethib.com>
parents:
231
diff
changeset
|
54 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
|
55 #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
|
56 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
|
57 try: |
|
92a6fd2632f1
Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents:
297
diff
changeset
|
58 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
|
59 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
|
60 return characters |
|
92a6fd2632f1
Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents:
297
diff
changeset
|
61 except InvalidExeException: |
|
92a6fd2632f1
Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents:
297
diff
changeset
|
62 pass |
|
92a6fd2632f1
Improve heuristic to filter out non-game exes (like custom.exe).
Thibaut Girka <thib@sitedethib.com>
parents:
297
diff
changeset
|
63 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
|
64 |
|
5afc75f71fed
Add “SHT” support to EoSD, and do a little cleanup.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
220
diff
changeset
|
65 |
|
325
cddfd3cb4797
Add music support for >PCB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
66 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
|
67 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
|
68 return FMT.read(file) #TODO: modular |
|
325
cddfd3cb4797
Add music support for >PCB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
69 |
|
cddfd3cb4797
Add music support for >PCB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
321
diff
changeset
|
70 |
|
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
429
diff
changeset
|
71 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
|
72 """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
|
73 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
|
74 assert len(anm) == 1 |
|
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
429
diff
changeset
|
75 return anm[0] |
| 97 | 76 |
| 77 | |
|
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
429
diff
changeset
|
78 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
|
79 """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
|
80 return sum((self.get_anm(name) for name in names), []) |
