add get_front_face() get_back_face() get_cards_from_link()

This commit is contained in:
GenevensiS
2025-12-06 21:39:12 +01:00
parent 71e395aff6
commit ffbe3daf39
6 changed files with 176 additions and 18 deletions
+12
View File
@@ -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.
@@ -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
+12
View File
@@ -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.
+4 -2
View File
@@ -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.
+140 -10
View File
@@ -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);
ScriptCustomCollectionP ret(new ScriptCustomCollection());
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);
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);
@@ -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' =>'',