207 lines
5.2 KiB
C++
207 lines
5.2 KiB
C++
#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>
|
|
#include <vector>
|
|
|
|
namespace XCEngine {
|
|
namespace Scripting {
|
|
|
|
enum class ScriptFieldType {
|
|
None = 0,
|
|
Float,
|
|
Double,
|
|
Bool,
|
|
Int32,
|
|
UInt64,
|
|
String,
|
|
Vector2,
|
|
Vector3,
|
|
Vector4,
|
|
GameObject,
|
|
Component
|
|
};
|
|
|
|
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);
|
|
}
|
|
};
|
|
|
|
struct ComponentReference {
|
|
uint64_t gameObjectUUID = 0;
|
|
uint64_t scriptComponentUUID = 0;
|
|
|
|
bool operator==(const ComponentReference& other) const {
|
|
return gameObjectUUID == other.gameObjectUUID
|
|
&& scriptComponentUUID == other.scriptComponentUUID;
|
|
}
|
|
|
|
bool operator!=(const ComponentReference& other) const {
|
|
return !(*this == other);
|
|
}
|
|
};
|
|
|
|
struct ScriptFieldMetadata {
|
|
std::string name;
|
|
ScriptFieldType type = ScriptFieldType::None;
|
|
|
|
bool operator==(const ScriptFieldMetadata& other) const {
|
|
return name == other.name && type == other.type;
|
|
}
|
|
|
|
bool operator!=(const ScriptFieldMetadata& other) const {
|
|
return !(*this == other);
|
|
}
|
|
};
|
|
|
|
enum class ScriptFieldClassStatus {
|
|
Unassigned = 0,
|
|
Available,
|
|
Missing
|
|
};
|
|
|
|
enum class ScriptFieldValueSource {
|
|
None = 0,
|
|
DefaultValue,
|
|
StoredValue,
|
|
ManagedValue
|
|
};
|
|
|
|
enum class ScriptFieldIssue {
|
|
None = 0,
|
|
StoredOnly,
|
|
TypeMismatch
|
|
};
|
|
|
|
enum class ScriptFieldWriteStatus {
|
|
Applied = 0,
|
|
EmptyFieldName,
|
|
UnknownField,
|
|
InvalidValue,
|
|
TypeMismatch,
|
|
StoredOnlyField,
|
|
ApplyFailed
|
|
};
|
|
|
|
enum class ScriptFieldClearStatus {
|
|
Applied = 0,
|
|
EmptyFieldName,
|
|
UnknownField,
|
|
NoValueToClear,
|
|
ApplyFailed
|
|
};
|
|
|
|
using ScriptFieldValue = std::variant<
|
|
std::monostate,
|
|
float,
|
|
double,
|
|
bool,
|
|
int32_t,
|
|
uint64_t,
|
|
std::string,
|
|
Math::Vector2,
|
|
Math::Vector3,
|
|
Math::Vector4,
|
|
GameObjectReference,
|
|
ComponentReference>;
|
|
|
|
struct ScriptFieldDefaultValue {
|
|
std::string fieldName;
|
|
ScriptFieldType type = ScriptFieldType::None;
|
|
ScriptFieldValue value = std::monostate{};
|
|
|
|
bool operator==(const ScriptFieldDefaultValue& other) const {
|
|
return fieldName == other.fieldName
|
|
&& type == other.type
|
|
&& value == other.value;
|
|
}
|
|
|
|
bool operator!=(const ScriptFieldDefaultValue& other) const {
|
|
return !(*this == other);
|
|
}
|
|
};
|
|
|
|
struct ScriptFieldSnapshot {
|
|
ScriptFieldMetadata metadata;
|
|
bool declaredInClass = false;
|
|
bool hasDefaultValue = false;
|
|
ScriptFieldValue defaultValue = std::monostate{};
|
|
bool hasValue = false;
|
|
ScriptFieldValue value = std::monostate{};
|
|
ScriptFieldValueSource valueSource = ScriptFieldValueSource::None;
|
|
ScriptFieldIssue issue = ScriptFieldIssue::None;
|
|
bool hasStoredValue = false;
|
|
ScriptFieldType storedType = ScriptFieldType::None;
|
|
ScriptFieldValue storedValue = std::monostate{};
|
|
|
|
bool operator==(const ScriptFieldSnapshot& other) const {
|
|
return metadata == other.metadata
|
|
&& declaredInClass == other.declaredInClass
|
|
&& hasDefaultValue == other.hasDefaultValue
|
|
&& defaultValue == other.defaultValue
|
|
&& hasValue == other.hasValue
|
|
&& value == other.value
|
|
&& valueSource == other.valueSource
|
|
&& issue == other.issue
|
|
&& hasStoredValue == other.hasStoredValue
|
|
&& storedType == other.storedType
|
|
&& storedValue == other.storedValue;
|
|
}
|
|
|
|
bool operator!=(const ScriptFieldSnapshot& other) const {
|
|
return !(*this == other);
|
|
}
|
|
};
|
|
|
|
struct ScriptFieldModel {
|
|
ScriptFieldClassStatus classStatus = ScriptFieldClassStatus::Unassigned;
|
|
std::vector<ScriptFieldSnapshot> fields;
|
|
};
|
|
|
|
struct ScriptFieldWriteRequest {
|
|
std::string fieldName;
|
|
ScriptFieldType type = ScriptFieldType::None;
|
|
ScriptFieldValue value = std::monostate{};
|
|
};
|
|
|
|
struct ScriptFieldWriteResult {
|
|
std::string fieldName;
|
|
ScriptFieldType type = ScriptFieldType::None;
|
|
ScriptFieldWriteStatus status = ScriptFieldWriteStatus::ApplyFailed;
|
|
};
|
|
|
|
struct ScriptFieldClearRequest {
|
|
std::string fieldName;
|
|
};
|
|
|
|
struct ScriptFieldClearResult {
|
|
std::string fieldName;
|
|
ScriptFieldClearStatus status = ScriptFieldClearStatus::ApplyFailed;
|
|
};
|
|
|
|
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
|