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 readonly MetaColor color;
public readonly Type InheritingColorType;
#region Properties
public byte R
@ -72,10 +71,6 @@ namespace DCFApixels.DragonECS
{
color = new MetaColor(colorCode, true);
}
public MetaColorAttribute(Type inheritingColorType)
{
InheritingColorType = inheritingColorType;
}
#endregion
}
[Serializable]

View File

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

View File

@ -521,19 +521,11 @@ namespace DCFApixels.DragonECS
}
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)
{
#if DEBUG || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает
bool isCustom = meta.Type.TryGetAttribute(out MetaColorAttribute atr);
return (isCustom ? GetColorFromAttribute(atr) : AutoColor(meta), isCustom);
return (isCustom ? atr.color : AutoColor(meta), isCustom);
#else
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetColor)} method does not work.");
return (MetaColor.White, false);
@ -545,7 +537,14 @@ namespace DCFApixels.DragonECS
public static MetaGroup GetGroup(Type type)
{
#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
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetGroup)} method does not work.");
return MetaGroup.Empty;