Games::Resource - open game resource files via standard paths



NAME

Games::Resource - open game resource files via standard paths


SYNOPSIS

        use Games::Resource;
        # set configuration
        Games::Resource::config (
          data_path => 'data',
          mod_path => '',
          language => 'de',
          resource_extension => '.zip',
          resource_files => [ 'sounds', 'textures', 'models', ... ],
          resource_hints => { md2 => 'models', ogg => 'sounds', ... },
        );
        # construct an object   
        my $file = Games::Resource::open('models','apple.md2');
        # get the handle to the file (unless part of an zip file)
        # This is not recommended.
        my $FILE_HANDLE = $file->handle();
        # or just the contents, regardless of how the file was stored
        $contents = $file->contents();          # not handle->contents unless


EXPORTS

Exports nothing on default.


DESCRIPTION

This package provides a standard way to access your game resources stored in files. After setting up the paths and resource hints, you can simple specify the filename and the module will figure out where the file actually is. Here is an example with the example values from above:

        my $FILE_HANDLE = Game::Resource::open('books/book1.txt');

This would first try:

        data/books/en/book1.txt

On the reasoning that you specified 'de' as language. If it was not found (because there is no German version), the next file tried would be:


        data/books/book1.txt

to access the "default language" version. If it was still not found, the resource files will be tried. Since you did not specifiy a hint for .txt files, all of them (in semi-random order) will be tried, like:

        data/sounds.zip
        data/textures.zip
        data/models.zip
        ...

In each of these resource files, the files:

        data/books/en/book1.txt
        data/books/book1.txt

will be tried.

If the file cannot be found at all, undef will be returned.

The reasource files must currently be ZIP archive. Maybe later other archive formats will be supported.

The paths are assumed relative to the current path.

The file will be closed automatically when the object returned by the open manpage is destroyed, e.g. goes out of scope or is freed otherwise.


METHODS

config()
        my $cfg = Game::Resource::config( );
        Game::Resource::config( $config );

Set/get the config values.

open()
        Games::Resource::open ($path, $file);

Try to find the given path and file and return a file handle. On error, returns undef.


AUTHORS

(c) 2003, Tels <http://bloodgate.com/>


SEE ALSO

the SDL:App::FPS manpage, the SDL::App manpage and SDL.


NAME

Games::Resource - open game resource files via standard paths


SYNOPSIS

        use Games::Resource;
        Games::Resource::config (
          data_path => 'data',
          mod_path => '',
          language => 'de',
          resource_extension => '.zip',
          resource_files => [ 'sounds', 'textures', 'models', ... ],
          resource_hints => [ md2 => 'models', ogg => 'sounds', ... ],
        );
        
        my $FILE_HANDLE = Games::Resource::open('models','apple.md2');


EXPORTS

Exports nothing on default.


DESCRIPTION

This package provides a standard way to access your game resources stored in files. After setting up the paths and resource hints, you can simple specify the filename and the module will figure out where the file actually is. Here is an example with the example values from above:

        my $FILE_HANDLE = Game::Resource::open('books/book1.txt');

This would first try:

        data/books/en/book1.txt

On the reasoning that you specified 'de' as language. If it was not found (because there is no German version), the next file tried would be:


        data/books/book1.txt

to access the "default language" version. If it was still not found, the resource files will be tried. Since you did not specifiy a hint for .txt files, all of them (in semi-random order) will be tried, like:

        data/sounds.zip
        data/textures.zip
        data/models.zip
        ...

In each of these resource files, the files:

        data/books/en/book1.txt
        data/books/book1.txt

will be tried.

If the file cannot be found at all, undef will be returned.


METHODS

config()
        my $cfg = Game::Resource::config( );
        Game::Resource::config( $config );

Set/get the config values.

Renders the brush.

open()
        Games::Resource::open ($path, $file);
        
        Try to find the given path and file and return a file handle. On error, returns
        undef.


AUTHORS

(c) 2003, Tels <http://bloodgate.com/>


SEE ALSO

the SDL:App::FPS manpage, the SDL::App manpage and SDL.


NAME

Games::Resource - open game resource files via standard paths


SYNOPSIS

        use Games::Resource;
        Games::Resource::config (
          data_path => 'data',
          mod_path => '',
          language => 'de',
          resource_extension => '.zip',
          resource_files => [ 'sounds', 'textures', 'models', ... ],
          resource_hints => [ md2 => 'models', ogg => 'sounds', ... ],
        );
        
        my $FILE_HANDLE = Games::Resource::open('models','apple.md2');


EXPORTS

Exports nothing on default.


DESCRIPTION

This package provides a standard way to access your game resources stored in files. After setting up the paths and resource hints, you can simple specify the filename and the module will figure out where the file actually is. Here is an example with the example values from above:

        my $FILE_HANDLE = Game::Resource::open('books/book1.txt');

This would first try:

        data/books/en/book1.txt

On the reasoning that you specified 'de' as language. If it was not found (because there is no German version), the next file tried would be:


        data/books/book1.txt

to access the "default language" version. If it was still not found, the resource files will be tried. Since you did not specifiy a hint for .txt files, all of them (in semi-random order) will be tried, like:

        data/sounds.zip
        data/textures.zip
        data/models.zip
        ...

In each of these resource files, the files:

        data/books/en/book1.txt
        data/books/book1.txt

will be tried.

If the file cannot be found at all, undef will be returned.


METHODS

config()
        my $cfg = Game::Resource::config( );
        Game::Resource::config( $config );

Set/get the config values.

Renders the brush.

open()
        Games::Resource::open ($path, $file);
        
        Try to find the given path and file and return a file handle. On error, returns
        undef.

The returned handle is not in binmode, you need to do this by yourself if you think you need it (e.g. opening non-text files under some old fashioned OS like win32).


AUTHORS

(c) 2003, Tels <http://bloodgate.com/>


SEE ALSO

the SDL:App::FPS manpage, the SDL::App manpage and SDL.