Fix up item usage
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Chickensoft.Collections;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
@@ -11,12 +12,16 @@ public interface IGameRepo : IDisposable
|
||||
|
||||
event Action? CloseInventory;
|
||||
|
||||
event Action<string>? AnnounceMessage;
|
||||
event Action<string>? AnnounceMessageOnMainScreenEvent;
|
||||
|
||||
event Action<string>? AnnounceMessageInInventoryEvent;
|
||||
|
||||
event Action<int>? DoubleExpTimeStart;
|
||||
|
||||
event Action? DoubleExpTimeEnd;
|
||||
|
||||
event Action<IInventoryItem>? RemoveItemFromInventoryEvent;
|
||||
|
||||
void Pause();
|
||||
|
||||
void Resume();
|
||||
@@ -29,6 +34,10 @@ public interface IGameRepo : IDisposable
|
||||
|
||||
public void AnnounceMessageOnMainScreen(string message);
|
||||
|
||||
public void AnnounceMessageInInventory(string message);
|
||||
|
||||
public void RemoveItemFromInventory(IInventoryItem item);
|
||||
|
||||
public double ExpRate { get; }
|
||||
}
|
||||
|
||||
@@ -37,9 +46,11 @@ public class GameRepo : IGameRepo
|
||||
public event Action? Ended;
|
||||
public event Action? OpenInventory;
|
||||
public event Action? CloseInventory;
|
||||
public event Action<string>? AnnounceMessage;
|
||||
public event Action<string>? AnnounceMessageOnMainScreenEvent;
|
||||
public event Action<string>? AnnounceMessageInInventoryEvent;
|
||||
public event Action<int>? DoubleExpTimeStart;
|
||||
public event Action? DoubleExpTimeEnd;
|
||||
public event Action<IInventoryItem>? RemoveItemFromInventoryEvent;
|
||||
|
||||
public IAutoProp<bool> IsPaused => _isPaused;
|
||||
private readonly AutoProp<bool> _isPaused;
|
||||
@@ -68,8 +79,7 @@ public class GameRepo : IGameRepo
|
||||
|
||||
public void StartDoubleEXP(TimeSpan lengthOfEffect)
|
||||
{
|
||||
CloseInventory?.Invoke();
|
||||
AnnounceMessageOnMainScreen("Experience points temporarily doubled.");
|
||||
AnnounceMessageInInventory("Experience points temporarily doubled.");
|
||||
DoubleExpTimeStart?.Invoke(lengthOfEffect.Seconds);
|
||||
ExpRate = 2;
|
||||
}
|
||||
@@ -82,7 +92,17 @@ public class GameRepo : IGameRepo
|
||||
|
||||
public void AnnounceMessageOnMainScreen(string message)
|
||||
{
|
||||
AnnounceMessage?.Invoke(message);
|
||||
AnnounceMessageOnMainScreenEvent?.Invoke(message);
|
||||
}
|
||||
|
||||
public void AnnounceMessageInInventory(string message)
|
||||
{
|
||||
AnnounceMessageInInventoryEvent?.Invoke(message);
|
||||
}
|
||||
|
||||
public void RemoveItemFromInventory(IInventoryItem item)
|
||||
{
|
||||
RemoveItemFromInventoryEvent?.Invoke(item);
|
||||
}
|
||||
|
||||
public void OnGameEnded()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
|
||||
namespace Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
@@ -13,18 +15,29 @@ public partial class InGameUILogic
|
||||
OnAttach(() =>
|
||||
{
|
||||
var gameRepo = Get<IGameRepo>();
|
||||
gameRepo.AnnounceMessage += OnAnnounceMessage;
|
||||
gameRepo.AnnounceMessageOnMainScreenEvent += OnAnnounceMessageOnMainScreen;
|
||||
gameRepo.AnnounceMessageInInventoryEvent += OnAnnounceMessageInInventory;
|
||||
gameRepo.RemoveItemFromInventoryEvent += OnRemoveItemFromInventory;
|
||||
});
|
||||
OnDetach(() =>
|
||||
{
|
||||
var gameRepo = Get<IGameRepo>();
|
||||
gameRepo.AnnounceMessage -= OnAnnounceMessage;
|
||||
gameRepo.AnnounceMessageOnMainScreenEvent -= OnAnnounceMessageOnMainScreen;
|
||||
gameRepo.AnnounceMessageInInventoryEvent -= OnAnnounceMessageInInventory;
|
||||
});
|
||||
}
|
||||
|
||||
private void OnAnnounceMessage(string message)
|
||||
private void OnAnnounceMessageOnMainScreen(string message)
|
||||
{
|
||||
Output(new Output.AnnounceMessage(message));
|
||||
Output(new Output.AnnounceMessageOnMainScreen(message));
|
||||
}
|
||||
|
||||
private void OnAnnounceMessageInInventory(string message)
|
||||
{
|
||||
Output(new Output.AnnounceMessageInInventory(message));
|
||||
}
|
||||
|
||||
private void OnRemoveItemFromInventory(IInventoryItem item) => Output(new Output.RemoveItemFromInventory(item));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
namespace Zennysoft.Game.Ma.Implementation;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Game.Ma.Implementation;
|
||||
public partial class InGameUILogic
|
||||
{
|
||||
public static class Output
|
||||
{
|
||||
public readonly record struct AnnounceMessage(string Message);
|
||||
public readonly record struct AnnounceMessageOnMainScreen(string Message);
|
||||
public readonly record struct AnnounceMessageInInventory(string Message);
|
||||
public readonly record struct RemoveItemFromInventory(IInventoryItem Item);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user