#==============================================================================
# ■ 文章导入导出 v0.3 1003 by zh99998
#------------------------------------------------------------------------------
# 把这个放F11里,运行游戏
# 弹出的文本文档就是导出的对话,用记事本修改即可
# 导入的时候把第一行改为false
# 感谢kissye ^ ^
#==============================================================================
#--------------------------------------------------------------------------
# ● 设定部分
# OUT : 导入/导出标记
# TAB : 指定分隔符,默认为两个空格
# HEAD: 是否显示事件位置信息
# INFO: 是否显示对话角色头像等信息
#--------------------------------------------------------------------------
OUT = true #导入时请改为false
TAB = " " * 2
HEAD = true
INFO = true
#--------------------------------------------------------------------------
# ● 缩进
#--------------------------------------------------------------------------
INDENT = HEAD ? INFO ? 3 : 2 : INFO ? 1 : 0
#--------------------------------------------------------------------------
# ● 导出方法定义
#--------------------------------------------------------------------------
def read_event(list, head)
text = []
list.each do |command|
text.push ["#{HEAD ? TAB * 2 : ""}<头像名[#{command.parameters[0]}]头像编号[#{command.parameters[1]}]背景[#{command.parameters[2]}]位置[#{command.parameters[3]}]>\r\n"]if command.code == 101
text[-1].push (TAB * INDENT + command.parameters[0]) if command.code == 401
end
return if text.empty?
result = HEAD ? head : ""
text.each do |text|
INFO ? result += text.shift : text.shift
text.each {|text| result += text + "\r\n"}
end
#想不出词了,于是全用text -0-
return result
end
#--------------------------------------------------------------------------
# ● 导入方法定义
#--------------------------------------------------------------------------
def save_event(list)
index = 0
while index < list.size
if list[index].code == 101
list[index].parameters = @text[0].shift
index += 1
#获取接下来的401
while index < list.size and list[index].code == 401
if @text[0].empty? #如果text里的文字已经没有了,就直接删掉当前命令
list.delete_at(index)
else
list[index].parameters[0] = @text[0].shift
indent = list[index].indent#替换文字,并记录当前命令缩排等级(后面的添加用)
index += 1
end
end
for text in @text[0] #如果text还有多余的,就添加上
list.insert(index, RPG::EventCommand.new(401, indent, [text]))
index += 1
end
@text.shift #清除text的第一项,准备下一次循环
else
index += 1 #如果命令不是101,就直接检查下一命令
end
end
return list #返回修改后的命令列表
end
if OUT
#--------------------------------------------------------------------------
# ● 导出
#--------------------------------------------------------------------------
file = File.open("messages.txt", "wb")
load_data("Data/MapInfos.rvdata").each_pair do |map_id, map|
file.write("<地图[#{map_id}]#{map.name}>\r\n") if HEAD
load_data(sprintf("Data/Map%03d.rvdata", map_id)).events.each_pair {|event_id, event| event.pages.each_index {|page_id| file.write(read_event(event.pages[page_id].list, "#{TAB}<事件[#{event_id}]#{event.name}页[#{page_id+1}]>\r\n"))}}
end
file.write("<全局事件>\r\n")
load_data("Data/CommonEvents.rvdata").each {|command| file.write(read_event(command.list, "#{TAB}<全局事件[#{command.id}]>\r\n")) if command}
file.write("<战斗>\r\n")
load_data("Data/Troops.rvdata").each {|battle| battle.pages.each_index {|page_id| file.write(read_event(battle.pages[page_id].list, "#{TAB}<战斗[#{battle.id}]#{battle.name}页[#{page_id+1}]>\r\n"))} if battle}
file.close
`notepad.exe messages.txt`
else
#--------------------------------------------------------------------------
# ● 导入
#--------------------------------------------------------------------------
@text = []
file = File.open("messages.txt")
file.each_line do |line|
line = line.split("")[-1] #该死的编码问题……
line = line.split("\n")[0] #去掉换行符
if line and line[HEAD ? TAB.size * 2 : 0, 11] == "<头像名[" and INFO
line = line[TAB.size * 2, line.size - TAB.size * 2] if HEAD
@text.push [[line[11,line.size - 46], line[-21,1].to_i, line[-12,1].to_i, line[-3,1].to_i]]
elsif line and line[0, TAB.size * INDENT] == TAB * INDENT and line[0,1] != "<"
@text[-1].push line[TAB.size * INDENT, line.size - TAB.size * INDENT]
end
end
file.close
load_data("Data/MapInfos.rvdata").each_key do |map_id|
map_file = (sprintf("Data/Map%03d.rvdata", map_id))
data = load_data(map_file)
data.events.each_pair {|event_id, event| event.pages.each_index {|page_id| data.events[event_id].pages[page_id].list = save_event(event.pages[page_id].list)}}
save_data(data, map_file)
end
data = load_data("Data/CommonEvents.rvdata")
data.each_index {|event_id| data[event_id].list = save_event(data[event_id].list) unless event_id == 0}
save_data(data,"Data/CommonEvents.rvdata")
data = load_data("Data/Troops.rvdata")
data.each_index {|troop_id| data[troop_id].pages.each_index {|page_id| data[troop_id].pages[page_id].list = save_event(data[troop_id].pages[page_id].list)}unless troop_id == 0}
save_data(data, "Data/Troops.rvdata")
end