diff --git a/data/ch-s.mse-locale/locale b/data/ch-s.mse-locale/locale index f8914738..31e64fd9 100644 --- a/data/ch-s.mse-locale/locale +++ b/data/ch-s.mse-locale/locale @@ -1094,6 +1094,8 @@ error: negative image height: Image with zero or negative height created in function '%s' #TODO: Localize can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. + #TODO: Localize + symbol image has alpha: For best results, image should be black and white with no transparency. # error from files #TODO: Localize diff --git a/data/ch-t.mse-locale/locale b/data/ch-t.mse-locale/locale index c5e17f25..2540a634 100644 --- a/data/ch-t.mse-locale/locale +++ b/data/ch-t.mse-locale/locale @@ -1092,6 +1092,8 @@ error: negative image height: Image with zero or negative height created in function '%s' #TODO: Localize can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. + #TODO: Localize + symbol image has alpha: For best results, image should be black and white with no transparency. # error from files #TODO: Localize diff --git a/data/da.mse-locale/locale b/data/da.mse-locale/locale index 9cc87772..ab4da063 100644 --- a/data/da.mse-locale/locale +++ b/data/da.mse-locale/locale @@ -1119,6 +1119,8 @@ error: negative image height: Image with zero or negative height created in function '%s' #TODO: Localize can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. + #TODO: Localize + symbol image has alpha: For best results, image should be black and white with no transparency. # error from files #TODO: Localize Section diff --git a/data/de.mse-locale/locale b/data/de.mse-locale/locale index 548ec15c..77f5ec5d 100644 --- a/data/de.mse-locale/locale +++ b/data/de.mse-locale/locale @@ -1021,6 +1021,7 @@ error: negative image width: Bild mit Breite Null oder negativer Breite, erstellt in der Funktion '%s' negative image height: Bild mit Höhe Null oder negativer Höhe, erstellt in der Funktion '%s' can't load image: Bild konnte nicht geladen werden. Stelle sicher, dass das tatsächliche Format des Bildes mit der gespeicherten Dateiendung übereinstimmt. + symbol image has alpha: Für optimale Ergebnisse sollte das Bild schwarzweiß und ohne Transparenz sein. # error from files no card fields: Das Spiel '%s' hat keine Kartenfelder. Definieren Sie mindestens ein Kartenfeld. diff --git a/data/en.mse-locale/locale b/data/en.mse-locale/locale index c770d918..e8fdfcb3 100644 --- a/data/en.mse-locale/locale +++ b/data/en.mse-locale/locale @@ -1023,6 +1023,7 @@ error: negative image width: Image with zero or negative width created in function '%s' negative image height: Image with zero or negative height created in function '%s' can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. + symbol image has alpha: For best results, image should be black and white with no transparency. # error from files no card fields: Game '%s' does not have any card fields. Define at least one card field. diff --git a/data/es.mse-locale/locale b/data/es.mse-locale/locale index 36762da1..f5f21dc2 100644 --- a/data/es.mse-locale/locale +++ b/data/es.mse-locale/locale @@ -1095,6 +1095,8 @@ error: negative image height: Image with zero or negative height created in function '%s' #TODO: Localize can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. + #TODO: Localize + symbol image has alpha: For best results, image should be black and white with no transparency. # error from files #TODO: Localize diff --git a/data/fr.mse-locale/locale b/data/fr.mse-locale/locale index 5565b8fb..ac93740c 100644 --- a/data/fr.mse-locale/locale +++ b/data/fr.mse-locale/locale @@ -1022,6 +1022,7 @@ error: negative image width: Image de largeur nulle ou négative créée par la fonction '%s' negative image height: Image de hauteur nulle ou négative créée par la fonction '%s' can't load image: Échec du chargement de l'image. Assurez-vous que le format réel de l'image corresponde à son extension enregistrée. + symbol image has alpha: Pour un résultat optimal, l'image doit être en noir et blanc sans transparence. # error from files no card fields: Le jeu '%s' ne contient aucun champ de carte. Définissez au moins un champ de carte. diff --git a/data/it.mse-locale/locale b/data/it.mse-locale/locale index 3e6a99d7..8a2b6de8 100644 --- a/data/it.mse-locale/locale +++ b/data/it.mse-locale/locale @@ -1022,6 +1022,7 @@ error: negative image width: Immagine con larghezza zero o negativa creata nella funzione '%s' negative image height: Immagine con altezza zero o negativa creata nella funzione '%s' can't load image: Impossibile caricare l'immagine. Assicurarsi che il formato effettivo dell'immagine corrisponda all'estensione salvata. + symbol image has alpha: Per ottenere risultati ottimali, l'immagine dovrebbe essere in bianco e nero, senza trasparenza. # error from files no card fields: Il gioco '%s' non ha campi carta. Definisci almeno un campo carta. diff --git a/data/jp.mse-locale/locale b/data/jp.mse-locale/locale index aad1c9b0..5b492816 100644 --- a/data/jp.mse-locale/locale +++ b/data/jp.mse-locale/locale @@ -1095,6 +1095,8 @@ error: negative image height: Image with zero or negative height created in function '%s' #TODO: Localize can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. + #TODO: Localize + symbol image has alpha: For best results, image should be black and white with no transparency. # error from files #TODO: Localize diff --git a/data/ko.mse-locale/locale b/data/ko.mse-locale/locale index 5f6dc6bf..ef59b9ac 100644 --- a/data/ko.mse-locale/locale +++ b/data/ko.mse-locale/locale @@ -1101,6 +1101,8 @@ error: negative image height: Image with zero or negative height created in function '%s' #TODO: Localize can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. + #TODO: Localize + symbol image has alpha: For best results, image should be black and white with no transparency. # error from files #TODO: Localize diff --git a/data/pl.mse-locale/locale b/data/pl.mse-locale/locale index 9372d742..867ecf0e 100644 --- a/data/pl.mse-locale/locale +++ b/data/pl.mse-locale/locale @@ -1151,6 +1151,8 @@ error: negative image height: Image with zero or negative height created in function '%s' #TODO: Localize can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. + #TODO: Localize + symbol image has alpha: For best results, image should be black and white with no transparency. # error from files #TODO: Localize diff --git a/data/pt-br.mse-locale/locale b/data/pt-br.mse-locale/locale index e14efe5b..9644c59c 100644 --- a/data/pt-br.mse-locale/locale +++ b/data/pt-br.mse-locale/locale @@ -1023,6 +1023,7 @@ error: negative image width: Imagem com largura zero ou negativa criada na função '%s' negative image height: Imagem com altura zero ou negativa criada na função '%s' can't load image: Falha ao carregar a imagem. Verifique se o formato real da imagem corresponde à extensão salva. + symbol image has alpha: Para obter melhores resultados, a imagem deve ser em preto e branco, sem transparência. # error from files no card fields: O jogo '%s' não possui campos de Card. Defina pelo menos um campo de Card. diff --git a/data/ru.mse-locale/locale b/data/ru.mse-locale/locale index 65a60139..997545b6 100644 --- a/data/ru.mse-locale/locale +++ b/data/ru.mse-locale/locale @@ -1147,6 +1147,8 @@ error: negative image height: Image with zero or negative height created in function '%s' #TODO: Localize can't load image: Failed to load image. Ensure the image's actual format matches its saved extension. + #TODO: Localize + symbol image has alpha: For best results, image should be black and white with no transparency. # error from files #TODO: Localize Section diff --git a/src/data/action/value.cpp b/src/data/action/value.cpp index 56be57e5..b8f7d3f3 100644 --- a/src/data/action/value.cpp +++ b/src/data/action/value.cpp @@ -194,10 +194,11 @@ String compute_new_variable_value(const String& str, const String& tag, size_t s } while (end_i < str.size() && is_formatting_tag(str, end_i)) { - end_i = str.find_first_of(">", end_i) + 1; + end_i = str.find_first_of(">", end_i); + if (end_i != String::npos) end_i++; } String prefix(substr(str, 0, start_i)); - String suffix(substr(str, end_i)); + String suffix = end_i == String::npos ? String() : substr(str, end_i); String selection(substr(str, start_i, end_i - start_i)); // tally open tags that are variants of this tag diff --git a/src/data/format/image_to_symbol.cpp b/src/data/format/image_to_symbol.cpp index 153721ca..2be84cf2 100644 --- a/src/data/format/image_to_symbol.cpp +++ b/src/data/format/image_to_symbol.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -205,11 +206,13 @@ SymbolShapeP read_symbol_shape(const ImageData& data) { SymbolP image_to_symbol(Image& img) { - int w = img.GetWidth(), h = img.GetHeight(); - // 1. threshold the image + int w = img.GetWidth(), h = img.GetHeight(); + // get rid of alpha channel + fill_alpha(img, w, h); + // threshold the image greyscale(img); threshold(img.GetData(), w, h); - // 2. read as many symbol shapes as we can + // read as many symbol shapes as we can ImageData data = {w,h,img.GetData()}; SymbolP symbol(new Symbol); while (true) { @@ -221,6 +224,30 @@ SymbolP image_to_symbol(Image& img) { return symbol; } +void fill_alpha(Image& img, int w, int h) { + if (!img.HasAlpha() || w <= 0 || h <= 0) return; + Byte* alpha = img.GetAlpha(); + for (int i = 0; i < w*h ; ++i) { + if (alpha[i] < 255) { + Byte* pixels = img.GetData(); + Byte first_pixel = pixels[0]; + for (int j = 1; j < 3 * w * h; ++j) { + if (pixels[j] != first_pixel) { + wxMessageDialog dial = wxMessageDialog(nullptr, _ERROR_("symbol image has alpha")); + dial.ShowModal(); + break; + } + } + Image copy = img.Copy(); + memset(copy.GetData(), 255, 3 * w * h); + memset(pixels, 0, 3 * w * h); + memset(alpha, 255, w * h); + img.Paste(copy, 0, 0, wxIMAGE_ALPHA_BLEND_COMPOSE); + return; + } + } +} + SymbolP import_symbol(Image& img) { SymbolP symbol; if (is_mse1_symbol(img)) { diff --git a/src/data/format/image_to_symbol.hpp b/src/data/format/image_to_symbol.hpp index aa19db43..b8e3582a 100644 --- a/src/data/format/image_to_symbol.hpp +++ b/src/data/format/image_to_symbol.hpp @@ -23,6 +23,9 @@ bool is_mse1_symbol(const Image& img); /// Convert an image to a symbol, destroys the image in the process SymbolP image_to_symbol(Image& img); + +/// If an image has alpha, try to save it if it has only one color +void fill_alpha(Image& img, int w, int h); // ----------------------------------------------------------------------------- : Simplify symbol