2018-07-22 16:54:00 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
if len(sys.argv) != 3:
|
2023-08-18 18:34:12 +02:00
|
|
|
sys.exit('Usage: generate.py <colors.json> <block_types.rs>')
|
2018-07-22 16:54:00 +02:00
|
|
|
|
|
|
|
with open(sys.argv[1]) as f:
|
|
|
|
colors = json.load(f)
|
|
|
|
|
|
|
|
output = {}
|
|
|
|
|
|
|
|
with open(sys.argv[2], 'w') as f:
|
2023-02-07 22:09:14 +01:00
|
|
|
print('use enumflags2::make_bitflags;', file=f);
|
|
|
|
print('', file=f)
|
|
|
|
print('use super::*;', file=f)
|
|
|
|
print('', file=f)
|
2023-12-29 20:54:26 +01:00
|
|
|
print('pub const BLOCK_TYPES: &[(&str, ConstBlockType)] = &[', file=f)
|
2023-02-07 22:09:14 +01:00
|
|
|
|
2018-07-22 16:54:00 +02:00
|
|
|
for name, info in colors.items():
|
2020-06-18 23:38:21 +02:00
|
|
|
flags = []
|
|
|
|
if info['opaque']:
|
2023-02-07 22:09:14 +01:00
|
|
|
flags.append('Opaque')
|
2020-06-18 23:38:21 +02:00
|
|
|
if info['grass']:
|
2023-02-07 22:09:14 +01:00
|
|
|
flags.append('Grass')
|
2020-06-18 23:38:21 +02:00
|
|
|
if info['foliage']:
|
2023-02-07 22:09:14 +01:00
|
|
|
flags.append('Foliage')
|
2020-06-18 23:53:08 +02:00
|
|
|
if info['birch']:
|
2023-02-07 22:09:14 +01:00
|
|
|
flags.append('Birch')
|
2020-06-18 23:53:08 +02:00
|
|
|
if info['spruce']:
|
2023-02-07 22:09:14 +01:00
|
|
|
flags.append('Spruce')
|
2020-06-18 23:38:21 +02:00
|
|
|
if info['water']:
|
2023-02-07 22:09:14 +01:00
|
|
|
flags.append('Water')
|
2023-02-13 00:11:36 +01:00
|
|
|
flags = 'make_bitflags!(BlockFlag::{' + '|'.join(flags) + '})'
|
2020-06-18 23:38:21 +02:00
|
|
|
|
2023-12-29 20:54:26 +01:00
|
|
|
sign_material = 'None'
|
|
|
|
if info['sign_material']:
|
|
|
|
sign_material = 'Some("%s")' % info['sign_material']
|
|
|
|
|
|
|
|
print('\t("%s", ConstBlockType { ' % name, file=f)
|
2023-12-30 01:42:17 +01:00
|
|
|
print('\t\tblock_color: BlockColor { flags: %s, color: Color([%u, %u, %u]) },' % (
|
2020-06-18 23:38:21 +02:00
|
|
|
flags,
|
2018-07-22 16:54:00 +02:00
|
|
|
info['color']['r'],
|
|
|
|
info['color']['g'],
|
|
|
|
info['color']['b'],
|
2018-11-07 22:50:42 +01:00
|
|
|
), file=f)
|
2023-12-29 20:54:26 +01:00
|
|
|
print('\t\tsign_material: %s,' % sign_material, file=f)
|
2023-12-30 01:42:17 +01:00
|
|
|
print('}),', file=f)
|
|
|
|
|
2023-02-07 22:09:14 +01:00
|
|
|
print('];', file=f)
|