Add animation panel action planner
This commit is contained in:
@@ -297,6 +297,14 @@ struct PlanAnimationOperationArgs {
|
||||
bool playback_active = false;
|
||||
};
|
||||
|
||||
struct PlanAnimationPanelActionArgs {
|
||||
std::string action = "next";
|
||||
int total_duration = 1;
|
||||
int current_frame = 0;
|
||||
int target_frame = 0;
|
||||
bool playback_active = false;
|
||||
};
|
||||
|
||||
struct PlanBrushOperationArgs {
|
||||
std::string kind = "settings";
|
||||
std::string path;
|
||||
@@ -1003,6 +1011,52 @@ const char* document_animation_operation_name(pp::app::DocumentAnimationOperatio
|
||||
return "goto-frame";
|
||||
}
|
||||
|
||||
const char* document_animation_panel_action_name(pp::app::DocumentAnimationPanelAction action) noexcept
|
||||
{
|
||||
switch (action) {
|
||||
case pp::app::DocumentAnimationPanelAction::goto_frame:
|
||||
return "goto-frame";
|
||||
case pp::app::DocumentAnimationPanelAction::next_frame:
|
||||
return "next-frame";
|
||||
case pp::app::DocumentAnimationPanelAction::previous_frame:
|
||||
return "previous-frame";
|
||||
case pp::app::DocumentAnimationPanelAction::playback_step:
|
||||
return "playback-step";
|
||||
case pp::app::DocumentAnimationPanelAction::toggle_playback:
|
||||
return "toggle-playback";
|
||||
}
|
||||
|
||||
return "goto-frame";
|
||||
}
|
||||
|
||||
pp::foundation::Result<pp::app::DocumentAnimationPanelAction> parse_document_animation_panel_action(
|
||||
std::string_view action)
|
||||
{
|
||||
if (action == "goto" || action == "goto-frame") {
|
||||
return pp::foundation::Result<pp::app::DocumentAnimationPanelAction>::success(
|
||||
pp::app::DocumentAnimationPanelAction::goto_frame);
|
||||
}
|
||||
if (action == "next" || action == "next-frame") {
|
||||
return pp::foundation::Result<pp::app::DocumentAnimationPanelAction>::success(
|
||||
pp::app::DocumentAnimationPanelAction::next_frame);
|
||||
}
|
||||
if (action == "prev" || action == "previous" || action == "previous-frame") {
|
||||
return pp::foundation::Result<pp::app::DocumentAnimationPanelAction>::success(
|
||||
pp::app::DocumentAnimationPanelAction::previous_frame);
|
||||
}
|
||||
if (action == "playback" || action == "playback-step") {
|
||||
return pp::foundation::Result<pp::app::DocumentAnimationPanelAction>::success(
|
||||
pp::app::DocumentAnimationPanelAction::playback_step);
|
||||
}
|
||||
if (action == "toggle-playback" || action == "play-toggle") {
|
||||
return pp::foundation::Result<pp::app::DocumentAnimationPanelAction>::success(
|
||||
pp::app::DocumentAnimationPanelAction::toggle_playback);
|
||||
}
|
||||
|
||||
return pp::foundation::Result<pp::app::DocumentAnimationPanelAction>::failure(
|
||||
pp::foundation::Status::invalid_argument("unknown animation panel action"));
|
||||
}
|
||||
|
||||
const char* brush_ui_texture_slot_name(pp::app::BrushUiTextureSlot slot) noexcept
|
||||
{
|
||||
switch (slot) {
|
||||
@@ -1557,6 +1611,7 @@ void print_help()
|
||||
<< " 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-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"
|
||||
<< " 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-canvas-tool --kind draw|erase|line|camera|grid|copy|cut|fill|mask-free|mask-line|bucket|pick|touch-lock [--current-mode-draw]\n"
|
||||
<< " plan-canvas-tool-state [--mode draw|erase|line|camera|grid|copy|cut|fill|mask-free|mask-line|bucket] [--picking] [--touch-lock]\n"
|
||||
@@ -4010,6 +4065,101 @@ int plan_animation_operation(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_animation_panel_action_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanAnimationPanelActionArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--action") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
args.action = argv[++i];
|
||||
} else if (key == "--playing") {
|
||||
args.playback_active = true;
|
||||
} else if (key == "--total-duration" || key == "--current-frame" || key == "--target-frame") {
|
||||
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 == "--total-duration") {
|
||||
args.total_duration = value.value();
|
||||
} else if (key == "--current-frame") {
|
||||
args.current_frame = value.value();
|
||||
} else {
|
||||
args.target_frame = value.value();
|
||||
}
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
int plan_animation_panel_action(int argc, char** argv)
|
||||
{
|
||||
PlanAnimationPanelActionArgs args;
|
||||
const auto status = parse_plan_animation_panel_action_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-animation-panel-action", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto action = parse_document_animation_panel_action(args.action);
|
||||
if (!action) {
|
||||
print_error("plan-animation-panel-action", action.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const pp::app::DocumentAnimationPanelState state {
|
||||
.total_duration = args.total_duration,
|
||||
.current_frame = args.current_frame,
|
||||
.playback_active = args.playback_active,
|
||||
};
|
||||
const auto plan = pp::app::plan_animation_panel_action(action.value(), state, args.target_frame);
|
||||
if (!plan) {
|
||||
print_error("plan-animation-panel-action", plan.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto& value = plan.value();
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-animation-panel-action\""
|
||||
<< ",\"state\":{\"action\":\"" << json_escape(args.action)
|
||||
<< "\",\"totalDuration\":" << args.total_duration
|
||||
<< ",\"currentFrame\":" << args.current_frame
|
||||
<< ",\"targetFrame\":" << args.target_frame
|
||||
<< ",\"playbackActive\":" << json_bool(args.playback_active)
|
||||
<< "},\"plan\":{\"action\":\"" << document_animation_panel_action_name(action.value())
|
||||
<< "\",\"operation\":\"" << document_animation_operation_name(value.operation)
|
||||
<< "\",\"frameCount\":" << value.frame_count
|
||||
<< ",\"currentFrame\":" << value.current_frame
|
||||
<< ",\"selectedFrame\":" << value.selected_frame
|
||||
<< ",\"targetFrame\":" << value.target_frame
|
||||
<< ",\"layerIndex\":" << value.layer_index
|
||||
<< ",\"layerId\":" << value.layer_id
|
||||
<< ",\"frameDuration\":" << value.frame_duration
|
||||
<< ",\"durationDelta\":" << value.duration_delta
|
||||
<< ",\"moveOffset\":" << value.move_offset
|
||||
<< ",\"onionSize\":" << value.onion_size
|
||||
<< ",\"playbackIdleMs\":" << value.playback_idle_ms
|
||||
<< ",\"requiresSelectedFrame\":" << json_bool(value.requires_selected_frame)
|
||||
<< ",\"mutatesDocument\":" << json_bool(value.mutates_document)
|
||||
<< ",\"reloadsAnimationLayers\":" << json_bool(value.reloads_animation_layers)
|
||||
<< ",\"updatesCanvasAnimation\":" << json_bool(value.updates_canvas_animation)
|
||||
<< ",\"marksUnsaved\":" << json_bool(value.marks_unsaved)
|
||||
<< ",\"playbackWasActive\":" << json_bool(value.playback_was_active)
|
||||
<< ",\"playbackActive\":" << json_bool(value.playback_active)
|
||||
<< ",\"resetsPlaybackTimer\":" << json_bool(value.resets_playback_timer)
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_brush_operation_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -7247,6 +7397,10 @@ int main(int argc, char** argv)
|
||||
return plan_animation_operation(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-animation-panel-action") {
|
||||
return plan_animation_panel_action(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-brush-operation") {
|
||||
return plan_brush_operation(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user