]> de.git.xonotic.org Git - xonotic/xonotic-maps.pk3dir.git/blob - scripts/entities.def2ent
entities.def -> .ent converter script (beginning)
[xonotic/xonotic-maps.pk3dir.git] / scripts / entities.def2ent
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 print <<EOF;
7 <?xml version="1.0"?>
8 <classes>
9 EOF
10
11 my $closetag;
12 my @spawnflags;
13 while(<STDIN>)
14 {
15         chomp;
16         s/&/&amp;/g;
17         s/</&lt;/g;
18         s/>/&gt;/g;
19         s/"/&quot;/g;
20         if(/^\/\*QUAKED (\S+) \((\S+ \S+ \S+)\) \((\S+ \S+ \S+)\) \((\S+ \S+ \S+)\) ?(.*)/)
21         {
22                 print "<point name=\"$1\" color=\"$2\" box=\"$3 $4\">\n";
23                 $closetag = "</point>";
24                 @spawnflags = split / /, $5;
25         }
26         elsif(/^\/\*QUAKED (\S+) \((\S+ \S+ \S+)\) \? ?(.*)/)
27         {
28                 print "<group name=\"$1\" color=\"$2\">\n";
29                 $closetag = "</group>";
30                 @spawnflags = split / /, $3;
31         }
32         elsif(/^\*\/$/)
33         {
34                 print "$closetag\n";
35         }
36         elsif(/^([0-9a-z_]*): +(.*)/)
37         {
38                 print "<string key=\"$1\" name=\"$1\">$2</string>\n";
39         }
40         elsif(/^([0-9A-Z_]*): +(.*)/)
41         {
42                 my $bit = [grep { $spawnflags[$_] eq $1; } 0..@spawnflags-1]->[0];
43                 warn "Cannot find bit $1 in @spawnflags\n"
44                         if not defined $bit;
45                 print "<flag key=\"$1\" name=\"$1\" bit=\"$bit\">$2</flag>\n";
46         }
47         else
48         {
49                 print "$_\n";
50         }
51 }
52
53 print <<EOF;
54 </classes>
55 EOF