… | |
… | |
6 | |
6 | |
7 | =cut |
7 | =cut |
8 | |
8 | |
9 | package Deliantra; |
9 | package Deliantra; |
10 | |
10 | |
11 | our $VERSION = '1.25'; |
11 | our $VERSION = '1.30'; |
12 | |
12 | |
13 | use common::sense; |
13 | use common::sense; |
14 | |
14 | |
15 | use base 'Exporter'; |
15 | use base 'Exporter'; |
16 | |
16 | |
… | |
… | |
56 | |
56 | |
57 | # same as in server save routine, to (hopefully) be compatible |
57 | # same as in server save routine, to (hopefully) be compatible |
58 | # to the other editors. |
58 | # to the other editors. |
59 | our @FIELD_ORDER_MAP = (qw( |
59 | our @FIELD_ORDER_MAP = (qw( |
60 | file_format_version |
60 | file_format_version |
61 | name attach swap_time reset_timeout fixed_resettime difficulty region |
61 | name attach swap_time reset_timeout fixed_resettime difficulty |
|
|
62 | region music |
62 | shopitems shopgreed shopmin shopmax shoprace |
63 | shopitems shopgreed shopmin shopmax shoprace |
63 | darkness width height enter_x enter_y msg maplore |
64 | darkness width height enter_x enter_y msg maplore |
64 | unique template |
65 | unique template |
65 | outdoor temp pressure humid windspeed winddir sky nosmooth |
66 | outdoor temp pressure humid windspeed winddir sky nosmooth |
66 | tile_path_1 tile_path_2 tile_path_3 tile_path_4 |
67 | tile_path_1 tile_path_2 tile_path_3 tile_path_4 |
… | |
… | |
814 | } else { |
815 | } else { |
815 | $root = $Deliantra::Data::TYPE{Misc}; |
816 | $root = $Deliantra::Data::TYPE{Misc}; |
816 | } |
817 | } |
817 | } |
818 | } |
818 | |
819 | |
|
|
820 | my (%ignore); |
819 | my @import = ($root); |
821 | my @import = ($root); |
820 | |
822 | |
821 | unshift @import, \%Deliantra::Data::DEFAULT_ATTR |
823 | 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) { |
824 | while (my $type = shift @import) { |
|
|
825 | # first import everything we will need: |
828 | push @import, |
826 | push @import, |
829 | grep $_, |
827 | grep $_, |
830 | map $Deliantra::Data::TYPE{$_}, |
828 | map $Deliantra::Data::TYPE{$_}, |
831 | @{$type->{import} || []}; |
829 | @{$type->{import} || []}; |
832 | |
830 | |
|
|
831 | # and compute the ignored attributes |
|
|
832 | for (@{$type->{ignore} || []}) { |
|
|
833 | $ignore{$_}++ for ref $_ ? @$_ : $_; |
|
|
834 | } |
|
|
835 | |
|
|
836 | push @new_import, $type; |
|
|
837 | } |
|
|
838 | (@import) = @new_import; |
|
|
839 | |
|
|
840 | # then add defaults to the back of the list, so they are added |
|
|
841 | # as last resort. |
|
|
842 | push @import, \%Deliantra::Data::DEFAULT_ATTR |
|
|
843 | unless $type == 116; |
|
|
844 | |
|
|
845 | my (@section_order, %section, @attr_order); |
|
|
846 | |
|
|
847 | # @import = root, imported, default |
|
|
848 | while (my $type = pop @import) { |
833 | $attr->{$_} ||= $type->{$_} |
849 | $attr->{$_} ||= $type->{$_} |
834 | for qw(name desc use); |
850 | for qw(name desc use); |
835 | |
|
|
836 | for (@{$type->{ignore} || []}) { |
|
|
837 | $ignore{$_}++ for ref $_ ? @$_ : $_; |
|
|
838 | } |
|
|
839 | |
851 | |
840 | for ([general => ($type->{attr} || [])], @{$type->{section} || []}) { |
852 | for ([general => ($type->{attr} || [])], @{$type->{section} || []}) { |
841 | my ($name, $attr) = @$_; |
853 | my ($name, $attr) = @$_; |
842 | push @section_order, $name; |
854 | push @section_order, $name; |
843 | for (@$attr) { |
855 | for (@$attr) { |
844 | my ($k, $v) = @$_; |
856 | my ($k, $v) = @$_; |
845 | push @attr_order, $k; |
857 | push @attr_order, $k; |
846 | $section{$name}{$k} ||= $v; |
858 | $section{$name}{$k} = $v; # overwrite, so that the root decides |
847 | } |
859 | } |
848 | } |
860 | } |
849 | } |
861 | } |
850 | |
862 | |
851 | # remove ignores for "root" type |
863 | # remove ignores for "root" type |
|
|
864 | for ( |
852 | for (map @{$_->[1]}, # section attributes |
865 | map @{$_->[1]}, # section attributes |
853 | [general => ($root->{attr} || [])], |
866 | [general => ($root->{attr} || [])], |
854 | @{$root->{section} || []}) |
867 | @{$root->{section} || []} |
855 | { |
868 | ) { |
856 | my ($k, $v) = @$_; |
869 | my ($k, $v) = @$_; |
857 | # skip fixed attributes, if they are ignored thats fine |
870 | # skip fixed attributes, if they are ignored thats fine |
858 | next if $v->{type} eq 'fixed'; |
871 | next if $v->{type} eq 'fixed'; |
859 | |
872 | |
860 | delete $ignore{$k}; # if the attributes are defined explicitly they |
873 | delete $ignore{$k}; # if the attributes are defined explicitly they |
… | |
… | |
871 | map exists $attr->{$_} && !$ignore{$_} |
884 | map exists $attr->{$_} && !$ignore{$_} |
872 | ? [$_ => delete $attr->{$_}] : (), |
885 | ? [$_ => delete $attr->{$_}] : (), |
873 | @attr_order |
886 | @attr_order |
874 | ] |
887 | ] |
875 | }, |
888 | }, |
876 | exists $section{$_} ? [$_ => delete $section{$_}] : (), |
889 | exists $section{$_} ? [$_ => delete $section{$_}] : (), |
877 | @section_order |
890 | @section_order |
878 | ]; |
891 | ]; |
879 | |
892 | |
880 | $attr |
893 | $attr |
881 | } |
894 | } |