mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Renamed --export to --export-image
Added new --export command line argument for exporting using a scripted/html export template.
This commit is contained in:
@@ -59,7 +59,7 @@ bool need_redirection;
|
||||
|
||||
// ----------------------------------------------------------------------------- : Main function
|
||||
|
||||
const char* redirect_flags[] = {"-?","--help","-v","--version","--cli","-c","--export","--create-installer"};
|
||||
const char* redirect_flags[] = {"-?","--help","-v","--version","--cli","-c","--export","--export-images","--create-installer"};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// determine whether we need to wrap console i/o
|
||||
|
||||
@@ -52,12 +52,7 @@ HtmlExportWindow::HtmlExportWindow(Window* parent, const SetP& set, const Export
|
||||
list->select(settings.gameSettingsFor(*set->game).default_export);
|
||||
}
|
||||
|
||||
void HtmlExportWindow::onOk(wxCommandEvent&) {
|
||||
ExportTemplateP exp = list->getSelection<ExportTemplate>();
|
||||
// get filename
|
||||
String name = wxFileSelector(_TITLE_("save html"),settings.default_export_dir,_(""),_(""),exp->file_type, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
|
||||
if (name.empty()) return;
|
||||
settings.default_export_dir = wxPathOnly(name);
|
||||
ScriptValueP export_set(SetP const& set, vector<CardP> const& cards, ExportTemplateP const& exp, String const& outname) {
|
||||
wxBusyCursor wait;
|
||||
// export info for script
|
||||
ExportInfo info;
|
||||
@@ -66,7 +61,8 @@ void HtmlExportWindow::onOk(wxCommandEvent&) {
|
||||
WITH_DYNAMIC_ARG(export_info, &info);
|
||||
// create directory?
|
||||
if (exp->create_directory) {
|
||||
wxFileName fn(name);
|
||||
if (outname.empty()) throw Error(_("No output filename specified for export"));
|
||||
wxFileName fn(outname);
|
||||
info.directory_relative = fn.GetName() + _("-files");
|
||||
fn.SetFullName(info.directory_relative);
|
||||
info.directory_absolute = fn.GetFullPath();
|
||||
@@ -77,17 +73,29 @@ void HtmlExportWindow::onOk(wxCommandEvent&) {
|
||||
// run export script
|
||||
Context& ctx = set->getContext();
|
||||
LocalScope scope(ctx);
|
||||
ctx.setVariable(_("cards"), to_script(&getSelection()));
|
||||
ctx.setVariable(_("options"), to_script(&settings.exportOptionsFor(*exp)));
|
||||
ctx.setVariable(_("cards"), to_script(&cards));
|
||||
ctx.setVariable(_("options"), to_script(&settings.exportOptionsFor(*exp)));
|
||||
ctx.setVariable(_("directory"), to_script(info.directory_relative));
|
||||
ScriptValueP result = exp->script.invoke(ctx);
|
||||
// Save to file
|
||||
wxFileOutputStream file(name);
|
||||
{ // TODO: write as image?
|
||||
if (!outname.empty()) {
|
||||
// TODO: write as image?
|
||||
// write as string
|
||||
wxFileOutputStream file(outname);
|
||||
wxTextOutputStream stream(file);
|
||||
stream.WriteString(*result);
|
||||
stream.WriteString(result->toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void HtmlExportWindow::onOk(wxCommandEvent&) {
|
||||
ExportTemplateP exp = list->getSelection<ExportTemplate>();
|
||||
// get filename
|
||||
String name = wxFileSelector(_TITLE_("save html"),settings.default_export_dir,_(""),_(""),exp->file_type, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
|
||||
if (name.empty()) return;
|
||||
settings.default_export_dir = wxPathOnly(name);
|
||||
// export
|
||||
export_set(set, getSelection(), exp, name);
|
||||
// Done
|
||||
EndModal(wxID_OK);
|
||||
}
|
||||
|
||||
+22
-2
@@ -28,6 +28,8 @@
|
||||
#include <wx/txtstrm.h>
|
||||
#include <wx/socket.h>
|
||||
|
||||
ScriptValueP export_set(SetP const& set, vector<CardP> const& cards, ExportTemplateP const& exp, String const& outname);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Main function/class
|
||||
|
||||
/// The application class for MSE.
|
||||
@@ -181,7 +183,10 @@ int MSE::OnRun() {
|
||||
<< PARAM << _("PACKAGE") << NORMAL << _(" [") << PARAM << _("PACKAGE") << NORMAL << _(" ...]]");
|
||||
cli << _("\n \tCreate an instaler, containing the listed packages.");
|
||||
cli << _("\n \tIf no output filename is specified, the name of the first package is used.");
|
||||
cli << _("\n\n ") << BRIGHT << _("--export") << NORMAL << PARAM << _(" FILE") << NORMAL << _(" [") << PARAM << _("IMAGE") << NORMAL << _("]");
|
||||
cli << _("\n\n ") << BRIGHT << _("--export") << NORMAL << PARAM << _(" TEMPLATE SETFILE ") << NORMAL << _(" [") << PARAM << _("OUTFILE") << NORMAL << _("]");
|
||||
cli << _("\n \tExport a set using an export template.");
|
||||
cli << _("\n \tIf no output filename is specified, the result is written to stdout.");
|
||||
cli << _("\n\n ") << BRIGHT << _("--export-images") << NORMAL << PARAM << _(" FILE") << NORMAL << _(" [") << PARAM << _("IMAGE") << NORMAL << _("]");
|
||||
cli << _("\n \tExport the cards in a set to image files,");
|
||||
cli << _("\n \tIMAGE is the same format as for 'export all card images'.");
|
||||
cli << _("\n\n ") << BRIGHT << _("--cli") << NORMAL << _(" [")
|
||||
@@ -225,7 +230,7 @@ int MSE::OnRun() {
|
||||
}
|
||||
CLISetInterface cli_interface(set,quiet);
|
||||
return EXIT_SUCCESS;
|
||||
} else if (arg == _("--export")) {
|
||||
} else if (arg == _("--export-images")) {
|
||||
if (args.size() < 2) {
|
||||
handle_error(Error(_("No input file specified for --export")));
|
||||
return EXIT_FAILURE;
|
||||
@@ -246,6 +251,21 @@ int MSE::OnRun() {
|
||||
// export
|
||||
export_images(set, set->cards, path, out, CONFLICT_NUMBER_OVERWRITE);
|
||||
return EXIT_SUCCESS;
|
||||
} else if (args[0] == _("--export")) {
|
||||
if (args.size() < 2) {
|
||||
throw Error(_("No export template specified for --export"));
|
||||
} else if (args.size() < 3) {
|
||||
throw Error(_("No input set file specified for --export"));
|
||||
}
|
||||
String export_template = args[1];
|
||||
ExportTemplateP exp = package_manager.open<ExportTemplate>(export_template);
|
||||
SetP set = import_set(args[2]);
|
||||
String out = args.size() >= 4 ? args[3] : _("");
|
||||
ScriptValueP result = export_set(set, set->cards, exp, out);
|
||||
if (out.empty()) {
|
||||
cli << result->toString();
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
handle_error(_("Invalid command line argument:\n") + arg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user