path to can select mws directory names for the art pictures
by Nate and Snacko
Moderators: Snacko, CCGHQ Admins
path to can select mws directory names for the art pictures
by dcelso » 15 Mar 2009, 00:54
Hello to all,
I have tryed the card generator 8.2.8 and it could not use the mws directory names for pics, so i have changed the php script for you can select the old directory nomeclature used in mws.
I have tryed the card generator 8.2.8 and it could not use the mws directory names for pics, so i have changed the php script for you can select the old directory nomeclature used in mws.
- Attachments
-
- mtgGeneratorFixForMWSDirNames.zip
- (2.08 KiB) Downloaded 414 times
- dcelso
- Posts: 17
- Joined: 15 Mar 2009, 00:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: path to can select mws directory names for the art pictures
by Huggybaby » 15 Mar 2009, 03:41
Interesting, thanks, and a nice first post too. Welcome to the forum dcelso.
-
Huggybaby - Administrator
- Posts: 3207
- Joined: 15 Jan 2006, 19:44
- Location: Finally out of Atlanta
- Has thanked: 701 times
- Been thanked: 594 times
Re: path to can select mws directory names for the art pictures
by Snacko » 15 Mar 2009, 08:58
Tested and made a few changes like moving the option to art.* namespace plus and proper indentation.
Will be included in the next release.
- Code: Select all
diff --git a/config.txt b/config.txt
index 2d30dbc..393fb2d 100644
--- a/config.txt
+++ b/config.txt
@@ -63,5 +63,6 @@ art.random = 0
art.keep.aspect.ratio = 1
art.directory = E:\mtg\pics
art.extension = jpg
+art.use.mws.directories.names = 1
art.error.when.missing = 0
art.debug = 0
diff --git a/scripts/classes/SetDB.php b/scripts/classes/SetDB.php
index b1604ab..36a8570 100644
--- a/scripts/classes/SetDB.php
+++ b/scripts/classes/SetDB.php
@@ -19,6 +19,8 @@ class SetDB {
private $pre8thSets = array();
public function __construct () {
+ global $config;
+
$file = fopen_utf8('data/sets.txt', 'r');
$i = 1000;
while (!feof($file)) {
@@ -31,8 +33,13 @@ class SetDB {
$abbreviations = explode(',', substr($line, 0, $spaceIndex));
$mainSet = "";
- foreach($abbreviations as $set)
- if (strlen($mainSet) < strlen($set) && strlen($set)<=3) $mainSet = $set;
+
+ if ($config['art.use.mws.directories.names'])
+ $mainSet = $abbreviations[0];
+ else
+ foreach($abbreviations as $set)
+ if (strlen($mainSet) < strlen($set) && strlen($set)<=3) $mainSet = $set;
+
$mainSet = strtoupper($mainSet);
$this->setToMainSet[(string)strtoupper($name)] = $mainSet;
Will be included in the next release.
Re: path to can select mws directory names for the art pictures
by dcelso » 16 Mar 2009, 01:30
Thanks for the welcome, really, this is not the first time I entered the forum but I never had the need to insert a post.
I am glad that it is useful. I saw that the new location is the correct, sorry for I have not seen berore
Moreover, I have seen a trouble in the file sets.txt, it is that the line for the ten edition is in a different order to the appropriate for can do this pacth.
-10ED,10TH,10E Tenth Edition
+10E,10ED,10TH Tenth Edition
And other thing is that if actualy we select no use mws directory names, this loop:
if ($config['art.use.mws.directories.names'])
$mainSet = $abbreviations[0];
else
foreach($abbreviations as $set)
if (strlen($mainSet) < strlen($set) && strlen($set)<=3) $mainSet = $set;
always give the last alias of the sets.txt, i.e., for the line 9E,9ED,9TH nine Edition will obtanin 9TH so the second alias never will be use in this case.
Other thing is that the commented line doesnt run well for ten edition since it have four letters in the two last alias and always will return the first alias.
Other thing that I saw is that if I use mnw directories the setsicons run well, but If I use the new format directories the setsicons are not rendered, it is because the names have the same that mws directories.
I am glad that it is useful. I saw that the new location is the correct, sorry for I have not seen berore
Moreover, I have seen a trouble in the file sets.txt, it is that the line for the ten edition is in a different order to the appropriate for can do this pacth.
-10ED,10TH,10E Tenth Edition
+10E,10ED,10TH Tenth Edition
And other thing is that if actualy we select no use mws directory names, this loop:
if ($config['art.use.mws.directories.names'])
$mainSet = $abbreviations[0];
else
foreach($abbreviations as $set)
if (strlen($mainSet) < strlen($set) && strlen($set)<=3) $mainSet = $set;
always give the last alias of the sets.txt, i.e., for the line 9E,9ED,9TH nine Edition will obtanin 9TH so the second alias never will be use in this case.
Other thing is that the commented line doesnt run well for ten edition since it have four letters in the two last alias and always will return the first alias.
Other thing that I saw is that if I use mnw directories the setsicons run well, but If I use the new format directories the setsicons are not rendered, it is because the names have the same that mws directories.
- dcelso
- Posts: 17
- Joined: 15 Mar 2009, 00:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: path to can select mws directory names for the art pictures
by Snacko » 16 Mar 2009, 11:33
- Code: Select all
if (strlen($mainSet) < strlen($set) && strlen($set)<=3) $mainSet = $set;
I completely forgot that this should be done the proper way, and I was going to make it work at some point. Here's a working autofinding the images patch , this one will be included after all the basic one was scrapped.
- Code: Select all
diff --git a/scripts/classes/ArtDB.php b/scripts/classes/ArtDB.php
index 409ef81..89082b6 100644
--- a/scripts/classes/ArtDB.php
+++ b/scripts/classes/ArtDB.php
@@ -20,9 +20,11 @@ class ArtDB {
private $titleToUsedArt = array();
private $picPatterns = array(' %', '%', ' (%)');
- public function __construct () {
+ public function __construct (SetDB $setDB) {
global $config;
+ $this->setDB = $setDB;
+
$this->ext = '.' . $config['art.extension'];
$this->root = $config['art.directory'];
@@ -98,7 +100,11 @@ class ArtDB {
}
} else {
if ($config['art.debug']) echo "\n";
- $fileName = $this->findImage($this->root . '/' . $set . '/', $name, $pic);
+ foreach ($this->setDB->getAbbrevs($set) as $abbrev) {
+ $fileName = $this->findImage($this->root . '/' . $abbrev . '/', $name, $pic);
+ if ($fileName)
+ break;
+ }
}
if (!$fileName && $config['art.error.when.missing']) error('No art found for card: ' . $title);
diff --git a/scripts/classes/ImageWriter.php b/scripts/classes/ImageWriter.php
index 8001ab0..a019e34 100644
--- a/scripts/classes/ImageWriter.php
+++ b/scripts/classes/ImageWriter.php
@@ -29,7 +29,7 @@ class ImageWriter {
global $config;
$this->setDB = new SetDB();
- $this->artDB = new ArtDB();
+ $this->artDB = new ArtDB($this->setDB);
$this->cardDB = new CardDB($this->setDB, $this->artDB);
$this->formatDB = new FormatDB($this->setDB, $this->cardDB);
$this->fontSizeDB = new FontSizeDB($config['card.text.use.font.size.cache']);
@@ -101,20 +101,20 @@ class ImageWriter {
// Determine the correct CardRenderer.
if (strpos($card->title, "/") !== FALSE)
- $renderer = new SplitRenderer();
+ $renderer = new SplitRenderer($this->setDB);
else if(strpos($card->legal, "\n-----\n") !== FALSE)
- $renderer = new EighthFlipRenderer();
+ $renderer = new EighthFlipRenderer($this->setDB);
else if ($card->set == "VG" && $config['render.vanguard'])
- $renderer = new VanguardRenderer();
+ $renderer = new VanguardRenderer($this->setDB);
else if (strpos($card->englishType, "Planeswalker")!== FALSE && $config['render.planeswalker'])
- $renderer = new PlanesWalkerRenderer();
+ $renderer = new PlanesWalkerRenderer($this->setDB);
else {
$isPre8th = $this->setDB->isPre8th($card->set) && !$card->promo;
if ($isPre8th && !$config['render.preEighth.basic.land.frames'] && $card->isBasicLand()) $isPre8th = false;
if ($config['render.preEighth'] && ($isPre8th || !$config['render.eighth']))
- $renderer = new PreEighthRenderer();
+ $renderer = new PreEighthRenderer($this->setDB);
else if ($config['render.eighth']){
- $renderer = new EighthRenderer();
+ $renderer = new EighthRenderer($this->setDB);
}
}
if (!$renderer) error('No renderer enabled for card: ' . $card);
diff --git a/scripts/classes/SetDB.php b/scripts/classes/SetDB.php
index 68f12bf..36363c5 100644
--- a/scripts/classes/SetDB.php
+++ b/scripts/classes/SetDB.php
@@ -59,6 +59,10 @@ class SetDB {
return @$this->setToMainSet[(string)strtoupper($set)];
}
+ public function getAbbrevs ($set) {
+ return array_keys($this->setToMainSet, $set);
+ }
+
public function getOrdinal ($set) {
return $this->mainSetToOrdinal[(string)$this->normalize($set)];
}
diff --git a/scripts/classes/renderers/CardRenderer.php b/scripts/classes/renderers/CardRenderer.php
index 1f63839..bf0b06c 100644
--- a/scripts/classes/renderers/CardRenderer.php
+++ b/scripts/classes/renderers/CardRenderer.php
@@ -15,6 +15,11 @@
////////////////////////////////////////////////////////////////////////
abstract class CardRenderer extends Renderer {
public $card;
+ public $setDB;
+
+ public function __construct (SetDB $setDB) {
+ $this->setDB = $setDB;
+ }
// Draws the art image within the specified box, cropping the art if necessary to maintain proportions.
public function drawArt (&$canvas, $artFileName, $artTop, $artLeft, $artBottom, $artRight, $ignoreAspectRatio = false) {
@@ -74,8 +79,18 @@ abstract class CardRenderer extends Renderer {
public function drawRarity ($canvas, $rarity, $set, $right, $middle, $height, $width, $whiteBorder, $fallback = true) {
$image = null;
- if ($whiteBorder) list($image, $srcWidth, $srcHeight) = getGIF('images/preEighth/rarity/' . $set . '_' . $rarity . '.gif');
- if (!$image && $fallback) list($image, $srcWidth, $srcHeight) = getGIF('images/eighth/rarity/' . $set . '_' . $rarity . '.gif');
+ if ($whiteBorder)
+ foreach ($this->setDB->getAbbrevs($set) as $abbrev){
+ list($image, $srcWidth, $srcHeight) = getGIF('images/preEighth/rarity/' . $abbrev . '_' . $rarity . '.gif');
+ if ($image)
+ break;
+ }
+ if (!$image && $fallback)
+ foreach ($this->setDB->getAbbrevs($set) as $abbrev) {
+ list($image, $srcWidth, $srcHeight) = getGIF('images/eighth/rarity/' . $abbrev . '_' . $rarity . '.gif');
+ if ($image)
+ break;
+ }
if ($image) {
$destWidth = $srcWidth;
$destHeight = $srcHeight;
Re: path to can select mws directory names for the art pictures
by dcelso » 16 Mar 2009, 18:13
Oh, very good, my patch is very sloppy in comparison to this.
Congratulations, I did not know the source code enough to have done it. .
Congratulations, I did not know the source code enough to have done it. .
- dcelso
- Posts: 17
- Joined: 15 Mar 2009, 00:46
- Has thanked: 0 time
- Been thanked: 0 time
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 16 guests