Mercurial > touhou
annotate pytouhou/formats/anm0.py @ 468:feecdb4a8928
Add “except *” to cdef void functions, and type some more.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 12 Sep 2013 15:47:08 +0200 |
parents | 40d5f3083ebc |
children |
rev | line source |
---|---|
52
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
41
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
41
diff
changeset
|
2 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
41
diff
changeset
|
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
41
diff
changeset
|
4 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
41
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
41
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
41
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
41
diff
changeset
|
8 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
41
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
41
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
41
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
41
diff
changeset
|
12 ## GNU General Public License for more details. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
41
diff
changeset
|
13 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
41
diff
changeset
|
14 |
204
88361534c77e
Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
15 """ANM0 files handling. |
88361534c77e
Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
16 |
88361534c77e
Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
17 This module provides classes for handling the ANM0 file format. |
88361534c77e
Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
18 The ANM0 format is a format used in Touhou 6: EoSD to describe sprites |
88361534c77e
Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
19 and animations. |
88361534c77e
Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
20 Almost everything rendered in the game is described by an ANM0 file. |
88361534c77e
Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
21 """ |
88361534c77e
Add some documentation (argh, so much left to document!)
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
22 |
2
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
23 from struct import pack, unpack |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
57
diff
changeset
|
24 from pytouhou.utils.helpers import read_string, get_logger |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
57
diff
changeset
|
25 |
377
70e2ed71b09c
Add meaningful exceptions in format parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
300
diff
changeset
|
26 from pytouhou.formats import WrongFormatError |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
27 from pytouhou.formats.thtx import Texture |
377
70e2ed71b09c
Add meaningful exceptions in format parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
300
diff
changeset
|
28 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
57
diff
changeset
|
29 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
57
diff
changeset
|
30 logger = get_logger(__name__) |
2
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
31 |
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
32 #TODO: refactor/clean up |
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
33 |
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
34 |
236
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
204
diff
changeset
|
35 class Script(list): |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
204
diff
changeset
|
36 def __init__(self): |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
204
diff
changeset
|
37 list.__init__(self) |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
204
diff
changeset
|
38 self.interrupts = {} |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
204
diff
changeset
|
39 |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
204
diff
changeset
|
40 |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
204
diff
changeset
|
41 |
282
dbb1a86c0235
Rename Animations to ANM0 and prepare AnmWrapper for dialogs and interface.
Thibaut Girka <thib@sitedethib.com>
parents:
245
diff
changeset
|
42 class ANM0(object): |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
43 _instructions = {0: {0: ('', 'delete'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
44 1: ('I', 'set_sprite'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
45 2: ('ff', 'set_scale'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
46 3: ('I', 'set_alpha'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
47 4: ('BBBx', 'set_color'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
48 5: ('I', 'jump'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
49 7: ('', 'toggle_mirrored'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
50 9: ('fff', 'set_3d_rotations'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
51 10: ('fff', 'set_3d_rotations_speed'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
52 11: ('ff', 'set_scale_speed'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
53 12: ('ii', 'fade'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
54 13: ('', 'set_blendmode_add'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
55 14: ('', 'set_blendmode_alphablend'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
56 15: ('', 'keep_still'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
57 16: ('ii', 'set_random_sprite'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
58 17: ('fff', 'set_3d_translation'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
59 18: ('fffi', 'move_to_linear'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
60 19: ('fffi', 'move_to_decel'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
61 20: ('fffi', 'move_to_accel'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
62 21: ('', 'wait'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
63 22: ('i', 'interrupt_label'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
64 23: ('', 'set_corner_relative_placement'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
65 24: ('', 'wait_ex'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
66 25: ('i', 'set_allow_offset'), #TODO: better name |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
67 26: ('i', 'set_automatic_orientation'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
68 27: ('f', 'shift_texture_x'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
69 28: ('f', 'shift_texture_y'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
70 29: ('i', 'set_visible'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
71 30: ('ffi', 'scale_in'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
72 31: ('i', None)}, |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
73 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
74 2: {0: ('', 'noop'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
75 1: ('', 'delete'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
76 2: ('', 'keep_still'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
77 3: ('I', 'set_sprite'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
78 4: ('II', 'jump_bis'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
79 5: ('III', 'jump_ex'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
80 6: ('fff', 'set_3d_translation'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
81 7: ('ff', 'set_scale'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
82 8: ('I', 'set_alpha'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
83 9: ('BBBx', 'set_color'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
84 10: ('', 'toggle_mirrored'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
85 12: ('fff', 'set_3d_rotations'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
86 13: ('fff', 'set_3d_rotations_speed'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
87 14: ('ff', 'set_scale_speed'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
88 15: ('ii', 'fade'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
89 16: ('I', 'set_blendmode'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
90 17: ('fffi', 'move_to_linear'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
91 18: ('fffi', 'move_to_decel'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
92 19: ('fffi', 'move_to_accel'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
93 20: ('', 'wait'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
94 21: ('i', 'interrupt_label'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
95 22: ('', 'set_corner_relative_placement'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
96 23: ('', 'wait_ex'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
97 24: ('i', 'set_allow_offset'), #TODO: better name |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
98 25: ('i', 'set_automatic_orientation'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
99 26: ('f', 'shift_texture_x'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
100 27: ('f', 'shift_texture_y'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
101 28: ('i', 'set_visible'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
102 29: ('ffi', 'scale_in'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
103 30: ('i', None), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
104 31: ('I', None), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
105 32: ('IIfff', 'move_in_linear_bis'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
106 33: ('IIBBBx', 'change_color_in'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
107 34: ('III', 'fade_bis'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
108 35: ('IIfff', 'rotate_in_bis'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
109 36: ('IIff', 'scale_in_bis'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
110 37: ('II', 'set_int'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
111 38: ('ff', 'set_float'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
112 42: ('ff', 'decrement_float'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
113 50: ('fff', 'add_float'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
114 52: ('fff', 'substract_float'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
115 55: ('III', 'divide_int'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
116 59: ('II', 'set_random_int'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
117 60: ('ff', 'set_random_float'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
118 69: ('IIII', 'branch_if_not_equal'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
119 79: ('I', 'wait_duration'), |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
120 80: ('I', None)}} |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
57
diff
changeset
|
121 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
57
diff
changeset
|
122 |
2
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
123 def __init__(self): |
402
88e2a2485b2b
Add a version attribute to ANM0 and latest discovered instruction.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
377
diff
changeset
|
124 self.version = 0 |
2
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
125 self.size = (0, 0) |
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
126 self.first_name = None |
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
127 self.secondary_name = None |
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
128 self.sprites = {} |
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
129 self.scripts = {} |
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
130 |
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
131 |
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
132 @classmethod |
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
133 def read(cls, file): |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
134 anm_list = [] |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
135 start_offset = 0 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
136 while True: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
137 file.seek(start_offset) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
138 nb_sprites, nb_scripts, zero1 = unpack('<III', file.read(12)) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
139 width, height, fmt, unknown1 = unpack('<IIII', file.read(16)) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
140 first_name_offset, unused, secondary_name_offset = unpack('<III', file.read(12)) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
141 version, unknown2, texture_offset, has_data, next_offset, unknown3 = unpack('<IIIIII', file.read(24)) |
2
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
142 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
143 if version == 0: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
144 assert zero1 == 0 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
145 assert unknown3 == 0 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
146 assert has_data == 0 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
147 elif version == 2: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
148 assert zero1 == 0 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
149 assert secondary_name_offset == 0 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
150 assert has_data == 1 # Can be false but we don’t support that yet. |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
151 else: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
152 raise WrongFormatError(version) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
153 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
154 instructions = cls._instructions[version] |
2
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
155 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
156 sprite_offsets = [unpack('<I', file.read(4))[0] for i in range(nb_sprites)] |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
157 script_offsets = [unpack('<II', file.read(8)) for i in range(nb_scripts)] |
2
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
158 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
159 self = cls() |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
160 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
161 self.size = (width, height) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
162 self.version = version |
2
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
163 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
164 # Names |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
165 if first_name_offset: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
166 file.seek(start_offset + first_name_offset) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
167 self.first_name = read_string(file, 32, 'ascii') #TODO: 32, really? |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
168 if secondary_name_offset: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
169 file.seek(start_offset + secondary_name_offset) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
170 self.secondary_name = read_string(file, 32, 'ascii') #TODO: 32, really? |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
171 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
172 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
173 # Sprites |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
174 for offset in sprite_offsets: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
175 file.seek(start_offset + offset) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
176 idx, x, y, width, height = unpack('<Iffff', file.read(20)) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
177 self.sprites[idx] = x, y, width, height |
2
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
178 |
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
179 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
180 # Scripts |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
181 for i, offset in script_offsets: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
182 self.scripts[i] = Script() |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
183 instruction_offsets = [] |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
184 file.seek(start_offset + offset) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
185 while True: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
186 instruction_offsets.append(file.tell() - (start_offset + offset)) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
187 if version == 0: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
188 time, opcode, size = unpack('<HBB', file.read(4)) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
189 elif version == 2: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
190 opcode, size, time, mask = unpack('<HHHH', file.read(8)) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
191 if opcode == 0xffff: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
192 break |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
193 size -= 8 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
194 data = file.read(size) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
195 if opcode in instructions: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
196 args = unpack('<%s' % instructions[opcode][0], data) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
197 else: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
198 args = (data,) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
199 logger.warn('unknown opcode %d', opcode) |
2
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
200 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
201 self.scripts[i].append((time, opcode, args)) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
202 if version == 0 and opcode == 0: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
203 break |
2
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
204 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
205 # Translate offsets to instruction pointers and register interrupts |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
206 for instr_offset, (j, instr) in zip(instruction_offsets, enumerate(self.scripts[i])): |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
207 time, opcode, args = instr |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
208 if version == 0: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
209 if opcode == 5: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
210 args = (instruction_offsets.index(args[0]),) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
211 elif opcode == 22: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
212 interrupt = args[0] |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
213 self.scripts[i].interrupts[interrupt] = j + 1 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
214 elif version == 2: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
215 if opcode == 4: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
216 args = (instruction_offsets.index(args[0]), args[1]) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
217 elif opcode == 5: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
218 args = (args[0], instruction_offsets.index(args[1]), args[2]) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
219 elif opcode == 21: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
220 interrupt = args[0] |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
221 self.scripts[i].interrupts[interrupt] = j + 1 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
222 elif opcode == 69: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
223 args = (args[0], args[1], instruction_offsets.index(args[2]), args[3]) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
224 self.scripts[i][j] = time, opcode, args |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
225 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
226 # Texture |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
227 if has_data: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
228 file.seek(start_offset + texture_offset) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
229 magic = file.read(4) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
230 assert magic == b'THTX' |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
231 zero, fmt, width, height, size = unpack('<HHHHI', file.read(12)) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
232 assert zero == 0 |
111 | 233 data = file.read(size) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
234 self.texture = Texture(width, height, fmt, data) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
57
diff
changeset
|
235 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
236 anm_list.append(self) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
57
diff
changeset
|
237 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
238 if next_offset: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
239 start_offset += next_offset |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
240 else: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
241 break |
2
057cb96907e3
Add preliminay support for EoSD's ANM format
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
242 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
402
diff
changeset
|
243 return anm_list |