# HG changeset patch # User Emmanuel Gil Peyrot # Date 1315751674 25200 # Node ID 2cad2e84a49ee16f8b95d61dc4e1ae0fce46b388 # Parent fba45c37ec997006dcae9e17e25eeb10c516f144 Add reading support for the MSG format. diff --git a/pytouhou/formats/msg.py b/pytouhou/formats/msg.py new file mode 100644 --- /dev/null +++ b/pytouhou/formats/msg.py @@ -0,0 +1,90 @@ +# -*- encoding: utf-8 -*- +## +## Copyright (C) 2011 Emmanuel Gil Peyrot +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published +## by the Free Software Foundation; version 3 only. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## + +import struct +from struct import pack, unpack, calcsize +from pytouhou.utils.helpers import read_string + +from pytouhou.utils.helpers import get_logger + +logger = get_logger(__name__) + +class MSG(object): + _instructions = {0: ('', None), + 1: ('hh', None), + 2: ('hh', 'change_face'), + 3: ('hhs', 'display_dialog_line'), + 4: ('I', 'pause'), + 5: ('hh', 'switch'), + 6: ('', 'add_enemy_sprite'), + 7: ('I', 'change_music'), + 8: ('hhs', 'display_character_line'), + 9: ('I', None), + 10: ('', None), + 11: ('', 'next_level'), + 12: ('', None), + 13: ('I', None), + 14: ('', None)} #TODO + + + def __init__(self): + self.msgs = [[]] + + + @classmethod + def read(cls, file): + entry_count, = unpack('