diff --git a/src/Application/Players/Weapons/ActiveWeaponCatalog.cs b/src/Application/Players/Weapons/ActiveWeaponCatalog.cs new file mode 100644 index 00000000..5f51ae04 --- /dev/null +++ b/src/Application/Players/Weapons/ActiveWeaponCatalog.cs @@ -0,0 +1,36 @@ +namespace CTF.Application.Players.Weapons; + +/// +/// Represents the active weapon catalog used by the server. +/// +/// +/// Consumers do not need to know which weapon catalog is active. +/// This class always exposes the catalog selected by the current server configuration. +/// +public class ActiveWeaponCatalog( + WeaponCatalogSettings settings, + FrozenDictionary catalogs) +{ + private WeaponCatalog Current + => catalogs[settings.Type]; + + /// + public int Count + => Current.Count; + + /// + public IReadOnlyList GetAll() + => Current.GetAll(); + + /// + public bool Contains(IWeapon weapon) + => Current.Contains(weapon); + + /// + public Result GetById(Weapon id) + => Current.GetById(id); + + /// + public Result GetByName(string weaponName) + => Current.GetByName(weaponName); +} diff --git a/src/Application/Players/Weapons/Catalogs/HeavyWeaponCatalog.cs b/src/Application/Players/Weapons/Catalogs/HeavyWeaponCatalog.cs index 7c0e409d..1460ff68 100644 --- a/src/Application/Players/Weapons/Catalogs/HeavyWeaponCatalog.cs +++ b/src/Application/Players/Weapons/Catalogs/HeavyWeaponCatalog.cs @@ -1,6 +1,6 @@ namespace CTF.Application.Players.Weapons.Catalogs; -public class HeavyWeaponCatalog : WeaponCatalogBase +public class HeavyWeaponCatalog : WeaponCatalog { public override WeaponCatalogType Type => WeaponCatalogType.Heavy; diff --git a/src/Application/Players/Weapons/Catalogs/MeleeWeaponCatalog.cs b/src/Application/Players/Weapons/Catalogs/MeleeWeaponCatalog.cs index 17ad6a1f..ed275278 100644 --- a/src/Application/Players/Weapons/Catalogs/MeleeWeaponCatalog.cs +++ b/src/Application/Players/Weapons/Catalogs/MeleeWeaponCatalog.cs @@ -1,6 +1,6 @@ namespace CTF.Application.Players.Weapons.Catalogs; -public class MeleeWeaponCatalog : WeaponCatalogBase +public class MeleeWeaponCatalog : WeaponCatalog { public override WeaponCatalogType Type => WeaponCatalogType.Melee; diff --git a/src/Application/Players/Weapons/Catalogs/MixedWeaponCatalog.cs b/src/Application/Players/Weapons/Catalogs/MixedWeaponCatalog.cs index 7d6e41d9..f693aad5 100644 --- a/src/Application/Players/Weapons/Catalogs/MixedWeaponCatalog.cs +++ b/src/Application/Players/Weapons/Catalogs/MixedWeaponCatalog.cs @@ -1,12 +1,12 @@ namespace CTF.Application.Players.Weapons.Catalogs; /// -/// Provides a combination of walking and run weapons. +/// Defines a weapon catalog that combines the Walking and Run weapon catalogs. /// /// /// This catalog contains all weapons available from both categories. /// -public class MixedWeaponCatalog : WeaponCatalogBase +public class MixedWeaponCatalog : WeaponCatalog { public override WeaponCatalogType Type => WeaponCatalogType.Mixed; diff --git a/src/Application/Players/Weapons/Catalogs/RifleOnlyWeaponCatalog.cs b/src/Application/Players/Weapons/Catalogs/RifleOnlyWeaponCatalog.cs index c08ce167..0dec9879 100644 --- a/src/Application/Players/Weapons/Catalogs/RifleOnlyWeaponCatalog.cs +++ b/src/Application/Players/Weapons/Catalogs/RifleOnlyWeaponCatalog.cs @@ -1,6 +1,6 @@ namespace CTF.Application.Players.Weapons.Catalogs; -public class RifleOnlyWeaponCatalog : WeaponCatalogBase +public class RifleOnlyWeaponCatalog : WeaponCatalog { public override WeaponCatalogType Type => WeaponCatalogType.RifleOnly; diff --git a/src/Application/Players/Weapons/Catalogs/RunWeaponCatalog.cs b/src/Application/Players/Weapons/Catalogs/RunWeaponCatalog.cs index 68ee4a74..2c324f94 100644 --- a/src/Application/Players/Weapons/Catalogs/RunWeaponCatalog.cs +++ b/src/Application/Players/Weapons/Catalogs/RunWeaponCatalog.cs @@ -1,13 +1,13 @@ namespace CTF.Application.Players.Weapons.Catalogs; /// -/// Provides weapons that allow players to remain mobile while fighting. +/// Defines a weapon catalog that allows players to remain mobile while fighting. /// /// /// These weapons support the classic Run Weapons (RW) gameplay style, /// where players can move quickly while attacking. /// -public class RunWeaponCatalog : WeaponCatalogBase +public class RunWeaponCatalog : WeaponCatalog { public override WeaponCatalogType Type => WeaponCatalogType.Run; diff --git a/src/Application/Players/Weapons/Catalogs/WalkingWeaponCatalog.cs b/src/Application/Players/Weapons/Catalogs/WalkingWeaponCatalog.cs index 673c1139..54e3d29a 100644 --- a/src/Application/Players/Weapons/Catalogs/WalkingWeaponCatalog.cs +++ b/src/Application/Players/Weapons/Catalogs/WalkingWeaponCatalog.cs @@ -1,12 +1,12 @@ namespace CTF.Application.Players.Weapons.Catalogs; /// -/// Provides weapons that restrict player mobility while fighting. +/// Defines a weapon catalog that restricts player mobility while fighting. /// /// /// Players can only walk while using most weapons in this catalog. /// -public class WalkingWeaponCatalog : WeaponCatalogBase +public class WalkingWeaponCatalog : WeaponCatalog { public override WeaponCatalogType Type => WeaponCatalogType.Walking; diff --git a/src/Application/Players/Weapons/Catalogs/WarWeaponCatalog.cs b/src/Application/Players/Weapons/Catalogs/WarWeaponCatalog.cs index d4e26ca6..d0b84e0b 100644 --- a/src/Application/Players/Weapons/Catalogs/WarWeaponCatalog.cs +++ b/src/Application/Players/Weapons/Catalogs/WarWeaponCatalog.cs @@ -1,6 +1,6 @@ namespace CTF.Application.Players.Weapons.Catalogs; -public class WarWeaponCatalog : WeaponCatalogBase +public class WarWeaponCatalog : WeaponCatalog { public override WeaponCatalogType Type => WeaponCatalogType.War; diff --git a/src/Application/Players/Weapons/Catalogs/WeaponCatalogBase.cs b/src/Application/Players/Weapons/Catalogs/WeaponCatalog.cs similarity index 92% rename from src/Application/Players/Weapons/Catalogs/WeaponCatalogBase.cs rename to src/Application/Players/Weapons/Catalogs/WeaponCatalog.cs index 5917d2c4..d9a25cee 100644 --- a/src/Application/Players/Weapons/Catalogs/WeaponCatalogBase.cs +++ b/src/Application/Players/Weapons/Catalogs/WeaponCatalog.cs @@ -6,7 +6,7 @@ /// /// Derived classes define which weapons belong to a specific catalog. /// -public abstract class WeaponCatalogBase +public abstract class WeaponCatalog { private readonly List _weapons = [ @@ -18,7 +18,7 @@ public abstract class WeaponCatalogBase /// Initializes the catalog with the weapons that are /// always available to players. /// - protected WeaponCatalogBase() + protected WeaponCatalog() { Define(_weapons); } @@ -29,7 +29,7 @@ protected WeaponCatalogBase() public abstract WeaponCatalogType Type { get; } /// - /// Populates the catalog with weapon definitions. + /// Defines the weapons that belong to this catalog. /// protected abstract void Define(List weapons); @@ -39,7 +39,7 @@ protected WeaponCatalogBase() public int Count => _weapons.Count; /// - /// Gets all weapons defined by the catalog. + /// Gets all weapons defined in this catalog. /// public IReadOnlyList GetAll() => _weapons; diff --git a/src/Application/Players/Weapons/ServiceCollectionExtensions.cs b/src/Application/Players/Weapons/ServiceCollectionExtensions.cs index 6fb5928f..d1042748 100644 --- a/src/Application/Players/Weapons/ServiceCollectionExtensions.cs +++ b/src/Application/Players/Weapons/ServiceCollectionExtensions.cs @@ -12,10 +12,10 @@ public static IServiceCollection AddWeaponServices(this IServiceCollection servi .AddWeaponCatalog() .AddWeaponCatalog() .AddWeaponCatalog() - .AddSingleton() + .AddSingleton() .AddSingleton(sp => { - var catalogs = sp.GetRequiredService>(); + var catalogs = sp.GetRequiredService>(); return catalogs.ToFrozenDictionary(w => w.Type); }); @@ -23,9 +23,9 @@ public static IServiceCollection AddWeaponServices(this IServiceCollection servi } private static IServiceCollection AddWeaponCatalog(this IServiceCollection services) - where T : WeaponCatalogBase + where T : WeaponCatalog { - services.AddSingleton(); + services.AddSingleton(); return services; } } diff --git a/src/Application/Players/Weapons/WeaponCatalog.cs b/src/Application/Players/Weapons/WeaponCatalog.cs deleted file mode 100644 index a84c6a8d..00000000 --- a/src/Application/Players/Weapons/WeaponCatalog.cs +++ /dev/null @@ -1,41 +0,0 @@ -namespace CTF.Application.Players.Weapons; - -/// -/// Provides access to the active weapon catalog. -/// -/// -/// Consumers do not need to know which catalog implementation is currently -/// active. The catalog selection is resolved internally based on the -/// server configuration. -/// -public class WeaponCatalog( - WeaponCatalogSettings settings, - FrozenDictionary catalogs) -{ - private WeaponCatalogBase Current => catalogs[settings.Type]; - - /// - /// Gets the number of weapons available in the active catalog. - /// - public int Count => Current.Count; - - /// - /// Gets all weapons available in the active catalog. - /// - public IReadOnlyList GetAll() => Current.GetAll(); - - /// - /// Determines whether the specified weapon belongs to this active catalog. - /// - public bool Contains(IWeapon weapon) => Current.Contains(weapon); - - /// - /// Gets a weapon from the active catalog by its identifier. - /// - public Result GetById(Weapon id) => Current.GetById(id); - - /// - /// Gets a weapon from the active catalog by its display name. - /// - public Result GetByName(string weaponName) => Current.GetByName(weaponName); -} diff --git a/src/Application/Players/Weapons/WeaponCatalogSystem.cs b/src/Application/Players/Weapons/WeaponCatalogSystem.cs index 69a07ea9..f615eda2 100644 --- a/src/Application/Players/Weapons/WeaponCatalogSystem.cs +++ b/src/Application/Players/Weapons/WeaponCatalogSystem.cs @@ -4,7 +4,7 @@ public class WeaponCatalogSystem( IEntityManager entityManager, IDialogService dialogService, IGunGameMode gunGameMode, - WeaponCatalog weaponCatalog, + ActiveWeaponCatalog weaponCatalog, WeaponCatalogSettings weaponCatalogSettings) : ISystem { [PlayerCommand("weaponcatalog")] diff --git a/src/Application/Players/Weapons/WeaponSelectionSystem.cs b/src/Application/Players/Weapons/WeaponSelectionSystem.cs index b8eb6699..dccaf673 100644 --- a/src/Application/Players/Weapons/WeaponSelectionSystem.cs +++ b/src/Application/Players/Weapons/WeaponSelectionSystem.cs @@ -3,7 +3,7 @@ public class WeaponSelectionSystem( IDialogService dialogService, IGunGameMode gunGameMode, - WeaponCatalog weaponCatalog) : ISystem + ActiveWeaponCatalog weaponCatalog) : ISystem { [Event] public void OnPlayerConnect(Player player) diff --git a/tests/Application.Tests/Players/Weapons/TestWeaponCatalog.cs b/tests/Application.Tests/Players/Weapons/TestWeaponCatalog.cs index 414c42b0..3876794e 100644 --- a/tests/Application.Tests/Players/Weapons/TestWeaponCatalog.cs +++ b/tests/Application.Tests/Players/Weapons/TestWeaponCatalog.cs @@ -1,6 +1,6 @@ namespace CTF.Application.Tests.Players.Weapons; -public class TestWeaponCatalog : WeaponCatalogBase +public class TestWeaponCatalog : WeaponCatalog { public override WeaponCatalogType Type => WeaponCatalogType.Mixed; diff --git a/tests/Application.Tests/Players/Weapons/WeaponCatalogBaseTests.cs b/tests/Application.Tests/Players/Weapons/WeaponCatalogTests.cs similarity index 98% rename from tests/Application.Tests/Players/Weapons/WeaponCatalogBaseTests.cs rename to tests/Application.Tests/Players/Weapons/WeaponCatalogTests.cs index 03cabab8..782f81f7 100644 --- a/tests/Application.Tests/Players/Weapons/WeaponCatalogBaseTests.cs +++ b/tests/Application.Tests/Players/Weapons/WeaponCatalogTests.cs @@ -1,6 +1,6 @@ namespace CTF.Application.Tests.Players.Weapons; -public class WeaponCatalogBaseTests +public class WeaponCatalogTests { [Test] public void GetById_WhenWeaponIdIsNotFound_ShouldReturnFailureResult()