feat(scripting): add field model editing and defaults support
This commit is contained in:
@@ -2,9 +2,12 @@
|
||||
|
||||
#include <XCEngine/Scripting/IScriptRuntime.h>
|
||||
#include <XCEngine/Scripting/NullScriptRuntime.h>
|
||||
#include <XCEngine/Scripting/ScriptFieldStorage.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
@@ -37,6 +40,60 @@ public:
|
||||
bool HasTrackedScriptComponent(const ScriptComponent* component) const;
|
||||
bool HasRuntimeInstance(const ScriptComponent* component) const;
|
||||
size_t GetTrackedScriptCount() const { return m_scriptOrder.size(); }
|
||||
bool TrySetScriptFieldValue(
|
||||
ScriptComponent* component,
|
||||
const std::string& fieldName,
|
||||
ScriptFieldType type,
|
||||
const ScriptFieldValue& value);
|
||||
bool TryGetScriptFieldValue(
|
||||
const ScriptComponent* component,
|
||||
const std::string& fieldName,
|
||||
ScriptFieldValue& outValue) const;
|
||||
bool ApplyScriptFieldWrites(
|
||||
ScriptComponent* component,
|
||||
const std::vector<ScriptFieldWriteRequest>& requests,
|
||||
std::vector<ScriptFieldWriteResult>& outResults);
|
||||
bool ClearScriptFieldOverrides(
|
||||
ScriptComponent* component,
|
||||
const std::vector<ScriptFieldClearRequest>& requests,
|
||||
std::vector<ScriptFieldClearResult>& outResults);
|
||||
bool TryGetScriptFieldModel(
|
||||
const ScriptComponent* component,
|
||||
ScriptFieldModel& outModel) const;
|
||||
bool TryGetScriptFieldSnapshots(
|
||||
const ScriptComponent* component,
|
||||
std::vector<ScriptFieldSnapshot>& outFields) const;
|
||||
|
||||
template<typename T>
|
||||
bool TrySetScriptFieldValue(ScriptComponent* component, const std::string& fieldName, const T& value) {
|
||||
using ValueType = std::decay_t<T>;
|
||||
return TrySetScriptFieldValue(
|
||||
component,
|
||||
fieldName,
|
||||
ScriptFieldTypeResolver<ValueType>::value,
|
||||
ScriptFieldValue(ValueType(value)));
|
||||
}
|
||||
|
||||
bool TrySetScriptFieldValue(ScriptComponent* component, const std::string& fieldName, const char* value) {
|
||||
return TrySetScriptFieldValue(component, fieldName, std::string(value ? value : ""));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool TryGetScriptFieldValue(const ScriptComponent* component, const std::string& fieldName, T& outValue) const {
|
||||
ScriptFieldValue value;
|
||||
if (!TryGetScriptFieldValue(component, fieldName, value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
using ValueType = std::decay_t<T>;
|
||||
const ValueType* typedValue = std::get_if<ValueType>(&value);
|
||||
if (!typedValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
outValue = *typedValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
struct ScriptInstanceKey {
|
||||
|
||||
Reference in New Issue
Block a user