Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
made all columns toggleable
Browse files Browse the repository at this point in the history
  • Loading branch information
slimDebug committed Jul 19, 2022
1 parent 8325af8 commit 06f725b
Show file tree
Hide file tree
Showing 13 changed files with 586 additions and 83 deletions.
19 changes: 19 additions & 0 deletions HuntMmrReader/Converters/BooleanToVisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace HuntMmrReader.Converters;

internal class BooleanToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value is true ? Visibility.Visible : Visibility.Collapsed;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
21 changes: 21 additions & 0 deletions HuntMmrReader/Converters/PlayerOptionsToBooleanConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Globalization;
using System.Windows.Data;
using HuntMmrReader.Enums;

namespace HuntMmrReader.Converters;

internal class PlayerOptionsToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is PlayerOptions playerOptionsValue && parameter is PlayerOptions playerOptionsParameter)
return playerOptionsValue.HasFlag(playerOptionsParameter);
return false;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
86 changes: 86 additions & 0 deletions HuntMmrReader/Enums/PlayerOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.ComponentModel;

namespace HuntMmrReader.Enums;

/// <summary>
/// Player options
/// </summary>
[Flags]
internal enum PlayerOptions
{
///<summary>Default value.</summary>
None = 0,

///<summary>This should be a string.</summary>
[Description("blood_line_name")] BloodLineName = 1,

///<summary>This should be a ushort.</summary>
[Description("bountyextracted")] BountyExtracted = 2,

///<summary>This should be a ushort.</summary>
[Description("bountypickedup")] BountyPickedUp = 4,

///<summary>This should be a ushort.</summary>
[Description("downedbyme")] DownedByMe = 8,

///<summary>This should be a ushort.</summary>
[Description("downedbyteammate")] DownedByTeammate = 16,

///<summary>This should be a ushort.</summary>
[Description("downedme")] DownedMe = 32,

///<summary>This should be a ushort.</summary>
[Description("downedteammate")] DownedTeammate = 64,

///<summary>This should be a bool.</summary>
[Description("hadWellspring")] HadWellspring = 128,

///<summary>This should be a bool.</summary>
[Description("hadbounty")] HadBounty = 256,

///<summary>This should be a bool.</summary>
[Description("ispartner")] IsPartner = 512,

///<summary>This should be a bool.</summary>
[Description("issoulsurvivor")] IsSoulSurvivor = 1024,

///<summary>This should be a ushort.</summary>
[Description("killedbyme")] KilledByMe = 2048,

///<summary>This should be a ushort.</summary>
[Description("killedbyteammate")] KilledByTeammate = 4096,

///<summary>This should be a ushort.</summary>
[Description("killedme")] KilledMe = 8192,

///<summary>This should be a ushort.</summary>
[Description("killedteammate")] KilledTeammate = 16384,

///<summary>This should be a ushort.</summary>
[Description("mmr")] Mmr = 32768,

///<summary>This should be a ulong.</summary>
[Description("profileid")] ProfileId = 65536,

///<summary>This should be a bool.</summary>
[Description("proximity")] Proximity = 131072,

///<summary>This should be a bool.</summary>
[Description("proximitytome")] ProximityToMe = 262144,

///<summary>This should be a bool.</summary>
[Description("proximitytoteammate")] ProximityToTeammate = 524288,

///<summary>This should be a bool.</summary>
[Description("skillbased")] SkillBased = 1048576,

///<summary>This should be a bool.</summary>
[Description("teamextraction")] TeamExtraction = 2097152,

///<summary>All values combined.</summary>
All = BloodLineName | BountyExtracted | BountyPickedUp | DownedByMe | DownedByTeammate | DownedMe | DownedTeammate |
HadWellspring | HadBounty | IsPartner | IsSoulSurvivor | KilledByMe | KilledByTeammate | KilledMe |
KilledTeammate | Mmr | ProfileId | Proximity | ProximityToMe | ProximityToTeammate | SkillBased |
TeamExtraction
}
23 changes: 23 additions & 0 deletions HuntMmrReader/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;

namespace HuntMmrReader.Extensions;

internal static class EnumExtensions
{
public static string GetDescription(this Enum e)
{
var attribute =
e.GetType()
.GetTypeInfo()
.GetMember(e.ToString())
.FirstOrDefault(member => member.MemberType == MemberTypes.Field)
?.GetCustomAttributes(typeof(DescriptionAttribute), false)
.SingleOrDefault()
as DescriptionAttribute;

return attribute?.Description ?? e.ToString();
}
}
23 changes: 20 additions & 3 deletions HuntMmrReader/Models/BaseModels/HuntBaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,29 @@ protected HuntBaseEntity(ushort mmr, ushort id)

protected HuntBaseEntity(string? mmr, ushort id)
{
Mmr = ushort.TryParse(mmr, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsedMmr)
? parsedMmr
: ushort.MinValue;
Mmr = ParseUInt16(mmr);
Id = id;
}

public ushort Mmr { get; }
public ushort Id { get; }

protected static bool ParseBoolean(string? input)
{
return bool.TryParse(input, out var parsedInput) && parsedInput;
}

protected static ushort ParseUInt16(string? input)
{
return ushort.TryParse(input, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsedInput)
? parsedInput
: ushort.MinValue;
}

protected static ulong ParseUInt64(string? input)
{
return ulong.TryParse(input, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsedInput)
? parsedInput
: ulong.MinValue;
}
}
89 changes: 69 additions & 20 deletions HuntMmrReader/Models/HuntPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,89 @@ namespace HuntMmrReader.Models;

public class HuntPlayer : HuntBaseEntity
{
public HuntPlayer(string? name, ushort mmr, bool hadBounty, bool hadWellSpring,
ushort killedByMe, ushort killedMe,
ushort playerId) : base(mmr, playerId)
public HuntPlayer(ushort id, ushort mmr, string bloodLineName, ushort bountyExtracted, ushort bountyPickedUp,
ushort downedByMe, ushort downedByTeammate, ushort downedMe, ushort downedTeammate, bool hadWellspring,
bool hadBounty, bool isPartner, bool isSoulSurvivor, ushort killedByMe, ushort killedByTeammate,
ushort killedMe, ushort killedTeammate, ulong profileId,
bool proximity, bool proximityToMe, bool proximityToTeammate, bool skillBased, bool teamExtraction) : base(mmr,
id)
{
Name = name ?? string.Empty;
BloodLineName = bloodLineName;
BountyExtracted = bountyExtracted;
BountyPickedUp = bountyPickedUp;
DownedByMe = downedByMe;
DownedByTeammate = downedByTeammate;
DownedMe = downedMe;
DownedTeammate = downedTeammate;
HadWellspring = hadWellspring;
HadBounty = hadBounty;
HadWellSpring = hadWellSpring;
IsPartner = isPartner;
IsSoulSurvivor = isSoulSurvivor;
KilledByMe = killedByMe;
KilledByTeammate = killedByTeammate;
KilledMe = killedMe;
KilledTeammate = killedTeammate;
ProfileId = profileId;
Proximity = proximity;
ProximityToMe = proximityToMe;
ProximityToTeammate = proximityToTeammate;
SkillBased = skillBased;
TeamExtraction = teamExtraction;
}

public HuntPlayer(string? name, string? mmr, string? hadBounty,
string? hadWellSpring, string? killedByMe, string? killedMe, ushort playerId) : base(mmr, playerId)
public HuntPlayer(ushort id, string? mmr, string? bloodLineName, string? bountyExtracted, string? bountyPickedUp,
string? downedByMe, string? downedByTeammate, string? downedMe, string? downedTeammate, string? hadWellspring,
string? hadBounty, string? isPartner, string? isSoulSurvivor, string? killedByMe, string? killedByTeammate,
string? killedMe, string? killedTeammate, string? profileId, string? proximity, string? proximityToMe,
string? proximityToTeammate, string? skillBased, string? teamExtraction) : base(mmr, id)
{
Name = name ?? string.Empty;
HadBounty = bool.TryParse(hadBounty, out var parsedHadBounty) && parsedHadBounty;
HadWellSpring = bool.TryParse(hadWellSpring, out var parsedHadWellSpring) && parsedHadWellSpring;
KilledByMe =
ushort.TryParse(killedByMe, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsedKilledByMe)
? parsedKilledByMe
: ushort.MinValue;
KilledMe = ushort.TryParse(killedMe, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsedKilledMe)
? parsedKilledMe
: ushort.MinValue;
BloodLineName = bloodLineName ?? string.Empty;
BountyExtracted = ParseUInt16(bountyExtracted);
BountyPickedUp = ParseUInt16(bountyPickedUp);
DownedByMe = ParseUInt16(downedByMe);
DownedByTeammate = ParseUInt16(downedByTeammate);
DownedMe = ParseUInt16(downedMe);
DownedTeammate = ParseUInt16(downedTeammate);
HadWellspring = ParseBoolean(hadWellspring);
HadBounty = ParseBoolean(hadBounty);
IsPartner = ParseBoolean(isPartner);
IsSoulSurvivor = ParseBoolean(isSoulSurvivor);
KilledByMe = ParseUInt16(killedByMe);
KilledByTeammate = ParseUInt16(killedByTeammate);
KilledMe = ParseUInt16(killedMe);
KilledTeammate = ParseUInt16(killedTeammate);
ProfileId = ParseUInt64(profileId);
Proximity = ParseBoolean(proximity);
ProximityToMe = ParseBoolean(proximityToMe);
ProximityToTeammate = ParseBoolean(proximityToTeammate);
SkillBased = ParseBoolean(skillBased);
TeamExtraction = ParseBoolean(teamExtraction);
}

public string Name { get; }
public string BloodLineName { get; }
public ushort BountyExtracted { get; }
public ushort BountyPickedUp { get; }
public ushort DownedByMe { get; }
public ushort DownedByTeammate { get; }
public ushort DownedMe { get; }
public ushort DownedTeammate { get; }
public bool HadWellspring { get; }
public bool HadBounty { get; }
public bool HadWellSpring { get; }
public bool IsPartner { get; }
public bool IsSoulSurvivor { get; }
public ushort KilledByMe { get; }
public ushort KilledByTeammate { get; }
public ushort KilledMe { get; }
public ushort KilledTeammate { get; }
public ulong ProfileId { get; }
public bool Proximity { get; }
public bool ProximityToMe { get; }
public bool ProximityToTeammate { get; }
public bool SkillBased { get; }
public bool TeamExtraction { get; }

public override string ToString()
{
return $"Player Name: {Name,-24} | MMR: {Mmr.ToString(CultureInfo.InvariantCulture),4}";
return $"Player Name: {BloodLineName,-24} | MMR: {Mmr.ToString(CultureInfo.InvariantCulture),4}";
}
}
Loading

0 comments on commit 06f725b

Please sign in to comment.