Add custom Tags for scripting api types to be used by plugins

This commit is contained in:
Wojciech Figat
2022-10-10 14:40:59 +02:00
parent 7924a62db6
commit 4d08dc77b2
3 changed files with 70 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ namespace Flax.Build.Bindings
public class ApiTypeInfo : IBindingsCache, ICloneable public class ApiTypeInfo : IBindingsCache, ICloneable
{ {
public ApiTypeInfo Parent; public ApiTypeInfo Parent;
public Dictionary<string, string> Tags;
public List<ApiTypeInfo> Children = new List<ApiTypeInfo>(); public List<ApiTypeInfo> Children = new List<ApiTypeInfo>();
public string NativeName; public string NativeName;
public string Name; 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) public virtual void AddChild(ApiTypeInfo apiTypeInfo)
{ {
apiTypeInfo.Parent = this; apiTypeInfo.Parent = this;
@@ -124,6 +139,7 @@ namespace Flax.Build.Bindings
BindingsGenerator.Write(writer, Comment); BindingsGenerator.Write(writer, Comment);
writer.Write(IsInBuild); writer.Write(IsInBuild);
writer.Write(IsDeprecated); writer.Write(IsDeprecated);
BindingsGenerator.Write(writer, Tags);
BindingsGenerator.Write(writer, Children); BindingsGenerator.Write(writer, Children);
} }
@@ -136,6 +152,7 @@ namespace Flax.Build.Bindings
Comment = BindingsGenerator.Read(reader, Comment); Comment = BindingsGenerator.Read(reader, Comment);
IsInBuild = reader.ReadBoolean(); IsInBuild = reader.ReadBoolean();
IsDeprecated = reader.ReadBoolean(); IsDeprecated = reader.ReadBoolean();
Tags = BindingsGenerator.Read(reader, Tags);
Children = BindingsGenerator.Read(reader, Children); Children = BindingsGenerator.Read(reader, Children);
// Fix hierarchy // Fix hierarchy

View File

@@ -19,7 +19,7 @@ namespace Flax.Build.Bindings
partial class BindingsGenerator partial class BindingsGenerator
{ {
private static readonly Dictionary<string, Type> TypeCache = new Dictionary<string, Type>(); 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) 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) internal static void Write(BinaryWriter writer, HashSet<string> list)
{ {
if (list != null) if (list != null)
@@ -156,6 +173,22 @@ namespace Flax.Build.Bindings
return list; 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 internal static T Read<T>(BinaryReader reader, T e) where T : IBindingsCache
{ {
var typename = reader.ReadString(); var typename = reader.ReadString();

View File

@@ -1,5 +1,6 @@
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. // Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
using System.Collections.Generic;
using System.IO; using System.IO;
namespace Flax.Build.Bindings namespace Flax.Build.Bindings
@@ -17,12 +18,28 @@ namespace Flax.Build.Bindings
public bool IsHidden; public bool IsHidden;
public AccessLevel Access; public AccessLevel Access;
public string Attributes; public string Attributes;
public Dictionary<string, string> Tags;
public bool HasAttribute(string name) public bool HasAttribute(string name)
{ {
return Attributes != null && Attributes.Contains(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) public virtual void Write(BinaryWriter writer)
{ {
writer.Write(Name); writer.Write(Name);
@@ -33,6 +50,7 @@ namespace Flax.Build.Bindings
writer.Write(IsHidden); writer.Write(IsHidden);
writer.Write((byte)Access); writer.Write((byte)Access);
BindingsGenerator.Write(writer, Attributes); BindingsGenerator.Write(writer, Attributes);
BindingsGenerator.Write(writer, Tags);
} }
public virtual void Read(BinaryReader reader) public virtual void Read(BinaryReader reader)
@@ -45,6 +63,7 @@ namespace Flax.Build.Bindings
IsHidden = reader.ReadBoolean(); IsHidden = reader.ReadBoolean();
Access = (AccessLevel)reader.ReadByte(); Access = (AccessLevel)reader.ReadByte();
Attributes = BindingsGenerator.Read(reader, Attributes); Attributes = BindingsGenerator.Read(reader, Attributes);
Tags = BindingsGenerator.Read(reader, Tags);
} }
} }
} }