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.135 by root, Tue Nov 3 14:56:58 2009 UTC vs.
Revision 1.140 by elmex, Fri Mar 19 23:11:43 2010 UTC

6 6
7=cut 7=cut
8 8
9package Deliantra; 9package Deliantra;
10 10
11our $VERSION = '1.25'; 11our $VERSION = '1.29';
12 12
13use common::sense; 13use common::sense;
14 14
15use base 'Exporter'; 15use base 'Exporter';
16 16
162 162
163 use overload 163 use overload
164 '=' => sub { bless [@{$_[0]}], ref $_[0] }, 164 '=' => sub { bless [@{$_[0]}], ref $_[0] },
165 '""' => \&as_string, 165 '""' => \&as_string,
166 '>=' => sub { $_[0][0] & $MOVE_TYPE{$_[1]} ? $_[0][1] & $MOVE_TYPE{$_[1]} : undef }, 166 '>=' => sub { $_[0][0] & $MOVE_TYPE{$_[1]} ? $_[0][1] & $MOVE_TYPE{$_[1]} : undef },
167 '<=' => sub {
168 ($_[0][0] & $MOVE_TYPE{$_[1]}) == $MOVE_TYPE{$_[1]}
169 ? $_[0][1] & $MOVE_TYPE{$_[1]}
170 : undef
171 },
167 '+=' => 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 },
168 '-=' => 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 },
169 '/=' => sub { $_[0][0] &= ~$MOVE_TYPE{$_[1]}; &normalise }, 174 '/=' => sub { $_[0][0] &= ~$MOVE_TYPE{$_[1]}; &normalise },
170 'x=' => sub { 175 'x=' => sub { # toggle between off, + and -
171 my $cur = $_[0] >= $_[1]; 176 my $cur = $_[0] >= $_[1];
172 if (!defined $cur) { 177 if (!defined $cur) {
173 if ($_[0] >= "all") { 178 if ($_[0] >= "all") {
174 $_[0] -= $_[1]; 179 $_[0] -= $_[1];
175 } else { 180 } else {
809 } else { 814 } else {
810 $root = $Deliantra::Data::TYPE{Misc}; 815 $root = $Deliantra::Data::TYPE{Misc};
811 } 816 }
812 } 817 }
813 818
819 my (%ignore);
814 my @import = ($root); 820 my @import = ($root);
815
816 unshift @import, \%Deliantra::Data::DEFAULT_ATTR
817 unless $type == 116;
818 821
819 my (%ignore); 822 my @new_import;
820 my (@section_order, %section, @attr_order);
821
822 while (my $type = shift @import) { 823 while (my $type = shift @import) {
824 # first import everything we will need:
823 push @import, 825 push @import,
824 grep $_, 826 grep $_,
825 map $Deliantra::Data::TYPE{$_}, 827 map $Deliantra::Data::TYPE{$_},
826 @{$type->{import} || []}; 828 @{$type->{import} || []};
827 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) {
828 $attr->{$_} ||= $type->{$_} 848 $attr->{$_} ||= $type->{$_}
829 for qw(name desc use); 849 for qw(name desc use);
830
831 for (@{$type->{ignore} || []}) {
832 $ignore{$_}++ for ref $_ ? @$_ : $_;
833 }
834 850
835 for ([general => ($type->{attr} || [])], @{$type->{section} || []}) { 851 for ([general => ($type->{attr} || [])], @{$type->{section} || []}) {
836 my ($name, $attr) = @$_; 852 my ($name, $attr) = @$_;
837 push @section_order, $name; 853 push @section_order, $name;
838 for (@$attr) { 854 for (@$attr) {
839 my ($k, $v) = @$_; 855 my ($k, $v) = @$_;
840 push @attr_order, $k; 856 push @attr_order, $k;
841 $section{$name}{$k} ||= $v; 857 $section{$name}{$k} = $v; # overwrite, so that the root decides
842 }
843 } 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.
844 } 875 }
845 876
846 $attr->{section} = [ 877 $attr->{section} = [
847 map !exists $section{$_} ? () : do { 878 map !exists $section{$_} ? () : do {
848 my $attr = delete $section{$_}; 879 my $attr = delete $section{$_};
852 map exists $attr->{$_} && !$ignore{$_} 883 map exists $attr->{$_} && !$ignore{$_}
853 ? [$_ => delete $attr->{$_}] : (), 884 ? [$_ => delete $attr->{$_}] : (),
854 @attr_order 885 @attr_order
855 ] 886 ]
856 }, 887 },
857
858 exists $section{$_} ? [$_ => delete $section{$_}] : (), 888 exists $section{$_} ? [$_ => delete $section{$_}] : (),
859 @section_order 889 @section_order
860 ]; 890 ];
861 891
862 $attr 892 $attr
863} 893}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines