-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_blocks_glsl.py
44 lines (37 loc) · 1.53 KB
/
generate_blocks_glsl.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
import os
# Open /shaders/block.properties
with open(
os.path.join(os.path.dirname(__file__), "shaders", "block.properties"), "r"
) as f:
lines = f.readlines()
# For each line in form "block.<id>=..." read the comment above it "# Block category name".
# If such line with a comment is found, remember the category name and the numeric id in a dictionary.
category_ids = {}
for i, line in enumerate(lines):
if line.startswith("block."):
block_id = line.split("=")[0].split(".")[1]
if lines[i - 1].startswith("#"):
block_category = lines[i - 1].split("# ")[1].strip()
category_ids[block_category] = block_id
# Convert all block categories to UPPERCASE_SNAKE_CASE
category_ids = {k.upper().replace(" ", "_"): v for k, v in category_ids.items()}
# Generate /shaders/src/modules/blocks.glsl
generated = []
generated.append("#ifndef BLOCKS_GLSL")
generated.append("#define BLOCKS_GLSL")
generated.append("")
generated.append('// This file is generated from block.properties using generate_blocks_glsl.py;')
generated.append("// Please do not edit.")
generated.append("")
generated.append("#define BLOCKS_UNKNOWN 0")
for block_category, block_id in category_ids.items():
generated.append(f"#define BLOCKS_{block_category} {block_id}")
generated.append("")
generated.append("#endif // BLOCKS_GLSL")
generated.append("")
# Write to /shaders/src/modules/blocks.glsl
with open(
os.path.join(os.path.dirname(__file__), "shaders", "src", "modules", "blocks.glsl"),
"w",
) as f:
f.write("\n".join(generated))