Create animation documents from pano cli
This commit is contained in:
@@ -21,6 +21,8 @@ struct DocumentArgs {
|
||||
std::uint32_t width = 0;
|
||||
std::uint32_t height = 0;
|
||||
std::uint32_t layers = 1;
|
||||
std::uint32_t frames = 1;
|
||||
std::uint32_t frame_duration_ms = 100;
|
||||
};
|
||||
|
||||
struct InspectImageArgs {
|
||||
@@ -45,7 +47,7 @@ void print_help()
|
||||
{
|
||||
std::cout
|
||||
<< "pano_cli commands:\n"
|
||||
<< " create-document --width N --height N [--layers N]\n"
|
||||
<< " create-document --width N --height N [--layers N] [--frames N] [--frame-duration-ms N]\n"
|
||||
<< " inspect-image --path FILE\n"
|
||||
<< " inspect-project --path FILE\n"
|
||||
<< " parse-layout --path FILE\n"
|
||||
@@ -56,7 +58,8 @@ pp::foundation::Status parse_document_args(int argc, char** argv, DocumentArgs&
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--width" || key == "--height" || key == "--layers") {
|
||||
if (key == "--width" || key == "--height" || key == "--layers" || key == "--frames"
|
||||
|| key == "--frame-duration-ms") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
@@ -70,8 +73,12 @@ pp::foundation::Status parse_document_args(int argc, char** argv, DocumentArgs&
|
||||
args.width = value.value();
|
||||
} else if (key == "--height") {
|
||||
args.height = value.value();
|
||||
} else {
|
||||
} else if (key == "--layers") {
|
||||
args.layers = value.value();
|
||||
} else if (key == "--frames") {
|
||||
args.frames = value.value();
|
||||
} else {
|
||||
args.frame_duration_ms = value.value();
|
||||
}
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
@@ -86,6 +93,14 @@ pp::foundation::Status parse_document_args(int argc, char** argv, DocumentArgs&
|
||||
return pp::foundation::Status::invalid_argument("layer count must be greater than zero");
|
||||
}
|
||||
|
||||
if (args.frames == 0) {
|
||||
return pp::foundation::Status::invalid_argument("frame count must be greater than zero");
|
||||
}
|
||||
|
||||
if (args.frame_duration_ms == 0) {
|
||||
return pp::foundation::Status::invalid_argument("frame duration must be greater than zero");
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
@@ -98,24 +113,40 @@ int create_document(int argc, char** argv)
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto document = pp::document::CanvasDocument::create(
|
||||
const auto document_result = pp::document::CanvasDocument::create(
|
||||
pp::document::DocumentConfig {
|
||||
.width = args.width,
|
||||
.height = args.height,
|
||||
.layer_count = args.layers,
|
||||
});
|
||||
if (!document) {
|
||||
print_error("create-document", document.status().message);
|
||||
if (!document_result) {
|
||||
print_error("create-document", document_result.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
auto document = document_result.value();
|
||||
const auto duration_status = document.set_frame_duration(0, args.frame_duration_ms);
|
||||
if (!duration_status.ok()) {
|
||||
print_error("create-document", duration_status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
for (std::uint32_t i = 1; i < args.frames; ++i) {
|
||||
const auto added_frame = document.add_frame(args.frame_duration_ms);
|
||||
if (!added_frame) {
|
||||
print_error("create-document", added_frame.status().message);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "{\"ok\":true,\"command\":\"create-document\",\"document\":{"
|
||||
<< "\"width\":" << document.value().width()
|
||||
<< ",\"height\":" << document.value().height()
|
||||
<< ",\"layers\":" << document.value().layers().size()
|
||||
<< ",\"activeLayer\":" << document.value().active_layer_index()
|
||||
<< ",\"frames\":" << document.value().frames().size()
|
||||
<< ",\"activeFrame\":" << document.value().active_frame_index()
|
||||
<< "\"width\":" << document.width()
|
||||
<< ",\"height\":" << document.height()
|
||||
<< ",\"layers\":" << document.layers().size()
|
||||
<< ",\"activeLayer\":" << document.active_layer_index()
|
||||
<< ",\"frames\":" << document.frames().size()
|
||||
<< ",\"activeFrame\":" << document.active_frame_index()
|
||||
<< ",\"animationDurationMs\":" << document.animation_duration_ms()
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user