mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Allow symbol_variation script function to load images from the stylesheet by filename
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@977 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -385,19 +385,20 @@ bool BuiltInImage::operator == (const GeneratedImage& that) const {
|
||||
|
||||
// ----------------------------------------------------------------------------- : SymbolToImage
|
||||
|
||||
SymbolToImage::SymbolToImage(const String& filename, Age age, const SymbolVariationP& variation)
|
||||
: filename(filename), age(age), variation(variation)
|
||||
SymbolToImage::SymbolToImage(bool is_local, const String& filename, Age age, const SymbolVariationP& variation)
|
||||
: is_local(is_local), filename(filename), age(age), variation(variation)
|
||||
{}
|
||||
SymbolToImage::~SymbolToImage() {}
|
||||
|
||||
Image SymbolToImage::generate(const Options& opt) const {
|
||||
// TODO : use opt.width and opt.height?
|
||||
if (!opt.local_package) throw ScriptError(_("Can only load images in a context where an image is expected"));
|
||||
Package* package = is_local ? opt.local_package : opt.package;
|
||||
if (!package) throw ScriptError(_("Can only load images in a context where an image is expected"));
|
||||
SymbolP the_symbol;
|
||||
if (filename.empty()) {
|
||||
the_symbol = default_symbol();
|
||||
} else {
|
||||
the_symbol = opt.local_package->readFile<SymbolP>(filename);
|
||||
the_symbol = package->readFile<SymbolP>(filename);
|
||||
}
|
||||
int size = max(100, 3*max(opt.width,opt.height));
|
||||
if (opt.width <= 1 || opt.height <= 1) {
|
||||
@@ -410,7 +411,8 @@ Image SymbolToImage::generate(const Options& opt) const {
|
||||
}
|
||||
bool SymbolToImage::operator == (const GeneratedImage& that) const {
|
||||
const SymbolToImage* that2 = dynamic_cast<const SymbolToImage*>(&that);
|
||||
return that2 && filename == that2->filename
|
||||
return that2 && is_local == that2->is_local
|
||||
&& filename == that2->filename
|
||||
&& age == that2->age
|
||||
&& (variation == that2->variation ||
|
||||
*variation == *that2->variation // custom variation
|
||||
|
||||
@@ -289,19 +289,20 @@ class BuiltInImage : public GeneratedImage {
|
||||
/// Use a symbol as an image
|
||||
class SymbolToImage : public GeneratedImage {
|
||||
public:
|
||||
SymbolToImage(const String& filename, Age age, const SymbolVariationP& variation);
|
||||
SymbolToImage(bool is_local, const String& filename, Age age, const SymbolVariationP& variation);
|
||||
~SymbolToImage();
|
||||
virtual Image generate(const Options& opt) const;
|
||||
virtual bool operator == (const GeneratedImage& that) const;
|
||||
virtual bool local() const { return true; }
|
||||
virtual bool local() const { return is_local; }
|
||||
|
||||
#ifdef __WXGTK__
|
||||
virtual bool threadSafe() const { return false; }
|
||||
#endif
|
||||
private:
|
||||
SymbolToImage(const SymbolToImage&); // copy ctor
|
||||
bool is_local; ///< Use local package?
|
||||
String filename;
|
||||
Age age; ///< Age the symbol was last updated
|
||||
Age age; ///< Age the symbol was last updated
|
||||
SymbolVariationP variation;
|
||||
};
|
||||
|
||||
|
||||
@@ -112,9 +112,20 @@ SCRIPT_FUNCTION(drop_shadow) {
|
||||
|
||||
SCRIPT_FUNCTION(symbol_variation) {
|
||||
// find symbol
|
||||
SCRIPT_PARAM(ValueP, symbol);
|
||||
SymbolValueP value = dynamic_pointer_cast<SymbolValue>(symbol);
|
||||
SCRIPT_OPTIONAL_PARAM(String, variation) {
|
||||
SCRIPT_PARAM(ScriptValueP, symbol); // TODO: change to input?
|
||||
ScriptObject<ValueP>* valueO = dynamic_cast<ScriptObject<ValueP>*>(symbol.get());
|
||||
SymbolValue* value = valueO ? dynamic_cast<SymbolValue*>(valueO->getValue().get()) : nullptr;
|
||||
String filename;
|
||||
if (value) {
|
||||
filename = value->filename;
|
||||
} else if (valueO) {
|
||||
throw ScriptError(_ERROR_2_("can't convert", valueO->typeName(), _TYPE_("symbol" )));
|
||||
} else {
|
||||
filename = from_script<String>(symbol);
|
||||
}
|
||||
// known variation?
|
||||
SCRIPT_OPTIONAL_PARAM_(String, variation)
|
||||
if (value && variation_) {
|
||||
// find style
|
||||
SCRIPT_PARAM(Set*, set);
|
||||
SCRIPT_OPTIONAL_PARAM_(CardP, card);
|
||||
@@ -124,7 +135,7 @@ SCRIPT_FUNCTION(symbol_variation) {
|
||||
FOR_EACH(v, style->variations) {
|
||||
if (v->name == variation) {
|
||||
// found it
|
||||
return new_intrusive3<SymbolToImage>(value->filename, value->last_update, v);
|
||||
return new_intrusive4<SymbolToImage>(value, filename, value->last_update, v);
|
||||
}
|
||||
}
|
||||
throw ScriptError(_("Variation of symbol not found ('") + variation + _("')"));
|
||||
@@ -158,7 +169,7 @@ SCRIPT_FUNCTION(symbol_variation) {
|
||||
} else {
|
||||
throw ScriptError(_("Unknown fill type for symbol_variation: ") + fill_type);
|
||||
}
|
||||
return new_intrusive3<SymbolToImage>(value->filename, value->last_update, var);
|
||||
return new_intrusive4<SymbolToImage>(value, filename, value ? value->last_update : Age(), var);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user