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   

,	