mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Implement unique IDs and card linking
This commit is contained in:
+133
-133
@@ -14,7 +14,7 @@
|
||||
#include <data/field/symbol.hpp>
|
||||
#include <render/symbol/filter.hpp>
|
||||
#include <gui/util.hpp> // load_resource_image
|
||||
#include <wx/wfstream.h>
|
||||
#include <wx/wfstream.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- : GeneratedImage
|
||||
|
||||
@@ -308,7 +308,7 @@ bool EnlargeImage::operator == (const GeneratedImage& that) const {
|
||||
// ----------------------------------------------------------------------------- : ResizeImage
|
||||
|
||||
Image ResizeImage::generate(const Options& opt) const {
|
||||
Image img = image->generate(opt);
|
||||
Image img = image->generate(opt);
|
||||
return resample(img, width, height);
|
||||
}
|
||||
bool ResizeImage::operator == (const GeneratedImage& that) const {
|
||||
@@ -321,16 +321,16 @@ bool ResizeImage::operator == (const GeneratedImage& that) const {
|
||||
// ----------------------------------------------------------------------------- : BleedEdgedImage
|
||||
|
||||
Image BleedEdgedImage::generate(const Options& opt) const {
|
||||
// create enlarged image
|
||||
// create enlarged image
|
||||
Image base_img = base_image->generate(opt);
|
||||
int w = base_img.GetWidth(), h = base_img.GetHeight();
|
||||
int w = base_img.GetWidth(), h = base_img.GetHeight();
|
||||
if (w <= 0 || h <= 0) {
|
||||
queue_message(MESSAGE_ERROR, _("Cannot add bleed edge to empty image"));
|
||||
queue_message(MESSAGE_ERROR, _("Cannot add bleed edge to empty image"));
|
||||
return base_img;
|
||||
}
|
||||
bool is_landscape = w > h;
|
||||
int dw = int(w * (horizontal_size > 0.0 ? horizontal_size : is_landscape ? 0.037 : 0.048));
|
||||
int dh = int(h * (vertical_size > 0.0 ? vertical_size : is_landscape ? 0.048 : 0.037));
|
||||
}
|
||||
bool is_landscape = w > h;
|
||||
int dw = int(w * (horizontal_size > 0.0 ? horizontal_size : is_landscape ? 0.037 : 0.048));
|
||||
int dh = int(h * (vertical_size > 0.0 ? vertical_size : is_landscape ? 0.048 : 0.037));
|
||||
if (dw <= 0 && dh <= 0) {
|
||||
return base_img;
|
||||
}
|
||||
@@ -339,119 +339,119 @@ Image BleedEdgedImage::generate(const Options& opt) const {
|
||||
Image img = wxImage(width, height, false);
|
||||
img.InitAlpha();
|
||||
Byte* data = img.GetData();
|
||||
Byte* alpha = img.GetAlpha();
|
||||
// fill with background color
|
||||
Byte* alpha = img.GetAlpha();
|
||||
// fill with background color
|
||||
for (UInt i = 0; i < size; ++i) {
|
||||
data[3 * i + 0] = background_color.Red();
|
||||
data[3 * i + 1] = background_color.Green();
|
||||
data[3 * i + 2] = background_color.Blue();
|
||||
alpha[i] = background_color.Alpha();
|
||||
}
|
||||
// paste original image
|
||||
img.Paste(base_img, dw, dh, wxIMAGE_ALPHA_BLEND_COMPOSE);
|
||||
// fill top left corner
|
||||
// paste original image
|
||||
img.Paste(base_img, dw, dh, wxIMAGE_ALPHA_BLEND_COMPOSE);
|
||||
// fill top left corner
|
||||
int pixel;
|
||||
int x_start = 0;
|
||||
int y_start = 0;
|
||||
int ref = dw + dh * width;
|
||||
int x_start = 0;
|
||||
int y_start = 0;
|
||||
int ref = dw + dh * width;
|
||||
for (int y = 0; y < dh; ++y) {
|
||||
for (int x = 0; x < dw; ++x) {
|
||||
for (int x = 0; x < dw; ++x) {
|
||||
pixel = x_start + x + (y_start + y) * width;
|
||||
data[3 * pixel + 0] = data[3 * ref + 0];
|
||||
data[3 * pixel + 1] = data[3 * ref + 1];
|
||||
data[3 * pixel + 2] = data[3 * ref + 2];
|
||||
alpha[pixel] = alpha[ref];
|
||||
}
|
||||
}
|
||||
// fill top right corner
|
||||
x_start = width - dw;
|
||||
y_start = 0;
|
||||
ref = x_start - 1 + dh * width;
|
||||
for (int y = 0; y < dh; ++y) {
|
||||
for (int x = 0; x < dw; ++x) {
|
||||
pixel = x_start + x + (y_start + y) * width;
|
||||
data[3 * pixel + 0] = data[3 * ref + 0];
|
||||
data[3 * pixel + 1] = data[3 * ref + 1];
|
||||
data[3 * pixel + 2] = data[3 * ref + 2];
|
||||
alpha[pixel] = alpha[ref];
|
||||
}
|
||||
}
|
||||
// fill bottom left corner
|
||||
x_start = 0;
|
||||
y_start = height - dh;
|
||||
ref = dw + (y_start - 1) * width;
|
||||
for (int y = 0; y < dh; ++y) {
|
||||
for (int x = 0; x < dw; ++x) {
|
||||
pixel = x_start + x + (y_start + y) * width;
|
||||
data[3 * pixel + 0] = data[3 * ref + 0];
|
||||
data[3 * pixel + 1] = data[3 * ref + 1];
|
||||
data[3 * pixel + 2] = data[3 * ref + 2];
|
||||
alpha[pixel] = alpha[ref];
|
||||
alpha[pixel] = alpha[ref];
|
||||
}
|
||||
}
|
||||
// fill bottom right corner
|
||||
x_start = width - dw;
|
||||
y_start = height - dh;
|
||||
// fill top right corner
|
||||
x_start = width - dw;
|
||||
y_start = 0;
|
||||
ref = x_start - 1 + dh * width;
|
||||
for (int y = 0; y < dh; ++y) {
|
||||
for (int x = 0; x < dw; ++x) {
|
||||
pixel = x_start + x + (y_start + y) * width;
|
||||
data[3 * pixel + 0] = data[3 * ref + 0];
|
||||
data[3 * pixel + 1] = data[3 * ref + 1];
|
||||
data[3 * pixel + 2] = data[3 * ref + 2];
|
||||
alpha[pixel] = alpha[ref];
|
||||
}
|
||||
}
|
||||
// fill bottom left corner
|
||||
x_start = 0;
|
||||
y_start = height - dh;
|
||||
ref = dw + (y_start - 1) * width;
|
||||
for (int y = 0; y < dh; ++y) {
|
||||
for (int x = 0; x < dw; ++x) {
|
||||
pixel = x_start + x + (y_start + y) * width;
|
||||
data[3 * pixel + 0] = data[3 * ref + 0];
|
||||
data[3 * pixel + 1] = data[3 * ref + 1];
|
||||
data[3 * pixel + 2] = data[3 * ref + 2];
|
||||
alpha[pixel] = alpha[ref];
|
||||
}
|
||||
}
|
||||
// fill bottom right corner
|
||||
x_start = width - dw;
|
||||
y_start = height - dh;
|
||||
ref = (x_start - 1) + (y_start - 1) * width;
|
||||
for (int y = 0; y < dh; ++y) {
|
||||
for (int x = 0; x < dw; ++x) {
|
||||
for (int x = 0; x < dw; ++x) {
|
||||
pixel = x_start + x + (y_start + y) * width;
|
||||
data[3 * pixel + 0] = data[3 * ref + 0];
|
||||
data[3 * pixel + 1] = data[3 * ref + 1];
|
||||
data[3 * pixel + 2] = data[3 * ref + 2];
|
||||
alpha[pixel] = alpha[ref];
|
||||
alpha[pixel] = alpha[ref];
|
||||
}
|
||||
}
|
||||
// fill left border
|
||||
x_start = 0;
|
||||
y_start = dh;
|
||||
for (int y = 0; y < height - dh - dh; ++y) {
|
||||
}
|
||||
// fill left border
|
||||
x_start = 0;
|
||||
y_start = dh;
|
||||
for (int y = 0; y < height - dh - dh; ++y) {
|
||||
ref = dw + (y_start + y) * width;
|
||||
for (int x = 0; x < dw; ++x) {
|
||||
for (int x = 0; x < dw; ++x) {
|
||||
pixel = x_start + x + (y_start + y) * width;
|
||||
data[3 * pixel + 0] = data[3 * ref + 0];
|
||||
data[3 * pixel + 1] = data[3 * ref + 1];
|
||||
data[3 * pixel + 2] = data[3 * ref + 2];
|
||||
alpha[pixel] = alpha[ref];
|
||||
alpha[pixel] = alpha[ref];
|
||||
}
|
||||
}
|
||||
// fill top border
|
||||
x_start = dw;
|
||||
y_start = 0;
|
||||
}
|
||||
// fill top border
|
||||
x_start = dw;
|
||||
y_start = 0;
|
||||
for (int y = 0; y < dh; ++y) {
|
||||
for (int x = 0; x < width - dw - dw; ++x) {
|
||||
pixel = x_start + x + (y_start + y) * width;
|
||||
for (int x = 0; x < width - dw - dw; ++x) {
|
||||
pixel = x_start + x + (y_start + y) * width;
|
||||
ref = x_start + x + dh * width;
|
||||
data[3 * pixel + 0] = data[3 * ref + 0];
|
||||
data[3 * pixel + 1] = data[3 * ref + 1];
|
||||
data[3 * pixel + 2] = data[3 * ref + 2];
|
||||
alpha[pixel] = alpha[ref];
|
||||
alpha[pixel] = alpha[ref];
|
||||
}
|
||||
}
|
||||
// fill right border
|
||||
x_start = width - dw;
|
||||
y_start = dh;
|
||||
for (int y = 0; y < height - dh - dh; ++y) {
|
||||
}
|
||||
// fill right border
|
||||
x_start = width - dw;
|
||||
y_start = dh;
|
||||
for (int y = 0; y < height - dh - dh; ++y) {
|
||||
ref = width - dw - 1 + (y_start + y) * width;
|
||||
for (int x = 0; x < dw; ++x) {
|
||||
for (int x = 0; x < dw; ++x) {
|
||||
pixel = x_start + x + (y_start + y) * width;
|
||||
data[3 * pixel + 0] = data[3 * ref + 0];
|
||||
data[3 * pixel + 1] = data[3 * ref + 1];
|
||||
data[3 * pixel + 2] = data[3 * ref + 2];
|
||||
alpha[pixel] = alpha[ref];
|
||||
alpha[pixel] = alpha[ref];
|
||||
}
|
||||
}
|
||||
// fill bottom border
|
||||
x_start = dw;
|
||||
y_start = height - dh;
|
||||
}
|
||||
// fill bottom border
|
||||
x_start = dw;
|
||||
y_start = height - dh;
|
||||
for (int y = 0; y < dh; ++y) {
|
||||
for (int x = 0; x < width - dw - dw; ++x) {
|
||||
pixel = x_start + x + (y_start + y) * width;
|
||||
for (int x = 0; x < width - dw - dw; ++x) {
|
||||
pixel = x_start + x + (y_start + y) * width;
|
||||
ref = x_start + x + (height - dh - 1) * width;
|
||||
data[3 * pixel + 0] = data[3 * ref + 0];
|
||||
data[3 * pixel + 1] = data[3 * ref + 1];
|
||||
data[3 * pixel + 2] = data[3 * ref + 2];
|
||||
alpha[pixel] = alpha[ref];
|
||||
alpha[pixel] = alpha[ref];
|
||||
}
|
||||
}
|
||||
// done
|
||||
@@ -621,7 +621,7 @@ Image PackagedImage::generate(const Options& opt) const {
|
||||
if (img.HasMask()) img.InitAlpha(); // we can't handle masks
|
||||
return img;
|
||||
} else {
|
||||
throw ScriptError(_("Unable to load image '") + filename + _("' from '" + opt.package->name() + _("'")));
|
||||
throw ScriptError(_("Unable to load image '") + filename + _("' from '") + opt.package->name() + _("'"));
|
||||
}
|
||||
}
|
||||
bool PackagedImage::operator == (const GeneratedImage& that) const {
|
||||
@@ -642,17 +642,17 @@ Image BuiltInImage::generate(const Options& opt) const {
|
||||
bool BuiltInImage::operator == (const GeneratedImage& that) const {
|
||||
const BuiltInImage* that2 = dynamic_cast<const BuiltInImage*>(&that);
|
||||
return that2 && name == that2->name;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : ArbitraryImage
|
||||
|
||||
Image ArbitraryImage::generate(const Options& opt) const {
|
||||
return image;
|
||||
}
|
||||
bool ArbitraryImage::operator == (const GeneratedImage& that) const {
|
||||
const ArbitraryImage* that2 = dynamic_cast<const ArbitraryImage*>(&that);
|
||||
return that2 && image.IsSameAs(that2->image);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : ArbitraryImage
|
||||
|
||||
Image ArbitraryImage::generate(const Options& opt) const {
|
||||
return image;
|
||||
}
|
||||
bool ArbitraryImage::operator == (const GeneratedImage& that) const {
|
||||
const ArbitraryImage* that2 = dynamic_cast<const ArbitraryImage*>(&that);
|
||||
return that2 && image.IsSameAs(that2->image);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : SymbolToImage
|
||||
@@ -716,48 +716,48 @@ bool ImageValueToImage::operator == (const GeneratedImage& that) const {
|
||||
return that2 && filename == that2->filename
|
||||
&& age == that2->age;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : ExternalImage
|
||||
|
||||
Image ExternalImage::generate(const Options& opt) const {
|
||||
wxFileName fname(filepath, wxPATH_UNIX);
|
||||
String filePathString = fname.GetAbsolutePath();
|
||||
|
||||
// ----------------------------------------------------------------------------- : ExternalImage
|
||||
|
||||
Image ExternalImage::generate(const Options& opt) const {
|
||||
wxFileName fname(filepath, wxPATH_UNIX);
|
||||
String filePathString = fname.GetAbsolutePath();
|
||||
|
||||
// has a pre-existing .mse-set file been loaded?
|
||||
if (opt.local_package->needSaveAs()) throw ScriptError(_ERROR_1_("can't import image without set", filePathString));
|
||||
|
||||
// does the file pointed to by filepath exist?
|
||||
if (!fname.FileExists()) throw ScriptError(_ERROR_1_("import not found", filePathString));
|
||||
|
||||
String fileExt = fname.GetExt();
|
||||
wxBitmapType bitmapType;
|
||||
if (fileExt == _("png")) bitmapType = wxBITMAP_TYPE_PNG;
|
||||
else if (fileExt == _("jpg") || fileExt == _("jpeg")) bitmapType = wxBITMAP_TYPE_JPEG;
|
||||
else bitmapType = wxBITMAP_TYPE_BMP;
|
||||
|
||||
// does the file exist in the package?
|
||||
String fileNameNoExtension = fname.GetName();
|
||||
if (!opt.local_package->existsIn(fileNameNoExtension)) {
|
||||
auto outStream = opt.local_package->openOut(fileNameNoExtension);
|
||||
wxFileInputStream inStream = wxFileInputStream(filepath.ToStdString());
|
||||
if (!inStream.IsOk()) throw ScriptError(_ERROR_1_("can't create file stream", filePathString));
|
||||
outStream->Write(inStream);
|
||||
if (!outStream->IsOk()) throw ScriptError(_ERROR_1_("can't write image to set", filePathString));
|
||||
outStream->Close();
|
||||
}
|
||||
|
||||
// save the package with the new image
|
||||
opt.local_package->save(false);
|
||||
|
||||
auto imageInputStream = opt.local_package->openIn(fileNameNoExtension);
|
||||
Image img(*imageInputStream.get(), bitmapType);
|
||||
|
||||
if (!img.IsOk()) throw ScriptError(_ERROR_1_("can't import image", filePathString));
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
bool ExternalImage::operator == (const GeneratedImage& that) const {
|
||||
const ExternalImage* that2 = dynamic_cast<const ExternalImage*>(&that);
|
||||
return that2 && that2->filepath == filepath;
|
||||
}
|
||||
if (opt.local_package->needSaveAs()) throw ScriptError(_ERROR_1_("can't import image without set", filePathString));
|
||||
|
||||
// does the file pointed to by filepath exist?
|
||||
if (!fname.FileExists()) throw ScriptError(_ERROR_1_("import not found", filePathString));
|
||||
|
||||
String fileExt = fname.GetExt();
|
||||
wxBitmapType bitmapType;
|
||||
if (fileExt == _("png")) bitmapType = wxBITMAP_TYPE_PNG;
|
||||
else if (fileExt == _("jpg") || fileExt == _("jpeg")) bitmapType = wxBITMAP_TYPE_JPEG;
|
||||
else bitmapType = wxBITMAP_TYPE_BMP;
|
||||
|
||||
// does the file exist in the package?
|
||||
String fileNameNoExtension = fname.GetName();
|
||||
if (!opt.local_package->existsIn(fileNameNoExtension)) {
|
||||
auto outStream = opt.local_package->openOut(fileNameNoExtension);
|
||||
wxFileInputStream inStream = wxFileInputStream(filepath.ToStdString());
|
||||
if (!inStream.IsOk()) throw ScriptError(_ERROR_1_("can't create file stream", filePathString));
|
||||
outStream->Write(inStream);
|
||||
if (!outStream->IsOk()) throw ScriptError(_ERROR_1_("can't write image to set", filePathString));
|
||||
outStream->Close();
|
||||
}
|
||||
|
||||
// save the package with the new image
|
||||
opt.local_package->save(false);
|
||||
|
||||
auto imageInputStream = opt.local_package->openIn(fileNameNoExtension);
|
||||
Image img(*imageInputStream.get(), bitmapType);
|
||||
|
||||
if (!img.IsOk()) throw ScriptError(_ERROR_1_("can't import image", filePathString));
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
bool ExternalImage::operator == (const GeneratedImage& that) const {
|
||||
const ExternalImage* that2 = dynamic_cast<const ExternalImage*>(&that);
|
||||
return that2 && that2->filepath == filepath;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user