1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 23:44:38 +00:00
azalea/codegen/lib/code/registry.py
mat 6eee543a33
Pathfinder (#25)
Pathfinding is very much not done, but it works enough and I want to get this merged.
TODO: fast replanning, goals that aren't a single node, falling moves (it should be able to play the dropper), parkour moves
2022-11-12 23:54:05 -06:00

32 lines
1.1 KiB
Python
Executable file

from lib.utils import to_snake_case, upper_first_letter, get_dir_location, to_camel_case
from ..mappings import Mappings
from typing import Optional
import re
REGISTRIES_DIR = get_dir_location('../azalea-registry/src/lib.rs')
def generate_registries(registries: dict):
code = []
code.append('use azalea_registry_macros::registry;')
code.append('')
for registry_name, registry in registries.items():
# registry!(Block, {
# Air => "minecraft:air",
# Stone => "minecraft:stone"
# });
registry_struct_name = to_camel_case(registry_name.split(':')[1])
code.append(f'registry!({registry_struct_name}, {{')
registry_entries = sorted(
registry['entries'].items(), key=lambda x: x[1]['protocol_id'])
for variant_name, _variant in registry_entries:
variant_struct_name = to_camel_case(
variant_name.split(':')[1])
code.append(f'\t{variant_struct_name} => "{variant_name}",')
code.append('});')
code.append('')
with open(REGISTRIES_DIR, 'w') as f:
f.write('\n'.join(code))