载入中...
搜索中...
未找到
EditorPropertyPresenter.cpp
浏览该文件的文档.
2
3namespace eve::editor {
4namespace {
5
6EditorValue selectionValue(const SelectionSnapshot& selection) {
8 items.reserve(selection.items.size());
9 for (const SelectionItem& item : selection.items) items.emplace_back(item.item.value());
10 return EditorValue(std::move(items));
11}
12
13Result<PropertyEditIntent> makeIntent(const PropertySchema& schema, const SelectionSnapshot& selection,
15 bool runtime) {
16 auto descriptor = schema.find(path);
17 if (!descriptor)
18 return eve::editing::failed<PropertyEditIntent>(EditorStatus::NotFound, RuleId("editor.property.not-found"),
19 "Property is not present in the schema: " + path.value());
20 if (runtime && (!hasPropertyFlag(descriptor->flags, PropertyFlag::Runtime) ||
21 hasPropertyFlag(descriptor->flags, PropertyFlag::EditorOnly)))
22 return eve::editing::failed<PropertyEditIntent>(EditorStatus::Rejected, RuleId("editor.property.runtime-hidden"),
23 "Property is unavailable in runtime editing");
24 Result<void> validation = validatePropertyValue(*descriptor, value);
25 if (!validation.ok()) return Result<PropertyEditIntent>::failure(validation.status());
26
28 payload["path"] = path.value();
29 payload["value"] = value;
30 payload["selection"] = selectionValue(selection);
31 switch (mode) {
32 case PropertySetMode::Absolute: payload["mode"] = "absolute"; break;
33 case PropertySetMode::Relative: payload["mode"] = "relative"; break;
34 case PropertySetMode::Reset: payload["mode"] = "reset"; break;
35 }
36 return eve::editing::applied<PropertyEditIntent>(
37 PropertyEditIntent{CommandId("editor.property.set"), EditorValue(std::move(payload))});
38}
39
40} // namespace
41
43 const SelectionSnapshot& selection,
44 const IPropertyProvider& provider) const {
45 PropertyPresentation presentation;
46 presentation.typeId = schema.typeId;
47 presentation.schemaVersion = schema.version;
48 presentation.rows.reserve(schema.properties.size());
49 for (const PropertyDescriptor& descriptor : schema.properties)
50 presentation.rows.push_back({descriptor, provider.read(selection, descriptor.path)});
51 return presentation;
52}
53
54Result<PropertyEditIntent> DeveloperPropertyPresenter::editIntent(const PropertySchema& schema,
55 const SelectionSnapshot& selection,
56 const PropertyPath& path,
57 const EditorValue& value,
58 PropertySetMode mode) const {
59 return makeIntent(schema, selection, path, value, mode, false);
60}
61
62PropertyPresentation RuntimePropertyPresenter::present(const PropertySchema& schema, const SelectionSnapshot& selection,
63 const IPropertyProvider& provider,
64 const HostProfile& profile) const {
65 PropertyPresentation presentation;
66 presentation.typeId = schema.typeId;
67 presentation.schemaVersion = schema.version;
68 if (!profile.hasFeatures(HostFeature::RuntimeWorld)) return presentation;
69 for (const PropertyDescriptor& descriptor : schema.properties) {
70 if (!hasPropertyFlag(descriptor.flags, PropertyFlag::Runtime) ||
71 hasPropertyFlag(descriptor.flags, PropertyFlag::EditorOnly))
72 continue;
73 presentation.rows.push_back({descriptor, provider.read(selection, descriptor.path)});
74 }
75 return presentation;
76}
77
78Result<PropertyEditIntent> RuntimePropertyPresenter::editIntent(
79 const PropertySchema& schema, const SelectionSnapshot& selection, const PropertyPath& path,
80 const EditorValue& value, const HostProfile& profile, PropertySetMode mode) const {
81 if (!profile.hasFeatures(HostFeature::RuntimeWorld))
82 return eve::editing::failed<PropertyEditIntent>(EditorStatus::Rejected,
83 RuleId("editor.property.runtime-feature-denied"),
84 "Host profile does not expose runtime world editing");
85 return makeIntent(schema, selection, path, value, mode, true);
86}
87
88} // namespace eve::editor
double value
Value::Object payload
std::string descriptor
std::string path
Definition PlayHost.cpp:110
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
UUID-backed identifier adapter for legacy textual boundaries.
Definition Identity.h:314
const std::string & value() const noexcept
Returns the exact legacy or canonical compatibility spelling.
Definition Identity.h:362
UI-independent property access for an immutable selection snapshot.
virtual PropertyReadResult read(const SelectionSnapshot &selection, const PropertyPath &path) const =0
Reads read.
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
PropertyPresentation present(const PropertySchema &schema, const SelectionSnapshot &selection, const IPropertyProvider &provider) const
Read every schema property, including advanced/editor-only rows.
Upper capability boundary for one editor host.
bool hasFeatures(HostFeature required) const
True when features.
PropertySetMode
PropertySetMode public API.
Result< void > validatePropertyValue(const PropertyDescriptor &descriptor, const Value &value)
Validate property value.
constexpr bool hasPropertyFlag(PropertyFlag value, PropertyFlag flag)
True when property flag.
eve::editing::Value EditorValue
Compatibility alias for the UI-independent authoring value tree.
Definition EditorValue.h:8
eve::editing::PropertyPath PropertyPath
Definition EditorIds.h:37
eve::editing::SelectionItem SelectionItem
Stable item stored in a selection snapshot.
eve::editing::CommandId CommandId
Definition EditorIds.h:30
eve::editing::RuleId RuleId
Definition EditorIds.h:32
eve::editing::SelectionSnapshot SelectionSnapshot
Immutable multi-selection captured for property and command work.
eve::editing::PropertySetMode PropertySetMode
eve::editing::PropertySchema PropertySchema
PropertyDescriptor public API.
EVENGINE_API_PLATFORM public API.
std::vector< PropertyDescriptor > properties
SelectionSnapshot public API.
Immutable presentation model consumed by developer or game UI.
std::vector< PropertyPresentationRow > rows