Skip to content

Commit

Permalink
Refactored share-directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpalmer committed Aug 21, 2010
1 parent e8ada2a commit cc4acbe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 20 additions & 8 deletions lib/Games/Maze/SDL.pm
Expand Up @@ -3,13 +3,32 @@ package Games::Maze::SDL;
# ABSTRACT: Maze game; using SDL!

use Moose;
use MooseX::ClassAttribute;
use Games::Maze::SDL::Model::Maze;
use Games::Maze::SDL::Model::Player;
use Games::Maze::SDL::View::Maze;
use Games::Maze::SDL::View::Player;
use Games::Maze::SDL::Controller;
use FindBin;
use Path::Class;
use File::ShareDir;

class_has 'share_dir' => (
is => 'ro',
lazy_build => 1,
init_arg => undef,
);

sub _build_share_dir {
my $root = Path::Class::Dir->new( $FindBin::Bin, '..' );
if ( -f $root->file('dist.ini') ) {
return $root->subdir('share');
}
else {
return Path::Class::Dir->new(
File::ShareDir::dist_dir('Games-Maze-SDL') );
}
}

sub run {
my ( $self, %options ) = @_;
Expand Down Expand Up @@ -62,13 +81,6 @@ sub run {
$controller->run;
}

sub sharedir {

# TODO
my $root = Path::Class::Dir->new( $FindBin::Bin, '..' );
return $root->subdir('share');
}

no Moose;
__PACKAGE__->meta->make_immutable;

Expand All @@ -80,7 +92,7 @@ __END__
use Games::Maze::SDL;
Games::Maze::SDL->run( %options );
Games::Maze::SDL->new->run( %options );
=head1 SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion lib/Games/Maze/SDL/View/Player.pm
Expand Up @@ -34,7 +34,7 @@ sub _build_sprite {
my ($self) = @_;

my $sprite = SDLx::Sprite::Animated->new(
image => Games::Maze::SDL->sharedir->file('hero.png'),
image => Games::Maze::SDL->share_dir->file('hero.png'),
rect => SDL::Rect->new( 0, 0, 24, 24 ),
ticks_per_frame => 10,
type => 'reverse',
Expand Down

0 comments on commit cc4acbe

Please sign in to comment.