add add_card_to_set script function

make styling_data initializable in new_card script function
This commit is contained in:
GenevensiS
2025-07-19 18:18:33 +02:00
parent 45d48d67b1
commit d85f5a4927
6 changed files with 139 additions and 20 deletions
+21
View File
@@ -0,0 +1,21 @@
Function: add_card_to_set
--Usage--
> add_card_to_set(card, set: set)
Add a [[type:card]] to a [[type:set]].
If the input is a collection, all cards contained inside will be added.
Returns true if a card was actually added to the set.
This is for use in the CLI.
--Parameters--
! Parameter Type Description
| @input@ [[type:card]] The card you want to add.
| @set@ [[type:set]] The set the card must belong to.
--Examples--
> # Create a new card and add it to the current set:
> add_card_to_set(new_card([]))
+2 -1
View File
@@ -101,8 +101,9 @@ These functions are built into the program, other [[type:function]]s can be defi
! Cards <<<
| [[fun:new_card]] Construct a new [[type:card]] object.
| [[fun:add_card_to_set]] Add a [[type:card]] to a [[type:set]].
| [[fun:get_card_styling]] Get the styling data of a [[type:card]].
| [[fun:get_card_styesheet]] Get the stylesheet of a [[type:card]].
| [[fun:get_card_stylesheet]] Get the stylesheet of a [[type:card]].
! HTML export <<<
| [[fun:to_html]] Convert [[type:tagged text]] to html.
+14 -8
View File
@@ -3,24 +3,30 @@ Function: new_card
--Usage--
> new_card(map_of_field_names_to_values)
Create a new [[type:card]] object not already in the set.
Creates a new [[type:card]] object. The card is not automatically added to a set. Use the [[fun:add_card_to_set]] function for that.
The argument is a map of values to set, for example @new_card([name: "My Card"])@ creates a card with the name @"My Card"@, and all other fields at their default value.
NOTE: you should use underscores instead of spaces in field names.
The argument is a map from card field names to values, for example @new_card([name: "My Card"])@ creates a card with the name @"My Card"@, and all other fields at their default value.
The map can also contain the following built-in keys: notes, id, linked_card_1 to linked_card_4, linked_relation_1 to linked_relation_4, stylesheet, and styling_data. For styling_data, the value must itself be a map from styling field names to values. Be sure to define a stylesheet before styling_data.
NOTE: you should use underscores instead of spaces in field names.
--Parameters--
! Parameter Type Description
| @input@ [[type:map]] of field names to field values Field values to set
| @ignore_field_not_found@ [[type:boolean]] Optional. If set to true, key/value pairs that don't correspond to a card field will be ignored instead of throwing.
| @ignore_field_not_found@ [[type:boolean]] Optional. If set to true, key/value pairs that don't correspond to a field will be ignored instead of throwing.
--Examples--
> # Create a new card
> my_card := new_card(
> [ name: "My Card"
>> , type: "Super cool"
> [ name: "My Card"
>> , rule_text: "This card is <i>mine</i>!"
>> , stylesheet: "magic-m15-adventure.mse-style"
>> , styling_data: [frames: "Reversed, vehicle", chop_main: "5,5"]
> ])
>
> # Write an image of the card to a file
> write_image_file(my_card, file: "my_card.jpg")
> write_image_file(my_card, file: "my_card.png")
> # Add the card to the current set
> add_card_to_set(my_card)