I want to generate textures programmatically and then store them in a way so I can access them by enum, i.e. I would have an enum for RED, GREEN, etc. and in the creation of a texture bundle I want to reference the generated texture for RED for example, instead of generating new textures every time. I've been trying to use a resource hashmap like this:
struct LightTextures {
map: HashMap<LightColor, Handle<Image>>,
}
However, I don't understand how to get from Image to Handle<Image> - nor do I feel my whole approach is correct. I was going to do something like this:
mut commands: Commands,
asset_server: Res<AssetServer>,
mut texture_handles: ResMut<LightTextures>,
) {
let texture_red = create_texture(LightColor::RED);
texture_handles.map.insert(LightColor::RED, texture_red);
}```
Then, in a commands.spawn() I would use the enum to refer to the texture. Am I missing something really basic? Is there a way to use the resource system to access such generated textures in an efficient way or do I really have to make my own resource hashmap? And if I do, can anyone help me find the correct way to insert and address the textures I generated?