mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01:00
Preparation for actually adding !Copy fields to BlockType. Only the Copy parts are added to the processed data, avoiding .clone() for the most part.
48 lines
1.1 KiB
Python
Executable file
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)
|