Added special skin category to include all skins except knives and gloves
This commit is contained in:
52
src/skins.rs
52
src/skins.rs
@@ -66,6 +66,7 @@ enum Categories {
|
||||
Pistols,
|
||||
Heavy,
|
||||
Equipment,
|
||||
Weapons, // Special category to get all weapons except gloves and knives
|
||||
}
|
||||
|
||||
impl Categories {
|
||||
@@ -78,6 +79,7 @@ impl Categories {
|
||||
Categories::Pistols => "Pistols",
|
||||
Categories::Heavy => "Heavy",
|
||||
Categories::Equipment => "Equipment",
|
||||
Categories::Weapons => "",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,10 +107,19 @@ pub async fn skin_info(
|
||||
}
|
||||
// Same with category
|
||||
if let Some(category) = info_query.category {
|
||||
default_skins = default_skins
|
||||
.into_iter()
|
||||
.filter(|x| category.as_str() == x.category)
|
||||
.collect();
|
||||
default_skins = match category {
|
||||
Categories::Weapons => default_skins
|
||||
.into_iter()
|
||||
.filter(|x| {
|
||||
![Categories::Gloves.as_str(), Categories::Knives.as_str()]
|
||||
.contains(&x.category.as_str())
|
||||
})
|
||||
.collect(),
|
||||
_ => default_skins
|
||||
.into_iter()
|
||||
.filter(|x| category.as_str() == x.category)
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
// For each remaining default weapon, see if the user has set a skin
|
||||
// Secific cases for Knives and Gloves
|
||||
@@ -261,7 +272,6 @@ pub struct PaintQuery {
|
||||
weapon: Uuid,
|
||||
team: Teams,
|
||||
agent: Option<bool>,
|
||||
gloves: Option<bool>
|
||||
}
|
||||
|
||||
pub async fn list_paint_index(
|
||||
@@ -270,24 +280,28 @@ pub async fn list_paint_index(
|
||||
) -> Result<Json<Vec<PaintIndexInfo>>, AppError> {
|
||||
let agent = match paint_query.agent {
|
||||
Some(agent) => agent,
|
||||
None => false
|
||||
};
|
||||
let gloves = match paint_query.gloves {
|
||||
Some(gloves) => gloves,
|
||||
None => false
|
||||
None => false,
|
||||
};
|
||||
let paints = if agent {
|
||||
let values = query!("SELECT a.name, a.def_index, a.display, r.color FROM agents a JOIN rarity r ON r.id = a.rarity WHERE a.team=$1", paint_query.team.as_i32()).fetch_all(&pool).await?;
|
||||
values.into_iter().map(|x| PaintIndexInfo {
|
||||
name: x.name,
|
||||
paint_index: x.def_index,
|
||||
display: x.display,
|
||||
color: x.color,
|
||||
min_float: 0.0,
|
||||
max_float: 0.0
|
||||
}).collect()
|
||||
values
|
||||
.into_iter()
|
||||
.map(|x| PaintIndexInfo {
|
||||
name: x.name,
|
||||
paint_index: x.def_index,
|
||||
display: x.display,
|
||||
color: x.color,
|
||||
min_float: 0.0,
|
||||
max_float: 0.0,
|
||||
})
|
||||
.collect()
|
||||
} else {
|
||||
let category = query!("SELECT w.category FROM weapons w WHERE w.id=$1", paint_query.weapon).fetch_one(&pool).await?;
|
||||
let category = query!(
|
||||
"SELECT w.category FROM weapons w WHERE w.id=$1",
|
||||
paint_query.weapon
|
||||
)
|
||||
.fetch_one(&pool)
|
||||
.await?;
|
||||
match category.category.as_str() {
|
||||
"Knives" | "Gloves" => query_as!(PaintIndexInfo, "SELECT w.name, s.paint_index, s.display, r.color, s.min_float, s.max_float FROM skins s JOIN rarity r ON r.id = s.rarity JOIN weapons w ON w.id = s.weapon WHERE w.category=$1", category.category).fetch_all(&pool).await?,
|
||||
_ => query_as!(PaintIndexInfo, "SELECT w.name, s.paint_index, s.display, r.color, s.min_float, s.max_float FROM skins s JOIN rarity r ON r.id = s.rarity JOIN weapons w ON w.id = s.weapon WHERE w.id=$1", paint_query.weapon).fetch_all(&pool).await?
|
||||
|
||||
Reference in New Issue
Block a user