EVR.Delegate.Keys = function()
{
   this.codes = [];
}
EVR.Delegate.Keys.prototype.add = function(code)
{
   this.codes.push(code);
}
EVR.Delegate.Keys.prototype.remove = function(code)
{
   var index = this.find(code);
   if (index !== null)
   {
      this.codes.splice(index, 1)
   }
}
EVR.Delegate.Keys.prototype.find = function(code)
{
   var codes = this.codes;
   for (var ii = codes.length - 1; ii >= 0; ii--)
   {
      if (codes[ii] == code)
      {
	 return ii;
      }
   }
   return null;
}
EVR.Delegate.Keys.prototype.toString = function()
{
   return "[object EVR.Delegate.Keys]";
}
EVR.include("delegate/Keys.js")

EVR.Delegate = function(application)
{
   this.application = application;
   this.introduction = application.introduction;
   this.history = application.history;
   this.resize_response = false;
   this.keys_down = new EVR.Delegate.Keys();
}

EVR.Delegate.prototype.handle_key_down = function(event)
{
   event = this.fix_event(event);
   var code = event.keyCode;
   if (this.keys_down.find(code) !== null)
   {
      return;
   }
   if (code == KEY_C)
   {
      console.toggle_visibility();
      this.application.repopulate();
   }
   if (code == KEY_ENTER)
   {
      this.handle_enter();
   }
   if (code == KEY_UP || code == KEY_UP_ALTERNATE)
   {
      !!this.menu && this.menu.attached && this.menu.select(-1);
      !!this.level && this.level.delegate.up();
   }
   if (code == KEY_DOWN || code == KEY_DOWN_ALTERNATE)
   {
      !!this.menu && this.menu.attached && this.menu.select(1);
      !!this.level && this.level.delegate.down();
   }
   if (code == KEY_SPRINT || code == KEY_SPRINT_ALTERNATE)
   {
      !!this.level && this.level.delegate.sprint();
   }
   if (code == KEY_GRID)
   {
      !!this.album && this.album.attached && this.album.toggle_grid();
   }
   if (code == KEY_PREVIOUS_PAGE)
   {
      !!this.album && this.album.attached && this.album.previous();
   }
   if (code == KEY_NEXT_PAGE)
   {
      !!this.album && this.album.attached && this.album.next();
   }
   if (code == KEY_QUIT)
   {
      !!this.album && this.album.attached && this.application.unload_album();
      !!this.ending && this.ending.visible && this.application.unload_ending();
   }
   if (code == KEY_MENU)
   {
      !!this.level && this.level.delegate.main_menu();
   }
   if (code == KEY_NEXT_LEVEL)
   {
      !!this.level && this.level.delegate.next_level();
   }
   if (code == KEY_SOUND)
   {
      this.application.toggle_sound();
   }
   this.keys_down.add(code);
}

EVR.Delegate.prototype.handle_enter = function()
{
   if (!!this.ending && this.ending.finished)
   {
      this.application.unload_ending();
      return;
   }
   if (!!this.about && this.about.attached)
   {
      this.application.unload_about();
      return;
   }
   if (!!this.instructions && this.instructions.attached)
   {
      this.application.unload_instructions();
      return;
   }
   if (this.history.attached)
   {
      this.application.unload_history();
      return;
   }
   if (!!this.level)
   {
      this.level.delegate.enter();
   }
   if (!!this.menu && this.menu.attached)
   {
      this.menu.execute();
   }
   if (!!this.album)
   {
      this.album.attached && this.album.toggle_menu();
   }
   if (!!!this.level)
   {
      this.application.build_start_menu();
   }
}

EVR.Delegate.prototype.handle_key_up = function(event)
{
   event = this.fix_event(event);
   var code = event.keyCode;
   if (code == KEY_SPRINT || code == KEY_SPRINT_ALTERNATE)
   {
      !!this.level && this.level.delegate.cancel_sprint();
   }
   this.keys_down.remove(code);
}

EVR.Delegate.prototype.handle_key_press = function(event)
{
   event = this.fix_event(event);
   var code = event.keyCode || event.charCode;
   switch (code)
   {
      case KEY_RESTART:
      case KEY_RESTART + 32:
         !!this.level && this.level.delegate.restart();
   }
}

EVR.Delegate.prototype.handle_resize_event = function()
{
   if (this.resize_response !== false)
   {
      window.clearInterval(this.resize_response);
   }
   var current = this;
   this.resize_response = window.setTimeout(
      function() { current.respond_to_resize() }, 200);
}

EVR.Delegate.prototype.respond_to_resize = function()
{
   this.application.repopulate();
}

EVR.Delegate.prototype.fix_event = function(event)
{
   if (typeof(event) == "undefined")
   {
      event = window.event;
   }
   return event;
}

EVR.Delegate.prototype.toString = function()
{
   return "[object EVR.Delegate]";
}
18.205.56.209
18.205.56.209
18.205.56.209
 
June 6, 2016