… | |
… | |
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 | |
821 | unshift @import, \%Deliantra::Data::DEFAULT_ATTR |
822 | my @new_import; |
822 | unless $type == 116; |
|
|
823 | |
|
|
824 | my (%ignore); |
|
|
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 | } |
858 | } |
848 | } |
859 | } |
849 | } |
860 | } |
850 | |
861 | |
851 | # remove ignores for "root" type |
862 | # remove ignores for "root" type |
|
|
863 | for ( |
852 | for (map @{$_->[1]}, # section attributes |
864 | map @{$_->[1]}, # section attributes |
853 | [general => ($root->{attr} || [])], |
865 | [general => ($root->{attr} || [])], |
854 | @{$root->{section} || []}) |
866 | @{$root->{section} || []} |
855 | { |
867 | ) { |
856 | my ($k, $v) = @$_; |
868 | my ($k, $v) = @$_; |
857 | # skip fixed attributes, if they are ignored thats fine |
869 | # skip fixed attributes, if they are ignored thats fine |
858 | next if $v->{type} eq 'fixed'; |
870 | next if $v->{type} eq 'fixed'; |
859 | |
871 | |
860 | delete $ignore{$k}; # if the attributes are defined explicitly they |
872 | delete $ignore{$k}; # if the attributes are defined explicitly they |
… | |
… | |
871 | map exists $attr->{$_} && !$ignore{$_} |
883 | map exists $attr->{$_} && !$ignore{$_} |
872 | ? [$_ => delete $attr->{$_}] : (), |
884 | ? [$_ => delete $attr->{$_}] : (), |
873 | @attr_order |
885 | @attr_order |
874 | ] |
886 | ] |
875 | }, |
887 | }, |
876 | exists $section{$_} ? [$_ => delete $section{$_}] : (), |
888 | exists $section{$_} ? [$_ => delete $section{$_}] : (), |
877 | @section_order |
889 | @section_order |
878 | ]; |
890 | ]; |
879 | |
891 | |
880 | $attr |
892 | $attr |
881 | } |
893 | } |