Prepare script lifecycle and data layer

This commit is contained in:
2026-03-26 20:14:58 +08:00
parent 5ca5ca1f19
commit 0921f2a459
20 changed files with 1367 additions and 26 deletions

View 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