Files
Radicade/Server/Avatars/AvatarItemDescription.cs
2026-10-16 23:33:13 -07:00

70 lines
1.6 KiB
C#

using System.Text;
namespace RadicadeServer.RecNet.Avatar;
public static class AvatarItemDescription
{
public static string Normalize(string? description)
{
if (string.IsNullOrWhiteSpace(description))
{
return description?.Trim() ?? string.Empty;
}
var trimmed = description.Trim();
var segments = trimmed.Split(',');
if (segments[0].Length == 0)
{
return trimmed;
}
var hasEmptySlot = false;
for (var index = 1; index < segments.Length - 1; index++)
{
if (segments[index].Length == 0)
{
hasEmptySlot = true;
break;
}
}
if (!hasEmptySlot)
{
return trimmed;
}
var builder = new StringBuilder(segments[0]).Append(',');
for (var index = 1; index < segments.Length; index++)
{
var material = segments[index].Trim();
if (material.Length == 0)
{
continue;
}
builder.Append(material).Append(',');
}
return builder.ToString();
}
public static bool HasEmptyMaterialSlot(string? description)
{
if (string.IsNullOrWhiteSpace(description))
{
return false;
}
var segments = description.Trim().Split(',');
for (var index = 1; index < segments.Length - 1; index++)
{
if (segments[index].Length == 0)
{
return true;
}
}
return false;
}
}