feat: working version with scopes.
This commit is contained in:
+19
-19
@@ -7,19 +7,30 @@ namespace GodotHostTest.Game;
|
||||
|
||||
public partial class Target : Node2D, ITarget
|
||||
{
|
||||
[Export] public double TimeOutDurationInSeconds;
|
||||
[Export] public required Timer TimeOutTimer;
|
||||
[Export] public required Sprite2D Image;
|
||||
[Export] public required Area2D CollisionArea;
|
||||
|
||||
private readonly Subject<Unit> _timedOut = new();
|
||||
private readonly Subject<Unit> _hit = new();
|
||||
|
||||
[Inject] private readonly ITargetCollector _targetCollector = null!;
|
||||
[Inject] private readonly IValueGetter<ITargetCollector> _targetCollector = null!;
|
||||
|
||||
private readonly Subject<Unit> _timedOut = new();
|
||||
[Export] public required Area2D CollisionArea;
|
||||
[Export] public required Sprite2D Image;
|
||||
[Export] public double TimeOutDurationInSeconds;
|
||||
[Export] public required Timer TimeOutTimer;
|
||||
|
||||
public Observable<Unit> TimedOut => _timedOut.AsObservable();
|
||||
|
||||
public Observable<Unit> Hit => _hit.AsObservable();
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
Image.Visible = true;
|
||||
CollisionArea.Monitoring = true;
|
||||
TimeOutTimer.Start(TimeOutDurationInSeconds);
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_targetCollector.NewTarget(this);
|
||||
_targetCollector.Value.NewTarget(this);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
@@ -28,10 +39,6 @@ public partial class Target : Node2D, ITarget
|
||||
_hit.Dispose();
|
||||
}
|
||||
|
||||
public Observable<Unit> TimedOut => _timedOut.AsObservable();
|
||||
|
||||
public Observable<Unit> Hit => _hit.AsObservable();
|
||||
|
||||
// todo: hook to collision
|
||||
private void OnHit()
|
||||
{
|
||||
@@ -40,13 +47,6 @@ public partial class Target : Node2D, ITarget
|
||||
_hit.OnNext(Unit.Default);
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
Image.Visible = true;
|
||||
CollisionArea.Monitoring = true;
|
||||
TimeOutTimer.Start(TimeOutDurationInSeconds);
|
||||
}
|
||||
|
||||
private void Disable()
|
||||
{
|
||||
Image.Visible = false;
|
||||
|
||||
Reference in New Issue
Block a user