<commit_before>import React from 'react';

import AppDisplay from './AppDisplay';

import AppContext, { defaultContext } from './AppContext';

import TransmuteDialog from './Magic/TransmuteDialog';
import { getSpellById } from './Magic/MagicUtils';
import { getToolById } from './Tools/ToolUtils';
import {
  BASE_SEED_DROP_RATE,
  BASE_TIME_PER_PLANT_GROWTH_PHASE,
  COME_DOWN_RATE,
  CONVERSIONS
} from './utils/Constants';
import GameLoop from './utils/GameLoop';
import {
  PLANT_GROWTH_PHASES,
  STRAINS } from './Weed/WeedList';
import {
  getRandomTier1Strain,
  getStrainById,
  plantAgePhaseFilter
} from './Weed/WeedUtils';

import { library } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; // eslint-disable-line no-unused-vars
import {
  faCannabis,
  faJoint
} from '@fortawesome/free-solid-svg-icons';

library.add(
  faCannabis,
  faJoint
);

class App extends React.Component {
  constructor(props) {
    super(props);

    this.loop = new GameLoop();

    this.state = {
      transmuteDialogOpen: false,
      // Set context methods
      context: {
        ...defaultContext,
        actions: {
          ...defaultContext.actions,
          addNotification: this.addNotification,
          agePlants: this.agePlants,
          harvestPlant: this.harvestPlant,
          decayHighness: this.decayHighness,
          plantSeed: this.plantSeed,
          removePlant: this.removePlant,
          saveState: this.saveState,
          selectTool: this.selectTool,
          selectWeed: this.selectWeed,
          smokeWeed: this.smokeWeed,
          startGame: this.startGame,
          stopGame: this.stopGame,
          toggleGame: this.toggleGame,
          toggleSpell: this.toggleSpell,
          updateTimestamp: this.updateTimestamp
        },
        magicActions: {
          ...defaultContext.magicActions,
          transmute: this.magicTransmute
        }
      }
    };
  }

  componentWillMount() {
    const { context } = this.state;
    const { actions } = context;
    const { addNotification } = actions;

    const player = JSON.parse(localStorage.getItem('weedWizard'));

    if (player) {
      addNotification('Game loaded!');

      this.setState({
        ...this.state,
        context: {
          ...context,
          player
        }
      });
    }
  }

  componentDidMount() {
    this.loop.start();
  }

  componentWillUnmount() {
    this.loop.stop();
  }

  closeTransmuteDialog = () => {
    this.setState({
      transmuteDialogOpen: false
    });
  };

  /**
   * Context Methods
   */

  addNotification = text => {
    const { context } = this.state;
    const { notifications } = context;

    notifications.push({
      message: text,
      key: new Date().getTime()
    });

    this.setState({
      context: {
        ...context,
        notifications
      }
    });
  };

  agePlants = () => {
    const { context } = this.state;
    const {
      actions,
      gameIsRunning,
      player,
      timeSinceLastUpdate } = context;
    const { addNotification } = actions;
    const {
      garden,
      spellsList } = player;
    let timeToAge = timeSinceLastUpdate;

    // If the Grow Faster spell is active, do that
    if (spellsList.find(SPELL => SPELL.id === 0).active) timeToAge *= 60;

    const newGarden = garden.map(plant => {
      if (typeof plant === 'undefined') return plant;
      else {
        const {
          age,
          phase } = plant;
        const newAge = age + timeToAge;
        const newPhase = plantAgePhaseFilter(newAge);

        let newGrowthProgress = age / BASE_TIME_PER_PLANT_GROWTH_PHASE;
        newGrowthProgress = (newGrowthProgress - Math.floor(newGrowthProgress)) * 100;

        if (phase !== newPhase && age > 1000) addNotification((
          <span>
            {'Congratulations! Your '}
            <b>{ plant.name }</b>
            {' plant has entered a '}
            <b>{ PLANT_GROWTH_PHASES[newPhase] }</b>
            {' phase!'}
          </span>
        ));

        return {
          ...plant,
          age: newAge,
          growthProgress: newGrowthProgress,
          phase: newPhase
        };
      }
    });

    if (gameIsRunning) {
      this.setState({
        context: {
          ...context,
          player: {
            ...player,
            garden: newGarden
          }
        }
      });
    }<commit_msg>Fix growth notification when paused bug.<commit_after>import React from 'react';

import AppDisplay from './AppDisplay';

import AppContext, { defaultContext } from './AppContext';

import TransmuteDialog from './Magic/TransmuteDialog';
import { getSpellById } from './Magic/MagicUtils';
import { getToolById } from './Tools/ToolUtils';
import {
  BASE_SEED_DROP_RATE,
  BASE_TIME_PER_PLANT_GROWTH_PHASE,
  COME_DOWN_RATE,
  CONVERSIONS
} from './utils/Constants';
import GameLoop from './utils/GameLoop';
import {
  PLANT_GROWTH_PHASES,
  STRAINS } from './Weed/WeedList';
import {
  getRandomTier1Strain,
  getStrainById,
  plantAgePhaseFilter
} from './Weed/WeedUtils';

import { library } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; // eslint-disable-line no-unused-vars
import {
  faCannabis,
  faJoint
} from '@fortawesome/free-solid-svg-icons';

library.add(
  faCannabis,
  faJoint
);

class App extends React.Component {
  constructor(props) {
    super(props);

    this.loop = new GameLoop();

    this.state = {
      transmuteDialogOpen: false,
      // Set context methods
      context: {
        ...defaultContext,
        actions: {
          ...defaultContext.actions,
          addNotification: this.addNotification,
          agePlants: this.agePlants,
          harvestPlant: this.harvestPlant,
          decayHighness: this.decayHighness,
          plantSeed: this.plantSeed,
          removePlant: this.removePlant,
          saveState: this.saveState,
          selectTool: this.selectTool,
          selectWeed: this.selectWeed,
          smokeWeed: this.smokeWeed,
          startGame: this.startGame,
          stopGame: this.stopGame,
          toggleGame: this.toggleGame,
          toggleSpell: this.toggleSpell,
          updateTimestamp: this.updateTimestamp
        },
        magicActions: {
          ...defaultContext.magicActions,
          transmute: this.magicTransmute
        }
      }
    };
  }

  componentWillMount() {
    const { context } = this.state;
    const { actions } = context;
    const { addNotification } = actions;

    const player = JSON.parse(localStorage.getItem('weedWizard'));

    if (player) {
      addNotification('Game loaded!');

      this.setState({
        ...this.state,
        context: {
          ...context,
          player
        }
      });
    }
  }

  componentDidMount() {
    this.loop.start();
  }

  componentWillUnmount() {
    this.loop.stop();
  }

  closeTransmuteDialog = () => {
    this.setState({
      transmuteDialogOpen: false
    });
  };

  /**
   * Context Methods
   */

  addNotification = text => {
    const { context } = this.state;
    const { notifications } = context;

    notifications.push({
      message: text,
      key: new Date().getTime()
    });

    this.setState({
      context: {
        ...context,
        notifications
      }
    });
  };

  agePlants = () => {
    const { context } = this.state;
    const {
      actions,
      gameIsRunning,
      player,
      timeSinceLastUpdate } = context;
    const { addNotification } = actions;
    const {
      garden,
      spellsList } = player;
    let timeToAge = timeSinceLastUpdate;

    if (gameIsRunning) {
    // If the Grow Faster spell is active, do that
    if (spellsList.find(SPELL => SPELL.id === 0).active) timeToAge *= 60;

    const newGarden = garden.map(plant => {
      if (typeof plant === 'undefined') return plant;
      else {
        const {
          age,
          phase } = plant;
        const newAge = age + timeToAge;
        const newPhase = plantAgePhaseFilter(newAge);

        let newGrowthProgress = age / BASE_TIME_PER_PLANT_GROWTH_PHASE;
        newGrowthProgress = (newGrowthProgress - Math.floor(newGrowthProgress)) * 100;

        if (phase !== newPhase && age > 1000) addNotification((
          <span>
            {'Congratulations! Your '}
            <b>{ plant.name }</b>
            {' plant has entered a '}
            <b>{ PLANT_GROWTH_PHASES[newPhase] }</b>
            {' phase!'}
          </span>
        ));

        return {
          ...plant,
          age: newAge,
          growthProgress: newGrowthProgress,
          phase: newPhase
        };
      }
    });

      this.setState({
        context: {
          ...context,
          player: {
            ...player,
            garden: newGarden
          }
        }
      });
    }
{'fraction_non_alphanumeric': 0.1178930710975472, 'fraction_numerical': 0.0024867186616932295, 'mean_word_length': 2.0754257907542577, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, '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': '6661516', 'n_tokens_mistral': 2750, 'n_tokens_neox': 2656, 'n_words': 545}