package game.locations.alarmClock;

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

import aseprite.Aseprite;

import game.locations.Interactive;

class Alarm extends Interactive {
  var anim: Aseprite;
  var buzzSound: SoundChannel;

  public function new() {
    super(false, 1);

    anim = new Aseprite('assets/locations/alarmClock/alarm');
    anim.play('5-59');
    addChild(anim);
  }

  public function start() {
    timer(2, function() {
      buzz();
    });
  }

  function buzz() {
    actionable = true;
    buzzSound = Assets.getSound('sound/buzzer.ogg').play(0, 999);
    anim.play('6-00');
  }

  override function action() {
    Assets.getSound('sound/button_toggle.ogg').play();
    buzzSound.stop();
    anim.play('6-00-norm');

    Game.currentGame.startSoundTrack();
    Game.currentGame.say('Как, уже пора вставать?');
    Game.currentGame.say('Кажется я только закрыл глаза...');
    Game.currentGame.say('Снова на "любимую" работу');

    dispatchEvent(new Event('wokeup'));
  }
}
