<commit_before>#import('dart:html');
#import('dart:json');

#import('../../lib/sweeper.dart');
#import('../../lib/canvas.dart');

#source('../canvas/texture_data.dart');

ImageLoader _imageLoader;

main() {
  _imageLoader = new ImageLoader(['art.png']);
  _imageLoader.loaded.add((args) => _doLoad());
  _imageLoader.load();
}

_doLoad() {
  _doAudio();
  final textures = _getTexturesFromJson(_artFramesJson);

  final targetMode = false;
  final int w = 7, h = 7;
  final int m = (w * h * 0.15625).toInt();

  final CanvasElement sweeperTable = query('#sweeperCanvas');
  final Element minesLeftDiv = query('#minesLeft');
  final Element gameStateDiv = query('#gameState');
  final Element clockDiv = query('#clock');

  assert(_imageLoader != null);

  final textureImg = _imageLoader.getResource('art.png');
  assert(textureImg != null);

  // populate globals
  populateTextures(textures);
  populateTextureImage(textureImg);

  final gameRoot = new GameRoot(w, h, m,
      sweeperTable, minesLeftDiv, gameStateDiv, clockDiv, targetMode);

  // disable touch events
  window.on.touchMove.add(_onTouchMove);

  final ButtonElement newGameButton = query('#newGame');
  newGameButton.on.click.add((args) => gameRoot.newGame());

  /*

  final ButtonElement flagButton = query('#flag');
  flagButton.on.click.add((args) => gameRoot.toggleTargetFlag());

  final ButtonElement revealButton = query('#reveal');
  revealButton.on.click.add((args) => gameRoot.revealTarget());

  final updateButtons = (args) {
    revealButton.disabled = !gameRoot.canRevealTarget;
    flagButton.disabled = !gameRoot.canFlagTarget;
  };

  gameRoot.targetChanged.add(updateButtons);

  updateButtons(null);

  */
}

void _onTouchMove(TouchEvent args) {
  args.preventDefault();
}

const String _sample = '../audio/Pop01.webm';

AudioLoader audioLoader;

void _doAudio() {
  final context = new AudioContext();

  audioLoader = new AudioLoader(context, [_sample]);
  audioLoader.loaded.add(_finishedLoading);
  audioLoader.load();
}

void _finishedLoading(args) {
  final context = audioLoader.context;
  // Create two sources and play them both together.
  var source = context.createBufferSource();

  source.buffer = audioLoader.getResource(_sample);
  source.connect(context.destination, 0);
  source.noteOn(0);
}<commit_msg>Using new loader features<commit_after>#import('dart:html');
#import('dart:json');

#import('../../lib/sweeper.dart');
#import('../../lib/canvas.dart');

#source('../canvas/texture_data.dart');

const String _sampleAudio = '../audio/Pop01.webm';

ImageLoader _imageLoader;
AudioLoader _audioLoader;

main() {
  _imageLoader = new ImageLoader(['art.png']);
  _imageLoader.loaded.add(_onLoaded);
  _imageLoader.progress.add(_onLoaded);
  _imageLoader.load();

  final audioContext = new AudioContext();

  _audioLoader = new AudioLoader(audioContext, [_sampleAudio]);
  _audioLoader.loaded.add(_onLoaded);
  _audioLoader.progress.add(_onLoaded);
  _audioLoader.load();
}

void _onLoaded(args) {
  print(_imageLoader.completedCount + _audioLoader.completedCount);
  if(_imageLoader.state == ResourceLoader.StateLoaded &&
      _audioLoader.state == ResourceLoader.StateLoaded) {
    _runSweeper();
  }
}

void _runSweeper() {
  _playSampleAudio();
  final textures = _getTexturesFromJson(_artFramesJson);

  final targetMode = false;
  final int w = 7, h = 7;
  final int m = (w * h * 0.15625).toInt();

  final CanvasElement sweeperTable = query('#sweeperCanvas');
  final Element minesLeftDiv = query('#minesLeft');
  final Element gameStateDiv = query('#gameState');
  final Element clockDiv = query('#clock');

  assert(_imageLoader != null);

  final textureImg = _imageLoader.getResource('art.png');
  assert(textureImg != null);

  // populate globals
  populateTextures(textures);
  populateTextureImage(textureImg);

  final gameRoot = new GameRoot(w, h, m,
      sweeperTable, minesLeftDiv, gameStateDiv, clockDiv, targetMode);

  // disable touch events
  window.on.touchMove.add(_onTouchMove);

  final ButtonElement newGameButton = query('#newGame');
  newGameButton.on.click.add((args) => gameRoot.newGame());

  /*

  final ButtonElement flagButton = query('#flag');
  flagButton.on.click.add((args) => gameRoot.toggleTargetFlag());

  final ButtonElement revealButton = query('#reveal');
  revealButton.on.click.add((args) => gameRoot.revealTarget());

  final updateButtons = (args) {
    revealButton.disabled = !gameRoot.canRevealTarget;
    flagButton.disabled = !gameRoot.canFlagTarget;
  };

  gameRoot.targetChanged.add(updateButtons);

  updateButtons(null);

  */
}

void _onTouchMove(TouchEvent args) {
  args.preventDefault();
}


void _playSampleAudio() {
  final context = _audioLoader.context;
  // Create two sources and play them both together.
  var source = context.createBufferSource();

  source.buffer = _audioLoader.getResource(_sampleAudio);
  source.connect(context.destination, 0);
  source.noteOn(0);
}
{'fraction_non_alphanumeric': 0.14522318723490205, 'fraction_numerical': 0.004847505554433448, 'mean_word_length': 4.860355029585799, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '6251374', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1529, 'n_words': 304}