"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _phaser = _interopRequireDefault(require("phaser"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }

function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var StageSummaryScene =
/*#__PURE__*/
function (_Phaser$Scene) {
  _inherits(StageSummaryScene, _Phaser$Scene);

  function StageSummaryScene() {
    var _this;

    _classCallCheck(this, StageSummaryScene);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(StageSummaryScene).call(this, {
      key: 'StageSummaryScene'
    }));

    _defineProperty(_assertThisInitialized(_this), "handleContinue", function () {
      console.log('continue');

      _this.scene.stop(_this.scene.key);

      _this.scene.get('GameScene').nextLevel();
    });

    _defineProperty(_assertThisInitialized(_this), "handleRetry", function () {
      console.log('retry');

      _this.scene.stop(_this.scene.key);

      _this.scene.get('GameScene').restart();
    });

    _defineProperty(_assertThisInitialized(_this), "handleBack", function () {
      console.log('back');

      _this.scene.stop(_this.scene.key);

      _this.game.events.emit('gameClear');
    });

    _defineProperty(_assertThisInitialized(_this), "addButtons", function () {
      var score = _this.scene.get('GameScene').score;

      var buttons = [];

      if (score > 0) {
        buttons = [_this.add.container(0, 0, [_this.add.image(0, 0, 'button').setDisplaySize(600, 200).setInteractive().on('pointerdown', _this.handleContinue), _this.add.text(0, 0, 'Continue', {
          fontSize: '96px',
          fill: '#ffffff'
        }).setOrigin(0.5, 0.5)])];
      }

      buttons = [].concat(_toConsumableArray(buttons), [_this.add.container(0, buttons.length * 250, [_this.add.image(0, 0, 'button').setDisplaySize(600, 200).setInteractive().on('pointerdown', _this.handleRetry), _this.add.text(0, 0, 'Retry', {
        fontSize: '96px',
        fill: '#ffffff'
      }).setOrigin(0.5, 0.5)])]);
      return buttons;
    });

    return _this;
  }

  _createClass(StageSummaryScene, [{
    key: "preload",
    value: function preload() {}
  }, {
    key: "create",
    value: function create() {
      var _this$scene$get = this.scene.get('GameScene'),
          score = _this$scene$get.score,
          level = _this$scene$get.level,
          seconds = _this$scene$get.seconds,
          totalScore = _this$scene$get.totalScore;

      var width = this.game.config.width;
      var height = this.game.config.height;

      if (level < 8) {
        this.add.container(width / 2, height / 2, [this.add.image(0, 0, 'frame').setDisplaySize(1600, 1400), this.add.text(0, -500, 'Your score', {
          fontSize: '126px',
          fill: '#000000'
        }).setOrigin(0.5, 0).setScrollFactor(0), this.add.image(-300, -200, score >= 10 ? 'star' : 'star-inactive'), this.add.image(0, -200, score >= 20 ? 'star' : 'star-inactive'), this.add.image(300, -200, score >= 30 ? 'star' : 'star-inactive'), this.add.container(0, 150, this.addButtons())]);
      } else {
        this.add.container(width / 2, height / 2, [this.add.image(0, 0, 'frame').setDisplaySize(1600, 1400), this.add.text(0, -500, 'GAME CLEAR', {
          fontSize: '126px',
          fill: '#000000'
        }).setOrigin(0.5, 0).setScrollFactor(0), this.add.container(0, 150, this.add.container(0, 0, [this.add.image(0, 0, 'button').setDisplaySize(600, 200).setInteractive().on('pointerdown', this.handleBack), this.add.text(0, 0, 'Back', {
          fontSize: '96px',
          fill: '#ffffff'
        }).setOrigin(0.5, 0.5)]))]);
      }

      this.game.events.emit('stageClear', {
        level: level,
        score: score,
        seconds: seconds,
        totalScore: totalScore
      });
    }
  }]);

  return StageSummaryScene;
}(_phaser["default"].Scene);

var _default = StageSummaryScene;
exports["default"] = _default;