Route layer merge through app core
This commit is contained in:
@@ -287,6 +287,14 @@ struct PlanLayerMenuArgs {
|
||||
std::string lower_name = "Layer 0";
|
||||
};
|
||||
|
||||
struct PlanLayerMergeArgs {
|
||||
int layer_count = 2;
|
||||
int from_index = 1;
|
||||
int to_index = 0;
|
||||
int animation_duration = 1;
|
||||
bool create_history = true;
|
||||
};
|
||||
|
||||
struct PlanAnimationOperationArgs {
|
||||
std::string kind = "goto";
|
||||
int frame_count = 1;
|
||||
@@ -1779,6 +1787,7 @@ void print_help()
|
||||
<< " plan-document-resize [--current-resolution N] [--selected-resolution-index N]\n"
|
||||
<< " plan-layer-rename --old-name NAME --new-name NAME\n"
|
||||
<< " plan-layer-menu --command clear|rename|merge [--no-current-layer] [--current-index N] [--animation-duration N] [--current-name NAME] [--lower-name NAME]\n"
|
||||
<< " plan-layer-merge [--layer-count N] [--from-index N] [--to-index N] [--animation-duration N] [--no-history]\n"
|
||||
<< " plan-layer-operation --kind add|duplicate|select|reorder|remove|opacity|visibility|alpha-lock|blend-mode|highlight [--layer-count N] [--index N] [--from-index N] [--to-index N] [--source-index N] [--name NAME] [--opacity N] [--blend-mode N] [--enabled]\n"
|
||||
<< " plan-animation-operation --kind add|duplicate|remove|duration|move|select|goto|next|prev|playback|toggle-playback|onion [--frame-count N] [--total-duration N] [--current-frame N] [--selected-frame N] [--layer-index N] [--layer-id N] [--current-duration N] [--delta N] [--offset N] [--onion-size N] [--playing]\n"
|
||||
<< " plan-animation-panel-action --action goto|next|prev|playback|toggle-playback [--total-duration N] [--current-frame N] [--target-frame N] [--playing]\n"
|
||||
@@ -3959,6 +3968,75 @@ int plan_layer_menu(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_layer_merge_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanLayerMergeArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--layer-count" || key == "--from-index" || key == "--to-index"
|
||||
|| key == "--animation-duration") {
|
||||
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 == "--layer-count") {
|
||||
args.layer_count = value.value();
|
||||
} else if (key == "--from-index") {
|
||||
args.from_index = value.value();
|
||||
} else if (key == "--to-index") {
|
||||
args.to_index = value.value();
|
||||
} else {
|
||||
args.animation_duration = value.value();
|
||||
}
|
||||
} else if (key == "--no-history") {
|
||||
args.create_history = false;
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
int plan_layer_merge(int argc, char** argv)
|
||||
{
|
||||
PlanLayerMergeArgs args;
|
||||
const auto status = parse_plan_layer_merge_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-layer-merge", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto plan = pp::app::plan_document_layer_merge(
|
||||
args.layer_count,
|
||||
args.from_index,
|
||||
args.to_index,
|
||||
args.animation_duration,
|
||||
args.create_history);
|
||||
if (!plan) {
|
||||
print_error("plan-layer-merge", plan.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto& value = plan.value();
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-layer-merge\""
|
||||
<< ",\"state\":{\"layerCount\":" << args.layer_count
|
||||
<< ",\"fromIndex\":" << args.from_index
|
||||
<< ",\"toIndex\":" << args.to_index
|
||||
<< ",\"animationDuration\":" << args.animation_duration
|
||||
<< ",\"createHistory\":" << json_bool(args.create_history)
|
||||
<< "},\"plan\":{\"fromIndex\":" << value.from_index
|
||||
<< ",\"toIndex\":" << value.to_index
|
||||
<< ",\"createHistory\":" << json_bool(value.create_history)
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_layer_operation_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -8215,6 +8293,10 @@ int main(int argc, char** argv)
|
||||
return plan_layer_menu(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-layer-merge") {
|
||||
return plan_layer_merge(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-layer-operation") {
|
||||
return plan_layer_operation(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user