--- deliantra/Deliantra/res2pm 2006/02/22 21:20:19 1.2 +++ deliantra/Deliantra/res2pm 2006/02/22 21:57:29 1.3 @@ -30,24 +30,36 @@ use XML::Parser::Grove; sub dump_hash { - my ($name, $ref) = @_; - require Data::Dumper; - $d = new Data::Dumper ([$ref], ["*$name"]); + my ($names, $refs) = @_; + + $d = new Data::Dumper ($refs, [map "*$_", @$names]); $d->Terse (1); $d->Indent (1); $d->Quotekeys (0); - $d->Useqq (1); + $d->Useqq (0); + $d->Useperl(1); $d->Sortkeys (sub { [sort { $a > 0 && $b > 0 ? $a <=> $b : $a cmp $b } keys %{+shift}] }); - my $d = $d->Dump; - $d =~ s/^ /\t\t/gm; - $d =~ s/^ /\t/gm; - $d =~ s/\s+$//; - print "our %$name = $d;\n\n"; + + my @vals = $d->Dump; + + while (@vals) { + my $v = shift @vals; + $v =~ s/^ /\t\t/gm; + $v =~ s/^ /\t/gm; + $v =~ s/\s+$//; + + my $name = shift @$names; + my $ref = shift @$refs; + + my $sigil = ref $ref eq "ARRAY" ? '@' : '%'; + + print "our $sigil$name = $v;\n\n"; + } } my $type = XML::Parser->new (Style => 'grove')->parsefile ("res/types.xml"); @@ -55,9 +67,12 @@ my %bitmask; my %list; my %type; -my $attr; +my %typename; +my @attr0; +my %attr; my %ignore_list; my %default_attr; +my %spell; sub string($) { local $_ = join "", @{shift->contents}; @@ -71,14 +86,21 @@ my ($e, $sect) = @_; my $arch = { - name => $e->attr ("editor"), type => $e->attr ("type"), + name => $e->attr ("editor"), desc => string $e, $e->attr("arch_begin") ? (end => $e->attr("arch_end")) : (), }; + delete $arch->{name} unless defined $arch->{name}; + delete $arch->{desc} unless length $arch->{desc}; + if ($arch->{type} =~ s/^(bitmask)_(.*)/$1/) { - $arch->{values} = $BITMASK{$2} ||= {}; + $arch->{value} = $bitmask{$2} ||= {}; + } elsif ($arch->{type} =~ s/^(list)_(.*)/$1/) { + $arch->{value} = $list{$2} ||= {}; + } elsif ($arch->{type} =~ s/^bool_special$/bool/) { + $arch->{value} = [$e->attr ("false"), $e->attr ("true")]; } $sect->{$e->attr ("arch") || $e->attr("arch_begin")} = $arch; @@ -103,7 +125,7 @@ } } } elsif ($e->name eq "import_type") { - push @{$type->{import}}, $xtype{$e->attr ("name")} ||= {}; + push @{$type->{import}}, $type{$e->attr ("name")} ||= {}; } elsif ($e->name eq "use") { $type->{use} = string $e; } elsif ($e->name eq "description") { @@ -140,10 +162,17 @@ } elsif ($e->name eq "default_type") { parse_type $e, \%default_attr; } elsif ($e->name eq "type") { - my $type = $attr{$e->attr ("name")} ||= {}; + my $type = $type{$e->attr ("name")} ||= {}; parse_type $e, $type; - unshift @{$type->{import}}, \%default_attr; - $type{$e->attr ("number")}{type}{$e->attr ("name")} = $type; + #unshift @{$type->{import}}, \%default_attr; + + if ($e->attr ("number") > 0) { + $attr{$e->attr ("number")} = $type; + } elsif ($e->attr ("name") eq "Misc") { + delete $type->{required}; + } else { + push @attr0, $type; + } } else { warn "unknown types element ", $e->name; @@ -153,21 +182,18 @@ my $type = XML::Parser->new (Style => 'grove')->parsefile ("res/typenumbers.xml"); for (grep ref, @{$type->root->contents}) { - $type{$_->attr ("number")}{name} = $_->attr ("name"); + $typename{$_->attr ("number")} = $_->attr ("name"); } -dump_hash "TYPE", \%type; - my $spell = XML::Parser->new (Style => 'grove')->parsefile ("res/spells.xml") or die; -my %spell; - for (grep ref, @{$spell->root->contents}) { $spell{$_->attr ("id")} = $_->attr ("name"); } -dump_hash "SPELL", \%spell; +dump_hash ["BITMASK", "LIST", "IGNORE_LIST", "DEFAULT_ATTR", "TYPE", "ATTR0", "ATTR", "TYPENAME", "SPELL"], + [\%bitmask, \%list, \%ignore_list, \%default_attr, \%type, \@attr0, \%attr, \%typename, \%spell]; print <