Implement unique IDs and card linking

This commit is contained in:
GenevensiS
2025-08-11 16:17:13 +02:00
committed by GitHub
parent 13406b946c
commit 3bf9de18b1
100 changed files with 2432 additions and 1219 deletions
+2 -2
View File
@@ -196,7 +196,7 @@ bool Package::existsIn(const String& file) {
if (filename.find(_(".mse-")) != String::npos) {
return false;
}
}
}
unique_ptr<wxInputStream> stream;
if (it != files.end() && it->second.wasWritten()) {
@@ -216,7 +216,7 @@ bool Package::existsIn(const String& file) {
return false;
}
return stream && stream->IsOk();
}
}
unique_ptr<wxInputStream> Package::openIn(const String& file) {
if (!file.empty() && file.GetChar(0) == _('/')) {
+1 -1
View File
@@ -107,7 +107,7 @@ bool PackageManager::existsInPackage(const String& name) {
}
}
throw FileNotFoundError(name, _("No package name specified, use '/package/filename'"));
}
}
pair<unique_ptr<wxInputStream>,Packaged*> PackageManager::openFileFromPackage(Packaged* package, const String& name) {
if (!name.empty() && name.GetChar(0) == _('/')) {
+4 -4
View File
@@ -357,10 +357,10 @@ template <> void Reader::handle(Vector2D& vec) {
template <> void Reader::handle(LocalFileName& f) {
f = LocalFileName::fromReadString(this->getValue());
}
String Reader::addLocale(String filename) {
return filename + _("_") + settings.locale;
}
String Reader::addLocale(String filename) {
return filename + _("_") + settings.locale;
}
// ----------------------------------------------------------------------------- : EnumReader
+4 -4
View File
@@ -116,9 +116,9 @@ public:
/// The package being read from
inline Packaged* getPackage() const { return package; }
String addLocale(String);
String addLocale(String);
/// Set the value that will be returned by the next getValue() call (may mess up the state of the reader)
inline void setValue(const String& value) { state = UNHANDLED; previous_value = value; };
@@ -180,7 +180,7 @@ private:
/** Maybe the key is "include file" */
template <typename T>
void unknownKey(T& v) {
if (key == _("include_file") || key == _("include_localized_file")) {
if (key == _("include_file") || key == _("include_localized_file")) {
value = key == _("include_localized_file") ? addLocale(value) : value;
auto [stream, include_package] = openFileFromPackage(package, value);
Reader sub_reader(*stream, include_package, value, ignore_invalid);
+6 -6
View File
@@ -50,14 +50,14 @@ String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def = warn_and
/// Translate 'key' in the for a Package using the current locale
[[deprecated]]
String tr(const Package&, const String& key, DefaultLocaleFun def);
[[deprecated]]
String tr(const Package&, const String& key, DefaultLocaleFun def);
[[deprecated]]
String tr(const String&, const String& key, DefaultLocaleFun def);
/// Translate 'key' in the for a Package using the current locale
[[deprecated]]
String tr(const Package&, const String& subcat, const String& key, DefaultLocaleFun def);
[[deprecated]]
String tr(const Package&, const String& subcat, const String& key, DefaultLocaleFun def);
[[deprecated]]
String tr(const String&, const String& subcat, const String& key, DefaultLocaleFun def);
/// A localized string for menus
@@ -99,9 +99,9 @@ String tr(const String&, const String& subcat, const String& key, DefaultLocaleF
#define _TOOLTIP_1_(s,a) format_string(_TOOLTIP_(s), a)
/// A localized string for tooltip labels, with 1 argument (printf style)
#define _LABEL_1_(s,a) format_string(_LABEL_(s), a)
#define _LABEL_1_(s,a) format_string(_LABEL_(s), a)
/// A localized string for tooltip labels, with 2 argument (printf style)
#define _LABEL_2_(s,a,b) format_string(_LABEL_(s), a, b)
#define _LABEL_2_(s,a,b) format_string(_LABEL_(s), a, b)
/// A localized string for tooltip labels, with 3 argument (printf style)
#define _LABEL_3_(s,a,b,c) format_string(_LABEL_(s), a, b, c)
+2 -2
View File
@@ -137,14 +137,14 @@ void uncanonical_name_form_in_place(String& str) {
}
}
String unified_form(String& str) {
String unified_form(String& str) {
str = trim(str);
for (String::iterator it = str.begin(); it != str.end(); ++it) {
if (*it == ' ') *it = '_';
else *it = toLower(*it);
}
return str;
}
}
String name_to_caption(const String& str) {
String ret;
+3 -3
View File
@@ -241,9 +241,9 @@ void uncanonical_name_form_in_place(String&);
inline String uncanonical_name_form(String s) {
uncanonical_name_form_in_place(s);
return s;
}
/// Convert a field name to canonical form, then to lower case, then trim it
}
/// Convert a field name to canonical form, then to lower case, then trim it
String unified_form(String&);
/// Convert a field name to a string that can be shown to the user
+6 -6
View File
@@ -645,9 +645,9 @@ String simplify_tagged(const String& str) {
// (where </tag> is the negation of tag)
bool add_or_cancel_tag(const String& tag, String& stack, bool all = false) {
if (all || starts_with(tag, _("/")) ||
starts_with(tag, _("b")) ||
starts_with(tag, _("i")) ||
starts_with(tag, _("u")) ||
starts_with(tag, _("b")) ||
starts_with(tag, _("i")) ||
starts_with(tag, _("u")) ||
starts_with(tag, _("sym"))) {
// cancel out all close tags, but not all open tags,
// so <xx></xx> is always removed
@@ -695,9 +695,9 @@ String simplify_tagged_overlap(const String& str) {
Char c = str.GetChar(i);
if (c == _('<')) {
String tag = tag_at(str, i);
if (starts_with(tag, _("b")) || starts_with(tag, _("/b")) ||
starts_with(tag, _("i")) || starts_with(tag, _("/i")) ||
starts_with(tag, _("u")) || starts_with(tag, _("/u")) ||
if (starts_with(tag, _("b")) || starts_with(tag, _("/b")) ||
starts_with(tag, _("i")) || starts_with(tag, _("/i")) ||
starts_with(tag, _("u")) || starts_with(tag, _("/u")) ||
starts_with(tag, _("sym")) || starts_with(tag, _("/sym"))) {
// optimize this tag
if (open_tags.find(_("<") + tag + _(">")) == String::npos) {
+31
View File
@@ -0,0 +1,31 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) Twan van Laarhoven and the other MSE developers |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#pragma once
// ----------------------------------------------------------------------------- : Includes
#include <random>
#include <sstream>
// ----------------------------------------------------------------------------- : UID
static std::random_device rd; // Get true random number generator
static std::mt19937_64 gen((static_cast<uint64_t>(rd()) << 32) ^ rd()); // Bitwise XOR two outputs to seed pseudo random number generator
static std::uniform_int_distribution<> dis(0, 9);
// Generate a string consisting of 32 uniformly random digits.
static String generate_uid() {
std::stringstream ss;
int i;
ss << std::hex;
for (i = 0; i < 32; i++) {
ss << dis(gen);
};
//return ss.str();
String wxString(ss.str().c_str(), wxConvUTF8);
return wxString;
}
+8 -8
View File
@@ -51,14 +51,14 @@ template <> void GetDefaultMember::handle(const Version& v) {
// ----------------------------------------------------------------------------- : Versions
// NOTE: Don't use leading zeroes, they mean octal
const Version app_version = 10000 * MSE_VERSION_MAJOR + 100 * MSE_VERSION_MINOR + MSE_VERSION_PATCH;
#if defined UNOFFICIAL_BUILD
const Char* version_suffix = _(" (Unofficial)");
#elif defined UNICODE
const Char* version_suffix = _("");
#else
const Char* version_suffix = _(" (ascii build)");
const Version app_version = 10000 * MSE_VERSION_MAJOR + 100 * MSE_VERSION_MINOR + MSE_VERSION_PATCH;
#if defined UNOFFICIAL_BUILD
const Char* version_suffix = _(" (Unofficial)");
#elif defined UNICODE
const Char* version_suffix = _("");
#else
const Char* version_suffix = _(" (ascii build)");
#endif
/// Which version of MSE are the files we write out compatible with?
+24 -9
View File
@@ -81,7 +81,7 @@ enum MenuID {
ID_MODE_SYMMETRY,
ID_MODE_PAINT,
ID_MODE_MAX,
// Welcome Window
ID_SELECT_LANGUAGE,
};
@@ -108,12 +108,14 @@ enum ChildMenuID {
ID_CARD_ROTATE_270,
// CardList
ID_SELECT_COLUMNS,
ID_CARD_LINK,
ID_CARD_AND_LINK_COPY,
ID_CARD_ADD_CSV,
ID_CARD_ADD_CSV_SEP,
ID_CARD_ADD_CSV_BROWSE,
ID_CARD_ADD_CSV_BROWSE,
ID_CARD_ADD_JSON,
ID_CARD_ADD_JSON_ARRAY,
ID_CARD_ADD_JSON_BROWSE,
ID_CARD_ADD_JSON_BROWSE,
// Keyword menu
ID_KEYWORD_ADD = 6101,
@@ -124,7 +126,7 @@ enum ChildMenuID {
// Format menu
ID_FORMAT_BOLD = 6201,
ID_FORMAT_ITALIC,
ID_FORMAT_ITALIC,
ID_FORMAT_UNDERLINE,
ID_FORMAT_SYMBOL,
ID_FORMAT_REMINDER,
@@ -192,6 +194,12 @@ enum ChildMenuID {
ID_COLLAPSE_NOTES = 8001,
ID_CARD_FILTER,
ID_CARD_COUNTER,
ID_CARD_LINK_TYPE,
ID_CARD_LINK_SELECT,
ID_CARD_LINK_UNLINK_1,
ID_CARD_LINK_UNLINK_2,
ID_CARD_LINK_UNLINK_3,
ID_CARD_LINK_UNLINK_4,
// Style panel
ID_STYLE_USE_FOR_ALL = 8011,
@@ -219,7 +227,7 @@ enum ChildMenuID {
ID_CUSTOM_PACK,
// Console panel
ID_EVALUATE,
ID_EVALUATE,
ID_CLEAR_CONSOLE,
// SymbolFont (Format menu)
@@ -279,12 +287,13 @@ enum ControlID {
ID_PREVIEW,
ID_SELECTOR,
ID_SIZE,
ID_GRID,
ID_LEFT,
ID_TOP,
ID_WIDTH,
ID_HEIGHT,
ID_SELECTION_CENTER,
ID_SELECTION_CENTER_HORIZONTALLY,
ID_SELECTION_CENTER,
ID_SELECTION_CENTER_HORIZONTALLY,
ID_SELECTION_CENTER_VERTICALLY,
ID_FIX_ASPECT,
ID_ZOOM,
@@ -294,8 +303,8 @@ enum ControlID {
ID_EXPORT_ZOOM_X,
ID_EXPORT_ZOOM_Y,
ID_SHARPEN,
ID_SHARPEN_AMOUNT,
// Internal window
ID_SHARPEN_AMOUNT,
// Internal window
ID_INTERNAL_SCALE,
// Updates window
ID_PACKAGE_LIST,
@@ -309,5 +318,11 @@ enum ControlID {
ID_ADD_ITEM,
ID_REMOVE_ITEM,
ID_DEFAULTS,
ID_CARD_LINK_EDITOR,
ID_CARD_LINK_VIEWER,
ID_CARD_LINK_RELATION_1,
ID_CARD_LINK_RELATION_2,
ID_CARD_LINK_RELATION_3,
ID_CARD_LINK_RELATION_4,
};