feat: project cleanup
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
<Project Sdk="Godot.NET.Sdk/4.7.1">
|
<Project Sdk="Godot.NET.Sdk/4.7.2">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||||
<RootNamespace>Game</RootNamespace>
|
<RootNamespace>Game</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
using Game.Shared.Domain;
|
|
||||||
|
|
||||||
namespace Game.Features.Players.Domain;
|
|
||||||
|
|
||||||
public class Player
|
|
||||||
{
|
|
||||||
public EntityId Id { get; private set; }
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
uid://cjblpuqhlu1yf
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace Game.Shared.Domain;
|
|
||||||
|
|
||||||
public readonly record struct EntityId(Guid Value);
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
uid://bpubrm4kms5hy
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Game.Shared.Events.Contracts;
|
|
||||||
|
|
||||||
public interface IEvent
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
uid://bc6g3mar6am56
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace Game.Shared.Events.Contracts;
|
|
||||||
|
|
||||||
public interface IEventBus
|
|
||||||
{
|
|
||||||
IDisposable Subscribe<TEvent>(Action<TEvent> handler) where TEvent : IEvent;
|
|
||||||
|
|
||||||
void Publish<TEvent>(TEvent gameEvent) where TEvent : IEvent;
|
|
||||||
|
|
||||||
void Clear();
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
uid://c6txowanjmm5j
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Game.Shared.Events.Contracts;
|
|
||||||
|
|
||||||
namespace Game.Shared.Events.Infrastructure;
|
|
||||||
|
|
||||||
public sealed class InMemoryEventBus : IEventBus
|
|
||||||
{
|
|
||||||
private readonly Dictionary<Type, List<Delegate>> _handlers = [];
|
|
||||||
private readonly object _lock = new();
|
|
||||||
|
|
||||||
public IDisposable Subscribe<TEvent>(Action<TEvent> handler) where TEvent : IEvent
|
|
||||||
{
|
|
||||||
ArgumentNullException.ThrowIfNull(handler);
|
|
||||||
|
|
||||||
var eventType = typeof(TEvent);
|
|
||||||
|
|
||||||
lock (_lock)
|
|
||||||
{
|
|
||||||
if (!_handlers.TryGetValue(eventType, out var list))
|
|
||||||
{
|
|
||||||
list = [];
|
|
||||||
_handlers[eventType] = list;
|
|
||||||
}
|
|
||||||
|
|
||||||
list.Add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new EventSubscription(() => Unsubscribe(eventType, handler));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Publish<TEvent>(TEvent gameEvent) where TEvent : IEvent
|
|
||||||
{
|
|
||||||
ArgumentNullException.ThrowIfNull(gameEvent);
|
|
||||||
|
|
||||||
List<Delegate> snapshot = null;
|
|
||||||
var eventType = typeof(TEvent);
|
|
||||||
|
|
||||||
lock (_lock)
|
|
||||||
{
|
|
||||||
if (_handlers.TryGetValue(eventType, out var list))
|
|
||||||
{
|
|
||||||
snapshot = new List<Delegate>(list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (snapshot == null) return;
|
|
||||||
|
|
||||||
foreach (var subscriber in snapshot)
|
|
||||||
{
|
|
||||||
((Action<TEvent>)subscriber)(gameEvent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Unsubscribe(Type eventType, Delegate handler)
|
|
||||||
{
|
|
||||||
lock (_lock)
|
|
||||||
{
|
|
||||||
if (!_handlers.TryGetValue(eventType, out var list)) return;
|
|
||||||
|
|
||||||
list.Remove(handler);
|
|
||||||
|
|
||||||
if (list.Count == 0)
|
|
||||||
{
|
|
||||||
_handlers.Remove(eventType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
lock (_lock)
|
|
||||||
{
|
|
||||||
_handlers.Clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private sealed class EventSubscription(Action unsubscribeAction) : IDisposable
|
|
||||||
{
|
|
||||||
private Action _unsubscribeAction = unsubscribeAction;
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
_unsubscribeAction?.Invoke();
|
|
||||||
_unsubscribeAction = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
uid://dsai75jgta1v3
|
|
||||||
Reference in New Issue
Block a user