update meta attributes

This commit is contained in:
Mikhail 2024-05-01 13:38:08 +08:00
parent d2f761a884
commit 514d761d00
8 changed files with 90 additions and 84 deletions

View File

@ -5,28 +5,28 @@ using System;
namespace DCFApixels.DragonECS
{
[MetaName(nameof(PreInit))]
[MetaColor(MetaColor.Orange)]
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.FRAMEWORK_NAME)]
public interface IEcsPreInit : IEcsProcess
{
void PreInit();
}
[MetaName(nameof(Init))]
[MetaColor(MetaColor.Orange)]
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.FRAMEWORK_NAME)]
public interface IEcsInit : IEcsProcess
{
void Init();
}
[MetaName(nameof(Run))]
[MetaColor(MetaColor.Orange)]
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.FRAMEWORK_NAME)]
public interface IEcsRun : IEcsProcess
{
void Run();
}
[MetaName(nameof(Destroy))]
[MetaColor(MetaColor.Orange)]
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.FRAMEWORK_NAME)]
public interface IEcsDestroy : IEcsProcess
{
@ -41,7 +41,7 @@ namespace DCFApixels.DragonECS.Internal
[Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
#endif
[MetaColor(MetaColor.Orange)]
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.FRAMEWORK_NAME)]
internal sealed class EcsPreInitRunner : EcsRunner<IEcsPreInit>, IEcsPreInit
{
@ -97,7 +97,7 @@ namespace DCFApixels.DragonECS.Internal
[Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
#endif
[MetaColor(MetaColor.Orange)]
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.FRAMEWORK_NAME)]
internal sealed class EcsInitRunner : EcsRunner<IEcsInit>, IEcsInit
{
@ -150,7 +150,7 @@ namespace DCFApixels.DragonECS.Internal
[Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
#endif
[MetaColor(MetaColor.Orange)]
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.FRAMEWORK_NAME)]
internal sealed class EcsRunRunner : EcsRunner<IEcsRun>, IEcsRun
{
@ -203,7 +203,7 @@ namespace DCFApixels.DragonECS.Internal
[Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
#endif
[MetaColor(MetaColor.Orange)]
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.FRAMEWORK_NAME)]
internal sealed class EcsDestroyRunner : EcsRunner<IEcsDestroy>, IEcsDestroy
{

View File

@ -2,6 +2,8 @@
namespace DCFApixels.DragonECS
{
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.FRAMEWORK_NAME)]
[DebuggerTypeProxy(typeof(DebuggerProxy))]
public sealed class EcsDefaultWorld : EcsWorld, IInjectionUnit
{
@ -12,6 +14,8 @@ namespace DCFApixels.DragonECS
initer.AddNode<EcsDefaultWorld>();
}
}
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.FRAMEWORK_NAME)]
[DebuggerTypeProxy(typeof(DebuggerProxy))]
public sealed class EcsEventWorld : EcsWorld, IInjectionUnit
{

View File

@ -156,36 +156,36 @@ namespace DCFApixels.DragonECS
#endregion
#region GetDescription
public static string GetDescription(object obj)
public static MetaDescription GetDescription(object obj)
{
return GetTypeMeta(obj).Description;
}
public static string GetDescription<T>()
public static MetaDescription GetDescription<T>()
{
return GetTypeMeta<T>().Description;
}
public static string GetDescription(Type type)
public static MetaDescription GetDescription(Type type)
{
return GetTypeMeta(type).Description;
}
public static bool TryGetDescription(object obj, out string description)
public static bool TryGetDescription(object obj, out MetaDescription description)
{
TypeMeta meta = GetTypeMeta(obj);
description = meta.Description;
return string.IsNullOrEmpty(description);
return description != MetaDescription.Empty;
}
public static bool TryGetDescription<T>(out string description)
public static bool TryGetDescription<T>(out MetaDescription description)
{
TypeMeta meta = GetTypeMeta<T>();
description = meta.Description;
return string.IsNullOrEmpty(description);
return description != MetaDescription.Empty;
}
public static bool TryGetDescription(Type type, out string description)
public static bool TryGetDescription(Type type, out MetaDescription description)
{
TypeMeta meta = GetTypeMeta(type);
description = meta.Description;
return string.IsNullOrEmpty(description);
return description != MetaDescription.Empty;
}
#endregion
@ -207,19 +207,19 @@ namespace DCFApixels.DragonECS
{
TypeMeta meta = GetTypeMeta(obj);
group = meta.Group;
return group.IsNull;
return group != MetaGroup.Empty;
}
public static bool TryGetGroup<T>(out MetaGroup group)
{
TypeMeta meta = GetTypeMeta<T>();
group = meta.Group;
return group.IsNull;
return group != MetaGroup.Empty;
}
public static bool TryGetGroup(Type type, out MetaGroup group)
{
TypeMeta meta = GetTypeMeta(type);
group = meta.Group;
return group.IsNull;
return group != MetaGroup.Empty;
}
#endregion
@ -308,7 +308,7 @@ namespace DCFApixels.DragonECS
{
string Name { get; }
MetaColor Color { get; }
string Description { get; }
MetaDescription Description { get; }
MetaGroup Group { get; }
IReadOnlyCollection<string> Tags { get; }
}
@ -324,7 +324,7 @@ namespace DCFApixels.DragonECS
private string _name;
private MetaColor _color;
private string _description;
private MetaDescription _description;
private MetaGroup _group;
private IReadOnlyCollection<string> _tags;
private int _typeCode;
@ -400,7 +400,7 @@ namespace DCFApixels.DragonECS
#endregion
#region Description
public string Description
public MetaDescription Description
{
get
{
@ -520,7 +520,7 @@ namespace DCFApixels.DragonECS
{
get { return _meta.Color; }
}
public string Description
public MetaDescription Description
{
get { return _meta.Description; }
}
@ -587,10 +587,10 @@ namespace DCFApixels.DragonECS
#endregion
#region GetDescription
public static string GetDescription(Type type)
public static MetaDescription GetDescription(Type type)
{
bool isCustom = type.TryGetCustomAttribute(out MetaDescriptionAttribute atr);
return isCustom ? atr.description : string.Empty;
return isCustom ? atr.Data : MetaDescription.Empty;
}
#endregion

View File

@ -1,6 +1,8 @@
using DCFApixels.DragonECS.Internal;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Xml.Linq;
namespace DCFApixels.DragonECS
{
@ -117,6 +119,12 @@ namespace DCFApixels.DragonECS
public const int White = -1;
/// <summary> color code Black. RGB is (0, 0, 0)</summary>
public const int Black = 0;
/// <summary> RGB is (255, 78, 133) color code </summary>
public const int DragonRose = (255 << 24) | (78 << 16) | (133 << 8) | 255;
/// <summary> RGB is (0, 255, 156) color code </summary>
public const int DragonCyan = (0 << 24) | (255 << 16) | (156 << 8) | 255;
#endregion
[FieldOffset(0)] public readonly int colorCode;
@ -329,5 +337,7 @@ namespace DCFApixels.DragonECS
(byte)(a.b - b.b));
}
#endregion
public override string ToString() { return $"({r}, {g}, {b})"; }
}
}

View File

@ -1,14 +1,44 @@
using System;
using System.Diagnostics;
namespace DCFApixels.DragonECS
{
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class MetaDescriptionAttribute : EcsMetaAttribute
{
public readonly string description;
public MetaDescriptionAttribute(string description)
public readonly MetaDescription Data;
public MetaDescriptionAttribute(string text)
{
this.description = description;
Data = new MetaDescription(null, text);
}
public MetaDescriptionAttribute(string author, string text)
{
Data = new MetaDescription(author, text);
}
}
public class MetaDescription
{
public static readonly MetaDescription Empty = new MetaDescription(null, null);
public readonly string Author;
public readonly string Text;
public MetaDescription(string author, string text)
{
if (author == null) { author = string.Empty; }
if (text == null) { text = string.Empty; }
Author = author;
Text = text;
}
public override string ToString()
{
if (string.IsNullOrEmpty(Author))
{
return Text;
}
else
{
return $"[{Author}] Text";
}
}
}
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace DCFApixels.DragonECS
@ -7,27 +8,27 @@ namespace DCFApixels.DragonECS
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class MetaGroupAttribute : EcsMetaAttribute
{
public readonly MetaGroupRef Data;
public readonly MetaGroup Data;
[Obsolete("With empty parameters, this attribute makes no sense.")]
public MetaGroupAttribute() { }
public MetaGroupAttribute(string name)
{
Data = new MetaGroupRef(name);
Data = new MetaGroup(name);
}
public MetaGroupAttribute(params string[] path)
{
Data = new MetaGroupRef(string.Join("/", path));
Data = new MetaGroup(string.Join("/", path));
}
}
public class MetaGroupRef
public class MetaGroup
{
public static readonly MetaGroupRef Empty = new MetaGroupRef("");
public static readonly MetaGroup Empty = new MetaGroup("");
private static string pattern = @"Module(?=/)";
private static char[] separatpor = new char[] { '/' };
public readonly string Name;
private string[] path = null;
private static string pattern = @"Module(?=/)";
private static char[] separatpor = new char[] { '/' };
public IReadOnlyCollection<string> Splited
{
get
@ -39,7 +40,7 @@ namespace DCFApixels.DragonECS
return path;
}
}
public MetaGroupRef(string name)
public MetaGroup(string name)
{
if (string.IsNullOrEmpty(name))
{
@ -53,32 +54,6 @@ namespace DCFApixels.DragonECS
}
Name = Regex.Replace(name, pattern, ""); ;
}
}
public readonly struct MetaGroup
{
public static readonly MetaGroup Empty = new MetaGroup(MetaGroupRef.Empty);
private readonly MetaGroupRef _source;
public string Name
{
get { return _source.Name; }
}
public IReadOnlyCollection<string> Splited
{
get { return _source.Splited; }
}
public bool IsNull
{
get { return _source == null; }
}
public MetaGroup(MetaGroupRef source)
{
_source = source;
}
public static implicit operator MetaGroup(MetaGroupRef group)
{
return new MetaGroup(group);
}
public override string ToString() { return Name; }
}
}

View File

@ -550,11 +550,11 @@ namespace DCFApixels.DragonECS
internal class DebuggerProxy
{
private EcsProcessRaw _process;
public IEnumerable<TypeMeta> Systems
public IEnumerable<IEcsProcess> Systems
{
get
{
return _process._systems.Cast<IEcsProcess>().Select(o => o.GetMeta()).ToArray();
return _process._systems.Cast<IEcsProcess>().ToArray();
}
}
public int Count
@ -652,37 +652,22 @@ namespace DCFApixels.DragonECS
internal class DebuggerProxy
{
private EcsProcess<TProcess> _process;
public IEnumerable<SystemInfoWrapper> Systems
public IEnumerable<IEcsProcess> Systems
{
get
{
return _process._systems.Select(o => new SystemInfoWrapper(o)).ToArray();
return _process._systems.Cast<IEcsProcess>().ToArray();
}
}
public int Count
{
get { return _process.Length; }
}
public TypeMeta __META { get { return typeof(TProcess).ToMeta(); } }
public DebuggerProxy(EcsProcess<TProcess> process)
{
_process = process;
}
public readonly struct SystemInfoWrapper
{
public readonly TProcess System;
public SystemInfoWrapper(TProcess system)
{
System = system;
}
public TypeMeta __META { get { return System.GetMeta(); } }
public override string ToString()
{
return System.GetMeta().Name;
}
}
}
#endregion
}

View File

@ -28,6 +28,9 @@ namespace DCFApixels.DragonECS
PoolRecycledComponentsCapacity = poolRecycledComponentsCapacity;
}
}
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.FRAMEWORK_NAME)]
#if ENABLE_IL2CPP
[Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
@ -797,7 +800,6 @@ namespace DCFApixels.DragonECS
}
public long Version { get { return _world.Version; } }
public IEcsPool[] Pools { get { return _world._pools; } }
public TypeMeta __META { get { return _world.GetMeta(); } }
public DebuggerProxy(EcsWorld world)
{
_world = world;