PointClickEngine::AssetManager
Inherits Reference < Object
Asset management system with ZIP archive support
The AssetManager provides a unified interface for loading game assets from both the filesystem and ZIP archives. It supports mounting multiple archives, caching loaded assets, and transparent fallback between archives and filesystem.
Features
- Mount multiple ZIP archives as virtual filesystems
- Automatic caching of loaded assets
- Transparent access to both archived and filesystem assets
- Singleton pattern for global access
Example
# Mount a game archive
AssetManager.mount_archive("game_assets.zip")
# Read a text file
dialog_text = AssetManager.read_file("dialogs/intro.txt")
# Read binary data (e.g., images)
image_data = AssetManager.read_bytes("sprites/player.png")
# Check if asset exists
if AssetManager.exists?("music/theme.ogg")
# Load the music
end
# List all files in a directory
sprites = AssetManager.list_files("sprites/")
Constructors
Class methods
Instance methods
Clear a single entry from cache
- path : Path to clear from cache
Clear specific entries from cache by prefix
- prefix : Path prefix to clear (e.g., "sprites/" clears all sprites)
Check if an asset exists in archives or filesystem
- path : Path to check
- returns : True if the asset exists
List all files in a directory across archives and filesystem
- directory : Directory path to list (empty for all files)
- returns : Array of file paths
Mount a ZIP archive as a virtual filesystem
Archives are searched before the filesystem when loading assets. Multiple archives can be mounted at different mount points.
- path : Path to the ZIP archive file
- mount_point : Virtual mount point (default: "/")
AssetManager.mount_archive("game_data.zip")
AssetManager.mount_archive("dlc_content.zip", "/dlc")
Read binary data from archives or filesystem
Searches mounted archives first, then falls back to filesystem. The result is cached for faster subsequent access.
- path : Path to the file to read
- returns : File contents as bytes, or nil if not found
Read a text file from archives or filesystem
Searches mounted archives first, then falls back to filesystem. The result is cached for faster subsequent access.
- path : Path to the file to read
- returns : File contents as a string
- raises : AssetNotFoundError if the file doesn't exist
Unmount a previously mounted archive
This also clears the asset cache to free memory.
- mount_point : The mount point to unmount (default: "/")