using Chickensoft.Collections; using Godot; namespace Zennysoft.Game.Ma.Implementation; public interface IGameRepo : IDisposable { event Action? Ended; event Action? OpenInventory; event Action? CloseInventory; event Action? AnnounceMessage; event Action? DoubleExpTimeStart; event Action? DoubleExpTimeEnd; void Pause(); void Resume(); IAutoProp IsPaused { get; } public void StartDoubleEXP(TimeSpan lengthOfEffect); public void EndDoubleExp(); public double ExpRate { get; } } public class GameRepo : IGameRepo { public event Action? Ended; public event Action? OpenInventory; public event Action? CloseInventory; public event Action? AnnounceMessage; public event Action? DoubleExpTimeStart; public event Action? DoubleExpTimeEnd; public IAutoProp IsPaused => _isPaused; private readonly AutoProp _isPaused; public double ExpRate { get; private set; } private bool _disposedValue; public GameRepo() { _isPaused = new AutoProp(true); ExpRate = 1; } public void Pause() { _isPaused.OnNext(true); GD.Print("Paused"); } public void Resume() { _isPaused.OnNext(false); GD.Print("Resume"); } public void StartDoubleEXP(TimeSpan lengthOfEffect) { CloseInventory?.Invoke(); AnnounceMessage?.Invoke("Experience points temporarily doubled."); DoubleExpTimeStart?.Invoke(lengthOfEffect.Seconds); ExpRate = 2; } public void EndDoubleExp() { AnnounceMessage?.Invoke("Experience points effect wore off."); ExpRate = 1; } public void OnGameEnded() { Pause(); Ended?.Invoke(); } protected void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { _isPaused.OnCompleted(); _isPaused.Dispose(); } _disposedValue = true; } } public void Dispose() { Dispose(disposing: true); GC.SuppressFinalize(this); } }