88 lines
1.7 KiB
C#
88 lines
1.7 KiB
C#
using Chickensoft.Collections;
|
|
using Godot;
|
|
using System;
|
|
|
|
namespace Zennysoft.Game.Ma.Implementation;
|
|
|
|
public interface IGameRepo : IDisposable
|
|
{
|
|
void Pause();
|
|
|
|
void Resume();
|
|
|
|
IAutoProp<bool> IsPaused { get; }
|
|
|
|
void SetPlayerGlobalTransform(Transform3D playerGlobalTransform);
|
|
|
|
public int MaxItemSize { get; }
|
|
|
|
public int EXPRate { get; set; }
|
|
|
|
public int CurrentFloor { get; set; }
|
|
}
|
|
|
|
public class GameRepo : IGameRepo
|
|
{
|
|
public event Action? Ended;
|
|
|
|
public IAutoProp<Transform3D> PlayerGlobalTransform => _playerGlobalTransform;
|
|
private readonly AutoProp<Transform3D> _playerGlobalTransform;
|
|
|
|
public IAutoProp<bool> IsPaused => _isPaused;
|
|
private readonly AutoProp<bool> _isPaused;
|
|
|
|
public int MaxItemSize => 20;
|
|
|
|
public int EXPRate { get; set; } = 1;
|
|
|
|
private bool _disposedValue;
|
|
|
|
public int CurrentFloor { get; set; } = 0;
|
|
|
|
public GameRepo()
|
|
{
|
|
_isPaused = new AutoProp<bool>(true);
|
|
_playerGlobalTransform = new AutoProp<Transform3D>(Transform3D.Identity);
|
|
}
|
|
|
|
public void Pause()
|
|
{
|
|
_isPaused.OnNext(true);
|
|
GD.Print("Paused");
|
|
}
|
|
|
|
public void Resume()
|
|
{
|
|
_isPaused.OnNext(false);
|
|
GD.Print("Resume");
|
|
}
|
|
|
|
public void SetPlayerGlobalTransform(Transform3D playerGlobalTransform) => _playerGlobalTransform.OnNext(playerGlobalTransform);
|
|
|
|
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);
|
|
}
|
|
}
|