
    ^j                        d Z ddlmZ ddlZddlZddlZddl	m
Z
 ddlmZ ej                            d          xZr ej        de           d!dZd"dZ G d d          Zd#dZd$dZd%dZd&d ZdS )'a  Game Controller support.

This module provides an interface for Game Controller devices, which are a
subset of Joysticks. Game Controllers have consistent button and axis mapping,
which resembles common dual-stick home video game console controllers.
Devices that are of this design can be automatically mapped to the "virtual"
Game Controller layout, providing a consistent abstraction for a large number
of different devices, with no tedious button and axis mapping for each one.
To achieve this, an internal mapping database contains lists of device ids
and their corresponding button and axis mappings. The mapping database is in
the same format as originated by the `SDL` library, which has become a
semi-standard and is in common use. Most popular controllers are included in
the built-in database, and additional mappings can be added at runtime.

Some Joysticks, such as Flight Sticks, etc., do not necessarily fit into the
layout (and limitations) of GameControllers. For those such devices, it is
recommended to use the Joystick interface instead.

To query which GameControllers are available, call :py:func:`get_controllers`.

.. versionadded:: 2.0
    )annotationsN   )Sign)mapping_listSDL_GAMECONTROLLERCONFIGvalueintreturnc                B    t           j        dk    r| dz  | dz	  z  dz  S | S )z*Ensure 16bit value is in Big Endian formatlittle   i  )_sys	byteorder)r   s    R/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/input/controller.py
_swap_le16r   &   s,    ~!!!
+v55L    busvendorproductversionnamestr	signaturedatac                    t          |           } t          |          }t          |          }t          |          }| dd|dd|dd|ddS )z=Create an SDL2 style GUID string from a device's identifiers.04x0000)r   )r   r   r   r   r   r   r   s          r   create_guidr   -   si     S//CF!!G!!GMMM6MMM7MMMGMMMMMr   c                  .    e Zd ZdZej        fddZd	 Zd
S )Relationcontrol_typeindexsignr"   r   r#   r	   r$   r   c                0    || _         || _        || _        d S )Nr!   )selfr"   r#   r$   s       r   __init__zRelation.__init__;   s    (
			r   c                8    d| j          d| j         d| j         dS )NzRelation(type=z, index=z, sign=)r!   )r&   s    r   __repr__zRelation.__repr__@   s*    Z 1ZZ4:ZZdiZZZZr   N)r"   r   r#   r	   r$   r   )__name__
__module____qualname__	__slots__r   DEFAULTr'   r*    r   r   r    r    8   sK        /ICG<     
[ [ [ [ [r   r    mapping_string dict[str, str | Relation] | Nonec           	        g d}	 |                                                      d          ^}}}t          ||          }n# t          $ r Y dS w xY w|D ]q}d|vr|                    d          ^}}}	||vr%d|v r"|                     d          }t          j        }
nXd|v r"|                     d          }t          j        }
n2d|v r"|                     d          }t          j        }
nt          j        }
|	                    d	          r*t          d
t          |dd                   |
          ||<   |	                    d          r+t          dt          |dd                   |
          ||<   "|	                    d          r:t          dt          |                    d          d                   |
          ||<   s|S )zParse a SDL2 style GameController mapping string.

    Args:
        mapping_string: A string containing an SDL style controller mapping.
    )guidebackstartabxyleftshoulder	leftstickrightshoulder
rightstickdpupdpdowndpleftdprightlefttriggerrighttriggerleftxleftyrightxrighty,)guidr   N:+-~r8   buttonr   r7   axish0hat0.)stripsplitdict
ValueErrorr   POSITIVENEGATIVEINVERTEDr/   
startswithr    r	   )r1   
valid_keysrJ   r   split_mapping	relationsitemkeyrelation_stringetcr$   s              r   _parse_mappingrc   D   s   W W WJ
%3%9%9%;%;%A%A#%F%F"d]d...		   tt  X Xd??%)ZZ__"_sj   /!!-33C88O=DDO##-33C88O=DDO##-33C88O=DD<D %%c** 	X%hOABB4G0H0H$OOIcNN'',, 	X%fc/!""2E.F.FMMIcNN''-- 	X%fc/2G2G2L2LQ2O.P.PRVWWIcNs   ;A 
AArJ   c                    t           D ]P}|                    |           s	 t          |          c S # t          $ r t	          j        d|            Y Mw xY wdS )zReturn a mapping for the passed device GUID.

    Args:
        guid: A device GUID; see :py:meth:`~pyglet.input.Device.get_guid`
    z$Unable to parse Controller mapping: N)r   r[   rc   rW   	_warningswarn)rJ   mappings     r   get_mappingrh   x   s        !!$'' 		!'***** 	 	 	NK'KKLLLH	 s   2!AAfilenameNonec                    t          |           5 }t          |                                           ddd           dS # 1 swxY w Y   dS )zAdd one or more mappings from a file.

    Given a file path, open and parse the file for mappings.

    Args:
        filename: A file path.
    N)openadd_mappings_from_stringread)ri   fs     r   add_mappings_from_filerp      s     
h +1 ***+ + + + + + + + + + + + + + + + + +s   "?AAstringc                    |                                  D ]A}|                                }|                    d          r,t          j        d|           BdS )z}Add one or more mappings from a string.

        Args:
            string: A string containing one or more mappings,
        #r   N)
splitlinesrT   r[   r   insert)rq   lines     r   rm   rm      sc     !!## % %zz||??3 	At$$$$	% %r   )r   r	   r
   r	   )r   r	   r   r	   r   r	   r   r	   r   r   r   r	   r   r	   r
   r   )r1   r   r
   r2   )rJ   r   r
   r2   )ri   r   r
   rj   )rq   r   r
   rj   )__doc__
__future__r   os_ossysr   warningsre   baser   controller_dbr   environget_env_configru   r   r   r    rc   rh   rp   rm   r0   r   r   <module>r      sU   , # " " " " "                   ' ' ' ' ' ' +//"<===; (L;'''   N N N N	[ 	[ 	[ 	[ 	[ 	[ 	[ 	[1 1 1 1h   "	+ 	+ 	+ 	+
% 
% 
% 
% 
% 
%r   