From d5d868ef2fc037b8ec5e7993743d14b0c843a8ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Sun, 26 Dec 2021 23:02:45 +0100 Subject: [PATCH] chore: move data classes to correct namespaces --- Core/NosSmooth.Game/Data/Characters/Family.cs | 9 -- Core/NosSmooth.Game/Data/Info/Position.cs | 23 ++++ .../Data/Inventory/InventoryItem.cs | 12 ++ Core/NosSmooth.Game/Data/Inventory/Item.cs | 12 -- Core/NosSmooth.Game/Data/Position.cs | 14 --- Core/NosSmooth.Game/Data/Social/Family.cs | 15 +++ .../{Handlers => Core}/EventDispatcher.cs | 103 +++++++++--------- .../{Handlers => Core}/IGameResponder.cs | 67 ++++++------ 8 files changed, 135 insertions(+), 120 deletions(-) delete mode 100644 Core/NosSmooth.Game/Data/Characters/Family.cs create mode 100644 Core/NosSmooth.Game/Data/Info/Position.cs create mode 100644 Core/NosSmooth.Game/Data/Inventory/InventoryItem.cs delete mode 100644 Core/NosSmooth.Game/Data/Inventory/Item.cs delete mode 100644 Core/NosSmooth.Game/Data/Position.cs create mode 100644 Core/NosSmooth.Game/Data/Social/Family.cs rename Core/NosSmooth.Game/Events/{Handlers => Core}/EventDispatcher.cs (92%) rename Core/NosSmooth.Game/Events/{Handlers => Core}/IGameResponder.cs (75%) diff --git a/Core/NosSmooth.Game/Data/Characters/Family.cs b/Core/NosSmooth.Game/Data/Characters/Family.cs deleted file mode 100644 index af894f8..0000000 --- a/Core/NosSmooth.Game/Data/Characters/Family.cs +++ /dev/null @@ -1,9 +0,0 @@ -// -// Family.cs -// -// Copyright (c) Christofel authors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace NosSmooth.Game.Data.Character; - -public record Family(); \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Info/Position.cs b/Core/NosSmooth.Game/Data/Info/Position.cs new file mode 100644 index 0000000..dae67b6 --- /dev/null +++ b/Core/NosSmooth.Game/Data/Info/Position.cs @@ -0,0 +1,23 @@ +// +// Position.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace NosSmooth.Game.Data.Info; + +/// +/// Represents nostale position on map. +/// +public record Position +{ + /// + /// Gets the x coordinate. + /// + public long X { get; internal set; } + + /// + /// Gets the y coordinate. + /// + public long Y { get; internal set; } +} \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Inventory/InventoryItem.cs b/Core/NosSmooth.Game/Data/Inventory/InventoryItem.cs new file mode 100644 index 0000000..f31010d --- /dev/null +++ b/Core/NosSmooth.Game/Data/Inventory/InventoryItem.cs @@ -0,0 +1,12 @@ +// +// InventoryItem.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace NosSmooth.Game.Data.Inventory; + +/// +/// Represents item in bag inventory of the character. +/// +public record InventoryItem(); \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Inventory/Item.cs b/Core/NosSmooth.Game/Data/Inventory/Item.cs deleted file mode 100644 index 5b40a07..0000000 --- a/Core/NosSmooth.Game/Data/Inventory/Item.cs +++ /dev/null @@ -1,12 +0,0 @@ -// -// Item.cs -// -// Copyright (c) Christofel authors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace NosSmooth.Game.Data.Inventory; - -public class Item -{ - -} \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Position.cs b/Core/NosSmooth.Game/Data/Position.cs deleted file mode 100644 index ddc9d98..0000000 --- a/Core/NosSmooth.Game/Data/Position.cs +++ /dev/null @@ -1,14 +0,0 @@ -// -// Position.cs -// -// Copyright (c) František Boháček. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace NosSmooth.Game.Data; - -/// -/// Represents nostale positition on map. -/// -/// The x coordinate. -/// The y coordinate. -public record Position(int X, int Y); \ No newline at end of file diff --git a/Core/NosSmooth.Game/Data/Social/Family.cs b/Core/NosSmooth.Game/Data/Social/Family.cs new file mode 100644 index 0000000..82e7515 --- /dev/null +++ b/Core/NosSmooth.Game/Data/Social/Family.cs @@ -0,0 +1,15 @@ +// +// Family.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace NosSmooth.Game.Data.Social; + +/// +/// Represents nostale family entity. +/// +/// The id of the family. +/// The name of the family. +/// The level of the entity. +public record Family(string? Id, string? Name, byte Level); \ No newline at end of file diff --git a/Core/NosSmooth.Game/Events/Handlers/EventDispatcher.cs b/Core/NosSmooth.Game/Events/Core/EventDispatcher.cs similarity index 92% rename from Core/NosSmooth.Game/Events/Handlers/EventDispatcher.cs rename to Core/NosSmooth.Game/Events/Core/EventDispatcher.cs index ebc03b4..ff09c1e 100644 --- a/Core/NosSmooth.Game/Events/Handlers/EventDispatcher.cs +++ b/Core/NosSmooth.Game/Events/Core/EventDispatcher.cs @@ -1,51 +1,52 @@ -// -// EventDispatcher.cs -// -// Copyright (c) František Boháček. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using Microsoft.Extensions.DependencyInjection; -using Remora.Results; - -namespace NosSmooth.Game.Events.Handlers; - -/// -/// Dispatches with . -/// -public class EventDispatcher -{ - private readonly IServiceProvider _provider; - - /// - /// Initializes a new instance of the class. - /// - /// The services provider. - public EventDispatcher(IServiceProvider provider) - { - _provider = provider; - } - - /// - /// Dispatches game responders that are registered in the service collection. - /// - /// The event to dispatch. - /// The cancellation token for cancelling the operation. - /// The type of the event. - /// A result that may or may not have succeeded. - public async Task DispatchEvent(TEvent @event, CancellationToken ct = default) - where TEvent : IGameEvent - { - var results = await Task.WhenAll( - _provider - .GetServices>() - .Select(responder => responder.Respond(@event, ct)) - ); - - return results.Length switch - { - 0 => Result.FromSuccess(), - 1 => results[0], - _ => new AggregateError(results.Cast().ToArray()), - }; - } -} \ No newline at end of file +// +// EventDispatcher.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.Extensions.DependencyInjection; +using Remora.Results; + +namespace NosSmooth.Game.Events.Core; + +/// +/// Dispatches with . +/// +public class EventDispatcher +{ + private readonly IServiceProvider _provider; + + /// + /// Initializes a new instance of the class. + /// + /// The services provider. + public EventDispatcher(IServiceProvider provider) + { + _provider = provider; + } + + /// + /// Dispatches game responders that are registered in the service collection. + /// + /// The event to dispatch. + /// The cancellation token for cancelling the operation. + /// The type of the event. + /// A result that may or may not have succeeded. + public async Task DispatchEvent(TEvent @event, CancellationToken ct = default) + where TEvent : IGameEvent + { + using var scope = _provider.CreateScope(); + var results = await Task.WhenAll( + scope.ServiceProvider + .GetServices>() + .Select(responder => responder.Respond(@event, ct)) + ); + + return results.Length switch + { + 0 => Result.FromSuccess(), + 1 => results[0], + _ => new AggregateError(results.Cast().ToArray()), + }; + } +} diff --git a/Core/NosSmooth.Game/Events/Handlers/IGameResponder.cs b/Core/NosSmooth.Game/Events/Core/IGameResponder.cs similarity index 75% rename from Core/NosSmooth.Game/Events/Handlers/IGameResponder.cs rename to Core/NosSmooth.Game/Events/Core/IGameResponder.cs index b649b82..e578f4d 100644 --- a/Core/NosSmooth.Game/Events/Handlers/IGameResponder.cs +++ b/Core/NosSmooth.Game/Events/Core/IGameResponder.cs @@ -1,34 +1,33 @@ -// -// IGameResponder.cs -// -// Copyright (c) František Boháček. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using OneOf.Types; -using Remora.Results; - -namespace NosSmooth.Game.Events.Handlers; - -/// -/// Represents interface for classes that respond to . -/// -public interface IGameResponder -{ -} - -/// -/// Represents interface for classes that respond to game events. -/// Responds to . -/// -/// The event type this responder responds to. -public interface IGameResponder : IGameResponder - where TEvent : IGameEvent -{ - /// - /// Respond to the given packet. - /// - /// The packet to respond to. - /// The cancellation token for cancelling the operation. - /// A result that may or may not have succeeded. - public Task Respond(TEvent packet, CancellationToken ct = default); -} \ No newline at end of file +// +// IGameResponder.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Remora.Results; + +namespace NosSmooth.Game.Events.Core; + +/// +/// Represents interface for classes that respond to . +/// +public interface IGameResponder +{ +} + +/// +/// Represents interface for classes that respond to game events. +/// Responds to . +/// +/// The event type this responder responds to. +public interface IGameResponder : IGameResponder + where TEvent : IGameEvent +{ + /// + /// Respond to the given packet. + /// + /// The packet to respond to. + /// The cancellation token for cancelling the operation. + /// A result that may or may not have succeeded. + public Task Respond(TEvent gameEvent, CancellationToken ct = default); +} -- 2.48.1