mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-17 17:34:36 +08:00
udpate typemeta add docs
This commit is contained in:
parent
56bc701e01
commit
f7fb996ffc
@ -11,11 +11,46 @@ namespace DCFApixels.DragonECS.Docs
|
||||
{
|
||||
[DataMember]
|
||||
private readonly DragonDocsMeta[] _metas;
|
||||
[NonSerialized]
|
||||
private DragonDocsMetaGroup[] _mapping = null;
|
||||
|
||||
public ReadOnlySpan<DragonDocsMeta> Meta
|
||||
{
|
||||
get { return new ReadOnlySpan<DragonDocsMeta>(_metas); }
|
||||
}
|
||||
public ReadOnlySpan<DragonDocsMetaGroup> Mapping
|
||||
{
|
||||
get
|
||||
{
|
||||
Init();
|
||||
return new ReadOnlySpan<DragonDocsMetaGroup>(_mapping); ;
|
||||
}
|
||||
}
|
||||
private bool _isInit = false;
|
||||
private void Init()
|
||||
{
|
||||
if (_isInit) { return; }
|
||||
|
||||
if (_metas.Length < 0)
|
||||
{
|
||||
_mapping = Array.Empty<DragonDocsMetaGroup>();
|
||||
}
|
||||
List<DragonDocsMetaGroup> groups = new List<DragonDocsMetaGroup>();
|
||||
string name = _metas[0].Name;
|
||||
int startIndex = 0;
|
||||
for (int i = 1; i < _metas.Length; i++)
|
||||
{
|
||||
var meta = _metas[i];
|
||||
if (name != meta.Name)
|
||||
{
|
||||
groups.Add(new DragonDocsMetaGroup(name, startIndex, i - startIndex));
|
||||
name = meta.Name;
|
||||
startIndex = i;
|
||||
}
|
||||
}
|
||||
groups.Add(new DragonDocsMetaGroup(name, startIndex, _metas.Length - startIndex));
|
||||
_mapping = groups.ToArray();
|
||||
}
|
||||
private DragonDocs(DragonDocsMeta[] metas)
|
||||
{
|
||||
_metas = metas;
|
||||
@ -50,4 +85,17 @@ namespace DCFApixels.DragonECS.Docs
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public struct DragonDocsMetaGroup
|
||||
{
|
||||
public readonly string Name;
|
||||
public readonly int StartIndex;
|
||||
public readonly int Length;
|
||||
public DragonDocsMetaGroup(string name, int startIndex, int length)
|
||||
{
|
||||
Name = name;
|
||||
StartIndex = startIndex;
|
||||
Length = length;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -20,7 +20,7 @@ namespace DCFApixels.DragonECS.Docs
|
||||
[DataMember] public readonly string Description = string.Empty;
|
||||
|
||||
[DataMember] public readonly string Group = string.Empty;
|
||||
[DataMember] public readonly string Tags = string.Empty;
|
||||
[DataMember] public readonly string[] Tags = Array.Empty<string>();
|
||||
|
||||
public DragonDocsMeta(TypeMeta meta)
|
||||
{
|
||||
@ -35,7 +35,11 @@ namespace DCFApixels.DragonECS.Docs
|
||||
Description = meta.Description.Text;
|
||||
|
||||
Group = meta.Group.Name;
|
||||
Tags = string.Join(", ", meta.Tags);
|
||||
Tags = new string[meta.Tags.Count];
|
||||
for (int i = 0, n = meta.Tags.Count; i < n; i++)
|
||||
{
|
||||
Tags[i] = meta.Tags[i];
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGetSourceType(out Type type)
|
||||
|
@ -20,16 +20,20 @@ namespace DCFApixels.DragonECS
|
||||
public readonly ref struct AutoScope
|
||||
{
|
||||
private readonly int _id;
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public AutoScope(int id)
|
||||
{
|
||||
_id = id;
|
||||
DebugService.Instance.ProfilerMarkBegin(id);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Dispose()
|
||||
{
|
||||
DebugService.Instance.ProfilerMarkEnd(_id);
|
||||
}
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static explicit operator EcsProfilerMarker(string markerName) { return new EcsProfilerMarker(markerName); }
|
||||
}
|
||||
|
||||
public static class EcsDebug
|
||||
|
@ -23,20 +23,20 @@ namespace DCFApixels.DragonECS
|
||||
public class MetaGroup
|
||||
{
|
||||
public static readonly MetaGroup Empty = new MetaGroup("");
|
||||
private static string pattern = @"Module(?=/)";
|
||||
private static char[] separatpor = new char[] { '/' };
|
||||
private static string _pattern = @"Module(?=/)";
|
||||
private static char[] _separatpor = new char[] { '/' };
|
||||
|
||||
public readonly string Name;
|
||||
private string[] path = null;
|
||||
private string[] _path = null;
|
||||
public IReadOnlyCollection<string> Splited
|
||||
{
|
||||
get
|
||||
{
|
||||
if (path == null)
|
||||
if (_path == null)
|
||||
{
|
||||
path = Name.Split(separatpor, StringSplitOptions.RemoveEmptyEntries);
|
||||
_path = Name.Split(_separatpor, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
}
|
||||
return path;
|
||||
return _path;
|
||||
}
|
||||
}
|
||||
public MetaGroup(string name)
|
||||
@ -51,7 +51,8 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
name += '/';
|
||||
}
|
||||
Name = Regex.Replace(name, pattern, ""); ;
|
||||
Name = Regex.Replace(name, _pattern, "");
|
||||
Name = string.Intern(Name);
|
||||
}
|
||||
public override string ToString() { return Name; }
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
@ -8,20 +7,28 @@ namespace DCFApixels.DragonECS
|
||||
public sealed class MetaTagsAttribute : EcsMetaAttribute
|
||||
{
|
||||
private readonly string[] _tags = Array.Empty<string>();
|
||||
public IReadOnlyCollection<string> Tags
|
||||
private static char[] _separatpor = new char[] { ',' };
|
||||
public IReadOnlyList<string> Tags
|
||||
{
|
||||
get { return _tags; }
|
||||
}
|
||||
|
||||
[Obsolete("With empty parameters, this attribute makes no sense.")]
|
||||
public MetaTagsAttribute() { }
|
||||
public MetaTagsAttribute(params string[] tags)
|
||||
public MetaTagsAttribute(string tags)
|
||||
{
|
||||
_tags = tags.Where(o => !string.IsNullOrEmpty(o)).ToArray();
|
||||
_tags = tags.Split(_separatpor, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
for (int i = 0; i < _tags.Length; i++)
|
||||
{
|
||||
_tags[i] = string.Intern(_tags[i]);
|
||||
}
|
||||
}
|
||||
public MetaTagsAttribute(params string[] tags) : this(string.Join(',', tags)) { }
|
||||
}
|
||||
public readonly ref struct MetaTags
|
||||
{
|
||||
public const string HIDDEN = EcsConsts.META_HIDDEN_TAG;
|
||||
|
||||
private static string[] _tags = new string[64];
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,12 @@ namespace DCFApixels.DragonECS
|
||||
MetaColor Color { get; }
|
||||
MetaDescription Description { get; }
|
||||
MetaGroup Group { get; }
|
||||
IReadOnlyCollection<string> Tags { get; }
|
||||
IReadOnlyList<string> Tags { get; }
|
||||
}
|
||||
|
||||
[MetaGroup(EcsConsts.FRAMEWORK_NAME)]
|
||||
[MetaColor(MetaColor.DragonRose)]
|
||||
[MetaDescription(EcsConsts.AUTHOR, "Basic class of the framework, intended for extending meta information of types, for customization of type display in the editor.")]
|
||||
[DebuggerTypeProxy(typeof(DebuggerProxy))]
|
||||
public sealed class TypeMeta : ITypeMeta
|
||||
{
|
||||
@ -32,7 +35,7 @@ namespace DCFApixels.DragonECS
|
||||
private MetaColor _color;
|
||||
private MetaDescription _description;
|
||||
private MetaGroup _group;
|
||||
private IReadOnlyCollection<string> _tags;
|
||||
private IReadOnlyList<string> _tags;
|
||||
private int _typeCode;
|
||||
|
||||
private InitFlag _initFlags = InitFlag.None;
|
||||
@ -154,7 +157,7 @@ namespace DCFApixels.DragonECS
|
||||
_isHidden = _tags.Contains(MetaTags.HIDDEN);
|
||||
}
|
||||
}
|
||||
public IReadOnlyCollection<string> Tags
|
||||
public IReadOnlyList<string> Tags
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -224,6 +227,10 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return _color.GetHashCode() ^ _name[0].GetHashCode() ^ _name[_name.Length - 1].GetHashCode();
|
||||
}
|
||||
private class DebuggerProxy : ITypeMeta
|
||||
{
|
||||
private readonly TypeMeta _meta;
|
||||
@ -247,7 +254,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
get { return _meta.Group; }
|
||||
}
|
||||
public IReadOnlyCollection<string> Tags
|
||||
public IReadOnlyList<string> Tags
|
||||
{
|
||||
get { return _meta.Tags; }
|
||||
}
|
||||
@ -314,7 +321,7 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region GetTags
|
||||
public static IReadOnlyCollection<string> GetTags(Type type)
|
||||
public static IReadOnlyList<string> GetTags(Type type)
|
||||
{
|
||||
var atr = type.GetCustomAttribute<MetaTagsAttribute>();
|
||||
return atr != null ? atr.Tags : Array.Empty<string>();
|
||||
|
Loading…
Reference in New Issue
Block a user