]> de.git.xonotic.org Git - xonotic/xonotic-maps.pk3dir.git/commitdiff
entities.def -> .ent converter script (beginning)
authorRudolf Polzer <divverent@alientrap.org>
Sun, 5 Dec 2010 15:04:08 +0000 (16:04 +0100)
committerRudolf Polzer <divverent@alientrap.org>
Sun, 5 Dec 2010 15:04:08 +0000 (16:04 +0100)
scripts/entities.def2ent [new file with mode: 0644]

diff --git a/scripts/entities.def2ent b/scripts/entities.def2ent
new file mode 100644 (file)
index 0000000..9de5aa2
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+print <<EOF;
+<?xml version="1.0"?>
+<classes>
+EOF
+
+my $closetag;
+my @spawnflags;
+while(<STDIN>)
+{
+       chomp;
+       s/&/&amp;/g;
+       s/</&lt;/g;
+       s/>/&gt;/g;
+       s/"/&quot;/g;
+       if(/^\/\*QUAKED (\S+) \((\S+ \S+ \S+)\) \((\S+ \S+ \S+)\) \((\S+ \S+ \S+)\) ?(.*)/)
+       {
+               print "<point name=\"$1\" color=\"$2\" box=\"$3 $4\">\n";
+               $closetag = "</point>";
+               @spawnflags = split / /, $5;
+       }
+       elsif(/^\/\*QUAKED (\S+) \((\S+ \S+ \S+)\) \? ?(.*)/)
+       {
+               print "<group name=\"$1\" color=\"$2\">\n";
+               $closetag = "</group>";
+               @spawnflags = split / /, $3;
+       }
+       elsif(/^\*\/$/)
+       {
+               print "$closetag\n";
+       }
+       elsif(/^([0-9a-z_]*): +(.*)/)
+       {
+               print "<string key=\"$1\" name=\"$1\">$2</string>\n";
+       }
+       elsif(/^([0-9A-Z_]*): +(.*)/)
+       {
+               my $bit = [grep { $spawnflags[$_] eq $1; } 0..@spawnflags-1]->[0];
+               warn "Cannot find bit $1 in @spawnflags\n"
+                       if not defined $bit;
+               print "<flag key=\"$1\" name=\"$1\" bit=\"$bit\">$2</flag>\n";
+       }
+       else
+       {
+               print "$_\n";
+       }
+}
+
+print <<EOF;
+</classes>
+EOF