载入中...
搜索中...
未找到
UiThemeEditorScriptBindings.cpp
浏览该文件的文档.
2
6
7#include <simplesquirrel/simplesquirrel.hpp>
8
9#include <cstdint>
10#include <string>
11
13#include "common/Value.h"
15
16namespace eve::ui_editor {
17namespace {
18
19constexpr const char* kBindingSource = "editor.ui.theme.squirrel";
20
21class ScriptUiThemeEditor {
22public:
23 explicit ScriptUiThemeEditor(std::string targetId) : editor_(std::move(targetId)) {}
24
25 UiThemeEditor& editor() noexcept { return editor_; }
26 const UiThemeEditor& editor() const noexcept { return editor_; }
27
28private:
29 UiThemeEditor editor_;
30};
31
32} // namespace
33
34void exposeUiThemeEditorScriptBindings(ssq::Table& table, ssq::Class& moduleClass) {
35 const editor::ScriptBind bind{table.getHandle(), kBindingSource};
36 auto themeEditor = editor::addScriptClass<ScriptUiThemeEditor>(table, "UiThemeEditor");
37
38 editor::registerEditorWorkspace<ScriptUiThemeEditor>(themeEditor, bind,
39 "theme editor and workspace must not be null");
40 themeEditor.addFunc("selectTheme", [bind](ScriptUiThemeEditor* self, const std::string& id) {
41 return bind.checked(self, "theme editor must not be null", [&] { return self->editor().selectTheme(id); });
42 });
43 themeEditor.addFunc("createFromPreset", [bind](ScriptUiThemeEditor* self, const std::string& id,
44 const std::string& name, const std::string& preset) {
45 return bind.checked(self, "theme editor must not be null",
46 [&] { return self->editor().createFromPreset(id, name, preset); });
47 });
48 themeEditor.addFunc("duplicateSelected",
49 [bind](ScriptUiThemeEditor* self, const std::string& id, const std::string& name) {
50 return bind.checked(self, "theme editor must not be null",
51 [&] { return self->editor().duplicateSelected(id, name); });
52 });
53 themeEditor.addFunc("deleteSelected", [bind](ScriptUiThemeEditor* self) {
54 return bind.checked(self, "theme editor must not be null", [&] { return self->editor().deleteSelected(); });
55 });
56 themeEditor.addFunc("setActiveSelected", [bind](ScriptUiThemeEditor* self) {
57 return bind.checked(self, "theme editor must not be null", [&] { return self->editor().setActiveSelected(); });
58 });
59 themeEditor.addFunc("resetSelectedToBase", [bind](ScriptUiThemeEditor* self) {
60 return bind.checked(self, "theme editor must not be null",
61 [&] { return self->editor().resetSelectedToBase(); });
62 });
63 themeEditor.addFunc(
64 "setColor", [bind](ScriptUiThemeEditor* self, const std::string& path, float r, float g, float b, float a) {
65 return bind.checked(self, "theme editor must not be null", [&] {
66 return self->editor().setToken(
67 path, ui_editing::EditorValue::Array{static_cast<double>(r), static_cast<double>(g),
68 static_cast<double>(b), static_cast<double>(a)});
69 });
70 });
71 themeEditor.addFunc("setFloat", [bind](ScriptUiThemeEditor* self, const std::string& path, float value) {
72 return bind.checked(self, "theme editor must not be null",
73 [&] { return self->editor().setToken(path, static_cast<double>(value)); });
74 });
75 themeEditor.addFunc("applyPreviewHost", [bind](ScriptUiThemeEditor* self, const std::string& hostName) {
76 return bind.checked(self, "theme editor must not be null",
77 [&] { return self->editor().applyPreviewHost(hostName); });
78 });
79 editor::registerEditorHistory<ScriptUiThemeEditor>(themeEditor, bind, "theme editor must not be null");
80 script::bindNullSafe<ScriptUiThemeEditor>(
81 themeEditor, "getPreviewRevision",
82 [](ScriptUiThemeEditor& self) { return static_cast<int>(self.editor().previewRevision()); }, 0);
83 script::bindNullSafe<ScriptUiThemeEditor>(
84 themeEditor, "getSelectedId", [](ScriptUiThemeEditor& self) { return self.editor().selectedId(); },
85 std::string{});
86 script::bindNullSafe<ScriptUiThemeEditor>(
87 themeEditor, "getActiveId", [](ScriptUiThemeEditor& self) { return self.editor().activeId(); }, std::string{});
88 script::bindNullSafe<ScriptUiThemeEditor>(
89 themeEditor, "getPreviewRuntimeName",
90 [](ScriptUiThemeEditor& self) { return self.editor().previewRuntimeName(); }, std::string{});
91 script::bindNullSafe<ScriptUiThemeEditor>(
92 themeEditor, "getThemeCount", [](ScriptUiThemeEditor& self) { return self.editor().themeCount(); }, 0);
93 themeEditor.addFunc("getThemeId", [](ScriptUiThemeEditor* self, int index) {
94 return self ? self->editor().themeId(index) : std::string{};
95 });
96 themeEditor.addFunc("getThemeName", [](ScriptUiThemeEditor* self, int index) {
97 return self ? self->editor().themeName(index) : std::string{};
98 });
99 themeEditor.addFunc("getThemeSelected", [](ScriptUiThemeEditor* self, int index) {
100 return self && self->editor().isThemeSelected(index);
101 });
102 themeEditor.addFunc("getThemeActive", [](ScriptUiThemeEditor* self, int index) {
103 return self && self->editor().isThemeActive(index);
104 });
105 themeEditor.addFunc("getColorR", [](ScriptUiThemeEditor* self, const std::string& path) {
106 return self ? self->editor().getColorChannel(path, 0) : 0.0f;
107 });
108 themeEditor.addFunc("getColorG", [](ScriptUiThemeEditor* self, const std::string& path) {
109 return self ? self->editor().getColorChannel(path, 1) : 0.0f;
110 });
111 themeEditor.addFunc("getColorB", [](ScriptUiThemeEditor* self, const std::string& path) {
112 return self ? self->editor().getColorChannel(path, 2) : 0.0f;
113 });
114 themeEditor.addFunc("getColorA", [](ScriptUiThemeEditor* self, const std::string& path) {
115 return self ? self->editor().getColorChannel(path, 3) : 1.0f;
116 });
117 themeEditor.addFunc("getFloat", [](ScriptUiThemeEditor* self, const std::string& path) {
118 return self ? self->editor().getFloat(path) : 0.0f;
119 });
120 // Additive structured snapshot; atomic getters above remain the compatibility surface.
121 themeEditor.addFunc("getState", [vm = table.getHandle()](ScriptUiThemeEditor* self) {
122 if (!self) {
125 {}, {}, kBindingSource)));
126 }
127 const auto& editor = self->editor();
131 {"selectedId", Value(editor.selectedId())},
132 {"activeId", Value(editor.activeId())},
133 {"previewRuntimeName", Value(editor.previewRuntimeName())},
134 {"revision", Value(static_cast<std::int64_t>(editor.revision()))},
135 {"previewRevision", Value(static_cast<std::int64_t>(editor.previewRevision()))},
136 {"themeCount", Value(editor.themeCount())},
137 }));
138 });
139
140 editor::registerEditorOwnedCreate<ScriptUiThemeEditor, UiEditorModule>(moduleClass, bind,
141 "theme catalog id must not be empty");
142}
143
144} // namespace eve::ui_editor
double value
HSQUIRRELVM vm
Definition ECS.cpp:20
tensor::Graph g
Definition GpuGraph.cpp:7
double r
std::string name
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
std::string path
Definition PlayHost.cpp:110
std::uint32_t targetId
Per-translation-unit VM + diagnostic-source helper for Squirrel bindings.
Squirrel adapter for the UI theme editor.
UI-neutral named Theme catalog editor: workspace, gallery preview, undo.
uint32_t index
Owning, renderer-independent dynamic values.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
static Status failure(StatusCode code, Diagnostic diagnostic)
Construct a failed status with one diagnostic.
Definition Status.h:84
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::map< std::string, Value > Object
Definition Value.h:34
std::vector< Value > Array
Editor facade binder: common script::BindContext plus history/owned-create helpers.
ssq::Table projectStatusResult(HSQUIRRELVM vm, const Status &status)
Project a checked native status that carries no payload.
void exposeUiThemeEditorScriptBindings(ssq::Table &table, ssq::Class &moduleClass)
Expose the script-owned UiThemeEditor factory on UiEditorModule.