diff --git a/data/magic-extended-art.mse-style/style b/data/magic-extended-art.mse-style/style index 9318beb9..ef964287 100644 --- a/data/magic-extended-art.mse-style/style +++ b/data/magic-extended-art.mse-style/style @@ -264,6 +264,7 @@ extra card field: type: choice name: pt box script: card.card_color + editable: false extra card style: pt box: diff --git a/data/magic-firepenguinmaster-flip.mse-style/style b/data/magic-firepenguinmaster-flip.mse-style/style index 44f079a2..2eeb01fa 100644 --- a/data/magic-firepenguinmaster-flip.mse-style/style +++ b/data/magic-firepenguinmaster-flip.mse-style/style @@ -401,10 +401,12 @@ extra card field: type: choice name: pt symbols script: "shieldsword" + editable: false extra card field: type: choice name: pt symbols 2 script: "shieldsword" + editable: false extra card style: pt symbols: diff --git a/data/magic-firepenguinmaster.mse-style/style b/data/magic-firepenguinmaster.mse-style/style index 77a0d449..92f16ffd 100644 --- a/data/magic-firepenguinmaster.mse-style/style +++ b/data/magic-firepenguinmaster.mse-style/style @@ -308,6 +308,7 @@ extra card field: type: choice name: pt symbols script: "shieldsword" + editable: false extra card style: pt symbols: diff --git a/data/magic-firepenguinmasterpromo.mse-style/style b/data/magic-firepenguinmasterpromo.mse-style/style index e382e728..5f9c99ea 100644 --- a/data/magic-firepenguinmasterpromo.mse-style/style +++ b/data/magic-firepenguinmasterpromo.mse-style/style @@ -312,6 +312,7 @@ extra card field: type: choice name: pt symbols script: "shieldsword" + editable: false extra card style: pt symbols: diff --git a/data/magic-firepenguinmastersplit.mse-style/style b/data/magic-firepenguinmastersplit.mse-style/style index f87a1420..de6edf9e 100644 --- a/data/magic-firepenguinmastersplit.mse-style/style +++ b/data/magic-firepenguinmastersplit.mse-style/style @@ -471,10 +471,12 @@ extra card field: type: choice name: pt symbols script: "shieldsword" + editable: false extra card field: type: choice name: pt symbols 2 script: "shieldsword" + editable: false extra card style: pt symbols: diff --git a/data/magic-firepenguinmastertokens.mse-style/style b/data/magic-firepenguinmastertokens.mse-style/style index 67af1f54..ebccf966 100644 --- a/data/magic-firepenguinmastertokens.mse-style/style +++ b/data/magic-firepenguinmastertokens.mse-style/style @@ -337,6 +337,7 @@ extra card field: type: choice name: pt symbols script: "shieldsword" + editable: false extra card style: pt symbols: diff --git a/data/magic-new-flip.mse-style/style b/data/magic-new-flip.mse-style/style index 5c55dc44..80e7685d 100644 --- a/data/magic-new-flip.mse-style/style +++ b/data/magic-new-flip.mse-style/style @@ -366,11 +366,12 @@ extra card field: type: choice name: pt box script: card.card_color - + editable: false extra card field: type: choice name: pt box 2 script: card.card_color + editable: false extra card style: pt box: diff --git a/data/magic-new-promo.mse-style/style b/data/magic-new-promo.mse-style/style index 6e8fc77a..fb8cd91f 100644 --- a/data/magic-new-promo.mse-style/style +++ b/data/magic-new-promo.mse-style/style @@ -269,6 +269,7 @@ extra card field: type: choice name: pt box script: card.card_color + editable: false extra card style: pt box: diff --git a/data/magic-new-split.mse-style/style b/data/magic-new-split.mse-style/style index dd29b9d8..48f221fc 100644 --- a/data/magic-new-split.mse-style/style +++ b/data/magic-new-split.mse-style/style @@ -410,11 +410,12 @@ extra card field: type: choice name: pt box script: card.card_color - + editable: false extra card field: type: choice name: pt box 2 script: card.card_color_2 + editable: false extra card style: pt box: diff --git a/data/magic-new.mse-style/style b/data/magic-new.mse-style/style index 7e72b6f7..ca776706 100644 --- a/data/magic-new.mse-style/style +++ b/data/magic-new.mse-style/style @@ -312,6 +312,7 @@ extra card field: type: choice name: pt box script: card.card_color + editable: false extra card style: pt box: diff --git a/data/magic-planeshifted.mse-style/style b/data/magic-planeshifted.mse-style/style index 00b1b9ce..ff7d7ebc 100644 --- a/data/magic-planeshifted.mse-style/style +++ b/data/magic-planeshifted.mse-style/style @@ -277,6 +277,7 @@ extra card field: type: choice name: pt box script: card.card_color + editable: false extra card style: pt box: diff --git a/src/data/card.cpp b/src/data/card.cpp index c9882286..26aebb9d 100644 --- a/src/data/card.cpp +++ b/src/data/card.cpp @@ -12,6 +12,7 @@ #include #include #include +#include DECLARE_TYPEOF_COLLECTION(FieldP); DECLARE_TYPEOF_NO_REV(IndexMap); @@ -51,6 +52,48 @@ void mark_dependency_member(const Card& card, const String& name, const Dependen IMPLEMENT_REFLECTION(Card) { REFLECT(stylesheet); REFLECT(notes); + REFLECT_NO_SCRIPT(extra_data); REFLECT_NAMELESS(data); } +// ----------------------------------------------------------------------------- : Styling + +// TODO : this is practically the same as Set::Styling, maybe somehow abstract it + +// Extra card data, for a specific stylesheet +/* The data is not read immediatly, because we do not know the stylesheet */ +class Card::Styling : public IntrusivePtrBase { + public: + /// The values on the extra card fields of the card. + /** The indices should correspond to the extra_card_fields in the StyleSheet */ + IndexMap extra_data; + /// Unparsed extra_data + String unread_data; + DECLARE_REFLECTION(); +}; + +IndexMap& Card::extraDataFor(const StyleSheet& stylesheet) { + StylingP& styling = extra_data[stylesheet.name()]; + if (!styling) { + styling = new_intrusive(); + styling->extra_data.init(stylesheet.extra_card_fields); + } else if (!styling->unread_data.empty() || (styling->extra_data.empty()) && !stylesheet.extra_card_fields.empty()) { + // we delayed the reading of the data, read it now + styling->extra_data.init(stylesheet.extra_card_fields); + Reader reader(new_shared1(styling->unread_data), _("extra card values for ") + stylesheet.stylesheetName()); + reader.handle_greedy(styling->extra_data); + styling->unread_data.clear(); + } + return styling->extra_data; +} + +// custom reflection : read into unread_data +template <> void Reader::handle(Card::Styling& s) { + handle(s.unread_data); +} +template <> void Writer::handle(const Card::Styling& s) { + handle(s.extra_data); +} +// for the love of god, don't depend on styling +template <> void GetMember::handle(const Card::Styling& s) {} +template <> void GetDefaultMember::handle(const Card::Styling& s) {} diff --git a/src/data/card.hpp b/src/data/card.hpp index fe50bf34..bb1bc305 100644 --- a/src/data/card.hpp +++ b/src/data/card.hpp @@ -34,15 +34,18 @@ class Card : public IntrusivePtrVirtualBase { /// The values on the fields of the card. /** The indices should correspond to the card_fields in the Game */ IndexMap data; - /// The values on the extra fields of the card. - /** The indices should correspond to the extra_card_fields in the StyleSheet */ - IndexMap extra_data; /// Notes for this card String notes; /// Alternative style to use for this card /** Optional; if not set use the card style from the set */ StyleSheetP stylesheet; + /// Extra values for specitic stylesheets, indexed by stylesheet name + DECLARE_POINTER_TYPE(Styling); + map extra_data; + /// Styling information for a particular stylesheet + IndexMap& extraDataFor(const StyleSheet& stylesheet) ; + /// Get the identification of this card, an identification is something like a name, title, etc. /** May return "" */ String identification() const; diff --git a/src/data/stylesheet.cpp b/src/data/stylesheet.cpp index 3dbd78f4..cc067c29 100644 --- a/src/data/stylesheet.cpp +++ b/src/data/stylesheet.cpp @@ -85,9 +85,9 @@ IMPLEMENT_REFLECTION(StyleSheet) { REFLECT(extra_card_fields); REFLECT_IF_READING { if (extra_card_style.init(extra_card_fields)) { - // make sure the extra_card_fields are not editable and savable + // if a value is not editable, don't save it FOR_EACH(f, extra_card_fields) { - f->editable = f->save_value = false; + if (!f->editable) f->save_value = false; } } } diff --git a/src/render/card/viewer.cpp b/src/render/card/viewer.cpp index fbc50412..88e44d9e 100644 --- a/src/render/card/viewer.cpp +++ b/src/render/card/viewer.cpp @@ -96,8 +96,7 @@ void DataViewer::setCard(const CardP& card, bool refresh) { this->card = card; stylesheet = new_stylesheet; setStyles(stylesheet, stylesheet->card_style, &stylesheet->extra_card_style); - card->extra_data.init(stylesheet->extra_card_fields); // make sure extra_data is initialized - setData(card->data, &card->extra_data); + setData(card->data, &card->extraDataFor(*stylesheet)); onChangeSize(); } diff --git a/src/script/script_manager.cpp b/src/script/script_manager.cpp index 1d802b62..f7d20e5b 100644 --- a/src/script/script_manager.cpp +++ b/src/script/script_manager.cpp @@ -196,8 +196,8 @@ void SetScriptManager::updateStyles(const CardP& card) { const StyleSheet& stylesheet = set.stylesheetFor(card); Context& ctx = getContext(card); // update extra card fields - card->extra_data.init(stylesheet.extra_card_fields); - FOR_EACH(v, card->extra_data) { + IndexMap& extra_data = card->extraDataFor(stylesheet); + FOR_EACH(v, extra_data) { v->update(ctx); } // update all styles