Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: construction of new_card with images? (closes #36) #38

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/script/functions/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
#include <data/field/text.hpp>
#include <data/field/choice.hpp>
#include <data/field/package_choice.hpp>
#include <data/field/color.hpp>
#include <data/game.hpp>
#include <data/field/color.hpp>
#include <data/field/image.hpp>
#include <data/game.hpp>
#include <data/set.hpp>
#include <data/card.hpp>
#include <util/error.hpp>

Expand Down Expand Up @@ -44,7 +46,18 @@ SCRIPT_FUNCTION(new_card) {
} else if (PackageChoiceValue* pvalue = dynamic_cast<PackageChoiceValue*>(value)) {
pvalue->package_name = v->toString();
} else if (ColorValue* cvalue = dynamic_cast<ColorValue*>(value)) {
cvalue->value = v->toColor();
cvalue->value = v->toColor();
} else if (ImageValue* ivalue = dynamic_cast<ImageValue*>(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") : _(""));
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably pull these out to a common function since this is just the same as what happens when using the slice window.

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));
}
Expand Down