Skip to content

asset_pack

FreeBodyEngine.core.files.asset_pack #

MAGIC = b'FBAP' module-attribute #

VERSION = 1 module-attribute #

AssetPack(data) #

Reads the .pak format written by build/builder.py's bundle_assets(): a MAGIC + version + entry-count header, an entry table (path, absolute data offset, data length), then the raw concatenated data. The whole table is parsed once at construction so any entry is then a direct slice - no per-read scanning.

Parses data (the whole .pak file's bytes) immediately - raises ValueError if it isn't a valid, current-version pak.

read(path) #

Returns the raw bytes stored at path - a direct slice of the already-loaded pack data, since init parsed the entry table up front. Raises KeyError if path isn't in this pack (check with in first).

AssetPackFileSystem(packs=None, asset_dir=None) #

Bases: FileSystem

The release-mode FileSystem: reads bundled .pak files sitting next to the frozen executable (see build/builder.py's run_pyinstaller, which ships dist/assets/*.pak as loose sibling files). user:// paths are the one exception - runtime-writable data (saves, logs) isn't part of any read-only pak, so those still hit the real filesystem, same as DevFileSystem does.

Loads every PACK_NAMES .pak found under asset_dir (default: an assets/ directory next to the frozen executable), unless packs is given directly (mainly for tests). Also loads the shared atlas's UV metadata out of the "data" pack, if present.

ATLAS_IMAGE_KEY = '_ENGINE_atlas.png' class-attribute instance-attribute #

ATLAS_METADATA_KEY = '_ENGINE_atlas.json' class-attribute instance-attribute #

PACK_NAMES = ('data', 'images', 'mesh') class-attribute instance-attribute #

atlas_uv = {} instance-attribute #

packs = packs if packs is not None else self._load_packs(base) instance-attribute #

user_files_path = self.sanitise_path(get_user_file_path()) instance-attribute #

ensure_path(path) #

Returns whether path exists as an entry in any loaded pack.

get_atlas_uv(path) #

Returns the (x, y, w, h) normalized UV rect path was packed into the shared atlas at, or None if it isn't an atlas-packed image (e.g. it's a non-image asset, or this is DevFileSystem/not release mode - other FileSystem classes simply don't define this method, callers should use getattr(fs, 'get_atlas_uv', None)).

get_file(path) #

Resolves path to a FileResource. user:// paths go straight to the real filesystem (same as DevFileSystem, since packs are read-only); anything else is looked up across every loaded pack, falling back to a region of the shared atlas image if path was atlas-packed at build time (see get_atlas_uv) rather than bundled as its own pack entry. Warns and returns None if path isn't found anywhere.

AssetPackStream(pack, path) #

Bases: FileStream

A read-only FileStream view onto one entry of an AssetPack.

.path mirrors DevFileStream's same-named attribute - callers (notably fbusl.compile(), which duck-types a source object as .data.path + .read() for error-message filenames) expect any FileStream to carry one, regardless of backend.

Wraps the entry at path within pack - reads nothing yet.

path = path instance-attribute #

read(size=-1, offset=0) #

Returns size bytes starting at offset into the entry's data (the whole entry when size is -1, the default). Re-reads the full entry from the pack on every call rather than caching it.