From 6cabf651fe6f9776b73ee488f85d8895526d782c Mon Sep 17 00:00:00 2001 From: Ethan Moffat Date: Thu, 28 Apr 2022 16:40:04 -0700 Subject: [PATCH] Use [Record] attribute for PaperdollData and remove IPaperdollData interface --- EOLib/Domain/Character/PaperdollData.cs | 178 ++---------------- EOLib/Domain/Character/PaperdollRepository.cs | 8 +- EndlessClient/Dialogs/PaperdollDialog.cs | 6 +- 3 files changed, 22 insertions(+), 170 deletions(-) diff --git a/EOLib/Domain/Character/PaperdollData.cs b/EOLib/Domain/Character/PaperdollData.cs index 6566a0f9e..617b579f4 100644 --- a/EOLib/Domain/Character/PaperdollData.cs +++ b/EOLib/Domain/Character/PaperdollData.cs @@ -1,186 +1,38 @@ -using EOLib.Domain.Online; +using Amadevus.RecordGenerator; +using EOLib.Domain.Online; using EOLib.IO; using System.Collections.Generic; -using System.Linq; namespace EOLib.Domain.Character { - public class PaperdollData : IPaperdollData + [Record] + public sealed partial class PaperdollData { - public string Name { get; private set; } + public string Name { get; } - public string Home { get; private set; } + public string Home { get; } - public string Partner { get; private set; } + public string Partner { get; } - public string Title { get; private set; } + public string Title { get; } - public string Guild { get; private set; } + public string Guild { get; } - public string Rank { get; private set; } + public string Rank { get; } - public short PlayerID { get; private set; } + public short PlayerID { get; } - public byte Class { get; private set; } + public byte Class { get; } - public byte Gender { get; private set; } + public byte Gender { get; } - public IReadOnlyDictionary Paperdoll { get; private set; } + public IReadOnlyDictionary Paperdoll { get; } - public OnlineIcon Icon { get; private set; } + public OnlineIcon Icon { get; } public PaperdollData() { Paperdoll = new Dictionary(); } - - private PaperdollData(string name, - string home, - string partner, - string title, - string guild, - string rank, - short playerID, - byte @class, - byte gender, - IReadOnlyDictionary paperdoll, - OnlineIcon icon) - { - Name = name; - Home = home; - Partner = partner; - Title = title; - Guild = guild; - Rank = rank; - PlayerID = playerID; - Class = @class; - Gender = gender; - Paperdoll = paperdoll; - Icon = icon; - } - - public IPaperdollData WithName(string name) - { - return new PaperdollData(name, Home, Partner, Title, Guild, Rank, PlayerID, Class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithHome(string home) - { - return new PaperdollData(Name, home, Partner, Title, Guild, Rank, PlayerID, Class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithPartner(string partner) - { - return new PaperdollData(Name, Home, partner, Title, Guild, Rank, PlayerID, Class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithTitle(string title) - { - return new PaperdollData(Name, Home, Partner, title, Guild, Rank, PlayerID, Class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithGuild(string guild) - { - return new PaperdollData(Name, Home, Partner, Title, guild, Rank, PlayerID, Class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithRank(string rank) - { - return new PaperdollData(Name, Home, Partner, Title, Guild, rank, PlayerID, Class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithPlayerID(short playerID) - { - return new PaperdollData(Name, Home, Partner, Title, Guild, Rank, playerID, Class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithClass(byte @class) - { - return new PaperdollData(Name, Home, Partner, Title, Guild, Rank, PlayerID, @class, Gender, Paperdoll, Icon); - } - - public IPaperdollData WithGender(byte gender) - { - return new PaperdollData(Name, Home, Partner, Title, Guild, Rank, PlayerID, Class, gender, Paperdoll, Icon); - } - - public IPaperdollData WithPaperdoll(IReadOnlyDictionary paperdoll) - { - return new PaperdollData(Name, Home, Partner, Title, Guild, Rank, PlayerID, Class, Gender, paperdoll, Icon); - } - - public IPaperdollData WithIcon(OnlineIcon icon) - { - return new PaperdollData(Name, Home, Partner, Title, Guild, Rank, PlayerID, Class, Gender, Paperdoll, icon); - } - - public override bool Equals(object obj) - { - var other = obj as PaperdollData; - if (other == null) - return false; - - return Name == other.Name && Home == other.Home && Partner == other.Partner && Title == other.Title && - Guild == other.Guild && Rank == other.Rank && PlayerID == other.PlayerID && - Class == other.Class && Gender == other.Gender && Icon == other.Icon && Paperdoll.SequenceEqual(other.Paperdoll); - } - - public override int GetHashCode() - { - int hashCode = 170256730; - hashCode = hashCode * -1521134295 + Name.GetHashCode(); - hashCode = hashCode * -1521134295 + Home.GetHashCode(); - hashCode = hashCode * -1521134295 + Partner.GetHashCode(); - hashCode = hashCode * -1521134295 + Title.GetHashCode(); - hashCode = hashCode * -1521134295 + Guild.GetHashCode(); - hashCode = hashCode * -1521134295 + Rank.GetHashCode(); - hashCode = hashCode * -1521134295 + PlayerID.GetHashCode(); - hashCode = hashCode * -1521134295 + Class.GetHashCode(); - hashCode = hashCode * -1521134295 + Gender.GetHashCode(); - hashCode = hashCode * -1521134295 + Paperdoll.Select(x => (int)x.Value) - .Aggregate(hashCode * -1521134295, (a, b) => a * -1521134295 + b.GetHashCode()); - hashCode = hashCode * -1521134295 + Icon.GetHashCode(); - return hashCode; - } - } - - public interface IPaperdollData - { - string Name { get; } - string Home { get; } - string Partner { get; } - string Title { get; } - string Guild { get; } - string Rank { get; } - - short PlayerID { get; } - byte Class { get; } - byte Gender { get; } - - IReadOnlyDictionary Paperdoll { get; } - - OnlineIcon Icon { get; } - - IPaperdollData WithName(string name); - - IPaperdollData WithHome(string home); - - IPaperdollData WithPartner(string partner); - - IPaperdollData WithTitle(string title); - - IPaperdollData WithGuild(string guild); - - IPaperdollData WithRank(string rank); - - IPaperdollData WithPlayerID(short playerID); - - IPaperdollData WithClass(byte @class); - - IPaperdollData WithGender(byte gender); - - IPaperdollData WithPaperdoll(IReadOnlyDictionary paperdoll); - - IPaperdollData WithIcon(OnlineIcon icon); } } diff --git a/EOLib/Domain/Character/PaperdollRepository.cs b/EOLib/Domain/Character/PaperdollRepository.cs index d3875f098..87eb64a98 100644 --- a/EOLib/Domain/Character/PaperdollRepository.cs +++ b/EOLib/Domain/Character/PaperdollRepository.cs @@ -5,19 +5,19 @@ namespace EOLib.Domain.Character { public interface IPaperdollRepository { - Dictionary VisibleCharacterPaperdolls { get; set; } + Dictionary VisibleCharacterPaperdolls { get; set; } } public interface IPaperdollProvider { - IReadOnlyDictionary VisibleCharacterPaperdolls { get; } + IReadOnlyDictionary VisibleCharacterPaperdolls { get; } } [AutoMappedType(IsSingleton = true)] public class PaperdollRepository : IPaperdollRepository, IPaperdollProvider { - public Dictionary VisibleCharacterPaperdolls { get; set; } = new Dictionary(); + public Dictionary VisibleCharacterPaperdolls { get; set; } = new Dictionary(); - IReadOnlyDictionary IPaperdollProvider.VisibleCharacterPaperdolls => VisibleCharacterPaperdolls; + IReadOnlyDictionary IPaperdollProvider.VisibleCharacterPaperdolls => VisibleCharacterPaperdolls; } } diff --git a/EndlessClient/Dialogs/PaperdollDialog.cs b/EndlessClient/Dialogs/PaperdollDialog.cs index 6411b2eae..b4eddd7a4 100644 --- a/EndlessClient/Dialogs/PaperdollDialog.cs +++ b/EndlessClient/Dialogs/PaperdollDialog.cs @@ -43,7 +43,7 @@ public class PaperdollDialog : BaseEODialog private Option _characterIconSourceRect; private readonly InventoryPanel _inventoryPanel; - private Option _paperdollData; + private Option _paperdollData; private readonly List _childItems; @@ -128,7 +128,7 @@ public PaperdollDialog(IGameStateProvider gameStateProvider, CenterInGameView(); DrawPosition = new Vector2(DrawPosition.X, 15); - _paperdollData = Option.None(); + _paperdollData = Option.None(); } public bool NoItemsDragging() => !_childItems.Any(x => x.IsBeingDragged); @@ -173,7 +173,7 @@ protected override void OnDrawControl(GameTime gameTime) _spriteBatch.End(); } - private void UpdateDisplayedData(IPaperdollData paperdollData) + private void UpdateDisplayedData(PaperdollData paperdollData) { _name.Text = Capitalize(paperdollData.Name); _home.Text = Capitalize(paperdollData.Home);