"""Support for simplified access to data on nodes of type omni.graph.nodes.ReadGamepadState

Reads the current state of the gamepad
"""


import omni.graph.core as og
import omni.graph.core._omni_graph_core as _og
import omni.graph.tools.ogn as ogn



class OgnReadGamepadStateDatabase(og.Database):
    """Helper class providing simplified access to data on nodes of type omni.graph.nodes.ReadGamepadState

    Class Members:
        node: Node being evaluated

    Attribute Value Properties:
        Inputs:
            inputs.deadzone
            inputs.gamepadElement
            inputs.gamepadId
        Outputs:
            outputs.isPressed
            outputs.value

    Predefined Tokens:
        tokens.LeftStickXAxis
        tokens.LeftStickYAxis
        tokens.RightStickXAxis
        tokens.RightStickYAxis
        tokens.LeftTrigger
        tokens.RightTrigger
        tokens.FaceButtonBottom
        tokens.FaceButtonRight
        tokens.FaceButtonLeft
        tokens.FaceButtonTop
        tokens.LeftShoulder
        tokens.RightShoulder
        tokens.SpecialLeft
        tokens.SpecialRight
        tokens.LeftStickButton
        tokens.RightStickButton
        tokens.DpadUp
        tokens.DpadRight
        tokens.DpadDown
        tokens.DpadLeft
    """

    # Imprint the generator and target ABI versions in the file for JIT generation
    GENERATOR_VERSION = (1, 41, 3)
    TARGET_VERSION = (2, 139, 12)

    # This is an internal object that provides per-class storage of a per-node data dictionary
    PER_NODE_DATA = {}

    # This is an internal object that describes unchanging attributes in a generic way
    # The values in this list are in no particular order, as a per-attribute tuple
    #     Name, Type, ExtendedTypeIndex, UiName, Description, Metadata,
    #     Is_Required, DefaultValue, Is_Deprecated, DeprecationMsg
    # You should not need to access any of this data directly, use the defined database interfaces
    INTERFACE = og.Database._get_interface([
        ('inputs:deadzone', 'float', 0, 'Deadzone', 'Threshold from [0, 1] that the value must pass for it to be registered as input', {ogn.MetadataKeys.DEFAULT: '0.1'}, True, 0.1, False, ''),
        ('inputs:gamepadElement', 'token', 0, 'Element', 'The gamepad element to check the state of', {'displayGroup': 'parameters', ogn.MetadataKeys.ALLOWED_TOKENS: 'Left Stick X Axis,Left Stick Y Axis,Right Stick X Axis,Right Stick Y Axis,Left Trigger,Right Trigger,Face Button Bottom,Face Button Right,Face Button Left,Face Button Top,Left Shoulder,Right Shoulder,Special Left,Special Right,Left Stick Button,Right Stick Button,D-Pad Up,D-Pad Right,D-Pad Down,D-Pad Left', ogn.MetadataKeys.ALLOWED_TOKENS_RAW: '{"LeftStickXAxis": "Left Stick X Axis", "LeftStickYAxis": "Left Stick Y Axis", "RightStickXAxis": "Right Stick X Axis", "RightStickYAxis": "Right Stick Y Axis", "LeftTrigger": "Left Trigger", "RightTrigger": "Right Trigger", "FaceButtonBottom": "Face Button Bottom", "FaceButtonRight": "Face Button Right", "FaceButtonLeft": "Face Button Left", "FaceButtonTop": "Face Button Top", "LeftShoulder": "Left Shoulder", "RightShoulder": "Right Shoulder", "SpecialLeft": "Special Left", "SpecialRight": "Special Right", "LeftStickButton": "Left Stick Button", "RightStickButton": "Right Stick Button", "DpadUp": "D-Pad Up", "DpadRight": "D-Pad Right", "DpadDown": "D-Pad Down", "DpadLeft": "D-Pad Left"}', ogn.MetadataKeys.DEFAULT: '"Left Stick X Axis"'}, True, "Left Stick X Axis", False, ''),
        ('inputs:gamepadId', 'uint', 0, 'Gamepad ID', 'Gamepad id number starting from 0', {ogn.MetadataKeys.DEFAULT: '0'}, True, 0, False, ''),
        ('outputs:isPressed', 'bool', 0, None, 'True if the gamepad element is currently pressed, false otherwise', {}, True, None, False, ''),
        ('outputs:value', 'float', 0, None, 'Value of how much the gamepad element is being pressed. [0, 1] for buttons [-1, 1] for stick and trigger', {}, True, None, False, ''),
    ])

    class tokens:
        LeftStickXAxis = "Left Stick X Axis"
        LeftStickYAxis = "Left Stick Y Axis"
        RightStickXAxis = "Right Stick X Axis"
        RightStickYAxis = "Right Stick Y Axis"
        LeftTrigger = "Left Trigger"
        RightTrigger = "Right Trigger"
        FaceButtonBottom = "Face Button Bottom"
        FaceButtonRight = "Face Button Right"
        FaceButtonLeft = "Face Button Left"
        FaceButtonTop = "Face Button Top"
        LeftShoulder = "Left Shoulder"
        RightShoulder = "Right Shoulder"
        SpecialLeft = "Special Left"
        SpecialRight = "Special Right"
        LeftStickButton = "Left Stick Button"
        RightStickButton = "Right Stick Button"
        DpadUp = "D-Pad Up"
        DpadRight = "D-Pad Right"
        DpadDown = "D-Pad Down"
        DpadLeft = "D-Pad Left"

    class ValuesForInputs(og.DynamicAttributeAccess):
        LOCAL_PROPERTY_NAMES = { }
        """Helper class that creates natural hierarchical access to input attributes"""
        def __init__(self, node: og.Node, attributes, dynamic_attributes: og.DynamicAttributeInterface):
            """Initialize simplified access for the attribute data"""
            context = node.get_graph().get_default_graph_context()
            super().__init__(context, node, attributes, dynamic_attributes)
            self._batchedReadAttributes = []
            self._batchedReadValues = []

        @property
        def deadzone(self):
            data_view = og.AttributeValueHelper(self._attributes.deadzone)
            return data_view.get()

        @deadzone.setter
        def deadzone(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.deadzone)
            data_view = og.AttributeValueHelper(self._attributes.deadzone)
            data_view.set(value)

        @property
        def gamepadElement(self):
            data_view = og.AttributeValueHelper(self._attributes.gamepadElement)
            return data_view.get()

        @gamepadElement.setter
        def gamepadElement(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.gamepadElement)
            data_view = og.AttributeValueHelper(self._attributes.gamepadElement)
            data_view.set(value)

        @property
        def gamepadId(self):
            data_view = og.AttributeValueHelper(self._attributes.gamepadId)
            return data_view.get()

        @gamepadId.setter
        def gamepadId(self, value):
            if self._setting_locked:
                raise og.ReadOnlyError(self._attributes.gamepadId)
            data_view = og.AttributeValueHelper(self._attributes.gamepadId)
            data_view.set(value)

        def _prefetch(self):
            readAttributes = self._batchedReadAttributes
            newValues = _og._prefetch_input_attributes_data(readAttributes)
            if len(readAttributes) == len(newValues):
                self._batchedReadValues = newValues

    class ValuesForOutputs(og.DynamicAttributeAccess):
        LOCAL_PROPERTY_NAMES = { }
        """Helper class that creates natural hierarchical access to output attributes"""
        def __init__(self, node: og.Node, attributes, dynamic_attributes: og.DynamicAttributeInterface):
            """Initialize simplified access for the attribute data"""
            context = node.get_graph().get_default_graph_context()
            super().__init__(context, node, attributes, dynamic_attributes)
            self._batchedWriteValues = { }

        @property
        def isPressed(self):
            data_view = og.AttributeValueHelper(self._attributes.isPressed)
            return data_view.get()

        @isPressed.setter
        def isPressed(self, value):
            data_view = og.AttributeValueHelper(self._attributes.isPressed)
            data_view.set(value)

        @property
        def value(self):
            data_view = og.AttributeValueHelper(self._attributes.value)
            return data_view.get()

        @value.setter
        def value(self, value):
            data_view = og.AttributeValueHelper(self._attributes.value)
            data_view.set(value)

        def _commit(self):
            _og._commit_output_attributes_data(self._batchedWriteValues)
            self._batchedWriteValues = { }

    class ValuesForState(og.DynamicAttributeAccess):
        """Helper class that creates natural hierarchical access to state attributes"""
        def __init__(self, node: og.Node, attributes, dynamic_attributes: og.DynamicAttributeInterface):
            """Initialize simplified access for the attribute data"""
            context = node.get_graph().get_default_graph_context()
            super().__init__(context, node, attributes, dynamic_attributes)

    def __init__(self, node):
        super().__init__(node)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_INPUT)
        self.inputs = OgnReadGamepadStateDatabase.ValuesForInputs(node, self.attributes.inputs, dynamic_attributes)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_OUTPUT)
        self.outputs = OgnReadGamepadStateDatabase.ValuesForOutputs(node, self.attributes.outputs, dynamic_attributes)
        dynamic_attributes = self.dynamic_attribute_data(node, og.AttributePortType.ATTRIBUTE_PORT_TYPE_STATE)
        self.state = OgnReadGamepadStateDatabase.ValuesForState(node, self.attributes.state, dynamic_attributes)
