载入中...
搜索中...
未找到
AvatarDocumentEditorScriptBindings.cpp
浏览该文件的文档.
2
6
7#include <simplesquirrel/simplesquirrel.hpp>
8
9#include <string>
11
12namespace eve::avatar_editor {
13namespace {
14
15constexpr const char* kBindingSource = "editor.avatar.document.squirrel";
16
17class ScriptAvatarDocumentEditor {
18public:
19 explicit ScriptAvatarDocumentEditor(std::string targetId) : editor_(std::move(targetId)) {}
20
21 AvatarDocumentEditor& editor() noexcept { return editor_; }
22 const AvatarDocumentEditor& editor() const noexcept { return editor_; }
23
24private:
25 AvatarDocumentEditor editor_;
26};
27
28} // namespace
29
30void exposeAvatarDocumentEditorScriptBindings(ssq::Table& table, ssq::Class& moduleClass) {
31 const editor::ScriptBind bind{table.getHandle(), kBindingSource};
32 auto avatarEditor = editor::addScriptClass<ScriptAvatarDocumentEditor>(table, "AvatarDocumentEditor");
33 editor::registerEditorWorkspace<ScriptAvatarDocumentEditor>(avatarEditor, bind,
34 "avatar editor and workspace must not be null");
35 avatarEditor.addFunc("selectLayer", [bind](ScriptAvatarDocumentEditor* self, const std::string& id) {
36 return bind.checked(self, "avatar editor must not be null", [&] { return self->editor().selectLayer(id); });
37 });
38 avatarEditor.addFunc("selectParameter", [bind](ScriptAvatarDocumentEditor* self, const std::string& id) {
39 return bind.checked(self, "avatar editor must not be null", [&] { return self->editor().selectParameter(id); });
40 });
41 avatarEditor.addFunc("selectExpression", [bind](ScriptAvatarDocumentEditor* self, const std::string& id) {
42 return bind.checked(self, "avatar editor must not be null",
43 [&] { return self->editor().selectExpression(id); });
44 });
45 avatarEditor.addFunc("pointerDown", [bind](ScriptAvatarDocumentEditor* self, float x, float y) {
46 return bind.checked(self, "avatar editor must not be null", [&] { return self->editor().pointerDown(x, y); });
47 });
48 avatarEditor.addFunc("setLayerVisible", [bind](ScriptAvatarDocumentEditor* self, bool visible) {
49 return bind.checked(self, "avatar editor must not be null",
50 [&] { return self->editor().setLayerVisible(visible); });
51 });
52 avatarEditor.addFunc("setLayerZ", [bind](ScriptAvatarDocumentEditor* self, int zIndex) {
53 return bind.checked(self, "avatar editor must not be null", [&] { return self->editor().setLayerZ(zIndex); });
54 });
55 avatarEditor.addFunc("setParameterValue", [bind](ScriptAvatarDocumentEditor* self, float value) {
56 return bind.checked(self, "avatar editor must not be null",
57 [&] { return self->editor().setParameterValue(static_cast<double>(value)); });
58 });
59 avatarEditor.addFunc("createLayer",
60 [bind](ScriptAvatarDocumentEditor* self, const std::string& id, const std::string& name) {
61 return bind.checked(self, "avatar editor must not be null",
62 [&] { return self->editor().createLayer(id, name); });
63 });
64 avatarEditor.addFunc("deleteSelectedLayer", [bind](ScriptAvatarDocumentEditor* self) {
65 return bind.checked(self, "avatar editor must not be null",
66 [&] { return self->editor().deleteSelectedLayer(); });
67 });
68 avatarEditor.addFunc("createParameter",
69 [bind](ScriptAvatarDocumentEditor* self, const std::string& id, const std::string& name) {
70 return bind.checked(self, "avatar editor must not be null",
71 [&] { return self->editor().createParameter(id, name); });
72 });
73 avatarEditor.addFunc("deleteSelectedParameter", [bind](ScriptAvatarDocumentEditor* self) {
74 return bind.checked(self, "avatar editor must not be null",
75 [&] { return self->editor().deleteSelectedParameter(); });
76 });
77 avatarEditor.addFunc("createExpression",
78 [bind](ScriptAvatarDocumentEditor* self, const std::string& id, const std::string& name) {
79 return bind.checked(self, "avatar editor must not be null",
80 [&] { return self->editor().createExpression(id, name); });
81 });
82 avatarEditor.addFunc("deleteSelectedExpression", [bind](ScriptAvatarDocumentEditor* self) {
83 return bind.checked(self, "avatar editor must not be null",
84 [&] { return self->editor().deleteSelectedExpression(); });
85 });
86 editor::registerEditorHistory<ScriptAvatarDocumentEditor>(avatarEditor, bind, "avatar editor must not be null");
87 avatarEditor.addFunc("getPreviewRevision", [](ScriptAvatarDocumentEditor* self) {
88 return self ? static_cast<int>(self->editor().previewRevision()) : 0;
89 });
90 avatarEditor.addFunc("getKind", [](ScriptAvatarDocumentEditor* self) {
91 return self ? self->editor().kind() : std::string{};
92 });
93 avatarEditor.addFunc("getSelectedId", [](ScriptAvatarDocumentEditor* self) {
94 return self ? self->editor().selectedId() : std::string{};
95 });
96 avatarEditor.addFunc("getSelectedType", [](ScriptAvatarDocumentEditor* self) {
97 return self ? self->editor().selectedType() : std::string{};
98 });
99 avatarEditor.addFunc("getLayerCount", [](ScriptAvatarDocumentEditor* self) {
100 return self ? self->editor().layerCount() : 0;
101 });
102 avatarEditor.addFunc("getLayerId", [](ScriptAvatarDocumentEditor* self, int index) {
103 return self ? self->editor().layerId(index) : std::string{};
104 });
105 avatarEditor.addFunc("getLayerName", [](ScriptAvatarDocumentEditor* self, int index) {
106 return self ? self->editor().layerName(index) : std::string{};
107 });
108 avatarEditor.addFunc("getLayerVisible", [](ScriptAvatarDocumentEditor* self, int index) {
109 return self && self->editor().layerVisible(index);
110 });
111 avatarEditor.addFunc("getLayerZ", [](ScriptAvatarDocumentEditor* self, int index) {
112 return self ? self->editor().layerZ(index) : 0;
113 });
114 avatarEditor.addFunc("getLayerSelected", [](ScriptAvatarDocumentEditor* self, int index) {
115 return self && self->editor().isLayerSelected(index);
116 });
117 avatarEditor.addFunc("getPreviewLayerCount", [](ScriptAvatarDocumentEditor* self) {
118 return self ? self->editor().previewLayerCount() : 0;
119 });
120 avatarEditor.addFunc("getPreviewX", [](ScriptAvatarDocumentEditor* self, int index) {
121 return self ? self->editor().previewX(index) : 0.0f;
122 });
123 avatarEditor.addFunc("getPreviewY", [](ScriptAvatarDocumentEditor* self, int index) {
124 return self ? self->editor().previewY(index) : 0.0f;
125 });
126 avatarEditor.addFunc("getPreviewW", [](ScriptAvatarDocumentEditor* self, int index) {
127 return self ? self->editor().previewW(index) : 0.0f;
128 });
129 avatarEditor.addFunc("getPreviewH", [](ScriptAvatarDocumentEditor* self, int index) {
130 return self ? self->editor().previewH(index) : 0.0f;
131 });
132 avatarEditor.addFunc("getPreviewR", [](ScriptAvatarDocumentEditor* self, int index) {
133 return self ? self->editor().previewR(index) : 0.0f;
134 });
135 avatarEditor.addFunc("getPreviewG", [](ScriptAvatarDocumentEditor* self, int index) {
136 return self ? self->editor().previewG(index) : 0.0f;
137 });
138 avatarEditor.addFunc("getPreviewB", [](ScriptAvatarDocumentEditor* self, int index) {
139 return self ? self->editor().previewB(index) : 0.0f;
140 });
141 avatarEditor.addFunc("getPreviewA", [](ScriptAvatarDocumentEditor* self, int index) {
142 return self ? self->editor().previewA(index) : 0.0f;
143 });
144 avatarEditor.addFunc("getPreviewSelected", [](ScriptAvatarDocumentEditor* self, int index) {
145 return self && self->editor().isPreviewSelected(index);
146 });
147 avatarEditor.addFunc("getPreviewName", [](ScriptAvatarDocumentEditor* self, int index) {
148 return self ? self->editor().previewName(index) : std::string{};
149 });
150 avatarEditor.addFunc("getParameterCount", [](ScriptAvatarDocumentEditor* self) {
151 return self ? self->editor().parameterCount() : 0;
152 });
153 avatarEditor.addFunc("getParameterId", [](ScriptAvatarDocumentEditor* self, int index) {
154 return self ? self->editor().parameterId(index) : std::string{};
155 });
156 avatarEditor.addFunc("getParameterName", [](ScriptAvatarDocumentEditor* self, int index) {
157 return self ? self->editor().parameterName(index) : std::string{};
158 });
159 avatarEditor.addFunc("getParameterValue", [](ScriptAvatarDocumentEditor* self, int index) {
160 return self ? self->editor().parameterValue(index) : 0.0f;
161 });
162 avatarEditor.addFunc("getParameterMinimum", [](ScriptAvatarDocumentEditor* self, int index) {
163 return self ? self->editor().parameterMinimum(index) : 0.0f;
164 });
165 avatarEditor.addFunc("getParameterMaximum", [](ScriptAvatarDocumentEditor* self, int index) {
166 return self ? self->editor().parameterMaximum(index) : 1.0f;
167 });
168 avatarEditor.addFunc("getParameterSelected", [](ScriptAvatarDocumentEditor* self, int index) {
169 return self && self->editor().isParameterSelected(index);
170 });
171 avatarEditor.addFunc("getExpressionCount", [](ScriptAvatarDocumentEditor* self) {
172 return self ? self->editor().expressionCount() : 0;
173 });
174 avatarEditor.addFunc("getExpressionId", [](ScriptAvatarDocumentEditor* self, int index) {
175 return self ? self->editor().expressionId(index) : std::string{};
176 });
177 avatarEditor.addFunc("getExpressionName", [](ScriptAvatarDocumentEditor* self, int index) {
178 return self ? self->editor().expressionName(index) : std::string{};
179 });
180 avatarEditor.addFunc("getExpressionSelected", [](ScriptAvatarDocumentEditor* self, int index) {
181 return self && self->editor().isExpressionSelected(index);
182 });
183 avatarEditor.addFunc("getExpressionChannelCount", [](ScriptAvatarDocumentEditor* self, int index) {
184 return self ? self->editor().expressionChannelCount(index) : 0;
185 });
186 avatarEditor.addFunc("getExpressionChannelName",
187 [](ScriptAvatarDocumentEditor* self, int expression, int channel) {
188 return self ? self->editor().expressionChannelName(expression, channel) : std::string{};
189 });
190
191 editor::registerEditorOwnedCreate<ScriptAvatarDocumentEditor, AvatarEditorModule>(moduleClass, bind, "avatar target id must not be empty");
192}
193
194} // namespace eve::avatar_editor
double value
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
Squirrel adapter for the avatar document editor.
UI-neutral avatar editor: workspace, layer composite preview, undo.
std::string name
std::uint32_t targetId
bool visible
uint32_t index
Editor facade binder: common script::BindContext plus history/owned-create helpers.
void exposeAvatarDocumentEditorScriptBindings(ssq::Table &table, ssq::Class &moduleClass)
Expose the script-owned AvatarDocumentEditor factory on AvatarEditorModule.