From 7d1bb771639dcdc422b5018856d39e5658f9c0ee Mon Sep 17 00:00:00 2001 From: twanvl Date: Fri, 9 Jan 2009 02:03:24 +0000 Subject: [PATCH] tweaks to compact reading with tag.isComplex(): no longer requires that many hacks git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1312 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/field/choice.cpp | 14 ++------------ src/data/pack.cpp | 13 +++++++++---- src/util/io/get_member.cpp | 5 +++++ src/util/io/get_member.hpp | 2 +- src/util/io/writer.hpp | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/data/field/choice.cpp b/src/data/field/choice.cpp index 1f8f5533..97e1c90d 100644 --- a/src/data/field/choice.cpp +++ b/src/data/field/choice.cpp @@ -143,8 +143,8 @@ IMPLEMENT_REFLECTION_ENUM(ChoiceChoiceType) { VALUE_N("radio", CHOICE_TYPE_RADIO); } -IMPLEMENT_REFLECTION_NO_GET_MEMBER(ChoiceField::Choice) { - if (isGroup() || line_below || enabled.isScripted() || (tag.reading() && tag.isComplex())) { +IMPLEMENT_REFLECTION(ChoiceField::Choice) { + if (isGroup() || line_below || enabled.isScripted() || tag.isComplex()) { // complex values are groups REFLECT(name); REFLECT_N("group_choice", default_name); @@ -157,16 +157,6 @@ IMPLEMENT_REFLECTION_NO_GET_MEMBER(ChoiceField::Choice) { } } -template <> void GetDefaultMember::handle(const ChoiceField::Choice& c) { - if (!c.isGroup()) handle(c.name); -} - -template <> void GetMember::handle(const ChoiceField::Choice& c) { - handle(_("name"), c.name); - handle(_("group choice"), c.default_name); - handle(_("choices"), c.choices); -} - // ----------------------------------------------------------------------------- : ChoiceStyle ChoiceStyle::ChoiceStyle(const ChoiceFieldP& field) diff --git a/src/data/pack.cpp b/src/data/pack.cpp index 3856a78d..5fc2ec77 100644 --- a/src/data/pack.cpp +++ b/src/data/pack.cpp @@ -172,7 +172,7 @@ IMPLEMENT_REFLECTION_ENUM(PackSelectType) { VALUE_N("replace", SELECT_REPLACE); VALUE_N("no replace", SELECT_NO_REPLACE); VALUE_N("cyclic", SELECT_CYCLIC); - VALUE_N("one", SELECT_PROPORTIONAL); + VALUE_N("proportional",SELECT_PROPORTIONAL); VALUE_N("nonempty", SELECT_NONEMPTY); VALUE_N("first", SELECT_FIRST); } @@ -198,9 +198,13 @@ IMPLEMENT_REFLECTION(PackType) { } IMPLEMENT_REFLECTION(PackItem) { - REFLECT(name); - REFLECT(amount); - REFLECT(probability); + if (!tag.isComplex()) { + REFLECT_NAMELESS(name); + } else { + REFLECT(name); + REFLECT(amount); + REFLECT(probability); + } } @@ -389,6 +393,7 @@ void PackInstance::generate(vector* out) { } else if (pack_type.select == SELECT_CYCLIC) { size_t total = cards.size() + pack_type.items.size(); + if (total <= 0) total = 1; // prevent div by 0 size_t div = requested_copies / total; size_t rem = requested_copies % total; for (size_t i = 0 ; i < total ; ++i) { diff --git a/src/util/io/get_member.cpp b/src/util/io/get_member.cpp index 21a68af5..8e22e4c6 100644 --- a/src/util/io/get_member.cpp +++ b/src/util/io/get_member.cpp @@ -33,3 +33,8 @@ template <> void GetDefaultMember::handle(const Color& v) { value = to_sc GetMember::GetMember(const String& name) : target_name(name) {} + +// caused by the pattern: if (!tag.isComplex()) { REFLECT_NAMELESS(stuff) } +template <> void GetMember::handle(const String& v) { + throw InternalError(_("GetDefaultMember::handle")); +} diff --git a/src/util/io/get_member.hpp b/src/util/io/get_member.hpp index 43b44b22..2de92fd8 100644 --- a/src/util/io/get_member.hpp +++ b/src/util/io/get_member.hpp @@ -74,7 +74,7 @@ class GetMember : private GetDefaultMember { /// Tell the reflection code we are not reading inline bool reading() const { return false; } inline bool scripting() const { return true; } - inline bool isComplex() const { return false; } + inline bool isComplex() const { return true; } inline void addAlias(int, const Char*, const Char*) {} inline void handleIgnore(int, const Char*) {} diff --git a/src/util/io/writer.hpp b/src/util/io/writer.hpp index 1dac1b37..a572b08c 100644 --- a/src/util/io/writer.hpp +++ b/src/util/io/writer.hpp @@ -31,7 +31,7 @@ class Writer { /// Tell the reflection code we are not reading inline bool reading() const { return false; } inline bool scripting() const { return false; } - inline bool isComplex() const { return false; } + inline bool isComplex() const { return true; } inline void addAlias(int, const Char*, const Char*) {} inline void handleIgnore(int, const Char*) {}