use super::pattern::LEAGUE_FILE_MAGIC_BYTES;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, strum::EnumIter)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum LeagueFileKind {
Animation,
Jpeg,
LightGrid,
LuaObj,
MapGeometry,
Png,
Tga,
Preload,
PropertyBin,
PropertyBinOverride,
RiotStringTable,
SimpleSkin,
Skeleton,
StaticMeshAscii,
StaticMeshBinary,
Svg,
Texture,
TextureDds,
Unknown,
WorldGeometry,
WwiseBank,
WwisePackage,
}
impl LeagueFileKind {
pub fn iter() -> impl Iterator<Item = Self> {
<Self as strum::IntoEnumIterator>::iter()
}
#[inline]
#[must_use]
pub fn extension(&self) -> Option<&'static str> {
Some(match self {
Self::Unknown => return None,
Self::Animation => "anm",
Self::Jpeg => "jpg",
Self::LightGrid => "lightgrid",
Self::LuaObj => "luaobj",
Self::MapGeometry => "mapgeo",
Self::Png => "png",
Self::Tga => "tga",
Self::Preload => "preload",
Self::PropertyBin => "bin",
Self::PropertyBinOverride => "bin",
Self::RiotStringTable => "stringtable",
Self::SimpleSkin => "skn",
Self::Skeleton => "skl",
Self::StaticMeshAscii => "sco",
Self::StaticMeshBinary => "scb",
Self::Texture => "tex",
Self::TextureDds => "dds",
Self::WorldGeometry => "wgeo",
Self::WwiseBank => "bnk",
Self::WwisePackage => "wpk",
Self::Svg => "svg",
})
}
#[must_use]
pub fn from_extension(extension: impl AsRef<str>) -> LeagueFileKind {
let extension = extension.as_ref();
if extension.is_empty() {
return LeagueFileKind::Unknown;
}
let extension = match extension.starts_with('.') {
true => &extension[1..],
false => extension,
};
match extension {
"anm" => Self::Animation,
"bin" => Self::PropertyBin,
"bnk" => Self::WwiseBank,
"dds" => Self::TextureDds,
"jpg" => Self::Jpeg,
"luaobj" => Self::LuaObj,
"mapgeo" => Self::MapGeometry,
"png" => Self::Png,
"tga" => Self::Tga,
"preload" => Self::Preload,
"scb" => Self::StaticMeshBinary,
"sco" => Self::StaticMeshAscii,
"skl" => Self::Skeleton,
"skn" => Self::SimpleSkin,
"stringtable" => Self::RiotStringTable,
"svg" => Self::Svg,
"tex" => Self::Texture,
"wgeo" => Self::WorldGeometry,
"wpk" => Self::WwisePackage,
_ => Self::Unknown,
}
}
pub fn identify_from_bytes(data: &[u8]) -> LeagueFileKind {
for magic_byte in LEAGUE_FILE_MAGIC_BYTES.iter() {
if magic_byte.matches(data) {
return magic_byte.kind;
}
}
LeagueFileKind::Unknown
}
}