-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileManager.gd
139 lines (113 loc) · 3.85 KB
/
FileManager.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
extends Node
class_name FileManager
static func getDialogueData(temp : PoolStringArray,keys) -> DialogueData:
var dialog = DialogueData.new()
dialog.text = temp[keys.find("Text")]
dialog.mood = temp[keys.find("AddRage")]
dialog.option1.text = temp[keys.find("Option1")]
dialog.option1.jump = temp[keys.find("Option1Jump")]
dialog.option1.mood = temp[keys.find("Option1Mood")]
dialog.option1.hint = temp[keys.find("Option1ShowText")]
dialog.option1.money = temp[keys.find("Option1Money")]
if not dialog.option1.hasContent():
dialog.option1 = null
dialog.option2.text = temp[keys.find("Option2")]
dialog.option2.jump = temp[keys.find("Option2Jump")]
dialog.option2.mood = temp[keys.find("Option2Mood")]
dialog.option2.hint = temp[keys.find("Option2ShowText")]
dialog.option2.money = temp[keys.find("Option2Money")]
if not dialog.option2.hasContent():
dialog.option2 = null
dialog.option3.text = temp[keys.find("Option3")]
dialog.option3.jump = temp[keys.find("Option3Jump")]
dialog.option3.mood = temp[keys.find("Option3Mood")]
dialog.option3.hint = temp[keys.find("Option3ShowText")]
dialog.option3.money = temp[keys.find("Option3Money")]
if not dialog.option3.hasContent():
dialog.option3 = null
dialog.option4.text = temp[keys.find("Option4")]
dialog.option4.jump = temp[keys.find("Option4Jump")]
dialog.option4.mood = temp[keys.find("Option4Mood")]
dialog.option4.hint = temp[keys.find("Option4ShowText")]
dialog.option4.money = temp[keys.find("Option4Money")]
if not dialog.option4.hasContent():
dialog.option4 = null
dialog.optionNo.jump = temp[keys.find("NoOptionJump")]
dialog.optionNo.mood = temp[keys.find("NoOptionMood")]
dialog.optionNo.money = temp[keys.find("NoOptionMoney")]
if dialog.optionNo.jump.empty() :
if dialog.option1 != null:
dialog.optionNo = dialog.option1
elif dialog.option2 != null:
dialog.optionNo = dialog.option2
elif dialog.option3 != null:
dialog.optionNo = dialog.option3
elif dialog.option4 != null:
dialog.optionNo = dialog.option4
else:
dialog.optionNo = null
return dialog
static func parseCsvFile(path: String) -> Dictionary:
var file = File.new()
file.open(path, File.READ)
var temp = file.get_csv_line(",")
if temp.size() <= 1:
return {}
var keys = []
for i in temp:
keys.push_back(i)
var data_list = {}
temp = file.get_csv_line(",")
while temp.size() > 1:
if temp.size() != keys.size():
break
var roleIdx = keys.find("ID")
var roleId = temp[roleIdx]
if data_list.has(roleId):
var role = data_list.get(roleId)
role.dialogMap[temp[keys.find("TextId")]] = getDialogueData(temp,keys)
else:
var role = RoleData.new()
role.id = roleId
role.roleName = temp[keys.find("Role")]
role.isNeedReturnGoods = temp[keys.find("IsReturnGoods")].to_lower() == "true"
role.dialogueIndex = temp[keys.find("TextId")]
role.level = temp[keys.find("Level")]
var dialogMap = {}
dialogMap[temp[keys.find("TextId")]] = getDialogueData(temp,keys)
role.dialogMap = dialogMap
data_list[roleId] = role
# 读取下一行数据
temp = file.get_csv_line(",")
file.close()
return data_list
## 文件是否存在
## @path 文件路径
static func exists_file(path: String) -> bool:
var file = File.new()
var exists = file.file_exists(path)
file.close()
return exists
## 保存数据
## @path 文件路径
## @data 数据
static func save_data(path: String, data) -> void:
var file = File.new()
file.open(path, File.WRITE)
file.store_var(data)
file.close()
## 加载数据
## @path 文件路径
## @return 返回数据
static func load_data(path: String):
var file = File.new()
file.open(path, File.READ)
var object = file.get_var()
file.close()
if object == null:
return null
else:
return instance_from_id(object.get_object_id())
static func remove_file(path: String) -> bool:
var dir = Directory.new()
return dir.remove(path)