diff --git a/Game/Level/LevelServices.cs.uid b/Game/Level/LevelServices.cs.uid new file mode 100644 index 0000000..29e5707 --- /dev/null +++ b/Game/Level/LevelServices.cs.uid @@ -0,0 +1 @@ +uid://c4pr1lc7ikb4h diff --git a/Game/Root/Root.cs b/Game/Root/Root.cs index 6c100d2..8da9031 100644 --- a/Game/Root/Root.cs +++ b/Game/Root/Root.cs @@ -1,7 +1,9 @@ +using System; using Godot; using GodotHostTest.AetherBind; using GodotHostTest.Interfaces; using OwofGames.AetherBind; +using OwofGames.GodotLume; namespace GodotHostTest.Game.Root; @@ -17,6 +19,9 @@ public partial class Root : Node2D { var levelData = _levelDataProvider.GetLevelData(_currentLevel.LevelNumber); AddChild(_sceneInstantiator.Instantiate(_levelScene, - (IValueSetter levelSetter) => { levelSetter.Set(levelData); })); + OnInstantiate(levelValueSetter => levelValueSetter.Set(levelData)))); } + + [ServiceMethod] + private partial Action OnInstantiate(Action> a); } \ No newline at end of file diff --git a/addons/AetherBind/ISceneInstantiator.cs b/addons/AetherBind/ISceneInstantiator.cs index f016112..de0a4dc 100644 --- a/addons/AetherBind/ISceneInstantiator.cs +++ b/addons/AetherBind/ISceneInstantiator.cs @@ -1,5 +1,6 @@ using System; using Godot; +using OwofGames.GodotLume; namespace GodotHostTest.AetherBind; @@ -9,7 +10,7 @@ public interface ISceneInstantiator /// Instantiate a packed scene, just like , but also looks for a scope between the top level children of the instantiated scene and triggers the dependency injection mechanism when found. /// /// The packed scene to instantiate. - /// An optional callback invoked once the scope has been created, but before instantiating the scene. + /// An optional callback invoked once the scope has been created, but before instantiating the scene, with the provider as argument. /// The created node, with its dependencies satisfied. - Node Instantiate(PackedScene packedScene, Delegate? onScopeCreated = null); + Node Instantiate(PackedScene packedScene, Action? onScopeCreated = null); } \ No newline at end of file diff --git a/addons/AetherBind/SceneInstantiator.cs b/addons/AetherBind/SceneInstantiator.cs index 58791e3..46a0af8 100644 --- a/addons/AetherBind/SceneInstantiator.cs +++ b/addons/AetherBind/SceneInstantiator.cs @@ -9,7 +9,7 @@ namespace GodotHostTest.AetherBind; internal class SceneInstantiator(IProvider provider) : ISceneInstantiator { /// - public Node Instantiate(PackedScene packedScene, Delegate? onScopeCreated = null) + public Node Instantiate(PackedScene packedScene, Action? onScopeCreated = null) { var node = packedScene.Instantiate(); var scope = node.GetChildren().OfType().SingleOrDefault(); diff --git a/addons/AetherBind/SceneInstantiatorExtensions.cs b/addons/AetherBind/SceneInstantiatorExtensions.cs index edd1d0f..4bf4456 100644 --- a/addons/AetherBind/SceneInstantiatorExtensions.cs +++ b/addons/AetherBind/SceneInstantiatorExtensions.cs @@ -1,5 +1,6 @@ using System; using Godot; +using OwofGames.GodotLume; namespace GodotHostTest.AetherBind; @@ -13,11 +14,11 @@ public static class SceneInstantiatorExtensions /// The packed scene to instantiate. /// /// An optional callback invoked once the scope has been created, but before instantiating the - /// scene. + /// scene, with the provider as argument. /// /// The created node, with its dependencies satisfied. private static T Instantiate(this ISceneInstantiator sceneInstantiator, PackedScene packedScene, - Delegate? onScopeCreated = null) where T : Node + Action? onScopeCreated = null) where T : Node { return (T)sceneInstantiator.Instantiate(packedScene, onScopeCreated); } diff --git a/addons/AetherBind/ServiceSource.cs b/addons/AetherBind/ServiceSource.cs index 76cb2ae..e0bbc9a 100644 --- a/addons/AetherBind/ServiceSource.cs +++ b/addons/AetherBind/ServiceSource.cs @@ -25,7 +25,6 @@ public partial class ServiceSource : Node var serviceScope = ScopeTypesAndNames.GetType(_serviceScope); provider = provider.GetScopedProvider(serviceScope); // invoke onScopeCreated, if present - // TODO: replace with a source code generation by turning this method private with Action argument, and every invocation site calls the necessary provider.Get<...> to build the argument list if (onScopeCreated != null) { var parameters = onScopeCreated.Method @@ -52,33 +51,6 @@ public partial class ServiceSource : Node { injectable.Inject(provider); } - - // var nodeType = node.GetType(); - // foreach (var field in nodeType - // .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) - // { - // if (field.GetCustomAttribute() == null) continue; - // var fieldType = field.FieldType; - // var service = provider.Get(fieldType); - // field.SetValue(node, service); - // } - // - // foreach (var method in nodeType.GetMethods(BindingFlags.Instance | BindingFlags.Public | - // BindingFlags.NonPublic)) - // { - // if (method.GetCustomAttribute() == null) continue; - // var parameters = method.GetParameters(); - // var values = new object?[parameters.Length]; - // var i = 0; - // foreach (var parameter in parameters) - // { - // var parameterType = parameter.ParameterType; - // var service = provider.Get(parameterType); - // values[i++] = service; - // } - // - // method.Invoke(node, values); - // } } }