Move GameLogic to new project

This commit is contained in:
2025-03-07 01:39:18 -08:00
parent b7bf4f3d10
commit 65e4af8595
28 changed files with 33 additions and 25 deletions

View File

@@ -0,0 +1,87 @@
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);
}
}