そんなわけで、コマンドリストを作ってみた。
一行づつファイルを読み込んで、<>で囲まれた部分をコマンドとして解釈するようにしている。
def commond(text_lines) @com = [] text_lines.each_line{|text_line| @com << text_line } /<(.*)?>(.*)?<\/(.*)?>/ =~ @com[@num] case ($1) when ("wait") then #コマンド行を削除 @all_text["test"][@page] = @all_text["test"][@page].sub(/<(.*)?>(.*)?<\/(.*)?>\n/,"") when ("img_path") then args = $2.split(/,/) #コマンド行を削除 @all_text["test"][@page] = @all_text["test"][@page].sub(/<(.*)?>(.*)?<\/(.*)?>\n/,"") setImg(args[0].to_i,args[1], args[2]) commond(@all_text["test"][@page]) when ("img_move") then args = $2.split(/,/) case args[1] when "LtoL" moveLtoL(args[0].to_i) when "LtoR" moveLtoR(args[0].to_i) when "RtoL" moveRtoL(args[0].to_i) when "RtoR" moveRtoR(args[0].to_i) end #コマンド行を削除 @all_text["test"][@page] = @all_text["test"][@page].sub(/<(.*)?>(.*)?<\/(.*)?>\n/,"") commond(@all_text["test"][@page]) when ("img_position") then args = $2.split(/,/) #コマンド行を削除 @all_text["test"][@page] = @all_text["test"][@page].sub(/<(.*)?>(.*)?<\/(.*)?>\n/,"") setImgPosition(args[0].to_i, args[1]) commond(@all_text["test"][@page]) when ("img_status") then args = $2.split(/,/) #コマンド行を削除 @all_text["test"][@page] = @all_text["test"][@page].sub(/<(.*)?>(.*)?<\/(.*)?>\n/,"") setImgStatus(args[0].to_i, args[1], args[2]) commond(@all_text["test"][@page]) when ("go_move") then p "ok" args = $2.split(/,/) #コマンド行を削除 @all_text["test"][@page] = @all_text["test"][@page].sub(/<(.*)?>(.*)?<\/(.*)?>\n/,"") goMove() @wait = true else nextPage() createText(@all_text["test"][@page]) end end