import StageButton       from '../objects/LevelButton';
import MenuOptionButton  from '../objects/MenuOptionButton';
import BackgroundPattern from '../objects/BackgroundPattern';


export default class Levels extends Phaser.State {

  init () {
    this.game.transitions.registerTransition('fade-from-black');
  }

  create () {
    this.game.transitions.doTransition();

    this.add.existing(new BackgroundPattern(this.game));
    this.add.image(0, 0, 'background-level-select');

    this.add.image(0, 32, 'labels', 'label-level-select');

    let backButton = new MenuOptionButton(this.game, 0, 0);
    backButton.onInputUp.add(() => this._doTransition('Title'));
    this.add.existing(backButton);

    this.game.storage.getItem('levels', this._addStageButtons, this);
  }

  // --------------------------------------------------------------------------

  _addStageButtons (err, unlockedLevels) {
    for (var len = unlockedLevels.length, i = 0; i < len; ++i) {
      var { name, buttonFace, locked } = unlockedLevels[i];
      var x = 48 + 32 * (i % 5);
      var y = 64 + 32 * Math.floor(i / 5);

      this.add.existing(
        this._makeStageButton(x, y, name, buttonFace, locked));
    }
  }

  _makeStageButton (x, y, level, buttonFace, locked) {
    let button = new StageButton(this.game, x, y, level);

    if (!locked) {
      button.unlock();
      button.onInputUp.add(() => this._doTransition('Game', level));
    }

    return button;
  }

  _doTransition (stateName, ... params) {
    this.game.transitions.registerTransition('fade-to-black');
    this.game.transitions.registerTransitionCallback(
      () => this._goToState(stateName, ... params));
    this.game.transitions.doTransition();
  }

  _goToState (stateName, ... params) {
    this.game.state.start(stateName, true, false, ... params);
  }

}

@@ -905,19 +905,19 @@
    for (
-var
+let
  len = u
@@ -971,19 +971,19 @@
     
-var
+let
  %7B name,
  but
@@ -974,36 +974,24 @@
  let %7B name,
- buttonFace,
  locked %7D = 
@@ -1015,19 +1015,19 @@
 ;%0A      
-var
+let
  x = 48 
@@ -1052,11 +1052,11 @@
     
-var
+let
  y =
@@ -1114,17 +1114,8 @@
 ing(
-%0A        
 this
@@ -1143,28 +1143,16 @@
 y, name,
- buttonFace,
  locked)
@@ -1201,20 +1201,8 @@
 vel,
- buttonFace,
  loc

Remove unused arg in method