
    Ii                     N    S r SSKJrJr  SSKJr   " S S\5      r " S S5      rg	)
z$Mixin for turn timer logic in games.    )AnyProtocol   )PokerTurnTimerc                   J    \ rS rSr% Sr\\S'   \\S'   S\SS4S jr	SS	 jr
S
rg)TurnTimerGameProtocol   z(Protocol for games using TurnTimerMixin.timeroptionssoundreturnNc                     g N )selfr   s     Ac:\Users\dbart\PlayPalace11\server\game_utils\turn_timer_mixin.py
play_sound TurnTimerGameProtocol.play_sound   s    c    c                     g r   r   r   s    r   _on_turn_timeout&TurnTimerGameProtocol._on_turn_timeout   s    r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   __annotations__r   strr   r   __static_attributes__r   r   r   r   r      s     2L111+r   r   c                   b    \ rS rSrSrSS jrSS jrSS jrSS jr\	S\
4S	 j5       rSS
 jrSrg)TurnTimerMixin   zMixin for managing turn timers.

Requires the class to have:
- self.timer: PokerTurnTimer
- self.options: object with 'turn_timer' attribute (str)
- self.play_sound(sound: str)
- _on_turn_timeout() -> implement this!
r   Nc                     SU l          [        U R                  R                  5      nUS::  a  U R                  R                  5         gU R                  R                  U5        g! [        [
        4 a    Sn NQf = f)z+Start the turn timer based on game options.Fr   N)	_timer_warning_playedintr   
turn_timer
ValueErrorAttributeErrorr
   clearstart)r   secondss     r   start_turn_timerTurnTimerMixin.start_turn_timer   sn     &+"	$,,112G a<JJ

! N+ 	G	s   A% %A:9A:c                 F    U R                   R                  5         SU l        g)zStop/clear the turn timer.FN)r
   r,   r'   r   s    r   stop_turn_timerTurnTimerMixin.stop_turn_timer/   s    

%*"r   c                     U R                   R                  5       (       a  U R                  5         U R                  5         g)z8Called every tick to update timer and check for timeout.N)r
   tickr   _maybe_play_timer_warningr   s    r   on_tick_turn_timer!TurnTimerMixin.on_tick_turn_timer4   s+    ::??!!#&&(r   c                 ,   U R                   (       a  g [        U R                  R                  5      nUS:  a  gU R                  R                  5       nUS:X  a#  SU l         U R                  U R                  5        gg! [        [
        4 a    Sn N_f = f)z*Play warning sound if time is running out.Nr         T)
r'   r(   r   r)   r*   r+   r
   seconds_remainingr   timer_warning_sound)r   total_seconds	remainings      r   r6   (TurnTimerMixin._maybe_play_timer_warning;   s    %%	 7 78M
 2JJ002	>)-D& OOD445  N+ 	M	s   A> >BBc                     g)z
Get the warning sound file path.

Defaults to the CrazyEights sound for backward compatibility,
but can be overridden by subclasses.
zgame_crazyeights/fivesec.oggr   r   s    r   r=   "TurnTimerMixin.timer_warning_soundZ   s     .r   c                     [         e)z@Hook called when timer expires. Must be implemented by subclass.)NotImplementedErrorr   s    r   r   TurnTimerMixin._on_turn_timeoutd   s    !!r   )r'   r   )r   r   r   r   r   r/   r2   r7   r6   propertyr!   r=   r   r"   r   r   r   r$   r$      s;    ""+
)6> .S . ."r   r$   N)r   typingr   r   poker_timerr   r   r$   r   r   r   <module>rI      s&    *   ',H ,T" T"r   