From e37d1d0ae9a362902727c5d3dc956291751cfef3 Mon Sep 17 00:00:00 2001 From: Daniel Bross Date: Tue, 19 Nov 2024 23:09:33 +0100 Subject: [PATCH] Meta-program: Use note @NewEntity on procedures to mark them as editor-ui callable entity creation procedures --- metaprogram.jai | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/metaprogram.jai b/metaprogram.jai index 6b5e6a0..6215fb4 100644 --- a/metaprogram.jai +++ b/metaprogram.jai @@ -225,7 +225,17 @@ message_loop :: () { if message.kind == { case .TYPECHECKED; typechecked := cast(*Message_Typechecked) message; - for typechecked.structs note_struct(it.expression); + for typechecked.structs { + note_struct(it.expression); + } + + for typechecked.procedure_headers { + for note: it.expression.notes { + if to_lower_copy_new(note.text,, allocator = temp) == "newentity" { + array_add(*new_entity_procs, it.expression.name); + } + } + } case .PHASE; phase := cast(*Message_Phase) message; @@ -290,7 +300,11 @@ generate_code :: (w: Workspace) { for entity_type_names { lower := to_lower_copy_new(it,, allocator=temp); - print_to_builder(*builder, "if ui_clickable_label(\"New %1\") return new_%2();", it, lower);; + print_to_builder(*builder, "if ui_clickable_label(\"New %1\") return new_%2();", it, lower); + } + + for new_entity_procs { + print_to_builder(*builder, "if ui_clickable_label(\"%1\") return %1();", it); } build_string := sprint(EDITOR_UI_ENTITY_CREATION, builder_to_string(*builder)); @@ -345,7 +359,7 @@ generate_code :: (w: Workspace) { builder: String_Builder; for entity_type_names { - print_to_builder(*builder, "new_%1 :: (scene: *Scene = null) -> *%2 { _scene := scene;\nif _scene == null { \n_scene = engine.current_scene; }\np, locator := find_and_occupy_empty_slot(*_scene.by_type._%2); p._locator = locator; register_entity(_scene, p); p.transform = create_identity_transform(); init_entity(p); return p; }\n", to_lower_copy_new(it,, allocator=temp), it); + print_to_builder(*builder, "new_%1 :: (scene: *Scene = null, init: bool = true) -> *%2 { _scene := scene;\nif _scene == null { \n_scene = engine.current_scene; }\np, locator := find_and_occupy_empty_slot(*_scene.by_type._%2); p._locator = locator; register_entity(_scene, p); p.transform = create_identity_transform(); if init { init_entity(p); } return p; }\n", to_lower_copy_new(it,, allocator=temp), it); } add_build_string(builder_to_string(*builder), w); @@ -368,6 +382,7 @@ generate_code :: (w: Workspace) { generated_code := false; entity_type_names: [..] string; +new_entity_procs: [..] string; // INSERTION_STRING represents the code we want to add to the target program. // We'll use print to insert useful things where the % markers are.