-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
94 lines (81 loc) · 2.95 KB
/
main.py
File metadata and controls
94 lines (81 loc) · 2.95 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
import os
import json
import sys
# Mapping of skills to corresponding item types
skill_to_item = {
"strength": "sword",
"defense": "armor",
"mining": "tool",
"farming": ["axe", "hoe"] # farming has multiple items
}
abbreviation = {
"strength": "str",
"defense": "def",
"mining": "min",
"farming": "far"
}
# Function to generate the config content
def generate_material_file(skill, material, level, item_type):
return {
"replace": True,
"skill": skill,
"level": level,
"item": f"minecraft:{item_type}",
"material": material
}
def generate_item_file(skill, item, level):
return {
"replace": True,
"skill": skill,
"level": level,
"item": item
}
def generate_custom_file(skill, item, level):
return {
"replace": True,
"skill": skill,
"level": level,
"item": "minecraft:custom_item",
"object": item
}
# Load the input JSON file
with open('./input/main.json', 'r') as f:
try:
input_data = json.load(f)
except json.JSONDecodeError as e:
print(f"Error loading JSON file: {e}")
sys.exit(1)
# Create the output folders
output_folder = os.path.join("output", "item")
os.makedirs(output_folder, exist_ok=True)
# Iterate through each skill and material, creating JSON files
for skill, materials in input_data.items():
for type, level in materials.items():
filename: str
config_data: dict
if ":" in type:
if "minecraft:" in type:
filename = f"{abbreviation[skill]}.item-{type.split(':')[1]}.json"
config_data = generate_item_file(skill, type, level)
else:
filename = f"{abbreviation[skill]}.custom-{type.split(":")[1]}.json"
config_data = generate_custom_file(skill, type, level)
# Write to the JSON file
with open(os.path.join(output_folder, filename), 'w') as f:
json.dump(config_data, f, indent=4)
elif isinstance(skill_to_item[skill], list):
for item_type in skill_to_item[skill]:
filename = f"{abbreviation[skill]}.{item_type}-{type}.json"
config_data = generate_material_file(skill, type, level, item_type)
# Write to the JSON file
with open(os.path.join(output_folder, filename), 'w') as f:
json.dump(config_data, f, indent=4)
else:
# Single item type
item_type = skill_to_item[skill]
filename = f"{abbreviation[skill]}.{item_type}-{type}.json"
config_data = generate_material_file(skill, type, level, item_type)
# Write to the JSON file
with open(os.path.join(output_folder, filename), 'w') as f:
json.dump(config_data, f, indent=4)
print(f"Config files generated in '{output_folder}' folder.")