From c36201cc894bcc99a06358eea31d210800980dae Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 28 Nov 2024 03:17:58 +0000 Subject: change DataComponentPatch::get to take in a generic (and add get_kind, has, and has_kind) --- codegen/genitemcomponents.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'codegen') diff --git a/codegen/genitemcomponents.py b/codegen/genitemcomponents.py index 73f03081..625af847 100644 --- a/codegen/genitemcomponents.py +++ b/codegen/genitemcomponents.py @@ -109,12 +109,12 @@ def remove_variant(variant: str): # now remove the struct line_before_struct = None # this is the #[derive] line - line_after_struct = None # impl DataComponent for ... {} + line_after_struct = None # impl DataComponent for ... {\n...\n} for i, line in enumerate(list(code)): if line == f'pub struct {variant} {{' or line == f'pub struct {variant};': line_before_struct = i - 1 - elif line == f'impl DataComponent for {variant} {{}}': - line_after_struct = i + 1 + elif line == f'impl DataComponent for {variant} {{': + line_after_struct = i + 3 break if line_before_struct is None: raise ValueError(f'Couldn\'t find struct {variant}') @@ -153,7 +153,9 @@ def add_variant(variant: str): code.append(f'pub struct {variant} {{') code.append(' pub todo: todo!(), // see DataComponents.java') code.append('}') - code.append(f'impl DataComponent for {variant} {{}}') + code.append(f'impl DataComponent for {variant} {{') + code.append(f' const KIND: DataComponentKind = DataComponentKind::{variant};') + code.append('}') with open(ITEM_COMPONENTS_DIR, 'w') as f: f.write('\n'.join(code)) -- cgit v1.2.3