The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

  Game::Asset - Load assets (images, music, etc.) for games

SYNOPSIS

    my $asset = Game::Asset->new({
        file => 't_data/test1.zip',
    });
    my $foo = $asset->get_by_name( 'foo' );
    my $name = $foo->name;
    my $type = $foo->type;

DESCRIPTION

A common way to handle game assets is to load them in one big zip file. It might end up named with extensions like ".wad" or ".pk3" or even ".jar", but it's a zip file.

This module allows you to load up these files and fetch their contents into Perl objects. Each type of file is represented by a class that does the Game::Asset::Type Moose role. Which type class, exactly, is determined with mappings defined in the index.yml file. There are also a few built-in mappings.

THE INDEX FILE

A file named index.yml (a YAML file) is required inside the zip file, and resolves to a hash. Keys are the file extensions (without the dot), and values are the Perl class that will handle that type. That class must do the Game::Asset::Type Moose role.

The file must exist. If you just want to use the built-in mappings, it can resolve to an empty hash.

Built-in Mappings

The following mappings are always available without being in the index file:

Multi-mappings

There are times when the given content should be processed by more than one mapping. For instance, a game may want to process a Graphics::GVG vector in both OpenGL and Chipmunk (physics library).

This is what multi-mappings are for. See Game::Asset::Multi for details.

ATTRIBUTES

file

The path to the zip file.

mappings

A hashref (with autoderef). The keys are the file extensions, and the values are the Game::Asset::Type classes that will handle that type.

entries

A list of all the assets with their file extensions removed. Note that the index.yml file is filtered out.

METHODS

get_by_name

  $asset->get_by_name( 'foo' );

Pass in a name of an asset (without the extension). Returns an object representing the data in the zip file.

Any other arguments passed will be passed to the handling class.

LICENSE

Copyright (c) 2016 Timm Murray All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, 
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright 
      notice, this list of conditions and the following disclaimer in the 
      documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.