Route brush preset list planning
This commit is contained in:
@@ -368,6 +368,14 @@ struct PlanBrushTextureListArgs {
|
||||
bool current_is_user_texture = false;
|
||||
};
|
||||
|
||||
struct PlanBrushPresetListArgs {
|
||||
std::string kind = "select";
|
||||
int item_count = 1;
|
||||
int current_index = 0;
|
||||
int offset = 1;
|
||||
bool has_current_brush = true;
|
||||
};
|
||||
|
||||
struct PlanBrushStrokeControlArgs {
|
||||
std::string kind = "float";
|
||||
std::string setting = "tip-size";
|
||||
@@ -1199,6 +1207,24 @@ const char* brush_texture_list_operation_name(pp::app::BrushTextureListOperation
|
||||
return "add-texture";
|
||||
}
|
||||
|
||||
const char* brush_preset_list_operation_name(pp::app::BrushPresetListOperation operation) noexcept
|
||||
{
|
||||
switch (operation) {
|
||||
case pp::app::BrushPresetListOperation::add_current_brush:
|
||||
return "add-current-brush";
|
||||
case pp::app::BrushPresetListOperation::remove_preset:
|
||||
return "remove-preset";
|
||||
case pp::app::BrushPresetListOperation::move_preset:
|
||||
return "move-preset";
|
||||
case pp::app::BrushPresetListOperation::select_preset:
|
||||
return "select-preset";
|
||||
case pp::app::BrushPresetListOperation::clear_presets:
|
||||
return "clear-presets";
|
||||
}
|
||||
|
||||
return "select-preset";
|
||||
}
|
||||
|
||||
const char* brush_stroke_control_operation_name(pp::app::BrushStrokeControlOperation operation) noexcept
|
||||
{
|
||||
switch (operation) {
|
||||
@@ -1897,6 +1923,7 @@ void print_help()
|
||||
<< " 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-brush-texture-list --kind add|remove|move [--dir NAME] [--data-path DIR] [--source FILE] [--item-count N] [--current-index N] [--offset N] [--user-texture]\n"
|
||||
<< " plan-brush-preset-list --kind add|remove|move|up|down|select|clear [--item-count N] [--current-index N] [--offset N] [--no-current-brush]\n"
|
||||
<< " plan-brush-stroke-control --kind float|bool|blend|tip-aspect-reset|default-reset [--setting NAME] [--value N] [--enabled|--disabled] [--blend-mode N]\n"
|
||||
<< " plan-paint-feedback [--width N] [--height N] [--simple|--complex] [--framebuffer-fetch] [--texture-copy] [--blit] [--explicit-transitions] [--render-only] [--depth]\n"
|
||||
<< " plan-stroke-composite [--width N] [--height N] [--layer-blend N] [--stroke-blend N] [--dual-blend] [--pattern-blend] [--framebuffer-fetch] [--texture-copy] [--blit] [--explicit-transitions] [--render-only] [--depth]\n"
|
||||
@@ -5032,6 +5059,104 @@ int plan_brush_texture_list(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_brush_preset_list_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanBrushPresetListArgs& 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 == "--item-count" || key == "--current-index" || key == "--offset") {
|
||||
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 == "--item-count") {
|
||||
args.item_count = value.value();
|
||||
} else if (key == "--current-index") {
|
||||
args.current_index = value.value();
|
||||
} else {
|
||||
args.offset = value.value();
|
||||
}
|
||||
} else if (key == "--no-current-brush") {
|
||||
args.has_current_brush = false;
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Result<pp::app::BrushPresetListPlan> make_brush_preset_list_plan(
|
||||
const PlanBrushPresetListArgs& args)
|
||||
{
|
||||
if (args.kind == "add") {
|
||||
return pp::app::plan_brush_preset_list_add(args.item_count, args.has_current_brush);
|
||||
}
|
||||
if (args.kind == "remove") {
|
||||
return pp::app::plan_brush_preset_list_remove(args.item_count, args.current_index);
|
||||
}
|
||||
if (args.kind == "move" || args.kind == "up" || args.kind == "down") {
|
||||
const int offset = args.kind == "up" ? -1 : (args.kind == "down" ? 1 : args.offset);
|
||||
return pp::app::plan_brush_preset_list_move(args.item_count, args.current_index, offset);
|
||||
}
|
||||
if (args.kind == "select") {
|
||||
return pp::app::plan_brush_preset_list_select(args.item_count, args.current_index);
|
||||
}
|
||||
if (args.kind == "clear") {
|
||||
return pp::app::plan_brush_preset_list_clear(args.item_count);
|
||||
}
|
||||
|
||||
return pp::foundation::Result<pp::app::BrushPresetListPlan>::failure(
|
||||
pp::foundation::Status::invalid_argument("unknown brush preset list operation kind"));
|
||||
}
|
||||
|
||||
int plan_brush_preset_list(int argc, char** argv)
|
||||
{
|
||||
PlanBrushPresetListArgs args;
|
||||
const auto status = parse_plan_brush_preset_list_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-brush-preset-list", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto plan = make_brush_preset_list_plan(args);
|
||||
if (!plan) {
|
||||
print_error("plan-brush-preset-list", plan.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto& value = plan.value();
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-brush-preset-list\""
|
||||
<< ",\"state\":{\"kind\":\"" << json_escape(args.kind)
|
||||
<< "\",\"itemCount\":" << args.item_count
|
||||
<< ",\"currentIndex\":" << args.current_index
|
||||
<< ",\"offset\":" << args.offset
|
||||
<< ",\"hasCurrentBrush\":" << json_bool(args.has_current_brush)
|
||||
<< "},\"plan\":{\"operation\":\"" << brush_preset_list_operation_name(value.operation)
|
||||
<< "\",\"itemCount\":" << value.item_count
|
||||
<< ",\"currentIndex\":" << value.current_index
|
||||
<< ",\"targetIndex\":" << value.target_index
|
||||
<< ",\"moveOffset\":" << value.move_offset
|
||||
<< ",\"savesList\":" << json_bool(value.saves_list)
|
||||
<< ",\"updatesEmptyNotification\":" << json_bool(value.updates_empty_notification)
|
||||
<< ",\"selectsTarget\":" << json_bool(value.selects_target)
|
||||
<< ",\"clearsSelection\":" << json_bool(value.clears_selection)
|
||||
<< ",\"notifiesBrushChanged\":" << json_bool(value.notifies_brush_changed)
|
||||
<< ",\"noOp\":" << json_bool(value.no_op)
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Result<pp::app::BrushStrokeFloatSetting> parse_brush_stroke_float_setting(
|
||||
std::string_view setting)
|
||||
{
|
||||
@@ -8852,6 +8977,10 @@ int main(int argc, char** argv)
|
||||
return plan_brush_texture_list(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-brush-preset-list") {
|
||||
return plan_brush_preset_list(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-brush-stroke-control") {
|
||||
return plan_brush_stroke_control(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user