use data::tables; use proto::RoleModelBin; use crate::logic::role::Avatar; pub struct RoleModel { pub avatar_list: Vec, } impl Default for RoleModel { fn default() -> Self { Self { avatar_list: tables::avatar_base_template_tb::iter() .map(|a| a.id) .filter(|tmpl_id| *tmpl_id < 2000) .map(|tmpl_id| Avatar::new(tmpl_id)) .collect(), } } } impl RoleModel { pub fn from_bin(bin: RoleModelBin) -> Self { Self { avatar_list: bin.avatar_list.into_iter().map(Avatar::from_bin).collect(), } } pub fn to_bin(&self) -> RoleModelBin { RoleModelBin { avatar_list: self.avatar_list.iter().map(Avatar::to_bin).collect(), } } }