MrGVSV / bevy_proto

Create config files for entities in Bevy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow `ProtoData` to store handles without paths

B-Reif opened this issue · comments

Currently the ProtoData struct requires a path when insert a handle:

    pub fn insert_handle<T: Asset>(
        &mut self,
        protoytpe: &dyn Prototypical,
        component: &dyn ProtoComponent,
        path: &HandlePath,
        handle: Handle<T>,
    ) {}

This poses a problem when inserting handles that don't correspond 1:1 with an asset path.

For instance, when loading an Aseprite file with bevy_ase, one .aseprite file path corresponds to many different handles (each frame has its own Image handle, other metadata handles are inserted, etc.)

As far as I can tell, ProtoData only uses this path as a key in its map. Fortunately for us, Handle already exposes HandleId, which implements Hash and uniquely identifies the Handle. We can fix this problem and simplify our API by keying on HandleId instead of a HandlePath.

This poses a problem when inserting handles that don't correspond 1:1 with an asset path.

For instance, when loading an Aseprite file with bevy_ase, one .aseprite file path corresponds to many different handles (each frame has its own Image handle, other metadata handles are inserted, etc.)

Good point. Not something I had considered when making this.

As far as I can tell, ProtoData only uses this path as a key in its map. Fortunately for us, Handle already exposes HandleId, which implements Hash and uniquely identifies the Handle. We can fix this problem and simplify our API by keying on HandleId instead of a HandlePath.

Yep, this is definitely a better way of doing this.