mirror of
https://gitee.com/freeyz/godot-mota.git
synced 2024-12-23 01:29:35 +08:00
修复持久化存档复制文件bug
This commit is contained in:
parent
ce22c8a9d7
commit
fedbc4621a
@ -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,6 +140,7 @@ 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:
|
||||||
|
if file_name != "level.data":
|
||||||
var copy_result = dir.copy(dest_dir + file_name,tmp_level_scene_path + file_name)
|
var copy_result = dir.copy(dest_dir + file_name,tmp_level_scene_path + file_name)
|
||||||
if copy_result != OK:
|
if copy_result != OK:
|
||||||
print("读取存档失败",copy_result)
|
print("读取存档失败",copy_result)
|
||||||
@ -146,7 +149,8 @@ func load_persistent(index:int)->void:
|
|||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user