Begin work on outlining dynamic side
This commit is contained in:
17
PkmnLib.Dynamic/Events/EventBatchId.cs
Normal file
17
PkmnLib.Dynamic/Events/EventBatchId.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace PkmnLib.Dynamic.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Allows for the batching of multiple events that should be shown at the same time.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is useful for when we send multiple events to the client in sequence, but we want to show them in one go.
|
||||
/// For example, when a Pokemon gets hurt by poison, we want to show the purple poison animation and the damage at the
|
||||
/// same time. This is done by batching the events together.
|
||||
/// </remarks>
|
||||
public record struct EventBatchId()
|
||||
{
|
||||
/// <summary>
|
||||
/// The unique identifier for this batch of events.
|
||||
/// </summary>
|
||||
public Guid Id { get; init; } = Guid.NewGuid();
|
||||
}
|
||||
11
PkmnLib.Dynamic/Events/EventData.cs
Normal file
11
PkmnLib.Dynamic/Events/EventData.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace PkmnLib.Dynamic.Events;
|
||||
|
||||
/// <summary>
|
||||
/// An event is something that happens during a battle. This can be used by front-end code to
|
||||
/// display information about the battle to the user. This is the only way for the front-end to
|
||||
/// know what is happening in the battle.
|
||||
/// </summary>
|
||||
public interface IEventData
|
||||
{
|
||||
|
||||
}
|
||||
21
PkmnLib.Dynamic/Events/EventHook.cs
Normal file
21
PkmnLib.Dynamic/Events/EventHook.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace PkmnLib.Dynamic.Events;
|
||||
|
||||
/// <summary>
|
||||
/// The event hook of a battle. This is used to hook into the battle and get notified when something
|
||||
/// happens that a front-end might want to know about.
|
||||
/// </summary>
|
||||
public class EventHook
|
||||
{
|
||||
/// <summary>
|
||||
/// The event handler that is called when the event is triggered.
|
||||
/// </summary>
|
||||
public event EventHandler<IEventData>? Handler;
|
||||
|
||||
/// <summary>
|
||||
/// Triggers the event, calling the handler with the given data.
|
||||
/// </summary>
|
||||
public void Invoke(IEventData data)
|
||||
{
|
||||
Handler?.Invoke(this, data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user