From 641acff92a60b5fedec5ae63372b352d9bfba439 Mon Sep 17 00:00:00 2001 From: Twan van Laarhoven Date: Tue, 19 May 2020 23:56:23 +0200 Subject: [PATCH] Add game and stylesheet version numbers to set files. Closes #39 --- src/data/card.cpp | 6 ++++++ src/data/set.cpp | 16 ++++++++++++++++ src/util/version.cpp | 8 +++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/data/card.cpp b/src/data/card.cpp index bd2cbca9..e65b5c2a 100644 --- a/src/data/card.cpp +++ b/src/data/card.cpp @@ -68,8 +68,14 @@ void mark_dependency_member(const Card& card, const String& name, const Dependen mark_dependency_member(card.data, name, dep); } +void reflect_version_check(Reader& handler, const Char* key, intrusive_ptr const& package); +void reflect_version_check(Writer& handler, const Char* key, intrusive_ptr const& package); +void reflect_version_check(GetMember& handler, const Char* key, intrusive_ptr const& package); +void reflect_version_check(GetDefaultMember& handler, const Char* key, intrusive_ptr const& package); + IMPLEMENT_REFLECTION(Card) { REFLECT(stylesheet); + reflect_version_check(handler, _("stylesheet_version"), stylesheet); REFLECT(has_styling); if (has_styling) { if (stylesheet) { diff --git a/src/data/set.cpp b/src/data/set.cpp index baee1cd7..dc8bfbf8 100644 --- a/src/data/set.cpp +++ b/src/data/set.cpp @@ -166,15 +166,31 @@ void Set::validate(Version file_app_version) { script_manager->updateAll(); } +void reflect_version_check(Reader& handler, const Char* key, intrusive_ptr const& package) { + if (!package) return; + Version v = package->version; + handler.handle(key, v); + if (package->version < v) { + queue_message(MESSAGE_WARNING, "This set file is made with a newer version of the '" + package->name() + "' template. Please update the template files."); + } +} +void reflect_version_check(Writer& handler, const Char* key, intrusive_ptr const& package) { + handler.handle(key, package->version); +} +void reflect_version_check(GetMember& handler, const Char* key, intrusive_ptr const& package) {} +void reflect_version_check(GetDefaultMember& handler, const Char* key, intrusive_ptr const& package) {} + IMPLEMENT_REFLECTION(Set) { REFLECT(game); if (game) { REFLECT_IF_READING { data.init(game->set_fields); } + reflect_version_check(handler, _("game_version"), game); WITH_DYNAMIC_ARG(game_for_reading, game.get()); REFLECT(stylesheet); REFLECT_COMPAT(<300, "style", stylesheet); + reflect_version_check(handler, _("stylesheet_version"), stylesheet); WITH_DYNAMIC_ARG(stylesheet_for_reading, stylesheet.get()); REFLECT_N("set_info", data); if (stylesheet) { diff --git a/src/util/version.cpp b/src/util/version.cpp index 6260b1e7..319f26b2 100644 --- a/src/util/version.cpp +++ b/src/util/version.cpp @@ -70,7 +70,8 @@ const Char* version_suffix = _(" (ascii build)"); * 0.3.0 : port of code to C++ * 0.3.1 : new keyword system, some new style options * 0.3.2 : package dependencies - * 0.3.3 : keyword separator before/after + * 0.3.3 : keywor + d separator before/after * 0.3.4 : html export; choice rendering based on scripted 'image' * 0.3.5 : word lists, symbol font 'as text' * 0.3.6 : free rotation, rotation behaviour changed. @@ -82,14 +83,15 @@ const Char* version_suffix = _(" (ascii build)"); * - store time created,modified for cards -> changes set and clipboard format * 0.3.9 : bugfix release mostly, a few new script functions * 2.0.0 : bugfix release mostly, added error console + * 2.0.2 : store game and stylesheet version numbers */ const Version file_version_locale = 20002; // 2.0.2 -const Version file_version_set = 308; // 0.3.8 +const Version file_version_set = 20002; // 2.0.2 const Version file_version_game = 308; // 0.3.8 const Version file_version_stylesheet = 308; // 0.3.8 const Version file_version_symbol_font = 306; // 0.3.6 const Version file_version_export_template = 307; // 0.3.7 const Version file_version_installer = 307; // 0.3.7 const Version file_version_symbol = 305; // 0.3.5 -const Version file_version_clipboard = 308; // 0.3.8 +const Version file_version_clipboard = 20002; // 2.0.2 const Version file_version_script = 307; // 0.3.7