mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-11-12 16:45:55 +08:00
update debug attributes
rename DebugName attributes to MetaName attributes rework DebugHide to MetaTags
This commit is contained in:
parent
a912b4716d
commit
4b0d188955
@ -6,21 +6,25 @@ using System;
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
#region Interfaces
|
||||
[MetaName(nameof(PreInit))]
|
||||
[BindWithEcsRunner(typeof(EcsPreInitProcessRunner))]
|
||||
public interface IEcsPreInitProcess : IEcsProcess
|
||||
{
|
||||
void PreInit();
|
||||
}
|
||||
[MetaName(nameof(Init))]
|
||||
[BindWithEcsRunner(typeof(EcsInitProcessRunner))]
|
||||
public interface IEcsInitProcess : IEcsProcess
|
||||
{
|
||||
void Init();
|
||||
}
|
||||
[MetaName(nameof(Run))]
|
||||
[BindWithEcsRunner(typeof(EcsRunProcessRunner))]
|
||||
public interface IEcsRunProcess : IEcsProcess
|
||||
{
|
||||
void Run();
|
||||
}
|
||||
[MetaName(nameof(Destroy))]
|
||||
[BindWithEcsRunner(typeof(EcsDestroyProcessRunner))]
|
||||
public interface IEcsDestroyProcess : IEcsProcess
|
||||
{
|
||||
@ -31,7 +35,7 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
namespace Internal
|
||||
{
|
||||
[DebugColor(DebugColor.Orange)]
|
||||
[MetaColor(MetaColor.Orange)]
|
||||
public sealed class EcsPreInitProcessRunner : EcsRunner<IEcsPreInitProcess>, IEcsPreInitProcess
|
||||
{
|
||||
#if DEBUG && !DISABLE_DEBUG
|
||||
@ -79,7 +83,7 @@ namespace DCFApixels.DragonECS
|
||||
#endif
|
||||
}
|
||||
}
|
||||
[DebugColor(DebugColor.Orange)]
|
||||
[MetaColor(MetaColor.Orange)]
|
||||
public sealed class EcsInitProcessRunner : EcsRunner<IEcsInitProcess>, IEcsInitProcess
|
||||
{
|
||||
#if DEBUG && !DISABLE_DEBUG
|
||||
@ -127,7 +131,7 @@ namespace DCFApixels.DragonECS
|
||||
#endif
|
||||
}
|
||||
}
|
||||
[DebugColor(DebugColor.Orange)]
|
||||
[MetaColor(MetaColor.Orange)]
|
||||
public sealed class EcsRunProcessRunner : EcsRunner<IEcsRunProcess>, IEcsRunProcess
|
||||
{
|
||||
#if DEBUG && !DISABLE_DEBUG
|
||||
@ -175,7 +179,7 @@ namespace DCFApixels.DragonECS
|
||||
#endif
|
||||
}
|
||||
}
|
||||
[DebugColor(DebugColor.Orange)]
|
||||
[MetaColor(MetaColor.Orange)]
|
||||
public sealed class EcsDestroyProcessRunner : EcsRunner<IEcsDestroyProcess>, IEcsDestroyProcess
|
||||
{
|
||||
#if DEBUG && !DISABLE_DEBUG
|
||||
@ -185,11 +189,11 @@ namespace DCFApixels.DragonECS
|
||||
_markers = new EcsProfilerMarker[targets.Length];
|
||||
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
|
||||
public void Destroy()
|
||||
void IEcsDestroyProcess.Destroy()
|
||||
{
|
||||
#if DEBUG && !DISABLE_DEBUG
|
||||
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
||||
|
||||
@ -5,16 +5,19 @@ using System.Linq;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
[MetaName(nameof(PreInject))]
|
||||
[BindWithEcsRunner(typeof(EcsPreInjectRunner))]
|
||||
public interface IEcsPreInject : IEcsProcess
|
||||
{
|
||||
void PreInject(object obj);
|
||||
}
|
||||
[MetaName(nameof(Inject))]
|
||||
[BindWithEcsRunner(typeof(EcsInjectRunner<>))]
|
||||
public interface IEcsInject<T> : IEcsProcess
|
||||
{
|
||||
void Inject(T obj);
|
||||
}
|
||||
[MetaName("PreInitInject")]
|
||||
[BindWithEcsRunner(typeof(EcsPreInitInjectProcessRunner))]
|
||||
public interface IEcsPreInitInjectProcess : IEcsProcess
|
||||
{
|
||||
@ -47,7 +50,8 @@ namespace DCFApixels.DragonECS
|
||||
_injectSystems = null;
|
||||
}
|
||||
}
|
||||
[DebugHide, DebugColor(DebugColor.Gray)]
|
||||
[MetaTags(MetaTags.HIDDEN)]
|
||||
[MetaColor(MetaColor.Gray)]
|
||||
public sealed class EcsPreInjectRunner : EcsRunner<IEcsPreInject>, IEcsPreInject
|
||||
{
|
||||
void IEcsPreInject.PreInject(object obj)
|
||||
@ -55,7 +59,8 @@ namespace DCFApixels.DragonECS
|
||||
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>
|
||||
{
|
||||
private EcsBaseTypeInjectRunner _baseTypeInjectRunner;
|
||||
@ -91,7 +96,8 @@ namespace DCFApixels.DragonECS
|
||||
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 void OnPreInitInjectionAfter()
|
||||
@ -103,8 +109,10 @@ namespace DCFApixels.DragonECS
|
||||
foreach (var item in targets) item.OnPreInitInjectionBefore();
|
||||
}
|
||||
}
|
||||
public class InjectSystemBase { }
|
||||
[DebugHide, DebugColor(DebugColor.Gray)]
|
||||
public abstract class InjectSystemBase { }
|
||||
|
||||
[MetaTags(MetaTags.HIDDEN)]
|
||||
[MetaColor(MetaColor.Gray)]
|
||||
public class InjectSystem<T> : InjectSystemBase, IEcsInject<EcsPipeline>, IEcsPreInitProcess, IEcsInject<PreInitInjectController>, IEcsPreInitInjectProcess
|
||||
{
|
||||
private EcsPipeline _pipeline;
|
||||
|
||||
@ -5,13 +5,15 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
namespace Internal
|
||||
{
|
||||
[DebugHide, DebugColor(DebugColor.Black)]
|
||||
[MetaTags(MetaTags.HIDDEN)]
|
||||
[MetaColor(MetaColor.Black)]
|
||||
public class SystemsLayerMarkerSystem : IEcsProcess
|
||||
{
|
||||
public readonly string name;
|
||||
public SystemsLayerMarkerSystem(string name) => this.name = name;
|
||||
}
|
||||
[DebugHide, DebugColor(DebugColor.Grey)]
|
||||
[MetaTags(MetaTags.HIDDEN)]
|
||||
[MetaColor(MetaColor.Grey)]
|
||||
public class EndFrameSystem : IEcsRunProcess, IEcsInject<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>
|
||||
where TComponent : struct, IEcsComponent
|
||||
{
|
||||
|
||||
@ -14,5 +14,7 @@
|
||||
public const string BASIC_LAYER = nameof(BASIC_LAYER);
|
||||
public const string END_LAYER = nameof(END_LAYER);
|
||||
public const string POST_END_LAYER = nameof(POST_END_LAYER);
|
||||
|
||||
public const string META_HIDDEN_TAG = "HiddenInDebagging";
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class DebugHideAttribute : Attribute { }
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
@ -67,7 +68,7 @@ namespace DCFApixels.DragonECS
|
||||
GetName(type: obj.GetType(), 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)
|
||||
{
|
||||
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(Type type, out string name)
|
||||
{
|
||||
if (type.TryGetCustomAttribute(out DebugNameAttribute atr))
|
||||
if (type.TryGetCustomAttribute(out MetaNameAttribute atr))
|
||||
{
|
||||
name = atr.name;
|
||||
return true;
|
||||
@ -88,29 +89,29 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region GetGroup
|
||||
public static DebugGroup GetGroup(object obj)
|
||||
public static MetaGroup GetGroup(object obj)
|
||||
{
|
||||
return obj is IEcsDebugMetaProvider intr ?
|
||||
GetGroup(intr.DebugMetaSource) :
|
||||
GetGroup(type: obj.GetType());
|
||||
}
|
||||
public static DebugGroup GetGroup<T>() => GetGroup(typeof(T));
|
||||
public static DebugGroup GetGroup(Type type) => type.TryGetCustomAttribute(out DebugGroupAttribute atr) ? atr.GetData() : DebugGroup.Empty;
|
||||
public static bool TryGetGroup(object obj, out DebugGroup group)
|
||||
public static MetaGroup GetGroup<T>() => GetGroup(typeof(T));
|
||||
public static MetaGroup GetGroup(Type type) => type.TryGetCustomAttribute(out MetaGroupAttribute atr) ? atr.GetData() : MetaGroup.Empty;
|
||||
public static bool TryGetGroup(object obj, out MetaGroup group)
|
||||
{
|
||||
return obj is IEcsDebugMetaProvider intr ?
|
||||
TryGetGroup(intr.DebugMetaSource, 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(Type type, out DebugGroup group)
|
||||
public static bool TryGetGroup<T>(out MetaGroup text) => TryGetGroup(typeof(T), out text);
|
||||
public static bool TryGetGroup(Type type, out MetaGroup group)
|
||||
{
|
||||
if (type.TryGetCustomAttribute(out DebugGroupAttribute atr))
|
||||
if (type.TryGetCustomAttribute(out MetaGroupAttribute atr))
|
||||
{
|
||||
group = atr.GetData();
|
||||
return true;
|
||||
}
|
||||
group = DebugGroup.Empty;
|
||||
group = MetaGroup.Empty;
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
@ -123,7 +124,7 @@ namespace DCFApixels.DragonECS
|
||||
GetDescription(type: obj.GetType());
|
||||
}
|
||||
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)
|
||||
{
|
||||
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(Type type, out string text)
|
||||
{
|
||||
if (type.TryGetCustomAttribute(out DebugDescriptionAttribute atr))
|
||||
if (type.TryGetCustomAttribute(out MetaDescriptionAttribute atr))
|
||||
{
|
||||
text = atr.description;
|
||||
return true;
|
||||
@ -149,7 +150,7 @@ namespace DCFApixels.DragonECS
|
||||
private class WordColor
|
||||
{
|
||||
public int wordsCount;
|
||||
public DebugColor color;
|
||||
public MetaColor color;
|
||||
}
|
||||
private class NameColor
|
||||
{
|
||||
@ -162,7 +163,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
color = new WordColor();
|
||||
_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++;
|
||||
colors.Add(color);
|
||||
@ -177,7 +178,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public DebugColor CalcColor()
|
||||
public MetaColor CalcColor()
|
||||
{
|
||||
float r = 0, g = 0, b = 0;
|
||||
int totalWordsCount = CalcTotalWordsColor();
|
||||
@ -189,11 +190,11 @@ namespace DCFApixels.DragonECS
|
||||
g += m * color.color.g;
|
||||
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 DebugColor CalcNameColorFor(Type type)
|
||||
private static MetaColor CalcNameColorFor(Type type)
|
||||
{
|
||||
Type targetType = type.IsGenericType ? type.GetGenericTypeDefinition() : type;
|
||||
if (!_names.TryGetValue(targetType, out NameColor nameColor))
|
||||
@ -224,39 +225,73 @@ namespace DCFApixels.DragonECS
|
||||
return words;
|
||||
}
|
||||
|
||||
public static DebugColor GetColor(object obj)
|
||||
public static MetaColor GetColor(object obj)
|
||||
{
|
||||
return obj is IEcsDebugMetaProvider intr ?
|
||||
GetColor(intr.DebugMetaSource) :
|
||||
GetColor(type: obj.GetType());
|
||||
}
|
||||
public static DebugColor GetColor<T>() => GetColor(typeof(T));
|
||||
public static DebugColor GetColor(Type type)
|
||||
public static MetaColor GetColor<T>() => GetColor(typeof(T));
|
||||
public static MetaColor GetColor(Type type)
|
||||
{
|
||||
var atr = type.GetCustomAttribute<DebugColorAttribute>();
|
||||
var atr = type.GetCustomAttribute<MetaColorAttribute>();
|
||||
return atr != null ? atr.color
|
||||
#if DEBUG //optimization for release build
|
||||
: CalcNameColorFor(type);
|
||||
#else
|
||||
: DebugColor.BlackColor;
|
||||
: MetaColor.BlackColor;
|
||||
#endif
|
||||
}
|
||||
public static bool TryGetColor(object obj, out DebugColor color)
|
||||
public static bool TryGetColor(object obj, out MetaColor color)
|
||||
{
|
||||
return obj is IEcsDebugMetaProvider intr ?
|
||||
TryGetColor(intr.DebugMetaSource, 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(Type type, out DebugColor color)
|
||||
public static bool TryGetColor<T>(out MetaColor color) => TryGetColor(typeof(T), out color);
|
||||
public static bool TryGetColor(Type type, out MetaColor color)
|
||||
{
|
||||
var atr = type.GetCustomAttribute<DebugColorAttribute>();
|
||||
var atr = type.GetCustomAttribute<MetaColorAttribute>();
|
||||
if (atr != null)
|
||||
{
|
||||
color = atr.color;
|
||||
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;
|
||||
}
|
||||
#endregion
|
||||
@ -269,7 +304,7 @@ namespace DCFApixels.DragonECS
|
||||
IsHidden(type: obj.GetType());
|
||||
}
|
||||
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
|
||||
|
||||
#region MetaSource
|
||||
@ -284,22 +319,22 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region GenerateTypeDebugData
|
||||
public static TypeDebugData GenerateTypeDebugData(object obj)
|
||||
public static TypeMetaData GenerateTypeDebugData(object obj)
|
||||
{
|
||||
return obj is IEcsDebugMetaProvider intr ?
|
||||
GenerateTypeDebugData(intr.DebugMetaSource) :
|
||||
GenerateTypeDebugData(type: obj.GetType());
|
||||
}
|
||||
public static TypeDebugData GenerateTypeDebugData<T>() => GenerateTypeDebugData(typeof(T));
|
||||
public static TypeDebugData GenerateTypeDebugData(Type type)
|
||||
public static TypeMetaData GenerateTypeDebugData<T>() => GenerateTypeDebugData(typeof(T));
|
||||
public static TypeMetaData GenerateTypeDebugData(Type type)
|
||||
{
|
||||
return new TypeDebugData(
|
||||
return new TypeMetaData(
|
||||
type,
|
||||
GetName(type),
|
||||
GetGroup(type),
|
||||
GetColor(type),
|
||||
GetDescription(type),
|
||||
IsHidden(type));
|
||||
GetTags(type).ToArray());
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -320,22 +355,22 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed class TypeDebugData
|
||||
public sealed class TypeMetaData
|
||||
{
|
||||
public readonly Type type;
|
||||
public readonly string name;
|
||||
public readonly DebugGroup group;
|
||||
public readonly DebugColor color;
|
||||
public readonly MetaGroup group;
|
||||
public readonly MetaColor color;
|
||||
public readonly string description;
|
||||
public readonly bool isHidden;
|
||||
public TypeDebugData(Type type, string name, DebugGroup group, DebugColor color, string description, bool isHidden)
|
||||
public readonly string[] tags;
|
||||
public TypeMetaData(Type type, string name, MetaGroup group, MetaColor color, string description, string[] tags)
|
||||
{
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.group = group;
|
||||
this.color = color;
|
||||
this.description = description;
|
||||
this.isHidden = isHidden;
|
||||
this.tags = tags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,20 +3,23 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class DebugColorAttribute : Attribute
|
||||
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class MetaColorAttribute : Attribute
|
||||
{
|
||||
public readonly DebugColor color;
|
||||
public byte r => color.r;
|
||||
public byte g => color.g;
|
||||
public byte b => color.b;
|
||||
public DebugColorAttribute(byte r, byte g, byte b) => color = new DebugColor(r, g, b, 255);
|
||||
public DebugColorAttribute(int colorCode) => color = new DebugColor(colorCode, true);
|
||||
public readonly MetaColor color;
|
||||
public byte R => color.r;
|
||||
public byte G => color.g;
|
||||
public byte B => color.b;
|
||||
public float FloatT => R / (float)byte.MaxValue;
|
||||
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)]
|
||||
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>
|
||||
public const int Red = (255 << 24) | (000 << 16) | (000 << 8) | 255;
|
||||
/// <summary> color code Green. RGB is (0, 255, 0)</summary>
|
||||
@ -66,37 +69,37 @@ namespace DCFApixels.DragonECS
|
||||
[FieldOffset(2)] public readonly byte g;
|
||||
[FieldOffset(1)] public readonly byte b;
|
||||
[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.g = g;
|
||||
this.b = b;
|
||||
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.g = g;
|
||||
this.b = b;
|
||||
this.a = a;
|
||||
}
|
||||
public DebugColor(int colorCode) : this() => this.colorCode = colorCode;
|
||||
public DebugColor(int colorCode, bool withoutAlpha) : this() => this.colorCode = withoutAlpha ? colorCode | 255 : colorCode;
|
||||
public MetaColor(int colorCode) : this() => this.colorCode = 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, byte) ToTupleRGBA() => (r, g, b, a);
|
||||
|
||||
public DebugColor UpContrastColor()
|
||||
public MetaColor UpContrastColor()
|
||||
{
|
||||
byte minChannel = Math.Min(Math.Min(r, g), b);
|
||||
byte maxChannel = Math.Max(Math.Max(r, g), b);
|
||||
if (maxChannel == minChannel)
|
||||
return default;
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
11
src/Debug/MetaAttributes/MetaDescriptionAttribute.cs
Normal file
11
src/Debug/MetaAttributes/MetaDescriptionAttribute.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
@ -3,13 +3,13 @@ using System.Text.RegularExpressions;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class DebugGroupAttribute : Attribute
|
||||
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
|
||||
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 rootCategory;
|
||||
public DebugGroupAttribute(string name)
|
||||
public MetaGroupAttribute(string name)
|
||||
{
|
||||
name = Regex.Replace(name, @"^[/|\\]+|[/|\\]+$", "");
|
||||
rootCategory = Regex.Match(name, @"^(.*?)[/\\]").Groups[1].Value;
|
||||
@ -19,15 +19,15 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
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);
|
||||
private readonly DebugGroupAttribute _source;
|
||||
public static readonly MetaGroup Empty = new MetaGroup(MetaGroupAttribute.Empty);
|
||||
private readonly MetaGroupAttribute _source;
|
||||
public string Name => _source.name;
|
||||
public string RootCategory => _source.rootCategory;
|
||||
public DebugGroup(DebugGroupAttribute source) => _source = source;
|
||||
public MetaGroup(MetaGroupAttribute source) => _source = source;
|
||||
public string[] SplitCategories() => _source.SplitCategories();
|
||||
}
|
||||
}
|
||||
11
src/Debug/MetaAttributes/MetaNameAttribute.cs
Normal file
11
src/Debug/MetaAttributes/MetaNameAttribute.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
24
src/Debug/MetaAttributes/MetaTagsAttribute.cs
Normal file
24
src/Debug/MetaAttributes/MetaTagsAttribute.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,4 @@
|
||||
using DCFApixels.DragonECS.Internal;
|
||||
using DCFApixels.DragonECS.RunnersCore;
|
||||
using DCFApixels.DragonECS.RunnersCore;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@ -166,7 +165,7 @@ namespace DCFApixels.DragonECS
|
||||
if(_subclass == null)
|
||||
{
|
||||
Type interfaceType = typeof(TInterface);
|
||||
if (interfaceType.TryGetAttribute(out BindWithEcsRunnerAttribute atr))
|
||||
if (interfaceType.TryGetCustomAttribute(out BindWithEcsRunnerAttribute atr))
|
||||
{
|
||||
Type runnerType = atr.runnerType;
|
||||
if (interfaceType.IsGenericType)
|
||||
|
||||
@ -2,9 +2,7 @@
|
||||
using DCFApixels.DragonECS.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Metrics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using static DCFApixels.DragonECS.EcsWorld;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user