104 lines
2.4 KiB
C#
104 lines
2.4 KiB
C#
using Chickensoft.Collections;
|
|
using Godot;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace GameJamDungeon;
|
|
|
|
public interface IGameRepo : IDisposable
|
|
{
|
|
event Action? Ended;
|
|
|
|
IAutoProp<List<InventoryItemInfo>> InventoryItems { get; }
|
|
|
|
IAutoProp<bool> IsInventoryScreenOpened { get; }
|
|
|
|
IAutoProp<bool> IsPaused { get; }
|
|
|
|
void Pause();
|
|
|
|
void Resume();
|
|
|
|
IAutoProp<Vector3> PlayerGlobalPosition { get; }
|
|
|
|
void SetPlayerGlobalPosition(Vector3 playerGlobalPosition);
|
|
|
|
public Weapon EquippedWeapon { get; }
|
|
}
|
|
|
|
public class GameRepo : IGameRepo
|
|
{
|
|
public event Action? Ended;
|
|
|
|
private readonly AutoProp<List<InventoryItemInfo>> _inventoryItems;
|
|
private readonly AutoProp<bool> _isInventoryScreenOpened;
|
|
|
|
public IAutoProp<List<InventoryItemInfo>> InventoryItems => _inventoryItems;
|
|
|
|
public IAutoProp<bool> IsInventoryScreenOpened => _isInventoryScreenOpened;
|
|
|
|
public IAutoProp<Vector3> PlayerGlobalPosition => _playerGlobalPosition;
|
|
private readonly AutoProp<Vector3> _playerGlobalPosition;
|
|
|
|
public IAutoProp<bool> IsPaused => _isPaused;
|
|
private readonly AutoProp<bool> _isPaused;
|
|
|
|
private Weapon _equippedWeapon;
|
|
public Weapon EquippedWeapon => _equippedWeapon;
|
|
|
|
private bool _disposedValue;
|
|
|
|
public GameRepo()
|
|
{
|
|
_inventoryItems = new AutoProp<List<InventoryItemInfo>>([]);
|
|
_isInventoryScreenOpened = new AutoProp<bool>(false);
|
|
_isPaused = new AutoProp<bool>(false);
|
|
_playerGlobalPosition = new AutoProp<Vector3>(Vector3.Zero);
|
|
_equippedWeapon = new Weapon() { InventoryInfo = WeaponInfo.Default };
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|