mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
documented new script functions
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1015 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+68
-70
@@ -1,4 +1,4 @@
|
|||||||
mse version: 0.3.6
|
mse version: 0.3.7
|
||||||
short name: Magic
|
short name: Magic
|
||||||
full name: Magic the Gathering
|
full name: Magic the Gathering
|
||||||
installer group: magic/game files
|
installer group: magic/game files
|
||||||
@@ -21,23 +21,23 @@ init script:
|
|||||||
############################################################## Sorting mana symbols
|
############################################################## Sorting mana symbols
|
||||||
|
|
||||||
# correctly sort a mana symbol (no guild mana)
|
# correctly sort a mana symbol (no guild mana)
|
||||||
mana_sort := sort_rule(order: "XYZI[0123456789]S(WUBRG)")
|
mana_sort := sort_text@(order: "XYZI[0123456789]S(WUBRG)")
|
||||||
# correctly sort guild mana
|
# correctly sort guild mana
|
||||||
mana_sort_guild := sort_rule(order: "[XYZI01234567890SWUBRG/|]") +
|
mana_sort_guild := sort_text@(order: "[XYZI01234567890SWUBRG/|]") +
|
||||||
replace_rule(
|
replace@(
|
||||||
match: "./.|././.|./././.|.[|]",
|
match: "./.|././.|./././.|.[|]",
|
||||||
in_context: "(^|[^/])<match>($|[^/])",
|
in_context: "(^|[^/])<match>($|[^/])",
|
||||||
replace: {sort_text(order:"in_place((WUBRG)")}
|
replace: {sort_text(order:"in_place((WUBRG)")}
|
||||||
)
|
)
|
||||||
mana_has_guild := match_rule(match: "[/|]") # Is there guild or half mana in the input?
|
mana_has_guild := match@(match: "[/|]") # Is there guild or half mana in the input?
|
||||||
# A mana cost can contain both normal and guild mana
|
# A mana cost can contain both normal and guild mana
|
||||||
mana_filter := to_upper + {
|
mana_filter := to_upper + {
|
||||||
if mana_has_guild() then mana_sort_guild()
|
if mana_has_guild() then mana_sort_guild()
|
||||||
else mana_sort()
|
else mana_sort()
|
||||||
}
|
}
|
||||||
# Like mana filter, only also allow tap symbols:
|
# Like mana filter, only also allow tap symbols:
|
||||||
tap_filter := sort_rule(order: "<TQ>")
|
tap_filter := sort_text@(order: "<TQ>")
|
||||||
mana_filter_t := replace_rule( # Remove [] used for forcing mana symbols
|
mana_filter_t := replace@( # Remove [] used for forcing mana symbols
|
||||||
match: "[\\[\\]]",
|
match: "[\\[\\]]",
|
||||||
replace: ""
|
replace: ""
|
||||||
) + { tap_filter() + mana_filter() }
|
) + { tap_filter() + mana_filter() }
|
||||||
@@ -59,8 +59,8 @@ init script:
|
|||||||
color_names_4 := { color_name(colors.0) + ", " + color_name(colors.1) + ", " + color_name(colors.2) + ", " + color_name(colors.3) }
|
color_names_4 := { color_name(colors.0) + ", " + color_name(colors.1) + ", " + color_name(colors.2) + ", " + color_name(colors.3) }
|
||||||
color_names_5 := { color_name(colors.0) + ", " + color_name(colors.1) + ", " + color_name(colors.2) + ", " + color_name(colors.3) + ", " + color_name(colors.4) }
|
color_names_5 := { color_name(colors.0) + ", " + color_name(colors.1) + ", " + color_name(colors.2) + ", " + color_name(colors.3) + ", " + color_name(colors.4) }
|
||||||
# color based on mana cost, input = a mana cost
|
# color based on mana cost, input = a mana cost
|
||||||
color_filter := sort_rule(order: "<WUBRG>")
|
color_filter := sort_text@(order: "<WUBRG>")
|
||||||
color_filterH := sort_rule(order: "</>")
|
color_filterH := sort_text@(order: "</>")
|
||||||
mana_to_color := {
|
mana_to_color := {
|
||||||
count := number_of_items(in: colors)
|
count := number_of_items(in: colors)
|
||||||
if hybrid == "" then
|
if hybrid == "" then
|
||||||
@@ -86,13 +86,13 @@ init script:
|
|||||||
# color based on land text box, input = textbox contents
|
# color based on land text box, input = textbox contents
|
||||||
color_text_filter :=
|
color_text_filter :=
|
||||||
# remove activation costs
|
# remove activation costs
|
||||||
replace_rule(
|
replace@(
|
||||||
match: "<sym[^>]*>[^<]+</sym[^>]*>"
|
match: "<sym[^>]*>[^<]+</sym[^>]*>"
|
||||||
in_context: "(?ix) (\\n|^)[^:]*<match>(,|:) | (pays?|additional|costs?)[ ]<match>",
|
in_context: "(?ix) (\\n|^)[^:]*<match>(,|:) | (pays?|additional|costs?)[ ]<match>",
|
||||||
replace: ""
|
replace: ""
|
||||||
) +
|
) +
|
||||||
# keep only mana
|
# keep only mana
|
||||||
filter_rule(match: "<sym[^>]*>([^<]+)") + color_filter;
|
filter_text@(match: "<sym[^>]*>([^<]+)") + color_filter;
|
||||||
# get the land frame for a "WUBRG"-style input.
|
# get the land frame for a "WUBRG"-style input.
|
||||||
land_multicolor := {
|
land_multicolor := {
|
||||||
count := number_of_items(in: colors)
|
count := number_of_items(in: colors)
|
||||||
@@ -137,12 +137,12 @@ init script:
|
|||||||
}
|
}
|
||||||
|
|
||||||
# The color of a card
|
# The color of a card
|
||||||
is_creature := match_rule(match: "(?i)Creature")
|
is_creature := match@(match: "(?i)Creature")
|
||||||
is_tribal := match_rule(match: "(?i)Tribal")
|
is_tribal := match@(match: "(?i)Tribal")
|
||||||
is_artifact := match_rule(match: "(?i)Artifact")
|
is_artifact := match@(match: "(?i)Artifact")
|
||||||
is_land := match_rule(match: "(?i)Land")
|
is_land := match@(match: "(?i)Land")
|
||||||
is_enchantment := match_rule(match: "(?i)Enchantment")
|
is_enchantment := match@(match: "(?i)Enchantment")
|
||||||
is_spell := match_rule(match: "(?i)Instant|Sorcery")
|
is_spell := match@(match: "(?i)Instant|Sorcery")
|
||||||
card_color := {
|
card_color := {
|
||||||
# usually the color of mana
|
# usually the color of mana
|
||||||
text_color := text_to_color(rules_text, land: is_land(type));
|
text_color := text_to_color(rules_text, land: is_land(type));
|
||||||
@@ -156,20 +156,18 @@ init script:
|
|||||||
};
|
};
|
||||||
|
|
||||||
# Number of colors in a card_color
|
# Number of colors in a card_color
|
||||||
card_color_color_count := {
|
card_color_color_count := count_chosen@(choices: "white,blue,black,red,green,artifact")
|
||||||
for each choice in ["white","blue","black","red","green","artifact"] do to_int(chosen())
|
|
||||||
}
|
|
||||||
# Clean up color field
|
# Clean up color field
|
||||||
card_color_filter := {
|
card_color_filter := {
|
||||||
colors := card_color_color_count()
|
colors := card_color_color_count()
|
||||||
if colors > 2 then
|
if colors > 2 then
|
||||||
input := remove_choice(choice: "overlay")
|
input := remove_choice(choice: "overlay")
|
||||||
if colors > 1 then (
|
if colors > 1 then (
|
||||||
input := require_choice(choice1: "multicolor", choice2: "hybrid", choice3: "land", choice4: "artifact")
|
input := require_choice(choices: "multicolor, hybrid, land, artifact")
|
||||||
input := exclusive_choice(choice1: "multicolor", choice2: "hybrid")
|
input := exclusive_choice(choices: "multicolor, hybrid")
|
||||||
input := require_exclusive_choice(choice1: "horizontal", choice2: "vertical", choice3: "radial", choice4: "overlay")
|
input := require_exclusive_choice(choices: "horizontal, vertical, radial, overlay")
|
||||||
) else
|
) else
|
||||||
input := remove_choice(choice1: "radial", choice2: "horizontal", choice3: "vertical", choice4: "overlay", choice5: "hybrid", choice6: "reversed")
|
input := remove_choice(choices: "radial, horizontal, vertical, overlay, hybrid, reversed")
|
||||||
if chosen(choice:"overlay") then
|
if chosen(choice:"overlay") then
|
||||||
input := remove_choice(choice: "reversed")
|
input := remove_choice(choice: "reversed")
|
||||||
input
|
input
|
||||||
@@ -192,7 +190,7 @@ init script:
|
|||||||
}
|
}
|
||||||
# Process the name for sorting rules (specifically, remove "The", "A", and "And" at the beginning, and make lowercase)
|
# Process the name for sorting rules (specifically, remove "The", "A", and "And" at the beginning, and make lowercase)
|
||||||
sort_name :=
|
sort_name :=
|
||||||
replace_rule (match: "^(The|An?) ", replace: "") +
|
replace@(match: "^(The|An?) ", replace: "") +
|
||||||
to_lower
|
to_lower
|
||||||
|
|
||||||
is_multicolor := { chosen(choice: "multicolor") and input != "artifact, multicolor" }
|
is_multicolor := { chosen(choice: "multicolor") and input != "artifact, multicolor" }
|
||||||
@@ -277,7 +275,7 @@ init script:
|
|||||||
|
|
||||||
# replaces — correctly
|
# replaces — correctly
|
||||||
add := "" # default is nothing
|
add := "" # default is nothing
|
||||||
separate_words := remove_tags + trim + replace_rule(match:" ", replace: {spacer})
|
separate_words := remove_tags + trim + replace@(match:" ", replace: {spacer})
|
||||||
for_mana_costs := format_cost := {
|
for_mana_costs := format_cost := {
|
||||||
if input.separator_before == "—" and contains(input.param, match: " ") then (
|
if input.separator_before == "—" and contains(input.param, match: " ") then (
|
||||||
if contains(input.param, match:",") then (
|
if contains(input.param, match:",") then (
|
||||||
@@ -289,16 +287,16 @@ init script:
|
|||||||
) else
|
) else
|
||||||
"{add}<param-mana>{input.param}</param-mana>"
|
"{add}<param-mana>{input.param}</param-mana>"
|
||||||
}
|
}
|
||||||
alternative_cost := replace_rule(match:"^[A-Z]", replace: { to_lower() })
|
alternative_cost := replace@(match:"^[A-Z]", replace: { to_lower() })
|
||||||
combined_cost := replace_rule(match:", [A-Z]", replace: { to_lower() })+
|
combined_cost := replace@(match:", [A-Z]", replace: { to_lower() })+
|
||||||
replace_rule(match:",", replace:" and")+
|
replace@(match:",", replace:" and")+
|
||||||
replace_rule(match:"^[STQXYZIWUBRG0-9/|]", in_context: "(^|[[:space:]])<match>", replace: "<sym-auto>&</sym-auto>")+
|
replace@(match:"^[STQXYZIWUBRG0-9/|]", in_context: "(^|[[:space:]])<match>", replace: "<sym-auto>&</sym-auto>")+
|
||||||
replace_rule(match:"^[A-Z]", replace: { to_lower() })
|
replace@(match:"^[A-Z]", replace: { to_lower() })
|
||||||
long_dash := replace_rule(match:"-", replace:"—")
|
long_dash := replace@(match:"-", replace:"—")
|
||||||
# Utilities for keywords
|
# Utilities for keywords
|
||||||
has_cc := { card.casting_cost != "" }
|
has_cc := { card.casting_cost != "" }
|
||||||
has_pt := { card.pt != "" }
|
has_pt := { card.pt != "" }
|
||||||
contains_target := match_rule(match:"(?i)([^a-z]|^)target([^a-z]|$)")
|
contains_target := match@(match:"(?i)([^a-z]|^)target([^a-z]|$)")
|
||||||
is_targeted := { contains_target(card.rule_text) }
|
is_targeted := { contains_target(card.rule_text) }
|
||||||
|
|
||||||
############################################################## The text box
|
############################################################## The text box
|
||||||
@@ -328,73 +326,73 @@ init script:
|
|||||||
| <param-cost><match>, # keyword argument that is declared as cost
|
| <param-cost><match>, # keyword argument that is declared as cost
|
||||||
";
|
";
|
||||||
# truncates the name of legends
|
# truncates the name of legends
|
||||||
legend_filter := replace_rule(match:", [A-Z,a-z,Æ,0-9,' ]*", replace: "" )+
|
legend_filter := replace@(match:", [A-Z,a-z,Æ,0-9,' ]*", replace: "" )+
|
||||||
replace_rule(match:"the [A-Z,a-z,Æ,0-9,' ]*", replace: "" )
|
replace@(match:"the [A-Z,a-z,Æ,0-9,' ]*", replace: "" )
|
||||||
# the rule text filter
|
# the rule text filter
|
||||||
# - adds mana symbols
|
# - adds mana symbols
|
||||||
# - makes text in parentheses italic
|
# - makes text in parentheses italic
|
||||||
text_filter :=
|
text_filter :=
|
||||||
# step 1 : remove all automatic tags
|
# step 1 : remove all automatic tags
|
||||||
tag_remove_rule(tag: "<sym-auto>") +
|
remove_tag@(tag: "<sym-auto>") +
|
||||||
tag_remove_rule(tag: "<i-auto>") +
|
remove_tag@(tag: "<i-auto>") +
|
||||||
# step 2 : reminder text for keywords
|
# step 2 : reminder text for keywords
|
||||||
expand_keywords_rule(
|
expand_keywords@(
|
||||||
default_expand: { chosen(choice:mode, set.automatic_reminder_text) },
|
default_expand: { chosen(choice:mode, set.automatic_reminder_text) },
|
||||||
combine: {
|
combine: {
|
||||||
if mode == "pseudo" then "<i-auto>{keyword}</i-auto>"
|
if mode == "pseudo" then "<i-auto>{keyword}</i-auto>"
|
||||||
else "{keyword}<atom-reminder-{mode}> ({process_english_hints(reminder)})</atom-reminder-{mode}>" }
|
else "{keyword}<atom-reminder-{mode}> ({process_english_hints(reminder)})</atom-reminder-{mode}>" }
|
||||||
) +
|
) +
|
||||||
# step 2b : move action keywords' reminder text to the end of the line
|
# step 2b : move action keywords' reminder text to the end of the line
|
||||||
replace_rule(
|
replace@(
|
||||||
match: "(<atom-reminder-action>(?:(?!<kw-).)*</atom-reminder-action></kw[^>]*>)(((?!<atom-reminder| ?<kw-)[^\n(])+)",
|
match: "(<atom-reminder-action>(?:(?!<kw-).)*</atom-reminder-action></kw[^>]*>)(((?!<atom-reminder| ?<kw-)[^\n(])+)",
|
||||||
replace: "\\2\\1"
|
replace: "\\2\\1"
|
||||||
) +
|
) +
|
||||||
# step 2c : remove duplicate reminder text
|
# step 2c : remove duplicate reminder text
|
||||||
replace_rule(
|
replace@(
|
||||||
match: "(<atom-reminder-[^>]*>[^)]+[)]</atom-reminder-[^>]*>)([^\n]+)\\1"
|
match: "(<atom-reminder-[^>]*>[^)]+[)]</atom-reminder-[^>]*>)([^\n]+)\\1"
|
||||||
replace: "\\2\\1"
|
replace: "\\2\\1"
|
||||||
) +
|
) +
|
||||||
# step 3a : expand shortcut words ~ and CARDNAME
|
# step 3a : expand shortcut words ~ and CARDNAME
|
||||||
replace_rule(
|
replace@(
|
||||||
match: "~|~THIS~|CARDNAME",
|
match: "~|~THIS~|CARDNAME",
|
||||||
in_context: "(^|[[:space:]]|\\()<match>", # TODO: Allow any punctuation before
|
in_context: "(^|[[:space:]]|\\()<match>", # TODO: Allow any punctuation before
|
||||||
replace: "<atom-cardname></atom-cardname>"
|
replace: "<atom-cardname></atom-cardname>"
|
||||||
) +
|
) +
|
||||||
# step 3b : expand shortcut words ` and shortened LEGENDNAME
|
# step 3b : expand shortcut words ` and shortened LEGENDNAME
|
||||||
replace_rule(
|
replace@(
|
||||||
match: "LEGENDNAME",
|
match: "LEGENDNAME",
|
||||||
in_context: "(^|[[:space:]]|\\()<match>", # TODO: Allow any punctuation before
|
in_context: "(^|[[:space:]]|\\()<match>", # TODO: Allow any punctuation before
|
||||||
replace: "<atom-legname></atom-legname>"
|
replace: "<atom-legname></atom-legname>"
|
||||||
) +
|
) +
|
||||||
# step 3c : fill in atom fields
|
# step 3c : fill in atom fields
|
||||||
tag_contents_rule(
|
tag_contents@(
|
||||||
tag: "<atom-cardname>",
|
tag: "<atom-cardname>",
|
||||||
contents: { if card_name=="" then "CARDNAME" else card_name }
|
contents: { if card_name=="" then "CARDNAME" else card_name }
|
||||||
) +
|
) +
|
||||||
tag_contents_rule(
|
tag_contents@(
|
||||||
tag: "<atom-legname>",
|
tag: "<atom-legname>",
|
||||||
contents: { if card_name=="" then "LEGENDNAME" else legend_filter(card_name) }
|
contents: { if card_name=="" then "LEGENDNAME" else legend_filter(card_name) }
|
||||||
) +
|
) +
|
||||||
# step 4 : explict non mana symbols
|
# step 4 : explict non mana symbols
|
||||||
replace_rule(
|
replace@(
|
||||||
match: "\\][STQXYZIWUBRG0-9/|]+\\[",
|
match: "\\][STQXYZIWUBRG0-9/|]+\\[",
|
||||||
replace: {"<nosym>" + mana_filter_t() + "</nosym>"} ) +
|
replace: {"<nosym>" + mana_filter_t() + "</nosym>"} ) +
|
||||||
# step 5 : add mana & tap symbols
|
# step 5 : add mana & tap symbols
|
||||||
replace_rule(
|
replace@(
|
||||||
match: "[STQXYZIWUBRG0-9/|]+",
|
match: "[STQXYZIWUBRG0-9/|]+",
|
||||||
in_context: mana_context,
|
in_context: mana_context,
|
||||||
replace: {"<sym-auto>" + mana_filter_t() + "</sym-auto>"} ) +
|
replace: {"<sym-auto>" + mana_filter_t() + "</sym-auto>"} ) +
|
||||||
# step 5b : add explict mana symbols
|
# step 5b : add explict mana symbols
|
||||||
replace_rule(
|
replace@(
|
||||||
match: "\\[[STQXYZIWUBRG0-9/|]+\\]",
|
match: "\\[[STQXYZIWUBRG0-9/|]+\\]",
|
||||||
replace: {"<sym>" + mana_filter_t() + "</sym>"} ) +
|
replace: {"<sym>" + mana_filter_t() + "</sym>"} ) +
|
||||||
# step 7 : italic reminder text
|
# step 7 : italic reminder text
|
||||||
replace_rule(
|
replace@(
|
||||||
match: "[(]([^)\n]|[(][^)\n]*[)])*[)]?",
|
match: "[(]([^)\n]|[(][^)\n]*[)])*[)]?",
|
||||||
in_context: "(^|[[:space:]])<match>|<atom-keyword><match></",
|
in_context: "(^|[[:space:]])<match>|<atom-keyword><match></",
|
||||||
replace: "<i-auto>&</i-auto>") +
|
replace: "<i-auto>&</i-auto>") +
|
||||||
# step 8 : automatic capitalization
|
# step 8 : automatic capitalization
|
||||||
replace_rule(
|
replace@(
|
||||||
match: "[a-z]",
|
match: "[a-z]",
|
||||||
in_context: "[(](<param-[a-z]*>)?<match>[^)]|[ ]*: <param-cost><match>|—<match>| — <match>",
|
in_context: "[(](<param-[a-z]*>)?<match>[^)]|[ ]*: <param-cost><match>|—<match>| — <match>",
|
||||||
replace: to_upper) +
|
replace: to_upper) +
|
||||||
@@ -406,27 +404,27 @@ init script:
|
|||||||
# - makes all text italic
|
# - makes all text italic
|
||||||
flavor_text_filter :=
|
flavor_text_filter :=
|
||||||
# step 1 : remove italic tags
|
# step 1 : remove italic tags
|
||||||
tag_remove_rule(tag: "<i-flavor>") +
|
remove_tag@(tag: "<i-flavor>") +
|
||||||
# step 2 : surround by <i> tags
|
# step 2 : surround by <i> tags
|
||||||
{ "<i-flavor>" + input + "</i-flavor>" } +
|
{ "<i-flavor>" + input + "</i-flavor>" } +
|
||||||
# curly quotes
|
# curly quotes
|
||||||
curly_quotes
|
curly_quotes
|
||||||
|
|
||||||
# Move the cursor past the separator in the p/t and type boxes
|
# Move the cursor past the separator in the p/t and type boxes
|
||||||
type_over_pt := replace_rule(match:"/$", replace:"")
|
type_over_pt := replace@(match:"/$", replace:"")
|
||||||
type_over_type := replace_rule(match:" ?-$", replace:"")
|
type_over_type := replace@(match:" ?-$", replace:"")
|
||||||
|
|
||||||
super_type_filter :=
|
super_type_filter :=
|
||||||
tag_remove_rule(tag: "<word-list-") +
|
remove_tag@(tag: "<word-list-") +
|
||||||
type_over_type +
|
type_over_type +
|
||||||
{ "<word-list-type>{input}</word-list-type>" }
|
{ "<word-list-type>{input}</word-list-type>" }
|
||||||
|
|
||||||
space_to_wltags := replace_rule(match:"( +|<soft> </soft>)",
|
space_to_wltags := replace@(match:"( +|<soft> </soft>)",
|
||||||
replace:{"</word-list-{list_type}>{_1}<word-list-{list_type}>"})
|
replace:{"</word-list-{list_type}>{_1}<word-list-{list_type}>"})
|
||||||
sub_type_filter :=
|
sub_type_filter :=
|
||||||
tag_remove_rule(tag: "<word-list-") +
|
remove_tag@(tag: "<word-list-") +
|
||||||
replace_rule(match: " </soft>$", replace: "") + # remove trailing soft space
|
replace@(match: " </soft>$", replace: "") + # remove trailing soft space
|
||||||
tag_remove_rule(tag: "<soft") +
|
remove_tag@(tag: "<soft") +
|
||||||
{ list_type := if is_creature(type) then "class"
|
{ list_type := if is_creature(type) then "class"
|
||||||
else if is_land(type) then "land"
|
else if is_land(type) then "land"
|
||||||
else if is_artifact(type) then "artifact"
|
else if is_artifact(type) then "artifact"
|
||||||
@@ -449,9 +447,9 @@ init script:
|
|||||||
}
|
}
|
||||||
|
|
||||||
# all sub types, for word list
|
# all sub types, for word list
|
||||||
space_to_comma := replace_rule(match:" ", replace:",")
|
space_to_comma := replace@(match:" ", replace:",")
|
||||||
only_first := replace_rule(match:" .*", replace:"")
|
only_first := replace@(match:" .*", replace:"")
|
||||||
only_next := replace_rule(match:"^[^ ]* ?", replace:"")
|
only_next := replace@(match:"^[^ ]* ?", replace:"")
|
||||||
all_sub_types := {
|
all_sub_types := {
|
||||||
for each card in set do
|
for each card in set do
|
||||||
if contains(card.super_type) then "," + space_to_comma(to_text(card.sub_type))
|
if contains(card.super_type) then "," + space_to_comma(to_text(card.sub_type))
|
||||||
@@ -472,7 +470,7 @@ init script:
|
|||||||
|
|
||||||
typesymbol_for :=
|
typesymbol_for :=
|
||||||
to_text +
|
to_text +
|
||||||
replace_rule(match: "(Legendary|Basic|Snow|World| )", replace: "") +
|
replace@(match: "(Legendary|Basic|Snow|World| )", replace: "") +
|
||||||
{ if input == "Creature" then "creature"
|
{ if input == "Creature" then "creature"
|
||||||
else if input == "Sorcery" then "sorcery"
|
else if input == "Sorcery" then "sorcery"
|
||||||
else if input == "Instant" then "instant"
|
else if input == "Instant" then "instant"
|
||||||
@@ -490,22 +488,22 @@ init script:
|
|||||||
############################################################## Statistics utilities
|
############################################################## Statistics utilities
|
||||||
|
|
||||||
# Converted mana cost
|
# Converted mana cost
|
||||||
is_half_mana := match_rule(match: "1/2|[|][WUBRGS]")
|
is_half_mana := match@(match: "1/2|[|][WUBRGS]")
|
||||||
is_zero_slash := match_rule(match: "^0/")
|
is_zero_slash := match@(match: "^0/")
|
||||||
is_colored_mana := match_rule(match: "[WUBRG]")
|
is_colored_mana := match@(match: "[WUBRG]")
|
||||||
only_numbers := filter_rule(match: "^[0123456789]+")
|
only_numbers := filter_text@(match: "^[0123456789]+")
|
||||||
cmc_split := break_rule(match: "(?ix) 1/2 | [|][WUBRG] | ([0-9]+(?!/2)|[WUBRGS])(/[WUBRGS])\{0,4} ")
|
cmc_split := break_text@(match: "(?ix) 1/2 | [|][WUBRG] | ([0-9]+(?!/2)|[WUBRGS])(/[WUBRGS])\{0,4} ")
|
||||||
cmc := to_text + { 0 +
|
cmc := to_text + {
|
||||||
for each sym in cmc_split() do (
|
for each sym in cmc_split() do (
|
||||||
numbers := only_numbers(sym)
|
numbers := only_numbers(sym)
|
||||||
if is_half_mana(sym) then 0.5
|
if is_half_mana(sym) then 0.5
|
||||||
else if is_zero_slash(sym) then 1 # 0/C
|
else if is_zero_slash(sym) then 1 # 0/C
|
||||||
else if numbers != "" then 1 * numbers
|
else if numbers != "" then to_int(numbers)
|
||||||
else 1 # all other symbols are 1
|
else 1 # all other symbols are 1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
colored_mana := to_text + { 0 +
|
colored_mana := to_text + {
|
||||||
for each sym in cmc_split() do (
|
for each sym in cmc_split() do (
|
||||||
numbers := only_numbers(sym)
|
numbers := only_numbers(sym)
|
||||||
if is_colored_mana(sym) then
|
if is_colored_mana(sym) then
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
Function: abs
|
||||||
|
|
||||||
|
DOC_MSE_VERSION: since 0.3.7
|
||||||
|
|
||||||
|
--Usage--
|
||||||
|
> abs(some_number)
|
||||||
|
|
||||||
|
Returns the absolute value of a number.
|
||||||
|
|
||||||
|
--Parameters--
|
||||||
|
! Parameter Type Description
|
||||||
|
| @input@ [[type:int]] or [[type:double]] Number to determine the absolute value of
|
||||||
|
|
||||||
|
--Examples--
|
||||||
|
> abs(1.5) == 1.5
|
||||||
|
> abs(-1) == 1
|
||||||
@@ -6,9 +6,15 @@ These functions are built into the program, other [[type:function]]s can be defi
|
|||||||
| [[fun:to_string]] Convert any value to a [[type:string]]
|
| [[fun:to_string]] Convert any value to a [[type:string]]
|
||||||
| [[fun:to_int]] Convert any value to a [[type:int]]
|
| [[fun:to_int]] Convert any value to a [[type:int]]
|
||||||
| [[fun:to_real]] Convert any value to a [[type:double]]
|
| [[fun:to_real]] Convert any value to a [[type:double]]
|
||||||
|
| [[fun:to_number]] Convert any value to a number
|
||||||
| [[fun:to_boolean]] Convert any value to a [[type:boolean]]
|
| [[fun:to_boolean]] Convert any value to a [[type:boolean]]
|
||||||
| [[fun:to_color]] Convert any value to a [[type:color]]
|
| [[fun:to_color]] Convert any value to a [[type:color]]
|
||||||
|
|
||||||
|
! Numbers <<<
|
||||||
|
| [[fun:abs]] Absolute value
|
||||||
|
| [[fun:random_int]] Generate a random [[type:int]].
|
||||||
|
| [[fun:random_real]] Generate a random [[type:double]].
|
||||||
|
|
||||||
! Text manipulation <<<
|
! Text manipulation <<<
|
||||||
| [[fun:to_upper]] Convert a string to upper case, @"aBc" -> "ABC"@.
|
| [[fun:to_upper]] Convert a string to upper case, @"aBc" -> "ABC"@.
|
||||||
| [[fun:to_lower]] Convert a string to lower case, @"aBc" -> "abc"@.
|
| [[fun:to_lower]] Convert a string to lower case, @"aBc" -> "abc"@.
|
||||||
@@ -37,6 +43,8 @@ These functions are built into the program, other [[type:function]]s can be defi
|
|||||||
| [[fun:number_of_items]] Return the number of items in a list.
|
| [[fun:number_of_items]] Return the number of items in a list.
|
||||||
| [[fun:sort_list]] Sort a list.
|
| [[fun:sort_list]] Sort a list.
|
||||||
| [[fun:filter_list]] Filter a list, keeping only elements that match a predicate.
|
| [[fun:filter_list]] Filter a list, keeping only elements that match a predicate.
|
||||||
|
| [[fun:random_shuffle]] Randomly shuffle a list.
|
||||||
|
| [[fun:random_select]] Pick random elements from a list.
|
||||||
|
|
||||||
! Keywords <<<
|
! Keywords <<<
|
||||||
| [[fun:expand_keywords]] Expand the keywords in a piece of text.
|
| [[fun:expand_keywords]] Expand the keywords in a piece of text.
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
Function: random_int
|
||||||
|
|
||||||
|
DOC_MSE_VERSION: since 0.3.7
|
||||||
|
|
||||||
|
--Usage--
|
||||||
|
> random_int(begin: lower bound, end: upper bound)
|
||||||
|
|
||||||
|
Returns a random [[type:int]] between @begin@ and @end@.
|
||||||
|
By default @begin: 0@ is used.
|
||||||
|
The random number @x@ will be in the range @begin <= x < end@.
|
||||||
|
|
||||||
|
Since the result is random, calling the function twice will give a different answer.
|
||||||
|
|
||||||
|
--Parameters--
|
||||||
|
! Parameter Type Default Description
|
||||||
|
| @begin@ [[type:int]] @0@ Lower end point of the range the number will be in.
|
||||||
|
| @end@ [[type:int]] ''required'' Upper end point of the range the number will be in.
|
||||||
|
|
||||||
|
--Examples--
|
||||||
|
> random_int(end:10) == 2
|
||||||
|
> random_int(end:10) == 5
|
||||||
|
> random_int(begin:100, end:200) == 43
|
||||||
|
|
||||||
|
--See also--
|
||||||
|
| [[fun:random_real]] Generate a random [[type:double]].
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
Function: random_real
|
||||||
|
|
||||||
|
DOC_MSE_VERSION: since 0.3.7
|
||||||
|
|
||||||
|
--Usage--
|
||||||
|
> random_real(begin: lower bound, end: upper bound)
|
||||||
|
|
||||||
|
Returns a random [[type:double]] between @begin@ and @end@.
|
||||||
|
By default the range @0.0@ to @1.0@ is used.
|
||||||
|
|
||||||
|
Since the result is random, calling the function twice will give a different answer.
|
||||||
|
|
||||||
|
--Parameters--
|
||||||
|
! Parameter Type Default Description
|
||||||
|
| @begin@ [[type:double]] @0.0@ Lower end point of the range the number will be in.
|
||||||
|
| @end@ [[type:double]] @1.0@ Upper end point of the range the number will be in.
|
||||||
|
|
||||||
|
--Examples--
|
||||||
|
> random_real() == 0.1451651461
|
||||||
|
> random_real() == 0.7521351365
|
||||||
|
> random_real(begin:100, end:200) == 193.2914351341
|
||||||
|
|
||||||
|
--See also--
|
||||||
|
| [[fun:random_int]] Generate a random [[type:int|integer number]].
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
Function: random_select
|
||||||
|
|
||||||
|
DOC_MSE_VERSION: since 0.3.7
|
||||||
|
|
||||||
|
--Usage--
|
||||||
|
> random_select(some_list, count: some_number, replace: some_boolean)
|
||||||
|
|
||||||
|
Randomly select a number of items from a list.
|
||||||
|
|
||||||
|
If the @count@ parameter is not given, then a single item is picked at random.
|
||||||
|
|
||||||
|
Otherwise @count@ ''different'' items are selected (selection without replacment).
|
||||||
|
Setting the @replace@ parameter allows the same item to occur more than once in the result (selection with replacment).
|
||||||
|
|
||||||
|
Since the result is random, calling the function twice will give a different answer.
|
||||||
|
|
||||||
|
--Parameters--
|
||||||
|
! Parameter Type Description
|
||||||
|
| @input@ [[type:list]] List to shuffle.
|
||||||
|
| @count@ [[type:int]] Number of items to select.
|
||||||
|
| @replace@ [[type:boolean]] Select with replacement?
|
||||||
|
|
||||||
|
--Examples--
|
||||||
|
> random_select([1,2,3,4]) == 4
|
||||||
|
> random_select([1,2,3,4]) == 2
|
||||||
|
> random_select([1,2,3,4], count:3) == [2,3,1]
|
||||||
|
> random_select([1,2,3,4], count:3) == [3,1,4]
|
||||||
|
> random_select([1,2,3,4], count:3, replace: true) == [2,3,2]
|
||||||
|
> random_select([1,2,3,4], count:3, replace: true) == [1,3,4]
|
||||||
|
|
||||||
|
--See also--
|
||||||
|
| [[fun:random_shuffle]] Randomly shuffle a list.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
Function: random_shuffle
|
||||||
|
|
||||||
|
DOC_MSE_VERSION: since 0.3.7
|
||||||
|
|
||||||
|
--Usage--
|
||||||
|
> random_shuffle(some_list)
|
||||||
|
|
||||||
|
Randomly shuffle a list, putting the elements in a different order.
|
||||||
|
|
||||||
|
Since the result is random, calling the function twice will give a different answer.
|
||||||
|
|
||||||
|
--Parameters--
|
||||||
|
! Parameter Type Description
|
||||||
|
| @input@ [[type:list]] List to shuffle.
|
||||||
|
|
||||||
|
--Examples--
|
||||||
|
> random_shuffle([1,2,3,4]) == [4,1,2,3]
|
||||||
|
> random_shuffle([1,2,3,4]) == [2,3,4,1]
|
||||||
|
|
||||||
|
--See also--
|
||||||
|
| [[fun:random_select]] Pick random elements from a list.
|
||||||
@@ -16,9 +16,11 @@ Convert any value to a [[type:int]].
|
|||||||
| @input@ ''any type'' Value to convert to an integer number
|
| @input@ ''any type'' Value to convert to an integer number
|
||||||
|
|
||||||
--Examples--
|
--Examples--
|
||||||
> to_int(1.5) == "1"
|
> to_int(1.5) == "1"
|
||||||
> to_int("15") == "15"
|
> to_int("15") == "15"
|
||||||
> to_int(true) == 1
|
> to_int(true) == 1
|
||||||
|
> to_int(rgb(255,255,255)) == 255
|
||||||
|
|
||||||
--See also--
|
--See also--
|
||||||
| [[fun:to_real]] Convert any value to a [[type:double]]
|
| [[fun:to_real]] Convert any value to a [[type:double]]
|
||||||
|
| [[fun:to_number]] Convert any value to a number
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
Function: to_number
|
||||||
|
|
||||||
|
DOC_MSE_VERSION: since 0.3.7
|
||||||
|
|
||||||
|
--Usage--
|
||||||
|
> to_number(any value)
|
||||||
|
|
||||||
|
Convert any value to a number.
|
||||||
|
If the number can be represented as an [[type:int|integer number]] that is done.
|
||||||
|
Otherwise it is converted to a [[type:double]].
|
||||||
|
|
||||||
|
|
||||||
|
--Parameters--
|
||||||
|
! Parameter Type Description
|
||||||
|
| @input@ ''any type'' Value to convert to a number
|
||||||
|
|
||||||
|
--Examples--
|
||||||
|
> to_number(1) == 1
|
||||||
|
> to_number(1.5) == 1.5
|
||||||
|
> to_number("1") == 1
|
||||||
|
> to_number("1.5") == 1.5
|
||||||
|
|
||||||
|
--See also--
|
||||||
|
| [[fun:to_int]] Convert any value to a [[type:int]]
|
||||||
|
| [[fun:to_real]] Convert any value to a [[type:double]]
|
||||||
@@ -14,7 +14,8 @@ Convert any value to a [[type:double]].
|
|||||||
|
|
||||||
--Examples--
|
--Examples--
|
||||||
> to_real(1) == 1.0
|
> to_real(1) == 1.0
|
||||||
> to_real("1.5") == "1.5"
|
> to_real("1.5") == 1.5
|
||||||
|
|
||||||
--See also--
|
--See also--
|
||||||
| [[fun:to_int]] Convert any value to a [[type:int]]
|
| [[fun:to_int]] Convert any value to a [[type:int]]
|
||||||
|
| [[fun:to_number]] Convert any value to a number
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ See also:
|
|||||||
| @a / b@ [[script:operators|Floating point division]]
|
| @a / b@ [[script:operators|Floating point division]]
|
||||||
| @a div b@ [[script:operators|Integer division]]
|
| @a div b@ [[script:operators|Integer division]]
|
||||||
| @a mod b@ [[script:operators|Remainder]]
|
| @a mod b@ [[script:operators|Remainder]]
|
||||||
|
| @a ^ b@ [[script:operators|Exponentiation]]
|
||||||
| @not a@ [[type:boolean|Boolean not]]
|
| @not a@ [[type:boolean|Boolean not]]
|
||||||
| @a and b@ [[type:boolean|Boolean conjunction]]
|
| @a and b@ [[type:boolean|Boolean conjunction]]
|
||||||
| @a or b@ [[type:boolean|Boolean disjunction]]
|
| @a or b@ [[type:boolean|Boolean disjunction]]
|
||||||
|
|||||||
@@ -10,8 +10,11 @@ MSE script supports most basic mathamatical operators:
|
|||||||
| @a - b@ @3 - 2 == 1@ Substract two numbers
|
| @a - b@ @3 - 2 == 1@ Substract two numbers
|
||||||
| @a * b@ @3 * 2 == 6@ Multiply two numbers
|
| @a * b@ @3 * 2 == 6@ Multiply two numbers
|
||||||
| @a / b@ @3 / 2 == 1.5@ Divide two numbers. Does not round, always produces a [[type:double]].
|
| @a / b@ @3 / 2 == 1.5@ Divide two numbers. Does not round, always produces a [[type:double]].
|
||||||
| @a div b@ @3 div 2 == 1@ Divide two numbers. Rounds towards zero, producing an [[type:int]].<br/>
|
| @a div b@ @3 div 2 == 1@ DOC_MSE_VERSION: since 0.3.7
|
||||||
|
Divide two numbers. Rounds towards zero, producing an [[type:int]].
|
||||||
| @a mod b@ @3 mod 2 == 1@ Take the remainder after integer division (modulo)
|
| @a mod b@ @3 mod 2 == 1@ Take the remainder after integer division (modulo)
|
||||||
|
| @a ^ b@ @3 ^ 2 == 9@ DOC_MSE_VERSION: since 0.3.7
|
||||||
|
Exponentation, raise a to the power b.<br/> The numbers can be [[type:double]]s, so to calculate a square root use @2^0.5 == 1.41421356237@.
|
||||||
| @-a@ @-(3 + 2) == -5@ Negate a number (make it negative if positive and vice versa)
|
| @-a@ @-(3 + 2) == -5@ Negate a number (make it negative if positive and vice versa)
|
||||||
|
|
||||||
===The + operator===
|
===The + operator===
|
||||||
|
|||||||
Reference in New Issue
Block a user