Mercurial > touhou
comparison pytouhou/formats/msg.py @ 286:4838e9bab0f9
Implement dialogs (MSG files).
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 12 Feb 2012 16:06:03 +0100 |
parents | df8b2ab54639 |
children | 5492472963b0 |
comparison
equal
deleted
inserted
replaced
285:2100276c289d | 286:4838e9bab0f9 |
---|---|
27 4: ('I', 'pause'), | 27 4: ('I', 'pause'), |
28 5: ('hh', 'switch'), | 28 5: ('hh', 'switch'), |
29 6: ('', 'add_enemy_sprite'), | 29 6: ('', 'add_enemy_sprite'), |
30 7: ('I', 'change_music'), | 30 7: ('I', 'change_music'), |
31 8: ('hhs', 'display_character_line'), | 31 8: ('hhs', 'display_character_line'), |
32 9: ('I', None), | 32 9: ('I', 'show_scores'), |
33 10: ('', None), | 33 10: ('', 'freeze'), |
34 11: ('', 'next_level'), | 34 11: ('', 'next_level'), |
35 12: ('', None), | 35 12: ('', None), |
36 13: ('I', None), | 36 13: ('I', None), |
37 14: ('', None)} #TODO | 37 14: ('', None)} #TODO |
38 | 38 |
39 | 39 |
40 def __init__(self): | 40 def __init__(self): |
41 self.msgs = [[]] | 41 self.msgs = {} |
42 | 42 |
43 | 43 |
44 @classmethod | 44 @classmethod |
45 def read(cls, file): | 45 def read(cls, file): |
46 entry_count, = unpack('<I', file.read(4)) | 46 entry_count, = unpack('<I', file.read(4)) |
47 entry_offsets = unpack('<%dI' % entry_count, file.read(4 * entry_count)) | 47 entry_offsets = unpack('<%dI' % entry_count, file.read(4 * entry_count)) |
48 | 48 |
49 msg = cls() | 49 msg = cls() |
50 msg.msgs = [] | 50 msg.msgs = {} |
51 | 51 |
52 for offset in entry_offsets: | 52 for i, offset in enumerate(entry_offsets): |
53 if msg.msgs and offset == entry_offsets[0]: # In EoSD, Reimu’s scripts start at 0, and Marisa’s ones at 10. | 53 if msg.msgs and offset == entry_offsets[0]: # In EoSD, Reimu’s scripts start at 0, and Marisa’s ones at 10. |
54 continue # If Reimu has less than 10 scripts, the remaining offsets are equal to her first. | 54 continue # If Reimu has less than 10 scripts, the remaining offsets are equal to her first. |
55 | 55 |
56 msg.msgs.append([]) | 56 msg.msgs[i] = [] |
57 file.seek(offset) | 57 file.seek(offset) |
58 | 58 |
59 while True: | 59 while True: |
60 time, opcode, size = unpack('<HBB', file.read(4)) | 60 time, opcode, size = unpack('<HBB', file.read(4)) |
61 if time == 0 and opcode == 0: | 61 if time == 0 and opcode == 0: |
71 args = args[:-1] + (args[-1].decode('shift_jis'),) | 71 args = args[:-1] + (args[-1].decode('shift_jis'),) |
72 else: | 72 else: |
73 args = (data, ) | 73 args = (data, ) |
74 logger.warn('unknown msg opcode %d', opcode) | 74 logger.warn('unknown msg opcode %d', opcode) |
75 | 75 |
76 msg.msgs[-1].append((time, opcode, args)) | 76 msg.msgs[i].append((time, opcode, args)) |
77 | 77 |
78 | 78 |
79 return msg | 79 return msg |
80 | 80 |