MinedMap/resource/generate.py
Matthias Schiffer 8814dcff89
resource: split BlockType in Copy and !Copy parts
Preparation for actually adding !Copy fields to BlockType.

Only the Copy parts are added to the processed data, avoiding .clone()
for the most part.
2024-01-10 22:56:29 +01:00

48 lines
1.1 KiB
Python
Executable file

#!/usr/bin/env python3
import json
import os
import sys
if len(sys.argv) != 3:
sys.exit('Usage: generate.py <colors.json> <block_types.rs>')
with open(sys.argv[1]) as f:
colors = json.load(f)
output = {}
with open(sys.argv[2], 'w') as f:
print('use enumflags2::make_bitflags;', file=f);
print('', file=f)
print('use super::*;', file=f)
print('', file=f)
print('pub const BLOCK_TYPES: &[(&str, BlockType)] = &[', file=f)
for name, info in colors.items():
flags = []
if info['opaque']:
flags.append('Opaque')
if info['grass']:
flags.append('Grass')
if info['foliage']:
flags.append('Foliage')
if info['birch']:
flags.append('Birch')
if info['spruce']:
flags.append('Spruce')
if info['water']:
flags.append('Water')
flags = 'make_bitflags!(BlockFlag::{' + '|'.join(flags) + '})'
print('\t("%s", BlockType { ' % name, file=f)
print('\t\tblock_color: BlockColor { flags: %s, color: Color([%u, %u, %u]) },' % (
flags,
info['color']['r'],
info['color']['g'],
info['color']['b'],
), file=f)
print('}),', file=f)
print('];', file=f)