ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/res2pm
Revision: 1.14
Committed: Fri Mar 19 23:11:43 2010 UTC (14 years, 1 month ago) by elmex
Branch: MAIN
CVS Tags: rel-2_01, rel-1_30, HEAD
Changes since 1.13: +1 -2 lines
Log Message:
changed order of attribute overrides.

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 push @{$type->{ignore}}, $i->{Attributes}->{arch};
136 }
137 }
138 } elsif ($e->{Name} eq "import_type") {
139 #push @{$type->{import}}, $type{$e->{Attributes}->{name}} ||= {};
140 push @{$type->{import}}, $e->{Attributes}->{name};
141 } elsif ($e->{Name} eq "use") {
142 $type->{use} = string $e;
143 } elsif ($e->{Name} eq "description") {
144 $type->{desc} = string $e;
145 } elsif ($e->{Name} eq "section") {
146 my @attr;
147 for my $i (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
148 parse_attr $i, \@attr;
149 }
150 push @{ $type->{section} }, [$e->{Attributes}->{name} => \@attr];
151 } else {
152 warn "unknown types subelement ", $e->{Name};
153 }
154 }
155
156 $type
157 }
158
159 for my $e (grep $_->isa ('XML::Grove::Element'), @{$type->root->{Contents}}) {
160 if ($e->{Name} eq "bitmask") {
161 my $bm = $bitmask{$e->{Attributes}->{name}} ||= {};
162 for my $b (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
163 $bm->{$b->{Attributes}->{bit}} = $b->{Attributes}->{name};
164 }
165 } elsif ($e->{Name} eq "list") {
166 my $list = $list{$e->{Attributes}->{name}} ||= {};
167 for my $b (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
168 $list->{$b->{Attributes}->{value}} = $b->{Attributes}->{name};
169 }
170 } elsif ($e->{Name} eq "ignore_list") {
171 my $list = $ignore_list{$e->{Attributes}->{name}} ||= [];
172 for my $b (grep $_->isa ('XML::Grove::Element'), @{$e->{Contents}}) {
173 push @$list, $b->{Attributes}->{arch};
174 }
175 } elsif ($e->{Name} eq "default_type") {
176 parse_type $e, \%default_attr;
177 } elsif ($e->{Name} eq "type") {
178 my $type = $type{$e->{Attributes}->{name}} ||= {};
179
180 $type->{name} = $e->{Attributes}->{name};
181
182 parse_type $e, $type;
183
184 if ($e->{Attributes}->{number} > 0) {
185 $attr{$e->{Attributes}->{number}} = $type;
186 } elsif ($e->{Attributes}->{name} eq "Misc") {
187 delete $type->{required};
188 } else {
189 push @attr0, $type;
190 }
191
192 } else {
193 warn "unknown types element ", $e->{Name};
194 }
195 }
196
197 my $type = $parser->parse ( Source => { SystemId => "res/typenumbers.xml" } );
198
199 for (grep $_->isa ('XML::Grove::Element'), @{$type->root->{Contents}}) {
200 $typename{$_->{Attributes}->{number}} = $_->{Attributes}->{name};
201 }
202
203 my $spell = $parser->parse ( Source => { SystemId => "res/spells.xml" } )
204 or die;
205
206 for (grep $_->isa ('XML::Grove::Element'), @{$spell->root->{Contents}}) {
207 $spell{$_->{Attributes}->{id}} = $_->{Attributes}->{name};
208 }
209
210 dump_hash ["BITMASK", "LIST", "IGNORE_LIST", "DEFAULT_ATTR", "TYPE", "ATTR", "TYPENAME", "SPELL"],
211 [\%bitmask, \%list, \%ignore_list, \%default_attr, \%type, \%attr, \%typename, \%spell];
212
213 print <<EOF;
214
215 =head1 AUTHOR
216
217 Marc Lehmann <schmorp@schmorp.de>
218 http://home.schmorp.de/
219
220 The source files are part of the CFJavaEditor.
221
222 =cut
223
224 1
225 EOF
226