# HG changeset patch # User Emmanuel Gil Peyrot # Date 1417006817 -3600 # Node ID 725bd24235a245d0e7c7356a1a89e2e662bb3fc0 # Parent 9dbc234ea0870b52ff068a565e8cacb72f76344f Make ANM0 pure-python again, by moving the Cython-dependent ANM class into its own module. diff --git a/pytouhou/formats/anm0.pxd b/pytouhou/formats/animation.pxd rename from pytouhou/formats/anm0.pxd rename to pytouhou/formats/animation.pxd --- a/pytouhou/formats/anm0.pxd +++ b/pytouhou/formats/animation.pxd @@ -1,4 +1,4 @@ -cdef class ANM: +cdef class Animation: cdef public long version cdef public unicode first_name, secondary_name cdef public dict sprites, scripts diff --git a/pytouhou/formats/anm0.pyx b/pytouhou/formats/animation.pyx rename from pytouhou/formats/anm0.pyx rename to pytouhou/formats/animation.pyx --- a/pytouhou/formats/anm0.pyx +++ b/pytouhou/formats/animation.pyx @@ -1,6 +1,6 @@ # -*- encoding: utf-8 -*- ## -## Copyright (C) 2011 Thibaut Girka +## Copyright (C) 2014 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 @@ -12,34 +12,7 @@ ## GNU General Public License for more details. ## -"""ANM0 files handling. - -This module provides classes for handling the ANM0 file format. -The ANM0 format is a format used in Touhou 6: EoSD to describe sprites -and animations. -Almost everything rendered in the game is described by an ANM0 file. -""" - -from struct import pack, unpack -from pytouhou.utils.helpers import read_string, get_logger - -from pytouhou.formats import WrongFormatError -from pytouhou.formats.thtx import Texture - - -logger = get_logger(__name__) - -#TODO: refactor/clean up - - -class Script(list): - def __init__(self): - list.__init__(self) - self.interrupts = {} - - - -cdef class ANM: +cdef class Animation: def __init__(self): self.version = 0 self.size_inv[:] = [0, 0] @@ -52,199 +25,3 @@ cdef class ANM: def __set__(self, tuple value): width, height = value self.size_inv[:] = [1. / width, 1. / height] - - - -class ANM0(object): - _instructions = {0: {0: ('', 'delete'), - 1: ('I', 'set_sprite'), - 2: ('ff', 'set_scale'), - 3: ('I', 'set_alpha'), - 4: ('BBBx', 'set_color'), - 5: ('I', 'jump'), - 7: ('', 'toggle_mirrored'), - 9: ('fff', 'set_3d_rotations'), - 10: ('fff', 'set_3d_rotations_speed'), - 11: ('ff', 'set_scale_speed'), - 12: ('ii', 'fade'), - 13: ('', 'set_blendmode_add'), - 14: ('', 'set_blendmode_alphablend'), - 15: ('', 'keep_still'), - 16: ('ii', 'set_random_sprite'), - 17: ('fff', 'set_3d_translation'), - 18: ('fffi', 'move_to_linear'), - 19: ('fffi', 'move_to_decel'), - 20: ('fffi', 'move_to_accel'), - 21: ('', 'wait'), - 22: ('i', 'interrupt_label'), - 23: ('', 'set_corner_relative_placement'), - 24: ('', 'wait_ex'), - 25: ('i', 'set_allow_offset'), #TODO: better name - 26: ('i', 'set_automatic_orientation'), - 27: ('f', 'shift_texture_x'), - 28: ('f', 'shift_texture_y'), - 29: ('i', 'set_visible'), - 30: ('ffi', 'scale_in'), - 31: ('i', None)}, - - 2: {0: ('', 'noop'), - 1: ('', 'delete'), - 2: ('', 'keep_still'), - 3: ('I', 'set_sprite'), - 4: ('II', 'jump_bis'), - 5: ('III', 'jump_ex'), - 6: ('fff', 'set_3d_translation'), - 7: ('ff', 'set_scale'), - 8: ('I', 'set_alpha'), - 9: ('BBBx', 'set_color'), - 10: ('', 'toggle_mirrored'), - 12: ('fff', 'set_3d_rotations'), - 13: ('fff', 'set_3d_rotations_speed'), - 14: ('ff', 'set_scale_speed'), - 15: ('ii', 'fade'), - 16: ('I', 'set_blendmode'), - 17: ('fffi', 'move_to_linear'), - 18: ('fffi', 'move_to_decel'), - 19: ('fffi', 'move_to_accel'), - 20: ('', 'wait'), - 21: ('i', 'interrupt_label'), - 22: ('', 'set_corner_relative_placement'), - 23: ('', 'wait_ex'), - 24: ('i', 'set_allow_offset'), #TODO: better name - 25: ('i', 'set_automatic_orientation'), - 26: ('f', 'shift_texture_x'), - 27: ('f', 'shift_texture_y'), - 28: ('i', 'set_visible'), - 29: ('ffi', 'scale_in'), - 30: ('i', None), - 31: ('I', None), - 32: ('IIfff', 'move_in_linear_bis'), - 33: ('IIBBBx', 'change_color_in'), - 34: ('III', 'fade_bis'), - 35: ('IIfff', 'rotate_in_bis'), - 36: ('IIff', 'scale_in_bis'), - 37: ('II', 'set_int'), - 38: ('ff', 'set_float'), - 42: ('ff', 'decrement_float'), - 50: ('fff', 'add_float'), - 52: ('fff', 'substract_float'), - 55: ('III', 'divide_int'), - 59: ('II', 'set_random_int'), - 60: ('ff', 'set_random_float'), - 69: ('IIII', 'branch_if_not_equal'), - 79: ('I', 'wait_duration'), - 80: ('I', None)}} - - - @classmethod - def read(cls, file): - anm_list = [] - start_offset = 0 - while True: - file.seek(start_offset) - nb_sprites, nb_scripts, zero1 = unpack('width, 1. / height] - - - -class ANM0(object): +class ANM0(Animation): _instructions = {0: {0: ('', 'delete'), 1: ('I', 'set_sprite'), 2: ('ff', 'set_scale'), @@ -163,7 +148,7 @@ class ANM0(object): sprite_offsets = [unpack('