use std::io::Read; use std::collections::HashMap; use crate::texture_loader::{Texture,Textures}; use strafesnet_common::model::TextureId; pub struct TextureLoader{ texture_names:HashMap, } impl TextureLoader{ pub fn new()->Self{ Self{ texture_names:HashMap::new(), } } } impl crate::texture_loader::TextureLoaderTrait for TextureLoader{ type Error=std::io::Error; fn acquire_id(&mut self,name:&str)->TextureId{ let texture_id=TextureId::new(self.texture_names.len() as u32); *self.texture_names.entry(name.to_owned()).or_insert(texture_id) } fn load(&self)->Result{ let mut texture_data=vec![Vec::::new();self.texture_names.len()]; for (texture_name,texture_id) in &self.texture_names{ let path=std::path::PathBuf::from(format!("textures/{}.dds",texture_name.as_str())); if let Ok(mut file)=std::fs::File::open(path){ //TODO: parallel file.read_to_end(texture_data.get_mut(texture_id.get() as usize).unwrap())?; } } Ok(Textures::new(texture_data.into_iter().map(Texture::ImageDDS).collect())) } }