This commit is contained in:
Wojciech Figat
2021-11-22 17:06:54 +01:00
parent fd150b3cc1
commit 32fc3acc67
2 changed files with 14 additions and 8 deletions

View File

@@ -5,12 +5,14 @@
#include "ScriptingType.h"
#include "Engine/Core/Types/String.h"
// Utilities for using enums types (declared in scripting with API_ENUM).
template<class EnumType>
/// <summary>
/// Utilities for using enums types (declared in scripting with API_ENUM).
/// </summary>
class ScriptingEnum
{
public:
// Gets the list with enum items (the last item Name is null)
template<class EnumType>
static const ScriptingType::EnumItem* GetItems()
{
const ScriptingTypeHandle typeHandle = StaticType<EnumType>();
@@ -24,9 +26,10 @@ public:
}
// Gets the name of the enum value or null if invalid
template<class EnumType>
static const char* GetName(EnumType value)
{
if (const auto items = GetItems())
if (const auto items = GetItems<EnumType>())
{
for (int32 i = 0; items[i].Name; i++)
{
@@ -38,15 +41,17 @@ public:
}
// Gets the name of the enum value or empty string if invalid
template<class EnumType>
static String ToString(EnumType value)
{
return String(GetName(value));
return String(GetName<EnumType>(value));
}
// Gets the value of the enum based on the name.
template<class EnumType>
static EnumType FromString(const StringAnsiView& name)
{
if (const auto items = GetItems())
if (const auto items = GetItems<EnumType>())
{
for (int32 i = 0; items[i].Name; i++)
{
@@ -58,8 +63,9 @@ public:
}
// Gets the value of the enum based on the name.
template<class EnumType>
static EnumType FromString(const StringView& name)
{
return FromString(StringAnsi(name));
return FromString<EnumType>(StringAnsi(name));
}
};

View File

@@ -21,7 +21,7 @@ public:
/// Global table for registered even binder methods (key is pair of type and event name, value is method that takes instance with event, object to bind and flag to bind or unbind).
/// </summary>
/// <remarks>
/// Key: pair of event type name (full), event name.
/// Key: pair of event type, event name.
/// Value: event binder function with parameters: event caller instance (null for static events), object to bind, true to bind/false to unbind.
/// </remarks>
static Dictionary<Pair<ScriptingTypeHandle, StringView>, void(*)(ScriptingObject*, void*, bool)> EventsTable;
@@ -30,7 +30,7 @@ public:
/// The action called when any scripting event occurs. Can be used to invoke scripting code that binded to this particular event.
/// </summary>
/// <remarks>
/// Delegate parameters: event caller instance (null for static events), event invocation parameters list, event type name (full), event name.
/// Delegate parameters: event caller instance (null for static events), event invocation parameters list, event type, event name.
/// </remarks>
static Delegate<ScriptingObject*, Span<Variant>, ScriptingTypeHandle, StringView> Event;
};