Add custom Tags for scripting api types to be used by plugins
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Flax.Build.Bindings
|
||||
public class ApiTypeInfo : IBindingsCache, ICloneable
|
||||
{
|
||||
public ApiTypeInfo Parent;
|
||||
public Dictionary<string, string> Tags;
|
||||
public List<ApiTypeInfo> Children = new List<ApiTypeInfo>();
|
||||
public string NativeName;
|
||||
public string Name;
|
||||
@@ -109,6 +110,20 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
}
|
||||
|
||||
public string GetTag(string tag)
|
||||
{
|
||||
if (Tags != null && Tags.TryGetValue(tag, out var value))
|
||||
return value;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetTag(string tag, string value)
|
||||
{
|
||||
if (Tags == null)
|
||||
Tags = new Dictionary<string, string>();
|
||||
Tags[tag] = value;
|
||||
}
|
||||
|
||||
public virtual void AddChild(ApiTypeInfo apiTypeInfo)
|
||||
{
|
||||
apiTypeInfo.Parent = this;
|
||||
@@ -124,6 +139,7 @@ namespace Flax.Build.Bindings
|
||||
BindingsGenerator.Write(writer, Comment);
|
||||
writer.Write(IsInBuild);
|
||||
writer.Write(IsDeprecated);
|
||||
BindingsGenerator.Write(writer, Tags);
|
||||
BindingsGenerator.Write(writer, Children);
|
||||
}
|
||||
|
||||
@@ -136,6 +152,7 @@ namespace Flax.Build.Bindings
|
||||
Comment = BindingsGenerator.Read(reader, Comment);
|
||||
IsInBuild = reader.ReadBoolean();
|
||||
IsDeprecated = reader.ReadBoolean();
|
||||
Tags = BindingsGenerator.Read(reader, Tags);
|
||||
Children = BindingsGenerator.Read(reader, Children);
|
||||
|
||||
// Fix hierarchy
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Flax.Build.Bindings
|
||||
partial class BindingsGenerator
|
||||
{
|
||||
private static readonly Dictionary<string, Type> TypeCache = new Dictionary<string, Type>();
|
||||
private const int CacheVersion = 16;
|
||||
private const int CacheVersion = 17;
|
||||
|
||||
internal static void Write(BinaryWriter writer, string e)
|
||||
{
|
||||
@@ -43,6 +43,23 @@ namespace Flax.Build.Bindings
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Write(BinaryWriter writer, Dictionary<string, string> map)
|
||||
{
|
||||
if (map != null)
|
||||
{
|
||||
writer.Write(map.Count);
|
||||
foreach (var e in map)
|
||||
{
|
||||
writer.Write(e.Key);
|
||||
writer.Write(e.Value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(0);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Write(BinaryWriter writer, HashSet<string> list)
|
||||
{
|
||||
if (list != null)
|
||||
@@ -156,6 +173,22 @@ namespace Flax.Build.Bindings
|
||||
return list;
|
||||
}
|
||||
|
||||
internal static Dictionary<string, string> Read(BinaryReader reader, Dictionary<string, string> map)
|
||||
{
|
||||
var count = reader.ReadInt32();
|
||||
if (count != 0)
|
||||
{
|
||||
map = new Dictionary<string, string>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var key = reader.ReadString();
|
||||
var value = reader.ReadString();
|
||||
map.Add(key, value);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
internal static T Read<T>(BinaryReader reader, T e) where T : IBindingsCache
|
||||
{
|
||||
var typename = reader.ReadString();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Flax.Build.Bindings
|
||||
@@ -17,12 +18,28 @@ namespace Flax.Build.Bindings
|
||||
public bool IsHidden;
|
||||
public AccessLevel Access;
|
||||
public string Attributes;
|
||||
public Dictionary<string, string> Tags;
|
||||
|
||||
public bool HasAttribute(string name)
|
||||
{
|
||||
return Attributes != null && Attributes.Contains(name);
|
||||
}
|
||||
|
||||
public string GetTag(string tag)
|
||||
{
|
||||
if (Tags != null && Tags.TryGetValue(tag, out var value))
|
||||
return value;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetTag(string tag, string value)
|
||||
{
|
||||
if (Tags == null)
|
||||
Tags = new Dictionary<string, string>();
|
||||
Tags[tag] = value;
|
||||
}
|
||||
|
||||
|
||||
public virtual void Write(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(Name);
|
||||
@@ -33,6 +50,7 @@ namespace Flax.Build.Bindings
|
||||
writer.Write(IsHidden);
|
||||
writer.Write((byte)Access);
|
||||
BindingsGenerator.Write(writer, Attributes);
|
||||
BindingsGenerator.Write(writer, Tags);
|
||||
}
|
||||
|
||||
public virtual void Read(BinaryReader reader)
|
||||
@@ -45,6 +63,7 @@ namespace Flax.Build.Bindings
|
||||
IsHidden = reader.ReadBoolean();
|
||||
Access = (AccessLevel)reader.ReadByte();
|
||||
Attributes = BindingsGenerator.Read(reader, Attributes);
|
||||
Tags = BindingsGenerator.Read(reader, Tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user