diff options
| author | mat <github@matdoes.dev> | 2022-06-11 15:29:42 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-06-11 15:29:42 -0500 |
| commit | e79e58da3649803c58803329fc88ad5c7f6c3e9f (patch) | |
| tree | 43df090c05a94dac82317d2bfbdbf2af8f2d54f8 /codegen/lib | |
| parent | b852bdc48150c0c01f341f73dfb84084b50eda9c (diff) | |
| download | azalea-drasl-e79e58da3649803c58803329fc88ad5c7f6c3e9f.tar.xz | |
Include property names in blocks
Diffstat (limited to 'codegen/lib')
| -rw-r--r-- | codegen/lib/code/blocks.py | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/codegen/lib/code/blocks.py b/codegen/lib/code/blocks.py index d2fe6da2..09f4a85f 100644 --- a/codegen/lib/code/blocks.py +++ b/codegen/lib/code/blocks.py @@ -1,7 +1,6 @@ -from lib.utils import upper_first_letter -from lib.utils import get_dir_location -from lib.utils import to_camel_case +from lib.utils import to_snake_case, upper_first_letter, get_dir_location, to_camel_case from ..mappings import Mappings +import re BLOCKS_RS_DIR = get_dir_location('../azalea-block/src/blocks.rs') @@ -32,31 +31,48 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, mappings: Mappings # Find properties properties = {} + + # This dict looks like { 'FloweringAzaleaLeavesDistance': 'distance' } + property_struct_names_to_names = {} for block_id, block_data_burger in blocks_burger.items(): block_data_report = blocks_report[f'minecraft:{block_id}'] block_properties = {} - for property_name in list(block_data_report.get('properties', {}).keys()): + for property_struct_name in list(block_data_report.get('properties', {}).keys()): property_burger = None for property in block_data_burger['states']: - if property['name'] == property_name: + if property['name'] == property_struct_name: property_burger = property break if property_burger is None: print('Error: The reports have states for a block, but Burger doesn\'t!', block_data_burger) continue # assert property_burger is not None - property_variants = block_data_report['properties'][property_name] + property_variants = block_data_report['properties'][property_struct_name] property_struct_name = get_property_struct_name(property_burger, block_data_burger) block_properties[property_struct_name] = property_variants + + property_name = property_burger['name'] + # if the name ends with _<number>, remove that part + ending = property_name.split('_')[-1] + if ending.isdigit(): + property_name = property_name[:-(len(ending) + 1)] + property_struct_names_to_names[property_struct_name] = property_name + properties.update(block_properties) # Property codegen new_make_block_states_macro_code.append(' Properties => {') - for property_name, property_variants in properties.items(): + for property_struct_name, property_variants in properties.items(): + # face => Face { + # Floor, + # Wall, + # Ceiling, + # }, + property_name = property_struct_names_to_names[property_struct_name] new_make_block_states_macro_code.append( - f' {to_camel_case(property_name)} {{') + f' {property_name} => {property_struct_name} {{') for variant in property_variants: new_make_block_states_macro_code.append( |
