# (just copy paste this part to the file ~/.xonotic-map-compiler)
# Path to Xonotic (where the data directory is in)
- our $XONOTICDIR = '/home/rpolzer/Games/Xonotic';
+ our $XONOTICDIR = '.';
# Path to your q3map2 program. You find it in your GtkRadiant/install
# directory.
- our $Q3MAP2 = '/home/rpolzer/Games/Xonotic/netradiant/install/q3map2.x86';
+ our $Q3MAP2 = './netradiant/install/q3map2.x86';
# General flags for q3map2 (for example -threads 4)
our $Q3MAP2FLAGS = '-fs_forbiddenpath xonotic*-data*.pk3* -fs_forbiddenpath xonotic*-nexcompat*.pk3*';
{
$options->{minimap} = undef;
}
- elsif($_ eq '-noshaderlist')
- {
- $options->{noshaderlist} = 1;
- }
elsif($_ eq '-bsp_timeout')
{
$options->{bsp_timeout} = shift @ARGV;
}
}
-(my $mapdir = getcwd()) =~ s!/[^/]*(?:$)!!;
-$mapdir = "/" if $mapdir eq "";
-symlink "$mapdir", "$linkdir/data";
-
my ($prescale, $postscale) = ($options->{scalefactor} =~ /^([0-9.]+)(?::([0-9.]+))?$/);
$prescale = 1 if not defined $prescale;
$postscale = 1 if not defined $postscale;
+my $origcwd = getcwd();
for my $m(@{$options->{maps}})
{
- $m =~ s/\.(?:map|bsp)$//;
-
- if($prescale != 1)
+ chdir $origcwd
+ or die "chdir $origcwd: $!";
+ if($m =~ s!(.*)/!!)
{
- unshift @{$options->{bsp}}, "-keeplights";
+ my $predir = $1;
+ chdir $predir
+ or die "chdir $predir: $!";
}
+ symlink getcwd() . "/..", "$linkdir/data"
+ or die "symlink $linkdir/data: $!";
- my %shaders = map { m!/([^/.]*)\.shader(?:$)! ? ($1 => 1) : () } glob "../scripts/*.shader";
+ $m =~ s/\.(?:map|bsp)$//;
- my $restore_shaderlist = sub { };
- if(!$options->{noshaderlist})
+ if($prescale != 1)
{
- my $previous_shaderlist = undef;
- my $shaderlist = "";
- if(open my $fh, "<", "$XONOTICDIR/data/scripts/shaderlist.txt")
- {
- while(<$fh>)
- {
- $shaderlist .= $_;
- }
-
- # we may have to restore the file on exit
- $previous_shaderlist = $shaderlist
- if "$XONOTICDIR/data" eq $mapdir;
- }
- else
- {
- # possibly extract the shader list from a pk3?
- local $ENV{N} = $XONOTICDIR;
- $shaderlist = `cd "\$N" && for X in "\$N"/data/data*.pk3; do Y=\$X; done; unzip -p "\$Y" scripts/shaderlist.txt`;
- }
-
- my $shaderlist_new = "";
- for(split /\r?\n|\r/, $shaderlist)
- {
- delete $shaders{$_};
- $shaderlist_new .= "$_\n";
- }
- if(%shaders)
- {
- for(sort keys %shaders)
- {
- $shaderlist_new .= "$_\n";
- }
- }
- else
- {
- $shaderlist_new = undef;
- }
-
- $restore_shaderlist = sub
- {
- if(defined $shaderlist_new)
- {
- if(defined $previous_shaderlist)
- {
- open my $fh, ">", "$mapdir/scripts/shaderlist.txt";
- print $fh $previous_shaderlist;
- close $fh;
- }
- else
- {
- unlink "$mapdir/scripts/shaderlist.txt";
- }
- }
- };
-
- if(defined $shaderlist_new)
- {
- mkdir "$mapdir/scripts";
- open my $fh, ">", "$mapdir/scripts/shaderlist.txt";
- print $fh $shaderlist_new;
- close $fh;
- }
+ unshift @{$options->{bsp}}, "-keeplights";
}
local $SIG{INT} = sub
{
print "SIGINT caught, cleaning up...\n";
- $restore_shaderlist->();
exit 0;
};
- eval
+ unlink <$m/lm_*>; # delete old external lightmaps
+ q3map2 '-bsp', @{$options->{bsp}}, "$m.map"
+ or die "-bsp: $?";
+ if($prescale != 1)
{
- unlink <$m/lm_*>; # delete old external lightmaps
- q3map2 '-bsp', @{$options->{bsp}}, "$m.map"
- or die "-bsp: $?";
- if($prescale != 1)
- {
- q3map2 '-scale', @{$options->{scale}}, $prescale, "$m.bsp"
- or die "-scale: $?";
- rename "${m}_s.bsp", "$m.bsp"
- or die "rename ${m}_s.bsp $m.bsp: $!";
- }
- my @o = @{$options->{order}};
- push @o, qw/light vis/;
- my %o = ();
+ q3map2 '-scale', @{$options->{scale}}, $prescale, "$m.bsp"
+ or die "-scale: $?";
+ rename "${m}_s.bsp", "$m.bsp"
+ or die "rename ${m}_s.bsp $m.bsp: $!";
+ }
+ my @o = @{$options->{order}};
+ push @o, qw/light vis/;
+ my %o = ();
- for(@o)
+ for(@o)
+ {
+ next if $o{$_}++;
+ if($_ eq 'light')
{
- next if $o{$_}++;
- if($_ eq 'light')
- {
- if(defined $options->{light})
- {
- q3map2 '-light', @{$options->{light}}, "$m.map"
- or die "-light: $?";
- }
- }
- if($_ eq 'vis')
+ if(defined $options->{light})
{
- if(defined $options->{vis})
- {
- q3map2 '-vis', @{$options->{vis}}, "$m.map"
- or die "-vis: $?";
- }
+ q3map2 '-light', @{$options->{light}}, "$m.map"
+ or die "-light: $?";
}
}
-
- if($postscale != 1)
- {
- q3map2 '-scale', @{$options->{scale}}, $postscale, "$m.bsp"
- or die "-scale: $?";
- rename "${m}_s.bsp", "$m.bsp"
- or die "rename ${m}_s.bsp $m.bsp: $!";
- }
-
- if(defined $options->{minimap})
+ if($_ eq 'vis')
{
- q3map2 '-minimap', @{$options->{minimap}}, "$m.map"
- or die "-minimap: $?";
+ if(defined $options->{vis})
+ {
+ q3map2 '-vis', @{$options->{vis}}, "$m.map"
+ or die "-vis: $?";
+ }
}
+ }
- unlink "$m.srf";
- unlink "$m.prt";
-
- $restore_shaderlist->();
- 1;
+ if($postscale != 1)
+ {
+ q3map2 '-scale', @{$options->{scale}}, $postscale, "$m.bsp"
+ or die "-scale: $?";
+ rename "${m}_s.bsp", "$m.bsp"
+ or die "rename ${m}_s.bsp $m.bsp: $!";
}
- or do
+
+ if(defined $options->{minimap})
{
- $restore_shaderlist->();
- die $@;
- };
+ q3map2 '-minimap', @{$options->{minimap}}, "$m.map"
+ or die "-minimap: $?";
+ }
+
+ unlink "$m.srf";
+ unlink "$m.prt";
}