Ejemplo n.º 1
0
 def play_mistake_sound(self, node):
     if self.config(
             "timer/sound"
     ) and node.played_sound is None and Theme.MISTAKE_SOUNDS:
         node.played_sound = True
         play_sound(random.choice(Theme.MISTAKE_SOUNDS))
Ejemplo n.º 2
0
 def play_stone_sound(self, *_args):
     play_sound(random.choice(Theme.STONE_SOUNDS))
Ejemplo n.º 3
0
    def update_timer(self, _dt):
        game = self.katrain and self.katrain.game
        current_node = game and self.katrain.game.current_node
        if current_node:
            last_update_node, last_update_time, beeping = self.last_timer_update
            new_beeping = beeping
            now = time.time()
            main_time = self.katrain.config("timer/main_time", 0) * 60
            byo_len = max(1, self.katrain.config("timer/byo_length"))
            byo_num = max(1, self.katrain.config("timer/byo_periods"))
            sounds_on = self.katrain.config("timer/sound")
            player = self.katrain.next_player_info
            ai = player.ai
            used_period = False

            min_use = self.katrain.config("timer/minimal_use", 0)
            boing_at_remaining = byo_len - min_use
            main_time_remaining = main_time - game.main_time_used

            if not self.timer.paused and not ai and self.katrain.play_analyze_mode == MODE_PLAY:
                if last_update_node == current_node and not current_node.children:
                    if main_time_remaining > 0:
                        game.main_time_used += now - last_update_time
                    else:
                        current_node.time_used += now - last_update_time
                else:
                    current_node.time_used = 0
                    new_beeping = False
                time_remaining = byo_len - current_node.time_used
                while time_remaining < 0 and player.periods_used < byo_num:
                    current_node.time_used -= byo_len
                    time_remaining += byo_len
                    player.periods_used += 1
                    used_period = True

                if (self.beep_start - 2 * self.timer_interval < time_remaining
                        < self.beep_start and player.periods_used < byo_num):
                    new_beeping = True
                elif time_remaining > self.beep_start:
                    new_beeping = False

                if (min_use and not new_beeping
                        and boing_at_remaining - self.timer_interval <
                        time_remaining <
                        boing_at_remaining + self.timer_interval
                        and player.periods_used < byo_num):
                    play_sound(Theme.MINIMUM_TIME_PASSED_SOUND, volume=0.1)

            else:
                new_beeping = False

            if player.periods_used == byo_num:
                time_remaining = 0
            else:
                time_remaining = byo_len - current_node.time_used
            periods_rem = byo_num - player.periods_used

            if sounds_on:
                if beeping and not new_beeping and not used_period:
                    stop_sound(Theme.COUNTDOWN_SOUND)
                elif not beeping and new_beeping:
                    play_sound(Theme.COUNTDOWN_SOUND,
                               volume=0.5 if periods_rem > 1 else 1)

            self.last_timer_update = (current_node, now, new_beeping)

            if main_time_remaining > 0:
                self.timer.state = (main_time_remaining, None, ai)
            else:
                self.timer.state = (max(0,
                                        time_remaining), max(0,
                                                             periods_rem), ai)