remove inheriting meta

This commit is contained in:
DCFApixels 2025-03-23 21:12:43 +08:00
parent d675be7146
commit 3e59e7a5bd
3 changed files with 18 additions and 52 deletions

View File

@ -26,7 +26,6 @@ namespace DCFApixels.DragonECS
public sealed class MetaColorAttribute : EcsMetaAttribute, IMetaColor public sealed class MetaColorAttribute : EcsMetaAttribute, IMetaColor
{ {
public readonly MetaColor color; public readonly MetaColor color;
public readonly Type InheritingColorType;
#region Properties #region Properties
public byte R public byte R
@ -72,10 +71,6 @@ namespace DCFApixels.DragonECS
{ {
color = new MetaColor(colorCode, true); color = new MetaColor(colorCode, true);
} }
public MetaColorAttribute(Type inheritingColorType)
{
InheritingColorType = inheritingColorType;
}
#endregion #endregion
} }
[Serializable] [Serializable]

View File

@ -13,24 +13,12 @@ namespace DCFApixels.DragonECS
public sealed class MetaGroupAttribute : EcsMetaAttribute public sealed class MetaGroupAttribute : EcsMetaAttribute
{ {
public const char SEPARATOR = MetaGroup.SEPARATOR; public const char SEPARATOR = MetaGroup.SEPARATOR;
public readonly Type InheritingGroupType = null; public readonly string Name = string.Empty;
public readonly string RelativeName = string.Empty;
[Obsolete(EcsMetaAttributeHalper.EMPTY_NO_SENSE_MESSAGE)] [Obsolete(EcsMetaAttributeHalper.EMPTY_NO_SENSE_MESSAGE)]
public MetaGroupAttribute() { } public MetaGroupAttribute() { }
public MetaGroupAttribute(string name) { RelativeName = name; } public MetaGroupAttribute(string name) { Name = name; }
public MetaGroupAttribute(params string[] path) { RelativeName = string.Join(SEPARATOR, path); } public MetaGroupAttribute(params string[] path) { Name = string.Join(SEPARATOR, path); }
public MetaGroupAttribute(Type inheritingGroupType) { InheritingGroupType = inheritingGroupType; }
public MetaGroupAttribute(Type inheritingGroupType, string relativeName)
{
InheritingGroupType = inheritingGroupType;
RelativeName = relativeName;
}
public MetaGroupAttribute(Type inheritingGroupType, params string[] relativePath)
{
InheritingGroupType = inheritingGroupType;
RelativeName = string.Join(SEPARATOR, relativePath);
}
} }
[DebuggerDisplay("{Name}")] [DebuggerDisplay("{Name}")]
public class MetaGroup public class MetaGroup
@ -39,9 +27,8 @@ namespace DCFApixels.DragonECS
private const string SEPARATOR_STR = "/"; private const string SEPARATOR_STR = "/";
public const string UNGROUPED = "<UNGROUPED>"; public const string UNGROUPED = "<UNGROUPED>";
private const string PATTERN = @"Module(?=/)"; private const string PATTERN = @"Module(?=/)";
public static readonly MetaGroup Empty = new MetaGroup(null, UNGROUPED); public static readonly MetaGroup Empty = new MetaGroup(UNGROUPED);
public readonly MetaGroup ParentGroup;
public readonly string Name; public readonly string Name;
private string[] _splited = null; private string[] _splited = null;
public IReadOnlyCollection<string> Splited public IReadOnlyCollection<string> Splited
@ -59,7 +46,7 @@ namespace DCFApixels.DragonECS
{ {
get { return this == Empty; } get { return this == Empty; }
} }
private MetaGroup(MetaGroup parentGroup, string name) private MetaGroup(string name)
{ {
if (string.IsNullOrEmpty(name)) if (string.IsNullOrEmpty(name))
{ {
@ -79,27 +66,12 @@ namespace DCFApixels.DragonECS
Name = string.Intern(Name); Name = string.Intern(Name);
} }
public static MetaGroup FromName(string name) public static MetaGroup FromName(string name)
{
return FromName(null, name);
}
public static MetaGroup FromName(MetaGroup parentGroup, string name)
{
if(parentGroup == null || parentGroup == Empty)
{ {
if (string.IsNullOrWhiteSpace(name)) if (string.IsNullOrWhiteSpace(name))
{ {
return Empty; return Empty;
} }
return new MetaGroup(null, name); return new MetaGroup(name);
}
else
{
if (string.IsNullOrWhiteSpace(name))
{
return new MetaGroup(parentGroup, parentGroup.Name);
}
return new MetaGroup(parentGroup, parentGroup.Name + name);
}
} }
public static MetaGroup FromNameSpace(Type type) public static MetaGroup FromNameSpace(Type type)
{ {
@ -107,7 +79,7 @@ namespace DCFApixels.DragonECS
{ {
return Empty; return Empty;
} }
return new MetaGroup(null, type.Namespace.Replace('.', SEPARATOR)); return new MetaGroup(type.Namespace.Replace('.', SEPARATOR));
} }
public override string ToString() { return Name; } public override string ToString() { return Name; }
} }

View File

@ -521,19 +521,11 @@ namespace DCFApixels.DragonECS
} }
return MetaColor.FromHashCode(hash).UpContrast(); return MetaColor.FromHashCode(hash).UpContrast();
} }
private static MetaColor GetColorFromAttribute(MetaColorAttribute atr)
{
if(atr.InheritingColorType == null)
{
return atr.color;
}
return atr.InheritingColorType.ToMeta().Color;
}
public static (MetaColor, bool) GetColor(TypeMeta meta) public static (MetaColor, bool) GetColor(TypeMeta meta)
{ {
#if DEBUG || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает #if DEBUG || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает
bool isCustom = meta.Type.TryGetAttribute(out MetaColorAttribute atr); bool isCustom = meta.Type.TryGetAttribute(out MetaColorAttribute atr);
return (isCustom ? GetColorFromAttribute(atr) : AutoColor(meta), isCustom); return (isCustom ? atr.color : AutoColor(meta), isCustom);
#else #else
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetColor)} method does not work."); EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetColor)} method does not work.");
return (MetaColor.White, false); return (MetaColor.White, false);
@ -545,7 +537,14 @@ namespace DCFApixels.DragonECS
public static MetaGroup GetGroup(Type type) public static MetaGroup GetGroup(Type type)
{ {
#if DEBUG || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает #if DEBUG || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает
return type.TryGetAttribute(out MetaGroupAttribute atr) ? MetaGroup.FromName(atr.InheritingGroupType.GetMeta().Group, atr.RelativeName) : MetaGroup.FromNameSpace(type); if (type.TryGetAttribute(out MetaGroupAttribute atr))
{
return MetaGroup.FromName(atr.Name);
}
else
{
return MetaGroup.FromNameSpace(type);
}
#else #else
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetGroup)} method does not work."); EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetGroup)} method does not work.");
return MetaGroup.Empty; return MetaGroup.Empty;