载入中...
搜索中...
未找到
SceneEditorModule.cpp
浏览该文件的文档.
3
4#include "common/Capability.h"
9#include "scene/Scene.h"
10
11#include <simplesquirrel/simplesquirrel.hpp>
12
13#include <stdexcept>
14#include <string>
15#include <string_view>
16#include <vector>
17
19namespace {
20
21std::string stringField(const editor::EditorValue::Object& request, const char* key) {
22 const auto found = request.find(key);
23 if (found == request.end()) return {};
24 const auto* value = found->second.getIf<std::string>();
25 return value ? *value : std::string{};
26}
27
28} // namespace
29
31public:
32 std::vector<std::string_view> types() const override { return {"scene", "scene-host"}; }
33
35 const editor::TargetId& target, std::string_view type,
36 const editor::EditorValue::Object& request) override {
38 if (type == "scene") {
39 auto sceneTarget = std::make_unique<scene_editing::SceneDocumentTarget>(target.value());
40 const std::string object = stringField(request, "object");
41 if (!object.empty()) {
43 create.id = editor::ObjectId(object);
44 create.name = object;
45 auto operation = sceneTarget->makeCreate(create);
46 if (!operation.ok())
48 operation.status());
49 auto applied = sceneTarget->applyDomainOperation(operation.value());
50 if (!applied.ok())
52 applied.status());
53 }
54 owned.target = std::move(sceneTarget);
55 return eve::editing::applied<editor::AutomationOwnedTarget>(std::move(owned));
56 }
57
58 const std::string host = stringField(request, "host");
59 if (host.empty())
60 return eve::editing::failed<editor::AutomationOwnedTarget>(
61 editor::EditorStatus::Rejected, editor::RuleId("editor.automation.scene-host-name"),
62 "Live scene target requires a host name");
63 auto* sceneModule = eve::ModuleManager::getInstance<eve::scene::Scene>("Scene");
64 if (!sceneModule)
65 return eve::editing::failed<editor::AutomationOwnedTarget>(
66 editor::EditorStatus::Unsupported, editor::RuleId("editor.automation.scene-module-unavailable"),
67 "Scene module is not available");
68 auto hostResult = sceneModule->findHost(host);
69 if (!hostResult.ok() || !hostResult.value())
70 return eve::editing::failed<editor::AutomationOwnedTarget>(
71 editor::EditorStatus::NotFound, editor::RuleId("editor.automation.scene-host-not-found"),
72 "Live SceneHost does not exist: " + host);
73 owned.target = std::make_unique<scene_editing::SceneHostEditorTarget>(target.value(), hostResult.value());
74 return eve::editing::applied<editor::AutomationOwnedTarget>(std::move(owned));
75 }
76};
77
79
81 auto* registry = eve::cap::query<editing::IEditingCommandRegistry>();
82 if (!registry || !scene_editing::registerEditingCommands(*registry).ok())
83 throw std::runtime_error("Failed to register scene editing commands");
84 eve::cap::addListener<editor::IEditorAutomationTargetFactory>(factory_.get());
85}
86
88 eve::cap::removeListener<editor::IEditorAutomationTargetFactory>(factory_.get());
89 if (auto* registry = eve::cap::query<editing::IEditingCommandRegistry>())
90 registry->unregisterOwner("scene_editing").ignore("scene editor adapter shutdown");
91}
92
93void SceneEditorModule::expose(ssq::Table& table) {
94 auto module = table.addClass(name, SceneEditorModule::create, false);
95 exposeSceneEditorSessions(table, module);
96}
97void SceneEditorModule::expose(ssq::Class&) {}
98
99} // namespace eve::scene_editor
LogicalId target
ActionParameterOperation operation
double value
ActiveSource owned
const GltfImportRequest & request
std::uint32_t key
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:26
bool found
Json object
UIHostHandle host
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
std::map< std::string, Value > Object
Multi-provider extension point for domain-specific automation target creation.
std::vector< std::string_view > types() const override
Stable target type names this factory accepts.
editor::Result< editor::AutomationOwnedTarget > create(const editor::TargetId &target, std::string_view type, const editor::EditorValue::Object &request) override
Create a domain target from an automation request. @ownership Success transfers the target and any su...
Composition adapter that contributes scene editing commands and automation targets.
~SceneEditorModule() override
Scene editor module.
eve::editing::ObjectId ObjectId
Definition EditorIds.h:38
editing::Result< void > registerEditingCommands(editing::IEditingCommandRegistry &registry)
Register Scene-owned commands with a generic editing host.
void exposeSceneEditorSessions(ssq::Table &table, ssq::Class &module)
Register owned, UI-neutral scene editing sessions in the supplied VM; owner-thread only.
Target plus optional borrowed-dependency owner returned by an automation factory.
Request used to create a scene object in either backend.
Definition SceneTarget.h:27