#==============================================================================
# 
# ▼ SAI RMXP Blending Options v1.0
# -- Last Updated: 2012.01.12
# -- Author: Bishop Myers ("Sailerius")
# -- Requires: n/a
#
#==============================================================================
$imported = {} if $imported.nil?
$imported["SAI-RMXPBlendingOptions"] = true
#==============================================================================
# ▼ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2012.01.12 - First release
# 
#==============================================================================
# ▼ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# In RMXP, you had the ability to specify blending mode and opacity for each
# event. For some reason, this ability has been removed. This script attempts
# to compensate by allowing you to change blending mode and opacity through
# a notetag.
# 
#==============================================================================
# ▼ Instructions
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
# 
# This script adds the following notetags, which must be used in an event's
# name.
# <blend mode: x>
#   x must be one of 0, 1, or 2. 0 = normal; 1 = add; 2 = subtract
# <opacity: y>
#   y must be 0-255 inclusive
# 
#==============================================================================
# ▼ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script should be fully compatible with any other well-written Ace
# scripts, although I offer no guarantee of compatibility for scripts which
# rewrite the Sprite_Character's initialization method.
#
#==============================================================================
# ■ Game_CharacterBase
#==============================================================================
class Game_CharacterBase
  #--------------------------------------------------------------------------
  # * Allow writing to blend_type and opacity
  #--------------------------------------------------------------------------
  attr_accessor   :blend_type
  attr_accessor   :opacity
end
#==============================================================================
# ■ Sprite_Character
#==============================================================================
class Sprite_Character < Sprite_Base
  #--------------------------------------------------------------------------
  # * alias method: initialize
  #--------------------------------------------------------------------------
  alias :sprite_character_initialize_saiblendmodes :initialize
  def initialize(viewport, character = nil)
    sprite_character_initialize_saiblendmodes(viewport, character)
    # Don't bother with followers or vehicles
    if @character.instance_of?(Game_Event)
      # Parse the name for tags
      blend_regex = /<BLEND MODE: ((?:\d+,?\s*))>/i
      opacity_regex = /<OPACITY: ((?:\d+,?\s*))>/i
      blend_mode = @character.name.scan(blend_regex)
      opacity = @character.name.scan(opacity_regex)
      unless opacity.empty?
        # Get the value out of the nested arrays
        blend_mode = blend_mode.first.first
        # Set the blend mode
        @character.blend_type = blend_mode.to_i
      end
      unless blend_mode.empty?
        # Get the value out of the nested arrays
        opacity = opacity.first.first
        # Set the blend mode
        @character.opacity = opacity.to_i
      end    
    end
  end
end