载入中...
搜索中...
未找到
Editor.cpp
浏览该文件的文档.
1#include "editor/Editor.h"
2
3#include "common/Capability.h"
9#include "editor/EditorDock.h"
10#include "editor/EditorHost.h"
18#include "editor/GizmoManager.h"
22
23
24#include <simplesquirrel/simplesquirrel.hpp>
25
26#include <algorithm>
27#include <cmath>
28#include <cstdint>
29#include <memory>
30#include <stdexcept>
31#include <type_traits>
32#include <utility>
33#include <vector>
34
35namespace eve::editor {
36
38
39namespace {
40
41const char* statusName(EditorStatus status) {
42 switch (status) {
43 case EditorStatus::Ok: return "ok";
44 case EditorStatus::Applied: return "applied";
45 case EditorStatus::Pending: return "pending";
46 case EditorStatus::NoOp: return "no-op";
47 case EditorStatus::Rejected: return "rejected";
48 case EditorStatus::Conflict: return "conflict";
49 case EditorStatus::NotFound: return "not-found";
50 case EditorStatus::Unsupported: return "unsupported";
51 case EditorStatus::Cancelled: return "cancelled";
52 case EditorStatus::Failed: return "failed";
53 }
54 return "failed";
55}
56
57const char* transactionStateName(TransactionState state) {
58 switch (state) {
59 case TransactionState::Planning: return "planning";
60 case TransactionState::Previewing: return "previewing";
61 case TransactionState::PendingAuthority: return "pending-authority";
62 case TransactionState::Committed: return "committed";
63 case TransactionState::RolledBack: return "rolled-back";
64 case TransactionState::Rejected: return "rejected";
65 case TransactionState::Conflicted: return "conflicted";
66 case TransactionState::Failed: return "failed";
67 }
68 return "failed";
69}
70
71bool squirrelToEditorValue(HSQUIRRELVM vm, SQInteger index, EditorValue& out, size_t depth = 0) {
72 if (!vm || depth > 32) return false;
73 const SQInteger absolute = index > 0 ? index : sq_gettop(vm) + index + 1;
74 switch (sq_gettype(vm, absolute)) {
75 case OT_NULL: out = EditorValue{}; return true;
76 case OT_BOOL: {
77 SQBool value = SQFalse;
78 if (SQ_FAILED(sq_getbool(vm, absolute, &value))) return false;
79 out = EditorValue(value != SQFalse);
80 return true;
81 }
82 case OT_INTEGER: {
83 SQInteger value = 0;
84 if (SQ_FAILED(sq_getinteger(vm, absolute, &value))) return false;
85 out = EditorValue(static_cast<int64_t>(value));
86 return true;
87 }
88 case OT_FLOAT: {
89 SQFloat value = 0;
90 if (SQ_FAILED(sq_getfloat(vm, absolute, &value))) return false;
91 out = EditorValue(static_cast<double>(value));
92 return true;
93 }
94 case OT_STRING: {
95 const SQChar* value = nullptr;
96 if (SQ_FAILED(sq_getstring(vm, absolute, &value))) return false;
97 out = EditorValue(value ? value : "");
98 return true;
99 }
100 case OT_ARRAY: {
102 const SQInteger count = sq_getsize(vm, absolute);
103 values.reserve(static_cast<size_t>(count));
104 for (SQInteger i = 0; i < count; ++i) {
105 sq_pushinteger(vm, i);
106 if (SQ_FAILED(sq_get(vm, absolute))) return false;
108 const bool ok = squirrelToEditorValue(vm, -1, value, depth + 1);
109 sq_pop(vm, 1);
110 if (!ok) return false;
111 values.push_back(std::move(value));
112 }
113 out = EditorValue(std::move(values));
114 return true;
115 }
116 case OT_TABLE: {
118 sq_pushnull(vm);
119 while (SQ_SUCCEEDED(sq_next(vm, absolute))) {
120 const SQChar* key = nullptr;
121 const bool keyOk = sq_gettype(vm, -2) == OT_STRING && SQ_SUCCEEDED(sq_getstring(vm, -2, &key)) && key;
122 const std::string stableKey = keyOk ? key : "";
124 const bool valueOk = keyOk && squirrelToEditorValue(vm, -1, value, depth + 1);
125 sq_pop(vm, 2);
126 if (!valueOk) {
127 sq_pop(vm, 1);
128 return false;
129 }
130 values[stableKey] = std::move(value);
131 }
132 sq_pop(vm, 1);
133 out = EditorValue(std::move(values));
134 return true;
135 }
136 default: return false;
137 }
138}
139
140bool objectToEditorValue(const ssq::Object& object, EditorValue& out) {
141 HSQUIRRELVM vm = object.getHandle();
142 if (!vm) return false;
143 const SQInteger top = sq_gettop(vm);
144 sq_pushobject(vm, object.getRaw());
145 const bool ok = squirrelToEditorValue(vm, -1, out);
146 sq_settop(vm, top);
147 return ok;
148}
149
150void pushEditorValue(HSQUIRRELVM vm, const EditorValue& value) {
151 std::visit(
152 [&](const auto& current) {
153 using T = std::decay_t<decltype(current)>;
154 if constexpr (std::is_same_v<T, std::monostate>) {
155 sq_pushnull(vm);
156 } else if constexpr (std::is_same_v<T, bool>) {
157 sq_pushbool(vm, current ? SQTrue : SQFalse);
158 } else if constexpr (std::is_same_v<T, int64_t>) {
159 sq_pushinteger(vm, static_cast<SQInteger>(current));
160 } else if constexpr (std::is_same_v<T, double>) {
161 sq_pushfloat(vm, static_cast<SQFloat>(current));
162 } else if constexpr (std::is_same_v<T, std::string>) {
163 sq_pushstring(vm, current.c_str(), static_cast<SQInteger>(current.size()));
164 } else if constexpr (std::is_same_v<T, EditorValue::Array>) {
165 sq_newarray(vm, 0);
166 for (const EditorValue& entry : current) {
167 pushEditorValue(vm, entry);
168 sq_arrayappend(vm, -2);
169 }
170 } else if constexpr (std::is_same_v<T, EditorValue::Object>) {
171 sq_newtable(vm);
172 for (const auto& [key, entry] : current) {
173 sq_pushstring(vm, key.c_str(), static_cast<SQInteger>(key.size()));
174 pushEditorValue(vm, entry);
175 sq_newslot(vm, -3, SQFalse);
176 }
177 }
178 },
179 value.storage());
180}
181
182void setValue(ssq::Table& table, const char* name, const EditorValue& value) {
183 HSQUIRRELVM vm = table.getHandle();
184 sq_pushobject(vm, table.getRaw());
185 sq_pushstring(vm, name, -1);
186 pushEditorValue(vm, value);
187 sq_newslot(vm, -3, SQFalse);
188 sq_pop(vm, 1);
189}
190
191ssq::Array diagnosticArray(HSQUIRRELVM vm, const std::vector<EditorDiagnostic>& diagnostics) {
192 ssq::Array out(vm);
193 for (const EditorDiagnostic& diagnostic : diagnostics) {
194 ssq::Table item(vm);
195 item.set("rule", editing::diagnosticRule(diagnostic).value());
196 item.set("message", diagnostic.message());
197 item.set("severity", static_cast<int>(diagnostic.severity()));
198 out.push(item);
199 }
200 return out;
201}
202
203template <class T>
204ssq::Table resultTable(HSQUIRRELVM vm, const Result<T>& result) {
205 ssq::Table out(vm);
206 out.set("status", std::string(statusName(result.code())));
207 out.set("accepted", result.ok());
208 out.set("diagnostics", diagnosticArray(vm, result.diagnostics()));
209 return out;
210}
211
212Result<EditorValue> invalidScriptPayload() {
213 return eve::editing::failed<EditorValue>(
214 EditorStatus::Rejected, RuleId("editor.script.invalid-payload"),
215 "Script payload must contain only null, bool, number, string, array, or table values");
216}
217
218bool invokeScriptCommand(const ssq::Object& callback, const EditorValue& payload) {
219 const SQObjectType type = callback.getRaw()._type;
220 if (type != OT_CLOSURE && type != OT_NATIVECLOSURE) return false;
221 HSQUIRRELVM vm = callback.getHandle();
222 SQInteger top = sq_gettop(vm);
223 sq_pushobject(vm, callback.getRaw());
224 sq_pushroottable(vm);
225 pushEditorValue(vm, payload);
226 // `pushEditorValue` pushes an EditorValue, which is not one of the types the shared
227 // helper's typed-argument form accepts, so the parameter count is derived from the
228 // pushes instead -- the same rule (R-FACE-7). A script command that threw used to be
229 // reported to the author as "callback rejected the planned payload", which reads as a
230 // deliberate `return false`.
231 const SQInteger params = sq_gettop(vm) - top - 1; // receiver + arguments
232 bool accepted = false;
233 if (SQ_SUCCEEDED(sq_call(vm, params, SQTrue, SQTrue))) {
234 SQBool result = SQFalse;
235 accepted = SQ_SUCCEEDED(sq_getbool(vm, -1, &result)) && result != SQFalse;
236 } else {
237 script::reportScriptCallFailure(vm, "editor.script-command");
238 }
239 sq_settop(vm, top);
240 return accepted;
241}
242
243bool registerScriptCommandImpl(Editor* editor, const std::string& id, const std::string& displayName,
244 const std::string& category, ssq::Object callback, bool automationAllowed,
245 const std::string& panelCapability, const std::string& panelContext) {
246 if (!editor || id.empty()) return false;
247 const SQObjectType callbackType = callback.getRaw()._type;
248 if (callbackType != OT_CLOSURE && callbackType != OT_NATIVECLOSURE) return false;
249 if (automationAllowed && (panelCapability.empty() || panelContext.empty())) return false;
250
251 CommandDescriptor descriptor;
252 descriptor.id = CommandId(id);
253 descriptor.ownerModule = "script:" + id;
254 descriptor.displayName = displayName;
255 descriptor.category = category;
256 descriptor.automationAllowed = automationAllowed;
257 descriptor.payloadSchema = editing::emptyObjectPropertySchema("script." + id);
258 descriptor.panelCapability = panelCapability;
259 descriptor.panelContext = panelContext;
260 return editor->commandService()
261 .registerPlannedCommand(
263 [id](const CommandRequest& request) {
264 CommandPlan plan;
265 plan.summary = EditorValue::Object{{"command", EditorValue(id)}, {"payload", request.payload}};
267 operation.type = id;
268 operation.payload = request.payload;
269 plan.operations.push_back(std::move(operation));
270 return eve::editing::applied<CommandPlan>(std::move(plan));
271 },
272 [callback = std::move(callback)](const CommandRequest& request, const CommandPlan& plan) {
273 if (!invokeScriptCommand(callback, request.payload))
274 return eve::editing::failed<TransactionReceipt>(
275 EditorStatus::Rejected, RuleId("editor.script.command-rejected"),
276 "Script command callback rejected the planned payload");
277 TransactionReceipt receipt;
278 receipt.id = TransactionId(plan.id.value());
279 receipt.state = TransactionState::Committed;
280 receipt.beforeRevision = plan.baseRevision;
281 receipt.afterRevision = plan.baseRevision + 1;
282 receipt.authorityReceipt = "script:local";
283 return eve::editing::applied<TransactionReceipt>(std::move(receipt));
284 },
285 true)
286 .ok();
287}
288
289bool registerScriptCommand(Editor* editor, const std::string& id, const std::string& displayName,
290 const std::string& category, ssq::Object callback) {
291 return registerScriptCommandImpl(editor, id, displayName, category, std::move(callback), false, {}, {});
292}
293
294bool registerAutomatedScriptCommand(Editor* editor, const std::string& id, const std::string& displayName,
295 const std::string& category, const std::string& panelCapability,
296 const std::string& panelContext, ssq::Object callback) {
297 return registerScriptCommandImpl(editor, id, displayName, category, std::move(callback), true, panelCapability,
298 panelContext);
299}
300
301} // namespace
302
303namespace {
304
305bool attachEditorHostOpaque(void* host) {
306 auto* editorHost = static_cast<EditorHost*>(host);
307 if (!editorHost) return false;
308 return editorHost->exportMcp(EditorMcpExportMode::Commands).ok();
309}
310
311void detachEditorHostOpaque() { editorMcpProjector().detach(); }
312
313} // namespace
314
316 : targets_(std::make_unique<EditorTargetCoordinator>(commandService_)),
317 automation_(std::make_unique<EditorAutomationProvider>(commandService_, *targets_)) {
318 eve::cap::provide<eve::editing::IEditingCommandRegistry>(targets_.get());
319 eve::cap::provide<eve::IEditorAutomation>(automation_.get());
320 eve::setEditorMcpAttachHooks(&attachEditorHostOpaque, &detachEditorHostOpaque);
321}
322
324 eve::setEditorMcpAttachHooks(nullptr, nullptr);
325 eve::cap::revoke<eve::IEditorAutomation>(automation_.get());
326 eve::cap::revoke<eve::editing::IEditingCommandRegistry>(targets_.get());
327}
328
330
332 auto result = targets_->unregisterTarget(target);
333 if (result.code() == EditorStatus::Applied) automation_->targetUnregistered(target);
334 return result;
335}
336
340
341std::unique_ptr<TransformGizmo> Editor::newGizmo() { return std::make_unique<TransformGizmo>(); }
342
343std::unique_ptr<GizmoManager> Editor::newGizmoManager() { return std::make_unique<GizmoManager>(); }
344
345std::unique_ptr<EditorToolbar> Editor::newToolbar() { return std::make_unique<EditorToolbar>(); }
346
347std::unique_ptr<EditorInspector> Editor::newInspector() { return std::make_unique<EditorInspector>(); }
348
349std::unique_ptr<EditorDock> Editor::newDock() { return std::make_unique<EditorDock>(); }
350
351std::unique_ptr<EditorSession> Editor::newSession() {
352 auto session = std::make_unique<EditorSession>();
353 session->setCommandService(&commandService_);
354 return session;
355}
356
357Result<std::unique_ptr<EditorWorkspace>> Editor::newWorkspace(const std::string& id, const std::string& title) {
358 if (id.empty())
359 return eve::editing::failed<std::unique_ptr<EditorWorkspace>>(
360 EditorStatus::Rejected, RuleId("editor.workspace.empty-id"), "Workspace id must be non-empty");
361 return eve::editing::applied<std::unique_ptr<EditorWorkspace>>(
362 std::make_unique<EditorWorkspace>(id, title.empty() ? id : title));
363}
364
365Result<std::unique_ptr<EditorHost>> Editor::newHost(const std::string& id, const std::string& title) {
366 if (id.empty())
367 return eve::editing::failed<std::unique_ptr<EditorHost>>(EditorStatus::Rejected, RuleId("editor.host.empty-id"),
368 "EditorHost id must be non-empty");
370 options.id = id;
371 options.title = title.empty() ? id : title;
372 return eve::editing::applied<std::unique_ptr<EditorHost>>(std::make_unique<EditorHost>(*this, std::move(options)));
373}
374
375std::unique_ptr<ScriptEditorTool> Editor::newScriptTool(const std::string& id, const std::string& label) {
376 return std::make_unique<ScriptEditorTool>(id, label);
377}
378
379std::unique_ptr<ConstantBrushFalloff> Editor::newConstantBrushFalloff() {
380 return std::make_unique<ConstantBrushFalloff>();
381}
382std::unique_ptr<LinearBrushFalloff> Editor::newLinearBrushFalloff() { return std::make_unique<LinearBrushFalloff>(); }
383std::unique_ptr<SmoothBrushFalloff> Editor::newSmoothBrushFalloff() { return std::make_unique<SmoothBrushFalloff>(); }
384std::unique_ptr<CircleBrushKernel> Editor::newCircleBrushKernel() { return std::make_unique<CircleBrushKernel>(); }
385std::unique_ptr<BoxBrushKernel> Editor::newBoxBrushKernel() { return std::make_unique<BoxBrushKernel>(); }
386std::unique_ptr<PaintIntFieldOperation> Editor::newPaintIntFieldOperation(int value) {
387 return std::make_unique<PaintIntFieldOperation>(value);
388}
389std::unique_ptr<AddScalarFieldOperation> Editor::newAddScalarFieldOperation() {
390 return std::make_unique<AddScalarFieldOperation>();
391}
392std::unique_ptr<FieldBrushTool> Editor::newFieldBrushTool(const std::string& id, const std::string& label) {
393 return std::make_unique<FieldBrushTool>(id, label, nullptr, nullptr);
394}
395
396std::unique_ptr<SphereVolumeBrushKernel> Editor::newSphereVolumeBrushKernel() {
397 return std::make_unique<SphereVolumeBrushKernel>();
398}
399std::unique_ptr<BoxVolumeBrushKernel> Editor::newBoxVolumeBrushKernel() {
400 return std::make_unique<BoxVolumeBrushKernel>();
401}
402std::unique_ptr<PaintIntVolumeOperation> Editor::newPaintIntVolumeOperation(int value) {
403 return std::make_unique<PaintIntVolumeOperation>(value);
404}
405std::unique_ptr<VolumeBrushTool> Editor::newVolumeBrushTool(const std::string& id, const std::string& label) {
406 return std::make_unique<VolumeBrushTool>(id, label);
407}
408
409void Editor::expose(ssq::Table& table) {
410 auto cls = table.addClass(name, Editor::create, false);
411 expose(cls);
412
413 auto gizmo = table.addClass<TransformGizmo>(
414 "TransformGizmo", std::function<TransformGizmo*()>([]() -> TransformGizmo* { return nullptr; }), true);
415 gizmo.addFunc("setMode", &TransformGizmo::setMode);
416 gizmo.addFunc("getMode", &TransformGizmo::getMode);
417 gizmo.addFunc("setSpace", &TransformGizmo::setSpace);
418 gizmo.addFunc("getSpace", &TransformGizmo::getSpace);
419 gizmo.addFunc("setSize", &TransformGizmo::setSize);
420 gizmo.addFunc("getSize", &TransformGizmo::getSize);
421 gizmo.addFunc("setPosition", &TransformGizmo::setPosition);
422 gizmo.addFunc("getPositionX", &TransformGizmo::getPositionX);
423 gizmo.addFunc("getPositionY", &TransformGizmo::getPositionY);
424 gizmo.addFunc("getPositionZ", &TransformGizmo::getPositionZ);
425 gizmo.addFunc("setRotationEuler", &TransformGizmo::setRotationEuler);
426 gizmo.addFunc("getRotationX", &TransformGizmo::getRotationX);
427 gizmo.addFunc("getRotationY", &TransformGizmo::getRotationY);
428 gizmo.addFunc("getRotationZ", &TransformGizmo::getRotationZ);
429 gizmo.addFunc("setScale", &TransformGizmo::setScale);
430 gizmo.addFunc("getScaleX", &TransformGizmo::getScaleX);
431 gizmo.addFunc("getScaleY", &TransformGizmo::getScaleY);
432 gizmo.addFunc("getScaleZ", &TransformGizmo::getScaleZ);
433 gizmo.addFunc("setBounds", &TransformGizmo::setBounds);
434 gizmo.addFunc("getBoundsMinX", &TransformGizmo::getBoundsMinX);
435 gizmo.addFunc("getBoundsMinY", &TransformGizmo::getBoundsMinY);
436 gizmo.addFunc("getBoundsMinZ", &TransformGizmo::getBoundsMinZ);
437 gizmo.addFunc("getBoundsMaxX", &TransformGizmo::getBoundsMaxX);
438 gizmo.addFunc("getBoundsMaxY", &TransformGizmo::getBoundsMaxY);
439 gizmo.addFunc("getBoundsMaxZ", &TransformGizmo::getBoundsMaxZ);
440 gizmo.addFunc("setSnapTranslate", &TransformGizmo::setSnapTranslate);
441 gizmo.addFunc("setSnapRotate", &TransformGizmo::setSnapRotate);
442 gizmo.addFunc("setSnapScale", &TransformGizmo::setSnapScale);
443 gizmo.addFunc("getSnapTranslateX", &TransformGizmo::getSnapTranslateX);
444 gizmo.addFunc("getSnapTranslateY", &TransformGizmo::getSnapTranslateY);
445 gizmo.addFunc("getSnapTranslateZ", &TransformGizmo::getSnapTranslateZ);
446 gizmo.addFunc("getSnapRotate", &TransformGizmo::getSnapRotate);
447 gizmo.addFunc("getSnapScale", &TransformGizmo::getSnapScale);
448 gizmo.addFunc("getMatrix", &TransformGizmo::getMatrix);
449 gizmo.addFunc("pick", &TransformGizmo::pick);
450 gizmo.addFunc("beginDrag", &TransformGizmo::beginDrag);
451 gizmo.addFunc("updateDrag", &TransformGizmo::updateDrag);
452 gizmo.addFunc("endDrag", &TransformGizmo::endDrag);
453 gizmo.addFunc("isDragging", &TransformGizmo::isDragging);
454 gizmo.addFunc("isHovered", &TransformGizmo::isHovered);
455 gizmo.addFunc("getActiveAxis", &TransformGizmo::getActiveAxis);
456 gizmo.addFunc("getHoverAxis", &TransformGizmo::getHoverAxis);
457 gizmo.addFunc("rebuildParts", &TransformGizmo::rebuildParts);
458 gizmo.addFunc("getPartCount", &TransformGizmo::getPartCount);
459 gizmo.addFunc("getPartKind", &TransformGizmo::getPartKind);
460 gizmo.addFunc("getPartAxis", &TransformGizmo::getPartAxis);
461 gizmo.addFunc("getPartColorR", &TransformGizmo::getPartColorR);
462 gizmo.addFunc("getPartColorG", &TransformGizmo::getPartColorG);
463 gizmo.addFunc("getPartColorB", &TransformGizmo::getPartColorB);
464 gizmo.addFunc("getPartColorA", &TransformGizmo::getPartColorA);
465 gizmo.addFunc("getPartOriginX", &TransformGizmo::getPartOriginX);
466 gizmo.addFunc("getPartOriginY", &TransformGizmo::getPartOriginY);
467 gizmo.addFunc("getPartOriginZ", &TransformGizmo::getPartOriginZ);
468 gizmo.addFunc("getPartDirX", &TransformGizmo::getPartDirX);
469 gizmo.addFunc("getPartDirY", &TransformGizmo::getPartDirY);
470 gizmo.addFunc("getPartDirZ", &TransformGizmo::getPartDirZ);
471 gizmo.addFunc("getPartLength", &TransformGizmo::getPartLength);
472 gizmo.addFunc("getPartRadius", &TransformGizmo::getPartRadius);
473
474 auto mgr = table.addClass<GizmoManager>(
475 "GizmoManager", std::function<GizmoManager*()>([]() -> GizmoManager* { return nullptr; }), true);
476 mgr.addFunc("getGizmo", &GizmoManager::getGizmo);
477 mgr.addFunc("setPositionEnabled", &GizmoManager::setPositionEnabled);
478 mgr.addFunc("setRotationEnabled", &GizmoManager::setRotationEnabled);
479 mgr.addFunc("setScaleEnabled", &GizmoManager::setScaleEnabled);
480 mgr.addFunc("setBoundEnabled", &GizmoManager::setBoundEnabled);
481 mgr.addFunc("getPositionEnabled", &GizmoManager::getPositionEnabled);
482 mgr.addFunc("getRotationEnabled", &GizmoManager::getRotationEnabled);
483 mgr.addFunc("getScaleEnabled", &GizmoManager::getScaleEnabled);
484 mgr.addFunc("getBoundEnabled", &GizmoManager::getBoundEnabled);
485 mgr.addFunc("attach", &GizmoManager::attach);
486 mgr.addFunc("detach", &GizmoManager::detach);
487 mgr.addFunc("isAttached", &GizmoManager::isAttached);
488 mgr.addFunc("pick", &GizmoManager::pick);
489 mgr.addFunc("beginDrag", &GizmoManager::beginDrag);
490 mgr.addFunc("updateDrag", &GizmoManager::updateDrag);
491 mgr.addFunc("endDrag", &GizmoManager::endDrag);
492 mgr.addFunc("isDragging", &GizmoManager::isDragging);
493 mgr.addFunc("isHovered", &GizmoManager::isHovered);
494
495 auto tb = table.addClass<EditorToolbar>(
496 "EditorToolbar", std::function<EditorToolbar*()>([]() -> EditorToolbar* { return nullptr; }), true);
497 tb.addFunc("clear", &EditorToolbar::clear);
498 tb.addFunc("addTool", &EditorToolbar::addTool);
499 tb.addFunc("setIcon", &EditorToolbar::setIcon);
500 tb.addFunc("setShortcut", &EditorToolbar::setShortcut);
501 tb.addFunc("setActive", &EditorToolbar::setActive);
502 tb.addFunc("getActive", &EditorToolbar::getActive);
503 tb.addFunc("matchShortcut", &EditorToolbar::matchShortcut);
504 tb.addFunc("getToolCount", &EditorToolbar::getToolCount);
505 tb.addFunc("getToolId", &EditorToolbar::getToolId);
506 tb.addFunc("getToolLabel", &EditorToolbar::getToolLabel);
507 tb.addFunc("getToolIcon", &EditorToolbar::getToolIcon);
508 tb.addFunc("getToolShortcut", &EditorToolbar::getToolShortcut);
509
510 auto insp = table.addClass<EditorInspector>(
511 "EditorInspector", std::function<EditorInspector*()>([]() -> EditorInspector* { return nullptr; }), true);
512 insp.addFunc("clear", &EditorInspector::clear);
513 insp.addFunc("addFloat", &EditorInspector::addFloat);
514 insp.addFunc("addFloat3", &EditorInspector::addFloat3);
515 insp.addFunc("addBool", &EditorInspector::addBool);
516 insp.addFunc("addString", &EditorInspector::addString);
517 insp.addFunc("addChoice", &EditorInspector::addChoice);
518 insp.addFunc("getFieldCount", &EditorInspector::getFieldCount);
519 insp.addFunc("getFieldKind", &EditorInspector::getFieldKind);
520 insp.addFunc("getFieldId", &EditorInspector::getFieldId);
521 insp.addFunc("getFieldLabel", &EditorInspector::getFieldLabel);
522 insp.addFunc("getFloat", &EditorInspector::getFloat);
523 insp.addFunc("setFloat", &EditorInspector::setFloat);
524 insp.addFunc("getFloatMin", &EditorInspector::getFloatMin);
525 insp.addFunc("getFloatMax", &EditorInspector::getFloatMax);
526 insp.addFunc("getFloatStep", &EditorInspector::getFloatStep);
527 insp.addFunc("getFloat3X", &EditorInspector::getFloat3X);
528 insp.addFunc("getFloat3Y", &EditorInspector::getFloat3Y);
529 insp.addFunc("getFloat3Z", &EditorInspector::getFloat3Z);
530 insp.addFunc("setFloat3", &EditorInspector::setFloat3);
531 insp.addFunc("getBool", &EditorInspector::getBool);
532 insp.addFunc("setBool", &EditorInspector::setBool);
533 insp.addFunc("getString", &EditorInspector::getString);
534 insp.addFunc("setString", &EditorInspector::setString);
535 insp.addFunc("getChoice", &EditorInspector::getChoice);
536 insp.addFunc("setChoice", &EditorInspector::setChoice);
537 insp.addFunc("getChoicesCsv", &EditorInspector::getChoicesCsv);
538 insp.addFunc("isDirty", &EditorInspector::isDirty);
539 insp.addFunc("clearDirty", &EditorInspector::clearDirty);
540 insp.addFunc("clearAllDirty", &EditorInspector::clearAllDirty);
541 insp.addFunc("pollChangedId", &EditorInspector::pollChangedId);
542
543 auto dock = table.addClass<EditorDock>("EditorDock",
544 std::function<EditorDock*()>([]() -> EditorDock* { return nullptr; }), true);
545 dock.addFunc("setRegionSize", &EditorDock::setRegionSize);
546 dock.addFunc("getRegionSize", &EditorDock::getRegionSize);
547 dock.addFunc("layout", &EditorDock::layout);
548 dock.addFunc("getRegionX", &EditorDock::getRegionX);
549 dock.addFunc("getRegionY", &EditorDock::getRegionY);
550 dock.addFunc("getRegionW", &EditorDock::getRegionW);
551 dock.addFunc("getRegionH", &EditorDock::getRegionH);
552
553 auto constantFalloff = table.addClass<ConstantBrushFalloff>(
554 "ConstantBrushFalloff",
555 std::function<ConstantBrushFalloff*()>([]() -> ConstantBrushFalloff* { return nullptr; }), true);
556 auto linearFalloff = table.addClass<LinearBrushFalloff>(
557 "LinearBrushFalloff", std::function<LinearBrushFalloff*()>([]() -> LinearBrushFalloff* { return nullptr; }),
558 true);
559 auto smoothFalloff = table.addClass<SmoothBrushFalloff>(
560 "SmoothBrushFalloff", std::function<SmoothBrushFalloff*()>([]() -> SmoothBrushFalloff* { return nullptr; }),
561 true);
562 (void)constantFalloff;
563 (void)linearFalloff;
564 (void)smoothFalloff;
565
566 auto circleKernel = table.addClass<CircleBrushKernel>(
567 "CircleBrushKernel", std::function<CircleBrushKernel*()>([]() -> CircleBrushKernel* { return nullptr; }), true);
568 circleKernel.addFunc("setConstantFalloff", [](CircleBrushKernel* self, ConstantBrushFalloff* falloff) {
569 if (self) self->setFalloff(falloff);
570 });
571 circleKernel.addFunc("setLinearFalloff", [](CircleBrushKernel* self, LinearBrushFalloff* falloff) {
572 if (self) self->setFalloff(falloff);
573 });
574 circleKernel.addFunc("setSmoothFalloff", [](CircleBrushKernel* self, SmoothBrushFalloff* falloff) {
575 if (self) self->setFalloff(falloff);
576 });
577
578 auto boxKernel = table.addClass<BoxBrushKernel>(
579 "BoxBrushKernel", std::function<BoxBrushKernel*()>([]() -> BoxBrushKernel* { return nullptr; }), true);
580 boxKernel.addFunc("setConstantFalloff", [](BoxBrushKernel* self, ConstantBrushFalloff* falloff) {
581 if (self) self->setFalloff(falloff);
582 });
583 boxKernel.addFunc("setLinearFalloff", [](BoxBrushKernel* self, LinearBrushFalloff* falloff) {
584 if (self) self->setFalloff(falloff);
585 });
586 boxKernel.addFunc("setSmoothFalloff", [](BoxBrushKernel* self, SmoothBrushFalloff* falloff) {
587 if (self) self->setFalloff(falloff);
588 });
589
590 auto paintOperation = table.addClass<PaintIntFieldOperation>(
591 "PaintIntFieldOperation",
592 std::function<PaintIntFieldOperation*()>([]() -> PaintIntFieldOperation* { return nullptr; }), true);
593 paintOperation.addFunc("setValue", &PaintIntFieldOperation::setValue);
594 paintOperation.addFunc("getValue", &PaintIntFieldOperation::value);
595 auto addScalarOperation = table.addClass<AddScalarFieldOperation>(
596 "AddScalarFieldOperation",
597 std::function<AddScalarFieldOperation*()>([]() -> AddScalarFieldOperation* { return nullptr; }), true);
598 (void)addScalarOperation;
599
600 auto fieldTool = table.addClass<FieldBrushTool>(
601 "FieldBrushTool", std::function<FieldBrushTool*()>([]() -> FieldBrushTool* { return nullptr; }), true);
602 fieldTool.addFunc("setRadius", &FieldBrushTool::setRadius);
603 fieldTool.addFunc("setStrength", &FieldBrushTool::setStrength);
604 fieldTool.addFunc("getRadius", &FieldBrushTool::radius);
605 fieldTool.addFunc("getStrength", &FieldBrushTool::strength);
606 fieldTool.addFunc("setCircleKernel", [](FieldBrushTool* self, CircleBrushKernel* kernel) {
607 if (self) self->setKernel(kernel);
608 });
609 fieldTool.addFunc("setBoxKernel", [](FieldBrushTool* self, BoxBrushKernel* kernel) {
610 if (self) self->setKernel(kernel);
611 });
612 fieldTool.addFunc("setPaintIntOperation", [](FieldBrushTool* self, PaintIntFieldOperation* operation) {
613 if (self) self->setOperation(operation);
614 });
615 fieldTool.addFunc("setAddScalarOperation", [](FieldBrushTool* self, AddScalarFieldOperation* operation) {
616 if (self) self->setOperation(operation);
617 });
618
619 auto sphereVolumeKernel = table.addClass<SphereVolumeBrushKernel>(
620 "SphereVolumeBrushKernel",
621 std::function<SphereVolumeBrushKernel*()>([]() -> SphereVolumeBrushKernel* { return nullptr; }), true);
622 sphereVolumeKernel.addFunc("setConstantFalloff", [](SphereVolumeBrushKernel* self, ConstantBrushFalloff* falloff) {
623 if (self) self->setFalloff(falloff);
624 });
625 sphereVolumeKernel.addFunc("setLinearFalloff", [](SphereVolumeBrushKernel* self, LinearBrushFalloff* falloff) {
626 if (self) self->setFalloff(falloff);
627 });
628 sphereVolumeKernel.addFunc("setSmoothFalloff", [](SphereVolumeBrushKernel* self, SmoothBrushFalloff* falloff) {
629 if (self) self->setFalloff(falloff);
630 });
631
632 auto boxVolumeKernel = table.addClass<BoxVolumeBrushKernel>(
633 "BoxVolumeBrushKernel",
634 std::function<BoxVolumeBrushKernel*()>([]() -> BoxVolumeBrushKernel* { return nullptr; }), true);
635 boxVolumeKernel.addFunc("setConstantFalloff", [](BoxVolumeBrushKernel* self, ConstantBrushFalloff* falloff) {
636 if (self) self->setFalloff(falloff);
637 });
638 boxVolumeKernel.addFunc("setLinearFalloff", [](BoxVolumeBrushKernel* self, LinearBrushFalloff* falloff) {
639 if (self) self->setFalloff(falloff);
640 });
641 boxVolumeKernel.addFunc("setSmoothFalloff", [](BoxVolumeBrushKernel* self, SmoothBrushFalloff* falloff) {
642 if (self) self->setFalloff(falloff);
643 });
644
645 auto paintVolumeOperation = table.addClass<PaintIntVolumeOperation>(
646 "PaintIntVolumeOperation",
647 std::function<PaintIntVolumeOperation*()>([]() -> PaintIntVolumeOperation* { return nullptr; }), true);
648 paintVolumeOperation.addFunc("setValue", &PaintIntVolumeOperation::setValue);
649 paintVolumeOperation.addFunc("getValue", &PaintIntVolumeOperation::value);
650
651 auto volumeTool = table.addClass<VolumeBrushTool>(
652 "VolumeBrushTool", std::function<VolumeBrushTool*()>([]() -> VolumeBrushTool* { return nullptr; }), true);
653 volumeTool.addFunc("setRadius", &VolumeBrushTool::setRadius);
654 volumeTool.addFunc("getRadius", &VolumeBrushTool::radius);
655 volumeTool.addFunc("setSphereKernel", [](VolumeBrushTool* self, SphereVolumeBrushKernel* kernel) {
656 if (self) self->setKernel(kernel);
657 });
658 volumeTool.addFunc("setBoxKernel", [](VolumeBrushTool* self, BoxVolumeBrushKernel* kernel) {
659 if (self) self->setKernel(kernel);
660 });
661 volumeTool.addFunc("setPaintIntOperation", [](VolumeBrushTool* self, PaintIntVolumeOperation* operation) {
662 if (self) self->setOperation(operation);
663 });
664
665 auto session = table.addClass<EditorSession>(
666 "EditorSession", std::function<EditorSession*()>([]() -> EditorSession* { return nullptr; }), true);
667 session.addFunc("addTool", std::function<bool(EditorSession*, ScriptEditorTool*)>(
668 [](EditorSession* self, ScriptEditorTool* tool) { return self->addTool(tool); }));
669 session.addFunc("addFieldTool",
670 [](EditorSession* self, FieldBrushTool* tool) { return self && self->addTool(tool); });
671 session.addFunc("addVolumeTool",
672 [](EditorSession* self, VolumeBrushTool* tool) { return self && self->addTool(tool); });
673 session.addFunc("clearTarget", [](EditorSession* self) {
674 if (self) self->bindTarget(nullptr);
675 });
676 session.addFunc("removeTool", &EditorSession::removeTool);
677 session.addFunc("clearTools", &EditorSession::clearTools);
678 session.addFunc("activateTool", &EditorSession::activateTool);
679 session.addFunc("getToolCount", &EditorSession::getToolCount);
680 session.addFunc("getActiveToolId", &EditorSession::activeToolId);
681 session.addFunc("hasPointerCapture", &EditorSession::hasPointerCapture);
682 session.addFunc("update", &EditorSession::update);
683 session.addFunc("cancelActiveTool", &EditorSession::cancelActiveTool);
684 session.addFunc(
685 "undo", std::function<bool(EditorSession*)>([](EditorSession* self) { return self->transactions().undo(); }));
686 session.addFunc(
687 "redo", std::function<bool(EditorSession*)>([](EditorSession* self) { return self->transactions().redo(); }));
688 session.addFunc("canUndo", [](EditorSession* self) { return self && self->transactions().canUndo(); });
689 session.addFunc("canRedo", [](EditorSession* self) { return self && self->transactions().canRedo(); });
690 session.addFunc("clearHistory", [](EditorSession* self) {
691 if (self) self->transactions().clear();
692 });
693 session.addFunc("getCommandCount",
694 [](EditorSession* self) { return self ? static_cast<int>(self->availableCommands().size()) : 0; });
695 session.addFunc("getCommandId", [](EditorSession* self, int index) {
696 if (!self) return std::string{};
697 const auto commands = self->availableCommands();
698 return index >= 0 && index < static_cast<int>(commands.size()) ? commands[static_cast<size_t>(index)].id.value()
699 : std::string{};
700 });
701 session.addFunc("getCommandName", [](EditorSession* self, int index) {
702 if (!self) return std::string{};
703 const auto commands = self->availableCommands();
704 return index >= 0 && index < static_cast<int>(commands.size())
705 ? commands[static_cast<size_t>(index)].displayName
706 : std::string{};
707 });
708 session.addFunc("getCommandCategory", [](EditorSession* self, int index) {
709 if (!self) return std::string{};
710 const auto commands = self->availableCommands();
711 return index >= 0 && index < static_cast<int>(commands.size()) ? commands[static_cast<size_t>(index)].category
712 : std::string{};
713 });
714 session.addFunc("planCommand", [](EditorSession* self, const std::string& id, ssq::Object payload) -> ssq::Object {
715 HSQUIRRELVM vm = payload.getHandle();
717 if (!self || !objectToEditorValue(payload, value)) return resultTable(vm, invalidScriptPayload());
718 const Result<PlanId> planned = self->retainPlan(CommandId(id), value, CommandSource::Script);
719 ssq::Table out = resultTable(vm, planned);
720 if (planned.ok()) out.set("planId", planned.value().value());
721 return out;
722 });
723 session.addFunc(
724 "executePlan", [](EditorSession* self, const std::string& planId, ssq::Object scriptContext) -> ssq::Object {
725 HSQUIRRELVM vm = scriptContext.getHandle();
726 if (!self)
727 return resultTable(vm, eve::editing::failed<TransactionReceipt>(EditorStatus::Failed,
728 RuleId("editor.script.missing-session"),
729 "Editor session is not available"));
730 const Result<TransactionReceipt> executed =
731 self->executeRetainedPlan(PlanId(planId), CommandSource::Script);
732 ssq::Table out = resultTable(vm, executed);
733 if (executed.ok()) {
734 out.set("transactionId", executed.value().id.value());
735 out.set("transactionState", std::string(transactionStateName(executed.value().state)));
736 out.set("beforeRevision", static_cast<int64_t>(executed.value().beforeRevision));
737 out.set("afterRevision", static_cast<int64_t>(executed.value().afterRevision));
738 out.set("authorityReceipt", executed.value().authorityReceipt);
739 }
740 return out;
741 });
742 session.addFunc("executeCommand",
743 [](EditorSession* self, const std::string& id, ssq::Object payload) -> ssq::Object {
744 HSQUIRRELVM vm = payload.getHandle();
746 if (!self || !objectToEditorValue(payload, value))
747 return resultTable(vm, invalidScriptPayload());
748 const Result<EditorValue> executed =
749 self->executeCommand(CommandId(id), value, CommandSource::Script);
750 ssq::Table out = resultTable(vm, executed);
751 if (executed.ok()) setValue(out, "value", executed.value());
752 return out;
753 });
754 session.addFunc("dispatchPointer",
755 std::function<int(EditorSession*, int, int, int, float, float, float, float, float)>(
756 [](EditorSession* self, int phase, int pointerId, int button, float x, float y, float dx,
757 float dy, float pressure) {
758 EditorPointerEvent event;
759 event.phase = static_cast<EditorPointerEvent::Phase>(phase);
760 event.pointerId = pointerId;
761 event.button = button;
762 event.x = x;
763 event.y = y;
764 event.deltaX = dx;
765 event.deltaY = dy;
766 event.pressure = pressure;
767 const ToolResponse response = self->dispatchPointer(event);
768 return (response.handled ? 1 : 0) | (response.capturePointer ? 2 : 0) |
769 (response.releasePointer ? 4 : 0);
770 }));
771 session.addFunc("dispatchPointer3D",
772 std::function<int(EditorSession*, int, int, int, float, float, float, float, float, float, float)>(
773 [](EditorSession* self, int phase, int pointerId, int button, float x, float y, float z,
774 float dx, float dy, float dz, float pressure) {
775 EditorPointerEvent event;
776 event.phase = static_cast<EditorPointerEvent::Phase>(phase);
777 event.pointerId = pointerId;
778 event.button = button;
779 event.x = x;
780 event.y = y;
781 event.z = z;
782 event.deltaX = dx;
783 event.deltaY = dy;
784 event.deltaZ = dz;
785 event.pressure = pressure;
786 const ToolResponse response = self->dispatchPointer(event);
787 return (response.handled ? 1 : 0) | (response.capturePointer ? 2 : 0) |
788 (response.releasePointer ? 4 : 0);
789 }));
790
791 auto host = table.addClass<EditorHost>("EditorHost",
792 std::function<EditorHost*()>([]() -> EditorHost* { return nullptr; }), true);
793 host.addFunc("autoMount", [](EditorHost* self) {
794 if (!self) return 0;
795 auto report = self->autoMount();
796 return report.ok() ? static_cast<int>(report.value().mountedPackages) : -1;
797 });
798 host.addFunc("mount", [](EditorHost* self, const std::string& owner) {
799 if (!self) return 0;
800 auto report = self->mount(std::vector<std::string>{owner});
801 return report.ok() ? static_cast<int>(report.value().mountedPackages) : -1;
802 });
803 host.addFunc("unmount",
804 [](EditorHost* self, const std::string& owner) { return self && self->unmount(owner).ok(); });
805 host.addFunc("isMounted",
806 [](EditorHost* self, const std::string& owner) { return self && self->isMounted(owner); });
807 host.addFunc("getPanelCount",
808 [](EditorHost* self) { return self ? static_cast<int>(self->workspace().getPanelCount()) : 0; });
809 host.addFunc("exportMcp", [](EditorHost* self) { return self && self->exportMcp().ok(); });
810 host.addFunc("focusUndoOwner", [](EditorHost* self, const std::string& owner) {
811 return self && self->undo().focusOwner(owner).ok();
812 });
813
814 auto workspace = table.addClass<EditorWorkspace>(
815 "EditorWorkspace", std::function<EditorWorkspace*()>([]() -> EditorWorkspace* { return nullptr; }), true);
816 workspace.addFunc("getId", &EditorWorkspace::getId);
817 workspace.addFunc("getTitle", &EditorWorkspace::getTitle);
818 workspace.addFunc("setTitle", &EditorWorkspace::setTitle);
819 workspace.addFunc("registerPanel",
820 static_cast<bool (EditorWorkspace::*)(const std::string&, const std::string&,
821 const std::string&, int)>(&EditorWorkspace::registerPanel));
822 workspace.addFunc("removePanel",
823 static_cast<bool (EditorWorkspace::*)(const std::string&)>(&EditorWorkspace::removePanel));
824 workspace.addFunc("clearPanels", &EditorWorkspace::clearPanels);
825 workspace.addFunc("movePanel", static_cast<bool (EditorWorkspace::*)(const std::string&, const std::string&, int)>(
827 workspace.addFunc("setPanelCapability", &EditorWorkspace::setPanelCapability);
828 workspace.addFunc("setPanelContext", &EditorWorkspace::setPanelContext);
829 workspace.addFunc("setPanelVisible", &EditorWorkspace::setPanelVisible);
830 workspace.addFunc("setPanelSingleton", &EditorWorkspace::setPanelSingleton);
831 workspace.addFunc("activatePanel",
832 static_cast<bool (EditorWorkspace::*)(const std::string&)>(&EditorWorkspace::activatePanel));
833 workspace.addFunc("getActivePanel", &EditorWorkspace::getActivePanel);
834 workspace.addFunc("getPanelCount", &EditorWorkspace::getPanelCount);
835 workspace.addFunc("getPanelId", &EditorWorkspace::getPanelId);
836 workspace.addFunc("getPanelTitle", &EditorWorkspace::getPanelTitle);
837 workspace.addFunc("getPanelRegion", &EditorWorkspace::getPanelRegion);
838 workspace.addFunc("getPanelCapability", &EditorWorkspace::getPanelCapability);
839 workspace.addFunc("getPanelContext", &EditorWorkspace::getPanelContext);
840 workspace.addFunc("getPanelOrder", &EditorWorkspace::getPanelOrder);
841 workspace.addFunc("getPanelVisible", &EditorWorkspace::getPanelVisible);
842 workspace.addFunc("getPanelSingleton", &EditorWorkspace::getPanelSingleton);
843 workspace.addFunc("setRegionSize", &EditorWorkspace::setRegionSize);
844 workspace.addFunc("layout", &EditorWorkspace::layout);
845 workspace.addFunc("getRegionX", &EditorWorkspace::getRegionX);
846 workspace.addFunc("getRegionY", &EditorWorkspace::getRegionY);
847 workspace.addFunc("getRegionW", &EditorWorkspace::getRegionW);
848 workspace.addFunc("getRegionH", &EditorWorkspace::getRegionH);
849 workspace.addFunc("setMode", &EditorWorkspace::setMode);
850 workspace.addFunc("getMode", &EditorWorkspace::getMode);
851 workspace.addFunc("select", &EditorWorkspace::select);
852 workspace.addFunc("clearSelection", &EditorWorkspace::clearSelection);
853 workspace.addFunc("getSelectionCount", &EditorWorkspace::getSelectionCount);
854 workspace.addFunc("getSelectionItem", &EditorWorkspace::getSelectionItem);
855 workspace.addFunc("getSelectionType", &EditorWorkspace::getSelectionType);
856 workspace.addFunc("getPrimarySelection", &EditorWorkspace::getPrimarySelection);
857 workspace.addFunc("getSelectionSequence", &EditorWorkspace::getSelectionSequence);
858 workspace.addFunc("focus", &EditorWorkspace::focus);
859 workspace.addFunc("getFocusedSurface", &EditorWorkspace::getFocusedSurface);
860 workspace.addFunc("getRevision", &EditorWorkspace::getRevision);
861
862 auto scriptTool = table.addClass<ScriptEditorTool>(
863 "ScriptEditorTool", std::function<ScriptEditorTool*()>([]() -> ScriptEditorTool* { return nullptr; }), true);
864 scriptTool.addFunc("setShortcut", &ScriptEditorTool::setShortcut);
865 scriptTool.addFunc("setActivateCallback", &ScriptEditorTool::setActivateCallback);
866 scriptTool.addFunc("setDeactivateCallback", &ScriptEditorTool::setDeactivateCallback);
867 scriptTool.addFunc("setPointerCallback", &ScriptEditorTool::setPointerCallback);
868 scriptTool.addFunc("setKeyCallback", &ScriptEditorTool::setKeyCallback);
869 scriptTool.addFunc("setUpdateCallback", &ScriptEditorTool::setUpdateCallback);
870 scriptTool.addFunc("setCancelCallback", &ScriptEditorTool::setCancelCallback);
871}
872
873void Editor::expose(ssq::Class& cls) {
874 cls.addFunc("getName", &Editor::getName);
875 cls.addFunc("newGizmo", [](Editor* self) { return self->newGizmo().release(); });
876 cls.addFunc("newGizmoManager", [](Editor* self) { return self->newGizmoManager().release(); });
877 cls.addFunc("newToolbar", [](Editor* self) { return self->newToolbar().release(); });
878 cls.addFunc("newInspector", [](Editor* self) { return self->newInspector().release(); });
879 cls.addFunc("newDock", [](Editor* self) { return self->newDock().release(); });
880 cls.addFunc("newSession", [](Editor* self) { return self->newSession().release(); });
881 cls.addFunc("newWorkspace", [](Editor* self, const std::string& id, const std::string& title) {
882 auto created = self->newWorkspace(id, title);
883 return created.ok() ? std::move(created).takeValue().release() : nullptr;
884 });
885 cls.addFunc("newHost", [](Editor* self, const std::string& id, const std::string& title) {
886 auto created = self->newHost(id, title);
887 return created.ok() ? std::move(created).takeValue().release() : nullptr;
888 });
889 cls.addFunc("newScriptTool", [](Editor* self, const std::string& id, const std::string& label) {
890 return self->newScriptTool(id, label).release();
891 });
892 cls.addFunc("newConstantBrushFalloff", [](Editor* self) { return self->newConstantBrushFalloff().release(); });
893 cls.addFunc("newLinearBrushFalloff", [](Editor* self) { return self->newLinearBrushFalloff().release(); });
894 cls.addFunc("newSmoothBrushFalloff", [](Editor* self) { return self->newSmoothBrushFalloff().release(); });
895 cls.addFunc("newCircleBrushKernel", [](Editor* self) { return self->newCircleBrushKernel().release(); });
896 cls.addFunc("newBoxBrushKernel", [](Editor* self) { return self->newBoxBrushKernel().release(); });
897 cls.addFunc("newPaintIntFieldOperation", [](Editor* self, int value) {
898 return self->newPaintIntFieldOperation(value).release();
899 });
900 cls.addFunc("newAddScalarFieldOperation",
901 [](Editor* self) { return self->newAddScalarFieldOperation().release(); });
902 cls.addFunc("newFieldBrushTool", [](Editor* self, const std::string& id, const std::string& label) {
903 return self->newFieldBrushTool(id, label).release();
904 });
905 cls.addFunc("newSphereVolumeBrushKernel",
906 [](Editor* self) { return self->newSphereVolumeBrushKernel().release(); });
907 cls.addFunc("newBoxVolumeBrushKernel", [](Editor* self) { return self->newBoxVolumeBrushKernel().release(); });
908 cls.addFunc("newPaintIntVolumeOperation", [](Editor* self, int value) {
909 return self->newPaintIntVolumeOperation(value).release();
910 });
911 cls.addFunc("newVolumeBrushTool", [](Editor* self, const std::string& id, const std::string& label) {
912 return self->newVolumeBrushTool(id, label).release();
913 });
914 cls.addFunc("registerScriptCommand", registerScriptCommand);
915 cls.addFunc("registerAutomatedScriptCommand", registerAutomatedScriptCommand);
916 cls.addFunc("unregisterScriptCommand", [](Editor* self, const std::string& id) {
917 return self && self->commandService().unregisterCommand(CommandId(id), "script:" + id);
918 });
919}
920
921} // namespace eve::editor
double z
double y
double x
LogicalId target
ActionParameterOperation operation
Value::Object payload
std::string descriptor
struct SQVM * HSQUIRRELVM
std::string title
HSQUIRRELVM vm
Definition ECS.cpp:38
HSQOBJECT cls
Definition ECS.cpp:39
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
const GltfImportRequest & request
wgpu::PopErrorScopeStatus status
std::string label
std::string id
std::string response
Poco::JSON::Object::Ptr result
std::vector< RecipeParam > params
float tb
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:27
std::shared_ptr< OceanGpuSpectrum > owner
glm::dvec3 dx
glm::dvec3 dz
std::set< std::string > values
Object::Ptr value
int created
ScriptStructure out
double current
std::string string
float dy
Definition Shadow.cpp:151
const SquirrelValueOptions & options
int count
The single Squirrel projection for common Result, Status and Value.
float phase
std::optional< InteractionSession > session
Definition Tactics.cpp:39
UIHostHandle host
const char * category
std::uint32_t depth
uint32_t index
std::vector< VegetationPresetCommand > commands
ViewPreparation callback
virtual std::string getName() const =0
Returns the name.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
UUID-backed identifier adapter for legacy textual boundaries.
Definition Identity.h:313
IEditableTarget public API.
std::vector< Value > Array
std::map< std::string, Value > Object
MCP/DevTools adapter over command discovery and target coordination.
float getRegionX(const std::string &region) const
Returns the region x.
void setRegionSize(const std::string &region, float pixels)
Sets the region size.
float getRegionY(const std::string &region) const
Returns the region y.
void layout(float screenW, float screenH)
Layout.
float getRegionW(const std::string &region) const
Returns the region w.
float getRegionH(const std::string &region) const
Returns the region h.
float getRegionSize(const std::string &region) const
Returns the region size.
void addFloat(const std::string &id, const std::string &label, float value, float minV, float maxV, float step)
Adds float.
std::string getFieldKind(int index) const
Returns the field kind.
bool isDirty(const std::string &id) const
True when dirty.
void setFloat3(const std::string &id, float x, float y, float z)
Sets the float 3.
float getFloatStep(const std::string &id) const
Returns the float step.
std::string getFieldLabel(int index) const
Returns the field label.
float getFloat3X(const std::string &id) const
Returns the float 3 x.
void setChoice(const std::string &id, const std::string &value)
Sets the choice.
std::string getString(const std::string &id) const
Returns the string.
void clearDirty(const std::string &id)
Clears dirty.
std::string pollChangedId()
Returns next dirty field id, or "" if none.
void setFloat(const std::string &id, float value)
Sets the float.
std::string getChoice(const std::string &id) const
Returns the choice.
std::string getChoicesCsv(const std::string &id) const
Returns the choices csv.
void addString(const std::string &id, const std::string &label, const std::string &value)
Adds string.
float getFloat(const std::string &id) const
Returns the float.
float getFloat3Z(const std::string &id) const
Returns the float 3 z.
std::string getFieldId(int index) const
Returns the field id.
void setString(const std::string &id, const std::string &value)
Sets the string.
int getFieldCount() const
Returns the field count.
void setBool(const std::string &id, bool value)
Sets the bool.
void addBool(const std::string &id, const std::string &label, bool value)
Adds bool.
float getFloatMax(const std::string &id) const
Returns the float max.
float getFloatMin(const std::string &id) const
Returns the float min.
void addFloat3(const std::string &id, const std::string &label, float x, float y, float z)
Adds float 3.
bool getBool(const std::string &id) const
Returns the bool.
void addChoice(const std::string &id, const std::string &label, const std::string &choicesCsv, const std::string &selected)
Adds choice.
void clearAllDirty()
Clears all dirty.
float getFloat3Y(const std::string &id) const
Returns the float 3 y.
void detach()
Clear the active attachment.
Hosts interchangeable editor tools and routes their lifecycle/input.
bool hasPointerCapture() const
True when pointer capture.
bool removeTool(const std::string &id)
Remove a registered tool by id, deactivating it when necessary.
bool activateTool(const std::string &id)
Activate a registered tool by id. Empty id deactivates all tools.
void update(float dt)
Update the active tool.
void cancelActiveTool()
Cancel its gesture and clear pointer capture.
void clearTools()
Remove all tools and release any pointer capture.
std::string activeToolId() const
Active tool id.
int getToolCount() const
Returns the tool count.
Coordinates editable targets, per-target histories and domain commands.
std::string getToolLabel(int index) const
Returns the tool label.
std::string getToolId(int index) const
Returns the tool id.
void setIcon(const std::string &id, const std::string &icon)
Assigns a backend-neutral semantic icon name to an existing tool.
void addTool(const std::string &id, const std::string &label)
Adds tool.
int getToolCount() const
Returns the tool count.
bool setActive(const std::string &id)
Sets the active.
std::string getActive() const
Returns the active.
void setShortcut(const std::string &id, const std::string &key)
Sets the shortcut.
std::string getToolShortcut(int index) const
Returns the tool shortcut.
bool matchShortcut(const std::string &key)
Match shortcut.
std::string getToolIcon(int index) const
Returns the tool's semantic icon name.
std::string getPrimarySelection(const std::string &channel) const
Primary selected item id for a channel.
std::string getFocusedSurface(const std::string &channel) const
Focused surface id for a channel.
bool getPanelSingleton(int index) const
Panel singleton policy by deterministic index.
std::uint64_t getSelectionSequence(const std::string &channel) const
Monotonic selection sequence for MVVM change detection.
std::string getPanelCapability(int index) const
Panel capability requirement by deterministic index.
std::string getPanelRegion(int index) const
Panel dock region by deterministic index.
float getRegionH(const std::string &region) const
Computed region height.
std::string getPanelContext(int index) const
Panel input context by deterministic index.
Result< WorkspacePanelDescriptor > removePanel(const StableId &id)
Remove a panel and return its final owning descriptor.
std::uint64_t getRevision() const
Monotonic structural revision for cheap ViewModel synchronization.
bool setPanelContext(const std::string &id, const std::string &context)
Attach a semantic input context such as scene, graph, or timeline.
std::string getPanelTitle(int index) const
Panel title by deterministic index.
bool focus(const std::string &channel, const std::string &surface, const std::string &item)
Set UI-toolkit-independent focus for a channel.
std::string getSelectionItem(const std::string &channel, int index) const
Selected stable item id by channel/index.
const std::string & getMode() const
Current project-defined mode.
Result< WorkspacePanelDescriptor > registerPanel(WorkspacePanelDescriptor descriptor)
Register a checked owning panel descriptor.
void setTitle(const std::string &title)
Change the display title without changing workspace identity.
std::string getSelectionType(const std::string &channel, int index) const
Selected item type by channel/index.
bool select(const std::string &channel, const std::string &domain, const std::string &target, const std::string &item, const std::string &type, bool additive)
Select one stable item in a semantic channel.
bool setMode(const std::string &mode)
Set a project-defined mode such as edit, play, material, or animation.
Result< WorkspacePanelDescriptor > activatePanel(const StableId &id)
Activate a visible panel with structured not-found/rejected results.
float getRegionY(const std::string &region) const
Computed region Y coordinate.
int getPanelCount() const
Number of registered panels in deterministic region/order/id order.
Result< WorkspacePanelDescriptor > movePanel(const StableId &id, WorkspaceRegion region, int order)
Move a panel using a strongly typed dock region.
void clearPanels()
Remove every panel descriptor.
bool getPanelVisible(int index) const
Panel visibility by deterministic index.
bool setPanelCapability(const std::string &id, const std::string &capability)
Attach a capability requirement used by the host when filtering panels.
void layout(float width, float height)
Compute standard dock rectangles for the requested host size.
const std::string & getId() const
Stable project-defined workspace id.
int getPanelOrder(int index) const
Panel order by deterministic index.
bool setPanelSingleton(const std::string &id, bool singleton)
Mark whether hosts should allow more than one instance of this panel type.
void setRegionSize(const std::string &region, float pixels)
Configure one standard dock region size in pixels.
std::string getPanelId(int index) const
Panel id by deterministic index.
float getRegionX(const std::string &region) const
Computed region X coordinate.
const std::string & getActivePanel() const
Active panel id, or an empty string.
int getSelectionCount(const std::string &channel) const
Number of selected items in a channel.
bool setPanelVisible(const std::string &id, bool visible)
Show or hide a panel without removing its descriptor.
float getRegionW(const std::string &region) const
Computed region width.
bool clearSelection(const std::string &channel)
Clear one semantic selection channel.
const std::string & getTitle() const
User-facing workspace title.
Editor building blocks — not a shipped 3D/map editor app. Script: editor <- eve.Editor();
Definition Editor.h:47
std::unique_ptr< PaintIntVolumeOperation > newPaintIntVolumeOperation(int value)
Create a byte-range integer paint operation for volume targets. @ownership Unique ownership transfers...
Definition Editor.cpp:402
std::unique_ptr< PaintIntFieldOperation > newPaintIntFieldOperation(int value)
Create an integer-field paint operation. @ownership Unique ownership transfers to the caller.
Definition Editor.cpp:386
std::unique_ptr< EditorDock > newDock()
Create a dock model. @ownership Unique ownership transfers to the caller.
Definition Editor.cpp:349
std::unique_ptr< BoxVolumeBrushKernel > newBoxVolumeBrushKernel()
Create an axis-aligned box kernel for sparse three-dimensional fields. @ownership Unique ownership tr...
Definition Editor.cpp:399
std::unique_ptr< TransformGizmo > newGizmo()
Create a transform gizmo. @ownership Unique ownership transfers to the caller.
Definition Editor.cpp:341
~Editor() override
Editor.
Definition Editor.cpp:323
std::unique_ptr< VolumeBrushTool > newVolumeBrushTool(const std::string &id, const std::string &label)
Create a 3D brush tool whose kernel and operation are supplied separately. @ownership Unique ownershi...
Definition Editor.cpp:405
Result< void > unregisterEditingTarget(const TargetId &target)
Remove a borrowed editing target and its local transaction history.
Definition Editor.cpp:331
std::unique_ptr< ScriptEditorTool > newScriptTool(const std::string &id, const std::string &label)
Create a script-backed implementation of the IEditorTool protocol. @ownership Unique ownership transf...
Definition Editor.cpp:375
std::unique_ptr< BoxBrushKernel > newBoxBrushKernel()
Create a rotatable box brush kernel with a replaceable falloff. @ownership Unique ownership transfers...
Definition Editor.cpp:385
std::unique_ptr< EditorSession > newSession()
Create a host for interchangeable IEditorTool implementations. @ownership Unique ownership transfers ...
Definition Editor.cpp:351
std::unique_ptr< FieldBrushTool > newFieldBrushTool(const std::string &id, const std::string &label)
Create a field brush tool whose kernel and operation are supplied separately.
Definition Editor.cpp:392
std::unique_ptr< SphereVolumeBrushKernel > newSphereVolumeBrushKernel()
Create a spherical kernel for sparse three-dimensional fields. @ownership Unique ownership transfers ...
Definition Editor.cpp:396
std::unique_ptr< ConstantBrushFalloff > newConstantBrushFalloff()
Create a constant brush falloff strategy. @ownership Unique ownership transfers to the caller.
Definition Editor.cpp:379
std::unique_ptr< SmoothBrushFalloff > newSmoothBrushFalloff()
Create a smoothstep brush falloff strategy. @ownership Unique ownership transfers to the caller.
Definition Editor.cpp:383
std::unique_ptr< EditorToolbar > newToolbar()
Create a toolbar model. @ownership Unique ownership transfers to the caller.
Definition Editor.cpp:345
std::unique_ptr< LinearBrushFalloff > newLinearBrushFalloff()
Create a linear brush falloff strategy. @ownership Unique ownership transfers to the caller.
Definition Editor.cpp:382
std::unique_ptr< GizmoManager > newGizmoManager()
Create a gizmo manager. @ownership Unique ownership transfers to the caller.
Definition Editor.cpp:343
std::unique_ptr< AddScalarFieldOperation > newAddScalarFieldOperation()
Create an additive scalar-field operation. @ownership Unique ownership transfers to the caller.
Definition Editor.cpp:389
std::unique_ptr< CircleBrushKernel > newCircleBrushKernel()
Create a circular brush kernel with a replaceable falloff. @ownership Unique ownership transfers to t...
Definition Editor.cpp:384
std::unique_ptr< EditorInspector > newInspector()
Create an inspector model. @ownership Unique ownership transfers to the caller.
Definition Editor.cpp:347
Result< std::unique_ptr< EditorHost > > newHost(const std::string &id, const std::string &title)
Create a package-discovering EditorHost bound to this module.
Definition Editor.cpp:365
Result< std::unique_ptr< EditorWorkspace > > newWorkspace(const std::string &id, const std::string &title)
Create a UI-neutral composition model for a project-specific editor.
Definition Editor.cpp:357
Result< void > bindEditingTarget(EditorSession &session, const TargetId &target)
Bind a registered target to a host session without exposing the coordinator.
Definition Editor.cpp:337
Result< void > registerEditingTarget(IEditableTarget &target)
Register a borrowed editable target for UI, script and automation access.
Definition Editor.cpp:329
float radius() const
Radius.
float strength() const
Strength.
void setStrength(float strength)
Set the operation strength; negative values are permitted.
void setRadius(float radius)
Set brush radius in target coordinates.
bool getScaleEnabled() const
Returns the scale enabled.
bool isDragging() const
True when dragging.
void setPositionEnabled(bool enabled)
Sets the position enabled.
void setScaleEnabled(bool enabled)
Sets the scale enabled.
void setBoundEnabled(bool enabled)
Sets the bound enabled.
bool getPositionEnabled() const
Returns the position enabled.
bool isHovered() const
True when hovered.
bool isAttached() const
True when attached.
void setRotationEnabled(bool enabled)
Sets the rotation enabled.
TransformGizmo * getGizmo()
Returns the gizmo.
std::string pick(float ox, float oy, float oz, float dx, float dy, float dz)
Pick across enabled modes; sets gizmo mode to the winning tool.
bool getBoundEnabled() const
Returns the bound enabled.
bool getRotationEnabled() const
Returns the rotation enabled.
bool beginDrag(const std::string &axis, float ox, float oy, float oz, float dx, float dy, float dz)
Begins drag.
bool updateDrag(float ox, float oy, float oz, float dx, float dy, float dz)
Updates drag.
int value() const
Return the integer written by this operation.
void setValue(int value)
Change the integer written by subsequent stamps.
void setValue(int value)
Set the value written by subsequent stamps.
int value() const
Return the value written by this operation.
void setActivateCallback(ssq::Object callback)
Set a closure invoked when the tool becomes active.
void setKeyCallback(ssq::Object callback)
Set a closure invoked for normalized key input.
void setUpdateCallback(ssq::Object callback)
Set a closure invoked every active frame with delta time.
void setShortcut(const std::string &shortcut)
Set the shortcut shown by hosts.
void setDeactivateCallback(ssq::Object callback)
Set a closure invoked when the tool becomes inactive.
void setPointerCallback(ssq::Object callback)
Set a closure invoked for normalized pointer input.
void setCancelCallback(ssq::Object callback)
Set a closure invoked when the current gesture is cancelled.
3D transform gizmo (Three.js TransformControls + ImGuizmo style). Owns TRS + optional local bounds; i...
float getPartDirY(int index) const
Returns the part dir y.
float getSnapTranslateY() const
Returns the snap translate y.
std::string getHoverAxis() const
Returns the hover axis.
float getBoundsMinY() const
Returns the bounds min y.
void setSnapScale(float s)
Sets the snap scale.
float getSnapTranslateZ() const
Returns the snap translate z.
void setSnapRotate(float degrees)
Sets the snap rotate.
float getPartColorR(int index) const
Returns the part color r.
float getRotationZ() const
Returns the rotation z.
float getPositionY() const
Returns the position y.
bool isDragging() const
True when dragging.
void rebuildParts()
Rebuild draw parts for current mode/space (call after TRS/mode change).
float getBoundsMinZ() const
Returns the bounds min z.
float getPartDirX(int index) const
Returns the part dir x.
float getSize() const
Returns the size.
std::string pick(float ox, float oy, float oz, float dx, float dy, float dz)
Ray pick against active mode handles. Returns axis id: "x"|"y"|"z"|"xy"|"yz"|"xz"|"xyz"|"bx"|…|"bz"|"...
bool isHovered() const
True when hovered.
float getRotationX() const
Returns the rotation x.
float getPartDirZ(int index) const
Returns the part dir z.
std::string getPartKind(int index) const
Returns the part kind.
float getBoundsMinX() const
Returns the bounds min x.
std::string getMode() const
Returns the mode.
float getPartRadius(int index) const
Returns the part radius.
float getBoundsMaxZ() const
Returns the bounds max z.
float getMatrix(int index) const
Column-major matrix element 0..15 of current TRS.
void setSize(float size)
Sets the size.
float getPartColorG(int index) const
Returns the part color g.
float getSnapRotate() const
Returns the snap rotate.
void setBounds(float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
Local AABB extents for bound mode (relative to object origin).
float getPartColorB(int index) const
Returns the part color b.
bool beginDrag(const std::string &axis, float ox, float oy, float oz, float dx, float dy, float dz)
Begins drag.
float getPartOriginY(int index) const
Returns the part origin y.
void setSnapTranslate(float x, float y, float z)
Sets the snap translate.
float getScaleZ() const
Returns the scale z.
float getPositionZ() const
Returns the position z.
std::string getActiveAxis() const
Returns the active axis.
float getScaleX() const
Returns the scale x.
float getPartLength(int index) const
Returns the part length.
float getScaleY() const
Returns the scale y.
void setPosition(float x, float y, float z)
Sets the position.
float getPartColorA(int index) const
Returns the part color a.
bool updateDrag(float ox, float oy, float oz, float dx, float dy, float dz)
Updates drag.
float getSnapTranslateX() const
Returns the snap translate x.
float getPartOriginX(int index) const
Returns the part origin x.
void setRotationEuler(float x, float y, float z)
Euler radians, XYZ order.
void setMode(const std::string &mode)
Sets the mode.
float getBoundsMaxX() const
Returns the bounds max x.
float getRotationY() const
Returns the rotation y.
float getSnapScale() const
Returns the snap scale.
std::string getSpace() const
Returns the space.
void setScale(float x, float y, float z)
Sets the scale.
std::string getPartAxis(int index) const
Returns the part axis.
float getPartOriginZ(int index) const
Returns the part origin z.
float getBoundsMaxY() const
Returns the bounds max y.
int getPartCount() const
Returns the part count.
float getPositionX() const
Returns the position x.
void setSpace(const std::string &space)
Sets the space.
float radius() const
Return radius in target voxel coordinates.
void setRadius(float radius)
Set radius in target voxel coordinates.
SQInteger top
Definition Snapshot.cpp:115
PropertySchema emptyObjectPropertySchema(std::string_view typeId)
Build an explicit empty-object payload schema.
RuleId diagnosticRule(const Diagnostic &diagnostic)
Return the projected editing rule, or an empty RuleId when absent.
EditorMcpProjector & editorMcpProjector()
Process-wide projector used by EditorAutomationProvider and eve.mcp.attachEditor.
eve::editing::Value EditorValue
Compatibility alias for the UI-independent authoring value tree.
Definition EditorValue.h:8
eve::editing::PlanId PlanId
Definition EditorIds.h:35
eve::editing::TransactionState TransactionState
eve::editing::CommandId CommandId
Definition EditorIds.h:30
eve::Diagnostic EditorDiagnostic
eve::editing::RuleId RuleId
Definition EditorIds.h:32
eve::editing::TransactionReceipt TransactionReceipt
eve::editing::CommandPlan CommandPlan
eve::editing::DomainOperation DomainOperation
eve::editing::TransactionId TransactionId
Definition EditorIds.h:34
eve::editing::CommandRequest CommandRequest
@ Commands
Mode A: keep eve_editor_* with schema enrichment (default).
Result< void > accepted()
Build a successful write/validation result.
std::unordered_map< std::string, SkillDefinition > & table()
Definition Skill.cpp:73
std::string reportScriptCallFailure(HSQUIRRELVM vm, const char *what)
Report a failed engine-to-script call, consuming the VM's script error.
std::string_view statusName(BattleStatus status) noexcept
Return the stable protocol spelling of a battle status.
ControlEdit button(const char *label, float width=0.f, float height=0.f)
Shared immediate renderer for retained and EditorHost buttons.
StatusCode
Stable outcome category for an operation.
Definition Status.h:28
void setEditorMcpAttachHooks(EditorMcpAttachFn attach, EditorMcpDetachFn detach)
Register Host attach hooks used by eve.mcp.attachEditor.