#=========================================================================== # ◆ A1 Scripts ◆ # 音楽同期(RGSS3) # # バージョン : 1.10 (2012/01/02) # 作者 : A1 # URL     : http://a1tktk.web.fc2.com/ #--------------------------------------------------------------------------- # 機能: # ・音楽に合わせてメッセージを表示します #--------------------------------------------------------------------------- # 更新履歴   :2011/12/15 Ver1.00 リリース #    :2012/01/02 Ver1.10 A1共通スクリプトVer3.30対応 #--------------------------------------------------------------------------- # 設置場所 #  必要スクリプトより下 # # 必要スクリプト # A1共通処理スクリプトVer3.30 # ミリ秒ウェイト # マップイベント # 空メッセージでウィンドウを開かない #--------------------------------------------------------------------------- # 使い方 # 設定項目にメッセージを記述 # メッセージコマンド # # (d) 次の文字を表示するまでの時間 # 四分音符なら16 八分音符なら8 16分音符なら4 を指定など # 音符の長さに合わせて指定 # # {d} 次の文字を表示する時間 # 1小節 = 4拍子 * 16分 で計算(4拍子の場合) # # \SD[d] (d)と同様 # \WD[d] {d}と同様 # # \ES 音楽同期モードを終了させる # # \SF[on|off] 決定/キャンセルボタンによる文字送りを制御 # off で文字送りを不許可にする # # \BGM[v,p,n] BGMを再生する # v:ボリューム # p:ピッチ # n:ファイル名 # ファイル名を nil にすると演奏ストップ # # \MEV[no] マップイベントを並列処理モードで起動する # no:起動するページNo # マップイベントについてはスクリプト「マップイベント」参照 # # イベントコマンド「注釈」に記述 # #  音楽同期 [filename] # filename:再生・同期させるAudioファイル #============================================================================== $imported ||= {} $imported["A1_FixMusic"] = true if $imported["A1_Common_Script"] and $imported["A1_Use_Usec"] and $imported["A1_MapEvent"] and $imported["A1_EmptyMassage"] old_common_script("音楽同期", "3.30") if common_version < 3.30 #============================================================================== # ■ 設定項目 #============================================================================== module A1_System::Song #-------------------------------------------------------------------------- # 同期させるメッセージを含んだハッシュ #-------------------------------------------------------------------------- SONG_DATA = { # Audioファイル名をキー "sol_battle002_xp" => [ # ボリューム, ピッチ, テンポ, 1小節の拍子数, 開始補正 [100,100,145,4,3.2], [ # 顔グラフィック, 顔グラフィックIndex, 背景タイプ, 表示位置 ["",0,0,2], # 表示するメッセージ/コマンド "\\SF[off]" ], #-------------------------------------------------------------------------- # 以下、文章情報の繰り返し #-------------------------------------------------------------------------- [ ["",0,0,2], "{104}" ], [ ["",0,1,2], "\\MEV[1]さ(8)よ(8)な(8)ら(32) わ(6)た(6)し(12)が(8)あ(12)い(12)し(8)た(12)", "あ(12)な(8)た(12)に(12)は(8)も(8)う(12) あ(8)え(16)な(16)い(16)", ], [ ["",0,1,2], "き(8)っ(8)と(32) ふ(12)た(12)り(8)が(12)す(12)ご(8)し(12)て(12)た(8)", "ひ(12)び(12)は(8)ま(4)ぼ(12)ろ(16)し(64)", ], [ ["",0,1,2], "ふ(24)た(4)り(4)の(8)お(8)も(8)い(8) す(24)れ(4)ち(4)が(8)い(8)つ(4)づ(4)け(4)た(4)", "ふ(24)た(4)り(4)を(8)き(8)ず(8)つ(8)け(8)て(8)い(8)た(8)だ(8)け(8)な(8)の(8)", ], [ ["",0,1,2], "もう(24)い(4)ち(4)ど(12)だ(12)け(8)だ(16)き(16)し(16)め(16)た(12)ら(12)か(8)わ(12)れ(12)た(8)の?(40)", ], [ ["",0,1,2], "さ(8)よ(8)な(8)ら(32) わ(6)た(6)し(12)が(8)あ(12)い(12)し(8)た(12)", "あ(12)な(8)た(12)に(12)は(8)も(8)う(12) あ(8)え(16)な(16)い(16)", ], [ ["",0,1,2], "き(8)っ(8)と(32) ふ(12)た(12)り(8)が(12)す(12)ご(8)し(12)て(12)た(8)", "ひ(12)び(12)は(8)ま(4)ぼ(12)ろ(16)し(64)", ], [ ["",0,1,2], "{1784}\\MEV[2]", ], [ ["",0,1,2], "{1920}\\MEV[3]", ], [ ["",0,1,2], "\\MEV[4]も(4)う(12)あ(5)え(5)な(6)い(12)な(12)\\MEV[5]ら(8) う(12)し(12)な(12)え(12)る\\MEV[6](8)な(8)ら(4)", "た(4)だ(4)あ(4)つ(4)く(4) き(4)つ(4)く(4)キ(4)ス(4)く(4)わ(4)え(4)て(4) く(4)ち(4)づ(4)け(16)て(16)", ], [ ["",0,1,2], "\\MEV[1]さ(8)よ(8)な(8)ら(32) わ(6)た(6)し(12)が(8)あ(12)い(12)し(8)た(12)", "あ(12)な(8)た(12)に(12)は(8)も(8)う(12) あ(8)え(16)な(16)い(16)", ], [ ["",0,1,2], "き(8)っ(8)と(32) ふ(12)た(12)り(8)が(12)す(12)ご(8)し(12)て(12)た(8)", "ひ(12)び(12)は(8)ま(4)ぼ(12)ろ(16)し(64)", ], [ ["",0,1,2], "\\ES\\MEV[7]\\SF[on]\\BGM[0,0,nil]", ], ] } end #============================================================================== # ■ Window_Message #------------------------------------------------------------------------------ #  文章表示に使うメッセージウィンドウです。 #============================================================================== class Window_Message < Window_Base #-------------------------------------------------------------------------- # ☆ オブジェクト初期化 #-------------------------------------------------------------------------- alias a1_wm_song_initialize initialize def initialize @wait_for_next = 0 @wait_flg = false a1_wm_song_initialize end #-------------------------------------------------------------------------- # ○ 一文字出力前のウェイト #-------------------------------------------------------------------------- alias a1_fix_music_wm_wait_for_one_character_before wait_for_one_character_before def wait_for_one_character_before waito_for_fix_music if $game_temp.start_time > 0 a1_fix_music_wm_wait_for_one_character_before end #-------------------------------------------------------------------------- # ☆ 一文字出力後のウェイト #-------------------------------------------------------------------------- alias a1_fix_music_wm_wait_for_one_character wait_for_one_character def wait_for_one_character a1_fix_music_wm_wait_for_one_character if $game_temp.start_time == 0 end #-------------------------------------------------------------------------- # ☆ 音楽に合わせたウェイト #-------------------------------------------------------------------------- def waito_for_fix_music if @wait_flg Fiber.yield while calc_tempo < @wait_for_next @wait_flg = false end end #-------------------------------------------------------------------------- # ☆ 改ページ処理 #-------------------------------------------------------------------------- alias a1_fix_music_wm_new_page new_page def new_page(text, pos) waito_for_fix_music if $game_temp.start_time > 0 a1_fix_music_wm_new_page(text, pos) end #-------------------------------------------------------------------------- # ☆ テンポ計算 #-------------------------------------------------------------------------- def calc_tempo now_time = $a1_common.now_usec return (now_time - $game_temp.start_time) / ((1000.0 * ((60.0 / $game_temp.tempo)) / 16.0) ) end #-------------------------------------------------------------------------- # ○ 文章のチェック #-------------------------------------------------------------------------- alias a1_fix_music_wm_chk_text chk_text def chk_text(text) text.gsub!(/\eES/,"") return a1_fix_music_wm_chk_text(text) end #-------------------------------------------------------------------------- # ☆ 制御文字の処理 # code : 制御文字の本体部分(「\C[1]」なら「C」) # text : 描画処理中の文字列バッファ(必要なら破壊的に変更) # pos : 描画位置 {:x, :y, :new_x, :height} #-------------------------------------------------------------------------- alias a1_fix_music_wm_process_escape_character process_escape_character def process_escape_character(code, text, pos) case code.upcase when 'ES' $game_temp.start_time = 0 when 'WD' text.slice!(/\[([0-9]+)\]/) rescue 0 @wait_for_next = $1.to_i @wait_flg = true close when 'SD' text.slice!(/\[([0-9]+)\]/) rescue 0 @wait_for_next += $1.to_i @wait_flg = true when 'SF' text.slice!(/\[((?:on|off))\]/) rescue 0 case $1 when "on" @enable_show_fast = true when "off" @enable_show_fast = false end when 'BGM' text.slice!(/\[(\d+)[,](\d+)[,](.+)\]/) rescue 0 RPG::BGM.stop if $3 == "nil" RPG::BGM.new($3,$1.to_i,$2.to_i).play if $3 != "nil" when 'MEV' text.slice!(/\[(\d+)\]/) rescue 0 $game_map.start_map_event($1.to_i) else a1_fix_music_wm_process_escape_character(code, text, pos) end end end #============================================================================== # ■ Game_Temp #------------------------------------------------------------------------------ #  セーブデータに含まれない、一時的なデータを扱うクラスです。このクラスのイン # スタンスは $game_temp で参照されます。 #============================================================================== class Game_Temp #-------------------------------------------------------------------------- # ○ 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :tempo attr_accessor :start_time attr_accessor :tempo_step #-------------------------------------------------------------------------- # ☆ オブジェクト初期化 #-------------------------------------------------------------------------- alias a1_gt_song_initialize initialize def initialize a1_gt_song_initialize @tempo = 0 @start_time = 0 @tempo_step = 0 end #-------------------------------------------------------------------------- # ○ 歌データセット #-------------------------------------------------------------------------- def set_song_data(file_name) song_data = A1_System::Song::SONG_DATA[file_name].clone info = song_data[0] @tempo = info[2].to_i @tempo_step = info[3] lists = [] for j in 1...song_data.size song_list = song_data[j] lists.push($a1_common.create_event_list(101, 0, song_list[0])) for i in 1...song_list.size text = song_list[i].clone text.gsub!(/\(([0-9]+)\)/i) { sprintf("\\SD[%d]",$1.to_i) } text.gsub!(/\{([0-9]+)\}/i) { sprintf("\\WD[%d]",$1.to_i) } text = sprintf("%s\\^",text) if i == song_list.size-1 lists.push($a1_common.create_event_list(401, 0, [text])) end end lists.push(RPG::EventCommand.new) RPG::BGM.new(file_name,info[0],info[1]).play @start_time = ($a1_common.now_usec - (1000.0 * ((60.0 / @tempo))) * info[4]) return lists end end #============================================================================== # ■ A1_System::CommonModule #============================================================================== class A1_System::CommonModule #-------------------------------------------------------------------------- # ☆ 注釈コマンド定義 #-------------------------------------------------------------------------- alias a1_fix_music_define_command define_command def define_command a1_fix_music_define_command @cmd_108["音楽同期"] = :fix_music end end #============================================================================== # ■ Game_Interpreter #------------------------------------------------------------------------------ #  イベントコマンドを実行するインタプリタです。このクラスは Game_Map クラス、 # Game_Troop クラス、Game_Event クラスの内部で使用されます。 #============================================================================== class Game_Interpreter #-------------------------------------------------------------------------- # ○ 音楽同期 #-------------------------------------------------------------------------- def fix_music(params) child = Game_Interpreter.new(@depth + 1) child.setup($game_temp.set_song_data(params[0]), same_map? ? @event_id : 0) child.run end end end