载入中...
搜索中...
未找到
BiomeRulesEditorScriptBindings.cpp
浏览该文件的文档.
2
6
7#include <simplesquirrel/simplesquirrel.hpp>
8
9#include <cstdint>
10#include <string>
12
13namespace eve::biome_editor {
14namespace {
15
16constexpr const char* kBindingSource = "editor.biome.rules.squirrel";
17
18class ScriptBiomeRulesEditor {
19public:
20 explicit ScriptBiomeRulesEditor(std::string targetId) : editor_(std::move(targetId)) {}
21
22 BiomeRulesEditor& editor() noexcept { return editor_; }
23 const BiomeRulesEditor& editor() const noexcept { return editor_; }
24
25private:
26 BiomeRulesEditor editor_;
27};
28
29} // namespace
30
31void exposeBiomeRulesEditorScriptBindings(ssq::Table& table, ssq::Class& moduleClass) {
32 const editor::ScriptBind bind{table.getHandle(), kBindingSource};
33 auto biomeEditor = editor::addScriptClass<ScriptBiomeRulesEditor>(table, "BiomeRulesEditor");
34 editor::registerEditorWorkspace<ScriptBiomeRulesEditor>(biomeEditor, bind,
35 "biome editor and workspace must not be null");
36 biomeEditor.addFunc("selectLayer", [bind](ScriptBiomeRulesEditor* self, const std::string& id) {
37 return bind.checked(self, "biome editor must not be null", [&] { return self->editor().selectLayer(id); });
38 });
39 biomeEditor.addFunc("selectAsset", [bind](ScriptBiomeRulesEditor* self, const std::string& id) {
40 return bind.checked(self, "biome editor must not be null", [&] { return self->editor().selectAsset(id); });
41 });
42 biomeEditor.addFunc("setLayerDensity", [bind](ScriptBiomeRulesEditor* self, float density) {
43 return bind.checked(self, "biome editor must not be null",
44 [&] { return self->editor().setLayerDensity(static_cast<double>(density)); });
45 });
46 biomeEditor.addFunc("setLayerPriority", [bind](ScriptBiomeRulesEditor* self, int priority) {
47 return bind.checked(self, "biome editor must not be null",
48 [&] { return self->editor().setLayerPriority(priority); });
49 });
50 biomeEditor.addFunc("setAssetWeight", [bind](ScriptBiomeRulesEditor* self, float weight) {
51 return bind.checked(self, "biome editor must not be null",
52 [&] { return self->editor().setAssetWeight(static_cast<double>(weight)); });
53 });
54 biomeEditor.addFunc("createLayer",
55 [bind](ScriptBiomeRulesEditor* self, const std::string& id, const std::string& name) {
56 return bind.checked(self, "biome editor must not be null",
57 [&] { return self->editor().createLayer(id, name); });
58 });
59 biomeEditor.addFunc("deleteSelectedLayer", [bind](ScriptBiomeRulesEditor* self) {
60 return bind.checked(self, "biome editor must not be null",
61 [&] { return self->editor().deleteSelectedLayer(); });
62 });
63 biomeEditor.addFunc("createAsset",
64 [bind](ScriptBiomeRulesEditor* self, const std::string& id, const std::string& asset) {
65 return bind.checked(self, "biome editor must not be null",
66 [&] { return self->editor().createAsset(id, asset); });
67 });
68 biomeEditor.addFunc("deleteSelectedAsset", [bind](ScriptBiomeRulesEditor* self) {
69 return bind.checked(self, "biome editor must not be null",
70 [&] { return self->editor().deleteSelectedAsset(); });
71 });
72 biomeEditor.addFunc("addExclusion", [bind](ScriptBiomeRulesEditor* self, const std::string& spatialAsset) {
73 return bind.checked(self, "biome editor must not be null",
74 [&] { return self->editor().addExclusion(spatialAsset); });
75 });
76 biomeEditor.addFunc("removeExclusion", [bind](ScriptBiomeRulesEditor* self, const std::string& spatialAsset) {
77 return bind.checked(self, "biome editor must not be null",
78 [&] { return self->editor().removeExclusion(spatialAsset); });
79 });
80 biomeEditor.addFunc("setSeed", [bind](ScriptBiomeRulesEditor* self, int seed) {
81 return bind.checked(self, "biome editor must not be null",
82 [&] { return self->editor().setSeed(static_cast<std::uint32_t>(seed)); });
83 });
84 biomeEditor.addFunc("setSpacing", [bind](ScriptBiomeRulesEditor* self, float spacing) {
85 return bind.checked(self, "biome editor must not be null", [&] { return self->editor().setSpacing(spacing); });
86 });
87 editor::registerEditorHistory<ScriptBiomeRulesEditor>(biomeEditor, bind, "biome editor must not be null");
88 biomeEditor.addFunc("getPreviewRevision", [](ScriptBiomeRulesEditor* self) {
89 return self ? static_cast<int>(self->editor().previewRevision()) : 0;
90 });
91 biomeEditor.addFunc("getSeed", [](ScriptBiomeRulesEditor* self) {
92 return self ? static_cast<int>(self->editor().seed()) : 0;
93 });
94 biomeEditor.addFunc("getSpacing", [](ScriptBiomeRulesEditor* self) {
95 return self ? self->editor().spacing() : 0.0f;
96 });
97 biomeEditor.addFunc("getSelectedId", [](ScriptBiomeRulesEditor* self) {
98 return self ? self->editor().selectedId() : std::string{};
99 });
100 biomeEditor.addFunc("getSelectedType", [](ScriptBiomeRulesEditor* self) {
101 return self ? self->editor().selectedType() : std::string{};
102 });
103 biomeEditor.addFunc("getLayerCount", [](ScriptBiomeRulesEditor* self) {
104 return self ? self->editor().layerCount() : 0;
105 });
106 biomeEditor.addFunc("getLayerId", [](ScriptBiomeRulesEditor* self, int index) {
107 return self ? self->editor().layerId(index) : std::string{};
108 });
109 biomeEditor.addFunc("getLayerName", [](ScriptBiomeRulesEditor* self, int index) {
110 return self ? self->editor().layerName(index) : std::string{};
111 });
112 biomeEditor.addFunc("getLayerDensity", [](ScriptBiomeRulesEditor* self, int index) {
113 return self ? self->editor().layerDensity(index) : 0.0f;
114 });
115 biomeEditor.addFunc("getLayerPriority", [](ScriptBiomeRulesEditor* self, int index) {
116 return self ? self->editor().layerPriority(index) : 0;
117 });
118 biomeEditor.addFunc("getLayerSelected", [](ScriptBiomeRulesEditor* self, int index) {
119 return self && self->editor().isLayerSelected(index);
120 });
121 biomeEditor.addFunc("getAssetCount", [](ScriptBiomeRulesEditor* self) {
122 return self ? self->editor().assetCount() : 0;
123 });
124 biomeEditor.addFunc("getAssetId", [](ScriptBiomeRulesEditor* self, int index) {
125 return self ? self->editor().assetId(index) : std::string{};
126 });
127 biomeEditor.addFunc("getAssetRef", [](ScriptBiomeRulesEditor* self, int index) {
128 return self ? self->editor().assetRef(index) : std::string{};
129 });
130 biomeEditor.addFunc("getAssetWeight", [](ScriptBiomeRulesEditor* self, int index) {
131 return self ? self->editor().assetWeight(index) : 0.0f;
132 });
133 biomeEditor.addFunc("getAssetSelected", [](ScriptBiomeRulesEditor* self, int index) {
134 return self && self->editor().isAssetSelected(index);
135 });
136 biomeEditor.addFunc("getExclusionCount", [](ScriptBiomeRulesEditor* self) {
137 return self ? self->editor().exclusionCount() : 0;
138 });
139 biomeEditor.addFunc("getExclusionAsset", [](ScriptBiomeRulesEditor* self, int index) {
140 return self ? self->editor().exclusionAsset(index) : std::string{};
141 });
142 biomeEditor.addFunc("getPointCount", [](ScriptBiomeRulesEditor* self) {
143 return self ? self->editor().pointCount() : 0;
144 });
145 biomeEditor.addFunc("getPointX", [](ScriptBiomeRulesEditor* self, int index) {
146 return self ? self->editor().pointX(index) : 0.0f;
147 });
148 biomeEditor.addFunc("getPointZ", [](ScriptBiomeRulesEditor* self, int index) {
149 return self ? self->editor().pointZ(index) : 0.0f;
150 });
151 biomeEditor.addFunc("getPointAsset", [](ScriptBiomeRulesEditor* self, int index) {
152 return self ? self->editor().pointAsset(index) : std::string{};
153 });
154
155 editor::registerEditorOwnedCreate<ScriptBiomeRulesEditor, BiomeEditorModule>(moduleClass, bind, "biome target id must not be empty");
156}
157
158} // namespace eve::biome_editor
Squirrel adapter for the biome rules editor.
UI-neutral biome editor: workspace, PointSet preview, undo.
int priority
std::string name
std::uint32_t seed
Definition PointSet.cpp:807
std::uint32_t targetId
int spacing
uint32_t index
Editor facade binder: common script::BindContext plus history/owned-create helpers.
void exposeBiomeRulesEditorScriptBindings(ssq::Table &table, ssq::Class &moduleClass)
Expose the script-owned BiomeRulesEditor factory on BiomeEditorModule.