From c42068f918c8758123f6d6754f17ddb9442ecbce 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: Tue, 20 Jan 2026 10:30:21 +0100 Subject: [PATCH] add set_metadata, get_metadata script functions --- doc/function/from_json.txt | 2 +- doc/function/get_back_face.txt | 2 +- doc/function/get_card_export_settings.txt | 2 +- doc/function/get_card_from_uid.txt | 2 +- doc/function/get_card_stylesheet.txt | 2 +- doc/function/get_card_styling.txt | 2 +- doc/function/get_front_face.txt | 2 +- doc/function/get_metadata.txt | 15 +++++++++++++++ doc/function/set_metadata.txt | 16 ++++++++++++++++ doc/function/to_json.txt | 5 +++-- src/script/functions/image.cpp | 18 ++++++++++++++++++ 11 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 doc/function/get_metadata.txt create mode 100644 doc/function/set_metadata.txt diff --git a/doc/function/from_json.txt b/doc/function/from_json.txt index d51968e6..60bf1daf 100644 --- a/doc/function/from_json.txt +++ b/doc/function/from_json.txt @@ -10,7 +10,7 @@ To see the required syntax, use an output of the [[fun:to_json]] function. --Parameters-- ! Parameter Type Description | @input@ [[type:string]] JSON string to convert to an MSE script value. -| @set@ [[type:set]] The active set. This can be omited since "set" is a predefined variable. +| @set@ [[type:set]] The active set. This can be omitted since "set" is a predefined variable. --Examples-- > add_card_to_set(from_json("\{\"mse_object_type\":\"card\", \"data\":\{\"name\":\"Ajani\", \"rarity\":\"mythic rare\"\}\}")) diff --git a/doc/function/get_back_face.txt b/doc/function/get_back_face.txt index 9e8b3c6b..49669d57 100644 --- a/doc/function/get_back_face.txt +++ b/doc/function/get_back_face.txt @@ -9,4 +9,4 @@ 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. +| @set@ [[type:set]] The set in which to look. This can be omitted since 'set' is a predefined variable. diff --git a/doc/function/get_card_export_settings.txt b/doc/function/get_card_export_settings.txt index b3a1f700..4e580c47 100644 --- a/doc/function/get_card_export_settings.txt +++ b/doc/function/get_card_export_settings.txt @@ -10,4 +10,4 @@ Returns and array whose first element is the zoom percentage, the second is the --Parameters-- ! Parameter Type Description | @input@ [[type:card]] The card you want to retrieve the export settings from. -| @set@ [[type:set]] The set the card belongs to. This can be omited since "set" is a predefined variable. +| @set@ [[type:set]] The set the card belongs to. This can be omitted since "set" is a predefined variable. diff --git a/doc/function/get_card_from_uid.txt b/doc/function/get_card_from_uid.txt index b8e5a54e..75ab4493 100644 --- a/doc/function/get_card_from_uid.txt +++ b/doc/function/get_card_from_uid.txt @@ -9,4 +9,4 @@ Returns nil if no card was found. --Parameters-- ! Parameter Type Description | @input@ [[type:string]] The uid of the card we want to retrieve. -| @set@ [[type:set]] The set in which to look. This can be omited since 'set' is a predefined variable. +| @set@ [[type:set]] The set in which to look. This can be omitted since 'set' is a predefined variable. diff --git a/doc/function/get_card_stylesheet.txt b/doc/function/get_card_stylesheet.txt index 7a3610a0..619eb124 100644 --- a/doc/function/get_card_stylesheet.txt +++ b/doc/function/get_card_stylesheet.txt @@ -10,7 +10,7 @@ This is for use in exporter scripts. In card scripts, use the "stylesheet" prede --Parameters-- ! Parameter Type Description | @input@ [[type:card]] The card you want to retrieve the stylesheet from. -| @set@ [[type:set]] The set the card belongs to. In an exporter script, this can be omited since "set" is a predefined variable. +| @set@ [[type:set]] The set the card belongs to. In an exporter script, this can be omitted since "set" is a predefined variable. --Examples-- > # Retrieve the card regions from the card's stylesheet diff --git a/doc/function/get_card_styling.txt b/doc/function/get_card_styling.txt index 2ae7cb42..92ff115a 100644 --- a/doc/function/get_card_styling.txt +++ b/doc/function/get_card_styling.txt @@ -10,7 +10,7 @@ This is for use in exporter scripts. In card scripts, use the 'styling' predefin --Parameters-- ! Parameter Type Description | @input@ [[type:card]] The card you want to retrieve the styling data from. -| @set@ [[type:set]] The set the card belongs to. In an exporter script, this can be omited since 'set' is a predefined variable. +| @set@ [[type:set]] The set the card belongs to. In an exporter script, this can be omitted since 'set' is a predefined variable. --Examples-- > # Retrieve the value "is foil" from the card's styling options diff --git a/doc/function/get_front_face.txt b/doc/function/get_front_face.txt index 0a2fbc22..5901f46d 100644 --- a/doc/function/get_front_face.txt +++ b/doc/function/get_front_face.txt @@ -9,4 +9,4 @@ 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. +| @set@ [[type:set]] The set in which to look. This can be omitted since 'set' is a predefined variable. diff --git a/doc/function/get_metadata.txt b/doc/function/get_metadata.txt new file mode 100644 index 00000000..dcb8cf45 --- /dev/null +++ b/doc/function/get_metadata.txt @@ -0,0 +1,15 @@ +Function: get_metadata + +--Usage-- +> get_metadata(input: image) + +Returns the metadata of an image, or an empty string if there isn't any. + +Metadata is only stored when an image is saved as a PNG. +It is saved in a uncompressed iTXt chunk with the key "Description". +If the image is saved as a JPG, the metadata is lost. + +--Parameters-- +! Parameter Type Description +| @input@ [[type:image]] The image whose metadata we'll get. +| @set@ [[type:set]] The active set. This can be omitted since 'set' is a predefined variable. diff --git a/doc/function/set_metadata.txt b/doc/function/set_metadata.txt new file mode 100644 index 00000000..73d7a3bc --- /dev/null +++ b/doc/function/set_metadata.txt @@ -0,0 +1,16 @@ +Function: set_metadata + +--Usage-- +> set_metadata(input: image, metadata: string) + +Returns a copy of the input image with the metadata set to the given string. + +Metadata is only stored when an image is saved as a PNG. +It is saved in a uncompressed iTXt chunk with the key "Description". +If the image is saved as a JPG, the metadata is lost. + +--Parameters-- +! Parameter Type Description +| @input@ [[type:image]] The image that will be copied. +| @metadata@ [[type:string]] The metadata that will be stored in the copy. +| @set@ [[type:set]] The active set. This can be omitted since 'set' is a predefined variable. diff --git a/doc/function/to_json.txt b/doc/function/to_json.txt index 3e160b91..db149c8c 100644 --- a/doc/function/to_json.txt +++ b/doc/function/to_json.txt @@ -3,13 +3,14 @@ Function: to_json --Usage-- > to_json(some_script_value) -Convert a [[type:list]], a [[type:map]], a [[type:card]], a [[type:keyword]], a [[type:pack_type]] or a [[type:set]] to a JSON string. +Convert a [[type:list]], a [[type:map]], a [[type:style]], a [[type:card]], a [[type:keyword]], a [[type:pack_type]] or a [[type:set]] to a JSON string. +This method is also useful for debugging purposes. --Parameters-- ! Parameter Type Description | @input@ some_script_value MSE script value to convert to a JSON string. -| @set@ [[type:set]] The active set. This can be omited since "set" is a predefined variable. +| @set@ [[type:set]] The active set. This can be omitted since "set" is a predefined variable. --Examples-- > to_json(card) diff --git a/src/script/functions/image.cpp b/src/script/functions/image.cpp index 3bc9881f..ac9e4ce2 100644 --- a/src/script/functions/image.cpp +++ b/src/script/functions/image.cpp @@ -65,6 +65,22 @@ SCRIPT_FUNCTION(download_image) { // ----------------------------------------------------------------------------- : Image functions +SCRIPT_FUNCTION(get_metadata) { + SCRIPT_PARAM(Set*, set); + SCRIPT_PARAM(GeneratedImageP, input); + Image img = input->generate(GeneratedImage::Options(0, 0, set)); + SCRIPT_RETURN(img.GetOption(wxIMAGE_OPTION_PNG_DESCRIPTION)); +} + +SCRIPT_FUNCTION(set_metadata) { + SCRIPT_PARAM(Set*, set); + SCRIPT_PARAM(GeneratedImageP, input); + SCRIPT_PARAM(String, metadata); + Image img = input->generate(GeneratedImage::Options(0, 0, set)); + img.SetOption(wxIMAGE_OPTION_PNG_DESCRIPTION, metadata); + return make_intrusive(img); +} + SCRIPT_FUNCTION(width_of) { SCRIPT_PARAM(Set*, set); SCRIPT_PARAM(GeneratedImageP, input); @@ -311,6 +327,8 @@ SCRIPT_FUNCTION(built_in_image) { void init_script_image_functions(Context& ctx) { ctx.setVariable(_("to_image"), script_to_image); ctx.setVariable(_("to_card_image"), script_to_card_image); + ctx.setVariable(_("set_metadata"), script_set_metadata); + ctx.setVariable(_("get_metadata"), script_get_metadata); ctx.setVariable(_("width_of"), script_width_of); ctx.setVariable(_("height_of"), script_height_of); ctx.setVariable(_("dimensions_of"), script_dimensions_of);