chore: cleanup

This commit is contained in:
redglow
2026-07-29 11:05:27 +02:00
parent 2c0a3f47a4
commit 5c4519ed26
20 changed files with 110 additions and 70 deletions
+12 -4
View File
@@ -9,16 +9,24 @@ namespace GodotHostTest.Game.Score;
public partial class Score : Control
{
[Export] private AnimationPlayer _animationPlayer = null!;
[Inject] private ICurrentLevel _currentLevel = null!;
[Export] private Label _label = null!;
[Inject] private IScore _score = null!;
public override void _Ready()
{
_score.Score.Subscribe(UpdateScore).AddTo(this);
_score.Score.Chunk(2, 1).Where(values => values.Length == 2 && values[1] < values[0])
.Subscribe(OnScoreDecreasing).AddTo(this);
// update the score label whenever the score changes
_score.Score
.Subscribe(UpdateScore)
.AddTo(this);
// run an animation whenever the score decreases
_score.Score
.Chunk(2, 1)
.Where(values => values.Length == 2 && values[1] < values[0])
.Subscribe(OnScoreDecreasing)
.AddTo(this);
}
private void OnScoreDecreasing<T>(T _)
+10 -11
View File
@@ -6,24 +6,23 @@ namespace GodotHostTest.Game.Score;
public class TotalScore : IScore, IDisposable
{
private readonly IDisposable _connectedObservableDisposable;
public TotalScore(ITargetEventBus targetEventBus)
{
var connectedObservable = targetEventBus.Hit.Select(_ => 20)
.Merge(targetEventBus.TimedOut.Select(_ => -5))
.Scan(0, (x1, x2) => x1 + x2)
.Prepend(0)
.Replay(1);
_connectedObservableDisposable = connectedObservable.Connect();
Score = connectedObservable.AsObservable();
Score =
// map every hit target to +20 points
targetEventBus.Hit.Select(_ => 20)
// map every missed target to -5 points
.Merge(targetEventBus.TimedOut.Select(_ => -5))
// sum them all (starting with 0)
.Scan(0, (x1, x2) => x1 + x2)
.ToReadOnlyReactiveProperty();
}
public void Dispose()
{
_connectedObservableDisposable.Dispose();
Score.Dispose();
GC.SuppressFinalize(this);
}
public Observable<int> Score { get; }
public ReadOnlyReactiveProperty<int> Score { get; }
}