AssetDescriptor class abstract

Declares key and returns the handle to keep in a field - the third describe* hook alongside describeType/describeStruct, and the typed-handle rule applied to assets.

There is no asset name and nothing to look up at use time: has returns the handle, the declarer keeps it in a late final field, and that field is the only thing an asset-typed component field will accept.

class Player extends EntityStruct with Renderable2D {
  static const playerTexture = AssetKey<Texture>(BundleSource('player.png'));

  late final TextureAsset texture;
  late final DataPointer<TextureAsset> sprite;

  @override
  void describeAssets(AssetDescriptor descriptor) {
    super.describeAssets(descriptor);
    texture = descriptor.has(playerTexture);   // typed handle, kept
  }

  @override
  void describeStruct(DataDescriptor data) {
    super.describeStruct(data);
    sprite = data.hasPacked(assets.of<Texture>(), texture);
  }
}

The two types are deliberately distinct: playerTexture is an AssetKey<Texture> (identity - which asset) and texture is an Asset<Texture> (the addressed handle a row can point at). So sprite[e] = playerTexture does not compile and sprite[e] = texture does, which is the whole point of routing every asset through this pass.

Constructors

AssetDescriptor()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

has<T>(AssetKey<T> key) Asset<T>
Declares key and returns its handle.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited