mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 13:17:00 -04:00
Cleaned up the reflection code a bit
* Renamed 'tag' variable to 'handler' * Removed addAlias stuff, instead check for matching names with if statements * Added after_reading function that is called by Reader after reading a complete object. This generalizes Packaged::validate, which is now also called via this mechanism. * Removed some backwards compatibility with <0.3.0 for templates
This commit is contained in:
+25
-25
@@ -34,13 +34,14 @@ IMPLEMENT_REFLECTION(ChoiceField) {
|
||||
REFLECT_N("default", default_script);
|
||||
REFLECT(initial);
|
||||
REFLECT(default_name);
|
||||
REFLECT_IF_READING {
|
||||
choices->initIds();
|
||||
}
|
||||
REFLECT(choice_colors);
|
||||
REFLECT(choice_colors_cardlist);
|
||||
}
|
||||
|
||||
void ChoiceField::after_reading(Version ver) {
|
||||
Field::after_reading(ver);
|
||||
choices->initIds();
|
||||
}
|
||||
// ----------------------------------------------------------------------------- : ChoiceField::Choice
|
||||
|
||||
ChoiceField::Choice::Choice()
|
||||
@@ -142,7 +143,9 @@ IMPLEMENT_REFLECTION_ENUM(ChoiceChoiceType) {
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION(ChoiceField::Choice) {
|
||||
if (isGroup() || line_below || enabled.isScripted() || tag.isComplex()) {
|
||||
REFLECT_IF_READING_SINGLE_VALUE {
|
||||
REFLECT_NAMELESS(name);
|
||||
} else {
|
||||
// complex values are groups
|
||||
REFLECT(name);
|
||||
REFLECT_N("group_choice", default_name);
|
||||
@@ -150,8 +153,6 @@ IMPLEMENT_REFLECTION(ChoiceField::Choice) {
|
||||
REFLECT(line_below);
|
||||
REFLECT(enabled);
|
||||
REFLECT(type);
|
||||
} else {
|
||||
REFLECT_NAMELESS(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,33 +243,32 @@ void ChoiceStyle::invalidate() {
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION_ENUM(ChoicePopupStyle) {
|
||||
VALUE_N("dropdown", POPUP_DROPDOWN);
|
||||
VALUE_N("menu", POPUP_MENU);
|
||||
VALUE_N("in place", POPUP_DROPDOWN_IN_PLACE);
|
||||
VALUE_N("dropdown", POPUP_DROPDOWN);
|
||||
VALUE_N("menu", POPUP_MENU);
|
||||
VALUE_N("in place", POPUP_DROPDOWN_IN_PLACE);
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION_ENUM(ChoiceRenderStyle) {
|
||||
VALUE_N("text", RENDER_TEXT);
|
||||
VALUE_N("image", RENDER_IMAGE);
|
||||
VALUE_N("both", RENDER_BOTH);
|
||||
VALUE_N("hidden", RENDER_HIDDEN);
|
||||
VALUE_N("image hidden", RENDER_HIDDEN_IMAGE);
|
||||
VALUE_N("checklist", RENDER_TEXT_CHECKLIST);
|
||||
VALUE_N("image checklist", RENDER_IMAGE_CHECKLIST);
|
||||
VALUE_N("both checklist", RENDER_BOTH_CHECKLIST);
|
||||
VALUE_N("text list", RENDER_TEXT_LIST);
|
||||
VALUE_N("image list", RENDER_IMAGE_LIST);
|
||||
VALUE_N("both list", RENDER_BOTH_LIST);
|
||||
VALUE_N("text", RENDER_TEXT);
|
||||
VALUE_N("image", RENDER_IMAGE);
|
||||
VALUE_N("both", RENDER_BOTH);
|
||||
VALUE_N("hidden", RENDER_HIDDEN);
|
||||
VALUE_N("image hidden", RENDER_HIDDEN_IMAGE);
|
||||
VALUE_N("checklist", RENDER_TEXT_CHECKLIST);
|
||||
VALUE_N("image checklist", RENDER_IMAGE_CHECKLIST);
|
||||
VALUE_N("both checklist", RENDER_BOTH_CHECKLIST);
|
||||
VALUE_N("text list", RENDER_TEXT_LIST);
|
||||
VALUE_N("image list", RENDER_IMAGE_LIST);
|
||||
VALUE_N("both list", RENDER_BOTH_LIST);
|
||||
}
|
||||
|
||||
template <typename T> void reflect_content(T& tag, const ChoiceStyle& cs) {}
|
||||
template <> void reflect_content(GetMember& tag, const ChoiceStyle& cs) {
|
||||
template <typename T> void reflect_content(T& handler, const ChoiceStyle& cs) {}
|
||||
template <> void reflect_content(GetMember& handler, const ChoiceStyle& cs) {
|
||||
REFLECT_N("content_width", cs.content_width);
|
||||
REFLECT_N("content_height", cs.content_height);
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION(ChoiceStyle) {
|
||||
REFLECT_ALIAS(300, "card_list_colors", "colors_card_list");
|
||||
REFLECT_BASE(Style);
|
||||
REFLECT(popup_style);
|
||||
REFLECT(render_style);
|
||||
@@ -277,7 +277,7 @@ IMPLEMENT_REFLECTION(ChoiceStyle) {
|
||||
REFLECT(font);
|
||||
REFLECT(image);
|
||||
REFLECT(choice_images);
|
||||
reflect_content(tag, *this);
|
||||
reflect_content(handler, *this);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : ChoiceValue
|
||||
@@ -301,7 +301,7 @@ bool ChoiceValue::update(Context& ctx) {
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION_NAMELESS(ChoiceValue) {
|
||||
if (fieldP->save_value || tag.scripting() || tag.reading()) REFLECT_NAMELESS(value);
|
||||
if (fieldP->save_value || !handler.isWriting) REFLECT_NAMELESS(value);
|
||||
}
|
||||
|
||||
INSTANTIATE_REFLECTION_NAMELESS(ChoiceValue)
|
||||
|
||||
@@ -42,6 +42,7 @@ class ChoiceField : public Field {
|
||||
map<String,Color> choice_colors_cardlist; ///< Colors for the various choices, for in the card list
|
||||
|
||||
virtual void initDependencies(Context&, const Dependency&) const;
|
||||
virtual void after_reading(Version ver);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ IMPLEMENT_REFLECTION(ColorField) {
|
||||
// ----------------------------------------------------------------------------- : ColorField::Choice
|
||||
|
||||
IMPLEMENT_REFLECTION(ColorField::Choice) {
|
||||
if (tag.reading() && !tag.isComplex()) {
|
||||
REFLECT_IF_READING_SINGLE_VALUE {
|
||||
REFLECT_NAMELESS(name);
|
||||
color = parse_color(name);
|
||||
} else {
|
||||
@@ -98,5 +98,5 @@ bool ColorValue::update(Context& ctx) {
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION_NAMELESS(ColorValue) {
|
||||
if (fieldP->save_value || tag.scripting() || tag.reading()) REFLECT_NAMELESS(value);
|
||||
if (fieldP->save_value || !handler.isWriting) REFLECT_NAMELESS(value);
|
||||
}
|
||||
|
||||
@@ -39,14 +39,14 @@ String ImageValue::toString() const {
|
||||
|
||||
// custom reflection: convert to ScriptImageP for scripting
|
||||
|
||||
void ImageValue::reflect(Reader& tag) {
|
||||
tag.handle(filename);
|
||||
void ImageValue::reflect(Reader& handler) {
|
||||
handler.handle(filename);
|
||||
}
|
||||
void ImageValue::reflect(Writer& tag) {
|
||||
if (fieldP->save_value) tag.handle(filename);
|
||||
void ImageValue::reflect(Writer& handler) {
|
||||
if (fieldP->save_value) handler.handle(filename);
|
||||
}
|
||||
void ImageValue::reflect(GetMember& tag) {}
|
||||
void ImageValue::reflect(GetDefaultMember& tag) {
|
||||
void ImageValue::reflect(GetMember& handler) {}
|
||||
void ImageValue::reflect(GetDefaultMember& handler) {
|
||||
// convert to ScriptImageP for scripting
|
||||
tag.handle( (ScriptValueP)make_intrusive<ImageValueToImage>(filename, last_update) );
|
||||
handler.handle( (ScriptValueP)make_intrusive<ImageValueToImage>(filename, last_update) );
|
||||
}
|
||||
|
||||
@@ -67,13 +67,13 @@ bool PackageChoiceValue::update(Context& ctx) {
|
||||
return change;
|
||||
}
|
||||
|
||||
void PackageChoiceValue::reflect(Reader& tag) {
|
||||
void PackageChoiceValue::reflect(Reader& handler) {
|
||||
REFLECT_NAMELESS(package_name);
|
||||
}
|
||||
void PackageChoiceValue::reflect(Writer& tag) {
|
||||
void PackageChoiceValue::reflect(Writer& handler) {
|
||||
REFLECT_NAMELESS(package_name);
|
||||
}
|
||||
void PackageChoiceValue::reflect(GetDefaultMember& tag) {
|
||||
void PackageChoiceValue::reflect(GetDefaultMember& handler) {
|
||||
if (package_name.empty()) {
|
||||
REFLECT_NAMELESS(package_name);
|
||||
} else if(package_name != field().initial) {
|
||||
|
||||
@@ -52,5 +52,5 @@ String SymbolValue::toString() const {
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION_NAMELESS(SymbolValue) {
|
||||
if (fieldP->save_value || tag.scripting() || tag.reading()) REFLECT_NAMELESS(filename);
|
||||
if (fieldP->save_value || !handler.isWriting) REFLECT_NAMELESS(filename);
|
||||
}
|
||||
|
||||
@@ -97,8 +97,8 @@ void TextStyle::checkContentDependencies(Context& ctx, const Dependency& dep) co
|
||||
alignment.initDependencies(ctx, dep);
|
||||
}
|
||||
|
||||
template <typename T> void reflect_content(T& tag, const TextStyle& ts) {}
|
||||
template <> void reflect_content(GetMember& tag, const TextStyle& ts) {
|
||||
template <typename T> void reflect_content(T& handler, const TextStyle& ts) {}
|
||||
template <> void reflect_content(GetMember& handler, const TextStyle& ts) {
|
||||
REFLECT_N("content_width", ts.content_width);
|
||||
REFLECT_N("content_height", ts.content_height);
|
||||
REFLECT_N("content_lines", ts.content_lines);
|
||||
@@ -127,7 +127,7 @@ IMPLEMENT_REFLECTION(TextStyle) {
|
||||
REFLECT(line_height_line_max);
|
||||
REFLECT(paragraph_height);
|
||||
REFLECT(direction);
|
||||
reflect_content(tag, *this);
|
||||
reflect_content(handler, *this);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : TextValue
|
||||
@@ -147,7 +147,7 @@ bool TextValue::update(Context& ctx) {
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION_NAMELESS(TextValue) {
|
||||
if (fieldP->save_value || tag.scripting() || tag.reading()) REFLECT_NAMELESS(value);
|
||||
if (fieldP->save_value || !handler.isWriting) REFLECT_NAMELESS(value);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : FakeTextValue
|
||||
|
||||
Reference in New Issue
Block a user