update meta group & tags

This commit is contained in:
Mikhail 2024-06-19 00:18:59 +08:00
parent ab3a4a758b
commit e2feab383c
2 changed files with 21 additions and 10 deletions

View File

@ -4,9 +4,12 @@ using System.Text.RegularExpressions;
namespace DCFApixels.DragonECS
{
using static MetaGroupAttribute;
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class MetaGroupAttribute : EcsMetaAttribute
{
public const char SEPARATOR = '/';
public readonly MetaGroup Data;
[Obsolete("With empty parameters, this attribute makes no sense.")]
@ -15,10 +18,12 @@ namespace DCFApixels.DragonECS
{
Data = new MetaGroup(name);
}
public MetaGroupAttribute(params string[] path)
{
Data = new MetaGroup(string.Join("/", path));
}
//public MetaGroupAttribute(string name0, string name1) : this($"{name0}/{name1}") { }
//public MetaGroupAttribute(string name0, string name1, string name2) : this($"{name0}/{name1}/{name2}") { }
//public MetaGroupAttribute(string name0, string name1, string name2, string name3) : this($"{name0}/{name1}/{name2}/{name3}") { }
//public MetaGroupAttribute(string name0, string name1, string name2, string name3, string name4) : this($"{name0}/{name1}/{name2}/{name3}/{name4}") { }
//public MetaGroupAttribute(string name0, string name1, string name2, string name3, string name4, string name5) : this($"{name0}/{name1}/{name2}/{name3}/{name4}/{name5}") { }
public MetaGroupAttribute(params string[] path) : this(string.Join(SEPARATOR, path)) { }
}
public class MetaGroup
{
@ -33,7 +38,7 @@ namespace DCFApixels.DragonECS
{
if (_path == null)
{
_path = EcsMetaAttributeHalper.Split('/', Name);
_path = EcsMetaAttributeHalper.Split(SEPARATOR, Name);
}
return _path;
}
@ -45,10 +50,10 @@ namespace DCFApixels.DragonECS
Name = string.Empty;
return;
}
name = name.Replace('\\', '/');
if (name[name.Length - 1] != '/')
name = name.Replace('\\', SEPARATOR);
if (name[name.Length - 1] != SEPARATOR)
{
name += '/';
name += SEPARATOR;
}
Name = Regex.Replace(name, _pattern, "");
Name = string.Intern(Name);

View File

@ -6,6 +6,7 @@ namespace DCFApixels.DragonECS
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class MetaTagsAttribute : EcsMetaAttribute
{
public const char SEPARATOR = ',';
private readonly string[] _tags = Array.Empty<string>();
public IReadOnlyList<string> Tags
{
@ -16,13 +17,18 @@ namespace DCFApixels.DragonECS
public MetaTagsAttribute() { }
public MetaTagsAttribute(string tags)
{
_tags = EcsMetaAttributeHalper.Split(',', tags);
_tags = EcsMetaAttributeHalper.Split(SEPARATOR, tags);
for (int i = 0; i < _tags.Length; i++)
{
_tags[i] = string.Intern(_tags[i]);
}
}
public MetaTagsAttribute(params string[] tags) : this(string.Join(',', tags)) { }
//public MetaTagsAttribute(string tag0, string tag1) : this($"{tag0},{tag1}") { }
//public MetaTagsAttribute(string tag0, string tag1, string tag2) : this($"{tag0},{tag1},{tag2}") { }
//public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3) : this($"{tag0},{tag1},{tag2},{tag3}") { }
//public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3, string tag4) : this($"{tag0},{tag1},{tag2},{tag3},{tag4}") { }
//public MetaTagsAttribute(string tag0, string tag1, string tag2, string tag3, string tag4, string tag5) : this($"{tag0},{tag1},{tag2},{tag3},{tag4},{tag5}") { }
public MetaTagsAttribute(params string[] tags) : this(string.Join(SEPARATOR, tags)) { }
}
public readonly ref struct MetaTags
{