Extract history UI operation planning
This commit is contained in:
@@ -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/history_ui.h"
|
||||
#include "app_core/quick_ui.h"
|
||||
#include "assets/image_format.h"
|
||||
#include "assets/image_metadata.h"
|
||||
@@ -276,6 +277,13 @@ struct PlanGridOperationArgs {
|
||||
int sample_count = 32;
|
||||
};
|
||||
|
||||
struct PlanHistoryOperationArgs {
|
||||
std::string kind = "undo";
|
||||
int undo_count = 0;
|
||||
int redo_count = 0;
|
||||
int memory_bytes = 0;
|
||||
};
|
||||
|
||||
struct PlanQuickOperationArgs {
|
||||
std::string kind = "brush";
|
||||
int current_index = 0;
|
||||
@@ -635,6 +643,20 @@ const char* grid_ui_operation_name(pp::app::GridUiOperation operation) noexcept
|
||||
return "request-heightmap-pick";
|
||||
}
|
||||
|
||||
const char* history_ui_operation_name(pp::app::HistoryUiOperation operation) noexcept
|
||||
{
|
||||
switch (operation) {
|
||||
case pp::app::HistoryUiOperation::undo:
|
||||
return "undo";
|
||||
case pp::app::HistoryUiOperation::redo:
|
||||
return "redo";
|
||||
case pp::app::HistoryUiOperation::clear:
|
||||
return "clear";
|
||||
}
|
||||
|
||||
return "undo";
|
||||
}
|
||||
|
||||
const char* quick_ui_slot_kind_name(pp::app::QuickUiSlotKind kind) noexcept
|
||||
{
|
||||
switch (kind) {
|
||||
@@ -919,6 +941,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-history-operation --kind undo|redo|clear [--undo-count N] [--redo-count N] [--memory-bytes 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"
|
||||
@@ -3079,6 +3102,93 @@ int plan_grid_operation(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_history_operation_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanHistoryOperationArgs& 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 == "--undo-count" || key == "--redo-count" || key == "--memory-bytes") {
|
||||
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 == "--undo-count") {
|
||||
args.undo_count = value.value();
|
||||
} else if (key == "--redo-count") {
|
||||
args.redo_count = value.value();
|
||||
} else {
|
||||
args.memory_bytes = value.value();
|
||||
}
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Result<pp::app::HistoryUiPlan> make_history_operation_plan(
|
||||
const PlanHistoryOperationArgs& args)
|
||||
{
|
||||
if (args.kind == "undo") {
|
||||
return pp::app::plan_history_undo(args.undo_count);
|
||||
}
|
||||
if (args.kind == "redo") {
|
||||
return pp::app::plan_history_redo(args.redo_count);
|
||||
}
|
||||
if (args.kind == "clear") {
|
||||
return pp::app::plan_history_clear(args.undo_count, args.redo_count, args.memory_bytes);
|
||||
}
|
||||
|
||||
return pp::foundation::Result<pp::app::HistoryUiPlan>::failure(
|
||||
pp::foundation::Status::invalid_argument("unknown history operation kind"));
|
||||
}
|
||||
|
||||
int plan_history_operation(int argc, char** argv)
|
||||
{
|
||||
PlanHistoryOperationArgs args;
|
||||
const auto status = parse_plan_history_operation_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-history-operation", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto plan = make_history_operation_plan(args);
|
||||
if (!plan) {
|
||||
print_error("plan-history-operation", plan.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto& value = plan.value();
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-history-operation\""
|
||||
<< ",\"state\":{\"kind\":\"" << json_escape(args.kind)
|
||||
<< "\",\"undoCount\":" << args.undo_count
|
||||
<< ",\"redoCount\":" << args.redo_count
|
||||
<< ",\"memoryBytes\":" << args.memory_bytes
|
||||
<< "},\"plan\":{\"operation\":\"" << history_ui_operation_name(value.operation)
|
||||
<< "\",\"undoCount\":" << value.undo_count
|
||||
<< ",\"redoCount\":" << value.redo_count
|
||||
<< ",\"memoryBytes\":" << value.memory_bytes
|
||||
<< ",\"invokesUndo\":" << json_bool(value.invokes_undo)
|
||||
<< ",\"invokesRedo\":" << json_bool(value.invokes_redo)
|
||||
<< ",\"clearsHistory\":" << json_bool(value.clears_history)
|
||||
<< ",\"updatesMemoryLabel\":" << json_bool(value.updates_memory_label)
|
||||
<< ",\"updatesTitle\":" << json_bool(value.updates_title)
|
||||
<< ",\"noOp\":" << json_bool(value.no_op)
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_quick_operation_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -5619,6 +5729,10 @@ int main(int argc, char** argv)
|
||||
return plan_grid_operation(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-history-operation") {
|
||||
return plan_history_operation(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-quick-operation") {
|
||||
return plan_quick_operation(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user