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, $mod) = @_; | my ($vfspath, $mod) = @_; | ||||
my $fn = "$vfsroot/$mod/simulation/templates/$vfspath.xml"; | my $fn = "$vfsroot/$mod/simulation/templates/special/filter/$vfspath.xml"; | ||||
if (not -e $fn) { | |||||
$fn = "$vfsroot/$mod/simulation/templates/mixins/$vfspath.xml"; | |||||
} | |||||
if (not -e $fn) { | |||||
$fn = "$vfsroot/$mod/simulation/templates/$vfspath.xml"; | |||||
} | |||||
return $fn; | return $fn; | ||||
} | } | ||||
sub get_file | sub get_file | ||||
{ | { | ||||
my ($vfspath, $mod) = @_; | my ($vfspath, $mod) = @_; | ||||
my $fn = get_filename($vfspath, $mod); | my $fn = get_filename($vfspath, $mod); | ||||
open my $f, $fn or die "Error loading $fn: $!"; | open my $f, $fn or die "Error loading $fn: $!"; | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | if (not -e $fn) | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return $main_mod; | return $main_mod; | ||||
} | } | ||||
sub load_inherited | sub load_inherited | ||||
{ | { | ||||
my ($vfspath, $mods) = @_; | my ($vfspath, $mods, $base) = @_; | ||||
if ($vfspath =~ /\|/) { | |||||
my @paths = split(/\|/, $vfspath, 2); | |||||
$base = load_inherited($paths[1], $mods, $base); | |||||
$base = load_inherited($paths[0], $mods, $base); | |||||
return $base | |||||
} | |||||
my $main_mod = get_main_mod($vfspath, $mods); | my $main_mod = get_main_mod($vfspath, $mods); | ||||
my $layer = load_xml($vfspath, get_file($vfspath, $main_mod)); | 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'}, $mods); | my $parent = load_inherited($layer->{Entity}{'@parent'}{' content'}, $mods, $base); | ||||
apply_layer($parent->{Entity}, $layer->{Entity}); | apply_layer($parent->{Entity}, $layer->{Entity}); | ||||
return $parent; | return $parent; | ||||
} else { | } else { | ||||
if (not $base) { | |||||
return $layer; | return $layer; | ||||
} | } | ||||
else { | |||||
apply_layer($base->{Entity}, $layer->{Entity}); | |||||
return $base | |||||
} | |||||
} | |||||
} | } | ||||
sub find_entities | sub find_entities | ||||
{ | { | ||||
my ($modName) = @_; | 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'; | ||||
Show All 11 Lines |
Wildfire Games · Phabricator