forked from TeamMoegMC/TheWinterRescue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject_localization_symbol.py
130 lines (118 loc) · 4.49 KB
/
inject_localization_symbol.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""
Replace the keys in fhresearches to '@'
Should run after extract_localization_symbol.sc
"""
import json
import os
def load_json(file_path):
with open(file_path, 'r') as f:
data = json.load(f)
return data
def save_json(file_path, data):
with open(file_path, 'w') as f:
json.dump(data, f, indent=2)
def process_research(file):
# skip non-json files
if not file.endswith('.json'):
return
# process the file
data = load_json(file)
# print(data)
# print('Processing:', file)
# get the value of the key 'name'
if ('name' in data):
name = data['name']
else:
name = '@'
# if name does not starts with '@', change it to '@'
if not name.startswith('@'):
name = '@'
# update the value of the key 'name'
data['name'] = name
# get the value of the key 'desc'
if ('desc' in data):
desc = data['desc']
else:
desc = ['@']
# desc is an array, loop through it
for i in range(len(desc)):
# if the element does not starts with '@', change it to '@'
if not desc[i].startswith('@'):
desc[i] = '@'
# update the value of the key 'desc'
data['desc'] = desc
# get the value of the key 'descAlt'
if ('descAlt' in data):
desc_alt = data['descAlt']
else:
desc_alt = ['@']
# desc is an array, loop through it
for i in range(len(desc_alt)):
# if the element does not starts with '@', change it to '@'
if not desc_alt[i].startswith('@'):
desc_alt[i] = '@'
# update the value of the key 'descAlt'
data['descAlt'] = desc_alt
data['showAltDesc'] = True
# get the value of the key 'effects'
if ('effects' in data):
effects = data['effects']
# effects is an array, loop through it
for i in range(len(effects)):
# if exists key 'tooltip' in effects
if 'tooltip' in effects[i]:
# get the value of the key 'tooltip'
tooltip = effects[i]['tooltip']
for j in range(len(tooltip)):
# if the element does not starts with '@', change it to '@'
if not tooltip[j].startswith('@'):
effects[i]['tooltip'][j] = '@'
print('Replaced tooltip to @ in effects: ', file)
# if exists key 'name' in effects
if 'name' in effects[i]:
# get the value of the key 'name'
name = effects[i]['name']
# if the element does not starts with '@', change it to '@'
if not name.startswith('@'):
effects[i]['name'] = '@'
print('Replaced name to @ in effects: ', file)
# update the value of the key 'effects'
data['effects'] = effects
# get the value of the key 'clues'
if ('clues' in data):
clues = data['clues']
# clues is an array, loop through it
for i in range(len(clues)):
# if exists key 'name' in clues
if 'name' in clues[i]:
# get the value of the key 'name'
name = clues[i]['name']
# if the element does not starts with '@', change it to '@'
if not name.startswith('@'):
clues[i]['name'] = '@'
print('Replaced name to @ in clues: ', file)
# if exists key 'desc' in clues
if 'desc' in clues[i]:
# get the value of the key 'desc'
desc = clues[i]['desc']
# if the element does not starts with '@', change it to '@'
if not desc.startswith('@'):
clues[i]['desc'] = '@'
print('Replaced desc to @ in effects: ', file)
# if exists key 'hint' in clues
if 'hint' in clues[i]:
# get the value of the key 'hint'
hint = clues[i]['hint']
# if the element does not starts with '@', change it to '@'
if not hint.startswith('@'):
clues[i]['hint'] = '@'
print('Replaced hint to @ in effects: ', file)
# update the value of the key 'clues'
data['clues'] = clues
# save the file
save_json(file, data)
if __name__ == '__main__':
# loop through all files in the current directory
research_dir = os.getcwd()+'/config/fhresearches/'
for file in os.listdir(research_dir):
process_research(research_dir+file)