#!/usr/bin/perl

# perl script to work through an xml sequence file

$ipfile=$ARGV[0];

open(IN, $ipfile);

$f_prefix="data/levels";

$start=`cat $ipfile.level`; 
if ($start > 0) {$start--;}
$count=0;
while (<IN>) {

if (/<intro>(.*)<\/intro>/ ) {print "$1 \n";}
if (/<level>/) {$count++;}
if (/<file>(.*)<\/file>/) {$file=$1;}
if (/<text>(.*)<\/text>/) {$text=$1; $valid=1; } 
if ( $count > $start && $valid==1 && $y !~ /q/) {
	print "$count\n$text \n";
	print "play ? (y/n)\n";
	$y=<STDIN>;
	if ($y =~ /y/) { `src/pingus -f $f_prefix/$file.pingus`; }
	if ($y =~ /q/) { `echo $count >$ipfile.level`; }
	$valid=0;
}

}
