#==============================================================================
#  @> Splash Screen ~ Karin's Soulkeeper, 2015
#------------------------------------------------------------------------------
#   v1.0 - May 10 : Started & finished.
#------------------------------------------------------------------------------
#  * Description:
#    This script displays a splash image at the start of the game. 
#------------------------------------------------------------------------------
#  * To Use:
#    Put this script below Materials and above Main.
#------------------------------------------------------------------------------
#  * Compatibility:
#    This script overwrites the SceneManager.first_scene_class method. If
#    there are scripts which also modify the said method, place this script
#    below it.
#------------------------------------------------------------------------------
#  * Terms:
#    Free to use in any kind of project, with or without credit. I wouldn't
#    really mind. Though I'd appreciate it! (^w^)/
#    Just don't, you know, claim that you made this here script yourself,
#    Because that's just mean (._.)
#==============================================================================

#CUSTOMIZATION OPTIONS
module KS
  module Splash_Screen
  
  #--------------------------------------------------------------------------
  # Enable/Disable script. Only affects playtests, and not the final game.
  #--------------------------------------------------------------------------
  # I suggest you disable this after checking, as it does slow play testing.
  # But hey, whatever boats your goat float.
  #--------------------------------------------------------------------------
  ENABLED = false
  
  #--------------------------------------------------------------------------
  # Set the name of the file to use in splash scene (Place in Graphics/System/)
  #--------------------------------------------------------------------------
  IMAGE_NAME = "SplashScreen"
  
  #--------------------------------------------------------------------------
  # Set time to display splash screen image (in frames)
  #--------------------------------------------------------------------------
  DISPLAY_TIME = 180
  
  #--------------------------------------------------------------------------
  # Set fadein transition duration (in frames)
  #--------------------------------------------------------------------------
  FADEIN_TIME = 90
  
  #--------------------------------------------------------------------------
  # Set fadeout transition duration (in frames)
  #--------------------------------------------------------------------------
  FADEOUT_TIME = 180
  
  end
end
# END OF CUSTOMIZATION OPTIONS

#==============================================================================
# ** Modified Module: SceneManager
#==============================================================================
if !$TEST || KS::Splash_Screen::ENABLED
module SceneManager
  #--------------------------------------------------------------------------
  # * Overwrite: Get First Scene Class
  #--------------------------------------------------------------------------
  def self.first_scene_class
    $BTEST ? Scene_Battle : Scene_SplashScreen
  end
end
#==============================================================================
# ** New Class: Scene_SplashScreen
#------------------------------------------------------------------------------
#  Displays an image prior to startup. Derived from Scene_GameOver.
#==============================================================================
class Scene_SplashScreen < Scene_Base
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  def start
    super
    puts "Splash screen active;"
    $data_system.title_bgm.play
    fadeout_frozen_graphics
    create_background
  end
  #--------------------------------------------------------------------------
  # * Termination Processing
  #--------------------------------------------------------------------------
  def terminate
    super
    dispose_background
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    Graphics.wait(KS::Splash_Screen::DISPLAY_TIME)
    goto_title
  end
  #--------------------------------------------------------------------------
  # * Execute Transition
  #--------------------------------------------------------------------------
  def perform_transition
    Graphics.transition(fadein_speed)
  end
  #--------------------------------------------------------------------------
  # * Fade Out Frozen Graphics
  #--------------------------------------------------------------------------
  def fadeout_frozen_graphics
    Graphics.transition(fadeout_speed)
    Graphics.freeze
  end
  #--------------------------------------------------------------------------
  # * Create Background
  #--------------------------------------------------------------------------
  def create_background
    @sprite = Sprite.new
    @sprite.bitmap = Cache.system(KS::Splash_Screen::IMAGE_NAME)
  end
  #--------------------------------------------------------------------------
  # * Free Background
  #--------------------------------------------------------------------------
  def dispose_background
    @sprite.bitmap.dispose
    @sprite.dispose
  end
  #--------------------------------------------------------------------------
  # * Get Fade Out Speed
  #--------------------------------------------------------------------------
  def fadeout_speed
    return KS::Splash_Screen::FADEOUT_TIME
  end
  #--------------------------------------------------------------------------
  # * Get Fade In Speed
  #--------------------------------------------------------------------------
  def fadein_speed
    return KS::Splash_Screen::FADEIN_TIME
  end
  #--------------------------------------------------------------------------
  # * Transition to Title Screen
  #--------------------------------------------------------------------------
  def goto_title
    Graphics.fadeout(Graphics.frame_rate)
    SceneManager.goto(Scene_Title)
  end
end

end