Prepare script lifecycle and data layer
This commit is contained in:
65
engine/include/XCEngine/Scripting/ScriptField.h
Normal file
65
engine/include/XCEngine/Scripting/ScriptField.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/Core/Math/Vector2.h>
|
||||
#include <XCEngine/Core/Math/Vector3.h>
|
||||
#include <XCEngine/Core/Math/Vector4.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Scripting {
|
||||
|
||||
enum class ScriptFieldType {
|
||||
None = 0,
|
||||
Float,
|
||||
Double,
|
||||
Bool,
|
||||
Int32,
|
||||
UInt64,
|
||||
String,
|
||||
Vector2,
|
||||
Vector3,
|
||||
Vector4,
|
||||
GameObject
|
||||
};
|
||||
|
||||
struct GameObjectReference {
|
||||
uint64_t gameObjectUUID = 0;
|
||||
|
||||
bool operator==(const GameObjectReference& other) const {
|
||||
return gameObjectUUID == other.gameObjectUUID;
|
||||
}
|
||||
|
||||
bool operator!=(const GameObjectReference& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
};
|
||||
|
||||
using ScriptFieldValue = std::variant<
|
||||
std::monostate,
|
||||
float,
|
||||
double,
|
||||
bool,
|
||||
int32_t,
|
||||
uint64_t,
|
||||
std::string,
|
||||
Math::Vector2,
|
||||
Math::Vector3,
|
||||
Math::Vector4,
|
||||
GameObjectReference>;
|
||||
|
||||
std::string ScriptFieldTypeToString(ScriptFieldType type);
|
||||
bool TryParseScriptFieldType(const std::string& value, ScriptFieldType& outType);
|
||||
|
||||
bool IsScriptFieldValueCompatible(ScriptFieldType type, const ScriptFieldValue& value);
|
||||
ScriptFieldValue CreateDefaultScriptFieldValue(ScriptFieldType type);
|
||||
std::string SerializeScriptFieldValue(ScriptFieldType type, const ScriptFieldValue& value);
|
||||
bool TryDeserializeScriptFieldValue(ScriptFieldType type, const std::string& value, ScriptFieldValue& outValue);
|
||||
|
||||
std::string EscapeScriptString(const std::string& value);
|
||||
std::string UnescapeScriptString(const std::string& value);
|
||||
|
||||
} // namespace Scripting
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user