Update to 0.0.1 version system for main ttrts client and check versions

This commit is contained in:
mdiluzio 2014-12-20 17:17:04 +00:00
parent 2d5f34559c
commit 63a8f61467

View file

@ -2,6 +2,9 @@
use strict; use strict;
use warnings; use warnings;
our $ttrts_perlai_versioncompat_major = 0;
our $ttrts_perlai_versioncompat_minor = 0;
# Get information about a unit from it's descriptor # Get information about a unit from it's descriptor
sub getUnit sub getUnit
{ {
@ -17,16 +20,21 @@ sub GetUnitsForTurn
open (my $TURNHANDLE, '<', $turnFile) or die "Could not open '$turnFile' $!"; open (my $TURNHANDLE, '<', $turnFile) or die "Could not open '$turnFile' $!";
# Skip the header information # Skip the header information
my $headerLine = <$TURNHANDLE>; my $num = 0;
my $sizeLine = <$TURNHANDLE>; while( !( <$TURNHANDLE> =~ /~~~~/ ) )
my $turnLine = <$TURNHANDLE>; {
( <$TURNHANDLE> =~ /~~~~/ ) or die "Gamestate file did not match expected format"; $num++;
$num > 20 and die "gamestate file did not reach ~~~~ line within 10 lines";
}
my @units; my @units;
while( my $unitLine = <$TURNHANDLE> ) while( my $unitLine = <$TURNHANDLE> )
{ {
chomp $unitLine; chomp $unitLine;
push(@units,$unitLine); if( !($unitLine eq "END") )
{
push(@units,$unitLine);
}
} }
close $TURNHANDLE; close $TURNHANDLE;
@ -34,6 +42,19 @@ sub GetUnitsForTurn
return @units; return @units;
} }
# Check version numbers against ttrts.pm version
sub checkVersion
{
my $version_major = shift;
my $version_minor = shift;
if( ($version_major != $ttrts_perlai_versioncompat_major)
or ($version_minor != $ttrts_perlai_versioncompat_minor) )
{
printf "ttrts.pm version does not match with this ttrts version\n";
die "ttrts.pm = v$ttrts_perlai_versioncompat_minor.$ttrts_perlai_versioncompat_major ttrts = v$version_major.$version_minor";
}
}
# Get information from the header for this turn # Get information from the header for this turn
sub GetHeaderForTurn sub GetHeaderForTurn
{ {
@ -45,15 +66,18 @@ sub GetHeaderForTurn
# Pull in the header information # Pull in the header information
my $headerLine = <$TURNHANDLE>; my $headerLine = <$TURNHANDLE>;
chomp $headerLine; chomp $headerLine;
my $nameLine = <$TURNHANDLE>;
chomp $nameLine;
my $sizeLine = <$TURNHANDLE>; my $sizeLine = <$TURNHANDLE>;
chomp $sizeLine; chomp $sizeLine;
my $turnLine = <$TURNHANDLE>; my $turnLine = <$TURNHANDLE>;
chomp $turnLine; chomp $turnLine;
my ($gameName) = ( $headerLine =~ /===== ([^ ]+) =====/ ); my ($version_major,$version_minor) = ( $headerLine =~ /==== ttrts v(\d+)\.(\d+)\.\d+ ====/ );
my ($gameX,$gameY) = ( $sizeLine =~ /SIZE:\[(\d+),(\d+)\]/ ); checkVersion $version_major,$version_minor;
( <$TURNHANDLE> =~ /~~~~/ ) or die "Gamestate file did not match expected format"; my ($gameName) = ( $nameLine =~ /NAME:(.+)/ );
my ($gameX,$gameY) = ( $sizeLine =~ /SIZE:\[(\d+),(\d+)\]/ );
close $TURNHANDLE; close $TURNHANDLE;
@ -111,6 +135,7 @@ sub OutputCommandsFile
{ {
open(my $cmdFile, '>', $cmdFileName) or die "Couldn't open '$cmdFileName' $!"; open(my $cmdFile, '>', $cmdFileName) or die "Couldn't open '$cmdFileName' $!";
print $cmdFile $commands; print $cmdFile $commands;
print $cmdFile "END";
close $cmdFile; close $cmdFile;
printf "Outputted $cmdFileName\n"; printf "Outputted $cmdFileName\n";