Merge pull request #36 from TomTkacz/master

implemented import_image function
This commit is contained in:
GenevensiS
2025-04-13 14:43:15 +02:00
committed by GitHub
8 changed files with 103 additions and 3 deletions
+6 -2
View File
@@ -14,6 +14,7 @@
#include <data/field/choice.hpp>
#include <data/field/package_choice.hpp>
#include <data/field/color.hpp>
#include <data/field/image.hpp>
#include <data/game.hpp>
#include <data/card.hpp>
#include <util/error.hpp>
@@ -33,7 +34,7 @@ SCRIPT_FUNCTION(new_card) {
// find value to update
IndexMap<FieldP,ValueP>::const_iterator value_it = new_card->data.find(name);
if (value_it == new_card->data.end()) {
throw ScriptError(format_string(_("Card doesn't have a field named '%s'"),name));
throw ScriptError(_ERROR_1_("no field with name", name));
}
Value* value = value_it->get();
// set the value
@@ -45,8 +46,11 @@ SCRIPT_FUNCTION(new_card) {
pvalue->package_name = v->toString();
} else if (ColorValue* cvalue = dynamic_cast<ColorValue*>(value)) {
cvalue->value = v->toColor();
} else if (ImageValue* ivalue = dynamic_cast<ImageValue*>(value)) {
wxFileName fname( static_cast<ExternalImage*>(v.get())->toString() );
ivalue->filename = LocalFileName::fromReadString( fname.GetName(), "");
} else {
throw ScriptError(format_string(_("Can not set value '%s', it is not of the right type"),name));
throw ScriptError(_ERROR_1_("can't set value", name));
}
}
SCRIPT_RETURN(new_card);
+11
View File
@@ -19,6 +19,7 @@
#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);
@@ -43,6 +44,15 @@ SCRIPT_FUNCTION(to_card_image) {
return make_intrusive<ArbitraryImage>(export_bitmap(set, input, (zoom / 100), deg_to_rad(angle)).ConvertToImage());
}
}
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;
}
// ----------------------------------------------------------------------------- : Image functions
@@ -269,4 +279,5 @@ void init_script_image_functions(Context& ctx) {
ctx.setVariable(_("drop_shadow"), script_drop_shadow);
ctx.setVariable(_("symbol_variation"), script_symbol_variation);
ctx.setVariable(_("built_in_image"), script_built_in_image);
ctx.setVariable(_("import_image"), script_import_image);
}