40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using GameCore.ECS;
|
|
using GameCore.Events;
|
|
|
|
namespace GameCore.State;
|
|
|
|
public class GameStateService(World world) : IGameStateService
|
|
{
|
|
private readonly HashSet<string> _unlockedLevelIds = [];
|
|
private readonly World _world = world;
|
|
public GameStatus CurrentStatus { get; private set; } = GameStatus.InMainMenu;
|
|
public string CurrentLevelId { get; private set; }
|
|
public IReadOnlyCollection<string> UnlockedLevelIds => _unlockedLevelIds;
|
|
|
|
public void SetStatus(GameStatus newStatus)
|
|
{
|
|
if (CurrentStatus == newStatus) return;
|
|
|
|
CurrentStatus = newStatus;
|
|
_world.PublishEvent(new GameStatusChangedEvent(newStatus));
|
|
}
|
|
|
|
public void StartGame(string startingLevelId)
|
|
{
|
|
CurrentLevelId = startingLevelId;
|
|
_unlockedLevelIds.Add(startingLevelId);
|
|
SetStatus(GameStatus.InGame);
|
|
}
|
|
|
|
public void UnlockLevel(string levelId)
|
|
{
|
|
_unlockedLevelIds.Add(levelId);
|
|
}
|
|
|
|
public void ResetProgress()
|
|
{
|
|
_unlockedLevelIds.Clear();
|
|
CurrentLevelId = null!;
|
|
SetStatus(GameStatus.InMainMenu);
|
|
}
|
|
} |