diff options
| author | mat <github@matdoes.dev> | 2022-06-09 19:37:03 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-06-09 19:37:03 -0500 |
| commit | 4a3a2d2a3da1dab19f492a39f50ac0cd22ae6512 (patch) | |
| tree | 57cb43ff37d032c3966c2eef66f123b4548b6eca /codegen/lib/code/blocks.py | |
| parent | 7d4eceefde825e65e51b89394f46beb41847103c (diff) | |
| download | azalea-drasl-4a3a2d2a3da1dab19f492a39f50ac0cd22ae6512.tar.xz | |
work on genblocks
Diffstat (limited to 'codegen/lib/code/blocks.py')
| -rw-r--r-- | codegen/lib/code/blocks.py | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/codegen/lib/code/blocks.py b/codegen/lib/code/blocks.py index ca178ff3..bc5083c7 100644 --- a/codegen/lib/code/blocks.py +++ b/codegen/lib/code/blocks.py @@ -1,11 +1,29 @@ -from lib.utils import to_camel_case from lib.utils import get_dir_location +from lib.utils import to_camel_case +from ..mappings import Mappings import json BLOCKS_RS_DIR = get_dir_location('../azalea-block/src/blocks.rs') +# Terminology: +# - Property: A property of a block, like "direction" +# - Variant: A potential state of a property, like "up" +# - State: A possible state of a block, a combination of variants +# - Block: Has properties and states. + + +def get_property_variants(data) -> list[str]: + if 'values' in data: + return list(map(str.lower, data['values'])) + if data['type'] == 'bool': + return ['true', 'false'] + if data['type'] == 'int': + # range between data['min'] and data['max'] + return [str(i) for i in range(data['min'], data['max'] + 1)] + raise Exception('Unknown property type: ' + data['type']) + -def generate_blocks(blocks: dict): +def generate_blocks(blocks: dict, mappings: Mappings): with open(BLOCKS_RS_DIR, 'r') as f: existing_code = f.read().splitlines() @@ -15,7 +33,14 @@ def generate_blocks(blocks: dict): # Find properties properties = {} for block_data in blocks.values(): - block_properties = block_data.get('properties', {}) + block_properties = {} + for property in block_data.get('states', []): + property_name = mappings.get_field( + property.get('declared_in', block_data['class']), property['field_name']).lower() + property_variants = get_property_variants(property) + block_properties[property_name] = property_variants + # if property_name == 'eggs': + # print(property, property_name, property_variants) properties.update(block_properties) # Property codegen @@ -35,7 +60,6 @@ def generate_blocks(blocks: dict): # Block codegen new_make_block_states_macro_code.append(' Blocks => {') for block_id, block_data in blocks.items(): - block_id = block_id.split(':')[1] block_states = block_data['states'] default_property_variants = {} |
