#!/usr/bin/perl -w # SCCG card maker # takes a card list and creates an HTML file of cards you can print out # Version 0.3 ($Date: 2001/12/02 12:43:23 $) # Copyright James Andrewartha (trs80@ucc.gu.uwa.edu.au) # License: GPL (http://www.fsf.org/copyleft/gpl.html) version 2 or greater # $Id: sccg-make.pl,v 1.2 2001/12/02 12:43:23 trs80 Exp trs80 $ # # Usage: sccg-make ( ()) # If no card files are given, the default set (sccg, expansion1, unisfa, # battle3k and blank) are used. HTML is output to sccg.html, # if the last argument ends in .html, or if only one cardfile is given, and it # ends in -cards, to the name of the cardfile with -cards removed and .html # appended. # # Valid lines for card file: # = # * # # Variables with meaning are currently "type", "author", "edition", "image" and "bg" # The first 3 take text, the last 2 take a URL. # bg is the background image for the entire card (eg a texture) # image is the picture for the card, and is scaled proportionally to 130x100 (HxW) # # After a variable is set, it is used for all card lines until another # line changes its value. # # The card name should be what the card does, the flavour text (if present) # is just for humour value or other comment. # # Blank lines and lines beginning with '#' are ignored. use Image::Size; @cardfiles = (); # push the cardfiles into an array so I can use them later for $value (@ARGV) { $cardfiles[++$#cardfiles] = $value; } # if no cardfiles, use the default set if ($#cardfiles == -1) { @cardfiles = ("initial-cards", "expansion1-cards", "unisfa-cards", "battle3k-cards", "blank-cards"); } # if no output file given, use sccg.html $htmlfile = pop(@cardfiles); # remove the output file from the list of card files if ($htmlfile !~ /.html$/) { push(@cardfiles,($htmlfile)); # fix up the list of card files $htmlfile = "sccg.html"; } # if only file given ends in "-cards", make output file s/-cards/.html/ if ($#cardfiles == 0 and $cardfiles[0] =~ /-cards$/) { $htmlfile = $cardfiles[0]; $htmlfile =~ s/-cards$/.html/; } open(HTMLFILE, ">$htmlfile") or die "$0: can't open output file $htmlfile, quitting."; # print the header print HTMLFILE "Swancon: The Collectible Card Game cards for printing\n\n"; print HTMLFILE ""; $number = 0; for $cardfile (@cardfiles) { unless (open(CARDFILE, $cardfile)) { warn "$0: can't open card file $cardfile, skipping."; next; } # some defaults %heading = (); $heading{"type"} = "Defies categorisation"; $heading{"author"} = "anonymous"; $heading{"edition"} = "Too lazy to name edition"; $heading{"image"} = "images/trans.gif"; $heading{"bg"} = "images/trans.gif"; while() { chomp; if (/ \= /) { # read in section values (Card type, author, edition) ($section, $value) = split / \= /; $heading{$section} = $value; } elsif (!/^#/ and !/^$/) { # not a comment or a blank line # read in the card if (/ \* /) { # the card has flavour text ($action, $flavour) = split / \* /; } else { # just a description $action = $_; $flavour = ""; } # output the card table ($height, $width) = (0,0); ($width, $height) = imgsize($heading{"image"}); #print "$height $width\t"; # reduce to 130x100 if too big if ($height > 100) { $width *= 100/$height; $height = 100; } if ($width > 130) { $height *= 130/$width; $width = 130; } $width = int($width); $height = int($height); if ($height <= 0 or $height > 100) { $height=100; } if ($width <= 0 or $width > 130) { $width=130; } #print "$height $width $heading{image}\n"; print HTMLFILE "\n"; $number++; } # four cards per line if ($number==5) { print HTMLFILE "\n\n\n"; $number=0; } } close CARDFILE; } # close up the HTML file print HTMLFILE "\n\n
" , "" , "" , "" , "\n" , "
" , $heading{"type"} , "
$action
" , "
$flavour\ 
" , "" , "
By: " , $heading{"author"} , "" , $heading{"edition"} , "
" , "
\n";