 |
解压事件中的脚本: file=File.open("../__scripts.as","w") file.write("//本代码是系统自动生成的,请不要修改这些代码\n") file.write("\n") file.write("package\n") file.write("{\n") file.write(" import RPG.*;\n") file.write(" public class __scripts\n") file.write(" {\n") #file.write(" public var num:int="+$game_scripts.length.to_s+";\n") file.write(" private var id:int;\n") file.write(" public var event_id:int=-1;\n") file.write(" private var fun:Function;\n") file.write(" public function __scripts(id:int):void\n") file.write(" {\n") file.write(" this.id=id;\n") file.write(" }\n") file.write(" public function execute():Boolean\n") file.write(" {\n") enter_flag=true # 上一条脚本是否换行 for i in 0..$game_scripts.length-1 file.write(" if (this.id=="+i.to_s+")\n") file.write(" {\n") file.write(" fun=function():Boolean\n") file.write(" {\n") for j in 0..$game_scripts[i].length-1 content=$game_scripts[i][j] file.write(" ") if enter_flag file.write(content) trc=trim(content) # 下面判断是否该换行 if trc[-1,1]==";" or \ /^[^;]*;[^;]*\/\/.*$/===trc or \ /^\/\//===trc # 开头以“//”开始的脚本视为整行注释 file.write("\n") enter_flag=true else enter_flag=false end end file.write(" return true;\n") file.write(" };\n") file.write(" }\n") end file.write(" return fun();\n") file.write(" }\n") file.write(" }\n") file.write("}") file.close()
|
 |
解压公共事件:ce=load_data("Data/CommonEvents.rxdata") file=File.open("../RXData/CommonEvents.as","w") file.write("//这些代码是系统自动生成的,请不要修改这些代码\n") file.write("\n") file.write("package RXData\n") file.write("{\n") file.write(" public dynamic class CommonEvents\n") file.write(" {\n") file.write(" public function CommonEvents()\n") file.write(" {\n") for id in 1..ce.length-1 a=" this["+id.to_s+"]" it=ce[id] file.write(a+"=new Object();\n") file.write(a+".name="+strfmt(it.name)+";\n") file.write(a+".trigger="+it.trigger.to_s+";\n") file.write(a+".switch_id="+it.switch_id.to_s+";\n") eventlist(file,it.list,a) # 执行内容 end file.write(" }\n") file.write(" }\n") file.write("}") file.close()
|
 |
函数库:$game_scripts=[] def trim(str) return str if (str.empty?) while str[0,1]==" " or str[0,1]=="\t" str[0,1]="" end while str[-1,1]==" " str[-1,1]="" end return str end # 安全输出字符串 def strfmt(str) str=str.gsub(/\\(\w)/,"\\\\\\\\\\1") str=str.gsub(/"/,"\\\"") str="\""+str+"\"" # 参数0加字符串符号 return str end
# 用于输出事件的执行内容 # 输出执行内容 def eventlist(file,list,script_head) file.write(script_head+".list=new Array();\n") scr_ar=[] for k in 0..list.length-1 l=list[k] next if (l.code==509 || l.code==209) next if (l.code==108 || l.code==408) # 跳过注释 s4=script_head+".list["+k.to_s+"]" file.write(s4+"=new Object();\n") file.write(s4+".code="+l.code.to_s+";\n") file.write(s4+".indent="+l.indent.to_s+";\n") if l.code==355 or l.code==655 # 脚本 file.write(s4+".parameters=["+$game_scripts.length.to_s+"];\n") scr_ar.push(l.parameters[0]) else pars=l.parameters pars[0]=strfmt(pars[0]) if ([101,123,401].include?(l.code)) file.write(s4+".parameters=["+pars.join(",")+"];\n") # 如果还有脚本组未导出 if (scr_ar.length>0) $game_scripts.push(scr_ar) scr_ar=[] end end end end
|