function splitWords ($text) { // Seperate "[lowercase char][uppercase char]" with a space. for ($i = 1, $n = strlen($text); $i < $n; $i++) { $char = substr($text, $i, 1); if ($char < 'A' || $char > 'Z') continue; $prevChar = substr($text, $i - 1, 1); if ($prevChar < 'a' || $prevChar > 'z') continue; $text = substr($text, 0, $i) . ' ' . substr($text, $i); $i++; } return upperCaseWords($text); }
function promptCardInfo ($cardType, $isLastCard = true) { global $writer; $card = new Card(); echo "Title:\n"; $card->title = upperCaseWords(trim(fgets(STDIN))); if (!$card->title) error('Invalid title.'); if ($cardType != 'v' && $cardType != 'l' && $cardType != 'fl' && ($cardType != 'f' || !$isLastCard)) { echo "Casting cost (ex: 4R, {4}{R}, 1RWU, {10}{WU}):\n"; $cost = trim(fgets(STDIN)); if (strpos($cost, '{') === false) { $newCost = ''; for ($i = 0, $n = strlen($cost); $i < $n; $i++) $newCost .= '{' . $cost[$i] . '}'; $cost = $newCost; } $card->cost = $cost; $colors = Card::getCostColors($cost); $colorCount = strlen($colors); if ($colorCount == 1) $card->color = $colors; else if ($colorCount > 1) $card->color = 'Gld'; else if ($card->cost) $card->color = 'Art'; } if ($cardType == 'v') { $card->color = 'Art'; $card->set = 'VG'; } if ($cardType == 'l' || ($cardType == 'fl' && !$isLastCard)) { $card->color = 'Lnd'; echo "Mana color(s) land can produce (ex: W, R, C, A, RG, RGW, WUBRG):\n"; $writer->titleToLandColors[strtolower($card->title)] = Card::getCostColors(trim(fgets(STDIN))); if (!$writer->titleToLandColors[strtolower($card->title)]) error('Invalid land mana color(s).'); } if (($cardType != 'f' && $cardType != 'fl') || !$isLastCard) { echo "Art (URL or local file path):\n"; $card->artFileName = trim(fgets(STDIN)); } if ($cardType != 'v') { echo "Type (ex: Creature - Human):\n"; $card->type = str_replace('-', '–', upperCaseWords(trim(fgets(STDIN)))); if ($cardType != 'l' && $cardType != 'fl') { echo "Power/toughness (ex: 3/4):\n"; $card->pt = trim(fgets(STDIN)); } } echo "Legal text (ex: {T}: Add {G} to your mana pool. #(This is italic.)#):\n"; $text = ''; while (true) { $input = trim(fgets(STDIN)); if ($input == '') break; if ($text) $text .= "\n"; $text .= $input; } $text = str_replace('-', '–', $text); $card->legal = $text; if ($cardType != 'f' && $cardType != 'fl') { echo "Flavor text:\n"; $text = ''; while (true) { $input = trim(fgets(STDIN)); if ($input == '') break; if ($text) $text .= "\n"; $text .= $input; } $card->flavor = str_replace('-', '—', $text); } if ($cardType == 'v') { echo "Starting & max hand size (ex: +1, -3, +10):\n"; $hand = trim(fgets(STDIN)); if (substr($hand, 0, 1) != '+' && substr($hand, 0, 1) != '-') error('Invalid starting & max hand size.'); echo "Starting life (ex: +5, -12, +0):\n"; $life = trim(fgets(STDIN)); if (substr($life, 0, 1) != '+' && substr($life, 0, 1) != '-') error('Invalid starting life.'); $card->legal = "Hand $hand, Life $life\n" . $card->legal; } if (($cardType != 'f' && $cardType != 'fl') || !$isLastCard) { echo "Artist:\n"; $card->artist = trim(fgets(STDIN)); echo "Copyright (ex: (tm) & (c) 2006 Lizards on a Post, Inc. 42/175):\n"; $card->copyright = trim(fgets(STDIN)); $card->copyright = str_replace('(tm)', '™', $card->copyright); $card->copyright = str_replace('(c)', '©', $card->copyright); if (!$card->copyright) $card->copyright = ' '; } if ($cardType != 'v' && (($cardType != 'f' && $cardType != 'fl') || $isLastCard) && ($cardType != 's' || $isLastCard)) { echo "Edition (ex: A, B, 7E, 9E, IN, RAV):\n"; $card->set = strtoupper(trim(fgets(STDIN))); echo "Rarity (ex: R, U, C):\n"; $card->rarity = strtoupper(trim(fgets(STDIN))); if ($card->rarity && !$card->set) $card->set = 'X'; } return $card; }