using Chickensoft.Collections; using Godot; using System; using System.Collections.Generic; namespace GameJamDungeon { public interface IGameRepo : IDisposable { event Action? Ended; IAutoProp> InventoryItems { get; } IAutoProp IsInventoryScreenOpened { get; } IAutoProp IsPaused { get; } void Pause(); void Resume(); IAutoProp PlayerGlobalPosition { get; } void SetPlayerGlobalPosition(Vector3 playerGlobalPosition); } public class GameRepo : IGameRepo { public event Action? Ended; private readonly AutoProp> _inventoryItems; private readonly AutoProp _isInventoryScreenOpened; public IAutoProp> InventoryItems => _inventoryItems; public IAutoProp IsInventoryScreenOpened => _isInventoryScreenOpened; public IAutoProp PlayerGlobalPosition => _playerGlobalPosition; private readonly AutoProp _playerGlobalPosition; public IAutoProp IsPaused => _isPaused; private readonly AutoProp _isPaused; private bool _disposedValue; public GameRepo() { _inventoryItems = new AutoProp>([]); _isInventoryScreenOpened = new AutoProp(false); _isPaused = new AutoProp(false); _playerGlobalPosition = new AutoProp(Vector3.Zero); } public void Pause() { _isPaused.OnNext(true); GD.Print("Paused"); } public void Resume() { _isPaused.OnNext(false); GD.Print("Resume"); } public void SetPlayerGlobalPosition(Vector3 playerGlobalPosition) => _playerGlobalPosition.OnNext(playerGlobalPosition); public void OnGameEnded() { Pause(); Ended?.Invoke(); } protected void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { _playerGlobalPosition.OnCompleted(); _playerGlobalPosition.Dispose(); _inventoryItems.OnCompleted(); _inventoryItems.Dispose(); _isInventoryScreenOpened.OnCompleted(); _isInventoryScreenOpened.Dispose(); } _disposedValue = true; } } public void Dispose() { Dispose(disposing: true); GC.SuppressFinalize(this); } } }