<commit_before>part of tilebasedwordsearch;

class GameClock {
  static const int DEFAULT_GAME_LENGTH = 70; // # of seconds in a game
  final GameLoop gameLoop;

  bool shouldPause = false;
  int gameLength = DEFAULT_GAME_LENGTH;
  Completer allDone = new Completer();
  
  @observable
  String timeRemaining = 'Not yet started';
  
  int secondsRemaining = DEFAULT_GAME_LENGTH;
  
  GameClock(GameLoop this.gameLoop, {this.gameLength:DEFAULT_GAME_LENGTH}) {
    if (gameLength != null) {
      secondsRemaining = gameLength;
    }
    timeRemaining = formatTime(secondsRemaining);
  }
  
  String formatTime(int seconds) {
    if (seconds <= 0) return '0'; // XXX ok for stop() case?
    
    int m = seconds ~/ 60;
    int s = seconds % 60;
    
    String minuteString = "";
    String secondString = "";

    if (m > 0) {
      minuteString = '${m.toString()}:';
      secondString = (s <= 9) ? '0$s' : '$s';
    } else {
      secondString = s.toString();
    }
    return '$minuteString$secondString';
  }
  
  tick(GameLoopTimer _) {
    if (!shouldPause) {
      secondsRemaining--;
      timeRemaining = formatTime(secondsRemaining);
      if (secondsRemaining > 0) {
        gameLoop.addTimer(tick, 1.0); // 1 second timer
      } else {
        allDone.complete(true);
        print('DONE!');
      }
    }
  }
  <commit_msg>format time remaining via setter<commit_after>part of tilebasedwordsearch;

class GameClock {
  static const int DEFAULT_GAME_LENGTH = 70; // # of seconds in a game
  final GameLoop gameLoop;

  bool shouldPause = false;
  int gameLength = DEFAULT_GAME_LENGTH;
  Completer allDone = new Completer();
  
  @observable
  String timeRemaining = 'Not yet started';
  
  int _secondsRemaining = DEFAULT_GAME_LENGTH;
  
  GameClock(GameLoop this.gameLoop, {this.gameLength:DEFAULT_GAME_LENGTH}) {
    if (gameLength != null) {
      secondsRemaining = gameLength;
    }
  }
  
  void set secondsRemaining(int remaining) {
    _secondsRemaining = remaining;
    timeRemaining = _formatTime(_secondsRemaining);
  }
  
  int get secondsRemaining => _secondsRemaining;
  
  // TODO: replace with intlx or something from intl
  String _formatTime(int seconds) {
    if (seconds <= 0) return '0'; // XXX ok for stop() case?
    
    int m = seconds ~/ 60;
    int s = seconds % 60;
    
    String minuteString = "";
    String secondString = "";

    if (m > 0) {
      minuteString = '${m.toString()}:';
      secondString = (s <= 9) ? '0$s' : '$s';
    } else {
      secondString = s.toString();
    }
    return '$minuteString$secondString';
  }
  
  tick(GameLoopTimer _) {
    if (!shouldPause) {
      secondsRemaining--;
      if (secondsRemaining > 0) {
        gameLoop.addTimer(tick, 1.0); // 1 second timer
      } else {
        allDone.complete(true);
        print('DONE!');
      }
    }
  }
  
{'fraction_non_alphanumeric': 0.11710758377425044, 'fraction_numerical': 0.010582010582010581, 'mean_word_length': 2.7071895424836603, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3359133', 'n_tokens_mistral': 938, 'n_tokens_neox': 908, 'n_words': 228}