mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Extending ScriptGlue now possible
This commit is contained in:
@@ -19,15 +19,6 @@ namespace GlitchyEditor.EditWindows
|
||||
{
|
||||
private static uint32 TableId;
|
||||
|
||||
public static this()
|
||||
{
|
||||
/*ScriptGlue.OnRegisterNativeCalls.Add(new () => {
|
||||
// TODO: Implement
|
||||
Runtime.NotImplemented();
|
||||
//ScriptGlue.RegisterCall<function bool(ref AssetHandle)>("ScriptGlue::ImGuiExtension_ShowAssetDropTarget", => ShowAssetDropTarget);
|
||||
});*/
|
||||
}
|
||||
|
||||
public static void ShowComponents(Entity entity, Type componentType = null)
|
||||
{
|
||||
float cellPaddingY = ImGui.GetTextLineHeight() / 3.0f;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using GlitchyEditor.EditWindows;
|
||||
using GlitchyEngine.Content;
|
||||
|
||||
namespace GlitchyEngine.Scripting;
|
||||
|
||||
extension ScriptGlue
|
||||
{
|
||||
static this()
|
||||
{
|
||||
OnRegisterNativeCalls.Add(new => RegisterExtensionCalls);
|
||||
}
|
||||
|
||||
private static void RegisterExtensionCalls()
|
||||
{
|
||||
EngineFunctions.[Friend]_functions.ImGuiExtension_ShowAssetDropTarget = => ImGuiExtension_ShowAssetDropTarget;
|
||||
}
|
||||
|
||||
[RegisterCall(EngineResultAsBool = true, IsExtension = true)]
|
||||
public static EngineResult ImGuiExtension_ShowAssetDropTarget(ref AssetHandle assetHandle)
|
||||
{
|
||||
return ComponentEditWindow.ShowAssetDropTarget(ref assetHandle) ? .Ok : .False;
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ class MessageOrigin
|
||||
struct RegisterCallAttribute : Attribute
|
||||
{
|
||||
public bool EngineResultAsBool { get; set mut; }
|
||||
public bool IsExtension { get; set mut; }
|
||||
}
|
||||
|
||||
struct TypeTranslationTemplate
|
||||
@@ -177,13 +178,21 @@ struct EngineFunctionsGeneratorAttribute : Attribute, IComptimeTypeApply
|
||||
[EngineFunctionsGenerator]
|
||||
struct EngineFunctions
|
||||
{
|
||||
static Self _functions;
|
||||
|
||||
[RegisterMethod]
|
||||
public static void FillEngineFunctions()
|
||||
{
|
||||
|
||||
OnRegisterNativeCalls.Invoke();
|
||||
|
||||
ScriptGlue.[Friend]_setEngineFunctions(&_functions);
|
||||
}
|
||||
}
|
||||
|
||||
static class ScriptGlue
|
||||
{
|
||||
/* Adding this attribute to a method will log method entry and returned Result<T> errors */
|
||||
[AttributeUsage(.Method)]
|
||||
struct RegisterMethodAttribute : Attribute, IOnMethodInit
|
||||
public struct RegisterMethodAttribute : Attribute, IOnMethodInit
|
||||
{
|
||||
[Comptime]
|
||||
public void OnMethodInit(MethodInfo method, Self* prev)
|
||||
@@ -194,21 +203,22 @@ static class ScriptGlue
|
||||
|
||||
for (var methodInfo in typeof(ScriptGlue).GetMethods(.Static | .NonPublic | .FlattenHierarchy))
|
||||
{
|
||||
if (methodInfo.GetCustomAttribute<RegisterCallAttribute>() case .Ok(let attribute))
|
||||
if (methodInfo.GetCustomAttribute<RegisterCallAttribute>() case .Ok(let attribute) && !attribute.IsExtension)
|
||||
{
|
||||
functionContent.AppendF($"functions.{methodInfo.Name} = => {methodInfo.Name};\n");
|
||||
functionContent.AppendF($"_functions.{methodInfo.Name} = => ScriptGlue.[Friend]{methodInfo.Name};\n");
|
||||
//functionContent.AppendF($"functions[{i}] = (void*)( => {methodInfo.Name});\n");
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
functionContent.Insert(0, scope $"EngineFunctions functions = .();\n");
|
||||
//functionContent.Insert(0, scope $"EngineFunctions functions = .();\n");
|
||||
|
||||
Compiler.EmitMethodEntry(method, functionContent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class ScriptGlue
|
||||
{
|
||||
public static Event<delegate void()> OnRegisterNativeCalls ~ _.Dispose();
|
||||
|
||||
private function void SetEngineFunctions(EngineFunctions* engineFunctions);
|
||||
@@ -242,16 +252,7 @@ static class ScriptGlue
|
||||
|
||||
private static void RegisterCalls()
|
||||
{
|
||||
FillEngineFunctions();
|
||||
}
|
||||
|
||||
[RegisterMethod]
|
||||
private static void FillEngineFunctions()
|
||||
{
|
||||
|
||||
OnRegisterNativeCalls.Invoke();
|
||||
|
||||
_setEngineFunctions(&functions);
|
||||
EngineFunctions.FillEngineFunctions();
|
||||
}
|
||||
|
||||
private static void RegisterComponent<T>() where T : struct, new
|
||||
@@ -1421,8 +1422,6 @@ static class ScriptGlue
|
||||
|
||||
Log.EngineLogger.AssertDebug(context != null);
|
||||
|
||||
Log.EngineLogger.Trace(StringView(fieldName));
|
||||
|
||||
context.AddField(StringView(fieldName), type, valueObject, StringView(fullTypeName));
|
||||
}
|
||||
|
||||
|
||||
@@ -77,9 +77,7 @@ public static class ImGuiExtension
|
||||
|
||||
public static bool ShowAssetDropTarget(ref UUID uuid)
|
||||
{
|
||||
// TODO: !!!
|
||||
// return ScriptGlue.ImGuiExtension_ShowAssetDropTarget(ref uuid);
|
||||
return false;
|
||||
return ScriptGlue.ImGuiExtension_ShowAssetDropTarget(ref uuid);
|
||||
}
|
||||
|
||||
public static bool Checkbox2(string label, ref bool2 value) => CheckboxN(2, label, ref value.X);
|
||||
|
||||
Reference in New Issue
Block a user