-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen.py
178 lines (142 loc) · 5.76 KB
/
gen.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"""
Generate texture and model reports
"""
import os, json
LOCAL = os.path.dirname(os.path.realpath(__file__))
report = {
"minecraft:model": {},
"minecraft:terrain_texture": {},
"minecraft:item_texture": {},
}
def uniqueItem(list, value):
"""Returns true if that item is already added in the list"""
for i in list:
if i == value:
return True
return False
def convertList(list):
return (
str(list)
.replace("[", "")
.replace("]", "")
.replace("'", "`")
.replace(",", "<br>")
)
def addReport(type, path, key, value):
cat = report[type]
if path in cat:
if key in cat[path]:
if uniqueItem(cat[path][key], value) == False:
cat[path][key].append(value)
else:
cat[path][key] = []
addReport(type, path, key, value)
else:
cat[path] = {}
addReport(type, path, key, value)
# terrain_texture
opn = open(os.path.join(LOCAL, "textures", "terrain_texture.json"), "r")
terrain_texture = json.load(opn)
opn.close()
texture_data = terrain_texture["texture_data"]
for texture in texture_data:
path = texture_data[texture]["textures"]
if type(path) == str:
addReport("minecraft:terrain_texture", path, "atlas", texture)
elif type(path) == dict:
addReport("minecraft:terrain_texture", path["path"], "atlas", texture)
# item_texture
opn = open(os.path.join(LOCAL, "textures", "item_texture.json"), "r")
item_texture = json.load(opn)
opn.close()
texture_data = item_texture["texture_data"]
for texture in texture_data:
path = texture_data[texture]["textures"]
if type(path) == str:
addReport("minecraft:item_texture", path, "atlas", texture)
elif type(path) == dict:
addReport("minecraft:item_texture", path["path"], "atlas", texture)
# model
model_path = os.path.join(LOCAL, "models", "blocks")
for filename in os.listdir(model_path):
model_file = os.path.join(model_path, filename)
if filename.endswith(".json") and os.path.isfile(model_file):
opn = open(model_file, "r")
model = json.load(opn)
opn.close()
path = "models/blocks/" + filename.replace(".json", "")
for submodel in model["minecraft:geometry"]:
material_instances = []
addReport(
"minecraft:model", submodel["description"]["identifier"], "path", path
)
# for each material_instance
for bone in submodel["bones"]:
if "name" in bone:
addReport(
"minecraft:model",
submodel["description"]["identifier"],
"bones",
bone["name"],
)
if "cubes" in bone:
for cube in bone["cubes"]:
if isinstance(cube["uv"], dict):
for k, uv in cube["uv"].items():
if "material_instance" in uv:
mi = uv["material_instance"]
addReport(
"minecraft:model",
submodel["description"]["identifier"],
"material_instance",
mi,
)
else:
addReport(
"minecraft:model",
submodel["description"]["identifier"],
"material_instance",
k,
)
# create report
wrt = open(os.path.join(LOCAL, "report.json"), "w")
wrt.write(json.dumps(report, indent=4))
wrt.close()
wrt = open(os.path.join(LOCAL, "data_table.md"), "w")
# Block Textures
block_textures_table = "| Name(s) | Path |\n|--|--|\n"
for path in report["minecraft:terrain_texture"]:
names = convertList(report["minecraft:terrain_texture"][path]["atlas"])
block_textures_table = block_textures_table + "| %s | `%s` |" % (names, path) + "\n"
with open(os.path.join(LOCAL, "docs", "__Block Textures.md"), "r") as temp:
template = temp.read()
with open(os.path.join(LOCAL, "docs", "Block Textures.md"), "w") as w:
w.write(template.replace("{Block Textures}", block_textures_table))
# Item Textures
item_textures_table = "| Name(s) | Path |\n|--|--|\n"
for path in report["minecraft:item_texture"]:
names = convertList(report["minecraft:item_texture"][path]["atlas"])
item_textures_table = item_textures_table + "| %s | `%s` |" % (names, path) + "\n"
with open(os.path.join(LOCAL, "docs", "__Item Textures.md"), "r") as temp:
template = temp.read()
with open(os.path.join(LOCAL, "docs", "Item Textures.md"), "w") as w:
w.write(template.replace("{Item Textures}", item_textures_table))
# Models
models_table = "| Name | Material Instances | Bones | Path |\n|--|--|--|--|\n"
for name in report["minecraft:model"]:
path = convertList(report["minecraft:model"][name]["path"])
if "bones" in report["minecraft:model"][name]:
bones = convertList(report["minecraft:model"][name]["bones"])
else:
bones = ""
if "material_instance" in report["minecraft:model"][name]:
mi = convertList(report["minecraft:model"][name]["material_instance"])
else:
mi = ""
models_table = (
models_table + "| `%s` | %s | %s | %s |" % (name, mi, bones, path) + "\n"
)
with open(os.path.join(LOCAL, "docs", "__Models.md"), "r") as temp:
template = temp.read()
with open(os.path.join(LOCAL, "docs", "Models.md"), "w") as w:
w.write(template.replace("{Models}", models_table))