ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra/res2pm
(Generate patch)

Comparing deliantra/Deliantra/res2pm (file contents):
Revision 1.2 by root, Wed Feb 22 21:20:19 2006 UTC vs.
Revision 1.10 by root, Tue Jul 3 00:16:50 2007 UTC

22 22
23See F<res/README> for more info. 23See F<res/README> for more info.
24 24
25=cut 25=cut
26 26
27package Crossfire::Data;
28
27EOF 29EOF
28 30
29use Data::Dumper; 31use Data::Dumper;
30use XML::Parser::Grove; 32use XML::Parser::Grove;
31 33
32sub dump_hash { 34sub 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
53my $type = XML::Parser->new (Style => 'grove')->parsefile ("res/types.xml"); 67my $type = XML::Parser->new (Style => 'grove')->parsefile ("res/types.xml");
54 68
55my %bitmask; 69my %bitmask;
56my %list; 70my %list;
57my %type; 71my %type;
72my %typename;
73my @attr0;
58my $attr; 74my %attr;
59my %ignore_list; 75my %ignore_list;
60my %default_attr; 76my %default_attr;
77my %spell;
61 78
62sub string($) { 79sub 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
70sub parse_attr { 87sub 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} eq "fixed") {
105 $arch->{value} = $e->attr ("value");
106 } elsif ($arch->{type} =~ s/^bool_special$/bool/) {
107 $arch->{value} = [$e->attr ("false"), $e->attr ("true")];
82 } 108 }
83 109
84 $sect->{$e->attr ("arch") || $e->attr("arch_begin")} = $arch; 110 push @$sect, [$e->attr ("arch") || $e->attr("arch_begin"), $arch];
85} 111}
86 112
87sub parse_type { 113sub parse_type {
88 my ($e, $type) = @_; 114 my ($e, $type) = @_;
89 115
116 my %main;
117
90 for my $e (grep ref, @{$e->contents}) { 118 for my $e (grep ref, @{$e->contents}) {
91 if ($e->name eq "required") { 119 if ($e->name eq "required") {
120 # not used
92 for my $i (grep ref, @{$e->contents}) { 121 #for my $i (grep ref, @{$e->contents}) {
93 $type->{required}{$i->attr ("arch")} = $i->attr ("value"); 122 # $type->{required}{$i->attr ("arch")} = $i->attr ("value");
94 } 123 #}
95 } elsif ($e->name eq "attribute") { 124 } elsif ($e->name eq "attribute") {
96 parse_attr $e, $type->{attr}{Main} ||= {}; 125 parse_attr $e, $type->{attr} ||= [];
97 } elsif ($e->name eq "ignore") { 126 } elsif ($e->name eq "ignore") {
98 for my $i (grep ref, @{$e->contents}) { 127 for my $i (grep ref, @{$e->contents}) {
99 if ($i->name eq "ignore_list") { 128 if ($i->name eq "ignore_list") {
100 push @{$type->{ignore}}, $ignore_list{$i->attr ("name")} ||= []; 129 push @{$type->{ignore}}, $ignore_list{$i->attr ("name")} ||= [];
101 } elsif ($i->name eq "attribute") { 130 } elsif ($i->name eq "attribute") {
102 push @{$type->{ignore}}, $i->attr ("arch"); 131 push @{$type->{ignore}}, $i->attr ("arch");
103 } 132 }
104 } 133 }
105 } elsif ($e->name eq "import_type") { 134 } elsif ($e->name eq "import_type") {
106 push @{$type->{import}}, $xtype{$e->attr ("name")} ||= {}; 135 #push @{$type->{import}}, $type{$e->attr ("name")} ||= {};
136 push @{$type->{import}}, $e->attr ("name");
107 } elsif ($e->name eq "use") { 137 } elsif ($e->name eq "use") {
108 $type->{use} = string $e; 138 $type->{use} = string $e;
109 } elsif ($e->name eq "description") { 139 } elsif ($e->name eq "description") {
110 $type->{desc} = string $e; 140 $type->{desc} = string $e;
111 } elsif ($e->name eq "section") { 141 } elsif ($e->name eq "section") {
142 my @attr;
112 for my $i (grep ref, @{$e->contents}) { 143 for my $i (grep ref, @{$e->contents}) {
113 parse_attr $i, $type->{attr}{$e->attr ("name")} ||= {}; 144 parse_attr $i, \@attr;
114 } 145 }
115# $type->{desc} = string $e; 146 push @{ $type->{section} }, [$e->attr ("name") => \@attr];
116 } else { 147 } else {
117 warn "unknown types subelement ", $e->name; 148 warn "unknown types subelement ", $e->name;
118 } 149 }
119 } 150 }
120 151
138 push @$list, $b->attr ("arch"); 169 push @$list, $b->attr ("arch");
139 } 170 }
140 } elsif ($e->name eq "default_type") { 171 } elsif ($e->name eq "default_type") {
141 parse_type $e, \%default_attr; 172 parse_type $e, \%default_attr;
142 } elsif ($e->name eq "type") { 173 } elsif ($e->name eq "type") {
143 my $type = $attr{$e->attr ("name")} ||= {}; 174 my $type = $type{$e->attr ("name")} ||= {};
175
176 $type->{name} = $e->attr ("name");
177
144 parse_type $e, $type; 178 parse_type $e, $type;
145 unshift @{$type->{import}}, \%default_attr; 179
146 $type{$e->attr ("number")}{type}{$e->attr ("name")} = $type; 180 if ($e->attr ("number") > 0) {
181 $attr{$e->attr ("number")} = $type;
182 } elsif ($e->attr ("name") eq "Misc") {
183 delete $type->{required};
184 } else {
185 push @attr0, $type;
186 }
147 187
148 } else { 188 } else {
149 warn "unknown types element ", $e->name; 189 warn "unknown types element ", $e->name;
150 } 190 }
151} 191}
152 192
153my $type = XML::Parser->new (Style => 'grove')->parsefile ("res/typenumbers.xml"); 193my $type = XML::Parser->new (Style => 'grove')->parsefile ("res/typenumbers.xml");
154 194
155for (grep ref, @{$type->root->contents}) { 195for (grep ref, @{$type->root->contents}) {
156 $type{$_->attr ("number")}{name} = $_->attr ("name"); 196 $typename{$_->attr ("number")} = $_->attr ("name");
157} 197}
158
159dump_hash "TYPE", \%type;
160 198
161my $spell = XML::Parser->new (Style => 'grove')->parsefile ("res/spells.xml") 199my $spell = XML::Parser->new (Style => 'grove')->parsefile ("res/spells.xml")
162 or die; 200 or die;
163 201
164my %spell;
165
166for (grep ref, @{$spell->root->contents}) { 202for (grep ref, @{$spell->root->contents}) {
167 $spell{$_->attr ("id")} = $_->attr ("name"); 203 $spell{$_->attr ("id")} = $_->attr ("name");
168} 204}
169 205
170dump_hash "SPELL", \%spell; 206dump_hash ["BITMASK", "LIST", "IGNORE_LIST", "DEFAULT_ATTR", "TYPE", "ATTR", "TYPENAME", "SPELL"],
207 [\%bitmask, \%list, \%ignore_list, \%default_attr, \%type, \%attr, \%typename, \%spell];
171 208
172print <<EOF; 209print <<EOF;
173 210
174=head1 AUTHOR 211=head1 AUTHOR
175 212

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines