From f2f8bda2300680eb0f86a463715ad1b434c14d7a Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Thu, 22 Aug 2024 20:45:01 -0500 Subject: [PATCH 1/2] BREAKING CHANGE: Rename Items property to TotalItems MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit “Items” is ambiguous because it can also mean a list of objects. --- src/Application/Players/Weapons/WeaponPack.cs | 2 +- src/Application/Players/Weapons/WeaponSystem.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Application/Players/Weapons/WeaponPack.cs b/src/Application/Players/Weapons/WeaponPack.cs index 29600194..ae48b7ce 100644 --- a/src/Application/Players/Weapons/WeaponPack.cs +++ b/src/Application/Players/Weapons/WeaponPack.cs @@ -8,7 +8,7 @@ public class WeaponPack : IEnumerable GtaWeapons.GetById(Weapon.Deagle).Value ]; - public int Items => _weapons.Count; + public int TotalItems => _weapons.Count; public IWeapon this[int index] => _weapons[index]; public bool IsEmpty() => _weapons.Count == 0; diff --git a/src/Application/Players/Weapons/WeaponSystem.cs b/src/Application/Players/Weapons/WeaponSystem.cs index fc76925b..a6b2ee8b 100644 --- a/src/Application/Players/Weapons/WeaponSystem.cs +++ b/src/Application/Players/Weapons/WeaponSystem.cs @@ -15,7 +15,7 @@ public void OnPlayerSpawn(Player player) WeaponPack selectedWeapons = weaponSelection.SelectedWeapons; // Don't user foreach for performance reasons. // OnPlayerSpawn is invoked too often. - for (int i = 0; i < selectedWeapons.Items; i++) + for (int i = 0; i < selectedWeapons.TotalItems; i++) { IWeapon weapon = selectedWeapons[i]; player.GiveWeapon(weapon.Id, IWeapon.UnlimitedAmmo); From 32e71ed9f246b7ca79edc23e9b1e38b1010f1e01 Mon Sep 17 00:00:00 2001 From: MrDave1999 Date: Thu, 22 Aug 2024 20:55:21 -0500 Subject: [PATCH 2/2] BREAKING CHANGE: Rename Max property to Count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit “Max” is ambiguous. It is not clear whether it refers to getting the object with the max value or to the total number of elements. --- src/Application/Players/Accounts/PlayerInfo.cs | 6 +++--- src/Application/Players/Accounts/RoleCollection.cs | 2 +- src/Application/Players/Ranks/RankCollection.cs | 12 ++++++------ src/Application/Players/Weapons/GtaWeapons.cs | 4 ++-- .../Players/Accounts/PlayerInfoTests.cs | 4 ++-- .../Application.Tests/Players/Accounts/RoleTests.cs | 2 +- .../Players/Ranks/RankCollectionTests.cs | 4 ++-- .../Players/Weapons/GtaWeaponsTests.cs | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Application/Players/Accounts/PlayerInfo.cs b/src/Application/Players/Accounts/PlayerInfo.cs index aa79833e..9fe7587e 100644 --- a/src/Application/Players/Accounts/PlayerInfo.cs +++ b/src/Application/Players/Accounts/PlayerInfo.cs @@ -138,7 +138,7 @@ public Result SetTotalDeaths(int value) public Result SetRole(RoleId id) { - if (id < 0 || (int)id >= RoleCollection.Max) + if (id < 0 || (int)id >= RoleCollection.Count) return Result.Failure(Messages.InvalidRole); RoleId = id; @@ -147,7 +147,7 @@ public Result SetRole(RoleId id) public Result SetRank(RankId id) { - if (id < 0 || (int)id >= RankCollection.Max) + if (id < 0 || (int)id >= RankCollection.Count) return Result.Failure(Messages.InvalidRank); RankId = id; @@ -218,7 +218,7 @@ public string GetStatsAsText() StatsPerRound.Deaths, StatsPerRound.KillingSpree, StatsPerRound.Points, - MaxRank = RankCollection.Max, + MaxRank = RankCollection.Count, Level = (int)RankId, RankName = rankResult.Value.Name }; diff --git a/src/Application/Players/Accounts/RoleCollection.cs b/src/Application/Players/Accounts/RoleCollection.cs index 9ff593fb..885f97f9 100644 --- a/src/Application/Players/Accounts/RoleCollection.cs +++ b/src/Application/Players/Accounts/RoleCollection.cs @@ -5,5 +5,5 @@ public class RoleCollection private RoleCollection() { } private static readonly RoleId[] s_roles = Enum.GetValues(); public static IReadOnlyList GetAll() => s_roles; - public static int Max => s_roles.Length; + public static int Count => s_roles.Length; } diff --git a/src/Application/Players/Ranks/RankCollection.cs b/src/Application/Players/Ranks/RankCollection.cs index 593482fe..01639d88 100644 --- a/src/Application/Players/Ranks/RankCollection.cs +++ b/src/Application/Players/Ranks/RankCollection.cs @@ -22,12 +22,12 @@ public class RankCollection ]; private RankCollection() { } - public static int Max => s_ranks.Length; + public static int Count => s_ranks.Length; public static IReadOnlyList GetAll() => s_ranks; public static Result GetById(RankId id) { - if ((int)id < 0 || (int)id >= Max) + if ((int)id < 0 || (int)id >= Count) return Result.Failure(Messages.InvalidRank); Rank rank = s_ranks[(int)id]; @@ -49,16 +49,16 @@ public static Result GetByRequiredKills(int value) return Result.Success(rank); } - IRank maxRank = s_ranks[Max - 1]; + IRank maxRank = s_ranks[Count - 1]; return Result.Success(maxRank); } public static Result GetNextRank(RankId previous) { - if ((int)previous < 0 || (int)previous >= Max) + if ((int)previous < 0 || (int)previous >= Count) return Result.Failure(Messages.InvalidRank); - Rank rank = ((int)previous + 1 == Max) ? + Rank rank = ((int)previous + 1 == Count) ? Rank.None : s_ranks[(int)previous + 1]; @@ -79,7 +79,7 @@ public Rank(RankId id, int requiredKills) Name = id.ToString(); RequiredKills = requiredKills; } - public bool IsMax() => Max == (int)Id + 1; + public bool IsMax() => Count == (int)Id + 1; public bool IsNotMax() => !IsMax(); } } diff --git a/src/Application/Players/Weapons/GtaWeapons.cs b/src/Application/Players/Weapons/GtaWeapons.cs index 3c65994f..428aebf1 100644 --- a/src/Application/Players/Weapons/GtaWeapons.cs +++ b/src/Application/Players/Weapons/GtaWeapons.cs @@ -17,7 +17,7 @@ public class GtaWeapons ]; private GtaWeapons() { } - public static int Max => s_weapons.Length; + public static int Count => s_weapons.Length; public static IReadOnlyList GetAll() => s_weapons; public static Result GetById(Weapon id) @@ -30,7 +30,7 @@ public static Result GetById(Weapon id) public static Result GetByIndex(int index) { - if(index < 0 || index >= Max) + if(index < 0 || index >= Count) return Result.Failure(Messages.InvalidWeapon); GtaWeapon weapon = s_weapons[index]; diff --git a/tests/Application.Tests/Players/Accounts/PlayerInfoTests.cs b/tests/Application.Tests/Players/Accounts/PlayerInfoTests.cs index 513a12f5..fe6c9b27 100644 --- a/tests/Application.Tests/Players/Accounts/PlayerInfoTests.cs +++ b/tests/Application.Tests/Players/Accounts/PlayerInfoTests.cs @@ -2,7 +2,7 @@ public class PlayerInfoTests { - static readonly int[] InvalidRankCases = [-1, -2, RankCollection.Max]; + static readonly int[] InvalidRankCases = [-1, -2, RankCollection.Count]; static readonly int[] InvalidSkinCases = [-1, -2, 312]; [TestCaseSource(nameof(InvalidRankCases))] @@ -296,7 +296,7 @@ public void GetStatsAsText_WhenStatsAreObtained_ShouldReturnsValidStringFormat() { // Arrange var player = new PlayerInfo(); - int maxRank = RankCollection.Max; + int maxRank = RankCollection.Count; var expectedString = "~w~KILLS: ~y~0 ~w~DEATHS: ~y~0 ~w~SPREE: ~y~0 " + $"~w~POINTS: ~y~0/100 ~w~LEVEL: ~y~0/{maxRank} ~w~RANK: ~y~Noob"; diff --git a/tests/Application.Tests/Players/Accounts/RoleTests.cs b/tests/Application.Tests/Players/Accounts/RoleTests.cs index 98c131c6..2fda5262 100644 --- a/tests/Application.Tests/Players/Accounts/RoleTests.cs +++ b/tests/Application.Tests/Players/Accounts/RoleTests.cs @@ -2,7 +2,7 @@ public class RoleTests { - static readonly int[] InvalidRoleCases = [-1, -2, RoleCollection.Max]; + static readonly int[] InvalidRoleCases = [-1, -2, RoleCollection.Count]; [TestCaseSource(nameof(InvalidRoleCases))] public void SetRole_WhenRoleIdIsInvalid_ShouldReturnsFailureResult(int value) diff --git a/tests/Application.Tests/Players/Ranks/RankCollectionTests.cs b/tests/Application.Tests/Players/Ranks/RankCollectionTests.cs index b47b450b..7dacc529 100644 --- a/tests/Application.Tests/Players/Ranks/RankCollectionTests.cs +++ b/tests/Application.Tests/Players/Ranks/RankCollectionTests.cs @@ -22,7 +22,7 @@ public void GetById_WhenRankIsInvalid_ShouldReturnsFailureResult(int value) public void GetById_WhenRankIsMax_ShouldReturnsFailureResult() { // Arrange - int max = RankCollection.Max; + int max = RankCollection.Count; RankId rankId = (RankId)max; string expectedMessage = Messages.InvalidRank; @@ -70,7 +70,7 @@ public void GetNextRank_WhenRankIsInvalid_ShouldReturnsFailureResult(int value) public void GetNextRank_WhenRankIsMax_ShouldReturnsFailureResult() { // Arrange - int max = RankCollection.Max; + int max = RankCollection.Count; RankId rankId = (RankId)max; string expectedMessage = Messages.InvalidRank; diff --git a/tests/Application.Tests/Players/Weapons/GtaWeaponsTests.cs b/tests/Application.Tests/Players/Weapons/GtaWeaponsTests.cs index cd178272..1c40fdfd 100644 --- a/tests/Application.Tests/Players/Weapons/GtaWeaponsTests.cs +++ b/tests/Application.Tests/Players/Weapons/GtaWeaponsTests.cs @@ -97,7 +97,7 @@ public void GetByIndex_WhenIndexIsInvalid_ShouldReturnsFailureResult(int index) public void GetByIndex_WhenIndexIsMax_ShouldReturnsFailureResult() { // Arrange - int index = GtaWeapons.Max; + int index = GtaWeapons.Count; string expectedMessage = Messages.InvalidWeapon; // Act