add download_image, refactor import_image

This commit is contained in:
GenevensiS
2025-12-28 13:59:23 +01:00
parent 3d0f21d483
commit 5c1b7b9dfc
13 changed files with 157 additions and 86 deletions
+6 -7
View File
@@ -68,9 +68,8 @@ inline static void set_container(Value* container, ScriptValueP& value, String k
cvalue->value = value->toColor();
}
else if (ImageValue* ivalue = dynamic_cast<ImageValue*>(container)) {
if (ExternalImage* image = dynamic_cast<ExternalImage*>(value.get())) {
wxFileName fname(image->toString());
ivalue->filename = LocalFileName::fromReadString(fname.GetName(), "");
if (ExternalImage* img = dynamic_cast<ExternalImage*>(value.get())) {
ivalue->filename = LocalFileName::fromReadString(img->toString(), "");
} else if (value->type() == SCRIPT_STRING) {
ivalue->filename = LocalFileName::fromReadString(value->toString(), "");
} else {
@@ -105,15 +104,15 @@ inline static bool set_stylesheet_container(const Game& game, CardP& card, Scrip
inline static bool set_builtin_container(const Game& game, CardP& card, ScriptValueP& value, String key_name, bool ignore_field_not_found) {
// check if the given value is for a built-in field, if found set it and return true
key_name = unified_form(key_name);
if (key_name == _("notes") || key_name == _("note")) {
if (key_name == _("card_notes") || key_name == _("notes") || key_name == _("note")) {
card->notes = value->toString();
return true;
}
else if (key_name == _("id") || key_name == _("uid")) {
else if (key_name == _("id") || key_name == _("uid") || key_name == _("uuid")) {
card->uid = value->toString();
return true;
}
else if (key_name == _("linked_card") || key_name == _("linked_card_1")) {
else if (key_name == _("linked_card_1") || key_name == _("linked_card")) {
card->linked_card_1 = value->toString();
return true;
}
@@ -129,7 +128,7 @@ inline static bool set_builtin_container(const Game& game, CardP& card, ScriptVa
card->linked_card_4 = value->toString();
return true;
}
else if (key_name == _("linked_relation") || key_name == _("linked_relation_1")) {
else if (key_name == _("linked_relation_1") || key_name == _("linked_relation")) {
card->linked_relation_1 = value->toString();
return true;
}
+8 -5
View File
@@ -19,7 +19,6 @@
#include <data/format/formats.hpp>
#include <gfx/generated_image.hpp>
#include <render/symbol/filter.hpp>
#include <cli/text_io_handler.hpp> // for MSE_CLI
void parse_enum(const String&, ImageCombine& out);
@@ -54,10 +53,13 @@ SCRIPT_FUNCTION(to_card_image) {
SCRIPT_FUNCTION(import_image) {
SCRIPT_PARAM(Set*, set);
SCRIPT_PARAM(String, input);
auto extImg = make_intrusive<ExternalImage>(input);
if (cli.haveConsole()) // makes sure generate() is called, but only once, when using the CLI
extImg->generate(GeneratedImage::Options(0, 0, set->stylesheet.get(), set));
return extImg;
return make_intrusive<ImportedImage>(set, input);
}
SCRIPT_FUNCTION(download_image) {
SCRIPT_PARAM(Set*, set);
SCRIPT_PARAM(String, input);
return make_intrusive<DownloadedImage>(set, input);
}
// ----------------------------------------------------------------------------- : Image functions
@@ -316,4 +318,5 @@ void init_script_image_functions(Context& ctx) {
ctx.setVariable(_("symbol_variation"), script_symbol_variation);
ctx.setVariable(_("built_in_image"), script_built_in_image);
ctx.setVariable(_("import_image"), script_import_image);
ctx.setVariable(_("download_image"), script_download_image);
}