ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/res2pm
Revision: 1.13
Committed: Fri Mar 19 21:38:14 2010 UTC (14 years, 1 month ago) by elmex
Branch: MAIN
Changes since 1.12: +2 -1 lines
Log Message:
added broken connected field.

File Contents

# Content
1 #!/opt/bin/perl
2
3 # usage: res2pm
4
5 open STDOUT, ">:utf8", "Deliantra/Data.pm"
6 or die "Deliantra/Data.pm: $!";
7
8 print <<EOF;
9 =head1 NAME
10
11 Deliantra::Data - various data structures useful for understanding archs and objects
12
13 =head1
14
15 THIS FILE IS AUTOGENERATED, DO NOT EDIT!
16
17 It's a translation of the following files:
18
19 res/spells.xml
20 res/types.xml
21 res/typenumbers.xml
22
23 See F<res/README> for more info.
24
25 =cut
26
27 package Deliantra::Data;
28
29 EOF
30
31 use Data::Dumper;
32 use XML::Grove::Builder;
33 use XML::Parser::PerlSAX;
34
35
36 sub dump_hash {
37 my ($names, $refs) = @_;
38
39 $d = new Data::Dumper ($refs, [map "*$_", @$names]);
40 $d->Terse (1);
41 $d->Indent (1);
42 $d->Quotekeys (0);
43 $d->Useqq (0);
44 $d->Useperl(1);
45 $d->Sortkeys (sub {
46 [sort {
47 $a > 0 && $b > 0 ? $a <=> $b
48 : $a cmp $b
49 } keys %{+shift}]
50 });
51
52 my @vals = $d->Dump;
53
54 while (@vals) {
55 my $v = shift @vals;
56 $v =~ s/^ /\t\t/gm;
57 $v =~ s/^ /\t/gm;
58 $v =~ s/\s+$//;
59
60 my $name = shift @$names;
61 my $ref = shift @$refs;
62
63 my $sigil = ref $ref eq "ARRAY" ? '@' : '%';
64
65 print "our $sigil$name = $v;\n\n";
66 }
67 }
68
69 my $grove_builder = XML::Grove::Builder->new;
70 my $parser = XML::Parser::PerlSAX->new ( Handler => $grove_builder );
71 my $type = $parser->parse ( Source => { SystemId => "res/types.xml" } );
72
73 my %bitmask;
74 my %list;
75 my %type;
76 my %typename;
77 my @attr0;
78 my %attr;
79 my %ignore_list;
80 my %default_attr;
81 my %spell;
82
83 sub string($) {
84 local $_ = join "", map $_->{Data}, @{shift->{Contents}};
85 $_ =~ s/^\s+//;
86 $_ =~ s/\s+$//;
87 $_ =~ s/\s+/ /g;
88 $_
89 }
90
91 sub parse_attr {
92 my ($e, $sect) = @_;
93
94 my $arch = {
95 type => $e->{Attributes}->{type},
96 name => $e->{Attributes}->{editor},
97 desc => string $e,
98 $e->{Attributes}->{arch_begin} ? (end => $e->{Attributes}->{arch_end}) : (),
99 };
100
101 delete $arch->{name} unless defined $arch->{name};
102 delete $arch->{desc} unless length $arch->{desc};
103
104 if ($arch->{type} =~ s/^(bitmask)_(.*)/$1/) {
105 $arch->{value} = $bitmask{$2} ||= {};
106 } elsif ($arch->{type} =~ s/^(list)_(.*)/$1/) {
107 $arch->{value} = $list{$2} ||= {};
108 } elsif ($arch->{type} eq "fixed") {
109 $arch->{value} = $e->{Attributes}->{value};
110 } elsif ($arch->{type} =~ s/^bool_special$/bool/) {
111 $arch->{value} = [$e->{Attributes}->{false}, $e->{Attributes}->{true}];
112 }
113
114 push @$sect, [$e->{Attributes}->{arch} || $e->{Attributes}->{arch_begin}, $arch];
115 }
116
117 sub parse_type {
118 my ($e, $type) = @_;
119
120 my %main;
121
122 for my $e (grep { $_->isa ('XML::Grove::Element') } @{$e->{Contents}}) {
123 if ($e->{Name} eq "required") {
124 # not used
125 #for my $i (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
126 # $type->{required}{$i->{Attributes}->{arch}} = $i->{Attributes}->{value};
127 #}
128 } elsif ($e->{Name} eq "attribute") {
129 parse_attr $e, $type->{attr} ||= [];
130 } elsif ($e->{Name} eq "ignore") {
131 for my $i (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
132 if ($i->{Name} eq "ignore_list") {
133 push @{$type->{ignore}}, $ignore_list{$i->{Attributes}->{name}} ||= [];
134 } elsif ($i->{Name} eq "attribute") {
135 warn "ACDD $i->{Attributes}->{arch}\n";
136 push @{$type->{ignore}}, [$i->{Attributes}->{arch}];
137 }
138 }
139 } elsif ($e->{Name} eq "import_type") {
140 #push @{$type->{import}}, $type{$e->{Attributes}->{name}} ||= {};
141 push @{$type->{import}}, $e->{Attributes}->{name};
142 } elsif ($e->{Name} eq "use") {
143 $type->{use} = string $e;
144 } elsif ($e->{Name} eq "description") {
145 $type->{desc} = string $e;
146 } elsif ($e->{Name} eq "section") {
147 my @attr;
148 for my $i (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
149 parse_attr $i, \@attr;
150 }
151 push @{ $type->{section} }, [$e->{Attributes}->{name} => \@attr];
152 } else {
153 warn "unknown types subelement ", $e->{Name};
154 }
155 }
156
157 $type
158 }
159
160 for my $e (grep $_->isa ('XML::Grove::Element'), @{$type->root->{Contents}}) {
161 if ($e->{Name} eq "bitmask") {
162 my $bm = $bitmask{$e->{Attributes}->{name}} ||= {};
163 for my $b (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
164 $bm->{$b->{Attributes}->{bit}} = $b->{Attributes}->{name};
165 }
166 } elsif ($e->{Name} eq "list") {
167 my $list = $list{$e->{Attributes}->{name}} ||= {};
168 for my $b (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
169 $list->{$b->{Attributes}->{value}} = $b->{Attributes}->{name};
170 }
171 } elsif ($e->{Name} eq "ignore_list") {
172 my $list = $ignore_list{$e->{Attributes}->{name}} ||= [];
173 for my $b (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
174 push @$list, $b->{Attributes}->{arch};
175 }
176 } elsif ($e->{Name} eq "default_type") {
177 parse_type $e, \%default_attr;
178 } elsif ($e->{Name} eq "type") {
179 my $type = $type{$e->{Attributes}->{name}} ||= {};
180
181 $type->{name} = $e->{Attributes}->{name};
182
183 parse_type $e, $type;
184
185 if ($e->{Attributes}->{number} > 0) {
186 $attr{$e->{Attributes}->{number}} = $type;
187 } elsif ($e->{Attributes}->{name} eq "Misc") {
188 delete $type->{required};
189 } else {
190 push @attr0, $type;
191 }
192
193 } else {
194 warn "unknown types element ", $e->{Name};
195 }
196 }
197
198 my $type = $parser->parse ( Source => { SystemId => "res/typenumbers.xml" } );
199
200 for (grep $_->isa ('XML::Grove::Element'), @{$type->root->{Contents}}) {
201 $typename{$_->{Attributes}->{number}} = $_->{Attributes}->{name};
202 }
203
204 my $spell = $parser->parse ( Source => { SystemId => "res/spells.xml" } )
205 or die;
206
207 for (grep $_->isa ('XML::Grove::Element'), @{$spell->root->{Contents}}) {
208 $spell{$_->{Attributes}->{id}} = $_->{Attributes}->{name};
209 }
210
211 dump_hash ["BITMASK", "LIST", "IGNORE_LIST", "DEFAULT_ATTR", "TYPE", "ATTR", "TYPENAME", "SPELL"],
212 [\%bitmask, \%list, \%ignore_list, \%default_attr, \%type, \%attr, \%typename, \%spell];
213
214 print <<EOF;
215
216 =head1 AUTHOR
217
218 Marc Lehmann <schmorp@schmorp.de>
219 http://home.schmorp.de/
220
221 The source files are part of the CFJavaEditor.
222
223 =cut
224
225 1
226 EOF
227