1 |
#!/opt/bin/perl |
2 |
|
3 |
# this script walks '.' recursively and will find all archetypes |
4 |
# that can be found and will look for face and state info in them |
5 |
# and return a json hash to stdout with the following key/value format: |
6 |
# |
7 |
# "<uuid><state>":"<face>" |
8 |
# |
9 |
# see also json_conv_old_faces for instructions on how to convert the facenames |
10 |
# |
11 |
|
12 |
use strict; |
13 |
use File::Find; |
14 |
|
15 |
*name = *File::Find::name; |
16 |
*dir = *File::Find::dir; |
17 |
|
18 |
my $first = 1; # marks the first key/value (don't print too many ','s) |
19 |
|
20 |
sub getarch { |
21 |
my ($file, $lines, $outarchs) = @_; |
22 |
|
23 |
my $inarch = 0; |
24 |
my $at_end = 0; |
25 |
|
26 |
my $archlines = []; |
27 |
do { |
28 |
my $line = shift @$lines; |
29 |
if ($line =~ m/^arch\s*(\S+)\s*$/) { |
30 |
if ($inarch) { |
31 |
unshift @$lines, $line; |
32 |
getarch ($file, $lines, $outarchs); |
33 |
} else { |
34 |
$inarch = 1; |
35 |
push @$archlines, $line; |
36 |
} |
37 |
} elsif ($line =~ m/^end\s*$/) { |
38 |
push @$archlines, $line; |
39 |
push @$outarchs, $archlines; |
40 |
$archlines = []; |
41 |
$at_end = 1; |
42 |
} else { |
43 |
push @$archlines, $line if $inarch; |
44 |
} |
45 |
} while (not ($at_end) && @$lines); |
46 |
|
47 |
if ($inarch and not $at_end) { |
48 |
die "mismatched archetype in $file!"; |
49 |
} |
50 |
} |
51 |
|
52 |
sub wanted { |
53 |
my $file = $_; |
54 |
-f $file or return; |
55 |
|
56 |
next if $file =~ /\.pst$/; |
57 |
|
58 |
open my $fh, "<$file" or return; |
59 |
my $map = do { local $/; <$fh> }; |
60 |
|
61 |
my $found_magic_ear; |
62 |
my $found_npc; |
63 |
|
64 |
my @lines = split /\r?\n/, $map; |
65 |
|
66 |
my $archs = []; |
67 |
getarch ($file, \@lines, $archs) while @lines; |
68 |
|
69 |
for my $archlines (@$archs) { |
70 |
my $arch; |
71 |
my $uuid; |
72 |
my $face; |
73 |
my $state; |
74 |
|
75 |
for (@$archlines) { |
76 |
if (/^arch\s*(\S+)\s*$/) { |
77 |
$arch = $1; |
78 |
} |
79 |
if (/^state\s*(\S+)\s*$/) { |
80 |
$state = $1; |
81 |
} |
82 |
if (/^uuid\s*(\S+)\s*$/) { |
83 |
$uuid = $1; |
84 |
} |
85 |
if (/^face\s*(\S+)\s*$/) { |
86 |
$face = $1; |
87 |
} |
88 |
} |
89 |
|
90 |
next if $arch eq 'map'; |
91 |
|
92 |
if ($uuid && $face) { |
93 |
$state *= 1; |
94 |
print "," unless $first; |
95 |
$first = 0; |
96 |
print "\n\"$uuid$state\":\"$face\""; |
97 |
} |
98 |
} |
99 |
} |
100 |
|
101 |
print "{"; |
102 |
find { no_chdir => 1, wanted => \&wanted }, "."; |
103 |
print "\n}\n"; |