From 2cc6aa5524ded510a146e34e133f1062775f0abb Mon Sep 17 00:00:00 2001 From: twanvl Date: Sun, 18 Mar 2007 19:15:29 +0000 Subject: [PATCH] Magic Workstation spoiler format export git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@216 0fc631ac-6414-0410-93d0-97cfa31319b6 --- data/magic.mse-game/game | 2 + src/data/format/formats.hpp | 3 ++ src/data/format/mtg_editor.cpp | 14 ++--- src/data/format/mws.cpp | 98 +++++++++++++++++++++++++++++++++- src/data/settings.cpp | 10 ++-- src/gui/set/window.cpp | 3 +- src/util/defaultable.hpp | 1 + 7 files changed, 117 insertions(+), 14 deletions(-) diff --git a/data/magic.mse-game/game b/data/magic.mse-game/game index a44389d7..40f1dbfd 100644 --- a/data/magic.mse-game/game +++ b/data/magic.mse-game/game @@ -803,6 +803,8 @@ statistics category: ############################# Keyword rules +has keywords: true + keyword parameter type: name: no parameter keyword parameter type: diff --git a/src/data/format/formats.hpp b/src/data/format/formats.hpp index ddd87a03..4875e5a9 100644 --- a/src/data/format/formats.hpp +++ b/src/data/format/formats.hpp @@ -91,5 +91,8 @@ void export_image(const SetP& set, const CardP& card, const String& filename); /// Generate a bitmap image of a card Bitmap export_bitmap(const SetP& set, const CardP& card); +/// Export a set to Magic Workstation format +void export_mws(const SetP& set); + // ----------------------------------------------------------------------------- : EOF #endif diff --git a/src/data/format/mtg_editor.cpp b/src/data/format/mtg_editor.cpp index 055a5cb4..e8f7428f 100644 --- a/src/data/format/mtg_editor.cpp +++ b/src/data/format/mtg_editor.cpp @@ -143,13 +143,13 @@ SetP MtgEditorFileFormat::importSet(const String& filename) { target = ¤t_card->value(_("power")).value; } else if (line == _("#TOUGHNESS#####")) { // toughness target = ¤t_card->value(_("toughness")).value; - } else if (line == _("#ILLUSTRATION##") || line == _("#ILLUSTRATION8#")) { // image + } else if (line == _("#ILLUSTRATION##") || line == _("#ILLUSTRATION8#")) { // image target = 0; line = file.ReadLine(); if (!wxFileExists(line)) { // based on card name and date line = filter1(filename) + set_date + _("/") + - filter2(current_card->value(_("name")).value()) + card_date + _(".jpg"); + filter2(current_card->value(_("name")).value) + card_date + _(".jpg"); } // copy image into set if (wxFileExists(line)) { @@ -177,16 +177,16 @@ SetP MtgEditorFileFormat::importSet(const String& filename) { // set defaults for artist and copyright to that of the first card if (!set->cards.empty()) { - String artist = set->cards[0]->value(_("illustrator")).value(); - String copyright = set->cards[0]->value(_("copyright")) .value(); + String artist = set->cards[0]->value(_("illustrator")).value; + String copyright = set->cards[0]->value(_("copyright")) .value; set->value(_("artist")) .value.assign(artist); set->value(_("copyright")).value.assign(copyright); // which cards have this value? FOR_EACH(card, set->cards) { Defaultable& card_artist = card->value(_("illustrator")).value; Defaultable& card_copyright = card->value(_("copyright")) .value; - if (card_artist() == artist) card_artist.makeDefault(); - if (card_copyright() == copyright) card_copyright.makeDefault(); + if (card_artist == artist) card_artist.makeDefault(); + if (card_copyright == copyright) card_copyright.makeDefault(); } } @@ -237,7 +237,7 @@ String MtgEditorFileFormat::filter2(const String& str) { void MtgEditorFileFormat::untag(const CardP& card, const String& field) { Defaultable& value = card->value(field).value; - value.assignDontChangeDefault(untag_no_escape(value())); + value.assignDontChangeDefault(untag_no_escape(value)); } diff --git a/src/data/format/mws.cpp b/src/data/format/mws.cpp index 5e85f472..4e8517a1 100644 --- a/src/data/format/mws.cpp +++ b/src/data/format/mws.cpp @@ -7,5 +7,101 @@ // ----------------------------------------------------------------------------- : Includes #include +#include +#include +#include +#include +#include +#include +#include +#include -// ----------------------------------------------------------------------------- : +DECLARE_TYPEOF_COLLECTION(CardP); + +// ----------------------------------------------------------------------------- : Utilities + +/// Convert a tagged string to MWS format: \t\t before each line beyond the first +String untag_mws(const String& str) { + return replace_all(untag(str), _("\n"), _("\n\t\t") ); +} +//String untag_mws(const Defaultable& str) { +// str. +//} + +/// Code for card color in MWS format +String card_color_mws(const String& col) { + if (col == _("white")) return _("W"); + if (col == _("blue")) return _("U"); + if (col == _("black")) return _("B"); + if (col == _("red")) return _("R"); + if (col == _("green")) return _("G"); + if (col == _("colorless")) return _("Art"); + if (col.find(_("land")) != String::npos) { + return _("Lnd"); // land + } else { + return _("Gld"); // multicolor + } +} + +/// Code for card rarity, used for MWS and Apprentice +String card_rarity_code(const String& rarity) { + if (rarity == _("rare")) return _("R"); + if (rarity == _("uncommon")) return _("U"); + else return _("C"); +} + +// ----------------------------------------------------------------------------- : export_mws + +void export_mws(const SetP& set) { + if (!set->game->isMagic()) { + throw Error(_("Can only export Magic sets to Magic Workstation")); + } + + // Select filename + String name = wxFileSelector(_("Export to file"),_(""),_(""),_(""), + _("Text files (*.txt)|*.txt|All Files|*.*"), + wxSAVE | wxOVERWRITE_PROMPT); + if (name.empty()) return; + wxBusyCursor busy; + // Open file + wxFileOutputStream f(name); + wxTextOutputStream file(f, wxEOL_DOS); + + // Write header + file.WriteString(set->value(_("title")).value + _(" Spoiler List\n")); + file.WriteString(_("Set exported using Magic Set Editor 2, version ") + app_version.toString() + _("\n\n")); + wxDateTime now = wxDateTime::Now(); + file.WriteString(_("Spoiler List created on ") + now.FormatISODate() + _(" ") + now.FormatISOTime()); + file.WriteString(_("\n\n")); + + // Write cards + FOR_EACH(card, set->cards) { + file.WriteString(_("Card Name:\t")); + file.WriteString(untag_mws(card->value(_("name")).value)); + file.WriteString(_("\nCard Color:\t")); + file.WriteString(card_color_mws(card->value(_("card color")).value)); + file.WriteString(_("\nMana Cost:\t")); + file.WriteString(untag_mws(card->value(_("casting cost")).value)); + file.WriteString(_("\nType & Class:\t")); + String sup_type = untag_mws(card->value(_("super type")).value); + String sub_type = untag_mws(card->value(_("sub type")).value); + if (sub_type.empty()) { + file.WriteString(sup_type); + } else { + file.WriteString(sup_type + _(" - ") + sub_type); + } + file.WriteString(_("\nPow/Tou:\t")); + file.WriteString(untag_mws(card->value(_("pt")).value)); + file.WriteString(_("\nCard Text:\t")); + file.WriteString(untag_mws(card->value(_("rule text")).value)); + file.WriteString(_("\nFlavor Text:\t")); + file.WriteString(untag_mws(card->value(_("flavor text")).value)); + file.WriteString(_("\nArtist:\t\t")); + file.WriteString(untag_mws(card->value(_("illustrator")).value)); + file.WriteString(_("\nRarity:\t\t")); + file.WriteString(card_rarity_code(card->value(_("rarity")).value)); + file.WriteString(_("\nCard #:\t\t")); + file.WriteString(untag_mws(card->value(_("card number")).value)); + file.WriteString(_("\n\n")); + } +} diff --git a/src/data/settings.cpp b/src/data/settings.cpp index 51c1b6e9..38cd3822 100644 --- a/src/data/settings.cpp +++ b/src/data/settings.cpp @@ -63,11 +63,11 @@ StyleSheetSettings::StyleSheetSettings() {} void StyleSheetSettings::useDefault(const StyleSheetSettings& ss) { - if (card_zoom .isDefault()) card_zoom .assignDefault(ss.card_zoom()); - if (card_angle .isDefault()) card_angle .assignDefault(ss.card_angle()); - if (card_anti_alias .isDefault()) card_anti_alias .assignDefault(ss.card_anti_alias()); - if (card_borders .isDefault()) card_borders .assignDefault(ss.card_borders()); - if (card_normal_export.isDefault()) card_normal_export.assignDefault(ss.card_normal_export()); + if (card_zoom .isDefault()) card_zoom .assignDefault(ss.card_zoom); + if (card_angle .isDefault()) card_angle .assignDefault(ss.card_angle); + if (card_anti_alias .isDefault()) card_anti_alias .assignDefault(ss.card_anti_alias); + if (card_borders .isDefault()) card_borders .assignDefault(ss.card_borders); + if (card_normal_export.isDefault()) card_normal_export.assignDefault(ss.card_normal_export); } IMPLEMENT_REFLECTION(StyleSheetSettings) { diff --git a/src/gui/set/window.cpp b/src/gui/set/window.cpp index 68d5cfec..455cbe0b 100644 --- a/src/gui/set/window.cpp +++ b/src/gui/set/window.cpp @@ -148,6 +148,7 @@ SetWindow::SetWindow(Window* parent, const SetP& set) // note: this still sends events for menu and toolbar items! wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED); SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES); + tabBar->SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES); setSet(set); current_panel->Layout(); @@ -456,7 +457,7 @@ void SetWindow::onFileExportApprentice(wxCommandEvent&) { } void SetWindow::onFileExportMWS(wxCommandEvent&) { -// exportMWS(set); + export_mws(set); } void SetWindow::onFilePrint(wxCommandEvent&) { diff --git a/src/util/defaultable.hpp b/src/util/defaultable.hpp index c471b7e0..6a0f0220 100644 --- a/src/util/defaultable.hpp +++ b/src/util/defaultable.hpp @@ -39,6 +39,7 @@ class Defaultable { } /// Get access to the value + inline operator const T& () const { return value; } inline const T& operator () () const { return value; } /// Get access to the value, for changing it inline T& mutate () {