Skip to content

Commit

Permalink
Merge pull request #32 from MrDave1999/breaking-change
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Rename the property that gets the number of elements in a collection
  • Loading branch information
MrDave1999 committed Aug 23, 2024
2 parents b576baa + 32e71ed commit 32a9629
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/Application/Players/Accounts/PlayerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
};
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Players/Accounts/RoleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ public class RoleCollection
private RoleCollection() { }
private static readonly RoleId[] s_roles = Enum.GetValues<RoleId>();
public static IReadOnlyList<RoleId> GetAll() => s_roles;
public static int Max => s_roles.Length;
public static int Count => s_roles.Length;
}
12 changes: 6 additions & 6 deletions src/Application/Players/Ranks/RankCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRank> GetAll() => s_ranks;

public static Result<IRank> GetById(RankId id)
{
if ((int)id < 0 || (int)id >= Max)
if ((int)id < 0 || (int)id >= Count)
return Result<IRank>.Failure(Messages.InvalidRank);

Rank rank = s_ranks[(int)id];
Expand All @@ -49,16 +49,16 @@ public static Result<IRank> GetByRequiredKills(int value)
return Result<IRank>.Success(rank);
}

IRank maxRank = s_ranks[Max - 1];
IRank maxRank = s_ranks[Count - 1];
return Result<IRank>.Success(maxRank);
}

public static Result<IRank> GetNextRank(RankId previous)
{
if ((int)previous < 0 || (int)previous >= Max)
if ((int)previous < 0 || (int)previous >= Count)
return Result<IRank>.Failure(Messages.InvalidRank);

Rank rank = ((int)previous + 1 == Max) ?
Rank rank = ((int)previous + 1 == Count) ?
Rank.None :
s_ranks[(int)previous + 1];

Expand All @@ -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();
}
}
4 changes: 2 additions & 2 deletions src/Application/Players/Weapons/GtaWeapons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IWeapon> GetAll() => s_weapons;

public static Result<IWeapon> GetById(Weapon id)
Expand All @@ -30,7 +30,7 @@ public static Result<IWeapon> GetById(Weapon id)

public static Result<IWeapon> GetByIndex(int index)
{
if(index < 0 || index >= Max)
if(index < 0 || index >= Count)
return Result<IWeapon>.Failure(Messages.InvalidWeapon);

GtaWeapon weapon = s_weapons[index];
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Players/Weapons/WeaponPack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class WeaponPack : IEnumerable<IWeapon>
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;

Expand Down
2 changes: 1 addition & 1 deletion src/Application/Players/Weapons/WeaponSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/Application.Tests/Players/Accounts/PlayerInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion tests/Application.Tests/Players/Accounts/RoleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/Application.Tests/Players/Ranks/RankCollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion tests/Application.Tests/Players/Weapons/GtaWeaponsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 32a9629

Please sign in to comment.