-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_parser.py
108 lines (79 loc) · 2.19 KB
/
data_parser.py
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
import json
def load_json(data_file= 'gamedata.json'):
with open(data_file) as file:
data = json.load(file)
return data
def get_sys_config(data_file= "gamedata.json"):
with open(data_file) as file:
data = json.load(file)
return data["System"]
def get_config(data_file= "gamedata.json"):
with open(data_file) as file:
data = json.load(file)
config= data["Settings"]
return config
def ch_config(key, new_val):
try:
data= load_json()
data["Settings"][key]["Value"]= new_val
save_json(data)
except:
print("Failed!")
return -1
def reset_config(data_file= "gamedata.json"):
with open(data_file) as file:
data = json.load(file)
data["Settings"]= data["Factory Data"]["Settings"]
save_json(data)
def get_user_data(user= "Guest", data_file= "gamedata.json"):
with open(data_file) as file:
data = json.load(file)
user_data= data["Users"][user]
return user_data
def update_user_data(key, new_val, user= "Guest"):
try:
data= load_json()
data["Users"][user][key[0]][key[1]]= new_val
save_json(data)
except:
pass
def get_users(data_file= "gamedata.json"):
with open(data_file) as file:
data = json.load(file)
users= data["Users"]
return list(users.keys())
def new_user(name, data_file= "gamedata.json"):
data= load_json()
if name not in get_users():
data["Users"][name]= data["Factory Data"]["New User"]
save_json(data)
else:
raise Exception("Name taken")
def del_user(name, data_file= "gamedata.json"):
data= load_json()
del data["Users"][name]
save_json(data)
def get_achievements(achievement_file= "achievements.json"):
with open(achievement_file) as file:
achievements= json.load(file)
return achievements
def save_json(data, data_file= "gamedata.json"):
try:
with open(data_file, 'w+') as file:
json.dump(data, file, indent=4)
print("Save successful!")
except:
print("Failed!")
return -1
def get_curr_user(data_file="gamedata.json"):
with open(data_file) as file:
data = json.load(file)
curr_user = data["Current User"]
return curr_user
def ch_user(user, data_file="gamedata.json"):
with open(data_file) as file:
data = json.load(file)
data["Current User"] = user
save_json(data)
if __name__ == "__main__":
new_user("ABC")