mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Better engine exception for scripting
This commit is contained in:
@@ -17,24 +17,16 @@ internal enum EngineResult
|
||||
EntityNotFound = -4, // The entity doesn't exist or was deleted.
|
||||
EntityDoesntHaveComponent = -5, // The entity has no component of type {typeof(T)} or it was deleted.
|
||||
AssetNotFound = -6, // No asset exists for AssetHandle \"{assetId}\".
|
||||
CustomError = 1 << 31
|
||||
}
|
||||
|
||||
public class EngineException(string message) : Exception(message);
|
||||
|
||||
public class EntityNotFoundException : Exception
|
||||
{
|
||||
|
||||
}
|
||||
public class EntityNotFoundException(string? message = null) : Exception(message);
|
||||
|
||||
public class ComponentNotFoundException : Exception
|
||||
{
|
||||
|
||||
}
|
||||
public class ComponentNotFoundException(string? message = null) : Exception(message);
|
||||
|
||||
public class AssetNotFoundException : Exception
|
||||
{
|
||||
|
||||
}
|
||||
public class AssetNotFoundException(string? message = null) : Exception(message);
|
||||
|
||||
internal static class EngineErrors
|
||||
{
|
||||
@@ -43,22 +35,24 @@ internal static class EngineErrors
|
||||
if (result >= 0)
|
||||
return;
|
||||
|
||||
string engineMessage = ScriptGlue.GetLastExceptionMessage();
|
||||
|
||||
switch (result)
|
||||
{
|
||||
case EngineResult.Error:
|
||||
throw new EngineException($"Unspecified engine excepiton in {callerName}");
|
||||
throw new EngineException(engineMessage ?? $"Unspecified engine excepiton in {callerName}");
|
||||
case EngineResult.NotImplemented:
|
||||
throw new NotImplementedException($"Function {callerName} is not implemented in the engine.");
|
||||
throw new NotImplementedException(engineMessage ?? $"Function {callerName} is not implemented in the engine.");
|
||||
case EngineResult.ArgumentError:
|
||||
throw new ArgumentException($"An argument passed to {callerName} is invalid.");
|
||||
throw new ArgumentException(engineMessage ?? $"An argument passed to {callerName} is invalid.");
|
||||
case EngineResult.EntityNotFound:
|
||||
throw new EntityNotFoundException();
|
||||
throw new EntityNotFoundException(engineMessage);
|
||||
case EngineResult.EntityDoesntHaveComponent:
|
||||
throw new ComponentNotFoundException();
|
||||
throw new ComponentNotFoundException(engineMessage);
|
||||
case EngineResult.AssetNotFound:
|
||||
throw new AssetNotFoundException();
|
||||
throw new AssetNotFoundException(engineMessage);
|
||||
default:
|
||||
throw new EngineException($"Unknown engine excepiton in {callerName}");
|
||||
throw new EngineException(engineMessage ?? $"Unknown engine excepiton in {callerName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ internal static unsafe partial class ScriptGlue
|
||||
struct ComponentFunctionPointers
|
||||
{
|
||||
public delegate* unmanaged[Cdecl]<UUID, void> AddComponent;
|
||||
public delegate* unmanaged[Cdecl]<UUID, bool> HasComponent;
|
||||
public delegate* unmanaged[Cdecl]<UUID, EngineResult> HasComponent;
|
||||
public delegate* unmanaged[Cdecl]<UUID, void> RemoveComponent;
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ internal static unsafe partial class ScriptGlue
|
||||
[UnmanagedCallersOnly]
|
||||
public static void RegisterComponentType(byte* fullComponentTypeName,
|
||||
delegate* unmanaged[Cdecl]<UUID, void> addComponent,
|
||||
delegate* unmanaged[Cdecl]<UUID, bool> hasComponent,
|
||||
delegate* unmanaged[Cdecl]<UUID, EngineResult> hasComponent,
|
||||
delegate* unmanaged[Cdecl]<UUID, void> removeComponent)
|
||||
{
|
||||
string? beefComponentTypeName = Marshal.PtrToStringUTF8((IntPtr)fullComponentTypeName);
|
||||
@@ -421,7 +421,9 @@ internal static unsafe partial class ScriptGlue
|
||||
|
||||
public static bool Entity_HasComponent(UUID entityId, Type componentType)
|
||||
{
|
||||
return ComponentTypeFunctions[componentType].HasComponent(entityId);
|
||||
EngineResult returnValue = ComponentTypeFunctions[componentType].HasComponent(entityId);
|
||||
EngineErrors.ThrowIfError(returnValue);
|
||||
return returnValue == EngineResult.Ok;
|
||||
}
|
||||
|
||||
public static void Entity_RemoveComponent(UUID entityId, Type componentType)
|
||||
|
||||
Reference in New Issue
Block a user