Extract quick UI operation planning

This commit is contained in:
2026-06-03 11:01:01 +02:00
parent 73fac0f8e4
commit 8dc476d205
8 changed files with 499 additions and 11 deletions

View File

@@ -12,6 +12,7 @@
#include "app_core/document_sharing.h"
#include "app_core/document_session.h"
#include "app_core/grid_ui.h"
#include "app_core/quick_ui.h"
#include "assets/image_format.h"
#include "assets/image_metadata.h"
#include "assets/image_pixels.h"
@@ -275,6 +276,16 @@ struct PlanGridOperationArgs {
int sample_count = 32;
};
struct PlanQuickOperationArgs {
std::string kind = "brush";
int current_index = 0;
int slot_index = 0;
int brush_index = 0;
int color_index = 0;
int slot_count = 3;
bool fire_event = false;
};
struct SimulateAppSessionArgs {
bool has_canvas = true;
bool new_document = false;
@@ -624,6 +635,34 @@ const char* grid_ui_operation_name(pp::app::GridUiOperation operation) noexcept
return "request-heightmap-pick";
}
const char* quick_ui_slot_kind_name(pp::app::QuickUiSlotKind kind) noexcept
{
switch (kind) {
case pp::app::QuickUiSlotKind::brush:
return "brush";
case pp::app::QuickUiSlotKind::color:
return "color";
}
return "brush";
}
const char* quick_ui_operation_name(pp::app::QuickUiOperation operation) noexcept
{
switch (operation) {
case pp::app::QuickUiOperation::select_slot:
return "select-slot";
case pp::app::QuickUiOperation::open_slot_popup:
return "open-slot-popup";
case pp::app::QuickUiOperation::restore_state:
return "restore-state";
case pp::app::QuickUiOperation::reset_state:
return "reset-state";
}
return "select-slot";
}
const char* document_file_write_decision_name(pp::app::DocumentFileWriteDecision decision) noexcept
{
switch (decision) {
@@ -880,6 +919,7 @@ void print_help()
<< " plan-animation-operation --kind add|duplicate|remove|duration|move|goto|next|prev|onion [--frame-count N] [--total-duration N] [--current-frame N] [--selected-frame N] [--current-duration N] [--delta N] [--offset N] [--onion-size N]\n"
<< " plan-brush-operation --kind color|tip|pattern|dual|preset|settings [--path FILE] [--thumb FILE] [--r N] [--g N] [--b N] [--a N] [--no-brush]\n"
<< " plan-grid-operation --kind pick|load|reload|clear|render|commit [--path FILE] [--no-heightmap] [--no-canvas] [--float32] [--float16] [--texture-resolution N] [--samples N]\n"
<< " plan-quick-operation --kind brush|color|restore|reset [--current-index N] [--slot-index N] [--brush-index N] [--color-index N] [--slot-count N] [--fire-event]\n"
<< " plan-share-file [--path FILE]\n"
<< " plan-picked-path [--path FILE]\n"
<< " plan-display-file [--path FILE]\n"
@@ -3039,6 +3079,122 @@ int plan_grid_operation(int argc, char** argv)
return 0;
}
pp::foundation::Status parse_plan_quick_operation_args(
int argc,
char** argv,
PlanQuickOperationArgs& args)
{
for (int i = 2; i < argc; ++i) {
const std::string_view key(argv[i]);
if (key == "--kind") {
if (i + 1 >= argc) {
return pp::foundation::Status::invalid_argument("missing value for option");
}
args.kind = argv[++i];
} else if (key == "--current-index" || key == "--slot-index" || key == "--brush-index"
|| key == "--color-index" || key == "--slot-count") {
if (i + 1 >= argc) {
return pp::foundation::Status::invalid_argument("missing value for option");
}
const auto value = parse_i32_arg(argv[++i]);
if (!value) {
return value.status();
}
if (key == "--current-index") {
args.current_index = value.value();
} else if (key == "--slot-index") {
args.slot_index = value.value();
} else if (key == "--brush-index") {
args.brush_index = value.value();
} else if (key == "--color-index") {
args.color_index = value.value();
} else {
args.slot_count = value.value();
}
} else if (key == "--fire-event") {
args.fire_event = true;
} else {
return pp::foundation::Status::invalid_argument("unknown option");
}
}
return pp::foundation::Status::success();
}
pp::foundation::Result<pp::app::QuickUiPlan> make_quick_operation_plan(
const PlanQuickOperationArgs& args)
{
if (args.kind == "brush") {
return pp::app::plan_quick_slot_click(
pp::app::QuickUiSlotKind::brush,
args.current_index,
args.slot_index,
args.slot_count);
}
if (args.kind == "color") {
return pp::app::plan_quick_slot_click(
pp::app::QuickUiSlotKind::color,
args.current_index,
args.slot_index,
args.slot_count);
}
if (args.kind == "restore") {
return pp::app::plan_quick_state_restore(
args.brush_index,
args.color_index,
args.slot_count,
args.fire_event);
}
if (args.kind == "reset") {
return pp::app::plan_quick_state_reset(args.slot_count, args.fire_event);
}
return pp::foundation::Result<pp::app::QuickUiPlan>::failure(
pp::foundation::Status::invalid_argument("unknown quick operation kind"));
}
int plan_quick_operation(int argc, char** argv)
{
PlanQuickOperationArgs args;
const auto status = parse_plan_quick_operation_args(argc, argv, args);
if (!status.ok()) {
print_error("plan-quick-operation", status.message);
return 2;
}
const auto plan = make_quick_operation_plan(args);
if (!plan) {
print_error("plan-quick-operation", plan.status().message);
return 2;
}
const auto& value = plan.value();
std::cout << "{\"ok\":true,\"command\":\"plan-quick-operation\""
<< ",\"state\":{\"kind\":\"" << json_escape(args.kind)
<< "\",\"currentIndex\":" << args.current_index
<< ",\"slotIndex\":" << args.slot_index
<< ",\"brushIndex\":" << args.brush_index
<< ",\"colorIndex\":" << args.color_index
<< ",\"slotCount\":" << args.slot_count
<< ",\"fireEvent\":" << json_bool(args.fire_event)
<< "},\"plan\":{\"operation\":\"" << quick_ui_operation_name(value.operation)
<< "\",\"slotKind\":\"" << quick_ui_slot_kind_name(value.slot_kind)
<< "\",\"slotIndex\":" << value.slot_index
<< ",\"previousIndex\":" << value.previous_index
<< ",\"slotCount\":" << value.slot_count
<< ",\"fireEvent\":" << json_bool(value.fire_event)
<< ",\"updatesSelection\":" << json_bool(value.updates_selection)
<< ",\"opensBrushPopup\":" << json_bool(value.opens_brush_popup)
<< ",\"opensColorPicker\":" << json_bool(value.opens_color_picker)
<< ",\"invokesChangeCallback\":" << json_bool(value.invokes_change_callback)
<< ",\"restoresSlots\":" << json_bool(value.restores_slots)
<< ",\"resetsSlots\":" << json_bool(value.resets_slots)
<< ",\"redrawsBrushPreviews\":" << json_bool(value.redraws_brush_previews)
<< ",\"mutatesQuickState\":" << json_bool(value.mutates_quick_state)
<< "}}\n";
return 0;
}
pp::foundation::Status parse_plan_share_file_args(
int argc,
char** argv,
@@ -5463,6 +5619,10 @@ int main(int argc, char** argv)
return plan_grid_operation(argc, argv);
}
if (command == "plan-quick-operation") {
return plan_quick_operation(argc, argv);
}
if (command == "plan-share-file") {
return plan_share_file(argc, argv);
}