-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSave data protected by password
More file actions
245 lines (224 loc) · 7.75 KB
/
Save data protected by password
File metadata and controls
245 lines (224 loc) · 7.75 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
extends Node
const SAVE_DIR = "user://saves/"
var save_path = SAVE_DIR + "save.dat"
onready var player = get_parent()
onready var player_mesh = get_parent().get_node("Mesh")
onready var stats = get_parent().get_node("Stats")
onready var camera = get_parent().get_node("Camroot/h/v/Camera")
onready var camera_h = get_parent().get_node("Camroot/h")
onready var camera_v = get_parent().get_node("Camroot/h/v")
onready var hair = get_parent().get_node("HairEditor")
onready var skin = get_parent().get_node("SkinEditor")
func _ready():
loadPlayerData()
func savePlayerData():
var data = {
"position": player.translation,
"rotation": player_mesh.rotation_degrees,
#camera stuff
"H_rotation": camera_h.rotation_degrees,
"V_rotation": camera_v.rotation_degrees,
"camera_position": camera.translation,
"camera_rotation": camera.rotation_degrees, # Save the camera's rotation
#Attributes
#leveling
"attribute": stats.attribute,
"spent_attribute_points_int": stats.spent_attribute_points_int,
"spent_attribute_points_wis": stats.spent_attribute_points_wis,
"spent_attribute_points_cha": stats.spent_attribute_points_cha,
"spent_attribute_points_vit": stats.spent_attribute_points_vit,
#Brain attributes
"creativity": stats.creativity,
"wisdom" : stats.wisdom,
"memory": stats.memory,
"intelligence": stats.intelligence,
"willpower": stats.willpower,
#Brute attributes
"power": stats.power,
"strength": stats.strength,
"impact": stats.impact,
"resistance": stats.resistance,
"tenacity": stats.tenacity,
#Precision attributes
"accuracy": stats.accuracy,
"dexterity": stats.dexterity,
"coordination": stats.coordination,
"balance": stats.balance,
"focus": stats.focus,
#Nimble attributes
"acrobatics": stats.acrobatics,
"agility": stats.agility,
"athletics": stats.athletics,
"flexibility": stats.flexibility,
"placeholder_": stats.placeholder_,
#Toughness attributes
"endurance": stats.endurance,
"stamina": stats.stamina,
"vitality": stats.vitality,
"vigor": stats.vigor,
"recovery": stats.recovery,
#Social attributes
"charisma": stats.charisma,
"loyalty": stats.loyalty,
"diplomacy": stats.diplomacy,
"leadership": stats.leadership,
"empathy": stats.empathy,
#crude stats
"health": stats.health,
"energy": stats.energy,
"resolve": stats.resolve,
"max_health": stats.max_health,
"max_energy": stats.max_energy,
"max_resolve": stats.max_resolve,
#hair
"hair0": hair.has_hair0,
"hair1": hair.has_hair1,
"hair2": hair.has_hair2,
"hair3": hair.has_hair3,
"hair_color": hair.hair_color,
#skin
"skin0": skin.skin0,
"skin1": skin.skin1,
"skin2": skin.skin2,
"skin3": skin.skin3,
}
var dir = Directory.new()
if !dir.dir_exists(SAVE_DIR):
dir.make_dir_recursive(SAVE_DIR)
var file = File.new()
var error = file.open_encrypted_with_pass(save_path, File.WRITE, "P@paB3ar6969")
if error == OK:
file.store_var(data)
file.close()
func loadPlayerData():
var file = File.new()
if file.file_exists(save_path):
var error = file.open_encrypted_with_pass(save_path, File.READ, "P@paB3ar6969")
if error == OK:
var player_data = file.get_var()
file.close()
if "position" in player_data:
player.translation = player_data["position"]
if "rotation" in player_data:
player.rotation_degrees = player_data["rotation"]
#attributes
if "attribute" in player_data:
stats.attribute = player_data["attribute"]
if "spent_attribute_points_int" in player_data:
stats.spent_attribute_points_int = player_data["spent_attribute_points_int"]
if "spent_attribute_points_cha" in player_data:
stats.spent_attribute_points_cha = player_data["spent_attribute_points_cha"]
if "spent_attribute_points_wis" in player_data:
stats.spent_attribute_points_wis = player_data["spent_attribute_points_wis"]
if "spent_attribute_points_vit" in player_data:
stats.spent_attribute_points_vit = player_data["spent_attribute_points_vit"]
#Brute attributes
if "power" in player_data:
stats.power = player_data["power"]
if "strength" in player_data:
stats.strength = player_data["strength"]
if "impact" in player_data:
stats.impact = player_data["impact"]
if "resistance" in player_data:
stats.resistance = player_data["resistance"]
if "tenacity" in player_data:
stats.tenacity = player_data["tenacity"]
#Brain attributes
if "creativity" in player_data:
stats.creativity = player_data["creativity"]
if "wisdom" in player_data:
stats.wisdom = player_data["wisdom"]
if "memory" in player_data:
stats.memory = player_data["memory"]
if "intelligence" in player_data:
stats.intelligence = player_data["intelligence"]
if "willpower" in player_data:
stats.willpower = player_data["willpower"]
#Precision attributes
if "accuracy" in player_data:
stats.accuracy = player_data["accuracy"]
if "dexterity" in player_data:
stats.dexterity = player_data["dexterity"]
if "cooridnation" in player_data:
stats.coordination = player_data["cooridnation"]
if "balance" in player_data:
stats.balance = player_data["balance"]
if "focus" in player_data:
stats.focus = player_data["focus"]
#Nimble attributes
if "acrobatics" in player_data:
stats.acrobatics = player_data["accuracy"]
if "agility" in player_data:
stats.agility = player_data["agility"]
if "flexibility" in player_data:
stats.flexibility = player_data["flexibility"]
if "athletics" in player_data:
stats.athletics = player_data["athletics"]
#Toughness attributes
if "endurance" in player_data:
stats.dexterity = player_data["endurance"]
if "stamina" in player_data:
stats.stamina = player_data["stamina"]
if "vitality" in player_data:
stats.vitality = player_data["vitality"]
if "vigor" in player_data:
stats.vigor = player_data["vigor"]
if "recovery" in player_data:
stats.recovery = player_data["recovery"]
#Social attributes
if "charisma" in player_data:
stats.charisma = player_data["charisma"]
if "loyalty" in player_data:
stats.loyalty = player_data["loyalty"]
if "diplomacy" in player_data:
stats.diplomacy = player_data["diplomacy"]
if "leadership" in player_data:
stats.leadership = player_data["leadership"]
if "empathy" in player_data:
stats.empathy = player_data["empathy"]
#crude stats
if "health" in player_data:
stats.health = player_data["health"]
if "max_health" in player_data:
stats.max_health = player_data["max_health"]
if "energy" in player_data:
stats.energy = player_data["energy"]
if "max_energy" in player_data:
stats.max_energy = player_data["max_energy"]
if "resolve" in player_data:
stats.resolve = player_data["resolve"]
if "max_resolve" in player_data:
stats.max_resolve = player_data["max_resolve"]
#hair
if "hair0" in player_data:
hair.has_hair0 = player_data["hair0"]
if "hair1" in player_data:
hair.has_hair1 = player_data["hair1"]
if "hair2" in player_data:
hair.has_hair2 = player_data["hair2"]
if "hair3" in player_data:
hair.has_hair3 = player_data["hair3"]
if "hair_color" in player_data:
hair.hair_color = player_data["hair_color"]
#skin
if "skin0" in player_data:
skin.skin0 = player_data["skin0"]
if "skin1" in player_data:
skin.skin1 = player_data["skin1"]
if "skin2" in player_data:
skin.skin2 = player_data["skin2"]
if "skin3" in player_data:
skin.skin3 = player_data["skin3"]
func resetSavedData():
var dir = Directory.new()
if dir.file_exists(save_path):
dir.remove(save_path)
print("Saved data reset")
func _input(event):
if event is InputEventKey:
if event.scancode == KEY_P: # Replace with the desired key code
resetSavedData()
func console_write(value):
print(str(value))
func _on_SaveDataTimer_timeout():
savePlayerData()