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.137 by root, Tue Dec 15 01:44:06 2009 UTC vs.
Revision 1.142 by root, Sat May 15 00:30:53 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
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.
59our @FIELD_ORDER_MAP = (qw( 59our @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
821 unshift @import, \%Deliantra::Data::DEFAULT_ATTR
822 unless $type == 116;
823 822
824 my (%ignore); 823 my @new_import;
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 }
848 } 859 }
860 }
861 }
862
863 # remove ignores for "root" type
864 for (
865 map @{$_->[1]}, # section attributes
866 [general => ($root->{attr} || [])],
867 @{$root->{section} || []}
868 ) {
869 my ($k, $v) = @$_;
870 # skip fixed attributes, if they are ignored thats fine
871 next if $v->{type} eq 'fixed';
872
873 delete $ignore{$k}; # if the attributes are defined explicitly they
874 # should NOT be ignored. ignore should mainly
875 # hit imported/inherited attributes.
849 } 876 }
850 877
851 $attr->{section} = [ 878 $attr->{section} = [
852 map !exists $section{$_} ? () : do { 879 map !exists $section{$_} ? () : do {
853 my $attr = delete $section{$_}; 880 my $attr = delete $section{$_};
857 map exists $attr->{$_} && !$ignore{$_} 884 map exists $attr->{$_} && !$ignore{$_}
858 ? [$_ => delete $attr->{$_}] : (), 885 ? [$_ => delete $attr->{$_}] : (),
859 @attr_order 886 @attr_order
860 ] 887 ]
861 }, 888 },
862
863 exists $section{$_} ? [$_ => delete $section{$_}] : (), 889 exists $section{$_} ? [$_ => delete $section{$_}] : (),
864 @section_order 890 @section_order
865 ]; 891 ];
866 892
867 $attr 893 $attr
868} 894}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines