class BaseTypeReader(object):
    target_type = None
    reader_name = None
    is_value_type = False
    is_generic_type = False
    is_enum_type = False
    file_platform = None
    file_version = None

    def __init__(self, stream=None, version=None):
        self.stream = stream
        self.version = version

    def __str__(self):
        return self.reader_name

    def read(self):
        raise ReaderError("Unimplemented type reader: '{}'".format(self.reader_name))

    def init_reader(self, file_platform=None, file_version=None):
        self.file_platform = file_platform
        self.file_version = file_version class ReaderError(Error):
    pass class TypeReaderPlugin(Plugin):
    """
    type reader plugins
    """ class ColourModifier(Modifier):
    def __init__(self, initial_colour, ultimate_colour):
        self.initial_colour = initial_colour
        self.ultimate_colour = ultimate_colour

    def __repr__(self):
        return 'ColourModifier(initial_colour={}, ultimate_colour={})'.format(self.initial_colour, self.ultimate_colour) class LinearGravityModifier(Modifier):
    def __init__(self, gravity):
        self.gravity = gravity

    def __repr__(self):
        return 'LinearGravityModifier(gravity={})'.format(self.gravity) class ModifierCollection(object):
    def __init__(self, modifiers):
        self.modifiers = modifiers

    def __repr__(self):
        return '{}'.format(self.modifiers) class OpacityModifier(Modifier):
    def __init__(self, initial, ultimate):
        self.initial = initial
        self.ultimate = ultimate

    def __repr__(self):
        return 'OpacityModifier(initial={}, ultimate={})'.format(self.initial, self.ultimate) class RotationRateModifier(Modifier):
    def __init__(self, initial_rate, final_rate):
        self.initial_rate = initial_rate
        self.final_rate = final_rate

    def __repr__(self):
        return 'RotationRateModifier(initial_rate={}, final_rate={})'.format(self.initial_rate, self.final_rate) class ScaleModifier(Modifier):
    def __init__(self, initial, ultimate):
        self.initial = initial
        self.ultimate = ultimate

    def __repr__(self):
        return 'ScaleModifier(initial={}, ultimate={})'.format(self.initial, self.ultimate) class ColourInterpolatorModifier(Modifier):
    def __init__(self, initial_colour, middle_colour, middle_position, final_colour):
        self.initial_colour = initial_colour
        self.middle_colour = middle_colour
        self.middle_position = middle_position
        self.final_colour = final_colour

    def __repr__(self):
        return 'ColourInterpolatorModifier(' \
               'initial_colour={}, middle_colour={}, middle_position={}, final_colour={})'.format(
                self.initial_colour, self.middle_colour, self.middle_position, self.final_colour) class ColourMergeModifier(Modifier):
    def __init__(self, merge_colour):
        self.merge_colour = merge_colour

    def __repr__(self):
        return 'ColourMergeModifier(merge_colour={})'.format(self.merge_colour) class DampingModifier(Modifier):
    def __init__(self, damping_coefficient):
        self.damping_coefficient = damping_coefficient

    def __repr__(self):
        return 'DampingModifier(damping_coefficient={})'.format(self.damping_coefficient) class HueShiftModifier(Modifier):
    def __init__(self, hue_shift):
        self.hue_shift = hue_shift

    def __repr__(self):
        return 'HueShiftModifier(hue_shift={})'.format(self.hue_shift) class OpacityInterpolatorModifier(Modifier):
    def __init__(self, initial_opacity, middle_opacity, middle_position, final_opacity):
        self.initial_opacity = initial_opacity
        self.middle_opacity = middle_opacity
        self.middle_position = middle_position
        self.final_opacity = final_opacity

    def __repr__(self):
        return 'OpacityInterpolatorModifier(' \
               'initial_opacity={}, middle_opacity={}, middle_position={}, final_opacity={})'.format(
                self.initial_opacity, self.middle_opacity, self.middle_position, self.final_opacity) class OpacityOscillator(Modifier):
    def __init__(self, frequency, minimum_opacity, maximum_opacity):
        self.frequency = frequency
        self.minimum_opacity = minimum_opacity
        self.maximum_opacity = maximum_opacity

    def __repr__(self):
        return 'OpacityOscillator(frequency={}, minimum_opacity={}, maximum_opacity={})'.format(
            self.frequency, self.minimum_opacity, self.maximum_opacity) class RotationModifier(Modifier):
    def __init__(self, rotation_rate):
        self.rotation_rate = rotation_rate

    def __repr__(self):
        return 'RotationModifier(rotation_rate={})'.format(self.rotation_rate) class TrajectoryRotationModifier(Modifier):
    def __init__(self, rotation_offset):
        self.rotation_offset = rotation_offset

    def __repr__(self):
        return 'TrajectoryRotationModifier(rotation_offset={})'.format(self.rotation_offset) class RadialForceModifier(Modifier):
    def __init__(self, radius, position, force, strength):
        self.radius = radius
        self.position = position
        self.force = force
        self.strength = strength

    def __repr__(self):
        return 'RadialForceModifier(radius={}, position={}, force={}, strength={})'.format(
            self.radius, self.position, self.force, self.strength) class RadialGravityModifier(Modifier):
    def __init__(self, radius, position):
        self.radius = radius
        self.position = position

    def __repr__(self):
        return 'RadialGravityModifier(radius={}, position={})'.format(self.radius, self.position) class RectangleConstraintDeflector(Modifier):
    def __init__(self, width, height, position):
        self.width = width
        self.height = height
        self.position = position

    def __repr__(self):
        return 'RectangleConstraintDeflector(width={}, height={}, position={})'.format(
            self.width, self.height, self.position) class RectangleForceModifier(Modifier):
    def __init__(self, width, height, position, force, strength):
        self.width = width
        self.height = height
        self.position = position
        self.force = force
        self.strength = strength

    def __repr__(self):
        return 'RectangleForceModifier(width={}, height={}, position={}, force={}, strength={})'.format(
            self.width, self.height, self.position, self.force, self.strength) class ScaleInterpolatorModifier(Modifier):
    def __init__(self, initial_scale, middle_scale, middle_position, final_scale):
        self.initial_scale = initial_scale
        self.middle_scale = middle_scale
        self.middle_position = middle_position
        self.final_scale = final_scale

    def __repr__(self):
        return 'ScaleInterpolatorModifier(' \
               'initial_scale={}, middle_scale={}, middle_position={}, final_scale={})'.format(
                self.initial_scale, self.middle_scale, self.middle_position, self.final_scale) class ScaleMergeModifier(Modifier):
    def __init__(self, merge_scale):
        self.merge_scale = merge_scale

    def __repr__(self):
        return 'ScaleMergeModifier(merge_scale={])'.format(self.merge_scale) class ScaleOscillator(Modifier):
    def __init__(self, frequency, minimum_scale, maximum_scale):
        self.frequency = frequency
        self.minimum_scale = minimum_scale
        self.maximum_scale = maximum_scale

    def __repr__(self):
        return 'ScaleOscillator(frequency={}, minimum_scale={}, maximum_scale={})'.format(
            self.frequency, self.minimum_scale, self.maximum_scale) class SineForceModifier(Modifier):
    def __init__(self, rotation, frequency, amplitude):
        self.rotation = rotation
        self.frequency = frequency
        self.amplitude = amplitude

    def __repr__(self):
        return 'SineForceModifier(rotation={}, frequency={}, amplitude={})'.format(
            self.rotation, self.frequency, self.amplitude) class VelocityClampModifier(Modifier):
    def __init__(self, maximum_velocity):
        self.maximum_velocity = maximum_velocity

    def __repr__(self):
        return 'VelocityClampModifier(maximum_velocity={})'.format(self.maximum_velocity) class XNAList(list):
    __slots__ = ()

    def xml(self, parent=None, xml_tag='List', xml_entry='Entry', attrib=None):
        if sys.version < '3':
            conv = unicode
        else:
            conv = str
        if parent is None:
            root = ET.Element(xml_tag)
        else:
            root = ET.SubElement(parent, xml_tag)
        for cur_value in self:
            if hasattr(cur_value, 'xml'):
                cur_value.xml(root)
            elif attrib is not None:
                cur_tag = ET.SubElement(root, xml_entry)
                cur_tag.set(attrib, conv(cur_value))
            else:
                cur_tag = ET.SubElement(root, xml_entry)
                cur_tag.text = conv(cur_value)
        return root
from xnb_parse.type_reader import BaseTypeReader, ReaderError, TypeReaderPlugin
from xnb_parse.xna_types.mercury.modifiers import (ColourModifier, LinearGravityModifier, ModifierCollection,
                                                   OpacityModifier, RotationRateModifier, ScaleModifier,
                                                   ColourInterpolatorModifier, ColourMergeModifier, DampingModifier,
                                                   HueShiftModifier, OpacityInterpolatorModifier, OpacityOscillator,
                                                   RotationModifier, TrajectoryRotationModifier, RadialForceModifier,
                                                   RadialGravityModifier, RectangleConstraintDeflector,
                                                   RectangleForceModifier, ScaleInterpolatorModifier,
                                                   ScaleMergeModifier, ScaleOscillator, SineForceModifier,
                                                   VelocityClampModifier)
from xnb_parse.xna_types.xna_system import XNAList

    def read(self):
        gravity = self.stream.read_vector2()
        return LinearGravityModifier(gravity)


class ColourInterpolatorModifierReader(ModifierReader, TypeReaderPlugin):
    target_type = 'ProjectMercury.Modifiers.ColourInterpolatorModifier'
    reader_name = \
        'Microsoft.Xna.Framework.Content.ReflectiveReader`1[ProjectMercury.Modifiers.ColourInterpolatorModifier]'

    def read(self):
        initial_colour = self.stream.read_vector3()
        middle_colour = self.stream.read_vector3()
        middle_position = self.stream.read_single()
        final_colour = self.stream.read_vector3()
        return ColourInterpolatorModifier(initial_colour, middle_colour, middle_position, final_colour)


class ColourMergeModifierReader(ModifierReader, TypeReaderPlugin):
    target_type = 'ProjectMercury.Modifiers.ColourMergeModifier'
    reader_name = 'Microsoft.Xna.Framework.Content.ReflectiveReader`1[ProjectMercury.Modifiers.ColourMergeModifier]'

    def read(self):
        merge_colour = self.stream.read_vector3()
        return ColourMergeModifier(merge_colour)


class DampingModifierReader(ModifierReader, TypeReaderPlugin):
    target_type = 'ProjectMercury.Modifiers.DampingModifier'
    reader_name = 'Microsoft.Xna.Framework.Content.ReflectiveReader`1[ProjectMercury.Modifiers.DampingModifier]'

    def read(self):
        damping_coefficient = self.stream.read_single()
        return DampingModifier(damping_coefficient)


class HueShiftModifierReader(ModifierReader, TypeReaderPlugin):
    target_type = 'ProjectMercury.Modifiers.HueShiftModifier'
    reader_name = 'Microsoft.Xna.Framework.Content.ReflectiveReader`1[ProjectMercury.Modifiers.HueShiftModifier]'

    def read(self):
        hue_shift = self.stream.single()
        return HueShiftModifier(hue_shift)


class OpacityInterpolatorModifierReader(ModifierReader, TypeReaderPlugin):
    target_type = 'ProjectMercury.Modifiers.OpacityInterpolatorModifier'
    reader_name = \
        'Microsoft.Xna.Framework.Content.ReflectiveReader`1[ProjectMercury.Modifiers.OpacityInterpolatorModifier]'

    def read(self):
        initial_opacity = self.stream.read_single()
        middle_opacity = self.stream.read_single()
        middle_position = self.stream.read_single()
        final_opacity = self.stream.read_single()
        return OpacityInterpolatorModifier(initial_opacity, middle_opacity, middle_position, final_opacity)


class OpacityOscillatorReader(ModifierReader, TypeReaderPlugin):
    target_type = 'ProjectMercury.Modifiers.OpacityOscillator'
    reader_name = 'Microsoft.Xna.Framework.Content.ReflectiveReader`1[ProjectMercury.Modifiers.OpacityOscillator]'

    def read(self):
        frequency = self.stream.read_single()
        minimum_opacity = self.stream.read_single()
        maximum_opacity = self.stream.read_single()
        return OpacityOscillator(frequency, minimum_opacity, maximum_opacity)


class RotationModifierReader(ModifierReader, TypeReaderPlugin):
    target_type = 'ProjectMercury.Modifiers.RotationModifier'
    reader_name = 'Microsoft.Xna.Framework.Content.ReflectiveReader`1[ProjectMercury.Modifiers.RotationModifier]'

    def read(self):
        rotation_rate = self.stream.read_single()
        return RotationModifier(rotation_rate)


class TrajectoryRotationModifierReader(ModifierReader, TypeReaderPlugin):
    target_type = 'ProjectMercury.Modifiers.TrajectoryRotationModifier'
    reader_name = \
        'Microsoft.Xna.Framework.Content.ReflectiveReader`1[ProjectMercury.Modifiers.TrajectoryRotationModifier]'

    def read(self):
        rotation_offset = self.stream.read_single()
        return TrajectoryRotationModifier(rotation_offset)


class RadialForceModifierReader(ModifierReader, TypeReaderPlugin):
    target_type = 'ProjectMercury.Modifiers.RadialForceModifier'
    reader_name = 'Microsoft.Xna.Framework.Content.ReflectiveReader`1[ProjectMercury.Modifiers.RadialForceModifier]'

    def read(self):
        radius = self.stream.read_single()
        position = self.stream.read_vector2()
        force = self.stream.read_vector2()
        strength = self.stream.read_single()
        return RadialForceModifier(radius, position, force, strength)


class RadialGravityModifierReader(ModifierReader, TypeReaderPlugin):
    target_type = 'ProjectMercury.Modifiers.RadialGravityModifier'
    reader_name = 'Microsoft.Xna.Framework.Content.ReflectiveReader`1[ProjectMercury.Modifiers.RadialGravityModifier]'

    def read(self):
        radius = self.stream.read_single()
        position = self.stream.read_vector2()
        return RadialGravityModifier(radius, position)


class RectangleConstraintDeflectorReader(ModifierReader, TypeReaderPlugin):
    target_type = 'ProjectMercury.Modifiers.RectangleConstraintDeflector'
    reader_name = \
        'Microsoft.Xna.Framework.Content.ReflectiveReader`1[ProjectMercury.Modifiers.RectangleConstraintDeflector]'

    def read(self):
        width = self.stream.read_single()
        height = self.stream.read_single()
        position = self.stream.read_vector2()

        return RectangleConstraintDeflector(width, height, position)