From 7ec002f00c6ea3018f830dc183acfac071ff97fc Mon Sep 17 00:00:00 2001 From: LuoZheng2002 <98627375+LuoZheng2002@users.noreply.github.com> Date: Wed, 1 Oct 2025 10:54:17 -0700 Subject: [PATCH] Renamed pool method typed_ref to try_get (#846) * replaced the BorrowAs trait with ObjectOrVariant trait; added explicit trait bounds in pool and graph's typed_ref method. * renamed pool's typed_ref to try_get * renamed try_get to try_get_node in BaseSceneGraph * deleted try_get_mut from impl Graph, and replaced all occurrences with try_get_node_mut * renamed typed_ref in SceneGraph to try_get * added graph::prelude which contains AbstractSceneGraph, BaseSceneGraph and SceneGraph traits; added use graph::prelude::* in the script template to expose try_get functionalities. * resolved merge issues * formatted code * added use fyrox::graph::prelude::* to template game/src/lib.rs to expose UserInterface's try_get functionality * added "#[allow(unused_imports)]" on game template and script template --- editor/src/asset/mod.rs | 2 +- editor/src/camera/mod.rs | 2 +- editor/src/camera/panel.rs | 3 +- editor/src/interaction/navmesh/selection.rs | 4 +- editor/src/plugins/absm/canvas.rs | 6 +- editor/src/plugins/absm/mod.rs | 12 ++-- editor/src/plugins/absm/toolbar.rs | 2 +- editor/src/plugins/animation/mod.rs | 6 +- editor/src/plugins/animation/toolbar.rs | 2 +- editor/src/plugins/animation/track.rs | 10 ++-- editor/src/plugins/collider/mod.rs | 2 +- editor/src/plugins/collider/panel.rs | 4 +- .../plugins/inspector/handlers/node/mod.rs | 3 +- editor/src/plugins/inspector/mod.rs | 2 +- editor/src/plugins/probe.rs | 4 +- editor/src/plugins/ragdoll.rs | 9 +-- editor/src/plugins/settings.rs | 2 +- editor/src/plugins/tilemap/mod.rs | 6 +- editor/src/scene/mod.rs | 4 +- editor/src/ui_scene/interaction/move_mode.rs | 4 +- editor/src/ui_scene/menu.rs | 2 +- editor/src/ui_scene/mod.rs | 6 +- editor/src/ui_scene/selection.rs | 10 ++-- editor/src/ui_scene/utils.rs | 18 +++--- editor/src/utils/mod.rs | 2 +- editor/src/world/graph.rs | 16 +++--- editor/src/world/item.rs | 2 +- editor/src/world/menu.rs | 4 +- editor/src/world/mod.rs | 5 +- editor/src/world/selection.rs | 6 +- fyrox-core/src/pool/mod.rs | 8 +-- fyrox-graph/src/lib.rs | 48 +++++++++------- fyrox-impl/src/engine/hotreload.rs | 3 +- fyrox-impl/src/engine/mod.rs | 8 ++- fyrox-impl/src/renderer/bundle.rs | 2 +- fyrox-impl/src/renderer/occlusion/mod.rs | 4 +- fyrox-impl/src/renderer/visibility.rs | 2 +- fyrox-impl/src/resource/gltf/animation.rs | 2 +- fyrox-impl/src/resource/gltf/node_names.rs | 6 +- fyrox-impl/src/scene/animation/absm.rs | 2 +- fyrox-impl/src/scene/animation/mod.rs | 4 +- fyrox-impl/src/scene/base.rs | 2 +- fyrox-impl/src/scene/collider.rs | 2 +- fyrox-impl/src/scene/dim2/collider.rs | 2 +- fyrox-impl/src/scene/dim2/joint.rs | 4 +- fyrox-impl/src/scene/dim2/physics.rs | 17 +++--- fyrox-impl/src/scene/graph/mod.rs | 57 ++++++++----------- fyrox-impl/src/scene/graph/physics.rs | 19 +++---- fyrox-impl/src/scene/joint.rs | 4 +- fyrox-impl/src/scene/mesh/mod.rs | 4 +- fyrox-impl/src/script/mod.rs | 8 +-- fyrox-ui/src/animation.rs | 3 +- fyrox-ui/src/build.rs | 2 +- fyrox-ui/src/color/gradient.rs | 4 +- fyrox-ui/src/dock/config.rs | 8 +-- fyrox-ui/src/dock/mod.rs | 4 +- fyrox-ui/src/file_browser/menu.rs | 2 +- fyrox-ui/src/file_browser/mod.rs | 2 +- fyrox-ui/src/grid.rs | 6 +- fyrox-ui/src/inspector/mod.rs | 2 +- fyrox-ui/src/lib.rs | 28 ++++----- fyrox-ui/src/log.rs | 2 +- fyrox-ui/src/menu.rs | 2 +- fyrox-ui/src/popup.rs | 10 ++-- fyrox-ui/src/scroll_panel.rs | 2 +- fyrox-ui/src/tree.rs | 4 +- template-core/src/lib.rs | 6 +- 67 files changed, 231 insertions(+), 224 deletions(-) diff --git a/editor/src/asset/mod.rs b/editor/src/asset/mod.rs index d5d444257..563c6ba87 100644 --- a/editor/src/asset/mod.rs +++ b/editor/src/asset/mod.rs @@ -837,7 +837,7 @@ impl AssetBrowser { if let Some(item) = engine .user_interfaces .first_mut() - .try_get(self.context_menu.placement_target) + .try_get_node(self.context_menu.placement_target) .and_then(|n| n.cast::()) { if let Ok(resource) = diff --git a/editor/src/camera/mod.rs b/editor/src/camera/mod.rs index ac33d4f9d..28ffd8e10 100644 --- a/editor/src/camera/mod.rs +++ b/editor/src/camera/mod.rs @@ -248,7 +248,7 @@ impl CameraController { .try_normalize(f32::EPSILON) .unwrap_or_default() .scale(5.0); - if let Some(relative_to) = graph.try_get(relative_to) { + if let Some(relative_to) = graph.try_get_node(relative_to) { return relative_to .global_transform() .try_inverse() diff --git a/editor/src/camera/panel.rs b/editor/src/camera/panel.rs index a373cb487..97977f27f 100644 --- a/editor/src/camera/panel.rs +++ b/editor/src/camera/panel.rs @@ -40,6 +40,7 @@ use crate::{ send_sync_message, send_sync_messages, Message, }; use fyrox::core::algebra::Vector2; +use fyrox::graph::BaseSceneGraph; use fyrox::gui::widget::WidgetMessage; use fyrox::scene::collider::BitMask; @@ -204,7 +205,7 @@ impl CameraPreviewControlPanel { let node_overrides = game_scene.graph_switches.node_overrides.as_mut().unwrap(); if let Some((camera_handle, original)) = self.camera_state.take() { - if let Some(camera) = scene.graph.try_get_mut(camera_handle) { + if let Some(camera) = scene.graph.try_get_node_mut(camera_handle) { *camera = original } diff --git a/editor/src/interaction/navmesh/selection.rs b/editor/src/interaction/navmesh/selection.rs index fef6317fd..8aad53a00 100644 --- a/editor/src/interaction/navmesh/selection.rs +++ b/editor/src/interaction/navmesh/selection.rs @@ -65,7 +65,7 @@ impl SelectionContainer for NavmeshSelection { ) { let game_scene = some_or_return!(controller.downcast_ref::()); let scene = &scenes[game_scene.scene]; - let node = scene.graph.try_get(self.navmesh_node).unwrap(); + let node = scene.graph.try_get_node(self.navmesh_node).unwrap(); (callback)(node as &dyn Reflect, node.has_inheritance_parent()); } @@ -98,7 +98,7 @@ impl SelectionContainer for NavmeshSelection { ctx.get_mut::() .scene .graph - .try_get_mut(navmesh_node) + .try_get_node_mut(navmesh_node) .map(|n| n as &mut dyn Reflect) }, )) diff --git a/editor/src/plugins/absm/canvas.rs b/editor/src/plugins/absm/canvas.rs index 0df552a3b..8be289d29 100644 --- a/editor/src/plugins/absm/canvas.rs +++ b/editor/src/plugins/absm/canvas.rs @@ -212,7 +212,7 @@ impl AbsmCanvas { T: 'static, { if ui - .try_get(node_handle) + .try_get_node(node_handle) .is_some_and(|n| n.has_component::()) { return node_handle; @@ -290,8 +290,8 @@ impl AbsmCanvas { { if transition_handle == transition.handle() { if let (Some(source_state), Some(dest_state)) = ( - ui.try_get(transition.segment.source), - ui.try_get(transition.segment.dest), + ui.try_get_node(transition.segment.source), + ui.try_get_node(transition.segment.dest), ) { let source_pos = source_state.center(); let dest_pos = dest_state.center(); diff --git a/editor/src/plugins/absm/mod.rs b/editor/src/plugins/absm/mod.rs index 72d8fc9e6..021a40566 100644 --- a/editor/src/plugins/absm/mod.rs +++ b/editor/src/plugins/absm/mod.rs @@ -130,7 +130,7 @@ where N: SceneGraphNode, { graph - .try_get_mut(handle) + .try_get_node_mut(handle) .and_then(|n| n.component_mut::>>>()) .map(|v| v.get_value_mut_silent()) } @@ -144,12 +144,12 @@ where N: SceneGraphNode, { let animation_player_handle = *graph - .try_get(handle) + .try_get_node(handle) .and_then(|n| n.component_ref::>>()) .cloned()?; graph - .try_get_mut(animation_player_handle) + .try_get_node_mut(animation_player_handle) .and_then(|n| n.component_mut::>>>()) .map(|ac| (animation_player_handle, ac.get_value_mut_silent())) } @@ -160,7 +160,7 @@ where N: SceneGraphNode, { graph - .try_get(handle) + .try_get_node(handle) .and_then(|n| n.component_ref::>>>()) .map(|v| v.get_value_ref()) } @@ -174,11 +174,11 @@ where N: SceneGraphNode, { graph - .try_get(handle) + .try_get_node(handle) .and_then(|n| n.component_ref::>>()) .and_then(|ap| { graph - .try_get(**ap) + .try_get_node(**ap) .and_then(|n| { n.component_ref::>>>() }) diff --git a/editor/src/plugins/absm/toolbar.rs b/editor/src/plugins/absm/toolbar.rs index a4559e37e..152c527a3 100644 --- a/editor/src/plugins/absm/toolbar.rs +++ b/editor/src/plugins/absm/toolbar.rs @@ -272,7 +272,7 @@ impl Toolbar { .cloned() .filter(|n| { graph - .try_get(*n) + .try_get_node(*n) .is_some_and(|n| !unique_nodes.contains(&n.parent())) }) .collect::>(); diff --git a/editor/src/plugins/animation/mod.rs b/editor/src/plugins/animation/mod.rs index 7a9398985..eff426fe0 100644 --- a/editor/src/plugins/animation/mod.rs +++ b/editor/src/plugins/animation/mod.rs @@ -178,7 +178,7 @@ where N: SceneGraphNode, { graph - .try_get_mut(handle) + .try_get_node_mut(handle) .and_then(|n| n.component_mut::>>>()) .map(|v| v.get_value_mut_silent()) } @@ -192,7 +192,7 @@ where N: SceneGraphNode, { graph - .try_get(handle) + .try_get_node(handle) .and_then(|n| { n.query_component_ref(TypeId::of::< InheritableVariable>>, @@ -454,7 +454,7 @@ impl AnimationEditor { assert!(node_overrides.insert(selection.animation_player)); let animation_player_node = - graph.try_get_mut(selection.animation_player).unwrap(); + graph.try_get_node_mut(selection.animation_player).unwrap(); // HACK. This is unreliable to just use `bool` here. It should be wrapped into // newtype or something. diff --git a/editor/src/plugins/animation/toolbar.rs b/editor/src/plugins/animation/toolbar.rs index 91f6c7f9d..ec77cc2aa 100644 --- a/editor/src/plugins/animation/toolbar.rs +++ b/editor/src/plugins/animation/toolbar.rs @@ -391,7 +391,7 @@ impl RootMotionDropdownArea { .content, MessageDirection::ToWidget, graph - .try_get(settings.node) + .try_get_node(settings.node) .map(|n| n.name().to_owned()) .unwrap_or_else(|| String::from("")), ), diff --git a/editor/src/plugins/animation/track.rs b/editor/src/plugins/animation/track.rs index 4a94b1fee..2f08d9d1f 100644 --- a/editor/src/plugins/animation/track.rs +++ b/editor/src/plugins/animation/track.rs @@ -936,7 +936,7 @@ impl TrackList { if message.destination() == self.property_selector && message.direction() == MessageDirection::FromWidget { - if let Some(node) = graph.try_get(self.selected_node.into()) { + if let Some(node) = graph.try_get_node(self.selected_node.into()) { for property_path in selected_properties { node.resolve_path(&property_path.path, &mut |result| match result { Ok(property) => { @@ -1117,7 +1117,7 @@ impl TrackList { N: SceneGraphNode, { let mut descriptors = Vec::new(); - if let Some(node) = graph.try_get(node) { + if let Some(node) = graph.try_get_node(node) { node.as_reflect(&mut |node| { descriptors = object_to_property_tree("", node, &mut |field: &FieldRef| { let type_id = field.value.field_value_as_reflect().type_id(); @@ -1237,7 +1237,7 @@ impl TrackList { return; }; - let Some(node) = graph.try_get(binding.target()) else { + let Some(node) = graph.try_get_node(binding.target()) else { Log::err("Invalid node handle!"); return; }; @@ -1390,7 +1390,7 @@ impl TrackList { .with_text(format!( "{} ({}:{})", graph - .try_get(model_track_binding.target()) + .try_get_node(model_track_binding.target()) .map(|n| n.name()) .unwrap_or_default(), model_track_binding.target().index(), @@ -1581,7 +1581,7 @@ impl TrackList { } let mut validation_result = Ok(()); - if let Some(target) = graph.try_get(model_track_binding.target()) { + if let Some(target) = graph.try_get_node(model_track_binding.target()) { if let Some(parent_group) = self.group_views.get(&model_track_binding.target().into()) { diff --git a/editor/src/plugins/collider/mod.rs b/editor/src/plugins/collider/mod.rs index 4583361cc..6c8a56181 100644 --- a/editor/src/plugins/collider/mod.rs +++ b/editor/src/plugins/collider/mod.rs @@ -496,7 +496,7 @@ impl InteractionMode for ColliderShapeInteractionMode { ctx.get_mut::() .scene .graph - .try_get_mut(collider) + .try_get_node_mut(collider) .map(|n| n as &mut dyn Reflect) }); self.message_sender.do_command(command); diff --git a/editor/src/plugins/collider/panel.rs b/editor/src/plugins/collider/panel.rs index bedb05162..d06b67523 100644 --- a/editor/src/plugins/collider/panel.rs +++ b/editor/src/plugins/collider/panel.rs @@ -62,7 +62,7 @@ fn set_property( ctx.get_mut::() .scene .graph - .try_get_mut(selected_collider) + .try_get_node_mut(selected_collider) .map(|n| n as &mut dyn Reflect) }, ))); @@ -199,7 +199,7 @@ impl ColliderControlPanel { ColliderShape::Capsule(_) => { let local_center = scene .graph - .try_get(collider_ref.parent()) + .try_get_node(collider_ref.parent()) .map(|p| p.global_transform()) .unwrap_or_default() .try_inverse() diff --git a/editor/src/plugins/inspector/handlers/node/mod.rs b/editor/src/plugins/inspector/handlers/node/mod.rs index 9c496d26c..0d2c91309 100644 --- a/editor/src/plugins/inspector/handlers/node/mod.rs +++ b/editor/src/plugins/inspector/handlers/node/mod.rs @@ -30,6 +30,7 @@ use crate::{ scene::commands::terrain::{AddTerrainLayerCommand, DeleteTerrainLayerCommand}, Command, }; +use fyrox::graph::BaseSceneGraph; pub struct SceneNodePropertyChangedHandler; @@ -83,7 +84,7 @@ impl SceneNodePropertyChangedHandler { ctx.get_mut::() .scene .graph - .try_get_mut(handle) + .try_get_node_mut(handle) .map(|n| n as &mut dyn Reflect) }) } diff --git a/editor/src/plugins/inspector/mod.rs b/editor/src/plugins/inspector/mod.rs index 06af4fc37..5d5dfaef8 100644 --- a/editor/src/plugins/inspector/mod.rs +++ b/editor/src/plugins/inspector/mod.rs @@ -178,7 +178,7 @@ fn current_widget_style( if let Some(ui_selection) = selection.as_ui() { return ui_scene .ui - .try_get(ui_selection.widgets[0]) + .try_get_node(ui_selection.widgets[0]) .and_then(|n| n.style.clone()); } } diff --git a/editor/src/plugins/probe.rs b/editor/src/plugins/probe.rs index f234e27e6..14ac6bfb5 100644 --- a/editor/src/plugins/probe.rs +++ b/editor/src/plugins/probe.rs @@ -30,7 +30,7 @@ use crate::{ Uuid, }, engine::Engine, - graph::SceneGraph, + graph::{BaseSceneGraph, SceneGraph}, gui::{ button::{ButtonBuilder, ButtonMessage}, grid::{Column, GridBuilder, Row}, @@ -218,7 +218,7 @@ impl InteractionMode for ReflectionProbeInteractionMode { ctx.get_mut::() .scene .graph - .try_get_mut(probe.transmute()) + .try_get_node_mut(probe.transmute()) .map(|n| n as &mut dyn Reflect) }, ); diff --git a/editor/src/plugins/ragdoll.rs b/editor/src/plugins/ragdoll.rs index 077b98b91..70ac8c9dd 100644 --- a/editor/src/plugins/ragdoll.rs +++ b/editor/src/plugins/ragdoll.rs @@ -306,7 +306,7 @@ impl RagdollPreset { apply_offset: bool, graph: &mut Graph, ) -> Handle { - if let Some(from_ref) = graph.try_get(from) { + if let Some(from_ref) = graph.try_get_node(from) { let offset = if apply_offset { from_ref .up_vector() @@ -364,7 +364,7 @@ impl RagdollPreset { ragdoll: Handle, graph: &mut Graph, ) -> Handle { - if let (Some(from_ref), Some(to_ref)) = (graph.try_get(from), graph.try_get(to)) { + if let (Some(from_ref), Some(to_ref)) = (graph.try_get_node(from), graph.try_get_node(to)) { let pos_from = from_ref.global_position(); let pos_to = to_ref.global_position(); @@ -418,7 +418,7 @@ impl RagdollPreset { ragdoll: Handle, graph: &mut Graph, ) -> Handle { - if let Some(from_ref) = graph.try_get(from) { + if let Some(from_ref) = graph.try_get_node(from) { let cuboid = RigidBodyBuilder::new( BaseBuilder::new() .with_name(name) @@ -458,7 +458,8 @@ impl RagdollPreset { (self.left_fore_arm, self.left_hand), (self.left_fore_arm, self.right_hand), ] { - if let (Some(upper_ref), Some(lower_ref)) = (graph.try_get(upper), graph.try_get(lower)) + if let (Some(upper_ref), Some(lower_ref)) = + (graph.try_get_node(upper), graph.try_get_node(lower)) { base_size = (upper_ref.global_position() - lower_ref.global_position()).norm(); break; diff --git a/editor/src/plugins/settings.rs b/editor/src/plugins/settings.rs index 1369d29d6..f8bde4f36 100644 --- a/editor/src/plugins/settings.rs +++ b/editor/src/plugins/settings.rs @@ -372,7 +372,7 @@ impl SettingsWindow { self.sync_to_model(ui, settings, sender, engine.resource_manager.clone()); } - if let Some(node) = ui.try_get(message.destination()) { + if let Some(node) = ui.try_get_node(message.destination()) { if let Some(user_data) = node.user_data_cloned::() { let inspector = ui.try_get_of_type::(self.inspector).unwrap(); diff --git a/editor/src/plugins/tilemap/mod.rs b/editor/src/plugins/tilemap/mod.rs index 5deb9eea5..4d6db05fb 100644 --- a/editor/src/plugins/tilemap/mod.rs +++ b/editor/src/plugins/tilemap/mod.rs @@ -581,7 +581,7 @@ impl TileMapEditorPlugin { let entry = editor.scenes.current_scene_entry_mut()?; let game_scene = entry.controller.downcast_mut::()?; let scene = &mut editor.engine.scenes[game_scene.scene]; - let node = scene.graph.try_get_mut(self.tile_map)?; + let node = scene.graph.try_get_node_mut(self.tile_map)?; node.component_mut::() } fn open_panel_for_tile_set( @@ -725,7 +725,7 @@ impl EditorPlugin for TileMapEditorPlugin { let palette = self.state.lock().selection_palette(); if let Some(palette) = ui - .try_get_mut(palette) + .try_get_node_mut(palette) .and_then(|p| p.cast_mut::()) { palette.sync_selection_to_model(); @@ -873,7 +873,7 @@ impl EditorPlugin for TileMapEditorPlugin { // Remove the editor data from the currently selected tile map, so it will render as normal. if let Some(tile_map) = scene .graph - .try_get_mut(self.tile_map) + .try_get_node_mut(self.tile_map) .and_then(|n| n.component_mut::()) { tile_map.before_effects.clear(); diff --git a/editor/src/scene/mod.rs b/editor/src/scene/mod.rs index 524c93dc4..3a921da66 100644 --- a/editor/src/scene/mod.rs +++ b/editor/src/scene/mod.rs @@ -300,7 +300,7 @@ impl GameScene { if let Some(selection) = editor_selection.as_graph() { for &node in selection.nodes() { - if let Some(node) = scene.graph.try_get(node) { + if let Some(node) = scene.graph.try_get_node(node) { scene.drawing_context.draw_oob( &node.local_bounding_box(), node.global_transform(), @@ -1047,7 +1047,7 @@ impl SceneController for GameScene { UiMessage::with_data(HandlePropertyEditorNameMessage( scene .graph - .try_get((*handle).into()) + .try_get_node((*handle).into()) .map(|n| n.name_owned()), )) .with_destination(*view) diff --git a/editor/src/ui_scene/interaction/move_mode.rs b/editor/src/ui_scene/interaction/move_mode.rs index 498cd5330..3a670d36f 100644 --- a/editor/src/ui_scene/interaction/move_mode.rs +++ b/editor/src/ui_scene/interaction/move_mode.rs @@ -83,7 +83,7 @@ impl InteractionMode for MoveWidgetsInteractionMode { .widgets .iter() .filter_map(|w| { - if let Some(widget_ref) = ui_scene.ui.try_get(*w) { + if let Some(widget_ref) = ui_scene.ui.try_get_node(*w) { if !in_bounds && widget_ref.screen_bounds().contains(mouse_position) { in_bounds = true; } @@ -179,7 +179,7 @@ impl InteractionMode for MoveWidgetsInteractionMode { let new_screen_space_position = mouse_position - entry.delta; let parent_inv_transform = ui_scene .ui - .try_get(ui_scene.ui.node(entry.widget).parent) + .try_get_node(ui_scene.ui.node(entry.widget).parent) .and_then(|w| w.visual_transform().try_inverse()) .unwrap_or_default(); let new_local_position = parent_inv_transform.transform_point(&Point2::new( diff --git a/editor/src/ui_scene/menu.rs b/editor/src/ui_scene/menu.rs index 443a9c0ad..739ac323f 100644 --- a/editor/src/ui_scene/menu.rs +++ b/editor/src/ui_scene/menu.rs @@ -71,7 +71,7 @@ fn resource_path_of_first_selected_node( ) -> Option { if let Some(ui_selection) = editor_selection.as_ui() { if let Some(first) = ui_selection.widgets.first() { - if let Some(resource) = ui_scene.ui.try_get(*first).and_then(|n| n.resource()) { + if let Some(resource) = ui_scene.ui.try_get_node(*first).and_then(|n| n.resource()) { return resource_manager.resource_path(resource.as_ref()); } } diff --git a/editor/src/ui_scene/mod.rs b/editor/src/ui_scene/mod.rs index a6d2542c5..fc471f726 100644 --- a/editor/src/ui_scene/mod.rs +++ b/editor/src/ui_scene/mod.rs @@ -100,7 +100,7 @@ impl UiScene { } fn select_object(&mut self, handle: ErasedHandle) { - if self.ui.try_get(handle.into()).is_some() { + if self.ui.try_get_node(handle.into()).is_some() { self.message_sender .do_command(ChangeSelectionCommand::new(Selection::new( UiSelection::single_or_empty(handle.into()), @@ -358,7 +358,7 @@ impl SceneController for UiScene { // Draw selection on top. if let Some(selection) = editor_selection.as_ui() { for node in selection.widgets.iter() { - if let Some(node) = self.ui.try_get(*node) { + if let Some(node) = self.ui.try_get_node(*node) { let bounds = node.screen_bounds(); let clip_bounds = node.clip_bounds(); let drawing_context = &mut self.ui.drawing_context; @@ -456,7 +456,7 @@ impl SceneController for UiScene { engine.user_interfaces.first_mut().send_message( UiMessage::with_data(HandlePropertyEditorNameMessage( self.ui - .try_get((*handle).into()) + .try_get_node((*handle).into()) .map(|n| n.name().to_owned()), )) .with_destination(*view) diff --git a/editor/src/ui_scene/selection.rs b/editor/src/ui_scene/selection.rs index dda7cb3fe..9cee23a01 100644 --- a/editor/src/ui_scene/selection.rs +++ b/editor/src/ui_scene/selection.rs @@ -56,7 +56,7 @@ impl SelectionContainer for UiSelection { ) { let ui_scene = some_or_return!(controller.downcast_ref::()); if let Some(first) = self.widgets.first() { - if let Some(node) = ui_scene.ui.try_get(*first) { + if let Some(node) = ui_scene.ui.try_get_node(*first) { (callback)(node as &dyn Reflect, node.has_inheritance_parent()) } } @@ -74,7 +74,7 @@ impl SelectionContainer for UiSelection { .widgets .iter() .filter_map(|&node_handle| { - let node = ui_scene.ui.try_get(node_handle)?; + let node = ui_scene.ui.try_get_node(node_handle)?; if args.is_inheritable() { // Prevent reverting property value if there's no parent resource. if node.resource().is_some() { @@ -89,7 +89,7 @@ impl SelectionContainer for UiSelection { make_command(args, move |ctx| { ctx.get_mut::() .ui - .try_get_mut(node_handle) + .try_get_node_mut(node_handle) .map(|n| n as &mut dyn Reflect) }) } @@ -111,7 +111,7 @@ impl SelectionContainer for UiSelection { move |ctx| { ctx.get_mut::() .ui - .try_get_mut(node_handle) + .try_get_node_mut(node_handle) .map(|n| n as &mut dyn Reflect) }, )) @@ -126,7 +126,7 @@ impl SelectionContainer for UiSelection { let ui_scene = controller.downcast_ref::()?; self.widgets .first() - .and_then(|h| ui_scene.ui.try_get(*h).map(|n| n.doc().to_string())) + .and_then(|h| ui_scene.ui.try_get_node(*h).map(|n| n.doc().to_string())) } } diff --git a/editor/src/ui_scene/utils.rs b/editor/src/ui_scene/utils.rs index ce8d06b21..a7499c9f9 100644 --- a/editor/src/ui_scene/utils.rs +++ b/editor/src/ui_scene/utils.rs @@ -67,14 +67,14 @@ impl WorldViewerDataProvider for UiSceneWorldViewerDataProvider<'_> { fn children_of(&self, node: ErasedHandle) -> Vec { self.ui - .try_get(node.into()) + .try_get_node(node.into()) .map(|n| n.children.iter().map(|c| (*c).into()).collect::>()) .unwrap_or_default() } fn child_count_of(&self, node: ErasedHandle) -> usize { self.ui - .try_get(node.into()) + .try_get_node(node.into()) .map(|n| n.children.len()) .unwrap_or_default() } @@ -91,19 +91,19 @@ impl WorldViewerDataProvider for UiSceneWorldViewerDataProvider<'_> { fn is_node_has_child(&self, node: ErasedHandle, child: ErasedHandle) -> bool { self.ui - .try_get(node.into()) + .try_get_node(node.into()) .is_some_and(|n| n.children().iter().any(|c| *c == child.into())) } fn parent_of(&self, node: ErasedHandle) -> ErasedHandle { self.ui - .try_get(node.into()) + .try_get_node(node.into()) .map(|n| n.parent().into()) .unwrap_or_default() } fn name_of(&self, node: ErasedHandle) -> Option> { - self.ui.try_get(node.into()).map(|n| { + self.ui.try_get_node(node.into()).map(|n| { Cow::Owned(format!( "{} [{}]", n.name(), @@ -113,11 +113,11 @@ impl WorldViewerDataProvider for UiSceneWorldViewerDataProvider<'_> { } fn is_valid_handle(&self, node: ErasedHandle) -> bool { - self.ui.try_get(node.into()).is_some() + self.ui.try_get_node(node.into()).is_some() } fn icon_of(&self, node: ErasedHandle) -> Option { - let node: &UiNode = self.ui.try_get(node.into()).unwrap(); + let node: &UiNode = self.ui.try_get_node(node.into()).unwrap(); // all icons are able to be used freely // todo: add more icons @@ -166,7 +166,7 @@ impl WorldViewerDataProvider for UiSceneWorldViewerDataProvider<'_> { fn is_instance(&self, node: ErasedHandle) -> bool { self.ui - .try_get(node.into()) + .try_get_node(node.into()) .is_some_and(|n| n.resource().is_some()) } @@ -211,7 +211,7 @@ impl WorldViewerDataProvider for UiSceneWorldViewerDataProvider<'_> { if let Some((parents_parent, position)) = self.ui.relative_position(parent, index_offset) { - if let Some(node) = self.ui.try_get(widget_handle) { + if let Some(node) = self.ui.try_get_node(widget_handle) { if node.parent() != parents_parent { commands.push(LinkWidgetsCommand::new( widget_handle, diff --git a/editor/src/utils/mod.rs b/editor/src/utils/mod.rs index 835f86b46..d177f5518 100644 --- a/editor/src/utils/mod.rs +++ b/editor/src/utils/mod.rs @@ -132,7 +132,7 @@ pub fn fetch_node_screen_center(handle: Handle, ctx: &BuildContext) -> V } pub fn fetch_node_screen_center_ui(handle: Handle, ui: &UserInterface) -> Vector2 { - ui.try_get(handle) + ui.try_get_node(handle) .map(|node| node.screen_bounds().center()) .unwrap_or_default() } diff --git a/editor/src/world/graph.rs b/editor/src/world/graph.rs index 1fe093497..1fdaaa7b2 100644 --- a/editor/src/world/graph.rs +++ b/editor/src/world/graph.rs @@ -69,7 +69,7 @@ impl WorldViewerDataProvider for EditorSceneWrapper<'_> { fn children_of(&self, node: ErasedHandle) -> Vec { self.scene .graph - .try_get(node.into()) + .try_get_node(node.into()) .map(|n| { n.children() .iter() @@ -82,7 +82,7 @@ impl WorldViewerDataProvider for EditorSceneWrapper<'_> { fn child_count_of(&self, node: ErasedHandle) -> usize { self.scene .graph - .try_get(node.into()) + .try_get_node(node.into()) .map_or(0, |node| node.children().len()) } @@ -100,14 +100,14 @@ impl WorldViewerDataProvider for EditorSceneWrapper<'_> { fn is_node_has_child(&self, node: ErasedHandle, child: ErasedHandle) -> bool { self.scene .graph - .try_get(node.into()) + .try_get_node(node.into()) .is_some_and(|node| node.children().contains(&child.into())) } fn parent_of(&self, node: ErasedHandle) -> ErasedHandle { self.scene .graph - .try_get(node.into()) + .try_get_node(node.into()) .map(|node| node.parent().into()) .unwrap_or_default() } @@ -115,7 +115,7 @@ impl WorldViewerDataProvider for EditorSceneWrapper<'_> { fn name_of(&self, node: ErasedHandle) -> Option> { self.scene .graph - .try_get(node.into()) + .try_get_node(node.into()) .map(|n| Cow::Borrowed(n.name())) } @@ -124,7 +124,7 @@ impl WorldViewerDataProvider for EditorSceneWrapper<'_> { } fn icon_of(&self, node: ErasedHandle) -> Option { - let node = self.scene.graph.try_get(node.into()).unwrap(); + let node = self.scene.graph.try_get_node(node.into()).unwrap(); if node.is_point_light() || node.is_directional_light() || node.is_spot_light() { load_image!("../../resources/light.png") } else if node.is_joint() || node.is_joint2d() { @@ -143,7 +143,7 @@ impl WorldViewerDataProvider for EditorSceneWrapper<'_> { fn is_instance(&self, node: ErasedHandle) -> bool { self.scene .graph - .try_get(node.into()) + .try_get_node(node.into()) .is_some_and(|n| n.resource().is_some()) } @@ -188,7 +188,7 @@ impl WorldViewerDataProvider for EditorSceneWrapper<'_> { if let Some((parents_parent, position)) = self.scene.graph.relative_position(parent, index_offset) { - if let Some(node) = self.scene.graph.try_get(node_handle) { + if let Some(node) = self.scene.graph.try_get_node(node_handle) { if node.parent() != parents_parent { commands.push(LinkNodesCommand::new( node_handle, diff --git a/editor/src/world/item.rs b/editor/src/world/item.rs index 245ce3be7..821eb7e23 100644 --- a/editor/src/world/item.rs +++ b/editor/src/world/item.rs @@ -225,7 +225,7 @@ impl Control for SceneItem { } else if let Some(msg) = message.data::() { match msg { WidgetMessage::DragOver(_) => { - if let Some(background) = ui.try_get(self.tree.background) { + if let Some(background) = ui.try_get_node(self.tree.background) { let cursor_pos = ui.cursor_position(); let bounds = background.screen_bounds(); let deflated_bounds = bounds.deflate(0.0, 5.0); diff --git a/editor/src/world/menu.rs b/editor/src/world/menu.rs index 00a3e72b5..f777eedec 100644 --- a/editor/src/world/menu.rs +++ b/editor/src/world/menu.rs @@ -91,7 +91,7 @@ fn resource_path_of_first_selected_node( if let Some(graph_selection) = editor_selection.as_graph() { if let Some(first) = graph_selection.nodes.first() { let scene = &engine.scenes[game_scene.scene]; - if let Some(resource) = scene.graph.try_get(*first).and_then(|n| n.resource()) { + if let Some(resource) = scene.graph.try_get_node(*first).and_then(|n| n.resource()) { return engine.resource_manager.resource_path(resource.as_ref()); } } @@ -395,7 +395,7 @@ impl SceneNodeContextMenu { let scene = &engine.scenes[game_scene.scene]; let mut commands = Vec::new(); for node_handle in graph_selection.nodes.iter() { - if let Some(node) = scene.graph.try_get(*node_handle) { + if let Some(node) = scene.graph.try_get_node(*node_handle) { (node as &dyn Reflect).enumerate_fields_recursively( &mut |path, _, val| { val.as_inheritable_variable(&mut |inheritable| { diff --git a/editor/src/world/mod.rs b/editor/src/world/mod.rs index 891065666..2ee74dadb 100644 --- a/editor/src/world/mod.rs +++ b/editor/src/world/mod.rs @@ -629,7 +629,7 @@ impl WorldViewer { self.colorize(ui); self.node_to_view_map - .retain(|k, v| data_provider.is_valid_handle(*k) && ui.try_get(*v).is_some()); + .retain(|k, v| data_provider.is_valid_handle(*k) && ui.try_get_node(*v).is_some()); } pub fn colorize(&mut self, ui: &UserInterface) { @@ -704,7 +704,8 @@ impl WorldViewer { self.handle_drop(ui, data_provider, message.destination(), node); } else if let Some(ButtonMessage::Click) = message.data::() { if let Some(&view) = self.breadcrumbs.get(&message.destination()) { - if let Some(graph_node) = ui.try_get(view).and_then(|n| n.cast::()) { + if let Some(graph_node) = ui.try_get_node(view).and_then(|n| n.cast::()) + { data_provider.on_selection_changed(&[graph_node.entity_handle]); } } else if message.destination() == self.collapse_all { diff --git a/editor/src/world/selection.rs b/editor/src/world/selection.rs index 3b501fdcd..f01798f9b 100644 --- a/editor/src/world/selection.rs +++ b/editor/src/world/selection.rs @@ -59,7 +59,7 @@ impl SelectionContainer for GraphSelection { if let Some(node) = self .nodes .first() - .and_then(|handle| scene.graph.try_get(*handle)) + .and_then(|handle| scene.graph.try_get_node(*handle)) { (callback)(node as &dyn Reflect, node.has_inheritance_parent()); } @@ -82,7 +82,7 @@ impl SelectionContainer for GraphSelection { game_scene.node_property_changed_handler.handle( args, node_handle, - scene.graph.try_get_mut(node_handle)?, + scene.graph.try_get_node_mut(node_handle)?, ) }) .collect::>(); @@ -103,7 +103,7 @@ impl SelectionContainer for GraphSelection { ctx.get_mut::() .scene .graph - .try_get_mut(node_handle) + .try_get_node_mut(node_handle) .map(|n| n as &mut dyn Reflect) }, )) diff --git a/fyrox-core/src/pool/mod.rs b/fyrox-core/src/pool/mod.rs index c98939584..0769e8e85 100644 --- a/fyrox-core/src/pool/mod.rs +++ b/fyrox-core/src/pool/mod.rs @@ -451,13 +451,13 @@ where } #[inline] - pub fn typed_ref>(&self, handle: Handle) -> Option<&U> { + pub fn try_get>(&self, handle: Handle) -> Option<&U> { let pool_object = self.try_borrow(handle.transmute())?; U::convert_to_dest_type(pool_object) } #[inline] - pub fn typed_mut>(&mut self, handle: Handle) -> Option<&mut U> { + pub fn try_get_mut>(&mut self, handle: Handle) -> Option<&mut U> { let pool_object = self.try_borrow_mut(handle.transmute())?; U::convert_to_dest_type_mut(pool_object) } @@ -1412,7 +1412,7 @@ where type Output = U; #[inline] fn index(&self, index: Handle) -> &Self::Output { - self.typed_ref(index).expect("The handle must be valid!") + self.try_get(index).expect("The handle must be valid!") } } @@ -1424,7 +1424,7 @@ where { #[inline] fn index_mut(&mut self, index: Handle) -> &mut Self::Output { - self.typed_mut(index).expect("The handle must be valid!") + self.try_get_mut(index).expect("The handle must be valid!") } } diff --git a/fyrox-graph/src/lib.rs b/fyrox-graph/src/lib.rs index b11244d5a..634288f1d 100644 --- a/fyrox-graph/src/lib.rs +++ b/fyrox-graph/src/lib.rs @@ -24,6 +24,10 @@ pub mod constructor; +pub mod prelude { + pub use crate::{AbstractSceneGraph, BaseSceneGraph, SceneGraph}; +} + use fxhash::FxHashMap; use fyrox_core::pool::{ErasedHandle, ObjectOrVariant, PayloadContainer}; use fyrox_core::reflect::ReflectHandle; @@ -703,10 +707,10 @@ pub trait BaseSceneGraph: AbstractSceneGraph { fn set_root(&mut self, root: Handle); /// Tries to borrow a node, returns Some(node) if the handle is valid, None - otherwise. - fn try_get(&self, handle: Handle) -> Option<&Self::Node>; + fn try_get_node(&self, handle: Handle) -> Option<&Self::Node>; /// Tries to borrow a node, returns Some(node) if the handle is valid, None - otherwise. - fn try_get_mut(&mut self, handle: Handle) -> Option<&mut Self::Node>; + fn try_get_node_mut(&mut self, handle: Handle) -> Option<&mut Self::Node>; /// Checks whether the given node handle is valid or not. fn is_valid_handle(&self, handle: Handle) -> bool; @@ -729,12 +733,14 @@ pub trait BaseSceneGraph: AbstractSceneGraph { /// Borrows a node by its handle. fn node(&self, handle: Handle) -> &Self::Node { - self.try_get(handle).expect("The handle must be valid!") + self.try_get_node(handle) + .expect("The handle must be valid!") } /// Borrows a node by its handle. fn node_mut(&mut self, handle: Handle) -> &mut Self::Node { - self.try_get_mut(handle).expect("The handle must be valid!") + self.try_get_node_mut(handle) + .expect("The handle must be valid!") } /// Reorders the node hierarchy so the `new_root` becomes the root node for the entire hierarchy @@ -839,9 +845,9 @@ pub trait SceneGraph: BaseSceneGraph { /// of nodes. It does *not* perform any tree traversal! fn linear_iter_mut(&mut self) -> impl Iterator; - fn typed_ref>(&self, handle: Handle) -> Option<&U>; + fn try_get>(&self, handle: Handle) -> Option<&U>; - fn typed_mut>( + fn try_get_mut>( &mut self, handle: Handle, ) -> Option<&mut U>; @@ -852,7 +858,7 @@ pub trait SceneGraph: BaseSceneGraph { where T: 'static, { - self.try_get(handle) + self.try_get_node(handle) .and_then(|n| n.query_component_ref(TypeId::of::())) .and_then(|c| c.downcast_ref()) } @@ -863,7 +869,7 @@ pub trait SceneGraph: BaseSceneGraph { where T: 'static, { - self.try_get_mut(handle) + self.try_get_node_mut(handle) .and_then(|n| n.query_component_mut(TypeId::of::())) .and_then(|c| c.downcast_mut()) } @@ -890,7 +896,7 @@ pub trait SceneGraph: BaseSceneGraph { C: FnMut(&Self::Node) -> Option<&T>, T: ?Sized, { - self.try_get(root_node).and_then(|root| { + self.try_get_node(root_node).and_then(|root| { if let Some(x) = cmp(root) { Some((root_node, x)) } else { @@ -911,7 +917,7 @@ pub trait SceneGraph: BaseSceneGraph { C: FnMut(&Self::Node) -> bool, { let mut handle = root_node; - while let Some(node) = self.try_get(handle) { + while let Some(node) = self.try_get_node(handle) { if cmp(node) { return Some((handle, node)); } @@ -970,7 +976,7 @@ pub trait SceneGraph: BaseSceneGraph { T: ?Sized, { let mut handle = root_node; - while let Some(node) = self.try_get(handle) { + while let Some(node) = self.try_get_node(handle) { if let Some(x) = cmp(node) { return Some((handle, x)); } @@ -1037,7 +1043,7 @@ pub trait SceneGraph: BaseSceneGraph { where C: FnMut(&Self::Node) -> bool, { - self.try_get(root_node).and_then(|root| { + self.try_get_node(root_node).and_then(|root| { if cmp(root) { Some((root_node, root)) } else { @@ -1076,8 +1082,8 @@ pub trait SceneGraph: BaseSceneGraph { child: Handle, offset: isize, ) -> Option<(Handle, usize)> { - let parents_parent_handle = self.try_get(child)?.parent(); - let parents_parent_ref = self.try_get(parents_parent_handle)?; + let parents_parent_handle = self.try_get_node(child)?.parent(); + let parents_parent_ref = self.try_get_node(parents_parent_handle)?; let position = parents_parent_ref.child_position(child)?; Some(( parents_parent_handle, @@ -1300,7 +1306,7 @@ pub trait SceneGraph: BaseSceneGraph { NodeMapping::UseHandles => { // Use original handle directly. resource_graph - .try_get(node.original_handle_in_resource()) + .try_get_node(node.original_handle_in_resource()) .map(|resource_node| { (resource_node, node.original_handle_in_resource()) }) @@ -1863,11 +1869,11 @@ mod test { } } - fn try_get(&self, handle: Handle) -> Option<&Self::Node> { + fn try_get_node(&self, handle: Handle) -> Option<&Self::Node> { self.nodes.try_borrow(handle) } - fn try_get_mut(&mut self, handle: Handle) -> Option<&mut Self::Node> { + fn try_get_node_mut(&mut self, handle: Handle) -> Option<&mut Self::Node> { self.nodes.try_borrow_mut(handle) } @@ -1904,12 +1910,12 @@ mod test { self.nodes.iter_mut() } - fn typed_ref>(&self, handle: Handle) -> Option<&U> { - self.nodes.typed_ref(handle) + fn try_get>(&self, handle: Handle) -> Option<&U> { + self.nodes.try_get(handle) } - fn typed_mut>(&mut self, handle: Handle) -> Option<&mut U> { - self.nodes.typed_mut(handle) + fn try_get_mut>(&mut self, handle: Handle) -> Option<&mut U> { + self.nodes.try_get_mut(handle) } } diff --git a/fyrox-impl/src/engine/hotreload.rs b/fyrox-impl/src/engine/hotreload.rs index f46e86aca..a2b0efe0e 100644 --- a/fyrox-impl/src/engine/hotreload.rs +++ b/fyrox-impl/src/engine/hotreload.rs @@ -38,6 +38,7 @@ use crate::{ script::Script, }; use fyrox_core::visitor::error::VisitError; +use fyrox_graph::BaseSceneGraph; use std::{ ops::Deref, sync::{mpsc::Sender, Arc}, @@ -74,7 +75,7 @@ impl SceneState { for index in 0..scene.graph.capacity() { let handle = scene.graph.handle_from_index(index); - let Some(node) = scene.graph.try_get_mut(handle) else { + let Some(node) = scene.graph.try_get_node_mut(handle) else { continue; }; diff --git a/fyrox-impl/src/engine/mod.rs b/fyrox-impl/src/engine/mod.rs index 43f0c7ecd..ececa3c80 100644 --- a/fyrox-impl/src/engine/mod.rs +++ b/fyrox-impl/src/engine/mod.rs @@ -636,7 +636,7 @@ impl ScriptMessageDispatcher { ScriptMessageKind::Hierarchical { root, routing } => match routing { RoutingStrategy::Up => { let mut node = root; - while let Some(node_ref) = scene.graph.try_get(node) { + while let Some(node_ref) = scene.graph.try_get_node(node) { let parent = node_ref.parent(); let mut context = ScriptMessageContext { @@ -2012,7 +2012,9 @@ impl Engine { { let payload = result.payload; if let Some(scene) = self.scenes.try_get_mut(node_task_handler.scene_handle) { - if let Some(node) = scene.graph.try_get_mut(node_task_handler.node_handle) { + if let Some(node) = + scene.graph.try_get_node_mut(node_task_handler.node_handle) + { if let Some(mut script) = node .scripts .get_mut(node_task_handler.script_index) @@ -2040,7 +2042,7 @@ impl Engine { ); if let Some(node) = - scene.graph.try_get_mut(node_task_handler.node_handle) + scene.graph.try_get_node_mut(node_task_handler.node_handle) { if let Some(entry) = node.scripts.get_mut(node_task_handler.script_index) diff --git a/fyrox-impl/src/renderer/bundle.rs b/fyrox-impl/src/renderer/bundle.rs index de22b3711..c1e815ab6 100644 --- a/fyrox-impl/src/renderer/bundle.rs +++ b/fyrox-impl/src/renderer/bundle.rs @@ -891,7 +891,7 @@ impl RenderDataBundleStorage { if let Some(lod_group) = node.lod_group() { for level in lod_group.levels.iter() { for &object in level.objects.iter() { - if let Some(object_ref) = graph.try_get(object) { + if let Some(object_ref) = graph.try_get_node(object) { let distance = observer_position .translation .metric_distance(&object_ref.global_position()); diff --git a/fyrox-impl/src/renderer/occlusion/mod.rs b/fyrox-impl/src/renderer/occlusion/mod.rs index a73aabc4f..58e6622c5 100644 --- a/fyrox-impl/src/renderer/occlusion/mod.rs +++ b/fyrox-impl/src/renderer/occlusion/mod.rs @@ -114,7 +114,7 @@ impl TileBuffer { fn inflated_world_aabb(graph: &Graph, object: Handle) -> Option { let mut aabb = graph - .try_get(object) + .try_get_node(object) .map(|node_ref| node_ref.world_bounding_box())?; aabb.inflate(Vector3::repeat(0.01)); Some(aabb) @@ -228,7 +228,7 @@ impl OcclusionTester { let mut lines = Vec::new(); for (object_index, object) in self.objects_to_test.iter().enumerate() { let object_index = object_index as u32; - let Some(node_ref) = graph.try_get(*object) else { + let Some(node_ref) = graph.try_get_node(*object) else { continue; }; diff --git a/fyrox-impl/src/renderer/visibility.rs b/fyrox-impl/src/renderer/visibility.rs index da1728c9f..f3e7f3e40 100644 --- a/fyrox-impl/src/renderer/visibility.rs +++ b/fyrox-impl/src/renderer/visibility.rs @@ -282,7 +282,7 @@ impl VisibilityCache { /// Updates the cache by removing unused data. pub fn update(&mut self, graph: &Graph) { self.observers.retain(|observer, data| { - let Some(observer_ref) = graph.try_get(*observer) else { + let Some(observer_ref) = graph.try_get_node(*observer) else { return false; }; diff --git a/fyrox-impl/src/resource/gltf/animation.rs b/fyrox-impl/src/resource/gltf/animation.rs index 30ec1370d..eb22e8503 100644 --- a/fyrox-impl/src/resource/gltf/animation.rs +++ b/fyrox-impl/src/resource/gltf/animation.rs @@ -112,7 +112,7 @@ impl ImportedTarget { self.binding.value_binding() } fn value_in_graph(&self, graph: &Graph) -> Option> { - let node: &Node = graph.try_get(self.handle)?; + let node: &Node = graph.try_get_node(self.handle)?; match self.binding { ImportedBinding::Position => { Some(node.local_transform().position().data.as_slice().into()) diff --git a/fyrox-impl/src/resource/gltf/node_names.rs b/fyrox-impl/src/resource/gltf/node_names.rs index bc0b8c4bf..b7fe381a4 100644 --- a/fyrox-impl/src/resource/gltf/node_names.rs +++ b/fyrox-impl/src/resource/gltf/node_names.rs @@ -170,13 +170,13 @@ fn get_ancestor_names<'a>( fn get_ancestor_name(mut handle: Handle, depth: usize, graph: &Graph) -> Option<&str> { for _ in 0..depth { - if let Some(n) = graph.try_get(handle) { + if let Some(n) = graph.try_get_node(handle) { handle = n.parent(); } else { return None; } } - graph.try_get(handle).map(Node::name) + graph.try_get_node(handle).map(Node::name) } fn contains_duplicate_name(names: &[&str]) -> bool { @@ -192,7 +192,7 @@ fn contains_duplicate_name(names: &[&str]) -> bool { fn count_ancestor_depth(mut handle: Handle, list: &[Handle], graph: &Graph) -> usize { let mut count: usize = 0; - while let Some(node) = graph.try_get(handle) { + while let Some(node) = graph.try_get_node(handle) { handle = node.parent(); if list.contains(&handle) { count += 1; diff --git a/fyrox-impl/src/scene/animation/absm.rs b/fyrox-impl/src/scene/animation/absm.rs index a23dac627..0ba4b6ad6 100644 --- a/fyrox-impl/src/scene/animation/absm.rs +++ b/fyrox-impl/src/scene/animation/absm.rs @@ -333,7 +333,7 @@ impl NodeTrait for AnimationBlendingStateMachine { fn validate(&self, scene: &Scene) -> Result<(), String> { if scene .graph - .try_get(*self.animation_player) + .try_get_node(*self.animation_player) .and_then(|n| n.component_ref::()) .is_none() { diff --git a/fyrox-impl/src/scene/animation/mod.rs b/fyrox-impl/src/scene/animation/mod.rs index 6bb7d5446..64c70342e 100644 --- a/fyrox-impl/src/scene/animation/mod.rs +++ b/fyrox-impl/src/scene/animation/mod.rs @@ -119,7 +119,7 @@ impl AnimationPoseExt for AnimationPose { for (node, local_pose) in self.poses() { if node.is_none() { Log::writeln(MessageKind::Error, "Invalid node handle found for animation pose, most likely it means that animation retargeting failed!"); - } else if let Some(node) = graph.try_get_mut(*node) { + } else if let Some(node) = graph.try_get_node_mut(*node) { local_pose.values.apply(node); } } @@ -132,7 +132,7 @@ impl AnimationPoseExt for AnimationPose { for (node, local_pose) in self.poses() { if node.is_none() { Log::writeln(MessageKind::Error, "Invalid node handle found for animation pose, most likely it means that animation retargeting failed!"); - } else if let Some(node_ref) = graph.try_get_mut(*node) { + } else if let Some(node_ref) = graph.try_get_node_mut(*node) { callback(node_ref, *node, local_pose); } } diff --git a/fyrox-impl/src/scene/base.rs b/fyrox-impl/src/scene/base.rs index 962f6722f..0618ee751 100644 --- a/fyrox-impl/src/scene/base.rs +++ b/fyrox-impl/src/scene/base.rs @@ -1124,7 +1124,7 @@ impl Base { if let Some(ancestor_node) = model .get_scene() .graph - .try_get(self.original_handle_in_resource) + .try_get_node(self.original_handle_in_resource) { return if ancestor_node.resource.is_none() { Some(resource.clone()) diff --git a/fyrox-impl/src/scene/collider.rs b/fyrox-impl/src/scene/collider.rs index 7e8c01f43..12fa871a5 100644 --- a/fyrox-impl/src/scene/collider.rs +++ b/fyrox-impl/src/scene/collider.rs @@ -1044,7 +1044,7 @@ impl NodeTrait for Collider { if scene .graph - .try_get(self.parent()) + .try_get_node(self.parent()) .and_then(|p| p.component_ref::()) .is_none() { diff --git a/fyrox-impl/src/scene/dim2/collider.rs b/fyrox-impl/src/scene/dim2/collider.rs index 7f5cc7963..685310c67 100644 --- a/fyrox-impl/src/scene/dim2/collider.rs +++ b/fyrox-impl/src/scene/dim2/collider.rs @@ -703,7 +703,7 @@ impl NodeTrait for Collider { if scene .graph - .try_get(self.parent()) + .try_get_node(self.parent()) .and_then(|p| p.component_ref::()) .is_none() { diff --git a/fyrox-impl/src/scene/dim2/joint.rs b/fyrox-impl/src/scene/dim2/joint.rs index 0871052e0..23a76be3a 100644 --- a/fyrox-impl/src/scene/dim2/joint.rs +++ b/fyrox-impl/src/scene/dim2/joint.rs @@ -594,13 +594,13 @@ impl NodeTrait for Joint { } fn validate(&self, scene: &Scene) -> Result<(), String> { - if scene.graph.typed_ref(self.body1()).is_none() { + if scene.graph.try_get(self.body1()).is_none() { return Err("2D Joint has invalid or unassigned handle to a \ first body, the joint will not operate!" .to_string()); } - if scene.graph.typed_ref(self.body2()).is_none() { + if scene.graph.try_get(self.body2()).is_none() { return Err("2D Joint has invalid or unassigned handle to a \ second body, the joint will not operate!" .to_string()); diff --git a/fyrox-impl/src/scene/dim2/physics.rs b/fyrox-impl/src/scene/dim2/physics.rs index 71ff6732a..00c5a9dd6 100644 --- a/fyrox-impl/src/scene/dim2/physics.rs +++ b/fyrox-impl/src/scene/dim2/physics.rs @@ -847,12 +847,12 @@ impl PhysicsWorld { }), exclude_collider: filter .exclude_collider - .and_then(|h| graph.try_get(h)) + .and_then(|h| graph.try_get_node(h)) .and_then(|n| n.component_ref::()) .map(|c| c.native.get()), exclude_rigid_body: filter .exclude_collider - .and_then(|h| graph.try_get(h)) + .and_then(|h| graph.try_get_node(h)) .and_then(|n| n.component_ref::()) .map(|c| c.native.get()), predicate: Some(&predicate), @@ -1242,12 +1242,12 @@ impl PhysicsWorld { if let Some(native) = self.joints.set.get_mut(joint.native.get(), false) { joint.body1.try_sync_model(|v| { - if let Some(rigid_body_node) = nodes.typed_ref(v) { + if let Some(rigid_body_node) = nodes.try_get(v) { native.body1 = rigid_body_node.native.get(); } }); joint.body2.try_sync_model(|v| { - if let Some(rigid_body_node) = nodes.typed_ref(v) { + if let Some(rigid_body_node) = nodes.try_get(v) { native.body2 = rigid_body_node.native.get(); } }); @@ -1295,10 +1295,9 @@ impl PhysicsWorld { }); let mut local_frames = joint.local_frames.borrow_mut(); if local_frames.is_none() { - if let (Some(body1), Some(body2)) = ( - nodes.typed_ref(joint.body1()), - nodes.typed_ref(joint.body2()), - ) { + if let (Some(body1), Some(body2)) = + (nodes.try_get(joint.body1()), nodes.try_get(joint.body2())) + { let (local_frame1, local_frame2) = calculate_local_frames(joint, body1, body2); native.data = convert_joint_params((*joint.params).clone(), local_frame1, local_frame2); @@ -1312,7 +1311,7 @@ impl PhysicsWorld { // A native joint can be created iff both rigid bodies are correctly assigned. if let (Some(body1), Some(body2)) = - (nodes.typed_ref(body1_handle), nodes.typed_ref(body2_handle)) + (nodes.try_get(body1_handle), nodes.try_get(body2_handle)) { // Calculate local frames first (if needed). let mut local_frames = joint.local_frames.borrow_mut(); diff --git a/fyrox-impl/src/scene/graph/mod.rs b/fyrox-impl/src/scene/graph/mod.rs index 6c9a2e03a..cdb2ec565 100644 --- a/fyrox-impl/src/scene/graph/mod.rs +++ b/fyrox-impl/src/scene/graph/mod.rs @@ -483,12 +483,6 @@ impl Graph { self.root } - /// Tries to mutably borrow a node, returns Some(node) if the handle is valid, None - otherwise. - #[inline] - pub fn try_get_mut(&mut self, handle: Handle) -> Option<&mut Node> { - self.pool.try_borrow_mut(handle) - } - /// Begins multi-borrow that allows you borrow to as many shared references to the graph /// nodes as you need and only one mutable reference to a node. See /// [`MultiBorrowContext::try_get`] for more info. @@ -873,7 +867,7 @@ impl Graph { where F: FnMut(Handle, &Node) -> bool, { - graph.try_get(node).and_then(|n| { + graph.try_get_node(node).and_then(|n| { if filter(node, n) { let mut aabb = n.local_bounding_box(); if aabb.is_invalid_or_degenerate() { @@ -1083,7 +1077,7 @@ impl Graph { func: &mut impl FnMut(Handle), ) { func(from); - if let Some(node) = graph.try_get(from) { + if let Some(node) = graph.try_get_node(from) { for &child in node.children() { traverse_recursive(graph, child, func) } @@ -1534,7 +1528,7 @@ impl Graph { #[inline] pub fn global_scale(&self, mut node: Handle) -> Vector3 { let mut global_scale = Vector3::repeat(1.0); - while let Some(node_ref) = self.try_get(node) { + while let Some(node_ref) = self.try_get_node(node) { global_scale = global_scale.component_mul(node_ref.local_transform().scale()); node = node_ref.parent; } @@ -1548,7 +1542,7 @@ impl Graph { where T: ScriptTrait, { - self.try_get(node) + self.try_get_node(node) .and_then(|node| node.try_get_script::()) } @@ -1560,7 +1554,7 @@ impl Graph { &self, node: Handle, ) -> Option> { - self.try_get(node).map(|n| n.try_get_scripts()) + self.try_get_node(node).map(|n| n.try_get_scripts()) } /// Tries to borrow a node using the given handle and searches the script buffer for a script @@ -1570,7 +1564,7 @@ impl Graph { where T: ScriptTrait, { - self.try_get_mut(node) + self.try_get_node_mut(node) .and_then(|node| node.try_get_script_mut::()) } @@ -1582,7 +1576,7 @@ impl Graph { &mut self, node: Handle, ) -> Option> { - self.try_get_mut(node).map(|n| n.try_get_scripts_mut()) + self.try_get_node_mut(node).map(|n| n.try_get_scripts_mut()) } /// Tries to borrow a node and find a component of the given type `C` across **all** available @@ -1593,7 +1587,7 @@ impl Graph { where C: Any, { - self.try_get(node) + self.try_get_node(node) .and_then(|node| node.try_get_script_component()) } @@ -1605,7 +1599,7 @@ impl Graph { where C: Any, { - self.try_get_mut(node) + self.try_get_node_mut(node) .and_then(|node| node.try_get_script_component_mut()) } @@ -1634,7 +1628,7 @@ impl> Index> for Graph { #[inline] fn index(&self, index: Handle) -> &Self::Output { - self.typed_ref(index) + self.try_get(index) .expect("The node handle is invalid or the object it points to has different type.") } } @@ -1642,7 +1636,7 @@ impl> Index> for Graph { impl> IndexMut> for Graph { #[inline] fn index_mut(&mut self, index: Handle) -> &mut Self::Output { - self.typed_mut(index) + self.try_get_mut(index) .expect("The node handle is invalid or the object it points to has different type.") } } @@ -1808,12 +1802,12 @@ impl BaseSceneGraph for Graph { } #[inline] - fn try_get(&self, handle: Handle) -> Option<&Self::Node> { + fn try_get_node(&self, handle: Handle) -> Option<&Self::Node> { self.pool.try_borrow(handle) } #[inline] - fn try_get_mut(&mut self, handle: Handle) -> Option<&mut Self::Node> { + fn try_get_node_mut(&mut self, handle: Handle) -> Option<&mut Self::Node> { self.pool.try_borrow_mut(handle) } @@ -1847,12 +1841,12 @@ impl SceneGraph for Graph { self.pool.iter_mut() } - fn typed_ref>(&self, handle: Handle) -> Option<&U> { - self.pool.typed_ref(handle) + fn try_get>(&self, handle: Handle) -> Option<&U> { + self.pool.try_get(handle) } - fn typed_mut>(&mut self, handle: Handle) -> Option<&mut U> { - self.pool.typed_mut(handle) + fn try_get_mut>(&mut self, handle: Handle) -> Option<&mut U> { + self.pool.try_get_mut(handle) } } @@ -2351,7 +2345,7 @@ mod test { assert!(graph[c].global_visibility()); assert!(graph[d].global_visibility()); - assert!(!graph.pool.typed_ref(a).unwrap().is_globally_enabled()); + assert!(!graph.pool.try_get(a).unwrap().is_globally_enabled()); assert!(!graph[b].is_globally_enabled()); assert!(!graph[c].is_globally_enabled()); assert!(!graph[d].is_globally_enabled()); @@ -2363,21 +2357,18 @@ mod test { let pivot = PivotBuilder::new(BaseBuilder::new()).build(&mut graph); let rigid_body = RigidBodyBuilder::new(BaseBuilder::new()).build(&mut graph); - assert!(graph.pool.typed_ref(pivot).is_some()); - assert!(graph.pool.typed_ref(pivot.transmute::()).is_some()); - assert!(graph - .pool - .typed_ref(pivot.transmute::()) - .is_none()); + assert!(graph.pool.try_get(pivot).is_some()); + assert!(graph.pool.try_get(pivot.transmute::()).is_some()); + assert!(graph.pool.try_get(pivot.transmute::()).is_none()); - assert!(graph.pool.typed_ref(rigid_body).is_some()); + assert!(graph.pool.try_get(rigid_body).is_some()); assert!(graph .pool - .typed_ref(rigid_body.transmute::()) + .try_get(rigid_body.transmute::()) .is_some()); assert!(graph .pool - .typed_ref(rigid_body.transmute::()) + .try_get(rigid_body.transmute::()) .is_none()); } } diff --git a/fyrox-impl/src/scene/graph/physics.rs b/fyrox-impl/src/scene/graph/physics.rs index 959da53c9..17df65fc5 100644 --- a/fyrox-impl/src/scene/graph/physics.rs +++ b/fyrox-impl/src/scene/graph/physics.rs @@ -1331,12 +1331,12 @@ impl PhysicsWorld { }), exclude_collider: filter .exclude_collider - .and_then(|h| graph.try_get(h)) + .and_then(|h| graph.try_get_node(h)) .and_then(|n| n.component_ref::()) .map(|c| c.native.get()), exclude_rigid_body: filter .exclude_collider - .and_then(|h| graph.try_get(h)) + .and_then(|h| graph.try_get_node(h)) .and_then(|n| n.component_ref::()) .map(|c| c.native.get()), predicate: Some(&predicate), @@ -1802,12 +1802,12 @@ impl PhysicsWorld { if let Some(native) = self.joints.set.get_mut(joint.native.get(), false) { joint.body1.try_sync_model(|v| { - if let Some(rigid_body_node) = nodes.typed_ref(v) { + if let Some(rigid_body_node) = nodes.try_get(v) { native.body1 = rigid_body_node.native.get(); } }); joint.body2.try_sync_model(|v| { - if let Some(rigid_body_node) = nodes.typed_ref(v) { + if let Some(rigid_body_node) = nodes.try_get(v) { native.body2 = rigid_body_node.native.get(); } }); @@ -1859,10 +1859,9 @@ impl PhysicsWorld { let mut local_frames = joint.local_frames.borrow_mut(); if local_frames.is_none() { - if let (Some(body1), Some(body2)) = ( - nodes.typed_ref(joint.body1()), - nodes.typed_ref(joint.body2()), - ) { + if let (Some(body1), Some(body2)) = + (nodes.try_get(joint.body1()), nodes.try_get(joint.body2())) + { let (local_frame1, local_frame2) = calculate_local_frames(joint, body1, body2); native.data = convert_joint_params((*joint.params).clone(), local_frame1, local_frame2); @@ -1878,10 +1877,10 @@ impl PhysicsWorld { // native bodies exists. if let (Some(body1), Some(body2)) = ( nodes - .typed_ref(body1_handle) + .try_get(body1_handle) .filter(|b| self.bodies.get(b.native.get()).is_some()), nodes - .typed_ref(body2_handle) + .try_get(body2_handle) .filter(|b| self.bodies.get(b.native.get()).is_some()), ) { // Calculate local frames first (if needed). diff --git a/fyrox-impl/src/scene/joint.rs b/fyrox-impl/src/scene/joint.rs index 74b254136..dff99c23d 100644 --- a/fyrox-impl/src/scene/joint.rs +++ b/fyrox-impl/src/scene/joint.rs @@ -679,13 +679,13 @@ impl NodeTrait for Joint { } fn validate(&self, scene: &Scene) -> Result<(), String> { - if scene.graph.typed_ref(self.body1()).is_none() { + if scene.graph.try_get(self.body1()).is_none() { return Err("3D Joint has invalid or unassigned handle to a \ first body, the joint will not operate!" .to_string()); } - if scene.graph.typed_ref(self.body2()).is_none() { + if scene.graph.try_get(self.body2()).is_none() { return Err("3D Joint has invalid or unassigned handle to a \ second body, the joint will not operate!" .to_string()); diff --git a/fyrox-impl/src/scene/mesh/mod.rs b/fyrox-impl/src/scene/mesh/mod.rs index b95298331..fb2ec5146 100644 --- a/fyrox-impl/src/scene/mesh/mod.rs +++ b/fyrox-impl/src/scene/mesh/mod.rs @@ -775,7 +775,9 @@ impl NodeTrait for Mesh { .bones .iter() .map(|bone_handle| { - if let Some(bone_node) = ctx.graph.try_get(*bone_handle) { + if let Some(bone_node) = + ctx.graph.try_get_node(*bone_handle) + { bone_node.global_transform() * bone_node.inv_bind_pose_transform() } else { diff --git a/fyrox-impl/src/script/mod.rs b/fyrox-impl/src/script/mod.rs index 5acfe8390..91684ebad 100644 --- a/fyrox-impl/src/script/mod.rs +++ b/fyrox-impl/src/script/mod.rs @@ -50,7 +50,7 @@ use std::{ use crate::engine::input::InputState; pub use fyrox_core_derive::ScriptMessagePayload; - +use fyrox_graph::BaseSceneGraph; pub mod constructor; pub(crate) trait UniversalScriptContext { @@ -424,7 +424,7 @@ pub struct ScriptContext<'a, 'b, 'c> { impl UniversalScriptContext for ScriptContext<'_, '_, '_> { fn node(&mut self) -> Option<&mut Node> { - self.scene.graph.try_get_mut(self.handle) + self.scene.graph.try_get_node_mut(self.handle) } fn destroy_script_deferred(&self, script: Script, index: usize) { @@ -508,7 +508,7 @@ pub struct ScriptMessageContext<'a, 'b, 'c> { impl UniversalScriptContext for ScriptMessageContext<'_, '_, '_> { fn node(&mut self) -> Option<&mut Node> { - self.scene.graph.try_get_mut(self.handle) + self.scene.graph.try_get_node_mut(self.handle) } fn destroy_script_deferred(&self, script: Script, index: usize) { @@ -583,7 +583,7 @@ pub struct ScriptDeinitContext<'a, 'b, 'c> { impl UniversalScriptContext for ScriptDeinitContext<'_, '_, '_> { fn node(&mut self) -> Option<&mut Node> { - self.scene.graph.try_get_mut(self.node_handle) + self.scene.graph.try_get_node_mut(self.node_handle) } fn destroy_script_deferred(&self, script: Script, index: usize) { diff --git a/fyrox-ui/src/animation.rs b/fyrox-ui/src/animation.rs index a52d83073..2338a7f21 100644 --- a/fyrox-ui/src/animation.rs +++ b/fyrox-ui/src/animation.rs @@ -38,7 +38,6 @@ use crate::{ BuildContext, Control, UiNode, UserInterface, }; use fyrox_graph::constructor::{ConstructorProvider, GraphNodeConstructor}; -use fyrox_graph::BaseSceneGraph; use std::ops::{Deref, DerefMut}; #[derive(Debug, Clone, PartialEq)] @@ -116,7 +115,7 @@ impl AnimationPoseExt for AnimationPose { for (node, local_pose) in self.poses() { if node.is_none() { Log::writeln(MessageKind::Error, "Invalid node handle found for animation pose, most likely it means that animation retargeting failed!"); - } else if let Some(node) = ui.try_get_mut(*node) { + } else if let Some(node) = ui.try_get_node_mut(*node) { node.invalidate_layout(); local_pose.values.apply(node); diff --git a/fyrox-ui/src/build.rs b/fyrox-ui/src/build.rs index 885dc93b9..0ba285a9d 100644 --- a/fyrox-ui/src/build.rs +++ b/fyrox-ui/src/build.rs @@ -146,7 +146,7 @@ impl BuildContext<'_> { /// Tries to fetch the node by its handle. Returns `None` if the handle is invalid. pub fn try_get_node(&self, node: Handle) -> Option<&UiNode> { - self.ui.try_get(node) + self.ui.try_get_node(node) } /// Tries to fetch the node by its handle. Returns `None` if the handle is invalid. diff --git a/fyrox-ui/src/color/gradient.rs b/fyrox-ui/src/color/gradient.rs index a520cef3d..c5b534f76 100644 --- a/fyrox-ui/src/color/gradient.rs +++ b/fyrox-ui/src/color/gradient.rs @@ -285,7 +285,7 @@ impl Control for ColorGradientEditor { gradient, )); } else if message.destination() == self.remove_point - && ui.try_get(self.context_menu_target.get()).is_some() + && ui.try_get_node(self.context_menu_target.get()).is_some() { let gradient = self.fetch_gradient(self.context_menu_target.get(), ui); @@ -333,7 +333,7 @@ impl Control for ColorGradientEditor { if message.destination() == self.point_context_menu.handle() { if let Some(point) = ui - .try_get(self.context_menu_target.get()) + .try_get_node(self.context_menu_target.get()) .and_then(|n| n.query_component::()) { let mut msg = ColorFieldMessage::color( diff --git a/fyrox-ui/src/dock/config.rs b/fyrox-ui/src/dock/config.rs index bd2bf5685..a52958d56 100644 --- a/fyrox-ui/src/dock/config.rs +++ b/fyrox-ui/src/dock/config.rs @@ -76,7 +76,7 @@ impl TileContentDescriptor { match tile_content { TileContent::Empty => Self::Empty, TileContent::Window(window) => Self::Window( - ui.try_get(*window) + ui.try_get_node(*window) .map(|w| w.name.clone()) .unwrap_or_default(), ), @@ -86,7 +86,7 @@ impl TileContentDescriptor { names: windows .iter() .map(|window| { - ui.try_get(*window) + ui.try_get_node(*window) .map(|w| w.name.clone()) .unwrap_or_default() }) @@ -151,7 +151,7 @@ fn find_window( if window_handle.is_none() { for other_window_handle in windows.iter().cloned() { - if let Some(window_node) = ui.try_get(other_window_handle) { + if let Some(window_node) = ui.try_get_node(other_window_handle) { if &window_node.name == window_name { return other_window_handle; } @@ -163,7 +163,7 @@ fn find_window( impl TileDescriptor { pub(super) fn from_tile_handle(handle: Handle, ui: &UserInterface) -> Self { - ui.try_get(handle) + ui.try_get_node(handle) .and_then(|t| t.query_component::()) .map(|t| Self { content: TileContentDescriptor::from_tile(&t.content, ui), diff --git a/fyrox-ui/src/dock/mod.rs b/fyrox-ui/src/dock/mod.rs index 697f539fb..f3c239064 100644 --- a/fyrox-ui/src/dock/mod.rs +++ b/fyrox-ui/src/dock/mod.rs @@ -245,7 +245,7 @@ impl DockingManager { .borrow() .iter() .filter_map(|h| { - ui.try_get(*h).map(|w| FloatingWindowDescriptor { + ui.try_get_node(*h).map(|w| FloatingWindowDescriptor { name: w.name.clone(), position: w.actual_local_position(), size: w.actual_local_size(), @@ -270,7 +270,7 @@ impl DockingManager { let mut stack = vec![root_tile_handle]; while let Some(tile_handle) = stack.pop() { if let Some(tile) = ui - .try_get(tile_handle) + .try_get_node(tile_handle) .and_then(|n| n.query_component::()) { match tile.content { diff --git a/fyrox-ui/src/file_browser/menu.rs b/fyrox-ui/src/file_browser/menu.rs index 2e5457e73..f5eece6fb 100644 --- a/fyrox-ui/src/file_browser/menu.rs +++ b/fyrox-ui/src/file_browser/menu.rs @@ -362,7 +362,7 @@ impl ItemContextMenu { } fn item_path(&self, ui: &UserInterface) -> Option { - ui.try_get(self.base_menu.popup.placement.target()) + ui.try_get_node(self.base_menu.popup.placement.target()) .and_then(|n| n.user_data_cloned::()) } } diff --git a/fyrox-ui/src/file_browser/mod.rs b/fyrox-ui/src/file_browser/mod.rs index 4d0912ec0..af72310dd 100644 --- a/fyrox-ui/src/file_browser/mod.rs +++ b/fyrox-ui/src/file_browser/mod.rs @@ -500,7 +500,7 @@ impl Control for FileBrowser { && message.direction() == MessageDirection::FromWidget { if let Some(&first_selected) = selection.first() { - if let Some(first_selected_ref) = ui.try_get(first_selected) { + if let Some(first_selected_ref) = ui.try_get_node(first_selected) { let mut path = first_selected_ref .user_data_cloned::() .unwrap() diff --git a/fyrox-ui/src/grid.rs b/fyrox-ui/src/grid.rs index 631c3203f..3b15dadcc 100644 --- a/fyrox-ui/src/grid.rs +++ b/fyrox-ui/src/grid.rs @@ -446,7 +446,7 @@ impl Grid { .iter() .copied() .filter(|&c| { - let Some(child_ref) = ui.try_get(c) else { + let Some(child_ref) = ui.try_get_node(c) else { return false; }; child_ref.row() == row_index && child_ref.column() == column_index @@ -470,7 +470,7 @@ impl Grid { } } for handle in self.children() { - let Some(node) = ui.try_get(*handle) else { + let Some(node) = ui.try_get_node(*handle) else { continue; }; let Some(row) = rows.get_mut(node.row()) else { @@ -507,7 +507,7 @@ impl Grid { measure_width: bool, measure_height: bool, ) { - let Some(node) = ui.try_get(child) else { + let Some(node) = ui.try_get_node(child) else { return; }; let mut rows = self.rows.borrow_mut(); diff --git a/fyrox-ui/src/inspector/mod.rs b/fyrox-ui/src/inspector/mod.rs index 0986d7adf..2c93beb6b 100644 --- a/fyrox-ui/src/inspector/mod.rs +++ b/fyrox-ui/src/inspector/mod.rs @@ -673,7 +673,7 @@ impl Inspector { ) -> Option<&ContextEntry> { let mut parent_handle = from; - while let Some(parent) = ui.try_get(parent_handle) { + while let Some(parent) = ui.try_get_node(parent_handle) { for entry in self.context.entries.iter() { if entry.property_container == parent_handle { return Some(entry); diff --git a/fyrox-ui/src/lib.rs b/fyrox-ui/src/lib.rs index a13005a29..c50d6d740 100644 --- a/fyrox-ui/src/lib.rs +++ b/fyrox-ui/src/lib.rs @@ -1319,7 +1319,7 @@ impl UserInterface { func: &mut impl FnMut(Handle), ) { func(from); - if let Some(node) = graph.try_get(from) { + if let Some(node) = graph.try_get_node(from) { for &child in node.children() { traverse_recursive(graph, child, func) } @@ -1378,10 +1378,10 @@ impl UserInterface { self.update_visual_transform(root); // Recalculate clip bounds, because they depend on the visual transform. - if let Some(root_ref) = self.try_get(root) { + if let Some(root_ref) = self.try_get_node(root) { self.calculate_clip_bounds( root, - self.try_get(root_ref.parent()) + self.try_get_node(root_ref.parent()) .map(|c| c.clip_bounds()) .unwrap_or_else(|| { Rect::new(0.0, 0.0, self.screen_size.x, self.screen_size.y) @@ -1447,7 +1447,7 @@ impl UserInterface { self.style = style; fn notify_depth_first(node: Handle, ui: &UserInterface) { - if let Some(node_ref) = ui.try_get(node) { + if let Some(node_ref) = ui.try_get_node(node) { for child in node_ref.children.iter() { notify_depth_first(*child, ui); } @@ -2121,8 +2121,8 @@ impl UserInterface { margin, } => { if let (Some(node), Some(relative_node)) = ( - self.try_get(message.destination()), - self.try_get(*relative_to), + self.try_get_node(message.destination()), + self.try_get_node(*relative_to), ) { // Calculate new anchor point in screen coordinate system. let relative_node_screen_size = relative_node.screen_bounds().size; @@ -2178,7 +2178,7 @@ impl UserInterface { } } - if let Some(parent) = self.try_get(node.parent()) { + if let Some(parent) = self.try_get_node(node.parent()) { // Transform screen anchor point into the local coordinate system // of the parent node. let local_anchor_point = @@ -2643,7 +2643,7 @@ impl UserInterface { state, text, } => { - if let Some(keyboard_focus_node) = self.try_get(self.keyboard_focus_node) { + if let Some(keyboard_focus_node) = self.try_get_node(self.keyboard_focus_node) { if keyboard_focus_node.is_globally_visible() { match state { ButtonState::Pressed => { @@ -3293,12 +3293,12 @@ impl BaseSceneGraph for UserInterface { } #[inline] - fn try_get(&self, handle: Handle) -> Option<&Self::Node> { + fn try_get_node(&self, handle: Handle) -> Option<&Self::Node> { self.nodes.try_borrow(handle) } #[inline] - fn try_get_mut(&mut self, handle: Handle) -> Option<&mut Self::Node> { + fn try_get_node_mut(&mut self, handle: Handle) -> Option<&mut Self::Node> { self.nodes.try_borrow_mut(handle) } @@ -3416,12 +3416,12 @@ impl SceneGraph for UserInterface { self.nodes.iter_mut() } - fn typed_ref>(&self, handle: Handle) -> Option<&U> { - self.nodes.typed_ref(handle) + fn try_get>(&self, handle: Handle) -> Option<&U> { + self.nodes.try_get(handle) } - fn typed_mut>(&mut self, handle: Handle) -> Option<&mut U> { - self.nodes.typed_mut(handle) + fn try_get_mut>(&mut self, handle: Handle) -> Option<&mut U> { + self.nodes.try_get_mut(handle) } } diff --git a/fyrox-ui/src/log.rs b/fyrox-ui/src/log.rs index dce5ac5dd..bf9055c3f 100644 --- a/fyrox-ui/src/log.rs +++ b/fyrox-ui/src/log.rs @@ -85,7 +85,7 @@ impl ContextMenu { } else if let Some(MenuItemMessage::Click) = message.data() { if message.destination() == self.copy { if let Some(field) = ui - .try_get(self.placement_target) + .try_get_node(self.placement_target) .and_then(|n| n.query_component::()) { let text = field.text(); diff --git a/fyrox-ui/src/menu.rs b/fyrox-ui/src/menu.rs index 4259e6fca..42509e461 100644 --- a/fyrox-ui/src/menu.rs +++ b/fyrox-ui/src/menu.rs @@ -1314,7 +1314,7 @@ impl Control for ContextMenu { if let Some(WidgetMessage::KeyDown(key_code)) = message.data() { if !message.handled() { - if let Some(parent_menu_item) = ui.try_get(self.parent_menu_item) { + if let Some(parent_menu_item) = ui.try_get_node(self.parent_menu_item) { if keyboard_navigation( ui, *key_code, diff --git a/fyrox-ui/src/popup.rs b/fyrox-ui/src/popup.rs index 07d04036b..a682a4fb3 100644 --- a/fyrox-ui/src/popup.rs +++ b/fyrox-ui/src/popup.rs @@ -358,13 +358,13 @@ fn adjust_placement_position( impl Popup { fn left_top_placement(&self, ui: &UserInterface, target: Handle) -> Vector2 { - ui.try_get(target) + ui.try_get_node(target) .map(|n| n.screen_position()) .unwrap_or_default() } fn right_top_placement(&self, ui: &UserInterface, target: Handle) -> Vector2 { - ui.try_get(target) + ui.try_get_node(target) .map(|n| n.screen_position() + Vector2::new(n.actual_global_size().x, 0.0)) .unwrap_or_else(|| { Vector2::new(ui.screen_size().x - self.widget.actual_global_size().x, 0.0) @@ -372,13 +372,13 @@ impl Popup { } fn center_placement(&self, ui: &UserInterface, target: Handle) -> Vector2 { - ui.try_get(target) + ui.try_get_node(target) .map(|n| n.screen_position() + n.actual_global_size().scale(0.5)) .unwrap_or_else(|| (ui.screen_size - self.widget.actual_global_size()).scale(0.5)) } fn left_bottom_placement(&self, ui: &UserInterface, target: Handle) -> Vector2 { - ui.try_get(target) + ui.try_get_node(target) .map(|n| n.screen_position() + Vector2::new(0.0, n.actual_global_size().y)) .unwrap_or_else(|| { Vector2::new(0.0, ui.screen_size().y - self.widget.actual_global_size().y) @@ -386,7 +386,7 @@ impl Popup { } fn right_bottom_placement(&self, ui: &UserInterface, target: Handle) -> Vector2 { - ui.try_get(target) + ui.try_get_node(target) .map(|n| n.screen_position() + n.actual_global_size()) .unwrap_or_else(|| ui.screen_size - self.widget.actual_global_size()) } diff --git a/fyrox-ui/src/scroll_panel.rs b/fyrox-ui/src/scroll_panel.rs index f800c1e39..0a58c48b5 100644 --- a/fyrox-ui/src/scroll_panel.rs +++ b/fyrox-ui/src/scroll_panel.rs @@ -205,7 +205,7 @@ impl ScrollPanel { children_size } fn bring_into_view(&self, ui: &UserInterface, handle: Handle) { - let Some(node_to_focus_ref) = ui.try_get(handle) else { + let Some(node_to_focus_ref) = ui.try_get_node(handle) else { return; }; let mut parent = handle; diff --git a/fyrox-ui/src/tree.rs b/fyrox-ui/src/tree.rs index f350f95e8..8d05f42f1 100644 --- a/fyrox-ui/src/tree.rs +++ b/fyrox-ui/src/tree.rs @@ -1042,7 +1042,7 @@ impl Control for TreeRoot { KeyCode::ArrowLeft => { if let Some(selection) = self.selected.first() { if let Some(item) = ui - .try_get(*selection) + .try_get_node(*selection) .and_then(|n| n.component_ref::()) { if item.is_expanded { @@ -1109,7 +1109,7 @@ impl TreeRoot { fn move_selection(&self, ui: &UserInterface, direction: Direction, expand: bool) { if let Some(selected_item) = self.selected.first() { let Some(item) = ui - .try_get(*selected_item) + .try_get_node(*selected_item) .and_then(|n| n.component_ref::()) else { return; diff --git a/template-core/src/lib.rs b/template-core/src/lib.rs index e259df550..ac25b9429 100644 --- a/template-core/src/lib.rs +++ b/template-core/src/lib.rs @@ -156,6 +156,8 @@ dylib-engine = ["fyrox/dylib"] write_file( base_path.join("game/src/lib.rs"), r#"//! Game project. +#[allow(unused_imports)] +use fyrox::graph::prelude::*; use fyrox::{ core::pool::Handle, core::visitor::prelude::*, core::reflect::prelude::*, event::Event, @@ -507,7 +509,7 @@ version = "0.1.0" edition = "2021" [package.metadata.android] -# This folder is used as a temporary storage for assets. Project exporter will clone everything +# This folder is used as a temporary storage for assets. Project exporter will clone everything # from data folder to this folder and cargo-apk will create the apk with these assets. assets = "assets" strip = "strip" @@ -666,6 +668,8 @@ pub fn init_script(root_path: &Path, raw_name: &str) -> Result<(), String> { file_name, format!( r#" +#[allow(unused_imports)] +use fyrox::graph::prelude::*; use fyrox::{{ core::{{visitor::prelude::*, reflect::prelude::*, type_traits::prelude::*}}, event::Event, script::{{ScriptContext, ScriptDeinitContext, ScriptTrait}},