Asset manifest06 / 12

Files, URLs and asset IDs

Connect project files to the names used by game code.

The manifest lists the game’s assets. Each has an id, a type and a URL. Code uses a stable identifier; Vite produces the file’s address in the build.

In assets.manifest.ts, import.meta.glob collects file URLs and AssetManifestBuilder turns them into asset bundles. Here is that fragment with the result type specified through glob<string>:

const images = import.meta.glob<string>(
  '@game/assets/images/**/*.{png,jpg,jpeg,webp,avif}',
  { eager: true, query: '?url', import: 'default' },
);

Here, eager: true retrieves the URLs immediately. It does not load image content through AssetManager: those requests run when the corresponding bundle is loaded.

01
game/assets/images/block.pngSource file
02
images/block.pngAsset ID using the default strategy after /assets/
03
importedUrlAddress prepared by Vite
04
AssetManagerLoaded image under a stable ID
The identifier stays readable even if the build tool changes the output filename.

A small bundle can be assembled manually:

const bundles = [{
  name: 'images',
  assets: [{ id: 'images/block.png', type: 'image', importedUrl: blockUrl }],
}] satisfies BundleDescriptor[];

blockUrl is the image URL imported with ?url. Import the BundleDescriptor type from @gamedevland/engine/assets. For larger collections, AssetManifestBuilder assembles bundles without listing every file manually.

BundleBuildPolicy determines grouping. The game separates music and effects into audio-music and audio-sfx. The asset type selects the loader: image, audio, json or font. The SDK prepares the loaded image for a node; components do not need to create the texture individually.

Sources ↗

Block Puzzle · assets.manifest.ts↗The example's complete manifest.