<commit_before>var PLAYER;

function startGame() {
  loadPlayer()
  updateUI()
}

function loadPlayer() {
  const player = Cookies.get('player');

  if (typeof player === 'undefined') {
    PLAYER = newPlayer()
  } else {
    PLAYER = parsePlayer(player)
  }
}

function parsePlayer(playerJSON) {
  return JSON.parse(playerJSON)
}

function newPlayer() {
  return {
    points: 0,
    teenagers: 0,
    kettles: 0,
    theaters: 0
  }
}

function savePlayer() {
  Cookies.set("player", PLAYER)
}

function earnPoints() {
  PLAYER.points += 1
  updateComponents(['points'])
  savePlayer()
}

function buyTeenagers(num) {
  teenagerIncrease = () => {
    if (PLAYER.points >= 20){
      PLAYER.teenagers += num
      PLAYER.points -= 20
      updateComponents(['points', 'teenagers'])

      savePlayer()
    }
  }
  return teenagerIncrease
}

function buyKettles(num) {
  kettleIncrease = () => {
    if (PLAYER.points >= 50){
      PLAYER.kettles += num
      PLAYER.points -= 50
      updateComponents(['points', 'kettles'])

      savePlayer()
    }
  }
  return kettleIncrease
}

function buyTheaters(num) {
  theaterIncrease = () => {
    if (PLAYER.points >= 250){
      PLAYER.theaters += num
      PLAYER.points -= 250
      updateComponents(['points', 'theaters'])

      savePlayer()
    }
  }<commit_msg>Refactor player functions into Player class<commit_after>var PLAYER;

function startGame() {
  PLAYER = new Player()
  PLAYER.load()
  updateUI()
}

class Player {
  constructor() {
    this.points = 0
    this.teenagers = 0
    this.kettles = 0
    this.theaters = 0
  }

  load() {
    const playerJSON = Cookies.get('player');

    if (typeof playerJSON === 'undefined') {
      // PLAYER = newPlayer()
    } else {
      const playerState = JSON.parse(playerJSON)
      this.points = playerState.points
      this.teenagers = playerState.teenagers
      this.kettles = playerState.kettles
      this.theaters = playerState.theaters
    }
  }

  save() {
    Cookies.set("player", this)
  }
}

function earnPoints() {
  PLAYER.points += 1
  updateComponents(['points'])
  PLAYER.save()
}

function buyTeenagers(num) {
  teenagerIncrease = () => {
    if (PLAYER.points >= 20){
      PLAYER.teenagers += num
      PLAYER.points -= 20
      updateComponents(['points', 'teenagers'])

      PLAYER.save()
    }
  }
  return teenagerIncrease
}

function buyKettles(num) {
  kettleIncrease = () => {
    if (PLAYER.points >= 50){
      PLAYER.kettles += num
      PLAYER.points -= 50
      updateComponents(['points', 'kettles'])

      PLAYER.save()
    }
  }
  return kettleIncrease
}

function buyTheaters(num) {
  theaterIncrease = () => {
    if (PLAYER.points >= 250){
      PLAYER.theaters += num
      PLAYER.points -= 250
      updateComponents(['points', 'theaters'])

      PLAYER.save()
    }
  }
{'fraction_non_alphanumeric': 0.1400709219858156, 'fraction_numerical': 0.01347517730496454, 'mean_word_length': 2.7613333333333334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1400708', 'n_tokens_mistral': 1012, 'n_tokens_neox': 924, 'n_words': 187}