package game.locations.elevatorMove;

import openfl.events.Event;
import openfl.display.Bitmap;
import openfl.Assets;

import game.locations.Location;
import game.locations.Interactive;

import base.GameSprite;

import aseprite.Aseprite;

class ElevatorMove extends Location {
  var leftDoor: GameSprite;
  var rightDoor: GameSprite;
  var shade: GameSprite;
  var buttons: Buttons = new Buttons();
  var basement: Interactive = new Interactive();

  public function new() {
    super();
    id = 'elevatorMove';

    basement = new Interactive(false, game.locations.entrance.Entrance);
    basement.initBitmap(bmpPath('basement'));
    basement.visible = false;
    addChild(basement);

    leftDoor = new GameSprite(bmpPath('door_left'));
    leftDoor.x = 87 - leftDoor.width;
    addChild(leftDoor);

    rightDoor = new GameSprite(bmpPath('door_right'));
    rightDoor.x = 160 + rightDoor.width;
    addChild(rightDoor);

    addBmpLayer('bg');

    buttons.x = 270;
    buttons.y = 25;
    addChild(buttons);

    timer(0.5, function() {
      Game.currentGame.playSound('sound/elevator/doors_open.ogg');
      leftDoor.tween({ x: 87 }, 1.6);
      rightDoor.tween({ x: 160 }, 1.6).then(function() {
        var moveSound = Game.currentGame.playSound('sound/elevator/move.ogg');

        var makeFlirks = function() {
          var flikr = new Aseprite('assets/locations/elevatorMove/flikr');
          flikr.playTimes(1, null, function() {
            removeChild(flikr);
          });
          addChild(flikr);
        };

        timer(4, makeFlirks);
        timer(7, makeFlirks);

        timer(10, function() {
          Game.currentGame.stopSound(moveSound);
          Game.currentGame.playSound('sound/elevator/doors_open.ogg');
          buttons.on = false;
          moveSound.stop();
            basement.visible = true;
            leftDoor.tween({ x: 87 - leftDoor.width }, 1.6);
            rightDoor.tween({ x: 160 + rightDoor.width }, 1.6).then(function() {
              timer(1, function() {
                buttons.actionable = true;
                basement.actionable = true;
                Game.currentGame.say('Что это? Не похоже на первый этаж.');
                Game.currentGame.say('Похоже лифт увез меня в подвал');

                rightLocation = game.locations.elevatorStoppedInside.ElevatorStoppedInside;
                downLocation = game.locations.elevatorBack.ElevatorBack;
              });
            });
        });
      });
    });
  }
}
