Hello, I've been ramming my head against the borrow checker due to conflicting mutable and immutable references to world, whilst trying to make a custom command.
What I'm trying to do is to make a generic custom command that spawns a sprite stack from a given AssetCollection struct.
An AssetCollection struct looks like this (it uses bevy_asset_loader):
#[derive(AssetCollection, Resource)]
struct VikGirl {
#[asset(texture_atlas(tile_size_x = 20, tile_size_y = 20, columns = 1, rows = 1))]
layout: Handle<TextureAtlasLayout>,
#[asset(image(sampler = nearest))]
#[asset(path = "Vik Girl.png")]
slice: Handle<Image>,
}
which has these impls:
impl StackedSprite for VikGirl {
fn layout(&self) -> Handle<TextureAtlasLayout> {
self.layout.clone()
}
fn slice(&self) -> Handle<Image> {
self.slice.clone()
}
}
There is also a generic stacked sprite struct which holds some info used for making the stack. It looks like this:
// Auxillary data for sprite stacks
struct SpriteStack<T: Resource + StackedSprite> {
pos: Vec3,
spacing: f32,
scale: f32,
slice_indexes: Vec<usize>,
_marker: std::marker::PhantomData<T>,
}
which has the impls:
impl<T: Resource + StackedSprite> SpriteStack<T> {
fn new(pos: Vec3,
spacing: f32,
scale: f32,
slice_indexes: Vec<usize>
) -> Self {
Self {
pos,
spacing,
scale,
slice_indexes,
_marker: std::marker::PhantomData,
}
}
}