Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/tools/entity/Entity.pm
package Entity; | package Entity; | ||||
use strict; | use strict; | ||||
use warnings; | use warnings; | ||||
use XML::Parser; | use XML::Parser; | ||||
use Data::Dumper; | use Data::Dumper; | ||||
use File::Find; | use File::Find; | ||||
my $vfsroot = '../../../binaries/data/mods'; | my $vfsroot = '../../../binaries/data/mods'; | ||||
sub get_filename | sub get_filename | ||||
{ | { | ||||
my ($vfspath) = @_; | my ($vfspath, $mod) = @_; | ||||
my $fn = "$vfsroot/public/simulation/templates/$vfspath.xml"; | my $fn = "$vfsroot/$mod/simulation/templates/$vfspath.xml"; | ||||
return $fn; | return $fn; | ||||
} | } | ||||
sub get_file | sub get_file | ||||
{ | { | ||||
my ($vfspath) = @_; | my ($vfspath, $mod) = @_; | ||||
my $fn = get_filename($vfspath); | my $fn = get_filename($vfspath, $mod); | ||||
open my $f, $fn or die "Error loading $fn: $!"; | open my $f, $fn or die "Error loading $fn: $!"; | ||||
local $/; | local $/; | ||||
return <$f>; | return <$f>; | ||||
} | } | ||||
sub trim | sub trim | ||||
{ | { | ||||
my ($t) = @_; | my ($t) = @_; | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | for my $k (grep $_ ne ' content', keys %$new) { | ||||
} | } | ||||
$base->{$k} ||= {}; | $base->{$k} ||= {}; | ||||
apply_layer($base->{$k}, $new->{$k}); | apply_layer($base->{$k}, $new->{$k}); | ||||
delete $base->{$k}{'@replace'}; | delete $base->{$k}{'@replace'}; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
sub get_main_mod | |||||
{ | |||||
my ($vfspath, $mods) = @_; | |||||
my @mods_list = split(/\|/, $mods); | |||||
my $main_mod = $mods_list[0]; | |||||
my $fn = "$vfsroot/$main_mod/simulation/templates/$vfspath.xml"; | |||||
if (not -e $fn) | |||||
{ | |||||
for my $dep (@mods_list) | |||||
{ | |||||
$fn = "$vfsroot/$dep/simulation/templates/$vfspath.xml"; | |||||
if (-e $fn) | |||||
{ | |||||
$main_mod = $dep; | |||||
last; | |||||
} | |||||
} | |||||
} | |||||
return $main_mod; | |||||
} | |||||
sub load_inherited | sub load_inherited | ||||
{ | { | ||||
my ($vfspath) = @_; | my ($vfspath, $mods) = @_; | ||||
my $layer = load_xml($vfspath, get_file($vfspath)); | my $main_mod = get_main_mod($vfspath, $mods); | ||||
my $layer = load_xml($vfspath, get_file($vfspath, $main_mod)); | |||||
if ($layer->{Entity}{'@parent'}) { | if ($layer->{Entity}{'@parent'}) { | ||||
my $parent = load_inherited($layer->{Entity}{'@parent'}{' content'}); | my $parent = load_inherited($layer->{Entity}{'@parent'}{' content'}, $mods); | ||||
apply_layer($parent->{Entity}, $layer->{Entity}); | apply_layer($parent->{Entity}, $layer->{Entity}); | ||||
return $parent; | return $parent; | ||||
} else { | } else { | ||||
return $layer; | return $layer; | ||||
} | } | ||||
} | } | ||||
sub find_entities | sub find_entities | ||||
{ | { | ||||
my ($modName) = @_; | |||||
my @files; | my @files; | ||||
my $find_process = sub { | my $find_process = sub { | ||||
return $File::Find::prune = 1 if $_ eq '.svn'; | return $File::Find::prune = 1 if $_ eq '.svn'; | ||||
my $n = $File::Find::name; | my $n = $File::Find::name; | ||||
return if /~$/; | return if /~$/; | ||||
return unless -f $_; | return unless -f $_; | ||||
$n =~ s~\Q$vfsroot\E/public/simulation/templates/~~; | $n =~ s~\Q$vfsroot\E/$modName/simulation/templates/~~; | ||||
$n =~ s/\.xml$//; | $n =~ s/\.xml$//; | ||||
push @files, $n; | push @files, $n; | ||||
}; | }; | ||||
find({ wanted => $find_process }, "$vfsroot/public/simulation/templates"); | find({ wanted => $find_process }, "$vfsroot/$modName/simulation/templates"); | ||||
return @files; | return @files; | ||||
} | } |
Wildfire Games · Phabricator