载入中...
搜索中...
未找到
avatar_editor.cpp
浏览该文件的文档.
3
7#include "common/Capability.h"
10
11#include <simplesquirrel/simplesquirrel.hpp>
12
13#include <stdexcept>
14#include <string>
15#include <string_view>
16#include <utility>
17#include <vector>
18
20namespace {
21
22std::string stringField(const editor::EditorValue::Object& request, const char* key) {
23 const auto found = request.find(key);
24 if (found == request.end()) return {};
25 const auto* value = found->second.getIf<std::string>();
26 return value ? *value : std::string{};
27}
28
31 if (!operation.ok())
33 return target.applyDomainOperation(operation.value());
34}
35
36} // namespace
37
39public:
40 std::vector<std::string_view> types() const override { return {"avatar"}; }
41
43 const editor::TargetId& target, std::string_view type, const editor::EditorValue::Object& request) override {
44 (void)type;
45 auto document = std::make_unique<avatar_editing::AvatarDocumentTarget>(target.value());
46 const std::string kind = stringField(request, "kind");
47 const std::string source = stringField(request, "source");
48 if (!kind.empty() || !source.empty()) {
49 auto applied = apply(*document, document->makeSetSource(kind.empty() ? document->kind() : kind, source));
50 if (!applied.ok())
52 }
53 const std::string layer = stringField(request, "layer");
54 if (!layer.empty()) {
57 value.name = layer;
58 const std::string texture = stringField(request, "texture");
59 value.textureAsset = texture.empty() ? layer + ".png" : texture;
60 auto applied = apply(*document, document->makeCreateLayer(value));
61 if (!applied.ok())
63 }
64 const std::string parameter = stringField(request, "parameter");
65 if (!parameter.empty()) {
67 value.id = editor::ObjectId(parameter);
68 value.name = parameter;
69 auto applied = apply(*document, document->makeCreateParameter(value));
70 if (!applied.ok())
72 }
74 owned.target = std::move(document);
75 return eve::editing::applied<editor::AutomationOwnedTarget>(std::move(owned));
76 }
77};
78
80
82 auto* registry = eve::cap::query<editing::IEditingCommandRegistry>();
83 if (!registry || !avatar_editing::registerEditingCommands(*registry).ok())
84 throw std::runtime_error("Failed to register avatar editing commands");
85 eve::cap::addListener<editor::IEditorAutomationTargetFactory>(factory_.get());
86}
87
89 eve::cap::removeListener<editor::IEditorAutomationTargetFactory>(factory_.get());
90 if (auto* registry = eve::cap::query<editing::IEditingCommandRegistry>())
91 registry->unregisterOwner("avatar_editing").ignore("avatar editor adapter shutdown");
92}
93
94void AvatarEditorModule::expose(ssq::Table& table) {
95 auto module = table.addClass(name, AvatarEditorModule::create, false);
97}
98void AvatarEditorModule::expose(ssq::Class&) {}
99
100} // namespace eve::avatar_editor
LogicalId target
ActionParameterOperation operation
double value
ActiveSource owned
Squirrel adapter for the avatar document editor.
const GltfImportRequest & request
std::uint32_t key
TokenKind kind
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:26
TileLayer * layer
bool found
const UnitySourceAsset & source
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
Revisioned image/Live2D/VRoid Avatar authoring asset.
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 avatar editing commands and automation targets.
~AvatarEditorModule() override
Avatar editor module.
AvatarEditorModule()
Avatar editor module.
std::map< std::string, Value > Object
Multi-provider extension point for domain-specific automation target creation.
editing::Result< void > registerEditingCommands(editing::IEditingCommandRegistry &registry)
Register Avatar-owned property and structure commands with a generic editing host.
void exposeAvatarDocumentEditorScriptBindings(ssq::Table &table, ssq::Class &moduleClass)
Expose the script-owned AvatarDocumentEditor factory on AvatarEditorModule.
eve::editing::ObjectId ObjectId
Definition EditorIds.h:38
Stable image layer in an Avatar asset.
Reflected Avatar parameter and its initial value.
Target plus optional borrowed-dependency owner returned by an automation factory.
std::unique_ptr< IEditableTarget > target