ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/Info/rewrite_exits.pl
Revision: 1.1
Committed: Sat Feb 4 23:55:19 2006 UTC (18 years, 3 months ago) by root
Content type: text/plain
Branch point for: UPSTREAM, MAIN
Log Message:
Initial revision

File Contents

# User Rev Content
1 root 1.1 #!/usr/bin/perl
2     # this will adjust the 'slaying' lines
3     # in the current directory, and all sub-directories,
4     # so shuffling maps to new directories is not a problem.
5     #
6     # This absolutely depends on each map having a unique name.
7     # This script should be placed outside of the map directory,
8     # but you should be inside it when you run it. Ideally
9     # in the top-level maps directory.
10     #
11     # Dupes are noted, and not adjusted.
12     #
13    
14     use File::Basename qw( basename );
15     use vars qw( $MAPBASE );
16     use strict;
17     use warnings;
18    
19     # this is the base directory of the maps.
20     # The slaying linesthatpointtoothermaps,
21     # will be re-written as $MAPBASE/filename
22     $MAPBASE = "/mlab";
23    
24     my %FILES = ();
25     my %DUPES = ();
26     open(FIND, "find ./|");
27     while (<FIND>) {
28     chomp;
29     next unless -f;
30     next if $_ =~ /editor/;
31     my $basename = basename($_);
32     if ($FILES{$basename}) {
33     unless (exists $DUPES{$basename}) {
34     $DUPES{$basename} = [];
35     push(@{ $DUPES{$basename} }, $FILES{$basename});
36     }
37     push(@{ $DUPES{$basename} }, $_);
38     #warn "DUPE!: $_ => $FILES{$basename}\n";
39     }
40     else {
41     $FILES{$basename} = $_;
42     }
43     }
44     close(FIND);
45     foreach my $file (keys %DUPES) {
46     delete $FILES{$file};
47     print "Dupe filename: $file Sizes:";
48     foreach my $x (@{ $DUPES{$file} }) {
49     printf " %s", -s $x; # file size
50     printf " %s", $x; # file path
51     }
52     print "\n";
53     }
54    
55     foreach my $file (keys %FILES) {
56     open(FILE, "<$FILES{$file}");
57     my $data = join("", <FILE>);
58     close(FILE);
59    
60     my $newdata = $data;
61    
62     $newdata =~ s/(slaying|final_map)\s+(.+)/mappath($1,$2)/eg;
63     if ($newdata ne $data) {
64     open(FILE, ">$FILES{$file}");
65     print FILE $newdata;
66     close(FILE);
67     }
68     #printf("%s => %s\n", $file, $FILES{$file});
69     }
70    
71     sub mappath {
72     my ($type,$name) = @_;
73     $name =~ s/\s+//g;
74     my $file = basename($name);
75     my $new = $FILES{$file};
76     if ($new) {
77     unless ($file =~ /[a-z]/) {
78     print "CASE?: $file\n";
79     }
80     $new =~ s/^\.\///;
81     return "$type $MAPBASE/$new";
82     }
83     return "$type $name";
84     }