package game.locations.celestialLockBasementWindow;

import openfl.events.MouseEvent;
import openfl.events.Event;
import openfl.geom.Rectangle;

import base.GameSprite;

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

class CelestialLockBasementWindow extends Location {
  var wndFrame: Interactive;
  var wndMask: GameSprite;

  public function new() {
    super();

    id = 'celestialLockBasementWindow';

    addBmpLayer('bg');
    addBmpLayer('bg_walls');
    var message = addBmpLayer('message');

    wndMask = new GameSprite(bmpPath('mask'));
    wndMask.x = 168;
    wndMask.y = 39;
    message.mask = wndMask;
    message.addChild(wndMask);

    wndFrame = new Interactive(['Похоже окно не заперто']);
    wndFrame.initBitmap(bmpPath('window_frame'));
    wndFrame.x = 155;
    wndFrame.y = 30;
    wndFrame.addEventListener(MouseEvent.MOUSE_DOWN, onFrameMouseDown);
    wndFrame.addEventListener(MouseEvent.MOUSE_UP, onFrameMouseUp);
    addChild(wndFrame);

    downLocation = game.locations.celestialLockBasement.CelestialLockBasement;
  }

  function onFrameMouseDown(e: MouseEvent) {
    wndFrame.startDrag(false, new Rectangle(0, 30, 155, 0));
  }

  function onFrameMouseUp(e: MouseEvent) {
    wndFrame.stopDrag();
  }

  override function update(delta: Float) {
    super.update(delta);

    wndMask.x = 168 + (wndFrame.x - 155);
  }
}
