Added special skin category to include all skins except knives and gloves

This commit is contained in:
2026-10-01 00:08:15 +02:00
parent 746b01000c
commit e7f5f393a5
2 changed files with 34 additions and 20 deletions

View File

@@ -17,7 +17,7 @@ use tower_sessions_sqlx_store::sqlx::PgPool as SessionPgPool;
mod error; mod error;
mod skins; mod skins;
mod users; mod users;
use skins::{agent_info, skin_info, weapons, list_paint_index}; use skins::{agent_info, list_paint_index, skin_info, weapons};
use users::{login, logout, me, reload, update}; use users::{login, logout, me, reload, update};
#[tokio::main] #[tokio::main]

View File

@@ -66,6 +66,7 @@ enum Categories {
Pistols, Pistols,
Heavy, Heavy,
Equipment, Equipment,
Weapons, // Special category to get all weapons except gloves and knives
} }
impl Categories { impl Categories {
@@ -78,6 +79,7 @@ impl Categories {
Categories::Pistols => "Pistols", Categories::Pistols => "Pistols",
Categories::Heavy => "Heavy", Categories::Heavy => "Heavy",
Categories::Equipment => "Equipment", Categories::Equipment => "Equipment",
Categories::Weapons => "",
} }
} }
} }
@@ -105,10 +107,19 @@ pub async fn skin_info(
} }
// Same with category // Same with category
if let Some(category) = info_query.category { if let Some(category) = info_query.category {
default_skins = default_skins default_skins = match category {
.into_iter() Categories::Weapons => default_skins
.filter(|x| category.as_str() == x.category) .into_iter()
.collect(); .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 // For each remaining default weapon, see if the user has set a skin
// Secific cases for Knives and Gloves // Secific cases for Knives and Gloves
@@ -261,7 +272,6 @@ pub struct PaintQuery {
weapon: Uuid, weapon: Uuid,
team: Teams, team: Teams,
agent: Option<bool>, agent: Option<bool>,
gloves: Option<bool>
} }
pub async fn list_paint_index( pub async fn list_paint_index(
@@ -270,24 +280,28 @@ pub async fn list_paint_index(
) -> Result<Json<Vec<PaintIndexInfo>>, AppError> { ) -> Result<Json<Vec<PaintIndexInfo>>, AppError> {
let agent = match paint_query.agent { let agent = match paint_query.agent {
Some(agent) => agent, Some(agent) => agent,
None => false None => false,
};
let gloves = match paint_query.gloves {
Some(gloves) => gloves,
None => false
}; };
let paints = if agent { 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?; 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 { values
name: x.name, .into_iter()
paint_index: x.def_index, .map(|x| PaintIndexInfo {
display: x.display, name: x.name,
color: x.color, paint_index: x.def_index,
min_float: 0.0, display: x.display,
max_float: 0.0 color: x.color,
}).collect() min_float: 0.0,
max_float: 0.0,
})
.collect()
} else { } 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() { 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?, "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? _ => 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?