12const editing::Value*
field(
const editing::Value&
value,
const char*
key) {
14 if (!
object)
return nullptr;
15 const auto found =
object->find(
key);
16 return found ==
object->end() ? nullptr : &
found->second;
19const std::string* stringField(
const editing::Value&
value,
const char*
key) {
21 return entry ? entry->getIf<std::string>() : nullptr;
27 if (
const auto* integer = entry->getIf<int64_t>()) {
28 output =
static_cast<int>(*integer);
31 if (
const auto* real = entry->getIf<
double>()) {
32 output =
static_cast<int>(*real);
41 const auto* flag = entry->getIf<
bool>();
42 if (!flag)
return false;
47editing::PropertyDescriptor stringProp(
const char*
path,
const char*
title) {
55editing::PropertyDescriptor intProp(
const char*
path,
const char*
title) {
63editing::PropertyDescriptor boolProp(
const char*
path,
const char*
title) {
71editing::EditingCommandDescriptor makeDescriptor(
const char*
id,
const char* displayName,
72 editing::PropertySchema schema) {
79 descriptor.targetKinds = {
"voxel-catalog",
"voxel-model"};
86VoxelCatalogTarget* asCatalog(editing::IEditableTarget&
target) {
87 return dynamic_cast<VoxelCatalogTarget*
>(&
target);
90editing::SelectionSnapshot selectionFor(
const VoxelCatalogTarget&
target,
const std::string& item) {
91 editing::SelectionSnapshot selection;
92 selection.channel =
"voxel-catalog";
93 editing::SelectionItem
row;
98 selection.items.push_back(row);
99 selection.primary =
row;
103editing::Result<editing::CommandPlan> planFrom(editing::Result<editing::DomainOperation>
operation,
104 editing::Value summary) {
107 "Voxel catalog rejected the planned edit");
108 editing::CommandPlan plan;
109 plan.operations.push_back(std::move(
operation).takeValue());
110 plan.summary = std::move(summary);
111 return eve::editing::applied<editing::CommandPlan>(std::move(plan));
117 std::vector<editing::EditingCommandDescriptor> descriptors;
120 schema.
typeId =
"voxel.model.create.v1";
121 schema.
properties.push_back(stringProp(
"id",
"Id"));
122 schema.
properties.push_back(stringProp(
"name",
"Name"));
123 schema.
properties.push_back(intProp(
"sizeX",
"Size X"));
124 schema.
properties.push_back(intProp(
"sizeY",
"Size Y"));
125 schema.
properties.push_back(intProp(
"sizeZ",
"Size Z"));
126 descriptors.push_back(makeDescriptor(
"voxel.model.create.v1",
"Create voxel model", std::move(schema)));
130 schema.
typeId =
"voxel.model.delete.v1";
131 schema.
properties.push_back(stringProp(
"id",
"Id"));
132 descriptors.push_back(makeDescriptor(
"voxel.model.delete.v1",
"Delete voxel model", std::move(schema)));
136 schema.
typeId =
"voxel.model.voxel.set.v1";
137 schema.
properties.push_back(stringProp(
"item",
"Item"));
138 schema.
properties.push_back(intProp(
"x",
"X"));
139 schema.
properties.push_back(intProp(
"y",
"Y"));
140 schema.
properties.push_back(intProp(
"z",
"Z"));
141 schema.
properties.push_back(boolProp(
"occupied",
"Occupied"));
142 descriptors.push_back(makeDescriptor(
"voxel.model.voxel.set.v1",
"Set voxel occupancy", std::move(schema)));
146 schema.
typeId =
"voxel.property.set.v1";
147 schema.
properties.push_back(stringProp(
"item",
"Item"));
148 schema.
properties.push_back(stringProp(
"path",
"Path"));
152 descriptors.push_back(makeDescriptor(
"voxel.property.set.v1",
"Set voxel catalog property", std::move(schema)));
159 auto registered =
registry.registerPlannedCommand(
161 auto* catalog = asCatalog(
target);
162 const std::string*
id = stringField(
request.payload,
"id");
163 if (!catalog || !
id ||
id->empty())
164 return eve::editing::failed<editing::CommandPlan>(editing::Status::Rejected,
166 "Voxel model create requires id");
167 const std::string*
name = stringField(
request.payload,
"name");
171 if (!readInt(
request.payload,
"sizeX",
model.sizeX,
false) ||
172 !readInt(
request.payload,
"sizeY",
model.sizeY,
false) ||
174 return eve::editing::failed<editing::CommandPlan>(editing::Status::Rejected,
176 "Voxel model size must be integers");
179 if (!registered.ok())
return registered;
181 registered =
registry.registerPlannedCommand(
183 auto* catalog = asCatalog(
target);
184 const std::string*
id = stringField(
request.payload,
"id");
185 if (!catalog || !
id ||
id->empty())
186 return eve::editing::failed<editing::CommandPlan>(editing::Status::Rejected,
188 "Voxel model delete requires id");
191 if (!registered.ok())
return registered;
193 registered =
registry.registerPlannedCommand(
194 descriptors[2], [](editing::IEditableTarget&
target,
const editing::CommandRequest&
request) {
195 auto* catalog = asCatalog(
target);
196 const std::string* item = stringField(
request.payload,
"item");
197 int x = 0,
y = 0,
z = 0;
199 if (!catalog || !item || item->empty() || !readInt(
request.payload,
"x",
x,
true) ||
200 !readInt(
request.payload,
"y",
y,
true) || !readInt(
request.payload,
"z",
z,
true) ||
202 return eve::editing::failed<editing::CommandPlan>(
203 editing::Status::Rejected, editing::RuleId(
"voxel.editing.voxel-payload"),
204 "Voxel occupancy requires item, x, y, z and occupied");
205 return planFrom(catalog->makeSetVoxel(editing::ObjectId(*item),
x,
y,
z,
occupied),
206 editing::Value::Object{{
"item", *item}});
208 if (!registered.ok())
return registered;
210 return registry.registerPlannedCommand(
211 descriptors[3], [](editing::IEditableTarget&
target,
const editing::CommandRequest&
request) {
212 auto* catalog = asCatalog(
target);
213 auto*
properties =
static_cast<editing::IPropertyProvider*
>(
214 target.queryCapability(VoxelCatalogTarget::propertyCapabilityId()));
215 const std::string* item = stringField(
request.payload,
"item");
216 const std::string*
path = stringField(
request.payload,
"path");
219 return eve::editing::failed<editing::CommandPlan>(editing::Status::Rejected,
220 editing::RuleId(
"voxel.editing.property-payload"),
221 "Voxel property requires item, path and value");
222 return planFrom(
properties->makeSet(selectionFor(*catalog, *item), editing::PropertyPath(*
path), *
value,
223 editing::PropertySetMode::Absolute),
224 editing::Value::Object{{
"item", *item}, {
"path", *
path}});
ActionParameterOperation operation
const GltfImportRequest & request
std::map< std::string, PropertyRule > properties
const eve::script::BindingContractRegistry & registry
MagicaVoxel-style sculpted models: bounded occupancy grids and hull sockets.
Move-only operation result carrying either a value or Status.
UUID-backed identifier adapter for legacy textual boundaries.
IEditableTarget public API.
Lower-layer registration boundary implemented by an editor or runtime editing host.
std::map< std::string, Value > Object
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
StrongId< TargetIdTag > TargetId
StrongId< ObjectIdTag > ObjectId
StrongId< StableIdTag > StableId
StrongId< RuleIdTag > RuleId
StrongId< CommandIdTag > CommandId
Result< bool > readBool(const Value::Object &object, std::string_view name)
Reads a required boolean.
WidgetDesc row(std::vector< WidgetDesc > children, std::string id)
Horizontal elastic layout row.
editing::Result< void > registerEditingCommands(editing::IEditingCommandRegistry ®istry)
Register voxel-catalog planned commands with a generic editing host.
std::vector< editing::EditingCommandDescriptor > voxelEditingCommandDescriptors()
Metadata for every Voxel planned command (shared with EditorPackage).
CommandRequest public API.
PropertyDescriptor public API.
EVENGINE_API_PLATFORM public API.
std::vector< PropertyDescriptor > properties
One MagicaVoxel-style object: a bounded occupancy grid.