载入中...
搜索中...
未找到
EditingProperty.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <type_traits>
5#include <variant>
6
7namespace eve::editing {
8
10 auto found = std::find_if(properties.begin(), properties.end(),
11 [&](const PropertyDescriptor& property) { return property.path == path; });
12 if (found == properties.end()) return {};
14}
15
16namespace {
17
20 switch (type) {
21 case PropertyType::Bool: return Kind::Bool;
22 case PropertyType::Int: return Kind::Integer;
23 case PropertyType::Float: return Kind::Number;
24 case PropertyType::String: return Kind::String;
25 case PropertyType::Enum: return Kind::Enum;
26 case PropertyType::Color: return Kind::Color;
27 case PropertyType::Vec2: return Kind::Vec2;
28 case PropertyType::Vec3: return Kind::Vec3;
29 case PropertyType::Vec4: return Kind::Vec4;
31 case PropertyType::Struct: return Kind::Struct;
32 case PropertyType::AssetRef: return Kind::AssetRef;
33 case PropertyType::ObjectRef: return Kind::ObjectRef;
34 case PropertyType::Array: return Kind::Array;
35 case PropertyType::Map: return Kind::Map;
36 case PropertyType::Action: return Kind::Action;
37 case PropertyType::ReadOnlyText: return Kind::ReadOnlyText;
38 }
39 return Kind::Auto;
40}
41
44 Flag result = Flag::None;
45 if (hasPropertyFlag(flags, PropertyFlag::ReadOnly)) result = result | Flag::ReadOnly;
46 if (hasPropertyFlag(flags, PropertyFlag::Advanced)) result = result | Flag::Advanced;
47 if (hasPropertyFlag(flags, PropertyFlag::EditorOnly)) result = result | Flag::EditorOnly;
48 if (hasPropertyFlag(flags, PropertyFlag::Runtime)) result = result | Flag::Runtime;
49 if (hasPropertyFlag(flags, PropertyFlag::Transient)) result = result | Flag::Transient;
50 if (hasPropertyFlag(flags, PropertyFlag::Dangerous)) result = result | Flag::Dangerous;
51 if (hasPropertyFlag(flags, PropertyFlag::MultiEdit)) result = result | Flag::MultiEdit;
52 return result;
53}
54
55const char* legacyRule(const std::string& code) {
56 if (code == "property_access.property.type") return "editor.property.type-mismatch";
57 if (code == "property_access.property.read-only") return "editor.property.read-only";
58 if (code == "property_access.property.choice") return "editor.property.invalid-enum";
59 if (code == "property_access.property.finite") return "editor.property.finite";
60 if (code == "property_access.property.minimum") return "editor.property.below-minimum";
61 if (code == "property_access.property.maximum") return "editor.property.above-maximum";
62 return "editor.property.invalid-value";
63}
64
65template <class ResultValue>
66Result<ResultValue> validationError(const property_access::WriteResult& validation,
67 const PropertyDescriptor& descriptor) {
68 return failed<ResultValue>(Status::Rejected, eve::DiagnosticCode::PreconditionViolation,
69 RuleId(legacyRule(validation.code)),
70 validation.message + ": " + descriptor.path.value());
71}
72
73} // namespace
74
77 result.path = source.path.value();
78 result.displayName = source.displayNameKey;
79 result.description = source.descriptionKey;
80 result.category = source.category;
81 result.kind = convertKind(source.type);
82 result.flags = convertFlags(source.flags);
83 result.defaultValue = toPresentationValue(source.defaultValue);
84 result.numeric.minimum = source.numeric.minimum;
85 result.numeric.maximum = source.numeric.maximum;
86 result.numeric.step = source.numeric.step;
87 result.numeric.units = source.numeric.units;
88 result.numeric.precision = source.numeric.precision;
89 result.choices = source.enumItems;
90 result.presenterHint = source.presenterHint;
91 return result;
92}
93
95 return std::visit(
96 [](const auto& current) -> eve::Value {
97 using T = std::decay_t<decltype(current)>;
98 if constexpr (std::is_same_v<T, std::monostate>) {
99 return {};
100 } else if constexpr (std::is_same_v<T, Value::Array>) {
101 eve::Value::Array result;
102 result.reserve(current.size());
103 for (const Value& entry : current) result.push_back(toPresentationValue(entry));
104 return result;
105 } else if constexpr (std::is_same_v<T, Value::Object>) {
106 eve::Value::Object result;
107 for (const auto& [key, entry] : current) result.emplace(key, toPresentationValue(entry));
108 return result;
109 } else {
110 return eve::Value(current);
111 }
112 },
113 value.storage());
114}
115
117 return std::visit(
118 [](const auto& current) -> Value {
119 using T = std::decay_t<decltype(current)>;
120 if constexpr (std::is_same_v<T, std::monostate>) {
121 return {};
122 } else if constexpr (std::is_same_v<T, eve::Value::Array>) {
123 Value::Array result;
124 result.reserve(current.size());
125 for (const eve::Value& entry : current) result.push_back(toEditingValue(entry));
126 return result;
127 } else if constexpr (std::is_same_v<T, eve::Value::Object>) {
128 Value::Object result;
129 for (const auto& [key, entry] : current) result.emplace(key, toEditingValue(entry));
130 return result;
131 } else {
132 return Value(current);
133 }
134 },
135 value.storage());
136}
137
139 const property_access::WriteResult validation =
141 if (!validation.accepted) return validationError<void>(validation, descriptor);
143 return eve::editing::failed<void>(Status::Rejected, RuleId("editor.property.type-mismatch"),
144 "Value type does not match property: " + descriptor.path.value());
145 return eve::editing::applied<void>();
146}
147
148} // namespace eve::editing
double value
std::string descriptor
DiagnosticCode code
std::uint32_t key
std::string path
Definition PlayHost.cpp:110
bool found
double current
const UnitySourceAsset & source
Move-only operation result carrying either a value or Status.
Definition Result.h:155
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::map< std::string, Value > Object
Definition Value.h:34
std::vector< Value > Array
Definition Value.h:33
PropertyDescriptorLookup public API.
Dotted property path (layout.size) compared and persisted as text.
Definition EditingIds.h:78
Deterministic owning value tree shared by authoring hosts.
std::vector< Value > Array
std::map< std::string, Value > Object
eve::Value toPresentationValue(const Value &value)
To presentation value.
PropertyType
PropertyType public API.
StrongId< RuleIdTag > RuleId
Definition EditingIds.h:60
PropertyFlag
PropertyFlag public API.
Result< void > validatePropertyValue(const PropertyDescriptor &descriptor, const Value &value)
Validate property value.
Value toEditingValue(const eve::Value &value)
To editing value.
property_access::PropertyDescriptor toPresentationDescriptor(const PropertyDescriptor &source)
To presentation descriptor.
PropertyFlag
Cross-host property visibility and editing flags.
PropertyKind
Semantic property kind used by renderer-independent presenters.
WriteResult validatePropertyValue(const PropertyDescriptor &property, const Value &value)
Validate one candidate value against the shared property contract.
std::optional< double > maximum
std::optional< double > step
std::optional< double > minimum
PropertyDescriptor public API.
std::vector< PropertyDescriptor > properties
PropertyDescriptorLookup find(const PropertyPath &path) const
Finds find.
One stable property description consumed by any UI shell.
Result of a model write, including a stable diagnostic code.