赞 | 189 |
VIP | 627 |
好人卡 | 188 |
积分 | 95 |
经验 | 171230 |
最后登录 | 2024-7-3 |
在线时间 | 5073 小时 |
Lv4.逐梦者 (版主)
- 梦石
- 0
- 星屑
- 9532
- 在线时间
- 5073 小时
- 注册时间
- 2013-6-21
- 帖子
- 3580
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 RyanBern 于 2016-3-15 13:03 编辑
使用RMXP时,有极低的几率出现游戏数据库损毁,从而导致制作进度完全丢失。所以我们要时刻记得备份游戏数据库。
但是毕竟有的时候会忘记,这样的话,如果出现游戏数据库损毁的情况就跪了。
所以,写这个脚本以防数据库突然损毁,在测试的时候实时备份。防患于未然。
#============================================================================= # 自动备份游戏数据 Ver 1.1 #----------------------------------------------------------------------------- # By : RyanBern #----------------------------------------------------------------------------- # 说明: # 这是一个自动备份游戏 Data 文件夹的脚本,以防止 Data 文件夹突然损坏而造成 # 制作进度的大量损失。 # 备份的时机为使用 RMXP 进行游戏测试的时候,每开一次游戏就会备份一次数据, # 如果正常打开游戏不会备份数据。具体设置请在下面的 RB::Data_Backup 进行设置。 #============================================================================= module RB end module RB::Data_Backup # 备份文件夹,可使用绝对路径或相对路径,不可设置为"Data" Backup_Dir = "Backup" # 启用备份,设置为 true 时自动备份 Activated = false # 是否仅备份数据(而不备份地图) Data_Only = false # 最大备份数量 Max_Backup = 3 end class Window_Backup < Window_Base def initialize super(0, 0, 240, 96) self.contents = Bitmap.new(width - 32, height - 32) self.x = 320 - width / 2 self.y = 240 - height / 2 @max = 1 @current = 0 refresh end def refresh self.contents.clear self.contents.draw_text(4, 0, 192, 32, "正在备份数据..") self.contents.draw_text(4, 32, 64, 32, "进度") end def draw_bar self.contents.fill_rect(64, 32 + 4, 144, 24, Color.new(255, 255, 255, 255)) self.contents.fill_rect(64 + 1, 32 + 5, 142, 22, Color.new(0, 0, 0, 0)) w = @max == 0 ? 140 : Integer(140.0 * @current / @max) self.contents.fill_rect(64 + 2, 32 + 6, w, 20, Color.new(255, 255, 255, 255)) end def set(num, max) @max = max @current = num draw_bar end end class Scene_Title def backup_data unless $DEBUG && RB::Data_Backup::Activated return end dir_name = RB::Data_Backup::Backup_Dir data_dir = "Data" if dir_name == data_dir print "目标文件夹和原文件夹相同。无法备份。" @backup_window.visible = false return end unless File.exists?(dir_name) Dir.mkdir(dir_name) end dirnames = [] Dir.foreach(dir_name) do |s| dirnames << s if File.directory?(dir_name + '/' + s) && s != "." && s != ".." end (0..(dirnames.size - RB::Data_Backup::Max_Backup)).each do |i| Dir.foreach(dir_name + '/' + dirnames[i]) do |f| next if f == "." || f == ".." File.delete(dir_name + '/' + dirnames[i] + '/' + f) end Dir.rmdir(dir_name + '/' + dirnames[i]) end time_string = Time.now.strftime("%Y_%m_%d_%H_%M_%S") dir_name += "/Backup_" + time_string Dir.mkdir(dir_name) filenames = [] Dir.foreach(data_dir) do |s| filenames << s if s != "." && s != ".." end if RB::Data_Backup::Data_Only filenames.reject!{|s| /Map\d+\.rxdata/ === s} end filenames.each_with_index do |filename, index| real_name = dir_name + '/' + filename file = File.open(real_name, "wb") Marshal.dump(load_data(data_dir + '/' + filename), file) file.close @backup_window.set(index + 1, filenames.size) Graphics.update end 16.times do @backup_window.opacity -= 16 @backup_window.contents_opacity -= 16 Graphics.update end @backup_window.visible = false end unless method_defined? :rb_main_20150409 alias rb_main_20150409 main def main $game_system = Game_System.new $data_system = load_data("Data/System.rxdata") @backup_window = Window_Backup.new @backup_window.visible = RB::Data_Backup::Activated && $DEBUG rb_main_20150409 @backup_window.dispose end end unless method_defined? :rb_update_20150409 alias rb_update_20150409 update def update if @backup_window.visible backup_data return end rb_update_20150409 end end end
#=============================================================================
# 自动备份游戏数据 Ver 1.1
#-----------------------------------------------------------------------------
# By : RyanBern
#-----------------------------------------------------------------------------
# 说明:
# 这是一个自动备份游戏 Data 文件夹的脚本,以防止 Data 文件夹突然损坏而造成
# 制作进度的大量损失。
# 备份的时机为使用 RMXP 进行游戏测试的时候,每开一次游戏就会备份一次数据,
# 如果正常打开游戏不会备份数据。具体设置请在下面的 RB::Data_Backup 进行设置。
#=============================================================================
module RB
end
module RB::Data_Backup
# 备份文件夹,可使用绝对路径或相对路径,不可设置为"Data"
Backup_Dir = "Backup"
# 启用备份,设置为 true 时自动备份
Activated = false
# 是否仅备份数据(而不备份地图)
Data_Only = false
# 最大备份数量
Max_Backup = 3
end
class Window_Backup < Window_Base
def initialize
super(0, 0, 240, 96)
self.contents = Bitmap.new(width - 32, height - 32)
self.x = 320 - width / 2
self.y = 240 - height / 2
@max = 1
@current = 0
refresh
end
def refresh
self.contents.clear
self.contents.draw_text(4, 0, 192, 32, "正在备份数据..")
self.contents.draw_text(4, 32, 64, 32, "进度")
end
def draw_bar
self.contents.fill_rect(64, 32 + 4, 144, 24, Color.new(255, 255, 255, 255))
self.contents.fill_rect(64 + 1, 32 + 5, 142, 22, Color.new(0, 0, 0, 0))
w = @max == 0 ? 140 : Integer(140.0 * @current / @max)
self.contents.fill_rect(64 + 2, 32 + 6, w, 20, Color.new(255, 255, 255, 255))
end
def set(num, max)
@max = max
@current = num
draw_bar
end
end
class Scene_Title
def backup_data
unless $DEBUG && RB::Data_Backup::Activated
return
end
dir_name = RB::Data_Backup::Backup_Dir
data_dir = "Data"
if dir_name == data_dir
print "目标文件夹和原文件夹相同。无法备份。"
@backup_window.visible = false
return
end
unless File.exists?(dir_name)
Dir.mkdir(dir_name)
end
dirnames = []
Dir.foreach(dir_name) do |s|
dirnames << s if File.directory?(dir_name + '/' + s) && s != "." && s != ".."
end
(0..(dirnames.size - RB::Data_Backup::Max_Backup)).each do |i|
Dir.foreach(dir_name + '/' + dirnames[i]) do |f|
next if f == "." || f == ".."
File.delete(dir_name + '/' + dirnames[i] + '/' + f)
end
Dir.rmdir(dir_name + '/' + dirnames[i])
end
time_string = Time.now.strftime("%Y_%m_%d_%H_%M_%S")
dir_name += "/Backup_" + time_string
Dir.mkdir(dir_name)
filenames = []
Dir.foreach(data_dir) do |s|
filenames << s if s != "." && s != ".."
end
if RB::Data_Backup::Data_Only
filenames.reject!{|s| /Map\d+\.rxdata/ === s}
end
filenames.each_with_index do |filename, index|
real_name = dir_name + '/' + filename
file = File.open(real_name, "wb")
Marshal.dump(load_data(data_dir + '/' + filename), file)
file.close
@backup_window.set(index + 1, filenames.size)
Graphics.update
end
16.times do
@backup_window.opacity -= 16
@backup_window.contents_opacity -= 16
Graphics.update
end
@backup_window.visible = false
end
unless method_defined? :rb_main_20150409
alias rb_main_20150409 main
def main
$game_system = Game_System.new
$data_system = load_data("Data/System.rxdata")
@backup_window = Window_Backup.new
@backup_window.visible = RB::Data_Backup::Activated && $DEBUG
rb_main_20150409
@backup_window.dispose
end
end
unless method_defined? :rb_update_20150409
alias rb_update_20150409 update
def update
if @backup_window.visible
backup_data
return
end
rb_update_20150409
end
end
end
|
评分
-
查看全部评分
|