feat: new ValueProvider improvements and source generator.
This commit is contained in:
@@ -2,6 +2,7 @@ using Godot;
|
||||
using GodotHostTest.AetherBind;
|
||||
using GodotHostTest.Game.Target;
|
||||
using GodotHostTest.Interfaces;
|
||||
using OwofGames.AetherBind;
|
||||
using OwofGames.GodotLume;
|
||||
using ServiceSource = GodotHostTest.AetherBind.ServiceSource;
|
||||
|
||||
@@ -13,7 +14,14 @@ public partial class LevelServiceSource : ServiceSource
|
||||
|
||||
protected override void OnScopeCreated(IProvider serviceProvider)
|
||||
{
|
||||
serviceProvider.Get<IValueSetter<ITargetCollector>>().Set(_targetSpawner);
|
||||
serviceProvider.Get<IValueSetter<ITargetSpawner>>().Set(_targetSpawner);
|
||||
OnScopeCreatedWithProvider(serviceProvider);
|
||||
}
|
||||
|
||||
[WithProvider]
|
||||
private void OnScopeCreated(IValueSetter<ITargetCollector> targetCollector,
|
||||
IValueSetter<ITargetSpawner> targetSpawner)
|
||||
{
|
||||
targetCollector.Set(_targetSpawner);
|
||||
targetSpawner.Set(_targetSpawner);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using Godot;
|
||||
using GodotHostTest.AetherBind;
|
||||
using GodotHostTest.Helpers;
|
||||
using GodotHostTest.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -8,16 +7,15 @@ using R3;
|
||||
|
||||
namespace GodotHostTest.Game.Projectile;
|
||||
|
||||
[Injected]
|
||||
public partial class Projectile : Node2D
|
||||
{
|
||||
[Inject] private ILogger<Projectile> _logger = null!;
|
||||
[Inject] private IValueGetter<ITargetSpawner> _targetSpawner = null!;
|
||||
[Inject] private ITargetSpawner _targetSpawner = null!;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_targetSpawner.Value.TargetSpawned
|
||||
_targetSpawner.TargetSpawned
|
||||
.Subscribe(_ => _logger.LogInformation("Projectile got informed of target spawning")).AddTo(this);
|
||||
}
|
||||
}
|
||||
+7
-8
@@ -1,13 +1,10 @@
|
||||
using System;
|
||||
using Godot;
|
||||
using GodotHostTest.AetherBind;
|
||||
using GodotHostTest.Interfaces;
|
||||
using OwofGames.AetherBind;
|
||||
using OwofGames.GodotLume;
|
||||
|
||||
namespace GodotHostTest.Game.Root;
|
||||
|
||||
[Injected]
|
||||
public partial class Root : Node2D
|
||||
{
|
||||
[Inject] private ICurrentLevel _currentLevel = null!;
|
||||
@@ -17,11 +14,13 @@ public partial class Root : Node2D
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
var levelData = _levelDataProvider.GetLevelData(_currentLevel.LevelNumber);
|
||||
AddChild(_sceneInstantiator.Instantiate(_levelScene,
|
||||
OnInstantiate(levelValueSetter => levelValueSetter.Set(levelData))));
|
||||
AddChild(_sceneInstantiator.Instantiate(_levelScene, OnInstantiateWithProvider));
|
||||
}
|
||||
|
||||
[ServiceMethod]
|
||||
private partial Action<IProvider> OnInstantiate(Action<IValueSetter<ILevel>> a);
|
||||
[WithProvider]
|
||||
private void OnInstantiate(IValueSetter<ILevel> levelValueSetter)
|
||||
{
|
||||
var levelData = _levelDataProvider.GetLevelData(_currentLevel.LevelNumber);
|
||||
levelValueSetter.Set(levelData);
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -1,5 +1,4 @@
|
||||
using Godot;
|
||||
using GodotHostTest.AetherBind;
|
||||
using GodotHostTest.Helpers;
|
||||
using GodotHostTest.Interfaces;
|
||||
using OwofGames.AetherBind;
|
||||
@@ -7,20 +6,19 @@ using R3;
|
||||
|
||||
namespace GodotHostTest.Game.Score;
|
||||
|
||||
[Injected]
|
||||
public partial class Score : Control, IScore
|
||||
{
|
||||
[Export] private AnimationPlayer _animationPlayer = null!;
|
||||
[Export] private Label _label = null!;
|
||||
|
||||
private int _score;
|
||||
[Inject] private IValueGetter<ITargetSpawner> _targetSpawner = null!;
|
||||
[Inject] private ITargetSpawner _targetSpawner = null!;
|
||||
|
||||
int IScore.Score => _score;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_targetSpawner.Value.TargetSpawned.Subscribe(OnTargetSpawned).AddTo(this);
|
||||
_targetSpawner.TargetSpawned.Subscribe(OnTargetSpawned).AddTo(this);
|
||||
base._Ready();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
using Godot;
|
||||
using GodotHostTest.AetherBind;
|
||||
using GodotHostTest.Interfaces;
|
||||
using OwofGames.AetherBind;
|
||||
using R3;
|
||||
|
||||
namespace GodotHostTest.Game.Target;
|
||||
|
||||
[Injected]
|
||||
public partial class Target : Node2D, ITarget
|
||||
{
|
||||
private readonly Subject<Unit> _hit = new();
|
||||
@@ -17,7 +15,7 @@ public partial class Target : Node2D, ITarget
|
||||
[Export] public double TimeOutDurationInSeconds;
|
||||
[Export] public required Timer TimeOutTimer;
|
||||
|
||||
[Inject] private IValueGetter<ITargetCollector> _targetCollector = null!;
|
||||
[Inject] private ITargetCollector _targetCollector = null!;
|
||||
|
||||
public Observable<Unit> TimedOut => _timedOut.AsObservable();
|
||||
|
||||
@@ -32,7 +30,7 @@ public partial class Target : Node2D, ITarget
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_targetCollector.Value.NewTarget(this);
|
||||
_targetCollector.NewTarget(this);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||
using Godot;
|
||||
using GodotHostTest.Helpers;
|
||||
using GodotHostTest.Interfaces;
|
||||
using OwofGames.AetherBind;
|
||||
using R3;
|
||||
|
||||
namespace GodotHostTest.Game.Target;
|
||||
@@ -11,10 +12,10 @@ public partial class TargetSpawner : Node2D, ITargetCollector, ITargetSpawner
|
||||
private readonly List<ITarget> _availableTargets = [];
|
||||
|
||||
private readonly Subject<ITarget> _targetSpawned = new();
|
||||
[Export] public double TimeBetweenSpawns;
|
||||
|
||||
[Export] public required Timer Timer;
|
||||
|
||||
[Inject] private ILevel _level = null!;
|
||||
|
||||
public void NewTarget(ITarget target)
|
||||
{
|
||||
_availableTargets.Add(target);
|
||||
@@ -26,7 +27,7 @@ public partial class TargetSpawner : Node2D, ITargetCollector, ITargetSpawner
|
||||
public override void _Ready()
|
||||
{
|
||||
Spawn();
|
||||
Timer.Start(TimeBetweenSpawns);
|
||||
Timer.Start(_level.TimeBetweenSpawns.TotalSeconds);
|
||||
}
|
||||
|
||||
private void MakeTargetAvailable(ITarget target)
|
||||
|
||||
@@ -4,7 +4,6 @@ using OwofGames.AetherBind;
|
||||
|
||||
namespace GodotHostTest.Game.Turret;
|
||||
|
||||
[Injected]
|
||||
public partial class Turret : Sprite2D
|
||||
{
|
||||
[Export] private PackedScene _projectilePackedScene = null!;
|
||||
|
||||
+1
-2
@@ -74,8 +74,8 @@ _data = {
|
||||
[node name="LevelScope" type="Node" parent="." unique_id=1267156771 node_paths=PackedStringArray("_targetSpawner", "InjectedNodes")]
|
||||
script = ExtResource("1_5saw1")
|
||||
_targetSpawner = NodePath("../Spawner")
|
||||
InjectedNodes = [NodePath("../Target"), NodePath("../Target2"), NodePath("../Target3"), NodePath("../Target4"), NodePath("../Target5"), NodePath("../Target6"), NodePath("../Score"), NodePath("../Turret"), NodePath("../Spawner")]
|
||||
_serviceScope = "GodotHostTest.Game.Level.LevelScope, godot-host-test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
|
||||
InjectedNodes = [NodePath("../Target"), NodePath("../Target2"), NodePath("../Target3"), NodePath("../Target4"), NodePath("../Target5"), NodePath("../Target6"), NodePath("../Score"), NodePath("../Turret")]
|
||||
|
||||
[node name="Target" parent="." unique_id=2101558052 instance=ExtResource("1_y7rhs")]
|
||||
position = Vector2(198, 143)
|
||||
@@ -103,7 +103,6 @@ TimeOutDurationInSeconds = 2.0
|
||||
|
||||
[node name="Spawner" type="Node2D" parent="." unique_id=251404460 node_paths=PackedStringArray("Timer")]
|
||||
script = ExtResource("2_5saw1")
|
||||
TimeBetweenSpawns = 1.5
|
||||
Timer = NodePath("Timer")
|
||||
|
||||
[node name="Timer" type="Timer" parent="Spawner" unique_id=1066078427]
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
[sub_resource type="Resource" id="Resource_bbjqm"]
|
||||
script = ExtResource("1_bkfnq")
|
||||
TimeBetweenSpawns = 2.0
|
||||
TimeBetweenSpawns = 0.5
|
||||
metadata/_custom_type_script = "uid://ywe7vkywrdvk"
|
||||
|
||||
[resource]
|
||||
|
||||
Reference in New Issue
Block a user