This repository has been archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_generator.py
88 lines (75 loc) · 2.3 KB
/
config_generator.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
#!/usr/bin/env python3
import json
import os
def clear(): os.system('cls' if os.name == 'nt' else 'clear')
config_map = {}
if os.path.exists("monopoly.json"):
config_map = json.load(open("monopoly.json"))
clear()
while True:
print("Help: comma (,) to delete existing value")
print("----------------------------------------")
tag = input("Tag: ").lower().strip()
if not tag:
break
if tag in config_map:
prev = config_map[tag] if type(config_map[tag]) == str else config_map[tag]["target"]
target = input(f"Target [,] ({prev}): ").lower().strip()
if target == ",":
config_map.pop(tag)
clear()
continue
if not target:
target = prev
else:
target = input("Target: ").lower().strip()
if not target:
break
prev_nbt = False
prev_exclude = []
if tag in config_map:
prev = config_map[tag]
if type(prev) == dict:
if "nbt" in prev:
prev_nbt = prev["nbt"]
if "exclude" in prev:
if type(prev["exclude"]) == str:
prev_exclude.append(prev["exclude"])
else:
prev_exclude.extend(prev["exclude"])
nbt_input = input(f"Allow nbt ? [y/n] ({prev_nbt}): ").lower().strip()
nbt = nbt_input == "y" if nbt_input else prev_nbt
exclude = []
j = 0
while True:
default = "" if j >= len(prev_exclude) else " [,] (" + prev_exclude[j] + ")"
ex = input(f"Exclude {j}{default}: ").lower().strip()
if ex == "," and default:
j = j + 1
continue
if not ex:
if not default:
break
ex = prev_exclude[j]
if ex not in exclude:
exclude.append(ex)
j = j + 1
if not nbt and not exclude:
config_map[tag] = target
else:
config = {"target": target}
if nbt:
config["nbt"] = True
if exclude:
if len(exclude) <= 1:
config["exclude"] = exclude[0]
else:
config["exclude"] = exclude
config_map[tag] = config
clear()
jsonConfig = json.dumps(config_map, indent=2)
clear()
file = open("monopoly.json", "w")
file.write(jsonConfig)
file.close()
print("saved")