class TypeReaderPlugin(Plugin):
    """
    type reader plugins
    """ class GenericTypeReader(BaseTypeReader):
    generic_target_type = None
    generic_reader_name = None
    is_generic_type = True
    generic_params = None
    readers = None

    def init_reader(self, file_platform=None, file_version=None):
        BaseTypeReader.init_reader(self, file_platform, file_version)
        if self.readers is None:
            self.readers = []
        for arg in self.generic_params:
            reader = self.stream.get_type_reader_by_type(arg)
            reader.init_reader(file_platform, file_version)
            self.readers.append(reader)

    @classmethod
    def create_from_type(cls, type_spec):
        # really need to figure out how to do this more cleanly
        body = dict(cls.__dict__)
        body['target_type'] = cls.generic_target_type + type_spec.suffix
        body['reader_name'] = cls.generic_reader_name + type_spec.suffix
        body['generic_params'] = [arg.full_name for arg in type_spec.generic_params]
        class_ = type(cls.__name__, cls.__bases__, body)
        return class_ class EnumTypeReader(ValueTypeReader):
    is_enum_type = True
    enum_type = None
    enum_type4 = None

    def read(self):
        value = self.stream.read_int32()
        if self.file_version == VERSION_40 and self.enum_type4 is not None:
            enum_type = self.enum_type4
        else:
            enum_type = self.enum_type
        if callable(enum_type):
            return enum_type(value)
        else:
            return value class XNASet(XNAList):
    __slots__ = ()

    def xml(self, parent=None, xml_tag='Set', xml_entry='Entry', attrib=None):
        root = XNAList.xml(self, parent=parent, xml_tag=xml_tag, xml_entry=xml_entry, attrib=attrib)
        return root class FaceOrientation(Enum):
    __slots__ = ()
    enum_values = dict(enumerate(['Left', 'Down', 'Back', 'Right', 'Top', 'Front'])) class LevelNodeType(Enum):
    __slots__ = ()
    enum_values = dict(enumerate(['Node', 'Hub', 'Lesser']))
    xml_tag = 'NodeType' class CollisionType(Enum):
    __slots__ = ()
    enum_values = dict(enumerate(['AllSides', 'TopOnly', 'None', 'Immaterial', 'TopNoStraightLedge'])) class Viewpoint(Enum):
    __slots__ = ()
    enum_values = dict(enumerate(['None', 'Front', 'Right', 'Back', 'Left', 'Up', 'Down', 'Perspective'])) class NpcAction(Enum):
    __slots__ = ()
    enum_values = dict(enumerate(['None', 'Idle', 'Idle2', 'Idle3', 'Walk', 'Turn', 'Talk', 'Burrow', 'Hide', 'ComeOut',
                                  'TakeOff', 'Fly', 'Land'])) class ActorType(Enum):
    __slots__ = ()
    enum_values = dict(enumerate(['None', 'Ladder', 'Bouncer', 'Sign', 'GoldenCube', 'PickUp', 'Bomb', 'Destructible',
                                  'DestructiblePermanent', 'Vase', 'Door', 'Heart', 'Watcher', 'Crystal', 'BlackHole',
                                  'Vine', 'BigBomb', 'TntBlock', 'TntPickup', 'MotorBlock', 'Hurt', 'Checkpoint',
                                  'TreasureChest', 'CubeShard', 'BigHeart', 'SkeletonKey', 'ExploSwitch', 'PushSwitch',
                                  'EightBitDoor', 'PushSwitchSticky', 'PushSwitchPermanent', 'SuckBlock', 'WarpGate',
                                  'OneBitDoor', 'SpinBlock', 'PivotHandle', 'FourBitDoor', 'LightningPlatform',
                                  'LightningGhost', 'Tombstone', 'SplitUpCube', 'UnlockedDoor', 'Hole', 'Couch',
                                  'Valve', 'Rumbler', 'Waterfall', 'Trickle', 'Drips', 'Geyser', 'ConnectiveRail',
                                  'BoltHandle', 'BoltNutBottom', 'BoltNutTop', 'CodeMachine', 'NumberCube',
                                  'LetterCube', 'TriSkull', 'Tome', 'SecretCube', 'LesserGate', 'Crumbler',
                                  'LaserEmitter', 'LaserBender', 'LaserReceiver', 'RebuildingHexahedron', 'TreasureMap',
                                  'Timeswitch', 'TimeswitchMovingPart', 'Mail', 'Mailbox', 'Bookcase', 'TwoBitDoor',
                                  'SixteenBitDoor', 'ThirtyTwoBitDoor', 'SixtyFourBitDoor', 'Owl', 'Bell',
                                  'RotatingGroup', 'BigWaterfall', 'Telescope', 'SinkPickup', 'QrCode', 'FpsPost',
                                  'PieceOfHeart', 'SecretPassage', 'Piston'])) class SurfaceType(Enum):
    __slots__ = ()
    enum_values = dict(enumerate(['Grass', 'Metal', 'Stone', 'Wood'])) class LiquidType(Enum):
    __slots__ = ()
    enum_values = dict(enumerate(['None', 'Water', 'Blood', 'Lava', 'Sewer', 'Purple', 'Green'])) class PathEndBehavior(Enum):
    __slots__ = ()
    enum_values = dict(enumerate(['Bounce', 'Loop', 'Stop'])) class ComparisonOperator(Enum):
    __slots__ = ()
    enum_values = {-1: 'None', 0: 'Equal', 1: 'Greater', 2: 'GreaterEqual', 3: 'Less', 4: 'LessEqual', 5: 'NotEqual'} class CodeInput(Enum):
    __slots__ = ()
    enum_values = {0: 'None', 1: 'Up', 2: 'Down', 4: 'Left', 8: 'Right', 16: 'SpinLeft', 32: 'SpinRight', 64: 'Jump'} class VibrationMotor(Enum):
    __slots__ = ()
    enum_values = dict(enumerate(['None', 'LeftLow', 'RightHigh']))
from xnb_parse.type_reader import TypeReaderPlugin, GenericTypeReader, EnumTypeReader
from xnb_parse.xna_types.xna_system import XNASet
from xnb_parse.xna_types.fez.fez_basic import (FaceOrientation, LevelNodeType, CollisionType, Viewpoint, NpcAction,
                                               ActorType, SurfaceType, LiquidType, PathEndBehavior, ComparisonOperator,
                                               CodeInput, VibrationMotor)
"""
FEZ basic type readers
"""

from __future__ import print_function



class FaceOrientationReader(EnumTypeReader, TypeReaderPlugin):
    target_type = 'FezEngine.FaceOrientation'
    reader_name = 'FezEngine.FaceOrientationReader'
    enum_type = FaceOrientation


class LevelNodeTypeReader(EnumTypeReader, TypeReaderPlugin):
    target_type = 'FezEngine.LevelNodeType'
    reader_name = 'FezEngine.LevelNodeTypeReader'
    enum_type = LevelNodeType


class CollisionTypeReader(EnumTypeReader, TypeReaderPlugin):
    target_type = 'FezEngine.CollisionType'
    reader_name = 'FezEngine.Readers.CollisionTypeReader'
    enum_type = CollisionType


class ViewpointReader(EnumTypeReader, TypeReaderPlugin):
    target_type = 'FezEngine.Viewpoint'
    reader_name = 'FezEngine.Readers.ViewpointReader'
    enum_type = Viewpoint


class NpcActionReader(EnumTypeReader, TypeReaderPlugin):
    target_type = 'FezEngine.Structure.NpcAction'
    reader_name = 'FezEngine.Readers.NpcActionReader'
    enum_type = NpcAction


class ActorTypeReader(EnumTypeReader, TypeReaderPlugin):
    target_type = 'FezEngine.Structure.ActorType'
    reader_name = 'FezEngine.Readers.ActorTypeReader'
    enum_type = ActorType


class SurfaceTypeReader(EnumTypeReader, TypeReaderPlugin):
    target_type = 'FezEngine.Structure.SurfaceType'
    reader_name = 'FezEngine.Readers.SurfaceTypeReader'

    enum_type = SurfaceType