From cd3c0887a678640f537744bf64235ea239c4566d Mon Sep 17 00:00:00 2001
From: GenevensiS <66968533+G-e-n-e-v-e-n-s-i-S@users.noreply.github.com>
Date: Sun, 28 Jan 2024 15:03:12 +0100
Subject: [PATCH] Fix multi-word subtypes (#31)
---
data/magic.mse-game/language | 40 +++++++++++++++++
data/magic.mse-game/script | 85 ++++++++++++++++++++++++------------
2 files changed, 96 insertions(+), 29 deletions(-)
diff --git a/data/magic.mse-game/language b/data/magic.mse-game/language
index eb9946625..d2ad5959d 100644
--- a/data/magic.mse-game/language
+++ b/data/magic.mse-game/language
@@ -14,6 +14,46 @@ lang_name := {
lang_setting := {
language()[input] or else languages[language().fallback][input] or else languages.English[input] or else ""
}
+
+spaced_sub_type_regex :=
+ replace@(match: "'", replace: "’") + ### standardize apostrophes
+ regex_escape + ### preemptive escape
+ replace@(match: ",", replace: "|") + ### match any sub type
+ replace@(match: "(^|\\|)[^ ]+(?=\\|)", replace: "") + ### eliminate sub types that don't contain spaces
+ replace@(match: "^\\|", replace: "") + ### eliminate starting |
+ replace@(match: "\\|$", replace: "") + ### eliminate trailing |
+ { "^(" + input + ")" } ### only match start of string
+complete_sub_type_list :=
+{
+ input.word_list_artifact + "," +
+ input.word_list_battle + "," +
+ input.word_list_dungeon + "," +
+ input.word_list_land + "," +
+ (for each submenu in input.word_lists_basic do submenu + ",") +
+ input.word_list_enchantment + "," +
+ input.word_list_spell + "," +
+ input.word_list_planeswalker + "," +
+ (for each submenu in input.word_lists_race do submenu + ",") +
+ (for each submenu in input.word_lists_class do submenu + ",") +
+ (for each submenu in input.word_lists_plane do submenu + ",")
+}
+replace_spaced_sub_type_map :=
+[
+ "de": replace@(replace: "", match: spaced_sub_type_regex(complete_sub_type_list(languages["Deutsch"])))
+ "en": replace@(replace: "", match: spaced_sub_type_regex(complete_sub_type_list(languages["English"])))
+ "es": replace@(replace: "", match: spaced_sub_type_regex(complete_sub_type_list(languages["Español"])))
+ "fr": replace@(replace: "", match: spaced_sub_type_regex(complete_sub_type_list(languages["Français"])))
+ "it": replace@(replace: "", match: spaced_sub_type_regex(complete_sub_type_list(languages["Italiano"])))
+ "ja": replace@(replace: "", match: spaced_sub_type_regex(complete_sub_type_list(languages["日本語"])))
+ "ko": replace@(replace: "", match: spaced_sub_type_regex(complete_sub_type_list(languages["한국어"])))
+ "pt-br": replace@(replace: "", match: spaced_sub_type_regex(complete_sub_type_list(languages["Português do Brasil"])))
+ "ru": replace@(replace: "", match: spaced_sub_type_regex(complete_sub_type_list(languages["Русский"])))
+ "zhs": replace@(replace: "", match: spaced_sub_type_regex(complete_sub_type_list(languages["汉语"])))
+ "zht": replace@(replace: "", match: spaced_sub_type_regex(complete_sub_type_list(languages["漢語"])))
+ "en_GB": replace@(replace: "", match: spaced_sub_type_regex(complete_sub_type_list(languages["English"])))
+ "en_CA": replace@(replace: "", match: spaced_sub_type_regex(complete_sub_type_list(languages["English"])))
+]
+
# language scripts
spanish_number := {
input := remove_tags(input)
diff --git a/data/magic.mse-game/script b/data/magic.mse-game/script
index 4cfa59aa7..9312939bb 100644
--- a/data/magic.mse-game/script
+++ b/data/magic.mse-game/script
@@ -1115,44 +1115,71 @@ super_type_filter := {
"<{tag}>{input}{tag}>"
}
-break_subtypes := split_text@(match: "[^<]*|?word-list-[^>]*>", include_empty:false) # splitting at word-list tags is for backwards compatibility, when atom-sep was not yet inserted everywhere.
-break_supertypes := split_text@(match: "[^<]*", include_empty:false)
-sub_type_filter := {
- input := remove_tag(tag: "" + subtype_separator + "", replace: "")
+ input := remove_tag(input, tag: "{part}")
- else
- languages[lang_name()].subtype_separator + "{part}"
- ) +
- (if length(parts) > 0 then
- # Add a new box at the end
- "{languages[lang_name()].subtype_separator}"
- else
- ""
+ if list_type_rest != nil then
+ (
+ ### Transform subtype_separators into spaces, we'll transform them back later
+ input := replace(input, match: subtype_separator, replace: " ")
+ input := replace(input, match: remove_tag(subtype_separator, tag: "" + sub_type + ""
+ else "" + sub_type + ""
+ ) else (
+ ### Check for single word sub types
+ split := split_at_spaces(input)
+ input := if length(split) > 1 then replace(input, match: "^" + regex_escape(split.0), replace: "") else ""
+ if i == 0 then "" + split.0 + ""
+ else "" + split.0 + "")))
)
- ) else input # do nothing
+ ### Add separators between types, keep additional spaces if there are more than one
+ sub_types := replace(sub_types, match: "(]*>)( *)("
+ else sub_types + "" + subtype_separator + ""
+ ) else input ### Do nothing if we don't know the type
}
# all sub types, for word list