class

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

exists?(path : String) : Bool
Source
instance
Source
list_files(directory : String = "") : Array(String)
Source
mount_archive(path : String, mount_point : String = "/")

Convenience methods

Source
read_bytes(path : String) : Bytes | Nil
Source
read_file(path : String) : String
Source
unmount_archive(mount_point : String = "/")
Source

Instance methods

cache_bytes

Get total cached bytes for debugging

Source
cache_size

Get cache size for debugging

Source
clear_cache

Clear the asset cache to free memory

Source
clear_cache_entry(path : String)

Clear a single entry from cache

  • path : Path to clear from cache
Source
clear_cache_prefix(prefix : String)

Clear specific entries from cache by prefix

  • prefix : Path prefix to clear (e.g., "sprites/" clears all sprites)
Source
exists?(path : String) : Bool

Check if an asset exists in archives or filesystem

  • path : Path to check
  • returns : True if the asset exists
Source
list_files(directory : String = "") : Array(String)

List all files in a directory across archives and filesystem

  • directory : Directory path to list (empty for all files)
  • returns : Array of file paths
Source
mount_archive(path : String, mount_point : String = "/")

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")
Source
read_bytes(path : String) : Bytes | Nil

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
Source
read_file(path : String) : String

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
Source
unmount_archive(mount_point : String = "/")

Unmount a previously mounted archive

This also clears the asset cache to free memory.

  • mount_point : The mount point to unmount (default: "/")
Source

Nested types