MrGVSV / bevy_proto

Create config files for entities in Bevy
Other
239 stars 25 forks source link

Allow `ProtoData` to store handles without paths #16

Closed B-Reif closed 2 years ago

B-Reif commented 2 years ago

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.

MrGVSV commented 2 years ago

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.