1
0
mirror of https://gitee.com/freeyz/godot-mota.git synced 2024-12-22 20:49:22 +08:00

修复持久化存档复制文件bug

This commit is contained in:
freewu32 2020-08-22 15:56:52 +08:00
parent ce22c8a9d7
commit fedbc4621a

View File

@ -105,8 +105,10 @@ func save_persistent(index:int)->void:
var dest_dir = "user://%s/" % index var dest_dir = "user://%s/" % index
dir.make_dir(dest_dir) dir.make_dir(dest_dir)
file.open(dest_dir + "level.data",File.WRITE) file.open(dest_dir + "level.data",File.WRITE)
file.store_32(self.level) file.store_string(to_json({
file.store_var(self.global,true) "level":self.level,
"global":self.global
}))
file.close() file.close()
#迁移数据到持久化目录 #迁移数据到持久化目录
if dir.open(tmp_level_scene_path) == OK: if dir.open(tmp_level_scene_path) == OK:
@ -138,15 +140,17 @@ func load_persistent(index:int)->void:
if dir.current_is_dir(): if dir.current_is_dir():
print("Found directory: " + file_name) print("Found directory: " + file_name)
else: else:
var copy_result = dir.copy(dest_dir + file_name,tmp_level_scene_path + file_name) if file_name != "level.data":
if copy_result != OK: var copy_result = dir.copy(dest_dir + file_name,tmp_level_scene_path + file_name)
print("读取存档失败",copy_result) if copy_result != OK:
print("读取存档失败",copy_result)
file_name = dir.get_next() file_name = dir.get_next()
else: else:
print("An error occurred when trying to access the path.") print("An error occurred when trying to access the path.")
#读取楼层 #读取楼层
file.open(dest_dir + "level.data",File.READ) file.open(dest_dir + "level.data",File.READ)
var level = file.get_32() var data = JSON.parse(file.get_as_text()).result
self.global = file.get_var(true) var level = data.level
self.global = data.global
file.close() file.close()
load_data(level) load_data(level)