mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
* start adding azalea-inventory * design more of how inventories are defined * start working on az-inv-macros * inventory macro works * start adding inventory codegen * update some deps * add inventory codegen * manually write inventory menus * put the inventories in Client * start on containersetcontent * inventory menu should hopefully work * checks in containersetcontent * format a comment * move some variant matches * inventory.rs * inventory stuff * more inventory stuff * inventory/container tracking works * start adding interact function * sequence number * start adding HitResultComponent * implement traverse_blocks * start adding clip * add clip function * update_hit_result_component * start trying to fix * fix * make some stuff simpler * clippy * lever * chest * container handle * fix ambiguity * fix some doc tests * move some container stuff from az-client to azalea * clicking container * start implementing simulate_click * keep working on simulate click * implement more of simulate_click this is really boring * inventory fixes * start implementing shift clicking * fix panic in azalea-chat i hope * shift clicking implemented * more inventory stuff * fix items not showing in containers sometimes * fix test * fix all warnings * remove a println --------- Co-authored-by: mat <git@matdoes.dev>
61 lines
2.3 KiB
Python
Executable file
61 lines
2.3 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):
|
|
with open(REGISTRIES_DIR, 'r') as f:
|
|
code = f.read().split('\n')
|
|
|
|
for registry_name, registry in registries.items():
|
|
# registry!(Block, {
|
|
# Air => "minecraft:air",
|
|
# Stone => "minecraft:stone"
|
|
# });
|
|
|
|
registry_name = registry_name.split(':')[1]
|
|
|
|
if registry_name.endswith('_type'):
|
|
# change _type to _kind because that's Rustier (and because _type
|
|
# is a reserved keyword)
|
|
registry_name = registry_name[:-5] + '_kind'
|
|
elif registry_name in {'menu'}:
|
|
registry_name += '_kind'
|
|
|
|
registry_struct_name = to_camel_case(registry_name)
|
|
|
|
registry_code = []
|
|
registry_code.append(f'enum {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])
|
|
registry_code.append(f'\t{variant_struct_name} => "{variant_name}",')
|
|
registry_code.append('}')
|
|
|
|
# when we find a "registry! {" line, find the next line that starts
|
|
# with "enum <name>" and replace that until we find a line that's "}"
|
|
found = False
|
|
in_registry_macro = False
|
|
for i, line in enumerate(list(code)):
|
|
if not in_registry_macro and line == "registry! {":
|
|
in_registry_macro = True
|
|
elif in_registry_macro and line == registry_code[0]:
|
|
# found it, now delete until we get to "}"
|
|
while code[i] != '}':
|
|
code.pop(i)
|
|
code[i] = '\n'.join(registry_code)
|
|
found = True
|
|
break
|
|
if not found:
|
|
code.append('registry! {')
|
|
code.append('\n'.join(registry_code))
|
|
code.append('}')
|
|
code.append('')
|
|
|
|
with open(REGISTRIES_DIR, 'w') as f:
|
|
f.write('\n'.join(code))
|