1
0
mirror of https://gitee.com/freeyz/godot-mota.git synced 2024-12-22 14:59:21 +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
dir.make_dir(dest_dir)
file.open(dest_dir + "level.data",File.WRITE)
file.store_32(self.level)
file.store_var(self.global,true)
file.store_string(to_json({
"level":self.level,
"global":self.global
}))
file.close()
#迁移数据到持久化目录
if dir.open(tmp_level_scene_path) == OK:
@ -138,15 +140,17 @@ func load_persistent(index:int)->void:
if dir.current_is_dir():
print("Found directory: " + file_name)
else:
var copy_result = dir.copy(dest_dir + file_name,tmp_level_scene_path + file_name)
if copy_result != OK:
print("读取存档失败",copy_result)
if file_name != "level.data":
var copy_result = dir.copy(dest_dir + file_name,tmp_level_scene_path + file_name)
if copy_result != OK:
print("读取存档失败",copy_result)
file_name = dir.get_next()
else:
print("An error occurred when trying to access the path.")
#读取楼层
file.open(dest_dir + "level.data",File.READ)
var level = file.get_32()
self.global = file.get_var(true)
var data = JSON.parse(file.get_as_text()).result
var level = data.level
self.global = data.global
file.close()
load_data(level)