Add metadata-only PPI save automation
This commit is contained in:
@@ -31,6 +31,14 @@ struct DocumentArgs {
|
||||
std::uint32_t frame_duration_ms = 100;
|
||||
};
|
||||
|
||||
struct SaveProjectArgs {
|
||||
std::string path;
|
||||
std::uint32_t width = 0;
|
||||
std::uint32_t height = 0;
|
||||
std::string layer_name = "Ink";
|
||||
std::uint32_t frame_duration_ms = 100;
|
||||
};
|
||||
|
||||
struct InspectImageArgs {
|
||||
std::string path;
|
||||
};
|
||||
@@ -144,6 +152,7 @@ void print_help()
|
||||
<< " load-project --path FILE\n"
|
||||
<< " parse-layout --path FILE\n"
|
||||
<< " record-render [--width N] [--height N]\n"
|
||||
<< " save-project --path FILE --width N --height N [--layer-name NAME] [--frame-duration-ms N]\n"
|
||||
<< " simulate-document-edits [--width N] [--height N]\n"
|
||||
<< " simulate-document-history [--width N] [--height N] [--history N]\n"
|
||||
<< " simulate-image-import [--width N] [--height N]\n"
|
||||
@@ -249,6 +258,108 @@ int create_document(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_save_project_args(int argc, char** argv, SaveProjectArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--path" || key == "--layer-name") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
|
||||
if (key == "--path") {
|
||||
args.path = argv[++i];
|
||||
} else {
|
||||
args.layer_name = argv[++i];
|
||||
}
|
||||
} else if (key == "--width" || key == "--height" || key == "--frame-duration-ms") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
|
||||
const auto value = pp::foundation::parse_u32(argv[++i]);
|
||||
if (!value) {
|
||||
return value.status();
|
||||
}
|
||||
|
||||
if (key == "--width") {
|
||||
args.width = value.value();
|
||||
} else if (key == "--height") {
|
||||
args.height = value.value();
|
||||
} else {
|
||||
args.frame_duration_ms = value.value();
|
||||
}
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
if (args.path.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("path must not be empty");
|
||||
}
|
||||
|
||||
if (args.width == 0 || args.height == 0) {
|
||||
return pp::foundation::Status::invalid_argument("width and height must be greater than zero");
|
||||
}
|
||||
|
||||
if (args.layer_name.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("layer name must not be empty");
|
||||
}
|
||||
|
||||
if (args.frame_duration_ms == 0) {
|
||||
return pp::foundation::Status::invalid_argument("frame duration must be greater than zero");
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
int save_project(int argc, char** argv)
|
||||
{
|
||||
SaveProjectArgs args;
|
||||
const auto status = parse_save_project_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("save-project", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto project = pp::assets::create_minimal_ppi_project(pp::assets::PpiMinimalProjectConfig {
|
||||
.width = args.width,
|
||||
.height = args.height,
|
||||
.layer_name = args.layer_name,
|
||||
.frame_duration_ms = args.frame_duration_ms,
|
||||
});
|
||||
if (!project) {
|
||||
print_error("save-project", project.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::ofstream stream(args.path, std::ios::binary);
|
||||
if (!stream) {
|
||||
print_error("save-project", "project file could not be opened for writing");
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto& bytes = project.value();
|
||||
stream.write(reinterpret_cast<const char*>(bytes.data()), static_cast<std::streamsize>(bytes.size()));
|
||||
if (!stream) {
|
||||
print_error("save-project", "project file could not be written");
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::cout << "{\"ok\":true,\"command\":\"save-project\""
|
||||
<< ",\"path\":\"" << json_escape(args.path) << "\""
|
||||
<< ",\"format\":\"ppi\""
|
||||
<< ",\"bytes\":" << bytes.size()
|
||||
<< ",\"document\":{\"width\":" << args.width
|
||||
<< ",\"height\":" << args.height
|
||||
<< ",\"layers\":1"
|
||||
<< ",\"frames\":1"
|
||||
<< ",\"layerName\":\"" << json_escape(args.layer_name) << "\""
|
||||
<< ",\"frameDurationMs\":" << args.frame_duration_ms
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_inspect_image_args(int argc, char** argv, InspectImageArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
@@ -1444,6 +1555,10 @@ int main(int argc, char** argv)
|
||||
return record_render(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "save-project") {
|
||||
return save_project(argc, argv);
|
||||
}
|
||||
|
||||
print_error(command, "unknown command");
|
||||
return 2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user