update debug attributes

rename DebugName attributes to MetaName attributes
rework DebugHide to MetaTags
This commit is contained in:
Mikhail 2023-12-20 23:16:57 +08:00
parent a912b4716d
commit 4b0d188955
22 changed files with 183 additions and 128 deletions

View File

@ -6,21 +6,25 @@ using System;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
#region Interfaces #region Interfaces
[MetaName(nameof(PreInit))]
[BindWithEcsRunner(typeof(EcsPreInitProcessRunner))] [BindWithEcsRunner(typeof(EcsPreInitProcessRunner))]
public interface IEcsPreInitProcess : IEcsProcess public interface IEcsPreInitProcess : IEcsProcess
{ {
void PreInit(); void PreInit();
} }
[MetaName(nameof(Init))]
[BindWithEcsRunner(typeof(EcsInitProcessRunner))] [BindWithEcsRunner(typeof(EcsInitProcessRunner))]
public interface IEcsInitProcess : IEcsProcess public interface IEcsInitProcess : IEcsProcess
{ {
void Init(); void Init();
} }
[MetaName(nameof(Run))]
[BindWithEcsRunner(typeof(EcsRunProcessRunner))] [BindWithEcsRunner(typeof(EcsRunProcessRunner))]
public interface IEcsRunProcess : IEcsProcess public interface IEcsRunProcess : IEcsProcess
{ {
void Run(); void Run();
} }
[MetaName(nameof(Destroy))]
[BindWithEcsRunner(typeof(EcsDestroyProcessRunner))] [BindWithEcsRunner(typeof(EcsDestroyProcessRunner))]
public interface IEcsDestroyProcess : IEcsProcess public interface IEcsDestroyProcess : IEcsProcess
{ {
@ -31,7 +35,7 @@ namespace DCFApixels.DragonECS
namespace Internal namespace Internal
{ {
[DebugColor(DebugColor.Orange)] [MetaColor(MetaColor.Orange)]
public sealed class EcsPreInitProcessRunner : EcsRunner<IEcsPreInitProcess>, IEcsPreInitProcess public sealed class EcsPreInitProcessRunner : EcsRunner<IEcsPreInitProcess>, IEcsPreInitProcess
{ {
#if DEBUG && !DISABLE_DEBUG #if DEBUG && !DISABLE_DEBUG
@ -79,7 +83,7 @@ namespace DCFApixels.DragonECS
#endif #endif
} }
} }
[DebugColor(DebugColor.Orange)] [MetaColor(MetaColor.Orange)]
public sealed class EcsInitProcessRunner : EcsRunner<IEcsInitProcess>, IEcsInitProcess public sealed class EcsInitProcessRunner : EcsRunner<IEcsInitProcess>, IEcsInitProcess
{ {
#if DEBUG && !DISABLE_DEBUG #if DEBUG && !DISABLE_DEBUG
@ -127,7 +131,7 @@ namespace DCFApixels.DragonECS
#endif #endif
} }
} }
[DebugColor(DebugColor.Orange)] [MetaColor(MetaColor.Orange)]
public sealed class EcsRunProcessRunner : EcsRunner<IEcsRunProcess>, IEcsRunProcess public sealed class EcsRunProcessRunner : EcsRunner<IEcsRunProcess>, IEcsRunProcess
{ {
#if DEBUG && !DISABLE_DEBUG #if DEBUG && !DISABLE_DEBUG
@ -175,7 +179,7 @@ namespace DCFApixels.DragonECS
#endif #endif
} }
} }
[DebugColor(DebugColor.Orange)] [MetaColor(MetaColor.Orange)]
public sealed class EcsDestroyProcessRunner : EcsRunner<IEcsDestroyProcess>, IEcsDestroyProcess public sealed class EcsDestroyProcessRunner : EcsRunner<IEcsDestroyProcess>, IEcsDestroyProcess
{ {
#if DEBUG && !DISABLE_DEBUG #if DEBUG && !DISABLE_DEBUG
@ -185,11 +189,11 @@ namespace DCFApixels.DragonECS
_markers = new EcsProfilerMarker[targets.Length]; _markers = new EcsProfilerMarker[targets.Length];
for (int i = 0; i < targets.Length; i++) for (int i = 0; i < targets.Length; i++)
{ {
_markers[i] = new EcsProfilerMarker($"{targets[i].GetType().Name}.{nameof(Destroy)}"); _markers[i] = new EcsProfilerMarker($"{targets[i].GetType().Name}.{nameof(IEcsDestroyProcess.Destroy)}");
} }
} }
#endif #endif
public void Destroy() void IEcsDestroyProcess.Destroy()
{ {
#if DEBUG && !DISABLE_DEBUG #if DEBUG && !DISABLE_DEBUG
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++) for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)

View File

@ -5,16 +5,19 @@ using System.Linq;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
[MetaName(nameof(PreInject))]
[BindWithEcsRunner(typeof(EcsPreInjectRunner))] [BindWithEcsRunner(typeof(EcsPreInjectRunner))]
public interface IEcsPreInject : IEcsProcess public interface IEcsPreInject : IEcsProcess
{ {
void PreInject(object obj); void PreInject(object obj);
} }
[MetaName(nameof(Inject))]
[BindWithEcsRunner(typeof(EcsInjectRunner<>))] [BindWithEcsRunner(typeof(EcsInjectRunner<>))]
public interface IEcsInject<T> : IEcsProcess public interface IEcsInject<T> : IEcsProcess
{ {
void Inject(T obj); void Inject(T obj);
} }
[MetaName("PreInitInject")]
[BindWithEcsRunner(typeof(EcsPreInitInjectProcessRunner))] [BindWithEcsRunner(typeof(EcsPreInitInjectProcessRunner))]
public interface IEcsPreInitInjectProcess : IEcsProcess public interface IEcsPreInitInjectProcess : IEcsProcess
{ {
@ -47,7 +50,8 @@ namespace DCFApixels.DragonECS
_injectSystems = null; _injectSystems = null;
} }
} }
[DebugHide, DebugColor(DebugColor.Gray)] [MetaTags(MetaTags.HIDDEN)]
[MetaColor(MetaColor.Gray)]
public sealed class EcsPreInjectRunner : EcsRunner<IEcsPreInject>, IEcsPreInject public sealed class EcsPreInjectRunner : EcsRunner<IEcsPreInject>, IEcsPreInject
{ {
void IEcsPreInject.PreInject(object obj) void IEcsPreInject.PreInject(object obj)
@ -55,7 +59,8 @@ namespace DCFApixels.DragonECS
foreach (var item in targets) item.PreInject(obj); foreach (var item in targets) item.PreInject(obj);
} }
} }
[DebugHide, DebugColor(DebugColor.Gray)] [MetaTags(MetaTags.HIDDEN)]
[MetaColor(MetaColor.Gray)]
public sealed class EcsInjectRunner<T> : EcsRunner<IEcsInject<T>>, IEcsInject<T> public sealed class EcsInjectRunner<T> : EcsRunner<IEcsInject<T>>, IEcsInject<T>
{ {
private EcsBaseTypeInjectRunner _baseTypeInjectRunner; private EcsBaseTypeInjectRunner _baseTypeInjectRunner;
@ -91,7 +96,8 @@ namespace DCFApixels.DragonECS
public override void Inject(object obj) => _runner.PreInject(obj); public override void Inject(object obj) => _runner.PreInject(obj);
} }
[DebugHide, DebugColor(DebugColor.Gray)] [MetaTags(MetaTags.HIDDEN)]
[MetaColor(MetaColor.Gray)]
public sealed class EcsPreInitInjectProcessRunner : EcsRunner<IEcsPreInitInjectProcess>, IEcsPreInitInjectProcess public sealed class EcsPreInitInjectProcessRunner : EcsRunner<IEcsPreInitInjectProcess>, IEcsPreInitInjectProcess
{ {
public void OnPreInitInjectionAfter() public void OnPreInitInjectionAfter()
@ -103,8 +109,10 @@ namespace DCFApixels.DragonECS
foreach (var item in targets) item.OnPreInitInjectionBefore(); foreach (var item in targets) item.OnPreInitInjectionBefore();
} }
} }
public class InjectSystemBase { } public abstract class InjectSystemBase { }
[DebugHide, DebugColor(DebugColor.Gray)]
[MetaTags(MetaTags.HIDDEN)]
[MetaColor(MetaColor.Gray)]
public class InjectSystem<T> : InjectSystemBase, IEcsInject<EcsPipeline>, IEcsPreInitProcess, IEcsInject<PreInitInjectController>, IEcsPreInitInjectProcess public class InjectSystem<T> : InjectSystemBase, IEcsInject<EcsPipeline>, IEcsPreInitProcess, IEcsInject<PreInitInjectController>, IEcsPreInitInjectProcess
{ {
private EcsPipeline _pipeline; private EcsPipeline _pipeline;

View File

@ -5,13 +5,15 @@ namespace DCFApixels.DragonECS
{ {
namespace Internal namespace Internal
{ {
[DebugHide, DebugColor(DebugColor.Black)] [MetaTags(MetaTags.HIDDEN)]
[MetaColor(MetaColor.Black)]
public class SystemsLayerMarkerSystem : IEcsProcess public class SystemsLayerMarkerSystem : IEcsProcess
{ {
public readonly string name; public readonly string name;
public SystemsLayerMarkerSystem(string name) => this.name = name; public SystemsLayerMarkerSystem(string name) => this.name = name;
} }
[DebugHide, DebugColor(DebugColor.Grey)] [MetaTags(MetaTags.HIDDEN)]
[MetaColor(MetaColor.Grey)]
public class EndFrameSystem : IEcsRunProcess, IEcsInject<EcsWorld> public class EndFrameSystem : IEcsRunProcess, IEcsInject<EcsWorld>
{ {
private readonly List<EcsWorld> _worlds = new List<EcsWorld>(); private readonly List<EcsWorld> _worlds = new List<EcsWorld>();
@ -25,7 +27,8 @@ namespace DCFApixels.DragonECS
} }
} }
} }
[DebugHide, DebugColor(DebugColor.Grey)] [MetaTags(MetaTags.HIDDEN)]
[MetaColor(MetaColor.Grey)]
public class DeleteOneFrameComponentSystem<TComponent> : IEcsRunProcess, IEcsInject<EcsWorld> public class DeleteOneFrameComponentSystem<TComponent> : IEcsRunProcess, IEcsInject<EcsWorld>
where TComponent : struct, IEcsComponent where TComponent : struct, IEcsComponent
{ {

View File

@ -14,5 +14,7 @@
public const string BASIC_LAYER = nameof(BASIC_LAYER); public const string BASIC_LAYER = nameof(BASIC_LAYER);
public const string END_LAYER = nameof(END_LAYER); public const string END_LAYER = nameof(END_LAYER);
public const string POST_END_LAYER = nameof(POST_END_LAYER); public const string POST_END_LAYER = nameof(POST_END_LAYER);
public const string META_HIDDEN_TAG = "HiddenInDebagging";
} }
} }

View File

@ -1,11 +0,0 @@
using System;
namespace DCFApixels.DragonECS
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
public sealed class DebugDescriptionAttribute : Attribute
{
public readonly string description;
public DebugDescriptionAttribute(string description) => this.description = description;
}
}

View File

@ -1,7 +0,0 @@
using System;
namespace DCFApixels.DragonECS
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
public sealed class DebugHideAttribute : Attribute { }
}

View File

@ -1,11 +0,0 @@
using System;
namespace DCFApixels.DragonECS
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
public sealed class DebugNameAttribute : Attribute
{
public readonly string name;
public DebugNameAttribute(string name) => this.name = name;
}
}

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@ -67,7 +68,7 @@ namespace DCFApixels.DragonECS
GetName(type: obj.GetType(), maxGenericDepth); GetName(type: obj.GetType(), maxGenericDepth);
} }
public static string GetName<T>(int maxGenericDepth = 2) => GetName(typeof(T), maxGenericDepth); public static string GetName<T>(int maxGenericDepth = 2) => GetName(typeof(T), maxGenericDepth);
public static string GetName(Type type, int maxGenericDepth = 2) => type.TryGetCustomAttribute(out DebugNameAttribute atr) ? atr.name : GetGenericTypeName(type, maxGenericDepth); public static string GetName(Type type, int maxGenericDepth = 2) => type.TryGetCustomAttribute(out MetaNameAttribute atr) ? atr.name : GetGenericTypeName(type, maxGenericDepth);
public static bool TryGetCustomName(object obj, out string name) public static bool TryGetCustomName(object obj, out string name)
{ {
return obj is IEcsDebugMetaProvider intr ? return obj is IEcsDebugMetaProvider intr ?
@ -77,7 +78,7 @@ namespace DCFApixels.DragonECS
public static bool TryGetCustomName<T>(out string name) => TryGetCustomName(type: typeof(T), out name); public static bool TryGetCustomName<T>(out string name) => TryGetCustomName(type: typeof(T), out name);
public static bool TryGetCustomName(Type type, out string name) public static bool TryGetCustomName(Type type, out string name)
{ {
if (type.TryGetCustomAttribute(out DebugNameAttribute atr)) if (type.TryGetCustomAttribute(out MetaNameAttribute atr))
{ {
name = atr.name; name = atr.name;
return true; return true;
@ -88,29 +89,29 @@ namespace DCFApixels.DragonECS
#endregion #endregion
#region GetGroup #region GetGroup
public static DebugGroup GetGroup(object obj) public static MetaGroup GetGroup(object obj)
{ {
return obj is IEcsDebugMetaProvider intr ? return obj is IEcsDebugMetaProvider intr ?
GetGroup(intr.DebugMetaSource) : GetGroup(intr.DebugMetaSource) :
GetGroup(type: obj.GetType()); GetGroup(type: obj.GetType());
} }
public static DebugGroup GetGroup<T>() => GetGroup(typeof(T)); public static MetaGroup GetGroup<T>() => GetGroup(typeof(T));
public static DebugGroup GetGroup(Type type) => type.TryGetCustomAttribute(out DebugGroupAttribute atr) ? atr.GetData() : DebugGroup.Empty; public static MetaGroup GetGroup(Type type) => type.TryGetCustomAttribute(out MetaGroupAttribute atr) ? atr.GetData() : MetaGroup.Empty;
public static bool TryGetGroup(object obj, out DebugGroup group) public static bool TryGetGroup(object obj, out MetaGroup group)
{ {
return obj is IEcsDebugMetaProvider intr ? return obj is IEcsDebugMetaProvider intr ?
TryGetGroup(intr.DebugMetaSource, out group) : TryGetGroup(intr.DebugMetaSource, out group) :
TryGetGroup(type: obj.GetType(), out group); TryGetGroup(type: obj.GetType(), out group);
} }
public static bool TryGetGroup<T>(out DebugGroup text) => TryGetGroup(typeof(T), out text); public static bool TryGetGroup<T>(out MetaGroup text) => TryGetGroup(typeof(T), out text);
public static bool TryGetGroup(Type type, out DebugGroup group) public static bool TryGetGroup(Type type, out MetaGroup group)
{ {
if (type.TryGetCustomAttribute(out DebugGroupAttribute atr)) if (type.TryGetCustomAttribute(out MetaGroupAttribute atr))
{ {
group = atr.GetData(); group = atr.GetData();
return true; return true;
} }
group = DebugGroup.Empty; group = MetaGroup.Empty;
return false; return false;
} }
#endregion #endregion
@ -123,7 +124,7 @@ namespace DCFApixels.DragonECS
GetDescription(type: obj.GetType()); GetDescription(type: obj.GetType());
} }
public static string GetDescription<T>() => GetDescription(typeof(T)); public static string GetDescription<T>() => GetDescription(typeof(T));
public static string GetDescription(Type type) => type.TryGetCustomAttribute(out DebugDescriptionAttribute atr) ? atr.description : string.Empty; public static string GetDescription(Type type) => type.TryGetCustomAttribute(out MetaDescriptionAttribute atr) ? atr.description : string.Empty;
public static bool TryGetDescription(object obj, out string text) public static bool TryGetDescription(object obj, out string text)
{ {
return obj is IEcsDebugMetaProvider intr ? return obj is IEcsDebugMetaProvider intr ?
@ -133,7 +134,7 @@ namespace DCFApixels.DragonECS
public static bool TryGetDescription<T>(out string text) => TryGetDescription(typeof(T), out text); public static bool TryGetDescription<T>(out string text) => TryGetDescription(typeof(T), out text);
public static bool TryGetDescription(Type type, out string text) public static bool TryGetDescription(Type type, out string text)
{ {
if (type.TryGetCustomAttribute(out DebugDescriptionAttribute atr)) if (type.TryGetCustomAttribute(out MetaDescriptionAttribute atr))
{ {
text = atr.description; text = atr.description;
return true; return true;
@ -149,7 +150,7 @@ namespace DCFApixels.DragonECS
private class WordColor private class WordColor
{ {
public int wordsCount; public int wordsCount;
public DebugColor color; public MetaColor color;
} }
private class NameColor private class NameColor
{ {
@ -162,7 +163,7 @@ namespace DCFApixels.DragonECS
{ {
color = new WordColor(); color = new WordColor();
_words.Add(word, color); _words.Add(word, color);
color.color = new DebugColor((byte)random.Next(), (byte)random.Next(), (byte)random.Next()).UpContrastColor() / 2; color.color = new MetaColor((byte)random.Next(), (byte)random.Next(), (byte)random.Next()).UpContrastColor() / 2;
} }
color.wordsCount++; color.wordsCount++;
colors.Add(color); colors.Add(color);
@ -177,7 +178,7 @@ namespace DCFApixels.DragonECS
} }
return result; return result;
} }
public DebugColor CalcColor() public MetaColor CalcColor()
{ {
float r = 0, g = 0, b = 0; float r = 0, g = 0, b = 0;
int totalWordsCount = CalcTotalWordsColor(); int totalWordsCount = CalcTotalWordsColor();
@ -189,11 +190,11 @@ namespace DCFApixels.DragonECS
g += m * color.color.g; g += m * color.color.g;
b += m * color.color.b; b += m * color.color.b;
} }
return new DebugColor((byte)r, (byte)g, (byte)b); return new MetaColor((byte)r, (byte)g, (byte)b);
} }
} }
private static Dictionary<Type, NameColor> _names = new Dictionary<Type, NameColor>(); private static Dictionary<Type, NameColor> _names = new Dictionary<Type, NameColor>();
private static DebugColor CalcNameColorFor(Type type) private static MetaColor CalcNameColorFor(Type type)
{ {
Type targetType = type.IsGenericType ? type.GetGenericTypeDefinition() : type; Type targetType = type.IsGenericType ? type.GetGenericTypeDefinition() : type;
if (!_names.TryGetValue(targetType, out NameColor nameColor)) if (!_names.TryGetValue(targetType, out NameColor nameColor))
@ -224,39 +225,73 @@ namespace DCFApixels.DragonECS
return words; return words;
} }
public static DebugColor GetColor(object obj) public static MetaColor GetColor(object obj)
{ {
return obj is IEcsDebugMetaProvider intr ? return obj is IEcsDebugMetaProvider intr ?
GetColor(intr.DebugMetaSource) : GetColor(intr.DebugMetaSource) :
GetColor(type: obj.GetType()); GetColor(type: obj.GetType());
} }
public static DebugColor GetColor<T>() => GetColor(typeof(T)); public static MetaColor GetColor<T>() => GetColor(typeof(T));
public static DebugColor GetColor(Type type) public static MetaColor GetColor(Type type)
{ {
var atr = type.GetCustomAttribute<DebugColorAttribute>(); var atr = type.GetCustomAttribute<MetaColorAttribute>();
return atr != null ? atr.color return atr != null ? atr.color
#if DEBUG //optimization for release build #if DEBUG //optimization for release build
: CalcNameColorFor(type); : CalcNameColorFor(type);
#else #else
: DebugColor.BlackColor; : MetaColor.BlackColor;
#endif #endif
} }
public static bool TryGetColor(object obj, out DebugColor color) public static bool TryGetColor(object obj, out MetaColor color)
{ {
return obj is IEcsDebugMetaProvider intr ? return obj is IEcsDebugMetaProvider intr ?
TryGetColor(intr.DebugMetaSource, out color) : TryGetColor(intr.DebugMetaSource, out color) :
TryGetColor(type: obj.GetType(), out color); TryGetColor(type: obj.GetType(), out color);
} }
public static bool TryGetColor<T>(out DebugColor color) => TryGetColor(typeof(T), out color); public static bool TryGetColor<T>(out MetaColor color) => TryGetColor(typeof(T), out color);
public static bool TryGetColor(Type type, out DebugColor color) public static bool TryGetColor(Type type, out MetaColor color)
{ {
var atr = type.GetCustomAttribute<DebugColorAttribute>(); var atr = type.GetCustomAttribute<MetaColorAttribute>();
if (atr != null) if (atr != null)
{ {
color = atr.color; color = atr.color;
return true; return true;
} }
color = DebugColor.BlackColor; color = MetaColor.BlackColor;
return false;
}
#endregion
#region GetTags
public static IReadOnlyCollection<string> GetTags(object obj)
{
return obj is IEcsDebugMetaProvider intr ?
GetTags(intr.DebugMetaSource) :
GetTags(type: obj.GetType());
}
public static IReadOnlyCollection<string> GetTags<T>() => GetTags(typeof(T));
public static IReadOnlyCollection<string> GetTags(Type type)
{
var atr = type.GetCustomAttribute<MetaTagsAttribute>();
return atr != null ? atr.Tags : Array.Empty<string>();
}
public static bool TryGetTags(object obj, out IReadOnlyCollection<string> tags)
{
return obj is IEcsDebugMetaProvider intr ?
TryGetTags(intr.DebugMetaSource, out tags) :
TryGetTags(type: obj.GetType(), out tags);
}
public static bool TryGetTags<T>(out IReadOnlyCollection<string> tags) => TryGetTags(typeof(T), out tags);
public static bool TryGetTags(Type type, out IReadOnlyCollection<string> tags)
{
var atr = type.GetCustomAttribute<MetaTagsAttribute>();
if (atr != null)
{
tags = atr.Tags;
return true;
}
tags = Array.Empty<string>();
return false; return false;
} }
#endregion #endregion
@ -269,7 +304,7 @@ namespace DCFApixels.DragonECS
IsHidden(type: obj.GetType()); IsHidden(type: obj.GetType());
} }
public static bool IsHidden<T>() => IsHidden(typeof(T)); public static bool IsHidden<T>() => IsHidden(typeof(T));
public static bool IsHidden(Type type) => type.TryGetCustomAttribute(out DebugHideAttribute _); public static bool IsHidden(Type type) => type.TryGetCustomAttribute(out MetaTagsAttribute atr) && atr.Tags.Contains(MetaTags.HIDDEN);
#endregion #endregion
#region MetaSource #region MetaSource
@ -284,22 +319,22 @@ namespace DCFApixels.DragonECS
#endregion #endregion
#region GenerateTypeDebugData #region GenerateTypeDebugData
public static TypeDebugData GenerateTypeDebugData(object obj) public static TypeMetaData GenerateTypeDebugData(object obj)
{ {
return obj is IEcsDebugMetaProvider intr ? return obj is IEcsDebugMetaProvider intr ?
GenerateTypeDebugData(intr.DebugMetaSource) : GenerateTypeDebugData(intr.DebugMetaSource) :
GenerateTypeDebugData(type: obj.GetType()); GenerateTypeDebugData(type: obj.GetType());
} }
public static TypeDebugData GenerateTypeDebugData<T>() => GenerateTypeDebugData(typeof(T)); public static TypeMetaData GenerateTypeDebugData<T>() => GenerateTypeDebugData(typeof(T));
public static TypeDebugData GenerateTypeDebugData(Type type) public static TypeMetaData GenerateTypeDebugData(Type type)
{ {
return new TypeDebugData( return new TypeMetaData(
type, type,
GetName(type), GetName(type),
GetGroup(type), GetGroup(type),
GetColor(type), GetColor(type),
GetDescription(type), GetDescription(type),
IsHidden(type)); GetTags(type).ToArray());
} }
#endregion #endregion
@ -320,22 +355,22 @@ namespace DCFApixels.DragonECS
} }
[Serializable] [Serializable]
public sealed class TypeDebugData public sealed class TypeMetaData
{ {
public readonly Type type; public readonly Type type;
public readonly string name; public readonly string name;
public readonly DebugGroup group; public readonly MetaGroup group;
public readonly DebugColor color; public readonly MetaColor color;
public readonly string description; public readonly string description;
public readonly bool isHidden; public readonly string[] tags;
public TypeDebugData(Type type, string name, DebugGroup group, DebugColor color, string description, bool isHidden) public TypeMetaData(Type type, string name, MetaGroup group, MetaColor color, string description, string[] tags)
{ {
this.type = type; this.type = type;
this.name = name; this.name = name;
this.group = group; this.group = group;
this.color = color; this.color = color;
this.description = description; this.description = description;
this.isHidden = isHidden; this.tags = tags;
} }
} }
} }

View File

@ -3,20 +3,23 @@ using System.Runtime.InteropServices;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class DebugColorAttribute : Attribute public sealed class MetaColorAttribute : Attribute
{ {
public readonly DebugColor color; public readonly MetaColor color;
public byte r => color.r; public byte R => color.r;
public byte g => color.g; public byte G => color.g;
public byte b => color.b; public byte B => color.b;
public DebugColorAttribute(byte r, byte g, byte b) => color = new DebugColor(r, g, b, 255); public float FloatT => R / (float)byte.MaxValue;
public DebugColorAttribute(int colorCode) => color = new DebugColor(colorCode, true); public float FloatG => G / (float)byte.MaxValue;
public float FloatB => B / (float)byte.MaxValue;
public MetaColorAttribute(byte r, byte g, byte b) => color = new MetaColor(r, g, b, 255);
public MetaColorAttribute(int colorCode) => color = new MetaColor(colorCode, true);
} }
[StructLayout(LayoutKind.Explicit, Pack = 1, Size = 4)] [StructLayout(LayoutKind.Explicit, Pack = 1, Size = 4)]
public readonly struct DebugColor public readonly struct MetaColor
{ {
public static readonly DebugColor BlackColor = new DebugColor(Black); public static readonly MetaColor BlackColor = new MetaColor(Black);
/// <summary> color code Red. RGB is (255, 0, 0)</summary> /// <summary> color code Red. RGB is (255, 0, 0)</summary>
public const int Red = (255 << 24) | (000 << 16) | (000 << 8) | 255; public const int Red = (255 << 24) | (000 << 16) | (000 << 8) | 255;
/// <summary> color code Green. RGB is (0, 255, 0)</summary> /// <summary> color code Green. RGB is (0, 255, 0)</summary>
@ -66,37 +69,37 @@ namespace DCFApixels.DragonECS
[FieldOffset(2)] public readonly byte g; [FieldOffset(2)] public readonly byte g;
[FieldOffset(1)] public readonly byte b; [FieldOffset(1)] public readonly byte b;
[FieldOffset(0)] public readonly byte a; [FieldOffset(0)] public readonly byte a;
public DebugColor(byte r, byte g, byte b) : this() public MetaColor(byte r, byte g, byte b) : this()
{ {
this.r = r; this.r = r;
this.g = g; this.g = g;
this.b = b; this.b = b;
a = 255; a = 255;
} }
public DebugColor(byte r, byte g, byte b, byte a) : this() public MetaColor(byte r, byte g, byte b, byte a) : this()
{ {
this.r = r; this.r = r;
this.g = g; this.g = g;
this.b = b; this.b = b;
this.a = a; this.a = a;
} }
public DebugColor(int colorCode) : this() => this.colorCode = colorCode; public MetaColor(int colorCode) : this() => this.colorCode = colorCode;
public DebugColor(int colorCode, bool withoutAlpha) : this() => this.colorCode = withoutAlpha ? colorCode | 255 : colorCode; public MetaColor(int colorCode, bool withoutAlpha) : this() => this.colorCode = withoutAlpha ? colorCode | 255 : colorCode;
public (byte, byte, byte) ToTupleRGB() => (r, g, b); public (byte, byte, byte) ToTupleRGB() => (r, g, b);
public (byte, byte, byte, byte) ToTupleRGBA() => (r, g, b, a); public (byte, byte, byte, byte) ToTupleRGBA() => (r, g, b, a);
public DebugColor UpContrastColor() public MetaColor UpContrastColor()
{ {
byte minChannel = Math.Min(Math.Min(r, g), b); byte minChannel = Math.Min(Math.Min(r, g), b);
byte maxChannel = Math.Max(Math.Max(r, g), b); byte maxChannel = Math.Max(Math.Max(r, g), b);
if (maxChannel == minChannel) if (maxChannel == minChannel)
return default; return default;
float factor = 255f / (maxChannel - minChannel); float factor = 255f / (maxChannel - minChannel);
return new DebugColor((byte)((r - minChannel) * factor), (byte)((g - minChannel) * factor), (byte)((b - minChannel) * factor)); return new MetaColor((byte)((r - minChannel) * factor), (byte)((g - minChannel) * factor), (byte)((b - minChannel) * factor));
} }
public static DebugColor operator /(DebugColor a, float b) public static MetaColor operator /(MetaColor a, float b)
{ {
return new DebugColor((byte)(a.r / b), (byte)(a.g / b), (byte)(a.b / b)); return new MetaColor((byte)(a.r / b), (byte)(a.g / b), (byte)(a.b / b));
} }
} }
} }

View File

@ -0,0 +1,11 @@
using System;
namespace DCFApixels.DragonECS
{
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class MetaDescriptionAttribute : Attribute
{
public readonly string description;
public MetaDescriptionAttribute(string description) => this.description = description;
}
}

View File

@ -3,13 +3,13 @@ using System.Text.RegularExpressions;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class DebugGroupAttribute : Attribute public sealed class MetaGroupAttribute : Attribute
{ {
public static readonly DebugGroupAttribute Empty = new DebugGroupAttribute(""); public static readonly MetaGroupAttribute Empty = new MetaGroupAttribute("");
public readonly string name; public readonly string name;
public readonly string rootCategory; public readonly string rootCategory;
public DebugGroupAttribute(string name) public MetaGroupAttribute(string name)
{ {
name = Regex.Replace(name, @"^[/|\\]+|[/|\\]+$", ""); name = Regex.Replace(name, @"^[/|\\]+|[/|\\]+$", "");
rootCategory = Regex.Match(name, @"^(.*?)[/\\]").Groups[1].Value; rootCategory = Regex.Match(name, @"^(.*?)[/\\]").Groups[1].Value;
@ -19,15 +19,15 @@ namespace DCFApixels.DragonECS
{ {
return Regex.Split(name, @"[/|\\]"); return Regex.Split(name, @"[/|\\]");
} }
public DebugGroup GetData() => new DebugGroup(this); public MetaGroup GetData() => new MetaGroup(this);
} }
public readonly struct DebugGroup public readonly struct MetaGroup
{ {
public static readonly DebugGroup Empty = new DebugGroup(DebugGroupAttribute.Empty); public static readonly MetaGroup Empty = new MetaGroup(MetaGroupAttribute.Empty);
private readonly DebugGroupAttribute _source; private readonly MetaGroupAttribute _source;
public string Name => _source.name; public string Name => _source.name;
public string RootCategory => _source.rootCategory; public string RootCategory => _source.rootCategory;
public DebugGroup(DebugGroupAttribute source) => _source = source; public MetaGroup(MetaGroupAttribute source) => _source = source;
public string[] SplitCategories() => _source.SplitCategories(); public string[] SplitCategories() => _source.SplitCategories();
} }
} }

View File

@ -0,0 +1,11 @@
using System;
namespace DCFApixels.DragonECS
{
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class MetaNameAttribute : Attribute
{
public readonly string name;
public MetaNameAttribute(string name) => this.name = name;
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace DCFApixels.DragonECS
{
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class MetaTagsAttribute : Attribute
{
private readonly string[] _tags;
public IReadOnlyCollection<string> Tags => _tags;
[Obsolete("With empty parameters, this attribute makes no sense.", true)]
public MetaTagsAttribute() { }
public MetaTagsAttribute(params string[] tags)
{
_tags = tags.Where(o => !string.IsNullOrEmpty(o)).ToArray();
}
}
public readonly ref struct MetaTags
{
public const string HIDDEN = EcsConsts.META_HIDDEN_TAG;
}
}

View File

@ -1,5 +1,4 @@
using DCFApixels.DragonECS.Internal; using DCFApixels.DragonECS.RunnersCore;
using DCFApixels.DragonECS.RunnersCore;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@ -166,7 +165,7 @@ namespace DCFApixels.DragonECS
if(_subclass == null) if(_subclass == null)
{ {
Type interfaceType = typeof(TInterface); Type interfaceType = typeof(TInterface);
if (interfaceType.TryGetAttribute(out BindWithEcsRunnerAttribute atr)) if (interfaceType.TryGetCustomAttribute(out BindWithEcsRunnerAttribute atr))
{ {
Type runnerType = atr.runnerType; Type runnerType = atr.runnerType;
if (interfaceType.IsGenericType) if (interfaceType.IsGenericType)

View File

@ -2,9 +2,7 @@
using DCFApixels.DragonECS.Utils; using DCFApixels.DragonECS.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using static DCFApixels.DragonECS.EcsWorld;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {

View File

@ -1,14 +0,0 @@
using System;
using System.Reflection;
namespace DCFApixels.DragonECS.Internal
{
internal static class ReflectionExtensions
{
public static bool TryGetAttribute<T>(this MemberInfo self, out T attribute) where T : Attribute
{
attribute = self.GetCustomAttribute<T>();
return attribute != null;
}
}
}