<commit_before>var utils = require('../utils');
var settings = require('../settings');
var gameMenu = {};

var isOpen = false;
var newGameCardSwapped = false;

gameMenu.open = function() {
  isOpen = true;
};

gameMenu.close = function() {
  isOpen = false;
};

function swapCard() {
  newGameCardSwapped = !newGameCardSwapped;
}

// see game.styl for dimensions
function boardHeight() {
  return utils.getViewportDims().vw * 80 / 100;
}

// see game.styl for dimensions
function cardHeight() {
  return boardHeight() + 144;
}

function renderRadio(label, name, value, settingsProp) {
  var isOn = settingsProp() === value;
  var id = name + value;
  return [
    m('input.radio[type=radio]', {
      name: name,
      id: id,
      class: value,
      value: value,
      checked: isOn ? 'checked' : '',
      onchange: function(e) {
        settingsProp(e.target.value);
      }
    }),
    m('label[for=' + id + ']', label)
  ];
}

function renderCheckbox(label, name, settingsProp) {
  var isOn = settingsProp();
  return [
    m('label[for=' + name + ']', label),
    m('input[type=checkbox][name=' + name + ']', {
      checked: isOn ? 'checked' : '',
      onchange: function() {
        settingsProp(!isOn);
      }
    })
  ];
}

function renderOption(label, value, storedValue) {
  return m('option[value=' + value + ']', {
    selected: storedValue === value ? 'selected' : ''
  }, label);
}

function renderSelect(label, name, options, settingsProp, isDisabled) {
  var storedValue = settingsProp();
  return [
    m('label[for=' + name + ']', label),
    m('select[name=' + name + ']', {
      disabled: isDisabled ? 'disabled' : '',
      onchange: function(e) { settingsProp(e.target.value); }
    }, options.map(function(e) {
      return renderOption(e[0], e[1], storedValue); })
    )
  ];
}

function renderAIForm(ctrl) {
  var isClockOff = !settings.newGame.ai.clock();
  return m('form.form', {
    onsubmit: function(e) {
      e.preventDefault();
      gameMenu.close();
      swapCard();
      ctrl.startAIGame();
    }
  }, [
    m('fieldset', [
      m('div.nice-radio', renderRadio('Human', 'selected', 'human', settings.newGame.selected)),
      m('div.nice-radio', renderRadio('Computer', 'selected', 'computer', settings.newGame.selected))<commit_msg>Improve and simplify view<commit_after>var utils = require('../utils');
var settings = require('../settings');
var gameMenu = {};

var isOpen = false;
var newGameCardSwapped = false;

gameMenu.open = function() {
  isOpen = true;
};

gameMenu.close = function() {
  isOpen = false;
};

function swapCard() {
  newGameCardSwapped = !newGameCardSwapped;
}

// see game.styl for dimensions
function boardHeight() {
  return utils.getViewportDims().vw * 80 / 100;
}

// see game.styl for dimensions
function cardHeight() {
  return boardHeight() + 144;
}

function renderRadio(label, name, value, settingsProp) {
  var isOn = settingsProp() === value;
  var id = name + value;
  return [
    m('input.radio[type=radio]', {
      name: name,
      id: id,
      'class': value,
      value: value,
      checked: isOn,
      onchange: function(e) {
        settingsProp(e.target.value);
      }
    }),
    m('label', { 'for': id }, label) ];
}

function renderCheckbox(label, name, settingsProp) {
  var isOn = settingsProp();
  return [
    m('label', { 'for': name }, label),
    m('input[type=checkbox]', {
      name: name,
      checked: isOn,
      onchange: function() {
        settingsProp(!isOn);
      }
    })
  ];
}

function renderOption(label, value, storedValue) {
  return m('option', {
    value: value,
    selected: storedValue === value
  }, label);
}

function renderSelect(label, name, options, settingsProp, isDisabled) {
  var storedValue = settingsProp();
  return [
    m('label', { 'for': name }, label),
    m('select', {
      name: name,
      disabled: isDisabled,
      onchange: function(e) { settingsProp(e.target.value); }
    }, options.map(function(e) {
      return renderOption(e[0], e[1], storedValue); })
    )
  ];
}

function renderAIForm(ctrl) {
  var isClockOff = !settings.newGame.ai.clock();
  return m('form.form', {
    onsubmit: function(e) {
      e.preventDefault();
      gameMenu.close();
      swapCard();
      ctrl.startAIGame();
    }
  }, [
    m('fieldset', [
      m('div.nice-radio', renderRadio('Human', 'selected', 'human', settings.newGame.selected)),
      m('div.nice-radio', renderRadio('Computer', 'selected', 'computer', settings.newGame.selected))
{'fraction_non_alphanumeric': 0.1708185053380783, 'fraction_numerical': 0.004448398576512456, 'mean_word_length': 3.226503759398496, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6683607', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1469, 'n_words': 320}