From 0e245ad3f5868214a92f158f24cb2b8400e902dd Mon Sep 17 00:00:00 2001 From: Dmitry Stepanov Date: Thu, 10 Sep 2026 22:55:38 +0300 Subject: [PATCH] `GraphNodeConstructorContainer::try_create_variant` helper --- fyrox-graph/src/constructor.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/fyrox-graph/src/constructor.rs b/fyrox-graph/src/constructor.rs index 387aa5d8c..08f38235d 100644 --- a/fyrox-graph/src/constructor.rs +++ b/fyrox-graph/src/constructor.rs @@ -117,6 +117,21 @@ impl GraphNodeConstructor { } } +#[derive(PartialEq, Clone, Debug)] +pub struct ConstructorVariantId { + pub type_uuid: Uuid, + pub variant_index: usize, +} + +impl ConstructorVariantId { + pub fn new(type_uuid: &Uuid, variant_index: usize) -> Self { + Self { + type_uuid: *type_uuid, + variant_index, + } + } +} + /// A special container that is able to create nodes by their type UUID. pub struct GraphNodeConstructorContainer { map: Mutex>>, @@ -163,6 +178,19 @@ impl GraphNodeConstructorContainer { .map(|c| (c.default)()) } + pub fn try_create_variant( + &self, + constructor_variant_id: &ConstructorVariantId, + ctx: &mut Ctx, + ) -> Option> { + let map = self.map.safe_lock(); + let variants = map.get(&constructor_variant_id.type_uuid)?; + let variant = variants + .variants + .get(constructor_variant_id.variant_index)?; + Some((variant.constructor)(ctx)) + } + /// Returns total amount of constructors. pub fn len(&self) -> usize { self.map.safe_lock().len()