mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Split script/functions.cpp into multiple files in new script/functions/ directory.
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@217 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -11,15 +11,6 @@
|
||||
#include <script/to_value.hpp>
|
||||
#include <util/dynamic_arg.hpp>
|
||||
#include <util/io/package.hpp>
|
||||
// for functions:
|
||||
#include <data/set.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <data/symbol.hpp>
|
||||
#include <data/field/symbol.hpp>
|
||||
#include <render/symbol/filter.hpp>
|
||||
#include <gui/util.hpp> // load_resource_image
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(SymbolStyle::VariationP);
|
||||
|
||||
IMPLEMENT_DYNAMIC_ARG(Package*, load_images_from, nullptr);
|
||||
|
||||
@@ -169,123 +160,3 @@ template <> void Writer::handle(const ScriptableImage& s) {
|
||||
template <> void GetDefaultMember::handle(const ScriptableImage& s) {
|
||||
handle(s.script.unparsed);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : Functions
|
||||
|
||||
SCRIPT_FUNCTION(linear_blend) {
|
||||
if (last_update_age() == 0) {
|
||||
ScriptImageP image1 = to_script_image(ctx.getVariable(_("image1")));
|
||||
ScriptImageP image2 = to_script_image(ctx.getVariable(_("image2")));
|
||||
SCRIPT_PARAM(double, x1); SCRIPT_PARAM(double, y1);
|
||||
SCRIPT_PARAM(double, x2); SCRIPT_PARAM(double, y2);
|
||||
linear_blend(image1->image, image2->image, x1, y1, x2, y2);
|
||||
return image1;
|
||||
} else {
|
||||
SCRIPT_RETURN(
|
||||
script_image_up_to_date(ctx.getVariable(_("image1"))) &&
|
||||
script_image_up_to_date(ctx.getVariable(_("image2")))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(masked_blend) {
|
||||
if (last_update_age() == 0) {
|
||||
ScriptImageP light = to_script_image(ctx.getVariable(_("light")));
|
||||
ScriptImageP dark = to_script_image(ctx.getVariable(_("dark")));
|
||||
ScriptImageP mask = to_script_image(ctx.getVariable(_("mask")));
|
||||
mask_blend(light->image, dark->image, mask->image);
|
||||
return light;
|
||||
} else {
|
||||
SCRIPT_RETURN(
|
||||
script_image_up_to_date(ctx.getVariable(_("light"))) &&
|
||||
script_image_up_to_date(ctx.getVariable(_("dark" ))) &&
|
||||
script_image_up_to_date(ctx.getVariable(_("mask" )))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(set_mask) {
|
||||
if (last_update_age() == 0) {
|
||||
ScriptImageP image = to_script_image(ctx.getVariable(_("image")));
|
||||
ScriptImageP mask = to_script_image(ctx.getVariable(_("mask")));
|
||||
set_alpha(image->image, mask->image);
|
||||
return image;
|
||||
} else {
|
||||
SCRIPT_RETURN(
|
||||
script_image_up_to_date(ctx.getVariable(_("image"))) &&
|
||||
script_image_up_to_date(ctx.getVariable(_("mask")))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool parse_enum(const String&, ImageCombine& out);
|
||||
|
||||
SCRIPT_FUNCTION(set_combine) {
|
||||
if (last_update_age() == 0) {
|
||||
SCRIPT_PARAM(String, combine);
|
||||
ScriptImageP image = to_script_image(ctx.getVariable(_("input")));
|
||||
// parse and set combine
|
||||
if (!parse_enum(combine, image->combine)) {
|
||||
throw ScriptError(_("Not a valid combine mode: '") + combine + _("'"));
|
||||
}
|
||||
return image;
|
||||
} else {
|
||||
SCRIPT_RETURN(
|
||||
script_image_up_to_date(ctx.getVariable(_("input")))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(symbol_variation) {
|
||||
SCRIPT_PARAM(ValueP, symbol);
|
||||
SymbolValueP value = dynamic_pointer_cast<SymbolValue>(symbol);
|
||||
if (last_update_age() == 0) {
|
||||
SCRIPT_PARAM(String, variation);
|
||||
// find set & style
|
||||
SCRIPT_PARAM(Set*, set);
|
||||
SCRIPT_OPTIONAL_PARAM_(CardP, card);
|
||||
SymbolStyleP style = dynamic_pointer_cast<SymbolStyle>(set->stylesheetFor(card)->styleFor(value->fieldP));
|
||||
if (!style) throw InternalError(_("Symbol value has a style of the wrong type"));
|
||||
// load symbol
|
||||
SymbolP symbol;
|
||||
if (value->filename.empty()) {
|
||||
symbol = default_symbol();
|
||||
} else {
|
||||
symbol = set->readFile<SymbolP>(value->filename);
|
||||
}
|
||||
// determine filter & render
|
||||
FOR_EACH(v, style->variations) {
|
||||
if (v->name == variation) {
|
||||
// render & filter
|
||||
return new_intrusive1<ScriptImage>(render_symbol(symbol, *v->filter, v->border_radius));
|
||||
}
|
||||
}
|
||||
throw ScriptError(_("Variation of symbol not found ('") + variation + _("')"));
|
||||
} else {
|
||||
// SCRIPT_RETURN(last_update_age() >= value->filename.last_update_age);
|
||||
SCRIPT_RETURN(last_update_age() > 1); // the symbol was created/loaded after program start,
|
||||
// don't use cached images
|
||||
// SCRIPT_RETURN(true);
|
||||
}
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(buildin_image) {
|
||||
if (last_update_age() == 0) {
|
||||
SCRIPT_PARAM(String, input);
|
||||
Image img = load_resource_image(input);
|
||||
if (!img.Ok()) throw ScriptError(_("There is no build in image '") + input + _("'"));
|
||||
return new_intrusive1<ScriptImage>(img);
|
||||
} else {
|
||||
SCRIPT_RETURN(true); // always up to date
|
||||
}
|
||||
}
|
||||
|
||||
void init_script_image_functions(Context& ctx) {
|
||||
ctx.setVariable(_("linear blend"), script_linear_blend);
|
||||
ctx.setVariable(_("masked blend"), script_masked_blend);
|
||||
ctx.setVariable(_("set mask"), script_set_mask);
|
||||
ctx.setVariable(_("set combine"), script_set_combine);
|
||||
ctx.setVariable(_("symbol variation"), script_symbol_variation);
|
||||
ctx.setVariable(_("buildin image"), script_buildin_image);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user