mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
ScriptGlue: Added Log.Exception
- Also pushed missing List Editor fix
This commit is contained in:
@@ -73,7 +73,7 @@ internal class EntityEditor
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
Log.Exception(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -558,7 +558,7 @@ internal class EntityEditor
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
Log.Exception(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -711,7 +711,19 @@ internal class EntityEditor
|
||||
|
||||
ImGui.PopID();
|
||||
}
|
||||
|
||||
|
||||
ShowButtons(type, reference);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows all buttons in the UI.
|
||||
/// </summary>
|
||||
private static void ShowButtons(Type type, object? reference)
|
||||
{
|
||||
ImGui.PushID("Buttons");
|
||||
|
||||
int i = 0;
|
||||
|
||||
// Iterate all methods
|
||||
foreach (MethodInfo method in type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
|
||||
{
|
||||
@@ -735,11 +747,24 @@ internal class EntityEditor
|
||||
}
|
||||
else if (ImGui.Button(showButton.ButtonText))
|
||||
{
|
||||
method.Invoke(reference, null);
|
||||
try
|
||||
{
|
||||
method.Invoke(reference, null);
|
||||
}
|
||||
catch (TargetInvocationException ex)
|
||||
{
|
||||
Log.Exception(ex.InnerException ?? ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Exception(ex);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.PopID();
|
||||
}
|
||||
|
||||
ImGui.PopID();
|
||||
}
|
||||
|
||||
struct ListPayload
|
||||
@@ -763,9 +788,18 @@ internal class EntityEditor
|
||||
|
||||
Debug.Assert(list != null);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Reference values can be null
|
||||
object? newElement = elementType.IsByRef ? null : ActivatorExtension.CreateInstanceSafe(elementType);
|
||||
|
||||
object? newElement = ActivatorExtension.CreateInstanceSafe(elementType);
|
||||
list?.Add(newElement);
|
||||
list?.Add(newElement);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error($"Failed to add new element to list: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveElement(IList? list, out object? newList)
|
||||
@@ -882,7 +916,7 @@ internal class EntityEditor
|
||||
|
||||
ImGui.SameLine(ImGui.GetWindowContentRegionMax().X - removeButtonWidth);
|
||||
|
||||
ImGui.BeginDisabled(myList == null || myList.Count == 0);
|
||||
ImGui.BeginDisabled(myList == null);
|
||||
|
||||
if (ImGui.SmallButton("-"))
|
||||
{
|
||||
|
||||
+20
-14
@@ -1,4 +1,4 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System;
|
||||
|
||||
namespace GlitchyEngine;
|
||||
|
||||
@@ -10,7 +10,7 @@ public class Log
|
||||
/// <summary>
|
||||
/// The severity of the log message.
|
||||
/// </summary>
|
||||
private enum LogLevel
|
||||
internal enum LogLevel
|
||||
{
|
||||
Trace = 0,
|
||||
Debug,
|
||||
@@ -27,7 +27,7 @@ public class Log
|
||||
/// <param name="message">The message to log.</param>
|
||||
public static void Trace(string message)
|
||||
{
|
||||
LogMessage_Impl(LogLevel.Trace, message);
|
||||
ScriptGlue.Log_LogMessage(LogLevel.Trace, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -36,7 +36,7 @@ public class Log
|
||||
/// <param name="message">The message to log.</param>
|
||||
public static void Info(string message)
|
||||
{
|
||||
LogMessage_Impl(LogLevel.Info, message);
|
||||
ScriptGlue.Log_LogMessage(LogLevel.Info, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -45,7 +45,7 @@ public class Log
|
||||
/// <param name="message">The message to log.</param>
|
||||
public static void Warning(string message)
|
||||
{
|
||||
LogMessage_Impl(LogLevel.Warning, message);
|
||||
ScriptGlue.Log_LogMessage(LogLevel.Warning, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,7 +54,7 @@ public class Log
|
||||
/// <param name="message">The message to log.</param>
|
||||
public static void Error(string message)
|
||||
{
|
||||
LogMessage_Impl(LogLevel.Error, message);
|
||||
ScriptGlue.Log_LogMessage(LogLevel.Error, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -63,7 +63,7 @@ public class Log
|
||||
/// <param name="message">The message to log.</param>
|
||||
public static void Critical(string message)
|
||||
{
|
||||
LogMessage_Impl(LogLevel.Critical, message);
|
||||
ScriptGlue.Log_LogMessage(LogLevel.Critical, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -72,7 +72,7 @@ public class Log
|
||||
/// <param name="obj">The object to serialize.</param>
|
||||
public static void Trace(object obj)
|
||||
{
|
||||
LogMessage_Impl(LogLevel.Trace, obj.ToString());
|
||||
ScriptGlue.Log_LogMessage(LogLevel.Trace, obj.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -81,7 +81,7 @@ public class Log
|
||||
/// <param name="obj">The object to serialize.</param>
|
||||
public static void Info(object obj)
|
||||
{
|
||||
LogMessage_Impl(LogLevel.Info, obj.ToString());
|
||||
ScriptGlue.Log_LogMessage(LogLevel.Info, obj.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -90,7 +90,7 @@ public class Log
|
||||
/// <param name="obj">The object to serialize.</param>
|
||||
public static void Warning(object obj)
|
||||
{
|
||||
LogMessage_Impl(LogLevel.Warning, obj.ToString());
|
||||
ScriptGlue.Log_LogMessage(LogLevel.Warning, obj.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -99,7 +99,7 @@ public class Log
|
||||
/// <param name="obj">The object to serialize.</param>
|
||||
public static void Error(object obj)
|
||||
{
|
||||
LogMessage_Impl(LogLevel.Error, obj.ToString());
|
||||
ScriptGlue.Log_LogMessage(LogLevel.Error, obj.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -108,9 +108,15 @@ public class Log
|
||||
/// <param name="obj">The object to serialize.</param>
|
||||
public static void Critical(object obj)
|
||||
{
|
||||
LogMessage_Impl(LogLevel.Critical, obj.ToString());
|
||||
ScriptGlue.Log_LogMessage(LogLevel.Critical, obj.ToString());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
private static extern string LogMessage_Impl(LogLevel logLevel, string message);
|
||||
/// <summary>
|
||||
/// Logs the give exception.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception to log.</param>
|
||||
public static void Exception(Exception exception)
|
||||
{
|
||||
ScriptGlue.Log_LogException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,17 @@ namespace GlitchyEngine;
|
||||
/// </summary>
|
||||
internal static class ScriptGlue
|
||||
{
|
||||
#region Log
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal static extern void Log_LogMessage(Log.LogLevel logLevel, string message);
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
public static extern void Log_LogException(Exception exception);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Entity
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
|
||||
@@ -134,7 +134,7 @@ public class SerializedObject
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
Log.Exception(e);
|
||||
// Don't attempt to use any other serializer after this error...
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user