From 96d4cb8dfc0d0a809c7df9fcc1594694256146ea Mon Sep 17 00:00:00 2001 From: Brendan Hagan Date: Fri, 29 Jul 2022 21:58:42 -0400 Subject: [PATCH] feat: construction of new_card with images? (closes #36) So it's a bit of a hack stemming from card fields wanting to be primitive types (in this case a string filename), on top of that it wants the path to relative to the active set - so you _need_ a set to write image files against. That seems a bit contrary to how new_card wants to operate, but I might be understating its usefulness. --- src/script/functions/construction.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/script/functions/construction.cpp b/src/script/functions/construction.cpp index d876d579..36d1bfca 100644 --- a/src/script/functions/construction.cpp +++ b/src/script/functions/construction.cpp @@ -13,8 +13,10 @@ #include #include #include -#include -#include +#include +#include +#include +#include #include #include @@ -44,7 +46,18 @@ SCRIPT_FUNCTION(new_card) { } else if (PackageChoiceValue* pvalue = dynamic_cast(value)) { pvalue->package_name = v->toString(); } else if (ColorValue* cvalue = dynamic_cast(value)) { - cvalue->value = v->toColor(); + cvalue->value = v->toColor(); + } else if (ImageValue* ivalue = dynamic_cast(value)) { + SCRIPT_PARAM(Set*, set); + // If we're dealing with a String assume it's a filepath and try to load it then store it. + // TODO: + + // If we're dealing with an in-memory image, go ahead and store it to an internal file within the set. + if (v->type() == ScriptType::SCRIPT_IMAGE) { + LocalFileName new_image_file = set->newFileName(name, settings.internal_image_extension ? _(".png") : _("")); + v->toImage()->generate(GeneratedImage::Options()).SaveFile(set->nameOut(new_image_file), wxBITMAP_TYPE_PNG); + ivalue->filename = new_image_file; + } } else { throw ScriptError(format_string(_("Can not set value '%s', it is not of the right type"),name)); }