예제 #1
0
 public function __construct(SetDB $setDB, CardDB $cardDB)
 {
     $this->cardDB = $cardDB;
     $file = fopen_utf8('data/formats.txt', 'r');
     while (!feof($file)) {
         $format = trim(fgets($file, 6000));
         if (!$format) {
             continue;
         }
         $this->formats[] = $format;
         $this->formatToBanned[$format] = array();
         $this->formatToRestricted[$format] = array();
         $this->formatToSets[$format] = array();
         $state = null;
         while (!feof($file)) {
             $line = trim(fgets($file, 6000));
             if (!$line) {
                 break;
             }
             if ($line == 'BANNED' || $line == 'RESTRICTED' || $line == 'SETS') {
                 $state = $line;
                 continue;
             }
             $line = strtolower($line);
             switch ($state) {
                 case 'BANNED':
                     $this->formatToBanned[$format][] = $line;
                     break;
                 case 'RESTRICTED':
                     $this->formatToRestricted[$format][] = $line;
                     break;
                 case 'SETS':
                     $set = $setDB->normalize($line);
                     if (!$set) {
                         error('Error parsing "data/formats.txt". Unknown set: ' . $set);
                     }
                     $this->formatToSets[$format][] = $set;
                     break;
                 default:
                     error('Error parsing "data/formats.txt". Invalid section: ' . $line);
             }
         }
     }
     fclose($file);
 }
예제 #2
0
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////
require_once 'scripts/includes/global.php';
echo "Card Generator v{$version} - Prices\n\n";
$files = getInputFiles(array_slice($argv, 1), 'Drag and drop a decklist file or directory here and press enter...');
$setDB = new SetDB();
$artDB = new ArtDB();
$cardDB = new CardDB($setDB, $artDB);
$convertor = new Convertor();
echo 'Downloading MagicTraders pricing...';
$prices = array();
$file = @fopen('http://www.magictraders.com/pricelists/current-magic', 'r');
if (!$file) {
    error('Unable to open URL: http://www.magictraders.com/pricelists/current-magic');
}
$count = 0;
while (!feof($file)) {
    $line = fgets($file, 4096);
    if (substr($line, 0, 6) == 'total:') {
        continue;
    }
예제 #3
0
 public function __construct(SetDB $setDB, ArtDB $artDB)
 {
     global $config;
     $this->setDB = $setDB;
     $this->artDB = $artDB;
     // Load english cards.
     echo 'Loading card data';
     $file = fopen_utf8('data/cards.csv', 'r');
     if (!$file) {
         error('Unable to open file: data/cards.csv');
     }
     $i = 0;
     while (($row = fgetcsv($file, 6000, ',')) !== FALSE) {
         if ($i++ % 400 == 0) {
             echo '.';
         }
         $card = CardDB::rowToCard($row);
         // Ignore cards with an unknown set.
         $card->set = $setDB->normalize($card->set);
         if (!$card->set) {
             continue;
         }
         $title = strtolower($card->title);
         if (!@$this->titleToCards[$title]) {
             $this->titleToCards[$title] = array();
         }
         $this->titleToCards[(string) $title][] = $card;
     }
     fclose($file);
     echo "\n";
     // Load foreign card data.
     $language = strtolower($config['output.language']);
     if ($language && $language != 'english') {
         echo "Loading {$language} card data";
         $file = fopen_utf8("data/cards-{$language}.csv", 'r');
         if (!$file) {
             error("Unable to open file: data/cards-{$language}.csv");
         }
         $i = 0;
         while (($row = fgetcsv($file, 6000, ',')) !== FALSE) {
             if ($i++ % 400 == 0) {
                 echo '.';
             }
             // Overwrite some of the english card values with the foreign values.
             $englishTitle = strtolower($row[0]);
             $cards = @$this->titleToCards[(string) $englishTitle];
             if (!$cards) {
                 //print_r($row);
                 echo "\nError matching card data for card: {$row['0']}";
                 continue;
                 // Skip errors
             }
             foreach ($cards as $card) {
                 CardDB::applyLanguageRowToCard($row, $card);
             }
         }
         fclose($file);
         echo "\n";
         if (!$config['output.english.flavor.text']) {
             echo "Loading {$language} card flavor data";
             $file = fopen_utf8("data/cards-{$language}-flavor.csv", 'r');
             if (!$file) {
                 echo "\nNo localized flavor for language: {$language}";
             } else {
                 $i = 0;
                 while (($row = fgetcsv($file, 6000, ',')) !== FALSE) {
                     if ($i++ % 400 == 0) {
                         echo '.';
                     }
                     // Overwrite some of the english card values with the foreign values.
                     $englishTitle = strtolower($row[0]);
                     $cards = @$this->titleToCards[(string) $englishTitle];
                     if (!$cards) {
                         //print_r($row);
                         echo "\nError matching card flavor for card: {$row['0']}";
                         continue;
                         // Skip errors.
                     }
                     // Find the card from needed edition and apply localized flavor.
                     foreach ($cards as $card) {
                         if ($card->set == $setDB->normalize($row[1])) {
                             $card->flavor = $row[2];
                             break;
                         }
                     }
                 }
                 fclose($file);
                 echo "\n";
             }
         }
     }
 }