a
    
ir                     @   sB   d Z ddlZddlmZ eeZdddZdd Zdd
dZdS )z.Game Speed Validation and Management Functions    N)configFc              
   C   s   zpt | } tjrtj}tj}ntj}tj}|r>| tjkr>| W S t|t	| |}|| krlt
d|  d|  |W S  ttfy } z0t
d|  dt| j d tjW  Y d}~S d}~0 0 dS )aD  
    Validate and clamp game speed to acceptable range.

    Args:
        speed: The speed value to validate (can be int, str, or any type)
        allow_question_pause: If True, allows SPEED_QUESTION_PAUSE value (100000)

    Returns:
        int: A valid game speed within acceptable bounds

    Note:
        - Higher speed values = slower gameplay (more ticks between updates)
        - Uses DEBUG mode settings if config.DEBUG is True
        - In debug mode, allows speeds from 1 (5000 updates/sec) to 100000
        - In production mode, allows speeds from 1 to 10000
    zGame speed z out of bounds, clamped to zInvalid game speed value:  (z), using defaultN)intr   DEBUGDEBUG_SPEED_MINDEBUG_SPEED_MAX	SPEED_MIN	SPEED_MAXSPEED_QUESTION_PAUSEmaxminloggerwarning
ValueError	TypeErrorerrortype__name__SPEED_DEFAULT)ZspeedZallow_question_pauseZ	min_speedZ	max_speedZvalidated_speede r   1/var/www/lichun.app/lichun/ws/utils/game_speed.pyvalidate_game_speed   s     r   c                   C   s   t jrt jS t jS )z
    Get the appropriate speed button values based on debug mode.

    Returns:
        list: Speed values for +/- button navigation
    )r   r   DEBUG_SPEED_BUTTON_VALUESSPEED_BUTTON_VALUESr   r   r   r   get_speed_button_values8   s    r   manualc                 C   s`   |dkrd| nd}|dkr$d| nd}t d|  d| d| d|dd| d|dd	 d
S )a  
    Log speed changes for debugging and monitoring.

    Args:
        user_id: User/player identifier
        old_speed: Previous speed value
        new_speed: New speed value
        source: Source of the change (manual, button, reset, question, etc.)
    r   i  zSpeed change [user=z] [z]: r   z.1fu
    ups) → z ups)N)r   info)user_idZ	old_speedZ	new_speedsourceZold_upsZnew_upsr   r   r   log_speed_changeA   s    r    )F)r   )	__doc__loggingr   	getLoggerr   r   r   r   r    r   r   r   r   <module>   s   

,	