-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexplorer_map_destination.py
More file actions
103 lines (96 loc) · 5.36 KB
/
Copy pathexplorer_map_destination.py
File metadata and controls
103 lines (96 loc) · 5.36 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
import glob
import json
import os
def get_json_from_file(fh):
try:
# If possible, read the file as JSON
return json.loads(fh)
except:
# If not, read the file as a string, and try to parse it as JSON
contents = ""
for line in fh.splitlines():
cleanedLine = line.split("//", 1)[0]
if len(cleanedLine) > 0 and line.endswith("\n") and "\n" not in cleanedLine:
cleanedLine += "\n"
contents += cleanedLine
while "/*" in contents:
preComment, postComment = contents.split("/*", 1)
contents = preComment + postComment.split("*/", 1)[1]
return json.loads(contents)
def main():
# Define the root directory where you want to search
root_directory = "." # Assuming you're starting from the root directory
global_function_values = []
# Recursively search for JSON files within loot_tables folders
for folder, _, files in os.walk(root_directory):
if "loot_tables" in folder:
for file in files:
if file.endswith(".json"):
try:
file_path = os.path.join(folder, file)
with open(file_path, "r", encoding="utf-8") as fh:
json_data = get_json_from_file(fh.read())
# Extract the "condition" values
condition_values = []
for pool in json_data.get("pools", []):
for entries in pool.get("entries", []):
for function in entries.get("functions", []):
if "destination" in function:
condition_values.append(function.get("destination"))
global_function_values.append(function.get("destination"))
print(f"Functions in {file_path}: {condition_values}")
except Exception as e:
print(f"Error in file: {file_path}")
print(e)
raise
if "trading" in folder:
for file in files:
if file.endswith(".json"):
try:
file_path = os.path.join(folder, file)
with open(file_path, "r", encoding="utf-8") as fh:
json_data = get_json_from_file(fh.read())
# Extract the "condition" values
condition_values = []
for pool in json_data.get("tiers", []):
for trade in pool.get("trades", []):
for give in trade.get("gives", []):
for function in give.get("functions", []):
if "destination" in function:
condition_values.append(function.get("destination"))
global_function_values.append(function.get("destination"))
print(f"Functions in {file_path}: {condition_values}")
except Exception as e:
print(f"Error in file: {file_path}")
print(e)
raise
if "trading" in folder:
for file in files:
if file.endswith(".json"):
try:
file_path = os.path.join(folder, file)
with open(file_path, "r", encoding="utf-8") as fh:
json_data = get_json_from_file(fh.read())
# Extract the "condition" values
condition_values = []
for pool in json_data.get("tiers", []):
for group in pool.get("groups", []):
for trade in group.get("trades", []):
for give in trade.get("gives", []):
for function in give.get("functions", []):
if "destination" in function:
condition_values.append(function.get("destination"))
global_function_values.append(function.get("destination"))
if "choice" in give:
for choice in give.get("choice", []):
for function in choice.get("functions", []):
if "destination" in function:
condition_values.append(function.get("destination"))
global_function_values.append(function.get("destination"))
print(f"Functions in {file_path}: {condition_values}")
except Exception as e:
print(f"Error in file: {file_path}")
print(e)
raise
print(f"Complete sest of functions: {set(global_function_values)}")
main()