using System; using GodotHostTest.Interfaces; using R3; namespace GodotHostTest.Game.Score; public class TotalScore : IScore, IDisposable { public TotalScore(ITargetEventBus targetEventBus) { 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() { Score.Dispose(); GC.SuppressFinalize(this); } public ReadOnlyReactiveProperty Score { get; } }