aboutsummaryrefslogtreecommitdiff
path: root/codegen/lib/code
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-08-27 20:31:21 -0500
committerGitHub <noreply@github.com>2022-08-27 20:31:21 -0500
commitb8228a036016fa58cab4b00a2e62298df299d41f (patch)
tree37ab80c054d2c0832d0ebf61cbbefd9e368260a8 /codegen/lib/code
parent029ae0e567ccdc631a358755eba43b742811ff05 (diff)
downloadazalea-drasl-b8228a036016fa58cab4b00a2e62298df299d41f.tar.xz
Azalea registry (#20)
* make azalea-registry crate * add trait feature to az-block * registr * registry macro * impl Display for registry things * registries
Diffstat (limited to 'codegen/lib/code')
-rw-r--r--codegen/lib/code/registry.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/codegen/lib/code/registry.py b/codegen/lib/code/registry.py
new file mode 100644
index 00000000..fbe9e5af
--- /dev/null
+++ b/codegen/lib/code/registry.py
@@ -0,0 +1,32 @@
+from typing import Optional
+from lib.utils import to_snake_case, upper_first_letter, get_dir_location, to_camel_case
+from ..mappings import Mappings
+import re
+
+REGISTRIES_DIR = get_dir_location('../azalea-registry/src/lib.rs')
+
+
+def generate_registries(registries: dict):
+ code = []
+
+ code.append('use 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))