15 descriptor.ownerModule =
"procgen_editing.road";
24 if (
operation.code() == EditorStatus::NoOp)
32 auto registered = add(
33 "road.node.add.v1",
"Add road node",
36 float x = 0.f,
y = 0.f,
z = 0.f,
radius = 6.f;
37 if (!road || !readNumber(
request.payload,
"x",
x) || !readNumber(
request.payload,
"y",
y) ||
38 !readNumber(
request.payload,
"z",
z) ||
39 (field(
request.payload,
"junctionRadius") && !readNumber(
request.payload,
"junctionRadius",
radius)))
40 return commandError<editing::CommandPlan>(
"editor.road.command.node-add",
41 "Road node add requires finite x, y and z");
42 return plan(road->makeAddNode(
x,
y,
z,
radius));
44 if (!registered.ok())
return registered;
46 registered = add(
"road.node.move.v1",
"Move road node",
50 float x = 0.f,
y = 0.f,
z = 0.f;
51 if (!road || !readId(
request.payload,
"id",
id) || !readNumber(
request.payload,
"x",
x) ||
52 !readNumber(
request.payload,
"y",
y) || !readNumber(
request.payload,
"z",
z))
53 return commandError<editing::CommandPlan>(
54 "editor.road.command.node-move",
"Road node move requires id and finite x, y and z");
55 return plan(road->makeMoveNode(
id,
x,
y,
z));
57 if (!registered.ok())
return registered;
60 add(
"road.node.connection.set.v1",
"Set custom road connection",
65 const auto* encoded = field(
request.payload,
"connection");
66 if (!road || !readId(
request.payload,
"id",
id) || !encoded || !decodeConnection(*encoded, connection))
67 return commandError<editing::CommandPlan>(
"editor.road.command.connection",
68 "custom connection requires id and valid asset data");
69 return plan(road->makeSetNodeConnection(
id, std::move(connection)));
71 if (!registered.ok())
return registered;
74 "road.node.radius.set.v1",
"Set road junction radius",
79 if (!road || !readId(
request.payload,
"id",
id) || !readNumber(
request.payload,
"junctionRadius",
radius))
80 return commandError<editing::CommandPlan>(
"editor.road.command.node-radius",
81 "Road node radius requires id and radius");
82 return plan(road->makeSetNodeJunctionRadius(
id,
radius));
84 if (!registered.ok())
return registered;
87 "road.node.junction-control.set.v1",
"Set road junction control",
92 if (!road || !readId(
request.payload,
"id",
id) ||
94 return commandError<editing::CommandPlan>(
95 "editor.road.command.node-control",
96 "Road junction control requires id and junctionControl in [0,3]");
99 if (!registered.ok())
return registered;
102 add(
"road.node.merge.v1",
"Merge nearby road nodes",
105 std::uint32_t keepNodeId = 0, removeNodeId = 0;
106 float maxDistance = 1.f;
107 if (!road || !readId(
request.payload,
"keepNodeId", keepNodeId) ||
108 !readId(
request.payload,
"removeNodeId", removeNodeId) ||
109 (field(
request.payload,
"maxDistance") && !readNumber(
request.payload,
"maxDistance", maxDistance)))
110 return commandError<editing::CommandPlan>(
"editor.road.command.node-merge",
111 "Road node merge requires two node ids");
112 return plan(road->makeMergeNodes(keepNodeId, removeNodeId, maxDistance));
114 if (!registered.ok())
return registered;
117 add(
"road.node.merge-and-connect.v1",
"Merge road nodes and connect turns",
120 std::uint32_t keepNodeId = 0, removeNodeId = 0;
121 float maxDistance = 1.f;
122 if (!road || !readId(
request.payload,
"keepNodeId", keepNodeId) ||
123 !readId(
request.payload,
"removeNodeId", removeNodeId) ||
124 (field(
request.payload,
"maxDistance") && !readNumber(
request.payload,
"maxDistance", maxDistance)))
125 return commandError<editing::CommandPlan>(
"editor.road.command.node-merge-connect",
126 "Road node merge and connect requires two node ids");
127 return plan(road->makeMergeNodesAndConnect(keepNodeId, removeNodeId, maxDistance));
129 if (!registered.ok())
return registered;
131 registered = add(
"road.node.remove.v1",
"Remove road node",
134 std::uint32_t
id = 0;
135 if (!road || !readId(
request.payload,
"id",
id))
136 return commandError<editing::CommandPlan>(
"editor.road.command.node-remove",
137 "Road node remove requires id");
138 return plan(road->makeRemoveNode(
id));
140 if (!registered.ok())
return registered;
142 registered = add(
"road.node.connect-all-turns.v1",
"Connect all road turns",
145 std::uint32_t
id = 0;
146 if (!road || !readId(
request.payload,
"id",
id))
147 return commandError<editing::CommandPlan>(
"editor.road.command.connect-turns",
148 "Connect all turns requires a node id");
149 return plan(road->makeConnectAllTurns(
id));
151 if (!registered.ok())
return registered;
154 add(
"road.edge.add.v1",
"Add road edge",
157 std::uint32_t
from = 0,
to = 0, ignored = 0;
159 std::vector<procgen::road::RoadControlPoint>
points;
161 if (
const auto* encoded = field(
request.payload,
"points")) pointPayload[
"points"] = *encoded;
162 if (
const auto* profiles = field(
request.payload,
"pointProfiles"))
163 pointPayload[
"pointProfiles"] = *profiles;
166 (field(
request.payload,
"lanesForward") &&
168 (field(
request.payload,
"lanesBackward") &&
170 return commandError<editing::CommandPlan>(
171 "editor.road.command.edge-add",
"Road edge add requires endpoints and at least two points");
174 if (!registered.ok())
return registered;
177 add(
"road.edge.add-and-connect.v1",
"Add road edge and connect endpoints",
180 std::uint32_t
from = 0,
to = 0, ignored = 0;
182 std::vector<procgen::road::RoadControlPoint>
points;
184 if (
const auto* encoded = field(
request.payload,
"points")) pointPayload[
"points"] = *encoded;
185 if (
const auto* profiles = field(
request.payload,
"pointProfiles"))
186 pointPayload[
"pointProfiles"] = *profiles;
189 (field(
request.payload,
"lanesForward") &&
191 (field(
request.payload,
"lanesBackward") &&
193 return commandError<editing::CommandPlan>(
194 "editor.road.command.edge-add-connect",
195 "Road edge add and connect requires endpoints and at least two points");
197 if (
const auto* encodedStyle = field(
request.payload,
"style")) {
200 return commandError<editing::CommandPlan>(
"editor.road.command.edge-add-connect-style",
201 "Road edge style is invalid");
203 stylePayload[
"id"] = std::int64_t{1};
204 if (!decodeStyle(
EditorValue(std::move(stylePayload)), ignored, style))
205 return commandError<editing::CommandPlan>(
"editor.road.command.edge-add-connect-style",
206 "Road edge style is invalid");
208 return plan(road->makeAddEdgeAndConnect(
from,
to, std::move(
points),
forward, backward, style));
210 if (!registered.ok())
return registered;
213 "road.edge.split.v1",
"Split road edge",
216 std::uint32_t
id = 0;
219 if (!road || !readId(
request.payload,
"id",
id) ||
221 (field(
request.payload,
"junctionRadius") && !readNumber(
request.payload,
"junctionRadius",
radius)))
222 return commandError<editing::CommandPlan>(
223 "editor.road.command.edge-split",
"Road split requires edge id and interior control-point index");
224 return plan(road->makeSplitEdge(
id,
static_cast<std::size_t
>(
index),
radius));
226 if (!registered.ok())
return registered;
229 "road.edge.split-at-position.v1",
"Split road edge at world position",
232 std::uint32_t
id = 0;
234 float maxDistance = 2.f,
radius = 6.f;
237 (field(
request.payload,
"maxDistance") && !readNumber(
request.payload,
"maxDistance", maxDistance)) ||
238 (field(
request.payload,
"junctionRadius") && !readNumber(
request.payload,
"junctionRadius",
radius)))
239 return commandError<editing::CommandPlan>(
240 "editor.road.command.edge-split-position",
241 "Road position split requires edge id and a finite world position");
242 return plan(road->makeSplitEdgeAtPosition(
id,
position, maxDistance,
radius));
244 if (!registered.ok())
return registered;
247 "road.node.connect-at-position.v1",
"Connect road node at world position",
252 float maxDistance = 2.f,
radius = 6.f;
257 (field(
request.payload,
"maxDistance") && !readNumber(
request.payload,
"maxDistance", maxDistance)) ||
258 (field(
request.payload,
"junctionRadius") && !readNumber(
request.payload,
"junctionRadius",
radius)) ||
259 (field(
request.payload,
"lanesForward") &&
261 (field(
request.payload,
"lanesBackward") &&
263 return commandError<editing::CommandPlan>(
264 "editor.road.command.node-connect-position",
265 "Road branch connection requires source node, edge and world position");
269 if (!registered.ok())
return registered;
272 "road.edge.connect-intersection.v1",
"Connect crossing road edges",
275 std::uint32_t firstEdgeId = 0, secondEdgeId = 0;
276 float maximumHeightDelta = 0.5f,
radius = 6.f;
277 if (!road || !readId(
request.payload,
"firstEdgeId", firstEdgeId) ||
278 !readId(
request.payload,
"secondEdgeId", secondEdgeId) ||
279 (field(
request.payload,
"maximumHeightDelta") &&
280 !readNumber(
request.payload,
"maximumHeightDelta", maximumHeightDelta)) ||
281 (field(
request.payload,
"junctionRadius") && !readNumber(
request.payload,
"junctionRadius",
radius)))
282 return commandError<editing::CommandPlan>(
283 "editor.road.command.edge-intersection",
284 "Road intersection requires two edge ids and finite tolerances");
285 return plan(road->makeConnectEdgeIntersection(firstEdgeId, secondEdgeId, maximumHeightDelta,
radius));
287 if (!registered.ok())
return registered;
289 registered = add(
"road.edge.lanes.set.v1",
"Set road edge lanes",
292 std::uint32_t
id = 0;
294 if (!road || !readId(
request.payload,
"id",
id) ||
297 return commandError<editing::CommandPlan>(
"editor.road.command.edge-lanes",
298 "Road lane edit requires id and lane counts");
299 return plan(road->makeSetEdgeLaneCounts(
id,
forward, backward));
301 if (!registered.ok())
return registered;
303 registered = add(
"road.edge.style.set.v1",
"Set road edge style",
306 std::uint32_t edgeId = 0;
308 if (!road || !decodeStyle(
request.payload, edgeId, style))
309 return commandError<editing::CommandPlan>(
310 "editor.road.command.edge-style",
"Road edge style requires a complete style payload");
311 return plan(road->makeSetEdgeStyle(edgeId, style));
313 if (!registered.ok())
return registered;
315 registered = add(
"road.edge.control-points.set.v1",
"Set road edge control points",
318 std::uint32_t edgeId = 0;
319 std::vector<procgen::road::RoadControlPoint>
points;
321 return commandError<editing::CommandPlan>(
322 "editor.road.command.edge-control-points",
323 "Road edge control points require id and at least two finite points");
324 return plan(road->makeSetEdgeControlPoints(edgeId, std::move(
points)));
326 if (!registered.ok())
return registered;
328 registered = add(
"road.edge.reverse.v1",
"Reverse road edge",
331 std::uint32_t edgeId = 0;
332 if (!road || !readId(
request.payload,
"id", edgeId))
333 return commandError<editing::CommandPlan>(
"editor.road.command.edge-reverse",
334 "Road edge reverse requires an id");
335 return plan(road->makeReverseEdge(edgeId));
337 if (!registered.ok())
return registered;
339 registered = add(
"road.edge.reconnect-endpoint.v1",
"Reconnect road edge endpoint",
342 std::uint32_t edgeId = 0,
nodeId = 0;
343 const auto* endpointValue = field(
request.payload,
"fromEndpoint");
344 const auto* fromEndpoint = endpointValue ? endpointValue->getIf<
bool>() :
nullptr;
345 if (!road || !fromEndpoint || !readId(
request.payload,
"id", edgeId) ||
347 return commandError<editing::CommandPlan>(
348 "editor.road.command.edge-reconnect",
349 "Road edge reconnect requires id, fromEndpoint, and nodeId");
350 return plan(road->makeReconnectEdgeEndpoint(edgeId, *fromEndpoint,
nodeId));
352 if (!registered.ok())
return registered;
354 registered = add(
"road.edge.reconnect-endpoint-and-connect.v1",
"Reconnect and connect road edge endpoint",
357 std::uint32_t edgeId = 0,
nodeId = 0;
358 const auto* endpointValue = field(
request.payload,
"fromEndpoint");
359 const auto* fromEndpoint = endpointValue ? endpointValue->getIf<
bool>() :
nullptr;
360 if (!road || !fromEndpoint || !readId(
request.payload,
"id", edgeId) ||
362 return commandError<editing::CommandPlan>(
363 "editor.road.command.edge-reconnect-connect",
364 "Road edge reconnect-and-connect requires id, fromEndpoint, and nodeId");
365 return plan(road->makeReconnectEdgeEndpointAndConnect(edgeId, *fromEndpoint,
nodeId));
367 if (!registered.ok())
return registered;
370 add(
"road.edge.snap-endpoint.v1",
"Snap road edge endpoint to nearest node",
373 std::uint32_t edgeId = 0;
374 float maxDistance = 0.f;
375 bool connectTurns =
true;
376 const auto* endpointValue = field(
request.payload,
"fromEndpoint");
377 const auto* fromEndpoint = endpointValue ? endpointValue->getIf<
bool>() :
nullptr;
378 const auto* connectValue = field(
request.payload,
"connectTurns");
379 const auto* connect = connectValue ? connectValue->getIf<
bool>() :
nullptr;
380 if (!road || !fromEndpoint || (connectValue && !connect) || !readId(
request.payload,
"id", edgeId) ||
381 !readNumber(
request.payload,
"maxDistance", maxDistance))
382 return commandError<editing::CommandPlan>(
383 "editor.road.command.edge-snap",
384 "Road edge snap requires id, fromEndpoint, and a finite maxDistance");
385 if (connect) connectTurns = *connect;
386 return plan(road->makeSnapEdgeEndpoint(edgeId, *fromEndpoint, maxDistance, connectTurns));
388 if (!registered.ok())
return registered;
390 registered = add(
"road.edge.detach-endpoint.v1",
"Detach road edge endpoint",
393 std::uint32_t edgeId = 0;
394 const auto* endpointValue = field(
request.payload,
"fromEndpoint");
395 const auto* fromEndpoint = endpointValue ? endpointValue->getIf<
bool>() :
nullptr;
396 if (!road || !fromEndpoint || !readId(
request.payload,
"id", edgeId))
397 return commandError<editing::CommandPlan>(
"editor.road.command.edge-detach",
398 "Road edge detach requires id and fromEndpoint");
399 return plan(road->makeDetachEdgeEndpoint(edgeId, *fromEndpoint));
401 if (!registered.ok())
return registered;
403 registered = add(
"road.edge.remove.v1",
"Remove road edge",
406 std::uint32_t
id = 0;
407 if (!road || !readId(
request.payload,
"id",
id))
408 return commandError<editing::CommandPlan>(
"editor.road.command.edge-remove",
409 "Road edge remove requires id");
410 return plan(road->makeRemoveEdge(
id));
412 if (!registered.ok())
return registered;
419 return commandError<editing::CommandPlan>(
"editor.road.command.lane-link",
420 "Road lane-link command requires a complete directed link");
421 return plan(addLink ? road->makeAddLaneLink(
link) : road->makeRemoveLaneLink(
link));
423 registered = add(
"road.lane-link.add.v1",
"Add road lane link",
427 if (!registered.ok())
return registered;
428 registered = add(
"road.lane-link.remove.v1",
"Remove road lane link",
432 if (!registered.ok())
return registered;
438 return commandError<editing::CommandPlan>(
"editor.road.command.lane-link-block",
439 "Road lane-link block command requires a complete directed link");
440 return plan(block ? road->makeBlockLaneLink(
link) : road->makeUnblockLaneLink(
link));
442 registered = add(
"road.lane-link.block.v1",
"Block road lane link",
446 if (!registered.ok())
return registered;
447 return add(
"road.lane-link.unblock.v1",
"Unblock road lane link",