Skip to content

Commit

Permalink
Add chaFile.GetFancyCharacterName extension method
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Nov 10, 2022
1 parent 7581d15 commit e2df846
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Shared.Core/Chara/CharacterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ public static ChaControl GetChaControl(this ChaFile chaFile)
Manager.Game.instance.heroineList.FirstOrDefault(h => h.chaFile == chaFile)?.chaCtrl;
#endif
}

/// <summary>
/// Get cleaned up full name of this character, including its translation if available.
/// </summary>
/// <param name="chaFile">Character to get the name of.</param>
/// <param name="describeIfEmpty">If the chaFile is null or the name is empty, a string describing this is returned. If set to false, an empty string is returned instead.</param>
public static string GetFancyCharacterName(this ChaFile chaFile, bool describeIfEmpty = true)
{
if (chaFile?.parameter?.fullname == null) return describeIfEmpty ? "[NULL]" : string.Empty;

var origName = chaFile.parameter.fullname.Trim();
if (origName.Length == 0) return describeIfEmpty ? "[NO NAME]" : string.Empty;

TranslationHelper.TryTranslate(origName, out var tl);
if (tl != null)
{
tl = tl.Trim();
if (tl.Length > 0 && origName != tl)
return $"{tl} ({origName})";
}

return origName;
}

#region Binding
Expand Down

0 comments on commit e2df846

Please sign in to comment.