diff --git a/doc/function/get_back_face.txt b/doc/function/get_back_face.txt new file mode 100644 index 00000000..9e8b3c6b --- /dev/null +++ b/doc/function/get_back_face.txt @@ -0,0 +1,12 @@ +Function: get_back_face + +--Usage-- +> get_back_face(input: card) + +Inspects a given [[type:card]]'s links to find one of type "Back Face", and returns the linked card. +Returns nil if no link of type "Back Face", or no card was found. + +--Parameters-- +! Parameter Type Description +| @input@ [[type:card]] The card whose links we'll inspect. +| @set@ [[type:set]] The set in which to look. This can be omited since 'set' is a predefined variable. diff --git a/doc/function/get_card_from_link.txt b/doc/function/get_cards_from_link.txt similarity index 50% rename from doc/function/get_card_from_link.txt rename to doc/function/get_cards_from_link.txt index c84ab731..31c0f91c 100644 --- a/doc/function/get_card_from_link.txt +++ b/doc/function/get_cards_from_link.txt @@ -1,10 +1,10 @@ -Function: get_card_from_link +Function: get_cards_from_link --Usage-- -> get_card_from_link(card: card, "link type") +> get_cards_from_link(card: card, input: "link type") -Inspects a given [[type:card]]'s links to find one of the given type, and returns the linked card. -Returns nil if no card was found. +Inspects a given [[type:card]]'s links to find those of the given type, and returns an array containing the linked cards. +Returns an empty array if no link of the given type, or no card was found. --Parameters-- ! Parameter Type Description diff --git a/doc/function/get_front_face.txt b/doc/function/get_front_face.txt new file mode 100644 index 00000000..0a2fbc22 --- /dev/null +++ b/doc/function/get_front_face.txt @@ -0,0 +1,12 @@ +Function: get_front_face + +--Usage-- +> get_front_face(input: card) + +Inspects a given [[type:card]]'s links to find one of type "Front Face", and returns the linked card. +Returns nil if no link of type "Front Face", or no card was found. + +--Parameters-- +! Parameter Type Description +| @input@ [[type:card]] The card whose links we'll inspect. +| @set@ [[type:set]] The set in which to look. This can be omited since 'set' is a predefined variable. diff --git a/doc/function/index.txt b/doc/function/index.txt index de23672b..44799762 100644 --- a/doc/function/index.txt +++ b/doc/function/index.txt @@ -109,8 +109,10 @@ These functions are built into the program, other [[type:function]]s can be defi | [[fun:get_card_styling]] Get the styling data of a [[type:card]]. | [[fun:get_card_stylesheet]] Get the stylesheet of a [[type:card]]. | [[fun:get_card_from_uid]] Find the [[type:card]] with the given uid. -| [[fun:get_card_from_link]] Find a [[type:card]] that has the given link type to the given [[type:card]]. -| [[fun:has_link]] Determine if the given the given [[type:card]] has a link of the given type. +| [[fun:get_cards_from_link]] Find all [[type:card]]s that have the given link type to the given [[type:card]]. +| [[fun:get_front_face]] Find a [[type:card]] that has the link type "Front Face" to the given [[type:card]]. +| [[fun:get_back_face]] Find a [[type:card]] that has the link type "Back Face" to the given [[type:card]]. +| [[fun:has_link]] Determine if the given [[type:card]] has a link of the given type. ! HTML export <<< | [[fun:to_html]] Convert [[type:tagged text]] to html. diff --git a/src/script/functions/basic.cpp b/src/script/functions/basic.cpp index 79162d5c..8c49e5fa 100644 --- a/src/script/functions/basic.cpp +++ b/src/script/functions/basic.cpp @@ -768,19 +768,147 @@ SCRIPT_FUNCTION(get_card_from_uid) { return script_nil; } -SCRIPT_FUNCTION(get_card_from_link) { +SCRIPT_FUNCTION(get_cards_from_link) { SCRIPT_PARAM_C(Set*, set); SCRIPT_PARAM_C(CardP, card); SCRIPT_PARAM_C(String, input); - String trimmed_input = input.Trim().Trim(false); - String uid = card->linked_relation_1 == trimmed_input ? card->linked_card_1 : - card->linked_relation_2 == trimmed_input ? card->linked_card_2 : - card->linked_relation_3 == trimmed_input ? card->linked_card_3 : - card->linked_relation_4 == trimmed_input ? card->linked_card_4 : - _(""); - if (uid.empty()) return script_nil; - FOR_EACH(other_card, set->cards) { - if (other_card->uid == uid) SCRIPT_RETURN(other_card); + ScriptCustomCollectionP ret(new ScriptCustomCollection()); + String trimmed_input = input.Trim().Trim(false); + if (card->linked_relation_1 == trimmed_input) { + String uid = card->linked_card_1; + bool found = false; + FOR_EACH(other_card, set->cards) { + if (other_card->uid == uid) { + ret->value.push_back(to_script(other_card)); + found = true; + break; + } + } + if (!found) { + card->linked_relation_1 = _(""); + card->linked_card_1 = _(""); + } + } + if (card->linked_relation_2 == trimmed_input) { + String uid = card->linked_card_2; + bool found = false; + FOR_EACH(other_card, set->cards) { + if (other_card->uid == uid) { + ret->value.push_back(to_script(other_card)); + found = true; + break; + } + } + if (!found) { + card->linked_relation_2 = _(""); + card->linked_card_2 = _(""); + } + } + if (card->linked_relation_3 == trimmed_input) { + String uid = card->linked_card_3; + bool found = false; + FOR_EACH(other_card, set->cards) { + if (other_card->uid == uid) { + ret->value.push_back(to_script(other_card)); + found = true; + break; + } + } + if (!found) { + card->linked_relation_3 = _(""); + card->linked_card_3 = _(""); + } + } + if (card->linked_relation_4 == trimmed_input) { + String uid = card->linked_card_4; + bool found = false; + FOR_EACH(other_card, set->cards) { + if (other_card->uid == uid) { + ret->value.push_back(to_script(other_card)); + found = true; + break; + } + } + if (!found) { + card->linked_relation_4 = _(""); + card->linked_card_4 = _(""); + } + } + return ret; +} + +SCRIPT_FUNCTION(get_front_face) { + SCRIPT_PARAM_C(Set*, set); + SCRIPT_PARAM_C(CardP, input); + if (input->linked_relation_1 == _("Front Face")) { + String uid = input->linked_card_1; + FOR_EACH(other_card, set->cards) { + if (other_card->uid == uid) SCRIPT_RETURN(other_card); + } + input->linked_relation_1 = _(""); + input->linked_card_1 = _(""); + } + if (input->linked_relation_2 == _("Front Face")) { + String uid = input->linked_card_2; + FOR_EACH(other_card, set->cards) { + if (other_card->uid == uid) SCRIPT_RETURN(other_card); + } + input->linked_relation_2 = _(""); + input->linked_card_2 = _(""); + } + if (input->linked_relation_3 == _("Front Face")) { + String uid = input->linked_card_3; + FOR_EACH(other_card, set->cards) { + if (other_card->uid == uid) SCRIPT_RETURN(other_card); + } + input->linked_relation_3 = _(""); + input->linked_card_3 = _(""); + } + if (input->linked_relation_4 == _("Front Face")) { + String uid = input->linked_card_4; + FOR_EACH(other_card, set->cards) { + if (other_card->uid == uid) SCRIPT_RETURN(other_card); + } + input->linked_relation_4 = _(""); + input->linked_card_4 = _(""); + } + return script_nil; +} + +SCRIPT_FUNCTION(get_back_face) { + SCRIPT_PARAM_C(Set*, set); + SCRIPT_PARAM_C(CardP, input); + if (input->linked_relation_1 == _("Back Face")) { + String uid = input->linked_card_1; + FOR_EACH(other_card, set->cards) { + if (other_card->uid == uid) SCRIPT_RETURN(other_card); + } + input->linked_relation_1 = _(""); + input->linked_card_1 = _(""); + } + if (input->linked_relation_2 == _("Back Face")) { + String uid = input->linked_card_2; + FOR_EACH(other_card, set->cards) { + if (other_card->uid == uid) SCRIPT_RETURN(other_card); + } + input->linked_relation_2 = _(""); + input->linked_card_2 = _(""); + } + if (input->linked_relation_3 == _("Back Face")) { + String uid = input->linked_card_3; + FOR_EACH(other_card, set->cards) { + if (other_card->uid == uid) SCRIPT_RETURN(other_card); + } + input->linked_relation_3 = _(""); + input->linked_card_3 = _(""); + } + if (input->linked_relation_4 == _("Back Face")) { + String uid = input->linked_card_4; + FOR_EACH(other_card, set->cards) { + if (other_card->uid == uid) SCRIPT_RETURN(other_card); + } + input->linked_relation_4 = _(""); + input->linked_card_4 = _(""); } return script_nil; } @@ -941,7 +1069,9 @@ void init_script_basic_functions(Context& ctx) { ctx.setVariable(_("random_select"), script_random_select); ctx.setVariable(_("random_select_many"), script_random_select_many); ctx.setVariable(_("get_card_from_uid"), script_get_card_from_uid); - ctx.setVariable(_("get_card_from_link"), script_get_card_from_link); + ctx.setVariable(_("get_cards_from_link"), script_get_cards_from_link); + ctx.setVariable(_("get_back_face"), script_get_back_face); + ctx.setVariable(_("get_front_face"), script_get_front_face); ctx.setVariable(_("has_link"), script_has_link); // keyword ctx.setVariable(_("expand_keywords"), script_expand_keywords); diff --git a/tools/website/drupal/mse-drupal-modules/highlight.inc b/tools/website/drupal/mse-drupal-modules/highlight.inc index 73fc78fe..9024c1a7 100644 --- a/tools/website/drupal/mse-drupal-modules/highlight.inc +++ b/tools/website/drupal/mse-drupal-modules/highlight.inc @@ -101,7 +101,9 @@ $built_in_functions = array( // cards 'new_card' =>'', 'has_link' =>'', - 'get_card_from_link' =>'', + 'get_front_face' =>'', + 'get_back_face' =>'', + 'get_cards_from_link' =>'', 'get_card_from_uid' =>'', 'get_card_styling' =>'', 'get_card_stylesheet' =>'',