ScriptEngine refactoring

This commit is contained in:
Simon Lübeß
2024-03-31 12:36:22 +02:00
parent abcacc84a9
commit 777f52ab49
4 changed files with 13 additions and 48 deletions
+7 -25
View File
@@ -13,19 +13,16 @@ abstract class SharpType : RefCounter
protected String _namespace ~ delete _;
protected String _className ~ delete _;
protected String _fullName ~ delete _;
protected ScriptFieldType _scriptType;
public StringView Namespace => _namespace;
public StringView ClassName => _className;
public StringView FullName => _fullName;
public ScriptFieldType ScriptType => _scriptType;
public this(StringView classNamespace, StringView className, ScriptFieldType scriptType)
public this(StringView classNamespace, StringView className)
{
_namespace = new String(classNamespace);
_className = new String(className);
_fullName = new $"{_namespace}.{_className}";
_scriptType = scriptType;
}
}
@@ -33,36 +30,21 @@ class SharpClass : SharpType
{
protected internal MonoClass* _monoClass;
public this(StringView classNamespace, StringView className, MonoImage* image, ScriptFieldType fieldType = .Class) :
base(classNamespace, className, fieldType)
public this(StringView classNamespace, StringView className, MonoImage* image) :
base(classNamespace, className)
{
_monoClass = Mono.mono_class_from_name(image, _namespace, _className);
Log.EngineLogger.AssertDebug(_monoClass != null);
}
internal this(MonoClass* monoClass, ScriptFieldType fieldType = .Class) :
base(StringView(Mono.mono_class_get_namespace(monoClass)), StringView(Mono.mono_class_get_name(monoClass)), fieldType)
internal this(MonoClass* monoClass) :
base(StringView(Mono.mono_class_get_namespace(monoClass)), StringView(Mono.mono_class_get_name(monoClass)))
{
_monoClass = monoClass;
Log.EngineLogger.AssertDebug(_monoClass != null);
}
internal MonoType* GetMonoType()
{
return Mono.mono_class_get_type(_monoClass);
}
internal bool IsType(MonoType* type)
{
return GetMonoType() == type;
}
internal bool IsSubclass(MonoClass* @class)
{
return Mono.mono_class_is_subclass_of(_monoClass, @class, false);
}
}
class ScriptClass : SharpClass
@@ -88,8 +70,8 @@ class ScriptClass : SharpClass
public bool RunInEditMode => _runInEditMode;
[AllowAppend]
public this(StringView classNamespace, StringView className, MonoImage* image, ScriptFieldType scriptFieldType = .Class) :
base(classNamespace, className, image, scriptFieldType)
public this(StringView classNamespace, StringView className, MonoImage* image) :
base(classNamespace, className, image)
{
_constructor = FindConstructor();
_onCreate = (OnCreateMethod)GetMethodThunk("OnCreate");
+2 -5
View File
@@ -585,15 +585,12 @@ static class ScriptEngine
if (scriptClass == null)
return;
let monoType = scriptClass.GetMonoType();
let monoReflectionType = Mono.mono_type_get_object(s_AppDomain, monoType);
let entityId = entity.UUID;
#unwarn
void*[2] args = .(&entityId, monoReflectionType);
void*[1] args = .(&entityId);
let method = Classes.EntityEditor.GetMethod("ShowDefaultEntityEditor", 2);
let method = Classes.EntityEditor.GetMethod("ShowDefaultEntityEditor", 1);
Classes.EntityEditor.Invoke(method, null, &args);
}
@@ -1,16 +0,0 @@
using System;
using GlitchyEngine.Core;
using GlitchyEngine.Math;
namespace GlitchyEngine.Scripting;
enum ScriptFieldType
{
case None;
case Class;
case Struct;
case Entity;
case Component;
}
+4 -2
View File
@@ -146,14 +146,16 @@ internal class EntityEditor
return false;
}
public static void ShowDefaultEntityEditor(UUID entityId, Type entityType)
public static void ShowDefaultEntityEditor(UUID entityId)
{
// TODO: Call custom editors here!
ScriptGlue.Entity_GetScriptInstance(entityId, out object? instance);
if (instance != null)
ShowEditor(entityType, instance);
{
ShowEditor(instance.GetType(), instance);
}
}
private static T? GetAttribute<T>(IEnumerable<Attribute>? attributes) where T : Attribute