… | |
… | |
22 | |
22 | |
23 | See F<res/README> for more info. |
23 | See F<res/README> for more info. |
24 | |
24 | |
25 | =cut |
25 | =cut |
26 | |
26 | |
|
|
27 | package Crossfire::Data; |
|
|
28 | |
27 | EOF |
29 | EOF |
28 | |
30 | |
29 | use Data::Dumper; |
31 | use Data::Dumper; |
30 | use XML::Parser::Grove; |
32 | use XML::Parser::Grove; |
31 | |
33 | |
32 | sub dump_hash { |
34 | sub dump_hash { |
33 | my ($name, $ref) = @_; |
35 | my ($names, $refs) = @_; |
34 | require Data::Dumper; |
36 | |
35 | $d = new Data::Dumper ([$ref], ["*$name"]); |
37 | $d = new Data::Dumper ($refs, [map "*$_", @$names]); |
36 | $d->Terse (1); |
38 | $d->Terse (1); |
37 | $d->Indent (1); |
39 | $d->Indent (1); |
38 | $d->Quotekeys (0); |
40 | $d->Quotekeys (0); |
39 | $d->Useqq (1); |
41 | $d->Useqq (0); |
|
|
42 | $d->Useperl(1); |
40 | $d->Sortkeys (sub { |
43 | $d->Sortkeys (sub { |
41 | [sort { |
44 | [sort { |
42 | $a > 0 && $b > 0 ? $a <=> $b |
45 | $a > 0 && $b > 0 ? $a <=> $b |
43 | : $a cmp $b |
46 | : $a cmp $b |
44 | } keys %{+shift}] |
47 | } keys %{+shift}] |
45 | }); |
48 | }); |
|
|
49 | |
46 | my $d = $d->Dump; |
50 | my @vals = $d->Dump; |
|
|
51 | |
|
|
52 | while (@vals) { |
|
|
53 | my $v = shift @vals; |
47 | $d =~ s/^ /\t\t/gm; |
54 | $v =~ s/^ /\t\t/gm; |
48 | $d =~ s/^ /\t/gm; |
55 | $v =~ s/^ /\t/gm; |
49 | $d =~ s/\s+$//; |
56 | $v =~ s/\s+$//; |
|
|
57 | |
|
|
58 | my $name = shift @$names; |
|
|
59 | my $ref = shift @$refs; |
|
|
60 | |
|
|
61 | my $sigil = ref $ref eq "ARRAY" ? '@' : '%'; |
|
|
62 | |
50 | print "our %$name = $d;\n\n"; |
63 | print "our $sigil$name = $v;\n\n"; |
|
|
64 | } |
51 | } |
65 | } |
52 | |
66 | |
53 | my $type = XML::Parser->new (Style => 'grove')->parsefile ("res/types.xml"); |
67 | my $type = XML::Parser->new (Style => 'grove')->parsefile ("res/types.xml"); |
54 | |
68 | |
55 | my %bitmask; |
69 | my %bitmask; |
56 | my %list; |
70 | my %list; |
57 | my %type; |
71 | my %type; |
|
|
72 | my %typename; |
|
|
73 | my @attr0; |
58 | my $attr; |
74 | my %attr; |
59 | my %ignore_list; |
75 | my %ignore_list; |
60 | my %default_attr; |
76 | my %default_attr; |
|
|
77 | my %spell; |
61 | |
78 | |
62 | sub string($) { |
79 | sub string($) { |
63 | local $_ = join "", @{shift->contents}; |
80 | local $_ = join "", @{shift->contents}; |
64 | $_ =~ s/^\s+//; |
81 | $_ =~ s/^\s+//; |
65 | $_ =~ s/\s+$//; |
82 | $_ =~ s/\s+$//; |
… | |
… | |
69 | |
86 | |
70 | sub parse_attr { |
87 | sub parse_attr { |
71 | my ($e, $sect) = @_; |
88 | my ($e, $sect) = @_; |
72 | |
89 | |
73 | my $arch = { |
90 | my $arch = { |
|
|
91 | type => $e->attr ("type"), |
74 | name => $e->attr ("editor"), |
92 | name => $e->attr ("editor"), |
75 | type => $e->attr ("type"), |
|
|
76 | desc => string $e, |
93 | desc => string $e, |
77 | $e->attr("arch_begin") ? (end => $e->attr("arch_end")) : (), |
94 | $e->attr("arch_begin") ? (end => $e->attr("arch_end")) : (), |
78 | }; |
95 | }; |
79 | |
96 | |
|
|
97 | delete $arch->{name} unless defined $arch->{name}; |
|
|
98 | delete $arch->{desc} unless length $arch->{desc}; |
|
|
99 | |
80 | if ($arch->{type} =~ s/^(bitmask)_(.*)/$1/) { |
100 | if ($arch->{type} =~ s/^(bitmask)_(.*)/$1/) { |
|
|
101 | $arch->{value} = $bitmask{$2} ||= {}; |
|
|
102 | } elsif ($arch->{type} =~ s/^(list)_(.*)/$1/) { |
81 | $arch->{values} = $BITMASK{$2} ||= {}; |
103 | $arch->{value} = $list{$2} ||= {}; |
|
|
104 | } elsif ($arch->{type} =~ s/^bool_special$/bool/) { |
|
|
105 | $arch->{value} = [$e->attr ("false"), $e->attr ("true")]; |
82 | } |
106 | } |
83 | |
107 | |
84 | $sect->{$e->attr ("arch") || $e->attr("arch_begin")} = $arch; |
108 | $sect->{$e->attr ("arch") || $e->attr("arch_begin")} = $arch; |
85 | } |
109 | } |
86 | |
110 | |
87 | sub parse_type { |
111 | sub parse_type { |
88 | my ($e, $type) = @_; |
112 | my ($e, $type) = @_; |
|
|
113 | |
|
|
114 | my %main; |
89 | |
115 | |
90 | for my $e (grep ref, @{$e->contents}) { |
116 | for my $e (grep ref, @{$e->contents}) { |
91 | if ($e->name eq "required") { |
117 | if ($e->name eq "required") { |
92 | for my $i (grep ref, @{$e->contents}) { |
118 | for my $i (grep ref, @{$e->contents}) { |
93 | $type->{required}{$i->attr ("arch")} = $i->attr ("value"); |
119 | $type->{required}{$i->attr ("arch")} = $i->attr ("value"); |
94 | } |
120 | } |
95 | } elsif ($e->name eq "attribute") { |
121 | } elsif ($e->name eq "attribute") { |
96 | parse_attr $e, $type->{attr}{Main} ||= {}; |
122 | parse_attr $e, $type->{attr} ||= {}; |
97 | } elsif ($e->name eq "ignore") { |
123 | } elsif ($e->name eq "ignore") { |
98 | for my $i (grep ref, @{$e->contents}) { |
124 | for my $i (grep ref, @{$e->contents}) { |
99 | if ($i->name eq "ignore_list") { |
125 | if ($i->name eq "ignore_list") { |
100 | push @{$type->{ignore}}, $ignore_list{$i->attr ("name")} ||= []; |
126 | push @{$type->{ignore}}, $ignore_list{$i->attr ("name")} ||= []; |
101 | } elsif ($i->name eq "attribute") { |
127 | } elsif ($i->name eq "attribute") { |
102 | push @{$type->{ignore}}, $i->attr ("arch"); |
128 | push @{$type->{ignore}}, $i->attr ("arch"); |
103 | } |
129 | } |
104 | } |
130 | } |
105 | } elsif ($e->name eq "import_type") { |
131 | } elsif ($e->name eq "import_type") { |
106 | push @{$type->{import}}, $xtype{$e->attr ("name")} ||= {}; |
132 | push @{$type->{import}}, $type{$e->attr ("name")} ||= {}; |
107 | } elsif ($e->name eq "use") { |
133 | } elsif ($e->name eq "use") { |
108 | $type->{use} = string $e; |
134 | $type->{use} = string $e; |
109 | } elsif ($e->name eq "description") { |
135 | } elsif ($e->name eq "description") { |
110 | $type->{desc} = string $e; |
136 | $type->{desc} = string $e; |
111 | } elsif ($e->name eq "section") { |
137 | } elsif ($e->name eq "section") { |
|
|
138 | my %attr; |
112 | for my $i (grep ref, @{$e->contents}) { |
139 | for my $i (grep ref, @{$e->contents}) { |
113 | parse_attr $i, $type->{attr}{$e->attr ("name")} ||= {}; |
140 | parse_attr $i, \%attr; |
114 | } |
141 | } |
115 | # $type->{desc} = string $e; |
142 | push @{ $type->{section} }, [$e->attr ("name") => \%attr]; |
116 | } else { |
143 | } else { |
117 | warn "unknown types subelement ", $e->name; |
144 | warn "unknown types subelement ", $e->name; |
118 | } |
145 | } |
119 | } |
146 | } |
120 | |
147 | |
… | |
… | |
138 | push @$list, $b->attr ("arch"); |
165 | push @$list, $b->attr ("arch"); |
139 | } |
166 | } |
140 | } elsif ($e->name eq "default_type") { |
167 | } elsif ($e->name eq "default_type") { |
141 | parse_type $e, \%default_attr; |
168 | parse_type $e, \%default_attr; |
142 | } elsif ($e->name eq "type") { |
169 | } elsif ($e->name eq "type") { |
143 | my $type = $attr{$e->attr ("name")} ||= {}; |
170 | my $type = $type{$e->attr ("name")} ||= {}; |
|
|
171 | |
|
|
172 | $type->{name} = $e->attr ("name"); |
|
|
173 | |
144 | parse_type $e, $type; |
174 | parse_type $e, $type; |
145 | unshift @{$type->{import}}, \%default_attr; |
175 | #unshift @{$type->{import}}, \%default_attr; |
146 | $type{$e->attr ("number")}{type}{$e->attr ("name")} = $type; |
176 | |
|
|
177 | if ($e->attr ("number") > 0) { |
|
|
178 | $attr{$e->attr ("number")} = $type; |
|
|
179 | } elsif ($e->attr ("name") eq "Misc") { |
|
|
180 | delete $type->{required}; |
|
|
181 | } else { |
|
|
182 | push @attr0, $type; |
|
|
183 | } |
147 | |
184 | |
148 | } else { |
185 | } else { |
149 | warn "unknown types element ", $e->name; |
186 | warn "unknown types element ", $e->name; |
150 | } |
187 | } |
151 | } |
188 | } |
152 | |
189 | |
153 | my $type = XML::Parser->new (Style => 'grove')->parsefile ("res/typenumbers.xml"); |
190 | my $type = XML::Parser->new (Style => 'grove')->parsefile ("res/typenumbers.xml"); |
154 | |
191 | |
155 | for (grep ref, @{$type->root->contents}) { |
192 | for (grep ref, @{$type->root->contents}) { |
156 | $type{$_->attr ("number")}{name} = $_->attr ("name"); |
193 | $typename{$_->attr ("number")} = $_->attr ("name"); |
157 | } |
194 | } |
158 | |
|
|
159 | dump_hash "TYPE", \%type; |
|
|
160 | |
195 | |
161 | my $spell = XML::Parser->new (Style => 'grove')->parsefile ("res/spells.xml") |
196 | my $spell = XML::Parser->new (Style => 'grove')->parsefile ("res/spells.xml") |
162 | or die; |
197 | or die; |
163 | |
198 | |
164 | my %spell; |
|
|
165 | |
|
|
166 | for (grep ref, @{$spell->root->contents}) { |
199 | for (grep ref, @{$spell->root->contents}) { |
167 | $spell{$_->attr ("id")} = $_->attr ("name"); |
200 | $spell{$_->attr ("id")} = $_->attr ("name"); |
168 | } |
201 | } |
169 | |
202 | |
170 | dump_hash "SPELL", \%spell; |
203 | dump_hash ["BITMASK", "LIST", "IGNORE_LIST", "DEFAULT_ATTR", "TYPE", "ATTR0", "ATTR", "TYPENAME", "SPELL"], |
|
|
204 | [\%bitmask, \%list, \%ignore_list, \%default_attr, \%type, \@attr0, \%attr, \%typename, \%spell]; |
171 | |
205 | |
172 | print <<EOF; |
206 | print <<EOF; |
173 | |
207 | |
174 | =head1 AUTHOR |
208 | =head1 AUTHOR |
175 | |
209 | |