Advertisement
LiTTleDRAgo

[RGSS/2/3] Missing Audio Replacer

May 10th, 2017
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.38 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # Missing Audio Replacer
  3. # Version: 1.00
  4. # Author : LiTTleDRAgo
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  6. ($imported ||= {})[:drg_missing_audio_replacer] = 1.00
  7. #==============================================================================
  8. # ** Audio
  9. #------------------------------------------------------------------------------
  10. #  This class handles audio. Background music, etc. is managed here
  11. #==============================================================================
  12. class << Audio
  13.   #--------------------------------------------------------------------------
  14.   # * CONFIGURATION
  15.   #--------------------------------------------------------------------------
  16.   BGM_REPLACE = {
  17.     'Title_Music'    => ['064-Slow07'],
  18.     }
  19.    
  20.   BGS_REPLACE = {
  21.     'Rain'           => ['005-Rain01', '006-Rain02'],
  22.     }
  23.  
  24.   ME_REPLACE = {
  25.     'Battle_Victory' => ['001-Victory01'],
  26.     }
  27.  
  28.   SE_REPLACE = {
  29.     'Cat'            => ['067-Animal02'],
  30.     'Horse'          => ['071-Animal06'],
  31.     }
  32.   #--------------------------------------------------------------------------
  33.   # * CONFIGURATION END
  34.   #--------------------------------------------------------------------------
  35.   @@sound_check = {}
  36.   #--------------------------------------------------------------------------
  37.   # * Play Background Music
  38.   #     bgm : background music to be played
  39.   #--------------------------------------------------------------------------
  40.   [:bgm,:bgs,:me,:se].each do |method|
  41.     $@ || alias_method(:"#{method}_exist_play", :"#{method}_play")
  42.     define_method(:"#{method}_play") do |*bgm|
  43.       bgm[0] = sound_exist?(File.basename(bgm[0]), method) || ''
  44.       send(:"#{method}_exist_play",*bgm) rescue send(:"#{method}_stop")
  45.     end
  46.   end
  47.   #--------------------------------------------------------------------------
  48.   # * Determine if Audio Exist
  49.   #--------------------------------------------------------------------------
  50.   def sound_exist?(sound,type)
  51.     key = [sound,type]
  52.     return @@sound_check[key] if @@sound_check[key] != nil
  53.     all_sound = [sound] + (eval("#{type.to_s.upcase}_REPLACE")[sound] || [])
  54.     @@sound_check[key] = all_sound.map {|s| "Audio/#{type}/#{s}"}.find do |s|
  55.       [se_exist_play(s, 0, 0), se_stop] rescue false
  56.     end || false
  57.   end
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement