feat(scripting): add field model editing and defaults support
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Scripting {
|
||||
@@ -37,6 +38,56 @@ struct GameObjectReference {
|
||||
}
|
||||
};
|
||||
|
||||
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,
|
||||
@@ -50,6 +101,80 @@ using ScriptFieldValue = std::variant<
|
||||
Math::Vector4,
|
||||
GameObjectReference>;
|
||||
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user