It is currently 23 Apr 2024, 13:30
   
Text Size

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

Postby 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.
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

Postby Huggybaby » 15 Mar 2009, 03:41

Interesting, thanks, and a nice first post too. Welcome to the forum dcelso.
User avatar
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

Postby Snacko » 15 Mar 2009, 08:58

Tested and made a few changes like moving the option to art.* namespace plus and proper indentation.
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.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Re: path to can select mws directory names for the art pictures

Postby 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.
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

Postby Snacko » 16 Mar 2009, 11:33

Code: Select all
if (strlen($mainSet) < strlen($set) && strlen($set)<=3) $mainSet = $set;
This code get's the 1st 3 letter code or if it can't find one it grabs the last longest abbreviation under 3 characters long. And this works as expected.

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;
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Re: path to can select mws directory names for the art pictures

Postby 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. :D.
dcelso
 
Posts: 17
Joined: 15 Mar 2009, 00:46
Has thanked: 0 time
Been thanked: 0 time


Return to HQ Card Generator

Who is online

Users browsing this forum: No registered users and 16 guests


Who is online

In total there are 16 users online :: 0 registered, 0 hidden and 16 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 16 guests

Login Form