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

Comparing deliantra/Deliantra/Deliantra.pm (file contents):
Revision 1.136 by elmex, Mon Nov 9 15:25:35 2009 UTC vs.
Revision 1.141 by root, Mon Mar 22 00:58:17 2010 UTC

6 6
7=cut 7=cut
8 8
9package Deliantra; 9package Deliantra;
10 10
11our $VERSION = '1.25'; 11our $VERSION = '1.30';
12 12
13use common::sense; 13use common::sense;
14 14
15use base 'Exporter'; 15use base 'Exporter';
16 16
170 : undef 170 : undef
171 }, 171 },
172 '+=' => sub { $_[0][0] |= $MOVE_TYPE{$_[1]}; $_[0][1] |= $MOVE_TYPE{$_[1]}; &normalise }, 172 '+=' => sub { $_[0][0] |= $MOVE_TYPE{$_[1]}; $_[0][1] |= $MOVE_TYPE{$_[1]}; &normalise },
173 '-=' => sub { $_[0][0] |= $MOVE_TYPE{$_[1]}; $_[0][1] &= ~$MOVE_TYPE{$_[1]}; &normalise }, 173 '-=' => sub { $_[0][0] |= $MOVE_TYPE{$_[1]}; $_[0][1] &= ~$MOVE_TYPE{$_[1]}; &normalise },
174 '/=' => sub { $_[0][0] &= ~$MOVE_TYPE{$_[1]}; &normalise }, 174 '/=' => sub { $_[0][0] &= ~$MOVE_TYPE{$_[1]}; &normalise },
175 'x=' => sub { 175 'x=' => sub { # toggle between off, + and -
176 my $cur = $_[0] >= $_[1]; 176 my $cur = $_[0] >= $_[1];
177 if (!defined $cur) { 177 if (!defined $cur) {
178 if ($_[0] >= "all") { 178 if ($_[0] >= "all") {
179 $_[0] -= $_[1]; 179 $_[0] -= $_[1];
180 } else { 180 } else {
814 } else { 814 } else {
815 $root = $Deliantra::Data::TYPE{Misc}; 815 $root = $Deliantra::Data::TYPE{Misc};
816 } 816 }
817 } 817 }
818 818
819 my (%ignore);
819 my @import = ($root); 820 my @import = ($root);
820
821 unshift @import, \%Deliantra::Data::DEFAULT_ATTR
822 unless $type == 116;
823 821
824 my (%ignore); 822 my @new_import;
825 my (@section_order, %section, @attr_order);
826
827 while (my $type = shift @import) { 823 while (my $type = shift @import) {
824 # first import everything we will need:
828 push @import, 825 push @import,
829 grep $_, 826 grep $_,
830 map $Deliantra::Data::TYPE{$_}, 827 map $Deliantra::Data::TYPE{$_},
831 @{$type->{import} || []}; 828 @{$type->{import} || []};
832 829
830 # and compute the ignored attributes
831 for (@{$type->{ignore} || []}) {
832 $ignore{$_}++ for ref $_ ? @$_ : $_;
833 }
834
835 push @new_import, $type;
836 }
837 (@import) = @new_import;
838
839 # then add defaults to the back of the list, so they are added
840 # as last resort.
841 push @import, \%Deliantra::Data::DEFAULT_ATTR
842 unless $type == 116;
843
844 my (@section_order, %section, @attr_order);
845
846 # @import = root, imported, default
847 while (my $type = pop @import) {
833 $attr->{$_} ||= $type->{$_} 848 $attr->{$_} ||= $type->{$_}
834 for qw(name desc use); 849 for qw(name desc use);
835
836 for (@{$type->{ignore} || []}) {
837 $ignore{$_}++ for ref $_ ? @$_ : $_;
838 }
839 850
840 for ([general => ($type->{attr} || [])], @{$type->{section} || []}) { 851 for ([general => ($type->{attr} || [])], @{$type->{section} || []}) {
841 my ($name, $attr) = @$_; 852 my ($name, $attr) = @$_;
842 push @section_order, $name; 853 push @section_order, $name;
843 for (@$attr) { 854 for (@$attr) {
844 my ($k, $v) = @$_; 855 my ($k, $v) = @$_;
845 push @attr_order, $k; 856 push @attr_order, $k;
846 $section{$name}{$k} ||= $v; 857 $section{$name}{$k} = $v; # overwrite, so that the root decides
847 }
848 } 858 }
859 }
860 }
861
862 # remove ignores for "root" type
863 for (
864 map @{$_->[1]}, # section attributes
865 [general => ($root->{attr} || [])],
866 @{$root->{section} || []}
867 ) {
868 my ($k, $v) = @$_;
869 # skip fixed attributes, if they are ignored thats fine
870 next if $v->{type} eq 'fixed';
871
872 delete $ignore{$k}; # if the attributes are defined explicitly they
873 # should NOT be ignored. ignore should mainly
874 # hit imported/inherited attributes.
849 } 875 }
850 876
851 $attr->{section} = [ 877 $attr->{section} = [
852 map !exists $section{$_} ? () : do { 878 map !exists $section{$_} ? () : do {
853 my $attr = delete $section{$_}; 879 my $attr = delete $section{$_};
857 map exists $attr->{$_} && !$ignore{$_} 883 map exists $attr->{$_} && !$ignore{$_}
858 ? [$_ => delete $attr->{$_}] : (), 884 ? [$_ => delete $attr->{$_}] : (),
859 @attr_order 885 @attr_order
860 ] 886 ]
861 }, 887 },
862
863 exists $section{$_} ? [$_ => delete $section{$_}] : (), 888 exists $section{$_} ? [$_ => delete $section{$_}] : (),
864 @section_order 889 @section_order
865 ]; 890 ];
866 891
867 $attr 892 $attr
868} 893}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines